diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 19:54:41 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 19:54:41 +0000 |
commit | cb0ce1e02b7d16ab9024da9335ab7c70c493aa4e (patch) | |
tree | 1665a8f8d944aa85938154cbf2fefa5797c226aa /chrome/browser/extensions | |
parent | 17496bbed312152a6a0c2251c88ccefd70849540 (diff) | |
download | chromium_src-cb0ce1e02b7d16ab9024da9335ab7c70c493aa4e.zip chromium_src-cb0ce1e02b7d16ab9024da9335ab7c70c493aa4e.tar.gz chromium_src-cb0ce1e02b7d16ab9024da9335ab7c70c493aa4e.tar.bz2 |
Bookmark manager: Open in incognito window.
Make IsIncognitoEnabled take an Extension* as an argument as well and use that where possible.
BUG=4890
TEST=Select one more bookmarks and right click/tools and select "Open in incognito". The bookmarks should open in an incognito window.
Review URL: http://codereview.chromium.org/750001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
7 files changed, 26 insertions, 20 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 5261a34..9f7cdcf 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -74,7 +74,7 @@ bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path, // the defaults. Extension* extension = service->extensions()->at(num_after - 1); service->extension_prefs()->OnExtensionInstalled(extension); - service->SetIsIncognitoEnabled(extension->id(), true); + service->SetIsIncognitoEnabled(extension, true); } return WaitForExtensionHostsToLoad(); diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 36f8651..fb380a1 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -285,7 +285,7 @@ ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( render_view_host->process()->id()); bool incognito_enabled = - profile()->GetExtensionsService()->IsIncognitoEnabled(extension->id()); + profile()->GetExtensionsService()->IsIncognitoEnabled(extension); // Update the extension permissions. Doing this each time we create an EFD // ensures that new processes are informed of permissions for newly installed @@ -357,11 +357,12 @@ void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, function->SetArgs(args); function->set_request_id(request_id); function->set_has_callback(has_callback); - function->set_include_incognito( - profile()->GetExtensionsService()->IsIncognitoEnabled(extension_id())); - ExtensionsService* service = profile()->GetExtensionsService(); DCHECK(service); + Extension* extension = service->GetExtensionById(extension_id(), false); + DCHECK(extension); + function->set_include_incognito(service->IsIncognitoEnabled(extension)); + ExtensionsQuotaService* quota = service->quota_service(); if (quota->Assess(extension_id(), function, args, base::TimeTicks::Now())) { function->Run(); diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc index f243949..2dd23d47 100644 --- a/chrome/browser/extensions/extension_toolbar_model.cc +++ b/chrome/browser/extensions/extension_toolbar_model.cc @@ -192,7 +192,7 @@ int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { int original_index = 0, i = 0; for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++original_index) { - if (service_->IsIncognitoEnabled((*iter)->id())) { + if (service_->IsIncognitoEnabled(*iter)) { if (incognito_index == i) break; ++i; @@ -207,7 +207,7 @@ int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { ++iter, ++i) { if (original_index == i) break; - if (service_->IsIncognitoEnabled((*iter)->id())) + if (service_->IsIncognitoEnabled(*iter)) ++incognito_index; } return incognito_index; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index b4373ec0..4e9cb54 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -580,16 +580,19 @@ base::Time ExtensionsService::LastPingDay(const std::string& extension_id) { return extension_prefs_->LastPingDay(extension_id); } -bool ExtensionsService::IsIncognitoEnabled(const std::string& extension_id) { - return extension_prefs_->IsIncognitoEnabled(extension_id); +bool ExtensionsService::IsIncognitoEnabled(const Extension* extension) { + // If this is a component extension we always allow it to work in incognito + // mode. + if (extension->location() == Extension::COMPONENT) + return true; + + // Check the prefs. + return extension_prefs_->IsIncognitoEnabled(extension->id()); } -void ExtensionsService::SetIsIncognitoEnabled(const std::string& extension_id, +void ExtensionsService::SetIsIncognitoEnabled(Extension* extension, bool enabled) { - extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); - - Extension* extension = GetExtensionByIdInternal(extension_id, true, true); - DCHECK(extension); + extension_prefs_->SetIsIncognitoEnabled(extension->id(), enabled); // Broadcast unloaded and loaded events to update browser state. NotifyExtensionUnloaded(extension); diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index ef7678f..3ab9d34 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -128,8 +128,8 @@ class ExtensionsService virtual base::Time LastPingDay(const std::string& extension_id); // Whether this extension can run in an incognito window. - bool IsIncognitoEnabled(const std::string& extension_id); - void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled); + bool IsIncognitoEnabled(const Extension* extension); + void SetIsIncognitoEnabled(Extension* extension, bool enabled); const FilePath& install_directory() const { return install_directory_; } diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index 6f23280..00b658e 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -446,8 +446,10 @@ void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const Value* value) { std::string extension_id, enable_str; CHECK(list->GetString(0, &extension_id)); CHECK(list->GetString(1, &enable_str)); - extensions_service_->SetIsIncognitoEnabled(extension_id, - (enable_str == "true")); + Extension* extension = extensions_service_->GetExtensionById(extension_id, + true); + DCHECK(extension); + extensions_service_->SetIsIncognitoEnabled(extension, (enable_str == "true")); } void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) { @@ -715,7 +717,7 @@ DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue( extension_data->SetString(L"version", extension->version()->GetString()); extension_data->SetBoolean(L"enabled", enabled); extension_data->SetBoolean(L"enabledIncognito", - service ? service->IsIncognitoEnabled(extension->id()) : false); + service ? service->IsIncognitoEnabled(extension) : false); extension_data->SetBoolean(L"allow_reload", extension->location() == Extension::LOAD); diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index db84280..36e0ff6 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -337,7 +337,7 @@ void UserScriptMaster::Observe(NotificationType type, // Add any content scripts inside the extension. Extension* extension = Details<Extension>(details).ptr(); bool incognito_enabled = profile_->GetExtensionsService()-> - IsIncognitoEnabled(extension->id()); + IsIncognitoEnabled(extension); const UserScriptList& scripts = extension->content_scripts(); for (UserScriptList::const_iterator iter = scripts.begin(); iter != scripts.end(); ++iter) { |