[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1 | // Copyright (c) 2012 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/extension_system.h" |
| 6 | |
[email protected] | 53603d2 | 2012-11-14 08:31:11 | [diff] [blame] | 7 | #include "base/base_switches.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 8 | #include "base/bind.h" |
| 9 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 11 | #include "base/strings/string_tokenizer.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 12 | #include "chrome/browser/browser_process.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 13 | #include "chrome/browser/content_settings/cookie_settings.h" |
[email protected] | 4868bcc | 2013-05-29 03:27:27 | [diff] [blame] | 14 | #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 15 | #include "chrome/browser/extensions/blacklist.h" |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 16 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 17 | #include "chrome/browser/extensions/event_router.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_info_map.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_pref_store.h" |
| 21 | #include "chrome/browser/extensions/extension_pref_value_map.h" |
[email protected] | ef9bba1 | 2012-04-06 16:26:09 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_pref_value_map_factory.h" |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_process_manager.h" |
| 25 | #include "chrome/browser/extensions/extension_service.h" |
| 26 | #include "chrome/browser/extensions/extension_system_factory.h" |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_warning_badge_service.h" |
| 28 | #include "chrome/browser/extensions/extension_warning_set.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 29 | #include "chrome/browser/extensions/lazy_background_task_queue.h" |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 30 | #include "chrome/browser/extensions/management_policy.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 31 | #include "chrome/browser/extensions/navigation_observer.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 32 | #include "chrome/browser/extensions/standard_management_policy_provider.h" |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 33 | #include "chrome/browser/extensions/state_store.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 34 | #include "chrome/browser/extensions/unpacked_installer.h" |
| 35 | #include "chrome/browser/extensions/user_script_master.h" |
| 36 | #include "chrome/browser/profiles/profile.h" |
| 37 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 38 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 39 | #include "chrome/common/chrome_switches.h" |
[email protected] | d69d7b17 | 2012-08-09 04:17:26 | [diff] [blame] | 40 | #include "chrome/common/chrome_version_info.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 41 | #include "chrome/common/extensions/extension.h" |
[email protected] | 5115ccc | 2012-06-11 19:47:07 | [diff] [blame] | 42 | #include "chrome/common/extensions/features/feature.h" |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 43 | #include "chrome/common/extensions/manifest.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 44 | #include "content/public/browser/browser_thread.h" |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 45 | #include "content/public/browser/url_data_source.h" |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 46 | #include "extensions/common/constants.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 47 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 48 | #if defined(OS_CHROMEOS) |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 49 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 50 | #include "chromeos/chromeos_switches.h" |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 51 | #include "chromeos/login/login_state.h" |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 52 | #endif |
| 53 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 54 | using content::BrowserThread; |
| 55 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 56 | namespace extensions { |
| 57 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 58 | // |
| 59 | // ExtensionSystem |
| 60 | // |
| 61 | |
| 62 | ExtensionSystem::ExtensionSystem() { |
[email protected] | d57a089c | 2012-08-16 00:26:43 | [diff] [blame] | 63 | // Only set if it hasn't already been set (e.g. by a test). |
| 64 | if (Feature::GetCurrentChannel() == Feature::GetDefaultChannel()) |
| 65 | Feature::SetCurrentChannel(chrome::VersionInfo::GetChannel()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | ExtensionSystem::~ExtensionSystem() { |
| 69 | } |
| 70 | |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 71 | // static |
| 72 | ExtensionSystem* ExtensionSystem::Get(Profile* profile) { |
| 73 | return ExtensionSystemFactory::GetForProfile(profile); |
| 74 | } |
| 75 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 76 | // |
| 77 | // ExtensionSystemImpl::Shared |
| 78 | // |
| 79 | |
| 80 | ExtensionSystemImpl::Shared::Shared(Profile* profile) |
| 81 | : profile_(profile) { |
| 82 | } |
| 83 | |
| 84 | ExtensionSystemImpl::Shared::~Shared() { |
| 85 | } |
| 86 | |
| 87 | void ExtensionSystemImpl::Shared::InitPrefs() { |
[email protected] | c4dc5cc | 2012-11-09 08:48:39 | [diff] [blame] | 88 | lazy_background_task_queue_.reset(new LazyBackgroundTaskQueue(profile_)); |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 89 | event_router_.reset(new EventRouter(profile_, ExtensionPrefs::Get(profile_))); |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 90 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 91 | // Two state stores. The latter, which contains declarative rules, must be |
| 92 | // loaded immediately so that the rules are ready before we issue network |
| 93 | // requests. |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 94 | state_store_.reset(new StateStore( |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 95 | profile_, |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 96 | profile_->GetPath().AppendASCII(ExtensionService::kStateStoreName), |
| 97 | true)); |
| 98 | rules_store_.reset(new StateStore( |
| 99 | profile_, |
| 100 | profile_->GetPath().AppendASCII(ExtensionService::kRulesStoreName), |
| 101 | false)); |
[email protected] | cb610dc | 2012-08-31 17:16:56 | [diff] [blame] | 102 | |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 103 | blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_))); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 104 | |
| 105 | standard_management_policy_provider_.reset( |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 106 | new StandardManagementPolicyProvider(ExtensionPrefs::Get(profile_))); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 107 | } |
| 108 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 109 | void ExtensionSystemImpl::Shared::RegisterManagementPolicyProviders() { |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 110 | DCHECK(standard_management_policy_provider_.get()); |
| 111 | management_policy_->RegisterProvider( |
| 112 | standard_management_policy_provider_.get()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 115 | void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
| 116 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 117 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 118 | navigation_observer_.reset(new NavigationObserver(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 119 | |
[email protected] | 53603d2 | 2012-11-14 08:31:11 | [diff] [blame] | 120 | bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); |
| 121 | ExtensionErrorReporter::Init(allow_noisy_errors); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 122 | |
| 123 | user_script_master_ = new UserScriptMaster(profile_); |
| 124 | |
| 125 | bool autoupdate_enabled = true; |
| 126 | #if defined(OS_CHROMEOS) |
| 127 | if (!extensions_enabled) |
| 128 | autoupdate_enabled = false; |
| 129 | else |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 130 | autoupdate_enabled = |
| 131 | !command_line->HasSwitch(chromeos::switches::kGuestSession); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 132 | #endif |
| 133 | extension_service_.reset(new ExtensionService( |
| 134 | profile_, |
| 135 | CommandLine::ForCurrentProcess(), |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 136 | profile_->GetPath().AppendASCII(extensions::kInstallDirectoryName), |
| 137 | ExtensionPrefs::Get(profile_), |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 138 | blacklist_.get(), |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 139 | autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 140 | extensions_enabled, |
| 141 | &ready_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 142 | |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 143 | // These services must be registered before the ExtensionService tries to |
| 144 | // load any extensions. |
| 145 | { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 146 | management_policy_.reset(new ManagementPolicy); |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 147 | RegisterManagementPolicyProviders(); |
| 148 | } |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 149 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 150 | bool skip_session_extensions = false; |
| 151 | #if defined(OS_CHROMEOS) |
| 152 | // Skip loading session extensions if we are not in a user session. |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 153 | skip_session_extensions = !chromeos::LoginState::Get()->IsUserLoggedIn(); |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 154 | if (!chrome::IsRunningInForcedAppMode()) { |
| 155 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 156 | skip_session_extensions); |
| 157 | } |
| 158 | #else |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 159 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 160 | skip_session_extensions); |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 161 | #endif |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 162 | if (command_line->HasSwitch(switches::kLoadComponentExtension)) { |
| 163 | CommandLine::StringType path_list = command_line->GetSwitchValueNative( |
| 164 | switches::kLoadComponentExtension); |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 165 | base::StringTokenizerT<CommandLine::StringType, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 166 | CommandLine::StringType::const_iterator> t(path_list, |
| 167 | FILE_PATH_LITERAL(",")); |
| 168 | while (t.GetNext()) { |
| 169 | // Load the component extension manifest synchronously. |
| 170 | // Blocking the UI thread is acceptable here since |
| 171 | // this flag designated for developers. |
| 172 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 173 | extension_service_->component_loader()->AddOrReplace( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 174 | base::FilePath(t.token())); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | extension_service_->Init(); |
| 178 | |
| 179 | if (extensions_enabled) { |
| 180 | // Load any extensions specified with --load-extension. |
| 181 | // TODO(yoz): Seems like this should move into ExtensionService::Init. |
| 182 | // But maybe it's no longer important. |
| 183 | if (command_line->HasSwitch(switches::kLoadExtension)) { |
| 184 | CommandLine::StringType path_list = command_line->GetSwitchValueNative( |
| 185 | switches::kLoadExtension); |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 186 | base::StringTokenizerT<CommandLine::StringType, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 187 | CommandLine::StringType::const_iterator> t(path_list, |
[email protected] | dd6d3667 | 2013-05-17 22:50:02 | [diff] [blame] | 188 | FILE_PATH_LITERAL(",")); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 189 | while (t.GetNext()) { |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 190 | std::string extension_id; |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 191 | UnpackedInstaller::Create(extension_service_.get())-> |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 192 | LoadFromCommandLine(base::FilePath(t.token()), &extension_id); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Make the chrome://extension-icon/ resource available. |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 198 | content::URLDataSource::Add(profile_, new ExtensionIconSource(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 199 | |
| 200 | // Initialize extension event routers. Note that on Chrome OS, this will |
| 201 | // not succeed if the user has not logged in yet, in which case the |
| 202 | // event routers are initialized in LoginUtilsImpl::CompleteLogin instead. |
| 203 | // The InitEventRouters call used to be in BrowserMain, because when bookmark |
| 204 | // import happened on first run, the bookmark bar was not being correctly |
| 205 | // initialized (see issue 40144). Now that bookmarks aren't imported and |
| 206 | // the event routers need to be initialized for every profile individually, |
| 207 | // initialize them with the extension service. |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 208 | // If import is going to run in a separate process (the profile itself is on |
| 209 | // the main process), wait for import to finish before initializing the |
| 210 | // routers. |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 211 | if (g_browser_process->profile_manager()->will_import()) { |
| 212 | extension_service_->InitEventRoutersAfterImport(); |
| 213 | } else { |
| 214 | extension_service_->InitEventRouters(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 215 | } |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 216 | |
| 217 | extension_warning_service_.reset(new ExtensionWarningService(profile_)); |
| 218 | extension_warning_badge_service_.reset( |
| 219 | new ExtensionWarningBadgeService(profile_)); |
| 220 | extension_warning_service_->AddObserver( |
| 221 | extension_warning_badge_service_.get()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 224 | void ExtensionSystemImpl::Shared::Shutdown() { |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 225 | if (extension_warning_service_) { |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 226 | extension_warning_service_->RemoveObserver( |
| 227 | extension_warning_badge_service_.get()); |
| 228 | } |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 229 | if (extension_service_) |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 230 | extension_service_->Shutdown(); |
| 231 | } |
| 232 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 233 | StateStore* ExtensionSystemImpl::Shared::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 234 | return state_store_.get(); |
| 235 | } |
| 236 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 237 | StateStore* ExtensionSystemImpl::Shared::rules_store() { |
| 238 | return rules_store_.get(); |
| 239 | } |
| 240 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 241 | ExtensionService* ExtensionSystemImpl::Shared::extension_service() { |
| 242 | return extension_service_.get(); |
| 243 | } |
| 244 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 245 | ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 246 | return management_policy_.get(); |
| 247 | } |
| 248 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 249 | UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { |
| 250 | return user_script_master_.get(); |
| 251 | } |
| 252 | |
| 253 | ExtensionInfoMap* ExtensionSystemImpl::Shared::info_map() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame^] | 254 | if (!extension_info_map_.get()) |
[email protected] | 9656bc5 | 2012-08-13 17:05:33 | [diff] [blame] | 255 | extension_info_map_ = new ExtensionInfoMap(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 256 | return extension_info_map_.get(); |
| 257 | } |
| 258 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 259 | LazyBackgroundTaskQueue* |
| 260 | ExtensionSystemImpl::Shared::lazy_background_task_queue() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 261 | return lazy_background_task_queue_.get(); |
| 262 | } |
| 263 | |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 264 | EventRouter* ExtensionSystemImpl::Shared::event_router() { |
[email protected] | c4dc5cc | 2012-11-09 08:48:39 | [diff] [blame] | 265 | return event_router_.get(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 266 | } |
| 267 | |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 268 | ExtensionWarningService* ExtensionSystemImpl::Shared::warning_service() { |
| 269 | return extension_warning_service_.get(); |
| 270 | } |
| 271 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 272 | Blacklist* ExtensionSystemImpl::Shared::blacklist() { |
| 273 | return blacklist_.get(); |
| 274 | } |
| 275 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 276 | // |
| 277 | // ExtensionSystemImpl |
| 278 | // |
| 279 | |
| 280 | ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
[email protected] | 98b67303 | 2012-12-11 10:26:02 | [diff] [blame] | 281 | : profile_(profile) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 282 | shared_ = ExtensionSystemSharedFactory::GetForProfile(profile); |
| 283 | |
| 284 | if (profile->IsOffTheRecord()) { |
| 285 | extension_process_manager_.reset(ExtensionProcessManager::Create(profile)); |
| 286 | } else { |
| 287 | shared_->InitPrefs(); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | ExtensionSystemImpl::~ExtensionSystemImpl() { |
[email protected] | 4868bcc | 2013-05-29 03:27:27 | [diff] [blame] | 292 | if (rules_registry_service_) |
| 293 | rules_registry_service_->Shutdown(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void ExtensionSystemImpl::Shutdown() { |
| 297 | extension_process_manager_.reset(); |
| 298 | } |
| 299 | |
[email protected] | 3dfa4c0 | 2012-07-30 17:21:41 | [diff] [blame] | 300 | void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 301 | DCHECK(!profile_->IsOffTheRecord()); |
| 302 | if (user_script_master() || extension_service()) |
| 303 | return; // Already initialized. |
| 304 | |
[email protected] | 9656bc5 | 2012-08-13 17:05:33 | [diff] [blame] | 305 | // The ExtensionInfoMap needs to be created before the |
| 306 | // ExtensionProcessManager. |
| 307 | shared_->info_map(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 308 | |
| 309 | extension_process_manager_.reset(ExtensionProcessManager::Create(profile_)); |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 310 | |
| 311 | serial_connection_manager_.reset(new ApiResourceManager<SerialConnection>( |
| 312 | BrowserThread::FILE)); |
| 313 | socket_manager_.reset(new ApiResourceManager<Socket>(BrowserThread::IO)); |
| 314 | usb_device_resource_manager_.reset( |
| 315 | new ApiResourceManager<UsbDeviceResource>(BrowserThread::IO)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 316 | |
[email protected] | 4868bcc | 2013-05-29 03:27:27 | [diff] [blame] | 317 | rules_registry_service_.reset(new RulesRegistryService(profile_)); |
| 318 | rules_registry_service_->RegisterDefaultRulesRegistries(); |
| 319 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 320 | shared_->Init(extensions_enabled); |
| 321 | } |
| 322 | |
[email protected] | 4868bcc | 2013-05-29 03:27:27 | [diff] [blame] | 323 | void ExtensionSystemImpl::InitForOTRProfile() { |
| 324 | // Only initialize the RulesRegistryService of the OTR ExtensionSystem if the |
| 325 | // regular ExtensionSystem has been initialized properly, as we depend on it. |
| 326 | // Some ChromeOS browser tests don't initialize the regular ExtensionSystem |
| 327 | // in login-tests. |
| 328 | if (extension_service()) { |
| 329 | rules_registry_service_.reset(new RulesRegistryService(profile_)); |
| 330 | rules_registry_service_->RegisterDefaultRulesRegistries(); |
| 331 | } |
| 332 | } |
| 333 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 334 | ExtensionService* ExtensionSystemImpl::extension_service() { |
| 335 | return shared_->extension_service(); |
| 336 | } |
| 337 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 338 | ManagementPolicy* ExtensionSystemImpl::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 339 | return shared_->management_policy(); |
| 340 | } |
| 341 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 342 | UserScriptMaster* ExtensionSystemImpl::user_script_master() { |
| 343 | return shared_->user_script_master(); |
| 344 | } |
| 345 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 346 | ExtensionProcessManager* ExtensionSystemImpl::process_manager() { |
| 347 | return extension_process_manager_.get(); |
| 348 | } |
| 349 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 350 | StateStore* ExtensionSystemImpl::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 351 | return shared_->state_store(); |
| 352 | } |
| 353 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 354 | StateStore* ExtensionSystemImpl::rules_store() { |
| 355 | return shared_->rules_store(); |
| 356 | } |
| 357 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 358 | ExtensionInfoMap* ExtensionSystemImpl::info_map() { |
| 359 | return shared_->info_map(); |
| 360 | } |
| 361 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 362 | LazyBackgroundTaskQueue* ExtensionSystemImpl::lazy_background_task_queue() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 363 | return shared_->lazy_background_task_queue(); |
| 364 | } |
| 365 | |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 366 | EventRouter* ExtensionSystemImpl::event_router() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 367 | return shared_->event_router(); |
| 368 | } |
| 369 | |
[email protected] | 4868bcc | 2013-05-29 03:27:27 | [diff] [blame] | 370 | RulesRegistryService* ExtensionSystemImpl::rules_registry_service() { |
| 371 | return rules_registry_service_.get(); |
| 372 | } |
| 373 | |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 374 | ApiResourceManager<SerialConnection>* |
| 375 | ExtensionSystemImpl::serial_connection_manager() { |
| 376 | return serial_connection_manager_.get(); |
| 377 | } |
| 378 | |
[email protected] | 3dfa4c0 | 2012-07-30 17:21:41 | [diff] [blame] | 379 | ApiResourceManager<Socket>* ExtensionSystemImpl::socket_manager() { |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 380 | return socket_manager_.get(); |
| 381 | } |
| 382 | |
| 383 | ApiResourceManager<UsbDeviceResource>* |
| 384 | ExtensionSystemImpl::usb_device_resource_manager() { |
| 385 | return usb_device_resource_manager_.get(); |
| 386 | } |
| 387 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 388 | ExtensionWarningService* ExtensionSystemImpl::warning_service() { |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 389 | return shared_->warning_service(); |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 392 | Blacklist* ExtensionSystemImpl::blacklist() { |
| 393 | return shared_->blacklist(); |
| 394 | } |
| 395 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 396 | const OneShotEvent& ExtensionSystemImpl::ready() const { |
| 397 | return shared_->ready(); |
| 398 | } |
| 399 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 400 | void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 401 | const Extension* extension) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 402 | base::Time install_time; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 403 | if (extension->location() != Manifest::COMPONENT) { |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 404 | install_time = ExtensionPrefs::Get(profile_)-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 405 | GetInstallTime(extension->id()); |
| 406 | } |
| 407 | bool incognito_enabled = |
| 408 | extension_service()->IsIncognitoEnabled(extension->id()); |
| 409 | BrowserThread::PostTask( |
| 410 | BrowserThread::IO, FROM_HERE, |
| 411 | base::Bind(&ExtensionInfoMap::AddExtension, info_map(), |
| 412 | make_scoped_refptr(extension), install_time, |
| 413 | incognito_enabled)); |
| 414 | } |
| 415 | |
| 416 | void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
| 417 | const std::string& extension_id, |
| 418 | const extension_misc::UnloadedExtensionReason reason) { |
| 419 | BrowserThread::PostTask( |
| 420 | BrowserThread::IO, FROM_HERE, |
| 421 | base::Bind(&ExtensionInfoMap::RemoveExtension, info_map(), |
| 422 | extension_id, reason)); |
| 423 | } |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 424 | |
| 425 | } // namespace extensions |