• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/extensions/external_component_loader.h"
6 
7 #include "base/command_line.h"
8 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/search/hotword_service_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/extension_constants.h"
16 #include "components/signin/core/browser/signin_manager.h"
17 #include "extensions/common/extension_urls.h"
18 
19 namespace extensions {
20 
ExternalComponentLoader(Profile * profile)21 ExternalComponentLoader::ExternalComponentLoader(Profile* profile)
22     : profile_(profile) {
23 }
24 
~ExternalComponentLoader()25 ExternalComponentLoader::~ExternalComponentLoader() {}
26 
27 // static
IsModifiable(const Extension * extension)28 bool ExternalComponentLoader::IsModifiable(const Extension* extension) {
29   if (extension->location() == Manifest::EXTERNAL_COMPONENT) {
30     static const char* enhanced_extension_hashes[] = {
31         "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2",  // http://crbug.com/312900
32         "D57DE394F36DC1C3220E7604C575D29C51A6C495",  // http://crbug.com/319444
33         "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9"   // http://crbug.com/371562
34     };
35     std::string hash = base::SHA1HashString(extension->id());
36     hash = base::HexEncode(hash.c_str(), hash.length());
37     for (size_t i = 0; i < arraysize(enhanced_extension_hashes); i++)
38       if (hash == enhanced_extension_hashes[i])
39         return true;
40   }
41   return false;
42 }
43 
StartLoading()44 void ExternalComponentLoader::StartLoading() {
45   prefs_.reset(new base::DictionaryValue());
46   std::string appId = extension_misc::kInAppPaymentsSupportAppId;
47   prefs_->SetString(appId + ".external_update_url",
48                     extension_urls::GetWebstoreUpdateUrl().spec());
49 
50   if (HotwordServiceFactory::IsHotwordAllowed(profile_)) {
51     std::string hotwordId = extension_misc::kHotwordExtensionId;
52     CommandLine* command_line = CommandLine::ForCurrentProcess();
53     if (command_line->HasSwitch(switches::kEnableExperimentalHotwording)) {
54       hotwordId = extension_misc::kHotwordSharedModuleId;
55     }
56     prefs_->SetString(hotwordId + ".external_update_url",
57                       extension_urls::GetWebstoreUpdateUrl().spec());
58   }
59 
60   InitBookmarksExperimentState(profile_);
61 
62   std::string ext_id;
63   if (GetBookmarksExperimentExtensionID(profile_->GetPrefs(), &ext_id) &&
64       !ext_id.empty()) {
65     prefs_->SetString(ext_id + ".external_update_url",
66                       extension_urls::GetWebstoreUpdateUrl().spec());
67   }
68 
69   LoadFinished();
70 }
71 
72 }  // namespace extensions
73