Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / external_component_loader.cc
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/sha1.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"
18
19 #if defined(OS_CHROMEOS)
20 #include "base/command_line.h"
21 #include "chromeos/chromeos_switches.h"
22 #endif
23
24 namespace extensions {
25
26 ExternalComponentLoader::ExternalComponentLoader(Profile* profile)
27     : profile_(profile) {
28 }
29
30 ExternalComponentLoader::~ExternalComponentLoader() {}
31
32 // static
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
39     };
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])
44         return true;
45   }
46   return false;
47 }
48
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());
54
55   if (HotwordServiceFactory::IsHotwordAllowed(profile_)) {
56     std::string hotword_id = extension_misc::kHotwordExtensionId;
57     if (HotwordService::IsExperimentalHotwordingEnabled()) {
58       hotword_id = extension_misc::kHotwordSharedModuleId;
59     }
60     prefs_->SetString(hotword_id + ".external_update_url",
61                       extension_urls::GetWebstoreUpdateUrl().spec());
62   }
63
64   InitBookmarksExperimentState(profile_);
65
66   {
67     std::string extension_id;
68     if (GetBookmarksExperimentExtensionID(profile_->GetPrefs(),
69                                           &extension_id) &&
70         !extension_id.empty()) {
71       prefs_->SetString(extension_id + ".external_update_url",
72                         extension_urls::GetWebstoreUpdateUrl().spec());
73     }
74   }
75
76 #if defined(OS_CHROMEOS)
77   {
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());
83     }
84   }
85 #endif
86
87   LoadFinished();
88 }
89
90 }  // namespace extensions