Moved some functions off ExtensionService into a new file extension_util.
These functions do not need any internal state of ExtensionService, so
do not need to be on the class itself. This makes it easier to understand
what ExtensionService is doing (as it now does less) and easier to change.
[email protected]
BUG=298537
Review URL: https://codereview.chromium.org/25366003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229223 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/autocomplete/extension_app_provider.cc b/chrome/browser/autocomplete/extension_app_provider.cc
index 468839d..56f0fd0 100644
--- a/chrome/browser/autocomplete/extension_app_provider.cc
+++ b/chrome/browser/autocomplete/extension_app_provider.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system_factory.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/url_database.h"
@@ -161,7 +162,7 @@
// provider is currently only used in the app launcher.
if (profile_->IsOffTheRecord() &&
- !extension_service->CanLoadInIncognito(app))
+ !extension_util::CanLoadInIncognito(app, extension_service))
continue;
GURL launch_url = app->is_platform_app() ?
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index d07e27f..50020fcc 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
@@ -204,7 +205,8 @@
GetExtensionById(template_url->GetExtensionId(), false);
if (!extension ||
(profile_->IsOffTheRecord() &&
- !extension_service->IsIncognitoEnabled(extension->id())))
+ !extension_util::IsIncognitoEnabled(extension->id(),
+ extension_service)))
return string16();
}
@@ -281,7 +283,8 @@
service->GetExtensionById(template_url->GetExtensionId(), false);
bool enabled =
extension && (!profile_->IsOffTheRecord() ||
- service->IsIncognitoEnabled(extension->id()));
+ extension_util::IsIncognitoEnabled(extension->id(),
+ service));
if (!enabled) {
i = matches.erase(i);
continue;
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index ce44e8f0..a15f5d3 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -58,6 +58,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/history/history_service_factory.h"
@@ -3576,7 +3577,7 @@
Manifest::IsUnpackedLocation(location));
extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id));
extension_value->SetBoolean("allowed_in_incognito",
- service->IsIncognitoEnabled(id));
+ extension_util::IsIncognitoEnabled(id, service));
extension_value->SetBoolean(
"has_page_action",
extension_action_manager->GetPageAction(*extension) != NULL);
@@ -3684,7 +3685,8 @@
AutomationJSONReply(this, reply_message).SendSuccess(NULL);
}
- service->SetIsIncognitoEnabled(extension->id(), allow_in_incognito);
+ extension_util::SetIsIncognitoEnabled(
+ extension->id(), service, allow_in_incognito);
}
// See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py
diff --git a/chrome/browser/chromeos/file_manager/file_browser_handlers.cc b/chrome/browser/chromeos/file_manager/file_browser_handlers.cc
index 1af7759..bedd4101 100644
--- a/chrome/browser/chromeos/file_manager/file_browser_handlers.cc
+++ b/chrome/browser/chromeos/file_manager/file_browser_handlers.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
@@ -105,7 +106,7 @@
++iter) {
const Extension* extension = iter->get();
if (profile->IsOffTheRecord() &&
- !service->IsIncognitoEnabled(extension->id()))
+ !extension_util::IsIncognitoEnabled(extension->id(), service))
continue;
FileBrowserHandler::List* handler_list =
diff --git a/chrome/browser/chromeos/file_manager/file_tasks.cc b/chrome/browser/chromeos/file_manager/file_tasks.cc
index 4bb9e0a..7e04159 100644
--- a/chrome/browser/chromeos/file_manager/file_tasks.cc
+++ b/chrome/browser/chromeos/file_manager/file_tasks.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/common/extensions/api/file_browser_handlers/file_browser_handler.h"
@@ -390,7 +391,7 @@
continue;
if (profile->IsOffTheRecord() &&
- !service->IsIncognitoEnabled(extension->id()))
+ !extension_util::IsIncognitoEnabled(extension->id(), service))
continue;
typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList;
diff --git a/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc b/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
index e285eb7..a452130 100644
--- a/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
+++ b/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/state_store.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension.h"
@@ -402,7 +403,7 @@
(*i)->HasAPIPermission(APIPermission::kDeclarativeWebRequest);
bool respects_off_the_record =
!(profile_->IsOffTheRecord()) ||
- extension_service->IsIncognitoEnabled((*i)->id());
+ extension_util::IsIncognitoEnabled((*i)->id(), extension_service);
if (needs_apis_storing_rules && respects_off_the_record)
ReadFromStorage((*i)->id());
}
diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
index bd92c26..eb81a66e 100644
--- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/extensions/extension_error_reporter.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/management_policy.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
@@ -341,9 +342,10 @@
}
}
- info->incognito_enabled = service->IsIncognitoEnabled(item.id());
+ info->incognito_enabled =
+ extension_util::IsIncognitoEnabled(item.id(),service);
info->wants_file_access = item.wants_file_access();
- info->allow_file_access = service->AllowFileAccess(&item);
+ info->allow_file_access = extension_util::AllowFileAccess(&item, service);
info->allow_reload = Manifest::IsUnpackedLocation(item.location());
info->is_unpacked = Manifest::IsUnpackedLocation(item.location());
info->terminated = service->terminated_extensions()->Contains(item.id());
@@ -608,7 +610,7 @@
<< extension->id();
result = false;
} else {
- service->SetAllowFileAccess(extension, params->allow);
+ extension_util::SetAllowFileAccess(extension, service, params->allow);
result = true;
}
@@ -630,7 +632,8 @@
if (!extension)
result = false;
else
- service->SetIsIncognitoEnabled(extension->id(), params->allow);
+ extension_util::SetIsIncognitoEnabled(
+ extension->id(),service, params->allow);
return result;
}
diff --git a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
index 34801a4..2fb85d7 100644
--- a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
+++ b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_galleries_preferences.h"
#include "chrome/browser/profiles/profile.h"
@@ -381,7 +382,7 @@
++iter) {
const Extension* extension = iter->get();
if (profile_->IsOffTheRecord() &&
- !service->IsIncognitoEnabled(extension->id()))
+ !extension_util::IsIncognitoEnabled(extension->id(), service))
continue;
MediaGalleriesHandler::List* handler_list =
diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc
index db57a4e..425d48b9 100644
--- a/chrome/browser/extensions/api/messaging/message_service.cc
+++ b/chrome/browser/extensions/api/messaging/message_service.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
#include "chrome/browser/extensions/process_map.h"
#include "chrome/browser/profiles/profile.h"
@@ -211,7 +212,8 @@
ExtensionSystem::Get(profile)->extension_service();
if (profile->IsOffTheRecord() &&
- !extension_service->IsIncognitoEnabled(target_extension_id)) {
+ !extension_util::IsIncognitoEnabled(target_extension_id,
+ extension_service)) {
// Allow the security token apps (normal, dev) to be connectable from
// incognito profiles. See http://crbug.com/295845.
std::set<std::string> incognito_whitelist;
diff --git a/chrome/browser/extensions/api/module/module.cc b/chrome/browser/extensions/api/module/module.cc
index b1295d1..31e849c 100644
--- a/chrome/browser/extensions/api/module/module.cc
+++ b/chrome/browser/extensions/api/module/module.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
namespace extensions {
@@ -51,7 +52,7 @@
const Extension* extension = GetExtension();
SetResult(new base::FundamentalValue(
- ext_service->IsIncognitoEnabled(extension->id())));
+ extension_util::IsIncognitoEnabled(extension->id(), ext_service)));
return true;
}
@@ -61,7 +62,7 @@
const Extension* extension = GetExtension();
SetResult(new base::FundamentalValue(
- ext_service->AllowFileAccess(extension)));
+ extension_util::AllowFileAccess(extension, ext_service)));
return true;
}
diff --git a/chrome/browser/extensions/api/preference/preference_helpers.cc b/chrome/browser/extensions/api/preference/preference_helpers.cc
index 8649f8e..162e2ae 100644
--- a/chrome/browser/extensions/api/preference/preference_helpers.cc
+++ b/chrome/browser/extensions/api/preference/preference_helpers.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/incognito_handler.h"
@@ -102,7 +103,7 @@
if (router->ExtensionHasEventListener(extension_id, event_name) &&
(*it)->HasAPIPermission(permission) &&
(!incognito || IncognitoInfo::IsSplitMode(it->get()) ||
- extension_service->CanCrossIncognito(it->get()))) {
+ extension_util::CanCrossIncognito(it->get(), extension_service))) {
// Inject level of control key-value.
base::DictionaryValue* dict;
bool rv = args->GetDictionary(0, &dict);
@@ -118,7 +119,9 @@
Profile* restrict_to_profile = NULL;
bool from_incognito = false;
if (IncognitoInfo::IsSplitMode(it->get())) {
- if (incognito && extension_service->IsIncognitoEnabled(extension_id)) {
+ if (incognito &&
+ extension_util::IsIncognitoEnabled(extension_id,
+ extension_service)) {
restrict_to_profile = profile->GetOffTheRecordProfile();
} else if (!incognito &&
PreferenceAPI::Get(profile)->DoesExtensionControlPref(
diff --git a/chrome/browser/extensions/api/tabs/windows_event_router.cc b/chrome/browser/extensions/api/tabs/windows_event_router.cc
index 1f90f45..adc9a078 100644
--- a/chrome/browser/extensions/api/tabs/windows_event_router.cc
+++ b/chrome/browser/extensions/api/tabs/windows_event_router.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/extensions/window_controller_list.h"
#include "chrome/browser/profiles/profile.h"
@@ -115,8 +116,9 @@
// can't see the new focused window across the incognito boundary.
// See crbug.com/46610.
if (new_active_profile && new_active_profile != profile &&
- !extensions::ExtensionSystem::Get(profile)->extension_service()->
- CanCrossIncognito(extension)) {
+ !extension_util::CanCrossIncognito(
+ extension,
+ extensions::ExtensionSystem::Get(profile)->extension_service())) {
event_args->Clear();
event_args->Append(new base::FundamentalValue(
extension_misc::kUnknownWindowId));
diff --git a/chrome/browser/extensions/context_menu_matcher.cc b/chrome/browser/extensions/context_menu_matcher.cc
index 950461d..c125660 100644
--- a/chrome/browser/extensions/context_menu_matcher.cc
+++ b/chrome/browser/extensions/context_menu_matcher.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/extensions/context_menu_matcher.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/common/context_menu_params.h"
#include "ui/gfx/favicon_size.h"
@@ -161,7 +162,7 @@
if (!all_items || all_items->empty())
return false;
- *can_cross_incognito = service->CanCrossIncognito(*extension);
+ *can_cross_incognito = extension_util::CanCrossIncognito(*extension, service);
items = GetRelevantExtensionItems(*all_items,
*can_cross_incognito);
diff --git a/chrome/browser/extensions/event_router.cc b/chrome/browser/extensions/event_router.cc
index b547a33..b5e88bf4 100644
--- a/chrome/browser/extensions/event_router.cc
+++ b/chrome/browser/extensions/event_router.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
#include "chrome/browser/extensions/process_map.h"
#include "chrome/browser/profiles/profile.h"
@@ -631,9 +632,9 @@
// incognito tab event sent to a normal process, or vice versa).
bool cross_incognito =
event->restrict_to_profile && profile != event->restrict_to_profile;
- if (cross_incognito &&
- !ExtensionSystem::Get(profile)->extension_service()->
- CanCrossIncognito(extension)) {
+ if (cross_incognito && !extension_util::CanCrossIncognito(
+ extension,
+ ExtensionSystem::Get(profile)->extension_service())) {
return false;
}
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index f5da8f6d..f0b3914 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -192,11 +193,11 @@
content::WindowedNotificationObserver load_signal(
chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(profile()));
- CHECK(!service->IsIncognitoEnabled(extension_id) ||
+ CHECK(!extension_util::IsIncognitoEnabled(extension_id, service) ||
extension->force_incognito_enabled());
if (flags & kFlagEnableIncognito) {
- service->SetIsIncognitoEnabled(extension_id, true);
+ extension_util::SetIsIncognitoEnabled(extension_id, service, true);
load_signal.Wait();
extension = service->GetExtensionById(extension_id, false);
CHECK(extension) << extension_id << " not found after reloading.";
@@ -207,9 +208,9 @@
content::WindowedNotificationObserver load_signal(
chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(profile()));
- CHECK(service->AllowFileAccess(extension));
+ CHECK(extension_util::AllowFileAccess(extension, service));
if (!(flags & kFlagEnableFileAccess)) {
- service->SetAllowFileAccess(extension, false);
+ extension_util::SetAllowFileAccess(extension, service, false);
load_signal.Wait();
extension = service->GetExtensionById(extension_id, false);
CHECK(extension) << extension_id << " not found after reloading.";
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 056dda4..d6da6d08 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/extensions/extension_function_registry.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/extension_web_ui.h"
#include "chrome/browser/extensions/extensions_quota_service.h"
#include "chrome/browser/extensions/process_map.h"
@@ -346,7 +347,8 @@
function_ui->SetRenderViewHost(render_view_host);
function_ui->set_dispatcher(AsWeakPtr());
function_ui->set_profile(profile_);
- function->set_include_incognito(service->CanCrossIncognito(extension));
+ function->set_include_incognito(extension_util::CanCrossIncognito(extension,
+ service));
if (!CheckPermissions(function.get(), extension, params, callback))
return;
diff --git a/chrome/browser/extensions/extension_functional_browsertest.cc b/chrome/browser/extensions/extension_functional_browsertest.cc
index 19c7e0a..78bc098 100644
--- a/chrome/browser/extensions/extension_functional_browsertest.cc
+++ b/chrome/browser/extensions/extension_functional_browsertest.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/test/base/ui_test_utils.h"
@@ -65,7 +66,8 @@
// Verify that the extension is enabled and allowed in incognito
// is disabled.
EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id_));
- EXPECT_FALSE(service->IsIncognitoEnabled(last_loaded_extension_id_));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_,
+ service));
}
IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, TestSetExtensionsState) {
@@ -73,24 +75,30 @@
InstallExtensionSilently(service, "google_talk.crx");
// Disable the extension and verify.
- service->SetIsIncognitoEnabled(last_loaded_extension_id_, false);
+ extension_util::SetIsIncognitoEnabled(
+ last_loaded_extension_id_, service, false);
service->DisableExtension(last_loaded_extension_id_,
Extension::DISABLE_USER_ACTION);
EXPECT_FALSE(service->IsExtensionEnabled(last_loaded_extension_id_));
// Enable the extension and verify.
- service->SetIsIncognitoEnabled(last_loaded_extension_id_, false);
+ extension_util::SetIsIncognitoEnabled(
+ last_loaded_extension_id_, service, false);
service->EnableExtension(last_loaded_extension_id_);
EXPECT_TRUE(service->IsExtensionEnabled(last_loaded_extension_id_));
// Allow extension in incognito mode and verify.
service->EnableExtension(last_loaded_extension_id_);
- service->SetIsIncognitoEnabled(last_loaded_extension_id_, true);
- EXPECT_TRUE(service->IsIncognitoEnabled(last_loaded_extension_id_));
+ extension_util::SetIsIncognitoEnabled(
+ last_loaded_extension_id_, service, true);
+ EXPECT_TRUE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_,
+ service));
// Disallow extension in incognito mode and verify.
service->EnableExtension(last_loaded_extension_id_);
- service->SetIsIncognitoEnabled(last_loaded_extension_id_, false);
- EXPECT_FALSE(service->IsIncognitoEnabled(last_loaded_extension_id_));
+ extension_util::SetIsIncognitoEnabled(
+ last_loaded_extension_id_, service, false);
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(last_loaded_extension_id_,
+ service));
}
} // namespace extensions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 751d536..cc04550 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -1001,7 +1001,7 @@
return is_active;
}
-bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
+bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) const {
return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled);
}
@@ -1011,7 +1011,7 @@
new base::FundamentalValue(enabled));
}
-bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) {
+bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) const {
return ReadPrefAsBooleanAndReturn(extension_id, kPrefAllowFileAccess);
}
diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h
index 22a00b1..a079c0e 100644
--- a/chrome/browser/extensions/extension_prefs.h
+++ b/chrome/browser/extensions/extension_prefs.h
@@ -369,14 +369,17 @@
// Returns true if the user enabled this extension to be loaded in incognito
// mode.
//
- // IMPORTANT: you probably want to use ExtensionService::IsIncognitoEnabled
+ // IMPORTANT: you probably want to use extension_utils::IsIncognitoEnabled
// instead of this method.
- bool IsIncognitoEnabled(const std::string& extension_id);
+ bool IsIncognitoEnabled(const std::string& extension_id) const;
void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
// Returns true if the user has chosen to allow this extension to inject
// scripts into pages with file URLs.
- bool AllowFileAccess(const std::string& extension_id);
+ //
+ // IMPORTANT: you probably want to use extension_utils::AllowFileAccess
+ // instead of this method.
+ bool AllowFileAccess(const std::string& extension_id) const;
void SetAllowFileAccess(const std::string& extension_id, bool allow);
bool HasAllowFileAccessSetting(const std::string& extension_id) const;
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 8da80d8..1bf01a1 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
@@ -957,7 +958,7 @@
const Extension* extension) {
// Keep in sync with duplicate in extension_info_map.cc.
ExtensionService* service = GetProfile()->GetExtensionService();
- return service && service->IsIncognitoEnabled(extension->id());
+ return extension_util::IsIncognitoEnabled(extension->id(), service);
}
void IncognitoExtensionProcessManager::Observe(
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 6a87a5f..52df5fe 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -50,6 +50,7 @@
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_sync_data.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/external_install_ui.h"
#include "chrome/browser/extensions/external_provider_impl.h"
#include "chrome/browser/extensions/external_provider_interface.h"
@@ -284,28 +285,6 @@
return !!GetInstalledApp(url);
}
-const Extension* ExtensionService::GetIsolatedAppForRenderer(
- int renderer_child_id) const {
- std::set<std::string> extension_ids =
- process_map_.GetExtensionsInProcess(renderer_child_id);
- // All apps in one process share the same partition.
- // It is only possible for the app to have isolated storage
- // if there is only 1 app in the process.
- if (extension_ids.size() != 1)
- return NULL;
-
- const extensions::Extension* extension =
- extensions_.GetByID(*(extension_ids.begin()));
- // We still need to check if the extension has isolated storage,
- // because it's common for there to be one extension in a process
- // without isolated storage.
- if (extension &&
- extensions::AppIsolationInfo::HasIsolatedStorage(extension))
- return extension;
-
- return NULL;
-}
-
// static
// This function is used to implement the command-line switch
// --uninstall-extension, and to uninstall an extension via sync. The LOG
@@ -1250,6 +1229,10 @@
return extension_prefs_;
}
+const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const {
+ return extension_prefs_;
+}
+
extensions::SettingsFrontend* ExtensionService::settings_frontend() {
return settings_frontend_.get();
}
@@ -1415,9 +1398,10 @@
extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
const Extension& extension) const {
- return extensions::ExtensionSyncData(extension,
- IsExtensionEnabled(extension.id()),
- IsIncognitoEnabled(extension.id()));
+ return extensions::ExtensionSyncData(
+ extension,
+ IsExtensionEnabled(extension.id()),
+ extension_util::IsIncognitoEnabled(extension.id(), this));
}
extensions::AppSyncData ExtensionService::GetAppSyncData(
@@ -1425,7 +1409,7 @@
return extensions::AppSyncData(
extension,
IsExtensionEnabled(extension.id()),
- IsIncognitoEnabled(extension.id()),
+ extension_util::IsIncognitoEnabled(extension.id(), this),
extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
extension.id()),
extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
@@ -1570,7 +1554,8 @@
bool extension_installed = (extension != NULL);
int result = extension ?
extension->version()->CompareTo(extension_sync_data.version()) : 0;
- SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
+ extension_util::SetIsIncognitoEnabled(
+ id, this, extension_sync_data.incognito_enabled());
extension = NULL; // No longer safe to use.
if (extension_installed) {
@@ -1607,79 +1592,6 @@
return true;
}
-bool ExtensionService::IsIncognitoEnabled(
- const std::string& extension_id) const {
- const Extension* extension = GetInstalledExtension(extension_id);
- if (extension && !extension->can_be_incognito_enabled())
- return false;
- // If this is an existing component extension we always allow it to
- // work in incognito mode.
- if (extension && extension->location() == Manifest::COMPONENT)
- return true;
- if (extension && extension->force_incognito_enabled())
- return true;
-
- // Check the prefs.
- return extension_prefs_->IsIncognitoEnabled(extension_id);
-}
-
-void ExtensionService::SetIsIncognitoEnabled(
- const std::string& extension_id, bool enabled) {
- const Extension* extension = GetInstalledExtension(extension_id);
- if (extension && !extension->can_be_incognito_enabled())
- return;
- if (extension && extension->location() == Manifest::COMPONENT) {
- // This shouldn't be called for component extensions unless they are
- // syncable.
- DCHECK(extensions::sync_helper::IsSyncable(extension));
-
- // If we are here, make sure the we aren't trying to change the value.
- DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id));
-
- return;
- }
-
- // Broadcast unloaded and loaded events to update browser state. Only bother
- // if the value changed and the extension is actually enabled, since there is
- // no UI otherwise.
- bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
- if (enabled == old_enabled)
- return;
-
- extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
-
- bool extension_is_enabled = extensions_.Contains(extension_id);
-
- // When we reload the extension the ID may be invalidated if we've passed it
- // by const ref everywhere. Make a copy to be safe.
- std::string id = extension_id;
- if (extension_is_enabled)
- ReloadExtension(id);
-
- // Reloading the extension invalidates the |extension| pointer.
- extension = GetInstalledExtension(id);
- if (extension)
- SyncExtensionChangeIfNeeded(*extension);
-}
-
-bool ExtensionService::CanCrossIncognito(const Extension* extension) const {
- // We allow the extension to see events and data from another profile iff it
- // uses "spanning" behavior and it has incognito access. "split" mode
- // extensions only see events for a matching profile.
- CHECK(extension);
- return IsIncognitoEnabled(extension->id()) &&
- !extensions::IncognitoInfo::IsSplitMode(extension);
-}
-
-bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
- if (extension->is_hosted_app())
- return true;
- // Packaged apps and regular extensions need to be enabled specifically for
- // incognito (and split mode should be set).
- return extensions::IncognitoInfo::IsSplitMode(extension) &&
- IsIncognitoEnabled(extension->id());
-}
-
void ExtensionService::OnExtensionMoved(
const std::string& moved_extension_id,
const std::string& predecessor_extension_id,
@@ -1694,27 +1606,6 @@
SyncExtensionChangeIfNeeded(*extension);
}
-bool ExtensionService::AllowFileAccess(const Extension* extension) const {
- return (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableExtensionsFileAccessCheck) ||
- extension_prefs_->AllowFileAccess(extension->id()));
-}
-
-void ExtensionService::SetAllowFileAccess(const Extension* extension,
- bool allow) {
- // Reload to update browser state. Only bother if the value changed and the
- // extension is actually enabled, since there is no UI otherwise.
- bool old_allow = AllowFileAccess(extension);
- if (allow == old_allow)
- return;
-
- extension_prefs_->SetAllowFileAccess(extension->id(), allow);
-
- bool extension_is_enabled = extensions_.Contains(extension->id());
- if (extension_is_enabled)
- ReloadExtension(extension->id());
-}
-
// Some extensions will autoupdate themselves externally from Chrome. These
// are typically part of some larger client application package. To support
// these, the extension will register its location in the the preferences file
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index d908dc5..e9e7cba 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -146,11 +146,6 @@
// Returns whether the URL is from either a hosted or packaged app.
bool IsInstalledApp(const GURL& url) const;
- // If the renderer is hosting an installed app with isolated storage,
- // returns it, otherwise returns NULL.
- const extensions::Extension* GetIsolatedAppForRenderer(
- int renderer_child_id) const;
-
// Attempts to uninstall an extension from a given ExtensionService. Returns
// true iff the target extension exists.
static bool UninstallExtensionHelper(ExtensionService* extensions_service,
@@ -188,11 +183,6 @@
extensions::ProcessMap* process_map() { return &process_map_; }
- // Whether this extension can run in an incognito window.
- virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
- virtual void SetIsIncognitoEnabled(const std::string& extension_id,
- bool enabled);
-
// Updates the app launcher value for the moved extension so that it is now
// located after the given predecessor and before the successor. This will
// trigger a sync if needed. Empty strings are used to indicate no successor
@@ -201,19 +191,6 @@
const std::string& predecessor_extension_id,
const std::string& successor_extension_id);
- // Returns true if the given extension can see events and data from another
- // sub-profile (incognito to original profile, or vice versa).
- bool CanCrossIncognito(const extensions::Extension* extension) const;
-
- // Returns true if the given extension can be loaded in incognito.
- bool CanLoadInIncognito(const extensions::Extension* extension) const;
-
- // Whether this extension can inject scripts into pages with file URLs.
- bool AllowFileAccess(const extensions::Extension* extension) const;
- // Will reload the extension since this permission is applied at loading time
- // only.
- void SetAllowFileAccess(const extensions::Extension* extension, bool allow);
-
// Whether the persistent background page, if any, is ready. We don't load
// other components until then. If there is no background page, or if it is
// non-persistent (lazy), we consider it to be ready.
@@ -512,6 +489,7 @@
// TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
// ExtensionPrefs* mutable_extension_prefs().
extensions::ExtensionPrefs* extension_prefs();
+ const extensions::ExtensionPrefs* extension_prefs() const;
extensions::SettingsFrontend* settings_frontend();
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 38c51b0..6465fd39 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -44,6 +44,7 @@
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_sync_data.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/external_install_ui.h"
#include "chrome/browser/extensions/external_policy_loader.h"
#include "chrome/browser/extensions/external_pref_loader.h"
@@ -2925,7 +2926,7 @@
// Disable it and allow it to run in incognito. These settings should carry
// over to the updated version.
service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION);
- service_->SetIsIncognitoEnabled(good->id(), true);
+ extension_util::SetIsIncognitoEnabled(good->id(), service_, true);
service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true);
path = data_dir_.AppendASCII("good2.crx");
@@ -2933,7 +2934,7 @@
ASSERT_EQ(1u, service_->disabled_extensions()->size());\
const Extension* good2 = service_->GetExtensionById(good_crx, true);
ASSERT_EQ("1.0.0.1", good2->version()->GetString());
- EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id()));
+ EXPECT_TRUE(extension_util::IsIncognitoEnabled(good2->id(), service_));
EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions(
good2->id()));
}
@@ -3187,7 +3188,7 @@
EXPECT_FALSE(
service_->extension_prefs()->IsExtensionDisabled(extension->id()));
EXPECT_TRUE(service_->IsExtensionEnabled(extension->id()));
- EXPECT_FALSE(service_->IsIncognitoEnabled(extension->id()));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(extension->id(), service_));
}
// Test updating a pending CRX as if the source is an external extension
@@ -5366,7 +5367,8 @@
EXPECT_EQ(extension->id(), data.id());
EXPECT_FALSE(data.uninstalled());
EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled());
- EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled());
+ EXPECT_EQ(extension_util::IsIncognitoEnabled(good_crx, service_),
+ data.incognito_enabled());
EXPECT_TRUE(data.version().Equals(*extension->version()));
EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
data.update_url());
@@ -5392,7 +5394,8 @@
EXPECT_EQ(extension->id(), data.id());
EXPECT_FALSE(data.uninstalled());
EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled());
- EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled());
+ EXPECT_EQ(extension_util::IsIncognitoEnabled(good_crx, service_),
+ data.incognito_enabled());
EXPECT_TRUE(data.version().Equals(*extension->version()));
EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
data.update_url());
@@ -5443,7 +5446,7 @@
EXPECT_FALSE(data.incognito_enabled());
}
- service_->SetIsIncognitoEnabled(good_crx, true);
+ extension_util::SetIsIncognitoEnabled(good_crx, service_, true);
{
syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS);
ASSERT_EQ(list.size(), 1U);
@@ -5705,7 +5708,7 @@
InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
- EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(good_crx, service_));
sync_pb::EntitySpecifics specifics;
sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
@@ -5724,7 +5727,7 @@
list[0] = sync_change;
service_->ProcessSyncChanges(FROM_HERE, list);
EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
- EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(good_crx, service_));
}
{
@@ -5739,7 +5742,7 @@
list[0] = sync_change;
service_->ProcessSyncChanges(FROM_HERE, list);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
- EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_TRUE(extension_util::IsIncognitoEnabled(good_crx, service_));
}
{
@@ -5754,7 +5757,7 @@
list[0] = sync_change;
service_->ProcessSyncChanges(FROM_HERE, list);
EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
- EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_TRUE(extension_util::IsIncognitoEnabled(good_crx, service_));
}
EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx));
@@ -5771,7 +5774,7 @@
InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
TerminateExtension(good_crx);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
- EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(good_crx, service_));
sync_pb::EntitySpecifics specifics;
sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
@@ -5790,7 +5793,7 @@
service_->ProcessSyncChanges(FROM_HERE, list);
EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
- EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_TRUE(extension_util::IsIncognitoEnabled(good_crx, service_));
EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx));
}
@@ -5805,7 +5808,7 @@
InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
- EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(good_crx, service_));
sync_pb::EntitySpecifics specifics;
sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
@@ -5887,11 +5890,11 @@
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
- EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_FALSE(extension_util::IsIncognitoEnabled(good_crx, service_));
service_->ProcessSyncChanges(FROM_HERE, list);
EXPECT_TRUE(service_->updater()->WillCheckSoon());
EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
- EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx));
+ EXPECT_TRUE(extension_util::IsIncognitoEnabled(good_crx, service_));
const extensions::PendingExtensionInfo* info;
EXPECT_TRUE((info = service_->pending_extension_manager()->
diff --git a/chrome/browser/extensions/extension_startup_browsertest.cc b/chrome/browser/extensions/extension_startup_browsertest.cc
index 300f023..b025054 100644
--- a/chrome/browser/extensions/extension_startup_browsertest.cc
+++ b/chrome/browser/extensions/extension_startup_browsertest.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/user_script_master.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -188,7 +189,7 @@
it != service->extensions()->end(); ++it) {
if ((*it)->location() == extensions::Manifest::COMPONENT)
continue;
- if (service->AllowFileAccess(it->get()))
+ if (extension_util::AllowFileAccess(it->get(), service))
extension_list.push_back(it->get());
}
@@ -196,7 +197,7 @@
content::WindowedNotificationObserver user_scripts_observer(
chrome::NOTIFICATION_USER_SCRIPTS_UPDATED,
content::NotificationService::AllSources());
- service->SetAllowFileAccess(extension_list[i], false);
+ extension_util::SetAllowFileAccess(extension_list[i], service, false);
user_scripts_observer.Wait();
}
diff --git a/chrome/browser/extensions/extension_system.cc b/chrome/browser/extensions/extension_system.cc
index 348c5ee..ddb687d 100644
--- a/chrome/browser/extensions/extension_system.cc
+++ b/chrome/browser/extensions/extension_system.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system_factory.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/extension_warning_badge_service.h"
#include "chrome/browser/extensions/extension_warning_set.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
@@ -395,7 +396,7 @@
GetInstallTime(extension->id());
}
bool incognito_enabled =
- extension_service()->IsIncognitoEnabled(extension->id());
+ extension_util::IsIncognitoEnabled(extension->id(), extension_service());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ExtensionInfoMap::AddExtension, info_map(),
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index c869fd9..a61dc42 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -402,7 +403,7 @@
for (ExtensionList::iterator iter = toolbar_items_.begin();
iter != toolbar_items_.end();
++iter, ++original_index) {
- if (service_->IsIncognitoEnabled((*iter)->id())) {
+ if (extension_util::IsIncognitoEnabled((*iter)->id(), service_)) {
if (incognito_index == i)
break;
++i;
@@ -418,7 +419,7 @@
++iter, ++i) {
if (original_index == i)
break;
- if (service_->IsIncognitoEnabled((*iter)->id()))
+ if (extension_util::IsIncognitoEnabled((*iter)->id(), service_))
++incognito_index;
}
return incognito_index;
diff --git a/chrome/browser/extensions/extension_util.cc b/chrome/browser/extensions/extension_util.cc
new file mode 100644
index 0000000..71375ddc
--- /dev/null
+++ b/chrome/browser/extensions/extension_util.cc
@@ -0,0 +1,124 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_util.h"
+
+#include "base/command_line.h"
+#include "chrome/browser/extensions/extension_prefs.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/incognito_handler.h"
+#include "chrome/common/extensions/sync_helper.h"
+#include "extensions/common/manifest.h"
+
+using extensions::Extension;
+using extensions::ExtensionPrefs;
+
+namespace extension_util {
+
+bool IsIncognitoEnabled(const std::string& extension_id,
+ const ExtensionService* service) {
+ if (!service)
+ return false;
+
+ const Extension* extension = service->GetInstalledExtension(extension_id);
+ if (extension && !extension->can_be_incognito_enabled())
+ return false;
+ // If this is an existing component extension we always allow it to
+ // work in incognito mode.
+ if (extension && extension->location() == extensions::Manifest::COMPONENT)
+ return true;
+ if (extension && extension->force_incognito_enabled())
+ return true;
+
+ // Check the prefs.
+ return service->extension_prefs()->IsIncognitoEnabled(extension_id);
+}
+
+void SetIsIncognitoEnabled(const std::string& extension_id,
+ ExtensionService* service,
+ bool enabled) {
+ const Extension* extension = service->GetInstalledExtension(extension_id);
+ if (extension && !extension->can_be_incognito_enabled())
+ return;
+ if (extension && extension->location() == extensions::Manifest::COMPONENT) {
+ // This shouldn't be called for component extensions unless it is called
+ // by sync, for syncable component extensions.
+ // See http://crbug.com/112290 and associated CLs for the sordid history.
+ DCHECK(extensions::sync_helper::IsSyncable(extension));
+
+ // If we are here, make sure the we aren't trying to change the value.
+ DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id, service));
+ return;
+ }
+
+ ExtensionPrefs* extension_prefs = service->extension_prefs();
+ // Broadcast unloaded and loaded events to update browser state. Only bother
+ // if the value changed and the extension is actually enabled, since there is
+ // no UI otherwise.
+ bool old_enabled = extension_prefs->IsIncognitoEnabled(extension_id);
+ if (enabled == old_enabled)
+ return;
+
+ extension_prefs->SetIsIncognitoEnabled(extension_id, enabled);
+
+ bool extension_is_enabled = service->extensions()->Contains(extension_id);
+
+ // When we reload the extension the ID may be invalidated if we've passed it
+ // by const ref everywhere. Make a copy to be safe.
+ std::string id = extension_id;
+ if (extension_is_enabled)
+ service->ReloadExtension(id);
+
+ // Reloading the extension invalidates the |extension| pointer.
+ extension = service->GetInstalledExtension(id);
+ if (extension)
+ service->SyncExtensionChangeIfNeeded(*extension);
+}
+
+bool CanCrossIncognito(const Extension* extension,
+ const ExtensionService* service) {
+ // We allow the extension to see events and data from another profile iff it
+ // uses "spanning" behavior and it has incognito access. "split" mode
+ // extensions only see events for a matching profile.
+ CHECK(extension);
+ return extension_util::IsIncognitoEnabled(extension->id(), service) &&
+ !extensions::IncognitoInfo::IsSplitMode(extension);
+}
+
+bool CanLoadInIncognito(const Extension* extension,
+ const ExtensionService* service) {
+ if (extension->is_hosted_app())
+ return true;
+ // Packaged apps and regular extensions need to be enabled specifically for
+ // incognito (and split mode should be set).
+ return extensions::IncognitoInfo::IsSplitMode(extension) &&
+ extension_util::IsIncognitoEnabled(extension->id(), service);
+}
+
+bool AllowFileAccess(const Extension* extension,
+ const ExtensionService* service) {
+ return (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableExtensionsFileAccessCheck) ||
+ service->extension_prefs()->AllowFileAccess(extension->id()));
+}
+
+void SetAllowFileAccess(const Extension* extension,
+ ExtensionService* service,
+ bool allow) {
+ // Reload to update browser state. Only bother if the value changed and the
+ // extension is actually enabled, since there is no UI otherwise.
+ bool old_allow = AllowFileAccess(extension, service);
+ if (allow == old_allow)
+ return;
+
+ service->extension_prefs()->SetAllowFileAccess(extension->id(), allow);
+
+ bool extension_is_enabled = service->extensions()->Contains(extension->id());
+ if (extension_is_enabled)
+ service->ReloadExtension(extension->id());
+}
+
+} // namespace extension_util
diff --git a/chrome/browser/extensions/extension_util.h b/chrome/browser/extensions/extension_util.h
new file mode 100644
index 0000000..fb9d74e
--- /dev/null
+++ b/chrome/browser/extensions/extension_util.h
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
+
+#include <string>
+
+namespace extensions {
+class Extension;
+}
+
+class ExtensionService;
+
+namespace extension_util {
+
+// Whether this extension can run in an incognito window.
+bool IsIncognitoEnabled(const std::string& extension_id,
+ const ExtensionService* service);
+
+// Will reload the extension since this permission is applied at loading time
+// only.
+void SetIsIncognitoEnabled(const std::string& extension_id,
+ ExtensionService* service,
+ bool enabled);
+
+// Returns true if the given extension can see events and data from another
+// sub-profile (incognito to original profile, or vice versa).
+bool CanCrossIncognito(const extensions::Extension* extension,
+ const ExtensionService* service);
+
+// Returns true if the given extension can be loaded in incognito.
+bool CanLoadInIncognito(const extensions::Extension* extension,
+ const ExtensionService* service);
+
+// Whether this extension can inject scripts into pages with file URLs.
+bool AllowFileAccess(const extensions::Extension* extension,
+ const ExtensionService* service);
+
+// Will reload the extension since this permission is applied at loading time
+// only.
+void SetAllowFileAccess(const extensions::Extension* extension,
+ ExtensionService* service,
+ bool allow);
+
+} // namespace extension_util
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc
index 631ba56..b2002c2 100644
--- a/chrome/browser/extensions/extension_web_ui.cc
+++ b/chrome/browser/extensions/extension_web_ui.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/image_loader.h"
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
@@ -228,7 +229,7 @@
// extension uses split mode.
bool incognito_override_allowed =
extensions::IncognitoInfo::IsSplitMode(extension) &&
- service->IsIncognitoEnabled(extension->id());
+ extension_util::IsIncognitoEnabled(extension->id(), service);
if (profile->IsOffTheRecord() && !incognito_override_allowed) {
++i;
continue;
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index 95b8f6aa..4a9ff1ca 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/image_loader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
@@ -373,8 +374,9 @@
extensions_info_[extension->id()] =
ExtensionSet::ExtensionPathAndDefaultLocale(
extension->path(), LocaleInfo::GetDefaultLocale(extension));
- bool incognito_enabled = extensions::ExtensionSystem::Get(profile_)->
- extension_service()->IsIncognitoEnabled(extension->id());
+ bool incognito_enabled = extension_util::IsIncognitoEnabled(
+ extension->id(),
+ extensions::ExtensionSystem::Get(profile_)->extension_service());
const UserScriptList& scripts =
ContentScriptsInfo::GetContentScripts(extension);
for (UserScriptList::const_iterator iter = scripts.begin();
diff --git a/chrome/browser/sync/test/integration/sync_extension_helper.cc b/chrome/browser/sync/test/integration/sync_extension_helper.cc
index 3e1c0d4cd..75a69e6 100644
--- a/chrome/browser/sync/test/integration/sync_extension_helper.cc
+++ b/chrome/browser/sync/test/integration/sync_extension_helper.cc
@@ -10,6 +10,7 @@
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/pending_extension_info.h"
#include "chrome/browser/extensions/pending_extension_manager.h"
#include "chrome/browser/profiles/profile.h"
@@ -116,20 +117,20 @@
void SyncExtensionHelper::IncognitoEnableExtension(
Profile* profile, const std::string& name) {
- profile->GetExtensionService()->SetIsIncognitoEnabled(
- extensions::id_util::GenerateId(name), true);
+ extension_util::SetIsIncognitoEnabled(extensions::id_util::GenerateId(name),
+ profile->GetExtensionService(), true);
}
void SyncExtensionHelper::IncognitoDisableExtension(
Profile* profile, const std::string& name) {
- profile->GetExtensionService()->SetIsIncognitoEnabled(
- extensions::id_util::GenerateId(name), false);
+ extension_util::SetIsIncognitoEnabled(extensions::id_util::GenerateId(name),
+ profile->GetExtensionService(), false);
}
bool SyncExtensionHelper::IsIncognitoEnabled(
Profile* profile, const std::string& name) const {
- return profile->GetExtensionService()->IsIncognitoEnabled(
- extensions::id_util::GenerateId(name));
+ return extension_util::IsIncognitoEnabled(
+ extensions::id_util::GenerateId(name), profile->GetExtensionService());
}
@@ -197,7 +198,7 @@
ExtensionState::ENABLED :
ExtensionState::DISABLED;
extension_state_map[id].incognito_enabled =
- extension_service->IsIncognitoEnabled(id);
+ extension_util::IsIncognitoEnabled(id, extension_service);
DVLOG(2) << "Extension " << (*it)->id() << " in profile "
<< profile_debug_name << " is "
@@ -215,7 +216,7 @@
for (id = pending_crx_ids.begin(); id != pending_crx_ids.end(); ++id) {
extension_state_map[*id].enabled_state = ExtensionState::PENDING;
extension_state_map[*id].incognito_enabled =
- extension_service->IsIncognitoEnabled(*id);
+ extension_util::IsIncognitoEnabled(*id, extension_service);
DVLOG(2) << "Extension " << *id << " in profile "
<< profile_debug_name << " is pending";
}
diff --git a/chrome/browser/ui/app_list/search/app_search_provider.cc b/chrome/browser/ui/app_list/search/app_search_provider.cc
index ceba03f..c7fc5f0 100644
--- a/chrome/browser/ui/app_list/search/app_search_provider.cc
+++ b/chrome/browser/ui/app_list/search/app_search_provider.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system_factory.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/search/app_result.h"
#include "chrome/browser/ui/app_list/search/tokenized_string.h"
@@ -82,7 +83,7 @@
continue;
if (profile_->IsOffTheRecord() &&
- !service->CanLoadInIncognito(app))
+ !extension_util::CanLoadInIncognito(app, service))
continue;
apps_.push_back(new App(app));
}
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index a17f3d8..749da3ac 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
@@ -761,8 +762,9 @@
// Only display incognito-enabled extensions while in incognito mode.
return
(!profile_->IsOffTheRecord() ||
- extensions::ExtensionSystem::Get(profile_)->extension_service()->
- IsIncognitoEnabled(extension->id()));
+ extension_util::IsIncognitoEnabled(
+ extension->id(),
+ extensions::ExtensionSystem::Get(profile_)->extension_service()));
}
- (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate {
diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
index 34f300a..d2f056b3 100644
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/extensions/extension_context_menu_model.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
@@ -694,8 +695,9 @@
const Extension* extension) {
// Only display incognito-enabled extensions while in incognito mode.
return (!profile_->IsOffTheRecord() ||
- extensions::ExtensionSystem::Get(profile_)->extension_service()->
- IsIncognitoEnabled(extension->id()));
+ extension_util:: IsIncognitoEnabled(
+ extension->id(),
+ extensions::ExtensionSystem::Get(profile_)->extension_service()));
}
void BrowserActionsToolbarGtk::HidePopup() {
diff --git a/chrome/browser/ui/views/browser_actions_container.cc b/chrome/browser/ui/views/browser_actions_container.cc
index 85018976..2565b30 100644
--- a/chrome/browser/ui/views/browser_actions_container.cc
+++ b/chrome/browser/ui/views/browser_actions_container.cc
@@ -9,6 +9,7 @@
#include "base/stl_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
@@ -808,8 +809,9 @@
// Only display incognito-enabled extensions while in incognito mode.
return
(!profile_->IsOffTheRecord() ||
- extensions::ExtensionSystem::Get(profile_)->extension_service()->
- IsIncognitoEnabled(extension->id()));
+ extension_util::IsIncognitoEnabled(
+ extension->id(),
+ extensions::ExtensionSystem::Get(profile_)->extension_service()));
}
void BrowserActionsContainer::ShowPopup(
diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
index 6fea215..403ee9e 100644
--- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
+++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/extension_warning_set.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
#include "chrome/browser/extensions/management_policy.h"
@@ -209,13 +210,13 @@
extension_data->SetBoolean("terminated",
extension_service_->terminated_extensions()->Contains(extension->id()));
extension_data->SetBoolean("enabledIncognito",
- extension_service_->IsIncognitoEnabled(extension->id()));
+ extension_util::IsIncognitoEnabled(extension->id(), extension_service_));
extension_data->SetBoolean("incognitoCanBeToggled",
extension->can_be_incognito_enabled() &&
!extension->force_incognito_enabled());
extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access());
extension_data->SetBoolean("allowFileAccess",
- extension_service_->AllowFileAccess(extension));
+ extension_util::AllowFileAccess(extension, extension_service_));
extension_data->SetBoolean("allow_reload",
Manifest::IsUnpackedLocation(extension->location()));
extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app());
@@ -861,8 +862,9 @@
// Bug: http://crbug.com/41384
base::AutoReset<bool> auto_reset_ignore_notifications(
&ignore_notifications_, true);
- extension_service_->SetIsIncognitoEnabled(extension->id(),
- enable_str == "true");
+ extension_util::SetIsIncognitoEnabled(extension->id(),
+ extension_service_,
+ enable_str == "true");
}
void ExtensionSettingsHandler::HandleAllowFileAccessMessage(
@@ -883,7 +885,8 @@
return;
}
- extension_service_->SetAllowFileAccess(extension, allow_str == "true");
+ extension_util::SetAllowFileAccess(
+ extension, extension_service_, allow_str == "true");
}
void ExtensionSettingsHandler::HandleUninstallMessage(