Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / external_registry_loader_win.cc
index cf446c0..ce44ae7 100644 (file)
@@ -5,18 +5,19 @@
 #include "chrome/browser/extensions/external_registry_loader_win.h"
 
 #include "base/bind.h"
-#include "base/file_util.h"
 #include "base/files/file_path.h"
-#include "base/memory/scoped_handle.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_file.h"
 #include "base/metrics/histogram.h"
 #include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
 #include "base/values.h"
 #include "base/version.h"
 #include "base/win/registry.h"
 #include "chrome/browser/extensions/external_provider_impl.h"
-#include "chrome/common/extensions/extension.h"
+#include "components/crx_file/id_util.h"
 #include "content/public/browser/browser_thread.h"
 
 using content::BrowserThread;
@@ -26,17 +27,28 @@ namespace {
 // The Registry subkey that contains information about external extensions.
 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions";
 
-// Registry value of of that key that defines the path to the .crx file.
+// Registry value of the key that defines the installation parameter.
+const wchar_t kRegistryExtensionInstallParam[] = L"install_parameter";
+
+// Registry value of the key that defines the path to the .crx file.
 const wchar_t kRegistryExtensionPath[] = L"path";
 
 // Registry value of that key that defines the current version of the .crx file.
 const wchar_t kRegistryExtensionVersion[] = L"version";
 
+// Registry value of the key that defines an external update URL.
+const wchar_t kRegistryExtensionUpdateUrl[] = L"update_url";
+
 bool CanOpenFileForReading(const base::FilePath& path) {
-  ScopedStdioHandle file_handle(file_util::OpenFile(path, "rb"));
+  base::ScopedFILE file_handle(base::OpenFile(path, "rb"));
   return file_handle.get() != NULL;
 }
 
+std::string MakePrefName(const std::string& extension_id,
+                         const std::string& pref_name) {
+  return base::StringPrintf("%s.%s", extension_id.c_str(), pref_name.c_str());
+}
+
 }  // namespace
 
 namespace extensions {
@@ -51,26 +63,26 @@ void ExternalRegistryLoader::StartLoading() {
 void ExternalRegistryLoader::LoadOnFileThread() {
   CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
   base::TimeTicks start_time = base::TimeTicks::Now();
-  scoped_ptr<DictionaryValue> prefs(new DictionaryValue);
+  scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
 
   // A map of IDs, to weed out duplicates between HKCU and HKLM.
-  std::set<string16> keys;
+  std::set<base::string16> keys;
   base::win::RegistryKeyIterator iterator_machine_key(
-      HKEY_LOCAL_MACHINE, ASCIIToWide(kRegistryExtensions).c_str());
+      HKEY_LOCAL_MACHINE, base::ASCIIToWide(kRegistryExtensions).c_str());
   for (; iterator_machine_key.Valid(); ++iterator_machine_key)
     keys.insert(iterator_machine_key.Name());
   base::win::RegistryKeyIterator iterator_user_key(
-      HKEY_CURRENT_USER, ASCIIToWide(kRegistryExtensions).c_str());
+      HKEY_CURRENT_USER, base::ASCIIToWide(kRegistryExtensions).c_str());
   for (; iterator_user_key.Valid(); ++iterator_user_key)
     keys.insert(iterator_user_key.Name());
 
   // Iterate over the keys found, first trying HKLM, then HKCU, as per Windows
   // policy conventions. We only fall back to HKCU if the HKLM key cannot be
   // opened, not if the data within the key is invalid, for example.
-  for (std::set<string16>::const_iterator it = keys.begin();
+  for (std::set<base::string16>::const_iterator it = keys.begin();
        it != keys.end(); ++it) {
     base::win::RegKey key;
-    string16 key_path = ASCIIToWide(kRegistryExtensions);
+    base::string16 key_path = base::ASCIIToWide(kRegistryExtensions);
     key_path.append(L"\\");
     key_path.append(*it);
     if (key.Open(HKEY_LOCAL_MACHINE,
@@ -83,7 +95,33 @@ void ExternalRegistryLoader::LoadOnFileThread() {
       }
     }
 
-    string16 extension_path_str;
+    std::string id = base::UTF16ToASCII(*it);
+    base::StringToLowerASCII(&id);
+    if (!crx_file::id_util::IdIsValid(id)) {
+      LOG(ERROR) << "Invalid id value " << id
+                 << " for key " << key_path << ".";
+      continue;
+    }
+
+    base::string16 extension_dist_id;
+    if (key.ReadValue(kRegistryExtensionInstallParam, &extension_dist_id) ==
+        ERROR_SUCCESS) {
+      prefs->SetString(MakePrefName(id, ExternalProviderImpl::kInstallParam),
+                       base::UTF16ToASCII(extension_dist_id));
+    }
+
+    // If there is an update URL present, copy it to prefs and ignore
+    // path and version keys for this entry.
+    base::string16 extension_update_url;
+    if (key.ReadValue(kRegistryExtensionUpdateUrl, &extension_update_url)
+        == ERROR_SUCCESS) {
+      prefs->SetString(
+          MakePrefName(id, ExternalProviderImpl::kExternalUpdateUrl),
+          base::UTF16ToASCII(extension_update_url));
+      continue;
+    }
+
+    base::string16 extension_path_str;
     if (key.ReadValue(kRegistryExtensionPath, &extension_path_str)
         != ERROR_SUCCESS) {
       // TODO(erikkay): find a way to get this into about:extensions
@@ -115,7 +153,7 @@ void ExternalRegistryLoader::LoadOnFileThread() {
       continue;
     }
 
-    string16 extension_version;
+    base::string16 extension_version;
     if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
         != ERROR_SUCCESS) {
       // TODO(erikkay): find a way to get this into about:extensions
@@ -124,15 +162,7 @@ void ExternalRegistryLoader::LoadOnFileThread() {
       continue;
     }
 
-    std::string id = WideToASCII(*it);
-    StringToLowerASCII(&id);
-    if (!Extension::IdIsValid(id)) {
-      LOG(ERROR) << "Invalid id value " << id
-                 << " for key " << key_path << ".";
-      continue;
-    }
-
-    Version version(WideToASCII(extension_version));
+    Version version(base::UTF16ToASCII(extension_version));
     if (!version.IsValid()) {
       LOG(ERROR) << "Invalid version value " << extension_version
                  << " for key " << key_path << ".";
@@ -140,16 +170,19 @@ void ExternalRegistryLoader::LoadOnFileThread() {
     }
 
     prefs->SetString(
-        id + "." + ExternalProviderImpl::kExternalVersion,
-        WideToASCII(extension_version));
+        MakePrefName(id, ExternalProviderImpl::kExternalVersion),
+        base::UTF16ToASCII(extension_version));
     prefs->SetString(
-        id + "." + ExternalProviderImpl::kExternalCrx,
+        MakePrefName(id, ExternalProviderImpl::kExternalCrx),
         extension_path_str);
+    prefs->SetBoolean(
+        MakePrefName(id, ExternalProviderImpl::kMayBeUntrusted),
+        true);
   }
 
   prefs_.reset(prefs.release());
-  HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin",
-                  base::TimeTicks::Now() - start_time);
+  LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin",
+                        base::TimeTicks::Now() - start_time);
   BrowserThread::PostTask(
       BrowserThread::UI, FROM_HERE,
       base::Bind(&ExternalRegistryLoader::LoadFinished, this));