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