1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/external_component_loader.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/search/hotword_service.h"
12 #include "chrome/browser/search/hotword_service_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/common/extensions/extension_constants.h"
15 #include "components/signin/core/browser/signin_manager.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/common/extension_urls.h"
19 #if defined(OS_CHROMEOS)
20 #include "base/command_line.h"
21 #include "chromeos/chromeos_switches.h"
24 namespace extensions {
26 ExternalComponentLoader::ExternalComponentLoader(Profile* profile)
30 ExternalComponentLoader::~ExternalComponentLoader() {}
33 bool ExternalComponentLoader::IsModifiable(const Extension* extension) {
34 if (extension->location() == Manifest::EXTERNAL_COMPONENT) {
35 static const char* const enhanced_extension_hashes[] = {
36 "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900
37 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444
38 "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562
40 std::string hash = base::SHA1HashString(extension->id());
41 hash = base::HexEncode(hash.c_str(), hash.length());
42 for (size_t i = 0; i < arraysize(enhanced_extension_hashes); i++)
43 if (hash == enhanced_extension_hashes[i])
49 void ExternalComponentLoader::StartLoading() {
50 prefs_.reset(new base::DictionaryValue());
51 std::string app_id = extension_misc::kInAppPaymentsSupportAppId;
52 prefs_->SetString(app_id + ".external_update_url",
53 extension_urls::GetWebstoreUpdateUrl().spec());
55 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) {
56 std::string hotword_id = extension_misc::kHotwordExtensionId;
57 if (HotwordService::IsExperimentalHotwordingEnabled()) {
58 hotword_id = extension_misc::kHotwordSharedModuleId;
60 prefs_->SetString(hotword_id + ".external_update_url",
61 extension_urls::GetWebstoreUpdateUrl().spec());
64 InitBookmarksExperimentState(profile_);
67 std::string extension_id;
68 if (GetBookmarksExperimentExtensionID(profile_->GetPrefs(),
70 !extension_id.empty()) {
71 prefs_->SetString(extension_id + ".external_update_url",
72 extension_urls::GetWebstoreUpdateUrl().spec());
76 #if defined(OS_CHROMEOS)
78 CommandLine* const command_line = CommandLine::ForCurrentProcess();
79 if (!command_line->HasSwitch(chromeos::switches::kDisableNewZIPUnpacker)) {
80 const std::string extension_id = extension_misc::kZIPUnpackerExtensionId;
81 prefs_->SetString(extension_id + ".external_update_url",
82 extension_urls::GetWebstoreUpdateUrl().spec());
90 } // namespace extensions