| 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 "apps/common/api/generated_api.h" | 7 #include "apps/common/api/generated_api.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| 11 #include "chrome/browser/app_mode/app_mode_utils.h" | 11 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/activity_log/activity_log.h" | 13 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 14 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" |
| 15 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" |
| 14 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" | 16 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" |
| 15 #include "chrome/browser/extensions/api/preference/preference_api.h" | 17 #include "chrome/browser/extensions/api/preference/preference_api.h" |
| 16 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" | 18 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" |
| 17 #include "chrome/browser/extensions/chrome_app_sorting.h" | 19 #include "chrome/browser/extensions/chrome_app_sorting.h" |
| 18 #include "chrome/browser/extensions/chrome_component_extension_resource_manager.
h" | 20 #include "chrome/browser/extensions/chrome_component_extension_resource_manager.
h" |
| 19 #include "chrome/browser/extensions/chrome_extension_host_delegate.h" | 21 #include "chrome/browser/extensions/chrome_extension_host_delegate.h" |
| 20 #include "chrome/browser/extensions/extension_system_factory.h" | 22 #include "chrome/browser/extensions/extension_system_factory.h" |
| 21 #include "chrome/browser/extensions/extension_util.h" | 23 #include "chrome/browser/extensions/extension_util.h" |
| 22 #include "chrome/browser/extensions/url_request_util.h" | 24 #include "chrome/browser/extensions/url_request_util.h" |
| 23 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 25 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
| 30 #include "chrome/common/extensions/api/generated_api.h" | 32 #include "chrome/common/extensions/api/generated_api.h" |
| 31 #include "chrome/common/extensions/features/feature_channel.h" | 33 #include "chrome/common/extensions/features/feature_channel.h" |
| 32 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 33 #include "extensions/browser/extension_function_registry.h" | 35 #include "extensions/browser/extension_function_registry.h" |
| 34 #include "extensions/browser/extension_prefs.h" | 36 #include "extensions/browser/extension_prefs.h" |
| 35 #include "extensions/browser/pref_names.h" | 37 #include "extensions/browser/pref_names.h" |
| 36 #include "extensions/common/api/generated_api.h" | 38 #include "extensions/common/api/generated_api.h" |
| 37 | 39 |
| 38 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 39 #include "chromeos/chromeos_switches.h" | 41 #include "chromeos/chromeos_switches.h" |
| 40 #endif | 42 #endif |
| 41 | 43 |
| 42 #if defined(ENABLE_EXTENSIONS) | |
| 43 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" | |
| 44 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" | |
| 45 #endif | |
| 46 | |
| 47 namespace extensions { | 44 namespace extensions { |
| 48 | 45 |
| 49 ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() { | 46 ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() { |
| 50 #if defined(ENABLE_EXTENSIONS) | |
| 51 api_client_.reset(new ChromeExtensionsAPIClient); | 47 api_client_.reset(new ChromeExtensionsAPIClient); |
| 52 #endif | |
| 53 // Only set if it hasn't already been set (e.g. by a test). | 48 // Only set if it hasn't already been set (e.g. by a test). |
| 54 if (GetCurrentChannel() == GetDefaultChannel()) | 49 if (GetCurrentChannel() == GetDefaultChannel()) |
| 55 SetCurrentChannel(chrome::VersionInfo::GetChannel()); | 50 SetCurrentChannel(chrome::VersionInfo::GetChannel()); |
| 56 } | 51 } |
| 57 | 52 |
| 58 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} | 53 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} |
| 59 | 54 |
| 60 bool ChromeExtensionsBrowserClient::IsShuttingDown() { | 55 bool ChromeExtensionsBrowserClient::IsShuttingDown() { |
| 61 return g_browser_process->IsShuttingDown(); | 56 return g_browser_process->IsShuttingDown(); |
| 62 } | 57 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 141 } |
| 147 | 142 |
| 148 PrefService* ChromeExtensionsBrowserClient::GetPrefServiceForContext( | 143 PrefService* ChromeExtensionsBrowserClient::GetPrefServiceForContext( |
| 149 content::BrowserContext* context) { | 144 content::BrowserContext* context) { |
| 150 return static_cast<Profile*>(context)->GetPrefs(); | 145 return static_cast<Profile*>(context)->GetPrefs(); |
| 151 } | 146 } |
| 152 | 147 |
| 153 void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( | 148 void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( |
| 154 content::BrowserContext* context, | 149 content::BrowserContext* context, |
| 155 std::vector<ExtensionPrefsObserver*>* observers) const { | 150 std::vector<ExtensionPrefsObserver*>* observers) const { |
| 156 #if defined(ENABLE_EXTENSIONS) | |
| 157 observers->push_back(ContentSettingsService::Get(context)); | 151 observers->push_back(ContentSettingsService::Get(context)); |
| 158 #endif | |
| 159 } | 152 } |
| 160 | 153 |
| 161 bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts( | 154 bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts( |
| 162 content::BrowserContext* context) const { | 155 content::BrowserContext* context) const { |
| 163 Profile* profile = static_cast<Profile*>(context); | 156 Profile* profile = static_cast<Profile*>(context); |
| 164 | 157 |
| 165 // The profile may not be valid yet if it is still being initialized. | 158 // 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. | 159 // In that case, defer loading, since it depends on an initialized profile. |
| 167 // http://crbug.com/222473 | 160 // http://crbug.com/222473 |
| 168 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | 161 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| 169 return true; | 162 return true; |
| 170 | 163 |
| 171 #if defined(OS_ANDROID) | |
| 172 return false; | |
| 173 #else | |
| 174 // There are no browser windows open and the browser process was | 164 // There are no browser windows open and the browser process was |
| 175 // started to show the app launcher. | 165 // started to show the app launcher. |
| 176 return chrome::GetTotalBrowserCountForProfile(profile) == 0 && | 166 return chrome::GetTotalBrowserCountForProfile(profile) == 0 && |
| 177 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList); | 167 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList); |
| 178 #endif | |
| 179 } | 168 } |
| 180 | 169 |
| 181 bool ChromeExtensionsBrowserClient::IsBackgroundPageAllowed( | 170 bool ChromeExtensionsBrowserClient::IsBackgroundPageAllowed( |
| 182 content::BrowserContext* context) const { | 171 content::BrowserContext* context) const { |
| 183 // Returns true if current session is Guest mode session and current | 172 // Returns true if current session is Guest mode session and current |
| 184 // browser context is *not* off-the-record. Such context is artificial and | 173 // browser context is *not* off-the-record. Such context is artificial and |
| 185 // background page shouldn't be created in it. | 174 // background page shouldn't be created in it. |
| 186 return !static_cast<Profile*>(context)->IsGuestSession() || | 175 return !static_cast<Profile*>(context)->IsGuestSession() || |
| 187 context->IsOffTheRecord(); | 176 context->IsOffTheRecord(); |
| 188 } | 177 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 return ActivityLog::GetInstance(context); | 228 return ActivityLog::GetInstance(context); |
| 240 } | 229 } |
| 241 | 230 |
| 242 ExtensionSystemProvider* | 231 ExtensionSystemProvider* |
| 243 ChromeExtensionsBrowserClient::GetExtensionSystemFactory() { | 232 ChromeExtensionsBrowserClient::GetExtensionSystemFactory() { |
| 244 return ExtensionSystemFactory::GetInstance(); | 233 return ExtensionSystemFactory::GetInstance(); |
| 245 } | 234 } |
| 246 | 235 |
| 247 void ChromeExtensionsBrowserClient::RegisterExtensionFunctions( | 236 void ChromeExtensionsBrowserClient::RegisterExtensionFunctions( |
| 248 ExtensionFunctionRegistry* registry) const { | 237 ExtensionFunctionRegistry* registry) const { |
| 249 // TODO(rockot): Figure out if and why Android really needs to build | |
| 250 // ChromeExtensionsBrowserClient and refactor so this ifdef isn't necessary. | |
| 251 // See http://crbug.com/349436 | |
| 252 #if defined(ENABLE_EXTENSIONS) | |
| 253 // Preferences. | 238 // Preferences. |
| 254 registry->RegisterFunction<extensions::GetPreferenceFunction>(); | 239 registry->RegisterFunction<extensions::GetPreferenceFunction>(); |
| 255 registry->RegisterFunction<extensions::SetPreferenceFunction>(); | 240 registry->RegisterFunction<extensions::SetPreferenceFunction>(); |
| 256 registry->RegisterFunction<extensions::ClearPreferenceFunction>(); | 241 registry->RegisterFunction<extensions::ClearPreferenceFunction>(); |
| 257 | 242 |
| 258 // Direct Preference Access for Component Extensions. | 243 // Direct Preference Access for Component Extensions. |
| 259 registry->RegisterFunction< | 244 registry->RegisterFunction< |
| 260 extensions::chromedirectsetting::GetDirectSettingFunction>(); | 245 extensions::chromedirectsetting::GetDirectSettingFunction>(); |
| 261 registry->RegisterFunction< | 246 registry->RegisterFunction< |
| 262 extensions::chromedirectsetting::SetDirectSettingFunction>(); | 247 extensions::chromedirectsetting::SetDirectSettingFunction>(); |
| 263 registry->RegisterFunction< | 248 registry->RegisterFunction< |
| 264 extensions::chromedirectsetting::ClearDirectSettingFunction>(); | 249 extensions::chromedirectsetting::ClearDirectSettingFunction>(); |
| 265 | 250 |
| 266 // Generated APIs from lower-level modules. | 251 // Generated APIs from lower-level modules. |
| 267 extensions::core_api::GeneratedFunctionRegistry::RegisterAll(registry); | 252 extensions::core_api::GeneratedFunctionRegistry::RegisterAll(registry); |
| 268 apps::api::GeneratedFunctionRegistry::RegisterAll(registry); | 253 apps::api::GeneratedFunctionRegistry::RegisterAll(registry); |
| 269 | 254 |
| 270 // Generated APIs from Chrome. | 255 // Generated APIs from Chrome. |
| 271 extensions::api::GeneratedFunctionRegistry::RegisterAll(registry); | 256 extensions::api::GeneratedFunctionRegistry::RegisterAll(registry); |
| 272 #endif | |
| 273 } | 257 } |
| 274 | 258 |
| 275 ComponentExtensionResourceManager* | 259 ComponentExtensionResourceManager* |
| 276 ChromeExtensionsBrowserClient::GetComponentExtensionResourceManager() { | 260 ChromeExtensionsBrowserClient::GetComponentExtensionResourceManager() { |
| 277 if (!resource_manager_) | 261 if (!resource_manager_) |
| 278 resource_manager_.reset(new ChromeComponentExtensionResourceManager()); | 262 resource_manager_.reset(new ChromeComponentExtensionResourceManager()); |
| 279 return resource_manager_.get(); | 263 return resource_manager_.get(); |
| 280 } | 264 } |
| 281 | 265 |
| 282 scoped_ptr<extensions::RuntimeAPIDelegate> | 266 scoped_ptr<extensions::RuntimeAPIDelegate> |
| 283 ChromeExtensionsBrowserClient::CreateRuntimeAPIDelegate( | 267 ChromeExtensionsBrowserClient::CreateRuntimeAPIDelegate( |
| 284 content::BrowserContext* context) const { | 268 content::BrowserContext* context) const { |
| 285 return scoped_ptr<extensions::RuntimeAPIDelegate>( | 269 return scoped_ptr<extensions::RuntimeAPIDelegate>( |
| 286 new ChromeRuntimeAPIDelegate(context)); | 270 new ChromeRuntimeAPIDelegate(context)); |
| 287 } | 271 } |
| 288 | 272 |
| 289 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |