Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / extensions / browser / extension_prefs.cc
index 87b739b..d7774c5 100644 (file)
@@ -195,6 +195,8 @@ const char kInstallSignature[] = "extensions.install_signature";
 // synced. Default value is false.
 const char kPrefDoNotSync[] = "do_not_sync";
 
+const char kCorruptedDisableCount[] = "extensions.corrupted_disable_count";
+
 // Provider of write access to a dictionary storing extension prefs.
 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
  public:
@@ -720,8 +722,9 @@ bool ExtensionPrefs::HasWipeoutBeenAcknowledged(
 void ExtensionPrefs::SetWipeoutAcknowledged(
     const std::string& extension_id,
     bool value) {
-  UpdateExtensionPref(extension_id, kPrefWipeoutAcknowledged,
-                      value ? base::Value::CreateBooleanValue(value) : NULL);
+  UpdateExtensionPref(extension_id,
+                      kPrefWipeoutAcknowledged,
+                      value ? new base::FundamentalValue(value) : NULL);
 }
 
 bool ExtensionPrefs::HasSettingsApiBubbleBeenAcknowledged(
@@ -735,7 +738,7 @@ void ExtensionPrefs::SetSettingsApiBubbleBeenAcknowledged(
     bool value) {
   UpdateExtensionPref(extension_id,
                       kPrefSettingsBubbleAcknowledged,
-                      value ? base::Value::CreateBooleanValue(value) : NULL);
+                      value ? new base::FundamentalValue(value) : NULL);
 }
 
 bool ExtensionPrefs::HasNtpOverriddenBubbleBeenAcknowledged(
@@ -748,7 +751,7 @@ void ExtensionPrefs::SetNtpOverriddenBubbleBeenAcknowledged(
     bool value) {
   UpdateExtensionPref(extension_id,
                       kPrefNtpBubbleAcknowledged,
-                      value ? base::Value::CreateBooleanValue(value) : NULL);
+                      value ? new base::FundamentalValue(value) : NULL);
 }
 
 bool ExtensionPrefs::HasProxyOverriddenBubbleBeenAcknowledged(
@@ -761,7 +764,7 @@ void ExtensionPrefs::SetProxyOverriddenBubbleBeenAcknowledged(
     bool value) {
   UpdateExtensionPref(extension_id,
                       kPrefProxyBubbleAcknowledged,
-                      value ? base::Value::CreateBooleanValue(value) : NULL);
+                      value ? new base::FundamentalValue(value) : NULL);
 }
 
 bool ExtensionPrefs::SetAlertSystemFirstRun() {
@@ -1004,7 +1007,7 @@ void ExtensionPrefs::MigratePermissions(const ExtensionIdList& extension_ids) {
     // An extension's granted permissions need to be migrated if the
     // full_access bit is present. This bit was always present in the previous
     // scheme and is never present now.
-    bool full_access;
+    bool full_access = false;
     const base::DictionaryValue* ext = GetExtensionPref(*ext_id);
     if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access))
       continue;
@@ -1222,15 +1225,6 @@ void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) {
   SetExtensionPrefFromContainer(pref_names::kToolbar, extension_ids);
 }
 
-bool ExtensionPrefs::GetKnownDisabled(ExtensionIdSet* id_set_out) {
-  return GetUserExtensionPrefIntoContainer(pref_names::kKnownDisabled,
-                                           id_set_out);
-}
-
-void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) {
-  SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids);
-}
-
 void ExtensionPrefs::OnExtensionInstalled(
     const Extension* extension,
     Extension::State initial_state,
@@ -1246,9 +1240,14 @@ void ExtensionPrefs::OnExtensionInstalled(
                              install_flags,
                              install_parameter,
                              extension_dict);
-  FinishExtensionInfoPrefs(extension->id(), install_time,
-                           extension->RequiresSortOrdinal(),
-                           page_ordinal, extension_dict);
+
+  bool requires_sort_ordinal = extension->RequiresSortOrdinal() &&
+                               (install_flags & kInstallFlagIsEphemeral) == 0;
+  FinishExtensionInfoPrefs(extension->id(),
+                           install_time,
+                           requires_sort_ordinal,
+                           page_ordinal,
+                           extension_dict);
 }
 
 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
@@ -1296,7 +1295,7 @@ BlacklistState ExtensionPrefs::GetExtensionBlacklistState(
   if (IsExtensionBlacklisted(extension_id))
     return BLACKLISTED_MALWARE;
   const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id);
-  int int_value;
+  int int_value = 0;
   if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value))
     return static_cast<BlacklistState>(int_value);
 
@@ -1338,23 +1337,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper(
   if (!extension->GetInteger(kPrefLocation, &location_value))
     return scoped_ptr<ExtensionInfo>();
 
-  base::FilePath::StringType path;
-  if (!extension->GetString(kPrefPath, &path))
-    return scoped_ptr<ExtensionInfo>();
-
-  // Make path absolute. Unpacked extensions will already have absolute paths,
-  // otherwise make it so.
   Manifest::Location location = static_cast<Manifest::Location>(location_value);
-#if !defined(OS_CHROMEOS)
-  if (!Manifest::IsUnpackedLocation(location)) {
-    DCHECK(location == Manifest::COMPONENT ||
-           !base::FilePath(path).IsAbsolute());
-#else
-  // On Chrome OS some extensions can be installed to shared location and
-  // thus use absolute paths in prefs.
-  if (!base::FilePath(path).IsAbsolute()) {
-#endif  // !defined(OS_CHROMEOS)
-    path = install_directory_.Append(path).value();
+  if (location == Manifest::COMPONENT) {
+    // Component extensions are ignored. Component extensions may have data
+    // saved in preferences, but they are already loaded at this point (by
+    // ComponentLoader) and shouldn't be populated into the result of
+    // GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to
+    // load them.
+    return scoped_ptr<ExtensionInfo>();
   }
 
   // Only the following extension types have data saved in the preferences.
@@ -1372,6 +1362,14 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper(
     // Just a warning for now.
   }
 
+  base::FilePath::StringType path;
+  if (!extension->GetString(kPrefPath, &path))
+    return scoped_ptr<ExtensionInfo>();
+
+  // Make path absolute. Most (but not all) extension types have relative paths.
+  if (!base::FilePath(path).IsAbsolute())
+    path = install_directory_.Append(path).value();
+
   return scoped_ptr<ExtensionInfo>(new ExtensionInfo(
       manifest, extension_id, base::FilePath(path), location));
 }
@@ -1385,13 +1383,8 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
       !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
     return scoped_ptr<ExtensionInfo>();
   int state_value;
-  if (!ext->GetInteger(kPrefState, &state_value) ||
-      state_value == Extension::ENABLED_COMPONENT) {
-    // Old preferences files may not have kPrefState for component extensions.
-    return scoped_ptr<ExtensionInfo>();
-  }
-
-  if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
+  if (ext->GetInteger(kPrefState, &state_value) &&
+      state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
     LOG(WARNING) << "External extension with id " << extension_id
                  << " has been uninstalled by the user";
     return scoped_ptr<ExtensionInfo>();
@@ -1461,7 +1454,8 @@ void ExtensionPrefs::SetDelayedInstallInfo(
   // Add transient data that is needed by FinishDelayedInstallInfo(), but
   // should not be in the final extension prefs. All entries here should have
   // a corresponding Remove() call in FinishDelayedInstallInfo().
-  if (extension->RequiresSortOrdinal()) {
+  if (extension->RequiresSortOrdinal() &&
+      (install_flags & kInstallFlagIsEphemeral) == 0) {
     extension_dict->SetString(
         kPrefSuggestedPageOrdinal,
         page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
@@ -1512,6 +1506,11 @@ bool ExtensionPrefs::FinishDelayedInstallInfo(
       new base::StringValue(
           base::Int64ToString(install_time.ToInternalValue())));
 
+  // Some extension pref values are written conditionally. If they are not
+  // present in the delayed install data, they should be removed when the
+  // delayed install is committed.
+  extension_dict->Remove(kPrefEphemeralApp, NULL);
+
   // Commit the delayed install data.
   for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd();
        it.Advance()) {
@@ -1585,8 +1584,19 @@ bool ExtensionPrefs::IsEphemeralApp(const std::string& extension_id) const {
 void ExtensionPrefs::OnEphemeralAppPromoted(const std::string& extension_id) {
   DCHECK(IsEphemeralApp(extension_id));
 
-  UpdateExtensionPref(
-      extension_id, kPrefEphemeralApp, new base::FundamentalValue(false));
+  UpdateExtensionPref(extension_id, kPrefEphemeralApp, NULL);
+
+  // Ephemerality was previously stored in the creation flags, so ensure the bit
+  // is cleared.
+  int creation_flags = Extension::NO_FLAGS;
+  if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) {
+    if (creation_flags & Extension::IS_EPHEMERAL) {
+      creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL);
+      UpdateExtensionPref(extension_id,
+                          kPrefCreationFlags,
+                          new base::FundamentalValue(creation_flags));
+    }
+  }
 }
 
 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
@@ -1881,6 +1891,15 @@ void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
                       new base::StringValue(install_parameter));
 }
 
+int ExtensionPrefs::GetCorruptedDisableCount() {
+  return prefs_->GetInteger(kCorruptedDisableCount);
+}
+
+void ExtensionPrefs::IncrementCorruptedDisableCount() {
+  int count = prefs_->GetInteger(kCorruptedDisableCount);
+  prefs_->SetInteger(kCorruptedDisableCount, count + 1);
+}
+
 ExtensionPrefs::ExtensionPrefs(
     PrefService* prefs,
     const base::FilePath& root_dir,
@@ -1959,14 +1978,6 @@ void ExtensionPrefs::RegisterProfilePrefs(
       pref_names::kLastChromeVersion,
       std::string(),  // default value
       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-  registry->RegisterListPref(pref_names::kKnownDisabled,
-                             user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-#if defined(TOOLKIT_VIEWS)
-  registry->RegisterIntegerPref(
-      pref_names::kBrowserActionContainerWidth,
-      0,
-      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-#endif
   registry->RegisterDictionaryPref(
       kInstallSignature,
       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
@@ -1979,6 +1990,10 @@ void ExtensionPrefs::RegisterProfilePrefs(
       pref_names::kNativeMessagingUserLevelHosts,
       true,  // default value
       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+  registry->RegisterIntegerPref(
+      kCorruptedDisableCount,
+      0,  // default value
+      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
 }
 
 template <class ExtensionIdContainer>
@@ -2026,12 +2041,7 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs(
     int install_flags,
     const std::string& install_parameter,
     base::DictionaryValue* extension_dict) {
-  // Leave the state blank for component extensions so that old chrome versions
-  // loading new profiles do not fail in GetInstalledExtensionInfo. Older
-  // Chrome versions would only check for an omitted state.
-  if (initial_state != Extension::ENABLED_COMPONENT)
-    extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
-
+  extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
   extension_dict->Set(kPrefLocation,
                       new base::FundamentalValue(extension->location()));
   extension_dict->Set(kPrefCreationFlags,
@@ -2052,10 +2062,10 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs(
   if (install_flags & kInstallFlagIsBlacklistedForMalware)
     extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
 
-  // TODO(tmdiep): Delete the pref if false, don't write false.
-  bool is_ephemeral = (install_flags & kInstallFlagIsEphemeral) != 0;
-  extension_dict->Set(kPrefEphemeralApp,
-                      new base::FundamentalValue(is_ephemeral));
+  if (install_flags & kInstallFlagIsEphemeral)
+    extension_dict->Set(kPrefEphemeralApp, new base::FundamentalValue(true));
+  else
+    extension_dict->Remove(kPrefEphemeralApp, NULL);
 
   base::FilePath::StringType path = MakePathRelative(install_directory_,
                                                      extension->path());