Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / install_verifier.cc
index 9cfb94c..66f20b6 100644 (file)
 #include "base/metrics/histogram.h"
 #include "base/prefs/pref_service.h"
 #include "base/stl_util.h"
+#include "chrome/browser/extensions/extension_management.h"
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/extensions/install_signer.h"
 #include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/manifest_url_handler.h"
-#include "chrome/common/pref_names.h"
+#include "chrome/grit/generated_resources.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/common/content_switches.h"
 #include "extensions/browser/extension_prefs.h"
@@ -26,8 +26,8 @@
 #include "extensions/browser/pref_names.h"
 #include "extensions/common/extension_set.h"
 #include "extensions/common/manifest.h"
+#include "extensions/common/manifest_url_handlers.h"
 #include "extensions/common/one_shot_event.h"
-#include "grit/generated_resources.h"
 #include "ui/base/l10n/l10n_util.h"
 
 namespace extensions {
@@ -128,19 +128,6 @@ void LogInitResultHistogram(InitResult result) {
                             result, INIT_RESULT_MAX);
 }
 
-bool FromStore(const Extension& extension) {
-  if (extension.from_webstore() || ManifestURL::UpdatesFromGallery(&extension))
-    return true;
-
-  // If an extension has no update url, our autoupdate code will ask the
-  // webstore about it (to aid in migrating to the webstore from self-hosting
-  // or sideloading based installs). So we want to do verification checks on
-  // such extensions too so that we don't accidentally disable old installs of
-  // extensions that did migrate to the webstore.
-  return (ManifestURL::GetUpdateURL(&extension).is_empty() &&
-          Manifest::IsAutoUpdateableLocation(extension.location()));
-}
-
 bool CanUseExtensionApis(const Extension& extension) {
   return extension.is_extension() || extension.is_legacy_packaged_app();
 }
@@ -196,7 +183,23 @@ InstallVerifier::~InstallVerifier() {}
 
 // static
 bool InstallVerifier::NeedsVerification(const Extension& extension) {
-  return FromStore(extension) && CanUseExtensionApis(extension);
+  return IsFromStore(extension) && CanUseExtensionApis(extension);
+}
+
+
+
+// static
+bool InstallVerifier::IsFromStore(const Extension& extension) {
+  if (extension.from_webstore() || ManifestURL::UpdatesFromGallery(&extension))
+    return true;
+
+  // If an extension has no update url, our autoupdate code will ask the
+  // webstore about it (to aid in migrating to the webstore from self-hosting
+  // or sideloading based installs). So we want to do verification checks on
+  // such extensions too so that we don't accidentally disable old installs of
+  // extensions that did migrate to the webstore.
+  return (ManifestURL::GetUpdateURL(&extension).is_empty() &&
+          Manifest::IsAutoUpdateableLocation(extension.location()));
 }
 
 void InstallVerifier::Init() {
@@ -242,11 +245,15 @@ base::Time InstallVerifier::SignatureTimestamp() {
     return base::Time();
 }
 
-bool InstallVerifier::IsKnownId(const std::string& id) {
+bool InstallVerifier::IsKnownId(const std::string& id) const {
   return signature_.get() && (ContainsKey(signature_->ids, id) ||
                               ContainsKey(signature_->invalid_ids, id));
 }
 
+bool InstallVerifier::IsInvalid(const std::string& id) const {
+  return ((signature_.get() && ContainsKey(signature_->invalid_ids, id)));
+}
+
 void InstallVerifier::VerifyExtension(const std::string& extension_id) {
   ExtensionIdSet ids;
   ids.insert(extension_id);
@@ -314,6 +321,11 @@ void InstallVerifier::RemoveMany(const ExtensionIdSet& ids) {
     BeginFetch();
 }
 
+bool InstallVerifier::AllowedByEnterprisePolicy(const std::string& id) const {
+  return ExtensionManagementFactory::GetForBrowserContext(context_)
+      ->IsInstallationExplicitlyAllowed(id);
+}
+
 std::string InstallVerifier::GetDebugPolicyProviderName() const {
   return std::string("InstallVerifier");
 }
@@ -372,7 +384,7 @@ bool InstallVerifier::MustRemainDisabled(const Extension* extension,
   if (ContainsKey(InstallSigner::GetForcedNotFromWebstore(), extension->id())) {
     verified = false;
     outcome = FORCED_NOT_VERIFIED;
-  } else if (!FromStore(*extension)) {
+  } else if (!IsFromStore(*extension)) {
     verified = false;
     outcome = NOT_FROM_STORE;
   } else if (signature_.get() == NULL &&
@@ -421,7 +433,7 @@ ExtensionIdSet InstallVerifier::GetExtensionsToVerify() const {
   for (ExtensionSet::const_iterator iter = extensions->begin();
        iter != extensions->end();
        ++iter) {
-    if (NeedsVerification(**iter))
+    if (NeedsVerification(*iter->get()))
       result.insert((*iter)->id());
   }
   return result;
@@ -469,7 +481,7 @@ void InstallVerifier::OnVerificationComplete(bool success, OperationType type) {
              ++iter) {
           int disable_reasons = prefs_->GetDisableReasons((*iter)->id());
           if (disable_reasons & Extension::DISABLE_NOT_VERIFIED &&
-              !MustRemainDisabled(*iter, NULL, NULL)) {
+              !MustRemainDisabled(iter->get(), NULL, NULL)) {
             prefs_->RemoveDisableReason((*iter)->id(),
                                         Extension::DISABLE_NOT_VERIFIED);
           }
@@ -510,24 +522,6 @@ void InstallVerifier::GarbageCollect() {
   }
 }
 
-bool InstallVerifier::AllowedByEnterprisePolicy(const std::string& id) const {
-  PrefService* pref_service = prefs_->pref_service();
-  if (pref_service->IsManagedPreference(pref_names::kInstallAllowList)) {
-    const base::ListValue* whitelist =
-        pref_service->GetList(pref_names::kInstallAllowList);
-    base::StringValue id_value(id);
-    if (whitelist && whitelist->Find(id_value) != whitelist->end())
-      return true;
-  }
-  if (pref_service->IsManagedPreference(pref_names::kInstallForceList)) {
-    const base::DictionaryValue* forcelist =
-        pref_service->GetDictionary(pref_names::kInstallForceList);
-    if (forcelist && forcelist->HasKey(id))
-      return true;
-  }
-  return false;
-}
-
 bool InstallVerifier::IsVerified(const std::string& id) const {
   return ((signature_.get() && ContainsKey(signature_->ids, id)) ||
           ContainsKey(provisional_, id));