Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "chrome/browser/extensions/crx_installer.h" | 38 #include "chrome/browser/extensions/crx_installer.h" |
| 39 #include "chrome/browser/extensions/default_apps_trial.h" | 39 #include "chrome/browser/extensions/default_apps_trial.h" |
| 40 #include "chrome/browser/extensions/extension_browser_event_router.h" | 40 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 41 #include "chrome/browser/extensions/extension_cookies_api.h" | 41 #include "chrome/browser/extensions/extension_cookies_api.h" |
| 42 #include "chrome/browser/extensions/extension_data_deleter.h" | 42 #include "chrome/browser/extensions/extension_data_deleter.h" |
| 43 #include "chrome/browser/extensions/extension_error_reporter.h" | 43 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 44 #include "chrome/browser/extensions/extension_global_error.h" | 44 #include "chrome/browser/extensions/extension_global_error.h" |
| 45 #include "chrome/browser/extensions/extension_host.h" | 45 #include "chrome/browser/extensions/extension_host.h" |
| 46 #include "chrome/browser/extensions/extension_input_ime_api.h" | 46 #include "chrome/browser/extensions/extension_input_ime_api.h" |
| 47 #include "chrome/browser/extensions/extension_management_api.h" | 47 #include "chrome/browser/extensions/extension_management_api.h" |
| 48 #include "chrome/browser/extensions/extension_pref_value_map.h" | |
| 48 #include "chrome/browser/extensions/extension_preference_api.h" | 49 #include "chrome/browser/extensions/extension_preference_api.h" |
| 49 #include "chrome/browser/extensions/extension_process_manager.h" | 50 #include "chrome/browser/extensions/extension_process_manager.h" |
| 50 #include "chrome/browser/extensions/extension_processes_api.h" | 51 #include "chrome/browser/extensions/extension_processes_api.h" |
| 51 #include "chrome/browser/extensions/extension_sorting.h" | 52 #include "chrome/browser/extensions/extension_sorting.h" |
| 52 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 53 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 53 #include "chrome/browser/extensions/extension_sync_data.h" | 54 #include "chrome/browser/extensions/extension_sync_data.h" |
| 54 #include "chrome/browser/extensions/extension_updater.h" | 55 #include "chrome/browser/extensions/extension_updater.h" |
| 55 #include "chrome/browser/extensions/extension_web_ui.h" | 56 #include "chrome/browser/extensions/extension_web_ui.h" |
| 56 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 57 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 57 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 58 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 74 #include "chrome/browser/ui/browser.h" | 75 #include "chrome/browser/ui/browser.h" |
| 75 #include "chrome/browser/ui/browser_list.h" | 76 #include "chrome/browser/ui/browser_list.h" |
| 76 #include "chrome/browser/ui/global_error_service.h" | 77 #include "chrome/browser/ui/global_error_service.h" |
| 77 #include "chrome/browser/ui/global_error_service_factory.h" | 78 #include "chrome/browser/ui/global_error_service_factory.h" |
| 78 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 79 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 79 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 80 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 80 #include "chrome/browser/ui/webui/favicon_source.h" | 81 #include "chrome/browser/ui/webui/favicon_source.h" |
| 81 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 82 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 82 #include "chrome/browser/web_applications/web_app.h" | 83 #include "chrome/browser/web_applications/web_app.h" |
| 83 #include "chrome/common/child_process_logging.h" | 84 #include "chrome/common/child_process_logging.h" |
| 85 #include "chrome/common/chrome_constants.h" | |
| 84 #include "chrome/common/chrome_notification_types.h" | 86 #include "chrome/common/chrome_notification_types.h" |
| 85 #include "chrome/common/chrome_paths.h" | 87 #include "chrome/common/chrome_paths.h" |
| 86 #include "chrome/common/chrome_switches.h" | 88 #include "chrome/common/chrome_switches.h" |
| 87 #include "chrome/common/extensions/extension.h" | 89 #include "chrome/common/extensions/extension.h" |
| 88 #include "chrome/common/extensions/extension_constants.h" | 90 #include "chrome/common/extensions/extension_constants.h" |
| 89 #include "chrome/common/extensions/extension_error_utils.h" | 91 #include "chrome/common/extensions/extension_error_utils.h" |
| 90 #include "chrome/common/extensions/extension_file_util.h" | 92 #include "chrome/common/extensions/extension_file_util.h" |
| 91 #include "chrome/common/extensions/extension_messages.h" | 93 #include "chrome/common/extensions/extension_messages.h" |
| 92 #include "chrome/common/extensions/extension_resource.h" | 94 #include "chrome/common/extensions/extension_resource.h" |
| 93 #include "chrome/common/pref_names.h" | 95 #include "chrome/common/pref_names.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 static bool IsSyncableExtension(const Extension& extension) { | 149 static bool IsSyncableExtension(const Extension& extension) { |
| 148 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION; | 150 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION; |
| 149 } | 151 } |
| 150 | 152 |
| 151 static bool IsSyncableApp(const Extension& extension) { | 153 static bool IsSyncableApp(const Extension& extension) { |
| 152 return extension.GetSyncType() == Extension::SYNC_TYPE_APP; | 154 return extension.GetSyncType() == Extension::SYNC_TYPE_APP; |
| 153 } | 155 } |
| 154 | 156 |
| 155 } // namespace | 157 } // namespace |
| 156 | 158 |
| 159 // static | |
| 160 bool ExtensionService::PlatformAppRequiresSeparateDataDirectory() { | |
| 161 #if defined(OS_MACOSX) | |
| 162 return true; | |
| 163 #else | |
| 164 return false; | |
|
Robert Sesek
2012/02/09 18:43:59
Leave a TODO here.
sail
2012/02/10 00:13:18
I'm not sure what the plans are for other platform
| |
| 165 #endif | |
| 166 } | |
| 167 | |
| 157 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() | 168 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
| 158 : background_page_ready(false), | 169 : background_page_ready(false), |
| 159 being_upgraded(false), | 170 being_upgraded(false), |
| 160 has_used_webrequest(false) { | 171 has_used_webrequest(false) { |
| 161 } | 172 } |
| 162 | 173 |
| 163 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { | 174 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
| 164 } | 175 } |
| 165 | 176 |
| 166 ExtensionService::NaClModuleInfo::NaClModuleInfo() { | 177 ExtensionService::NaClModuleInfo::NaClModuleInfo() { |
| (...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2221 } | 2232 } |
| 2222 | 2233 |
| 2223 // Do not record the install histograms for upgrades. | 2234 // Do not record the install histograms for upgrades. |
| 2224 if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { | 2235 if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { |
| 2225 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 2236 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 2226 extension->GetType(), 100); | 2237 extension->GetType(), 100); |
| 2227 RecordPermissionMessagesHistogram( | 2238 RecordPermissionMessagesHistogram( |
| 2228 extension, "Extensions.Permissions_Install"); | 2239 extension, "Extensions.Permissions_Install"); |
| 2229 } | 2240 } |
| 2230 | 2241 |
| 2231 extension_prefs_->OnExtensionInstalled( | 2242 SetupExtensionPrefs( |
| 2232 extension, | 2243 extension_prefs_, extension, from_webstore, page_ordinal, initial_enable); |
| 2233 initial_enable ? Extension::ENABLED : Extension::DISABLED, | 2244 if (initial_enable && PlatformAppRequiresSeparateDataDirectory()) { |
| 2234 from_webstore, | 2245 SetupExtensionPrefsInSeparateDataDirectory( |
| 2235 page_ordinal); | 2246 extension, from_webstore, page_ordinal); |
| 2236 | |
| 2237 // Unpacked extensions default to allowing file access, but if that has been | |
| 2238 // overridden, don't reset the value. | |
| 2239 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && | |
| 2240 !extension_prefs_->HasAllowFileAccessSetting(id)) { | |
| 2241 extension_prefs_->SetAllowFileAccess(id, true); | |
| 2242 } | 2247 } |
| 2243 | 2248 |
| 2244 // If the extension should automatically block network startup (e.g., it uses | |
| 2245 // the webRequest API), set the preference. Otherwise clear it, in case the | |
| 2246 // extension stopped using a relevant API. | |
| 2247 extension_prefs_->SetDelaysNetworkRequests( | |
| 2248 extension->id(), extension->ImplicitlyDelaysNetworkStartup()); | |
| 2249 | |
| 2250 content::NotificationService::current()->Notify( | 2249 content::NotificationService::current()->Notify( |
| 2251 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 2250 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 2252 content::Source<Profile>(profile_), | 2251 content::Source<Profile>(profile_), |
| 2253 content::Details<const Extension>(extension)); | 2252 content::Details<const Extension>(extension)); |
| 2254 | 2253 |
| 2255 // Temporary feature to always install shortcuts for platform apps to | 2254 // Temporary feature to always install shortcuts for platform apps to |
| 2256 // facilitate early testing. | 2255 // facilitate early testing. |
| 2257 // TODO(benwells): Remove before launching platform apps. | 2256 // TODO(benwells): Remove before launching platform apps. |
| 2258 if (extension->is_platform_app()) { | 2257 if (extension->is_platform_app()) { |
| 2259 StartInstallApplicationShortcut(extension); | 2258 StartInstallApplicationShortcut(extension); |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2700 // | 2699 // |
| 2701 // To coexist with certain unit tests that don't have an IO thread message | 2700 // To coexist with certain unit tests that don't have an IO thread message |
| 2702 // loop available at ExtensionService shutdown, we lazy-initialize this | 2701 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2703 // object so that those cases neither create nor destroy a SocketController. | 2702 // object so that those cases neither create nor destroy a SocketController. |
| 2704 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2703 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2705 if (!socket_controller_) { | 2704 if (!socket_controller_) { |
| 2706 socket_controller_ = new extensions::SocketController(); | 2705 socket_controller_ = new extensions::SocketController(); |
| 2707 } | 2706 } |
| 2708 return socket_controller_; | 2707 return socket_controller_; |
| 2709 } | 2708 } |
| 2709 | |
| 2710 void ExtensionService::SetupExtensionPrefs(ExtensionPrefs* prefs, | |
| 2711 const Extension* extension, | |
| 2712 bool from_webstore, | |
| 2713 const StringOrdinal& page_ordinal, | |
| 2714 bool initial_enable) { | |
| 2715 const std::string& id = extension->id(); | |
| 2716 prefs->OnExtensionInstalled( | |
| 2717 extension, | |
| 2718 initial_enable ? Extension::ENABLED : Extension::DISABLED, | |
| 2719 from_webstore, | |
| 2720 page_ordinal); | |
| 2721 | |
| 2722 // Unpacked extensions default to allowing file access, but if that has been | |
| 2723 // overridden, don't reset the value. | |
| 2724 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && | |
| 2725 !prefs->HasAllowFileAccessSetting(id)) { | |
| 2726 prefs->SetAllowFileAccess(id, true); | |
| 2727 } | |
| 2728 | |
| 2729 // If the extension should automatically block network startup (e.g., it uses | |
| 2730 // the webRequest API), set the preference. Otherwise clear it, in case the | |
| 2731 // extension stopped using a relevant API. | |
| 2732 prefs->SetDelaysNetworkRequests( | |
| 2733 id, extension->ImplicitlyDelaysNetworkStartup()); | |
| 2734 } | |
| 2735 | |
| 2736 void ExtensionService::SetupExtensionPrefsInSeparateDataDirectory( | |
| 2737 const Extension* extension, | |
| 2738 bool from_webstore, | |
| 2739 const StringOrdinal& page_ordinal) { | |
| 2740 const std::string& id = extension->id(); | |
| 2741 FilePath data_dir = web_app::GetWebAppDataDirectory( | |
| 2742 profile_->GetPath(), id, GURL(extension->launch_web_url())); | |
| 2743 FilePath profile_path = data_dir.AppendASCII(chrome::kInitialProfile); | |
| 2744 FilePath pref_path = profile_path.Append(chrome::kPreferencesFilename); | |
| 2745 scoped_ptr<PrefService> prefs_service(PrefService::CreatePrefService( | |
| 2746 pref_path, NULL, false)); | |
| 2747 | |
| 2748 ExtensionPrefValueMap map; | |
| 2749 ExtensionPrefs::RegisterUserPrefs(prefs_service.get()); | |
| 2750 ExtensionPrefs extension_prefs(prefs_service.get(), install_directory_, &map); | |
| 2751 extension_prefs.Init(false); | |
| 2752 | |
| 2753 SetupExtensionPrefs( | |
| 2754 &extension_prefs, extension, from_webstore, page_ordinal, true); | |
| 2755 extension_prefs.AddGrantedPermissions(id, extension->GetActivePermissions()); | |
| 2756 extension_prefs.SetExtensionState(id, Extension::ENABLED); | |
| 2757 | |
| 2758 prefs_service->CommitPendingWrite(); | |
| 2759 } | |
| OLD | NEW |