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" |
24 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
27 #include "chrome/common/extensions/api/generated_api.h" | 28 #include "chrome/common/extensions/api/generated_api.h" |
28 #include "chrome/common/extensions/features/feature_channel.h" | 29 #include "chrome/common/extensions/features/feature_channel.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "extensions/browser/extension_function_registry.h" | 31 #include "extensions/browser/extension_function_registry.h" |
31 #include "extensions/browser/extension_prefs.h" | 32 #include "extensions/browser/extension_prefs.h" |
32 #include "extensions/browser/pref_names.h" | 33 #include "extensions/browser/pref_names.h" |
33 #include "extensions/common/api/generated_api.h" | 34 #include "extensions/common/api/generated_api.h" |
34 | 35 |
35 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
36 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
37 #endif | 38 #endif |
38 | 39 |
39 // TODO(thestig): Remove this when extensions are fully removed on mobile. | 40 // TODO(thestig): Remove this when extensions are fully removed on mobile. |
40 #if defined(ENABLE_EXTENSIONS) | 41 #if defined(ENABLE_EXTENSIONS) |
41 #include "chrome/browser/extensions/activity_log/activity_log.h" | 42 #include "chrome/browser/extensions/activity_log/activity_log.h" |
42 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" | 43 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" |
43 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" | 44 #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); | |
52 api_client_.reset(new ChromeExtensionsAPIClient); | 51 api_client_.reset(new ChromeExtensionsAPIClient); |
53 #endif | 52 #endif |
54 // Only set if it hasn't already been set (e.g. by a test). | 53 // Only set if it hasn't already been set (e.g. by a test). |
55 if (GetCurrentChannel() == GetDefaultChannel()) | 54 if (GetCurrentChannel() == GetDefaultChannel()) |
56 SetCurrentChannel(chrome::VersionInfo::GetChannel()); | 55 SetCurrentChannel(chrome::VersionInfo::GetChannel()); |
57 } | 56 } |
58 | 57 |
59 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} | 58 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} |
60 | 59 |
61 bool ChromeExtensionsBrowserClient::IsShuttingDown() { | 60 bool ChromeExtensionsBrowserClient::IsShuttingDown() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 151 } |
153 | 152 |
154 void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( | 153 void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( |
155 content::BrowserContext* context, | 154 content::BrowserContext* context, |
156 std::vector<ExtensionPrefsObserver*>* observers) const { | 155 std::vector<ExtensionPrefsObserver*>* observers) const { |
157 #if defined(ENABLE_EXTENSIONS) | 156 #if defined(ENABLE_EXTENSIONS) |
158 observers->push_back(ContentSettingsService::Get(context)); | 157 observers->push_back(ContentSettingsService::Get(context)); |
159 #endif | 158 #endif |
160 } | 159 } |
161 | 160 |
162 ProcessManagerDelegate* | 161 bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts( |
163 ChromeExtensionsBrowserClient::GetProcessManagerDelegate() const { | 162 content::BrowserContext* context) const { |
164 #if defined(ENABLE_EXTENSIONS) | 163 Profile* profile = static_cast<Profile*>(context); |
165 return process_manager_delegate_.get(); | 164 |
| 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; |
166 #else | 173 #else |
167 return NULL; | 174 // There are no browser windows open and the browser process was |
| 175 // started to show the app launcher. |
| 176 return chrome::GetTotalBrowserCountForProfile(profile) == 0 && |
| 177 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList); |
168 #endif | 178 #endif |
169 } | 179 } |
170 | 180 |
| 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 |
171 scoped_ptr<ExtensionHostDelegate> | 190 scoped_ptr<ExtensionHostDelegate> |
172 ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() { | 191 ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() { |
173 return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate); | 192 return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate); |
174 } | 193 } |
175 | 194 |
176 bool ChromeExtensionsBrowserClient::DidVersionUpdate( | 195 bool ChromeExtensionsBrowserClient::DidVersionUpdate( |
177 content::BrowserContext* context) { | 196 content::BrowserContext* context) { |
178 Profile* profile = static_cast<Profile*>(context); | 197 Profile* profile = static_cast<Profile*>(context); |
179 | 198 |
180 // Unit tests may not provide prefs; assume everything is up-to-date. | 199 // 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... |
268 content::BrowserContext* context) const { | 287 content::BrowserContext* context) const { |
269 #if defined(ENABLE_EXTENSIONS) | 288 #if defined(ENABLE_EXTENSIONS) |
270 return scoped_ptr<extensions::RuntimeAPIDelegate>( | 289 return scoped_ptr<extensions::RuntimeAPIDelegate>( |
271 new ChromeRuntimeAPIDelegate(context)); | 290 new ChromeRuntimeAPIDelegate(context)); |
272 #else | 291 #else |
273 return scoped_ptr<extensions::RuntimeAPIDelegate>(); | 292 return scoped_ptr<extensions::RuntimeAPIDelegate>(); |
274 #endif | 293 #endif |
275 } | 294 } |
276 | 295 |
277 } // namespace extensions | 296 } // namespace extensions |
OLD | NEW |