| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/chrome_extensions_browser_client.h" | 5 #include "chrome/browser/extensions/chrome_extensions_browser_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/version.h" | 9 #include "base/version.h" |
| 10 #include "chrome/browser/app_mode/app_mode_utils.h" | 10 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" | 12 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" |
| 13 #include "chrome/browser/extensions/api/preference/preference_api.h" | 13 #include "chrome/browser/extensions/api/preference/preference_api.h" |
| 14 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" | 14 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" |
| 15 #include "chrome/browser/extensions/chrome_app_sorting.h" | 15 #include "chrome/browser/extensions/chrome_app_sorting.h" |
| 16 #include "chrome/browser/extensions/chrome_component_extension_resource_manager.
h" | 16 #include "chrome/browser/extensions/chrome_component_extension_resource_manager.
h" |
| 17 #include "chrome/browser/extensions/chrome_extension_host_delegate.h" | 17 #include "chrome/browser/extensions/chrome_extension_host_delegate.h" |
| 18 #include "chrome/browser/extensions/extension_system_factory.h" | 18 #include "chrome/browser/extensions/extension_system_factory.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
| 20 #include "chrome/browser/extensions/url_request_util.h" | 20 #include "chrome/browser/extensions/url_request_util.h" |
| 21 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 21 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | |
| 25 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/api/generated_api.h" | 27 #include "chrome/common/extensions/api/generated_api.h" |
| 29 #include "chrome/common/extensions/features/feature_channel.h" | 28 #include "chrome/common/extensions/features/feature_channel.h" |
| 30 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 31 #include "extensions/browser/extension_function_registry.h" | 30 #include "extensions/browser/extension_function_registry.h" |
| 32 #include "extensions/browser/extension_prefs.h" | 31 #include "extensions/browser/extension_prefs.h" |
| 33 #include "extensions/browser/pref_names.h" | 32 #include "extensions/browser/pref_names.h" |
| 34 #include "extensions/common/api/generated_api.h" | 33 #include "extensions/common/api/generated_api.h" |
| 35 | 34 |
| 36 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 37 #include "chromeos/chromeos_switches.h" | 36 #include "chromeos/chromeos_switches.h" |
| 38 #endif | 37 #endif |
| 39 | 38 |
| 40 // TODO(thestig): Remove this when extensions are fully removed on mobile. | 39 // TODO(thestig): Remove this when extensions are fully removed on mobile. |
| 41 #if defined(ENABLE_EXTENSIONS) | 40 #if defined(ENABLE_EXTENSIONS) |
| 42 #include "chrome/browser/extensions/activity_log/activity_log.h" | 41 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 43 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" | 42 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" |
| 44 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" | 43 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" |
| 44 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 namespace extensions { | 47 namespace extensions { |
| 48 | 48 |
| 49 ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() { | 49 ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() { |
| 50 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
| 51 process_manager_delegate_.reset(new ChromeProcessManagerDelegate); |
| 51 api_client_.reset(new ChromeExtensionsAPIClient); | 52 api_client_.reset(new ChromeExtensionsAPIClient); |
| 52 #endif | 53 #endif |
| 53 // Only set if it hasn't already been set (e.g. by a test). | 54 // Only set if it hasn't already been set (e.g. by a test). |
| 54 if (GetCurrentChannel() == GetDefaultChannel()) | 55 if (GetCurrentChannel() == GetDefaultChannel()) |
| 55 SetCurrentChannel(chrome::VersionInfo::GetChannel()); | 56 SetCurrentChannel(chrome::VersionInfo::GetChannel()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} | 59 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} |
| 59 | 60 |
| 60 bool ChromeExtensionsBrowserClient::IsShuttingDown() { | 61 bool ChromeExtensionsBrowserClient::IsShuttingDown() { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 152 } |
| 152 | 153 |
| 153 void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( | 154 void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( |
| 154 content::BrowserContext* context, | 155 content::BrowserContext* context, |
| 155 std::vector<ExtensionPrefsObserver*>* observers) const { | 156 std::vector<ExtensionPrefsObserver*>* observers) const { |
| 156 #if defined(ENABLE_EXTENSIONS) | 157 #if defined(ENABLE_EXTENSIONS) |
| 157 observers->push_back(ContentSettingsService::Get(context)); | 158 observers->push_back(ContentSettingsService::Get(context)); |
| 158 #endif | 159 #endif |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts( | 162 ProcessManagerDelegate* |
| 162 content::BrowserContext* context) const { | 163 ChromeExtensionsBrowserClient::GetProcessManagerDelegate() const { |
| 163 Profile* profile = static_cast<Profile*>(context); | 164 #if defined(ENABLE_EXTENSIONS) |
| 164 | 165 return process_manager_delegate_.get(); |
| 165 // The profile may not be valid yet if it is still being initialized. | |
| 166 // In that case, defer loading, since it depends on an initialized profile. | |
| 167 // http://crbug.com/222473 | |
| 168 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
| 169 return true; | |
| 170 | |
| 171 #if defined(OS_ANDROID) | |
| 172 return false; | |
| 173 #else | 166 #else |
| 174 // There are no browser windows open and the browser process was | 167 return NULL; |
| 175 // started to show the app launcher. | |
| 176 return chrome::GetTotalBrowserCountForProfile(profile) == 0 && | |
| 177 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList); | |
| 178 #endif | 168 #endif |
| 179 } | 169 } |
| 180 | 170 |
| 181 bool ChromeExtensionsBrowserClient::IsBackgroundPageAllowed( | |
| 182 content::BrowserContext* context) const { | |
| 183 // Returns true if current session is Guest mode session and current | |
| 184 // browser context is *not* off-the-record. Such context is artificial and | |
| 185 // background page shouldn't be created in it. | |
| 186 return !static_cast<Profile*>(context)->IsGuestSession() || | |
| 187 context->IsOffTheRecord(); | |
| 188 } | |
| 189 | |
| 190 scoped_ptr<ExtensionHostDelegate> | 171 scoped_ptr<ExtensionHostDelegate> |
| 191 ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() { | 172 ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() { |
| 192 return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate); | 173 return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate); |
| 193 } | 174 } |
| 194 | 175 |
| 195 bool ChromeExtensionsBrowserClient::DidVersionUpdate( | 176 bool ChromeExtensionsBrowserClient::DidVersionUpdate( |
| 196 content::BrowserContext* context) { | 177 content::BrowserContext* context) { |
| 197 Profile* profile = static_cast<Profile*>(context); | 178 Profile* profile = static_cast<Profile*>(context); |
| 198 | 179 |
| 199 // Unit tests may not provide prefs; assume everything is up-to-date. | 180 // Unit tests may not provide prefs; assume everything is up-to-date. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 content::BrowserContext* context) const { | 268 content::BrowserContext* context) const { |
| 288 #if defined(ENABLE_EXTENSIONS) | 269 #if defined(ENABLE_EXTENSIONS) |
| 289 return scoped_ptr<extensions::RuntimeAPIDelegate>( | 270 return scoped_ptr<extensions::RuntimeAPIDelegate>( |
| 290 new ChromeRuntimeAPIDelegate(context)); | 271 new ChromeRuntimeAPIDelegate(context)); |
| 291 #else | 272 #else |
| 292 return scoped_ptr<extensions::RuntimeAPIDelegate>(); | 273 return scoped_ptr<extensions::RuntimeAPIDelegate>(); |
| 293 #endif | 274 #endif |
| 294 } | 275 } |
| 295 | 276 |
| 296 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |