[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] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 14 | #include "chrome/browser/extensions/blacklist.h" |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 15 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 16 | #include "chrome/browser/extensions/error_console/error_console.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_service.h" |
| 19 | #include "chrome/browser/extensions/extension_system_factory.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_warning_badge_service.h" |
| 22 | #include "chrome/browser/extensions/extension_warning_set.h" |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 23 | #include "chrome/browser/extensions/install_verifier.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 24 | #include "chrome/browser/extensions/navigation_observer.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 25 | #include "chrome/browser/extensions/standard_management_policy_provider.h" |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 26 | #include "chrome/browser/extensions/state_store.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 27 | #include "chrome/browser/extensions/unpacked_installer.h" |
| 28 | #include "chrome/browser/extensions/user_script_master.h" |
| 29 | #include "chrome/browser/profiles/profile.h" |
| 30 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 31 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 32 | #include "chrome/common/chrome_switches.h" |
[email protected] | d69d7b17 | 2012-08-09 04:17:26 | [diff] [blame] | 33 | #include "chrome/common/chrome_version_info.h" |
[email protected] | 15d4d2d | 2013-08-09 06:49:03 | [diff] [blame] | 34 | #include "chrome/common/extensions/features/feature_channel.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 35 | #include "content/public/browser/browser_thread.h" |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 36 | #include "content/public/browser/url_data_source.h" |
[email protected] | 3442353 | 2013-11-21 18:13:10 | [diff] [blame] | 37 | #include "extensions/browser/event_router.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame^] | 38 | #include "extensions/browser/extension_pref_store.h" |
| 39 | #include "extensions/browser/extension_pref_value_map.h" |
| 40 | #include "extensions/browser/extension_pref_value_map_factory.h" |
| 41 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 42 | #include "extensions/browser/info_map.h" |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 43 | #include "extensions/browser/lazy_background_task_queue.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 44 | #include "extensions/browser/management_policy.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 45 | #include "extensions/browser/process_manager.h" |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 46 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 47 | #include "extensions/common/extension.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 48 | #include "extensions/common/manifest.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 49 | |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 50 | #if defined(ENABLE_NOTIFICATIONS) |
| 51 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 52 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 53 | #include "ui/message_center/notifier_settings.h" |
| 54 | #endif |
| 55 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 56 | #if defined(OS_CHROMEOS) |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 57 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 58 | #include "chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.h" |
| 59 | #include "chrome/browser/chromeos/login/user.h" |
| 60 | #include "chrome/browser/chromeos/login/user_manager.h" |
| 61 | #include "chrome/browser/chromeos/policy/device_local_account.h" |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 62 | #include "chromeos/chromeos_switches.h" |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 63 | #include "chromeos/login/login_state.h" |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 64 | #endif |
| 65 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 66 | using content::BrowserThread; |
| 67 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 68 | namespace extensions { |
| 69 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 70 | // |
| 71 | // ExtensionSystem |
| 72 | // |
| 73 | |
| 74 | ExtensionSystem::ExtensionSystem() { |
[email protected] | d57a089c | 2012-08-16 00:26:43 | [diff] [blame] | 75 | // Only set if it hasn't already been set (e.g. by a test). |
[email protected] | 15d4d2d | 2013-08-09 06:49:03 | [diff] [blame] | 76 | if (GetCurrentChannel() == GetDefaultChannel()) |
| 77 | SetCurrentChannel(chrome::VersionInfo::GetChannel()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | ExtensionSystem::~ExtensionSystem() { |
| 81 | } |
| 82 | |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 83 | // static |
| 84 | ExtensionSystem* ExtensionSystem::Get(Profile* profile) { |
| 85 | return ExtensionSystemFactory::GetForProfile(profile); |
| 86 | } |
| 87 | |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 88 | // static |
| 89 | ExtensionSystem* ExtensionSystem::GetForBrowserContext( |
| 90 | content::BrowserContext* profile) { |
| 91 | return ExtensionSystemFactory::GetForProfile(static_cast<Profile*>(profile)); |
| 92 | } |
| 93 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 94 | // |
| 95 | // ExtensionSystemImpl::Shared |
| 96 | // |
| 97 | |
| 98 | ExtensionSystemImpl::Shared::Shared(Profile* profile) |
| 99 | : profile_(profile) { |
| 100 | } |
| 101 | |
| 102 | ExtensionSystemImpl::Shared::~Shared() { |
| 103 | } |
| 104 | |
| 105 | void ExtensionSystemImpl::Shared::InitPrefs() { |
[email protected] | c4dc5cc | 2012-11-09 08:48:39 | [diff] [blame] | 106 | lazy_background_task_queue_.reset(new LazyBackgroundTaskQueue(profile_)); |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 107 | event_router_.reset(new EventRouter(profile_, ExtensionPrefs::Get(profile_))); |
[email protected] | d3bd607 | 2013-07-26 18:32:14 | [diff] [blame] | 108 | // TODO(yoz): Remove once crbug.com/159265 is fixed. |
| 109 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 110 | // Two state stores. The latter, which contains declarative rules, must be |
| 111 | // loaded immediately so that the rules are ready before we issue network |
| 112 | // requests. |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 113 | state_store_.reset(new StateStore( |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 114 | profile_, |
[email protected] | 501105b | 2013-09-26 05:42:02 | [diff] [blame] | 115 | profile_->GetPath().AppendASCII(extensions::kStateStoreName), |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 116 | true)); |
[email protected] | d3bd607 | 2013-07-26 18:32:14 | [diff] [blame] | 117 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 118 | rules_store_.reset(new StateStore( |
| 119 | profile_, |
[email protected] | 501105b | 2013-09-26 05:42:02 | [diff] [blame] | 120 | profile_->GetPath().AppendASCII(extensions::kRulesStoreName), |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 121 | false)); |
[email protected] | cb610dc | 2012-08-31 17:16:56 | [diff] [blame] | 122 | |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 123 | blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_))); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 124 | |
| 125 | standard_management_policy_provider_.reset( |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 126 | new StandardManagementPolicyProvider(ExtensionPrefs::Get(profile_))); |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 127 | |
| 128 | #if defined (OS_CHROMEOS) |
| 129 | const chromeos::User* user = chromeos::UserManager::Get()->GetActiveUser(); |
| 130 | policy::DeviceLocalAccount::Type device_local_account_type; |
| 131 | if (user && policy::IsDeviceLocalAccountUser(user->email(), |
| 132 | &device_local_account_type)) { |
| 133 | device_local_account_management_policy_provider_.reset( |
| 134 | new chromeos::DeviceLocalAccountManagementPolicyProvider( |
| 135 | device_local_account_type)); |
| 136 | } |
| 137 | #endif // defined (OS_CHROMEOS) |
| 138 | |
| 139 | #endif // defined(ENABLE_EXTENSIONS) |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 140 | } |
| 141 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 142 | void ExtensionSystemImpl::Shared::RegisterManagementPolicyProviders() { |
[email protected] | d3bd607 | 2013-07-26 18:32:14 | [diff] [blame] | 143 | // TODO(yoz): Remove once crbug.com/159265 is fixed. |
| 144 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 145 | DCHECK(standard_management_policy_provider_.get()); |
| 146 | management_policy_->RegisterProvider( |
| 147 | standard_management_policy_provider_.get()); |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 148 | |
| 149 | #if defined (OS_CHROMEOS) |
| 150 | if (device_local_account_management_policy_provider_) { |
| 151 | management_policy_->RegisterProvider( |
| 152 | device_local_account_management_policy_provider_.get()); |
| 153 | } |
| 154 | #endif // defined (OS_CHROMEOS) |
| 155 | |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 156 | management_policy_->RegisterProvider(install_verifier_.get()); |
| 157 | |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 158 | #endif // defined(ENABLE_EXTENSIONS) |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 159 | } |
| 160 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 161 | void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
| 162 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 163 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 164 | navigation_observer_.reset(new NavigationObserver(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 165 | |
[email protected] | 53603d2 | 2012-11-14 08:31:11 | [diff] [blame] | 166 | bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); |
| 167 | ExtensionErrorReporter::Init(allow_noisy_errors); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 168 | |
| 169 | user_script_master_ = new UserScriptMaster(profile_); |
| 170 | |
| 171 | bool autoupdate_enabled = true; |
| 172 | #if defined(OS_CHROMEOS) |
| 173 | if (!extensions_enabled) |
| 174 | autoupdate_enabled = false; |
| 175 | else |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 176 | autoupdate_enabled = |
| 177 | !command_line->HasSwitch(chromeos::switches::kGuestSession); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 178 | #endif |
| 179 | extension_service_.reset(new ExtensionService( |
| 180 | profile_, |
| 181 | CommandLine::ForCurrentProcess(), |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 182 | profile_->GetPath().AppendASCII(extensions::kInstallDirectoryName), |
| 183 | ExtensionPrefs::Get(profile_), |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 184 | blacklist_.get(), |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 185 | autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 186 | extensions_enabled, |
| 187 | &ready_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 188 | |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 189 | // These services must be registered before the ExtensionService tries to |
| 190 | // load any extensions. |
| 191 | { |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 192 | install_verifier_.reset(new InstallVerifier(ExtensionPrefs::Get(profile_), |
| 193 | profile_->GetRequestContext())); |
| 194 | install_verifier_->Init(); |
| 195 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 196 | management_policy_.reset(new ManagementPolicy); |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 197 | RegisterManagementPolicyProviders(); |
| 198 | } |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 199 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 200 | bool skip_session_extensions = false; |
| 201 | #if defined(OS_CHROMEOS) |
| 202 | // Skip loading session extensions if we are not in a user session. |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 203 | skip_session_extensions = !chromeos::LoginState::Get()->IsUserLoggedIn(); |
[email protected] | 531593d | 2014-01-08 18:48:31 | [diff] [blame] | 204 | if (chrome::IsRunningInForcedAppMode()) { |
| 205 | extension_service_->component_loader()-> |
| 206 | AddDefaultComponentExtensionsForKioskMode(skip_session_extensions); |
| 207 | } else { |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 208 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 209 | skip_session_extensions); |
| 210 | } |
| 211 | #else |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 212 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 213 | skip_session_extensions); |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 214 | #endif |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 215 | if (command_line->HasSwitch(switches::kLoadComponentExtension)) { |
| 216 | CommandLine::StringType path_list = command_line->GetSwitchValueNative( |
| 217 | switches::kLoadComponentExtension); |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 218 | base::StringTokenizerT<CommandLine::StringType, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 219 | CommandLine::StringType::const_iterator> t(path_list, |
| 220 | FILE_PATH_LITERAL(",")); |
| 221 | while (t.GetNext()) { |
| 222 | // Load the component extension manifest synchronously. |
| 223 | // Blocking the UI thread is acceptable here since |
| 224 | // this flag designated for developers. |
| 225 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 226 | extension_service_->component_loader()->AddOrReplace( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 227 | base::FilePath(t.token())); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | extension_service_->Init(); |
| 231 | |
[email protected] | c1909afb | 2013-11-13 21:12:51 | [diff] [blame] | 232 | // Make the chrome://extension-icon/ resource available. |
| 233 | content::URLDataSource::Add(profile_, new ExtensionIconSource(profile_)); |
| 234 | |
| 235 | extension_warning_service_.reset(new ExtensionWarningService(profile_)); |
| 236 | extension_warning_badge_service_.reset( |
| 237 | new ExtensionWarningBadgeService(profile_)); |
| 238 | extension_warning_service_->AddObserver( |
| 239 | extension_warning_badge_service_.get()); |
| 240 | error_console_.reset(new ErrorConsole(profile_, extension_service_.get())); |
| 241 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 242 | if (extensions_enabled) { |
| 243 | // Load any extensions specified with --load-extension. |
| 244 | // TODO(yoz): Seems like this should move into ExtensionService::Init. |
| 245 | // But maybe it's no longer important. |
| 246 | if (command_line->HasSwitch(switches::kLoadExtension)) { |
| 247 | CommandLine::StringType path_list = command_line->GetSwitchValueNative( |
| 248 | switches::kLoadExtension); |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 249 | base::StringTokenizerT<CommandLine::StringType, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 250 | CommandLine::StringType::const_iterator> t(path_list, |
[email protected] | dd6d3667 | 2013-05-17 22:50:02 | [diff] [blame] | 251 | FILE_PATH_LITERAL(",")); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 252 | while (t.GetNext()) { |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 253 | std::string extension_id; |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 254 | UnpackedInstaller::Create(extension_service_.get())-> |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 255 | LoadFromCommandLine(base::FilePath(t.token()), &extension_id); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | } |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 261 | void ExtensionSystemImpl::Shared::Shutdown() { |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 262 | if (extension_warning_service_) { |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 263 | extension_warning_service_->RemoveObserver( |
| 264 | extension_warning_badge_service_.get()); |
| 265 | } |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 266 | if (extension_service_) |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 267 | extension_service_->Shutdown(); |
| 268 | } |
| 269 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 270 | StateStore* ExtensionSystemImpl::Shared::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 271 | return state_store_.get(); |
| 272 | } |
| 273 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 274 | StateStore* ExtensionSystemImpl::Shared::rules_store() { |
| 275 | return rules_store_.get(); |
| 276 | } |
| 277 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 278 | ExtensionService* ExtensionSystemImpl::Shared::extension_service() { |
| 279 | return extension_service_.get(); |
| 280 | } |
| 281 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 282 | ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 283 | return management_policy_.get(); |
| 284 | } |
| 285 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 286 | UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { |
| 287 | return user_script_master_.get(); |
| 288 | } |
| 289 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 290 | InfoMap* ExtensionSystemImpl::Shared::info_map() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 291 | if (!extension_info_map_.get()) |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 292 | extension_info_map_ = new InfoMap(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 293 | return extension_info_map_.get(); |
| 294 | } |
| 295 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 296 | LazyBackgroundTaskQueue* |
| 297 | ExtensionSystemImpl::Shared::lazy_background_task_queue() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 298 | return lazy_background_task_queue_.get(); |
| 299 | } |
| 300 | |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 301 | EventRouter* ExtensionSystemImpl::Shared::event_router() { |
[email protected] | c4dc5cc | 2012-11-09 08:48:39 | [diff] [blame] | 302 | return event_router_.get(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 305 | ExtensionWarningService* ExtensionSystemImpl::Shared::warning_service() { |
| 306 | return extension_warning_service_.get(); |
| 307 | } |
| 308 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 309 | Blacklist* ExtensionSystemImpl::Shared::blacklist() { |
| 310 | return blacklist_.get(); |
| 311 | } |
| 312 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 313 | ErrorConsole* ExtensionSystemImpl::Shared::error_console() { |
| 314 | return error_console_.get(); |
| 315 | } |
| 316 | |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 317 | InstallVerifier* ExtensionSystemImpl::Shared::install_verifier() { |
| 318 | return install_verifier_.get(); |
| 319 | } |
| 320 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 321 | // |
| 322 | // ExtensionSystemImpl |
| 323 | // |
| 324 | |
| 325 | ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
[email protected] | 98b67303 | 2012-12-11 10:26:02 | [diff] [blame] | 326 | : profile_(profile) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 327 | shared_ = ExtensionSystemSharedFactory::GetForProfile(profile); |
| 328 | |
| 329 | if (profile->IsOffTheRecord()) { |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 330 | process_manager_.reset(ProcessManager::Create(profile)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 331 | } else { |
| 332 | shared_->InitPrefs(); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | ExtensionSystemImpl::~ExtensionSystemImpl() { |
| 337 | } |
| 338 | |
| 339 | void ExtensionSystemImpl::Shutdown() { |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 340 | process_manager_.reset(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | 7cf1ee4 | 2013-12-11 09:13:49 | [diff] [blame] | 343 | void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 344 | DCHECK(!profile_->IsOffTheRecord()); |
| 345 | if (user_script_master() || extension_service()) |
| 346 | return; // Already initialized. |
| 347 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 348 | // The InfoMap needs to be created before the ProcessManager. |
[email protected] | 9656bc5 | 2012-08-13 17:05:33 | [diff] [blame] | 349 | shared_->info_map(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 350 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 351 | process_manager_.reset(ProcessManager::Create(profile_)); |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 352 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 353 | shared_->Init(extensions_enabled); |
| 354 | } |
| 355 | |
| 356 | ExtensionService* ExtensionSystemImpl::extension_service() { |
| 357 | return shared_->extension_service(); |
| 358 | } |
| 359 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 360 | ManagementPolicy* ExtensionSystemImpl::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 361 | return shared_->management_policy(); |
| 362 | } |
| 363 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 364 | UserScriptMaster* ExtensionSystemImpl::user_script_master() { |
| 365 | return shared_->user_script_master(); |
| 366 | } |
| 367 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 368 | ProcessManager* ExtensionSystemImpl::process_manager() { |
| 369 | return process_manager_.get(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 370 | } |
| 371 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 372 | StateStore* ExtensionSystemImpl::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 373 | return shared_->state_store(); |
| 374 | } |
| 375 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 376 | StateStore* ExtensionSystemImpl::rules_store() { |
| 377 | return shared_->rules_store(); |
| 378 | } |
| 379 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 380 | InfoMap* ExtensionSystemImpl::info_map() { return shared_->info_map(); } |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 381 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 382 | LazyBackgroundTaskQueue* ExtensionSystemImpl::lazy_background_task_queue() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 383 | return shared_->lazy_background_task_queue(); |
| 384 | } |
| 385 | |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 386 | EventRouter* ExtensionSystemImpl::event_router() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 387 | return shared_->event_router(); |
| 388 | } |
| 389 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 390 | ExtensionWarningService* ExtensionSystemImpl::warning_service() { |
[email protected] | 2def34cd | 2012-12-08 07:07:54 | [diff] [blame] | 391 | return shared_->warning_service(); |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 392 | } |
| 393 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 394 | Blacklist* ExtensionSystemImpl::blacklist() { |
| 395 | return shared_->blacklist(); |
| 396 | } |
| 397 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 398 | const OneShotEvent& ExtensionSystemImpl::ready() const { |
| 399 | return shared_->ready(); |
| 400 | } |
| 401 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 402 | ErrorConsole* ExtensionSystemImpl::error_console() { |
| 403 | return shared_->error_console(); |
| 404 | } |
| 405 | |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 406 | InstallVerifier* ExtensionSystemImpl::install_verifier() { |
| 407 | return shared_->install_verifier(); |
| 408 | } |
| 409 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 410 | void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 411 | const Extension* extension) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 412 | base::Time install_time; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 413 | if (extension->location() != Manifest::COMPONENT) { |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 414 | install_time = ExtensionPrefs::Get(profile_)-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 415 | GetInstallTime(extension->id()); |
| 416 | } |
| 417 | bool incognito_enabled = |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 418 | extension_util::IsIncognitoEnabled(extension->id(), extension_service()); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 419 | |
| 420 | bool notifications_disabled = false; |
| 421 | #if defined(ENABLE_NOTIFICATIONS) |
| 422 | message_center::NotifierId notifier_id( |
| 423 | message_center::NotifierId::APPLICATION, |
| 424 | extension->id()); |
| 425 | |
| 426 | DesktopNotificationService* notification_service = |
| 427 | DesktopNotificationServiceFactory::GetForProfile(profile_); |
| 428 | notifications_disabled = |
| 429 | !notification_service->IsNotifierEnabled(notifier_id); |
| 430 | #endif |
| 431 | |
| 432 | BrowserThread::PostTask( |
| 433 | BrowserThread::IO, FROM_HERE, |
| 434 | base::Bind(&InfoMap::AddExtension, info_map(), |
| 435 | make_scoped_refptr(extension), install_time, |
| 436 | incognito_enabled, notifications_disabled)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
| 440 | const std::string& extension_id, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 441 | const UnloadedExtensionInfo::Reason reason) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 442 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 443 | BrowserThread::IO, |
| 444 | FROM_HERE, |
| 445 | base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 446 | } |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 447 | |
| 448 | } // namespace extensions |