Chromium Code Reviews| 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/version.h" | 10 #include "base/version.h" |
| 10 #include "chrome/browser/app_mode/app_mode_utils.h" | 11 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/activity_log/activity_log.h" | 13 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 13 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" | 14 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" |
| 14 #include "chrome/browser/extensions/api/preference/preference_api.h" | 15 #include "chrome/browser/extensions/api/preference/preference_api.h" |
| 15 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" | 16 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" |
| 16 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 17 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 17 #include "chrome/browser/extensions/chrome_app_sorting.h" | 18 #include "chrome/browser/extensions/chrome_app_sorting.h" |
| 18 #include "chrome/browser/extensions/chrome_extension_host_delegate.h" | 19 #include "chrome/browser/extensions/chrome_extension_host_delegate.h" |
| 19 #include "chrome/browser/extensions/extension_system_factory.h" | 20 #include "chrome/browser/extensions/extension_system_factory.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/extensions/url_request_util.h" | 22 #include "chrome/browser/extensions/url_request_util.h" |
| 22 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 23 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/common/chrome_paths.h" | |
| 26 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 29 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/api/generated_api.h" | 30 #include "chrome/common/extensions/api/generated_api.h" |
| 29 #include "chrome/common/extensions/features/feature_channel.h" | 31 #include "chrome/common/extensions/features/feature_channel.h" |
| 30 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 31 #include "extensions/browser/extension_function_registry.h" | 33 #include "extensions/browser/extension_function_registry.h" |
| 32 #include "extensions/browser/extension_prefs.h" | 34 #include "extensions/browser/extension_prefs.h" |
| 33 #include "extensions/browser/pref_names.h" | 35 #include "extensions/browser/pref_names.h" |
| 34 #include "extensions/common/api/generated_api.h" | 36 #include "extensions/common/api/generated_api.h" |
| 37 #include "grit/chrome_unscaled_resources.h" | |
| 38 #include "grit/component_extension_resources_map.h" | |
| 39 #include "grit/theme_resources.h" | |
| 35 | 40 |
| 36 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 37 #include "chromeos/chromeos_switches.h" | 42 #include "chromeos/chromeos_switches.h" |
| 43 #include "ui/file_manager/file_manager_resource_util.h" | |
| 38 #endif | 44 #endif |
| 39 | 45 |
| 40 #if defined(ENABLE_EXTENSIONS) | 46 #if defined(ENABLE_EXTENSIONS) |
| 41 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" | 47 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" |
| 42 #include "chrome/browser/extensions/api/content_settings/content_settings_servic e.h" | 48 #include "chrome/browser/extensions/api/content_settings/content_settings_servic e.h" |
| 43 #endif | 49 #endif |
| 44 | 50 |
| 51 #if defined(USE_AURA) | |
| 52 #include "ui/keyboard/keyboard_util.h" | |
| 53 #endif | |
| 54 | |
| 45 namespace extensions { | 55 namespace extensions { |
| 46 | 56 |
| 57 namespace { | |
| 58 | |
| 59 // Add the resources from |entries| (there are |size| of them) to | |
| 60 // |path_to_resource_id| after normalizing separators. | |
| 61 void AddComponentResourceEntries( | |
| 62 std::map<base::FilePath, int>* path_to_resource_id, | |
| 63 const GritResourceMap* entries, | |
| 64 size_t size) { | |
| 65 for (size_t i = 0; i < size; ++i) { | |
| 66 base::FilePath resource_path = base::FilePath().AppendASCII( | |
| 67 entries[i].name); | |
| 68 resource_path = resource_path.NormalizePathSeparators(); | |
| 69 | |
| 70 DCHECK(path_to_resource_id->find(resource_path) == | |
| 71 path_to_resource_id->end()); | |
| 72 (*path_to_resource_id)[resource_path] = entries[i].value; | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 47 ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() { | 78 ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() { |
| 48 #if defined(ENABLE_EXTENSIONS) | 79 #if defined(ENABLE_EXTENSIONS) |
| 49 api_client_.reset(new ChromeExtensionsAPIClient); | 80 api_client_.reset(new ChromeExtensionsAPIClient); |
| 50 #endif | 81 #endif |
| 51 // Only set if it hasn't already been set (e.g. by a test). | 82 // Only set if it hasn't already been set (e.g. by a test). |
| 52 if (GetCurrentChannel() == GetDefaultChannel()) | 83 if (GetCurrentChannel() == GetDefaultChannel()) |
| 53 SetCurrentChannel(chrome::VersionInfo::GetChannel()); | 84 SetCurrentChannel(chrome::VersionInfo::GetChannel()); |
| 85 | |
| 86 static const GritResourceMap kExtraComponentExtensionResources[] = { | |
|
James Cook
2014/06/18 16:29:07
I would prefer that all the ComponentExtensions co
Jun Mukai
2014/06/18 18:38:48
Done.
| |
| 87 {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON}, | |
| 88 {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16}, | |
| 89 {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128}, | |
| 90 {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16}, | |
| 91 #if defined(ENABLE_SETTINGS_APP) | |
| 92 {"settings_app/settings_app_icon_128.png", IDR_SETTINGS_APP_ICON_128}, | |
| 93 {"settings_app/settings_app_icon_16.png", IDR_SETTINGS_APP_ICON_16}, | |
| 94 {"settings_app/settings_app_icon_32.png", IDR_SETTINGS_APP_ICON_32}, | |
| 95 {"settings_app/settings_app_icon_48.png", IDR_SETTINGS_APP_ICON_48}, | |
| 96 #endif | |
| 97 }; | |
| 98 | |
| 99 AddComponentResourceEntries( | |
| 100 &path_to_resource_id_, | |
| 101 kComponentExtensionResources, | |
| 102 kComponentExtensionResourcesSize); | |
| 103 AddComponentResourceEntries( | |
| 104 &path_to_resource_id_, | |
| 105 kExtraComponentExtensionResources, | |
| 106 arraysize(kExtraComponentExtensionResources)); | |
| 107 #if defined(OS_CHROMEOS) | |
| 108 size_t file_manager_resource_size; | |
| 109 const GritResourceMap* file_manager_resources = | |
| 110 file_manager::GetFileManagerResources(&file_manager_resource_size); | |
| 111 AddComponentResourceEntries( | |
| 112 &path_to_resource_id_, | |
| 113 file_manager_resources, | |
| 114 file_manager_resource_size); | |
| 115 | |
| 116 size_t keyboard_resource_size; | |
| 117 const GritResourceMap* keyboard_resources = | |
| 118 keyboard::GetKeyboardExtensionResources(&keyboard_resource_size); | |
| 119 AddComponentResourceEntries( | |
| 120 &path_to_resource_id_, | |
| 121 keyboard_resources, | |
| 122 keyboard_resource_size); | |
| 123 #endif | |
| 54 } | 124 } |
| 55 | 125 |
| 56 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} | 126 ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} |
| 57 | 127 |
| 58 bool ChromeExtensionsBrowserClient::IsShuttingDown() { | 128 bool ChromeExtensionsBrowserClient::IsShuttingDown() { |
| 59 return g_browser_process->IsShuttingDown(); | 129 return g_browser_process->IsShuttingDown(); |
| 60 } | 130 } |
| 61 | 131 |
| 62 bool ChromeExtensionsBrowserClient::AreExtensionsDisabled( | 132 bool ChromeExtensionsBrowserClient::AreExtensionsDisabled( |
| 63 const CommandLine& command_line, | 133 const CommandLine& command_line, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 333 |
| 264 // Generated APIs from lower-level modules. | 334 // Generated APIs from lower-level modules. |
| 265 extensions::core_api::GeneratedFunctionRegistry::RegisterAll(registry); | 335 extensions::core_api::GeneratedFunctionRegistry::RegisterAll(registry); |
| 266 apps::api::GeneratedFunctionRegistry::RegisterAll(registry); | 336 apps::api::GeneratedFunctionRegistry::RegisterAll(registry); |
| 267 | 337 |
| 268 // Generated APIs from Chrome. | 338 // Generated APIs from Chrome. |
| 269 extensions::api::GeneratedFunctionRegistry::RegisterAll(registry); | 339 extensions::api::GeneratedFunctionRegistry::RegisterAll(registry); |
| 270 #endif | 340 #endif |
| 271 } | 341 } |
| 272 | 342 |
| 343 bool ChromeExtensionsBrowserClient::IsComponentExtensionResource( | |
| 344 const base::FilePath& extension_path, | |
| 345 const base::FilePath& resource_path, | |
| 346 int* resource_id) const { | |
| 347 base::FilePath directory_path = extension_path; | |
| 348 base::FilePath resources_dir; | |
| 349 base::FilePath relative_path; | |
| 350 if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || | |
| 351 !resources_dir.AppendRelativePath(directory_path, &relative_path)) { | |
| 352 return false; | |
| 353 } | |
| 354 relative_path = relative_path.Append(resource_path); | |
| 355 relative_path = relative_path.NormalizePathSeparators(); | |
| 356 | |
| 357 std::map<base::FilePath, int>::const_iterator entry = | |
| 358 path_to_resource_id_.find(relative_path); | |
| 359 if (entry != path_to_resource_id_.end()) | |
| 360 *resource_id = entry->second; | |
| 361 | |
| 362 return entry != path_to_resource_id_.end(); | |
| 363 } | |
| 364 | |
| 273 scoped_ptr<extensions::RuntimeAPIDelegate> | 365 scoped_ptr<extensions::RuntimeAPIDelegate> |
| 274 ChromeExtensionsBrowserClient::CreateRuntimeAPIDelegate( | 366 ChromeExtensionsBrowserClient::CreateRuntimeAPIDelegate( |
| 275 content::BrowserContext* context) const { | 367 content::BrowserContext* context) const { |
| 276 return scoped_ptr<extensions::RuntimeAPIDelegate>( | 368 return scoped_ptr<extensions::RuntimeAPIDelegate>( |
| 277 new ChromeRuntimeAPIDelegate(context)); | 369 new ChromeRuntimeAPIDelegate(context)); |
| 278 } | 370 } |
| 279 | 371 |
| 280 } // namespace extensions | 372 } // namespace extensions |
| OLD | NEW |