Chromium Code Reviews| Index: chrome/browser/extensions/extension_service.cc |
| diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc |
| index 9d6d90f55e8cd6b8f415da72ac43bfcd6bcb59a1..e7f0e17b3ecfbe926b6a18d38fbe0b8e64d7bcd5 100644 |
| --- a/chrome/browser/extensions/extension_service.cc |
| +++ b/chrome/browser/extensions/extension_service.cc |
| @@ -45,6 +45,7 @@ |
| #include "chrome/browser/extensions/extension_host.h" |
| #include "chrome/browser/extensions/extension_input_ime_api.h" |
| #include "chrome/browser/extensions/extension_management_api.h" |
| +#include "chrome/browser/extensions/extension_pref_value_map.h" |
| #include "chrome/browser/extensions/extension_preference_api.h" |
| #include "chrome/browser/extensions/extension_process_manager.h" |
| #include "chrome/browser/extensions/extension_processes_api.h" |
| @@ -78,7 +79,9 @@ |
| #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| #include "chrome/browser/ui/webui/favicon_source.h" |
| #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| +#include "chrome/browser/web_applications/web_app.h" |
| #include "chrome/common/child_process_logging.h" |
| +#include "chrome/common/chrome_constants.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -151,6 +154,16 @@ static bool IsSyncableApp(const Extension& extension) { |
| } // namespace |
| +// static |
| +bool ExtensionService::PlatformAppRequiresSeparateDataDirectory() { |
|
Aaron Boodman
2012/02/10 20:09:46
I think this would make more sense as a member of
sail
2012/02/11 23:15:11
Done.
|
| + // Currently separate data directories are only supported on Mac OSX. |
| +#if defined(OS_MACOSX) |
| + return true; |
| +#else |
| + return false; |
| +#endif |
| +} |
| + |
| ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
| : background_page_ready(false), |
| being_upgraded(false), |
| @@ -2225,25 +2238,13 @@ void ExtensionService::OnExtensionInstalled( |
| extension, "Extensions.Permissions_Install"); |
| } |
| - extension_prefs_->OnExtensionInstalled( |
| - extension, |
| - initial_enable ? Extension::ENABLED : Extension::DISABLED, |
| - from_webstore, |
| - page_ordinal); |
| - |
| - // Unpacked extensions default to allowing file access, but if that has been |
| - // overridden, don't reset the value. |
|
Aaron Boodman
2012/02/10 20:09:46
Seems like these could also be moved into Extensio
sail
2012/02/11 23:15:11
Done.
|
| - if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && |
| - !extension_prefs_->HasAllowFileAccessSetting(id)) { |
| - extension_prefs_->SetAllowFileAccess(id, true); |
| + SetupExtensionPrefs( |
| + extension_prefs_, extension, from_webstore, page_ordinal, initial_enable); |
| + if (initial_enable && PlatformAppRequiresSeparateDataDirectory()) { |
| + SetupExtensionPrefsInSeparateDataDirectory( |
| + extension, from_webstore, page_ordinal); |
| } |
| - // If the extension should automatically block network startup (e.g., it uses |
| - // the webRequest API), set the preference. Otherwise clear it, in case the |
| - // extension stopped using a relevant API. |
| - extension_prefs_->SetDelaysNetworkRequests( |
| - extension->id(), extension->ImplicitlyDelaysNetworkStartup()); |
| - |
| content::NotificationService::current()->Notify( |
| chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| content::Source<Profile>(profile_), |
| @@ -2636,3 +2637,54 @@ extensions::SocketController* ExtensionService::socket_controller() { |
| } |
| return socket_controller_; |
| } |
| + |
| +void ExtensionService::SetupExtensionPrefs(ExtensionPrefs* prefs, |
| + const Extension* extension, |
| + bool from_webstore, |
| + const StringOrdinal& page_ordinal, |
| + bool initial_enable) { |
| + const std::string& id = extension->id(); |
| + prefs->OnExtensionInstalled( |
| + extension, |
| + initial_enable ? Extension::ENABLED : Extension::DISABLED, |
| + from_webstore, |
| + page_ordinal); |
| + |
| + // Unpacked extensions default to allowing file access, but if that has been |
| + // overridden, don't reset the value. |
| + if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && |
| + !prefs->HasAllowFileAccessSetting(id)) { |
| + prefs->SetAllowFileAccess(id, true); |
| + } |
| + |
| + // If the extension should automatically block network startup (e.g., it uses |
| + // the webRequest API), set the preference. Otherwise clear it, in case the |
| + // extension stopped using a relevant API. |
| + prefs->SetDelaysNetworkRequests( |
| + id, extension->ImplicitlyDelaysNetworkStartup()); |
| +} |
| + |
| +void ExtensionService::SetupExtensionPrefsInSeparateDataDirectory( |
| + const Extension* extension, |
| + bool from_webstore, |
| + const StringOrdinal& page_ordinal) { |
| + const std::string& id = extension->id(); |
| + FilePath data_dir = web_app::GetWebAppDataDirectory( |
|
Aaron Boodman
2012/02/10 20:09:46
These few lines of code shows up in a couple place
sail
2012/02/11 23:15:11
This would involve moving several functions from w
|
| + profile_->GetPath(), id, GURL(extension->launch_web_url())); |
| + FilePath profile_path = data_dir.AppendASCII(chrome::kInitialProfile); |
| + FilePath pref_path = profile_path.Append(chrome::kPreferencesFilename); |
| + scoped_ptr<PrefService> prefs_service(PrefService::CreatePrefService( |
| + pref_path, NULL, false)); |
| + |
| + ExtensionPrefValueMap map; |
| + ExtensionPrefs::RegisterUserPrefs(prefs_service.get()); |
| + ExtensionPrefs extension_prefs(prefs_service.get(), install_directory_, &map); |
| + extension_prefs.Init(false); |
| + |
| + SetupExtensionPrefs( |
| + &extension_prefs, extension, from_webstore, page_ordinal, true); |
| + extension_prefs.AddGrantedPermissions(id, extension->GetActivePermissions()); |
| + extension_prefs.SetExtensionState(id, Extension::ENABLED); |
| + |
| + prefs_service->CommitPendingWrite(); |
| +} |