Commit e0b3de7b authored by kalman@chromium.org's avatar kalman@chromium.org

Generate a browser action for any extension which doesn't have a browser or

page action.

BUG=124605


Review URL: http://codereview.chromium.org/10264004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134657 0039d316-1c4b-4281-b951-d872f2087c98
parent 64bde8de
......@@ -56,37 +56,6 @@ using content::RenderViewHost;
using content::WebContents;
using extensions::ExtensionUpdater;
namespace {
bool ShouldShowExtension(const Extension* extension) {
// Don't show themes since this page's UI isn't really useful for themes.
if (extension->is_theme())
return false;
// Don't show component extensions because they are only extensions as an
// implementation detail of Chrome.
if (extension->location() == Extension::COMPONENT &&
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kShowComponentExtensionOptions))
return false;
// Always show unpacked extensions and apps.
if (extension->location() == Extension::LOAD)
return true;
// Unless they are unpacked, never show hosted apps. Note: We intentionally
// show packaged apps and platform apps because there are some pieces of
// functionality that are only available in chrome://extensions/ but which
// are needed for packaged and platform apps. For example, inspecting
// background pages. See http://crbug.com/116134.
if (extension->is_hosted_app())
return false;
return true;
}
} // namespace
///////////////////////////////////////////////////////////////////////////////
//
// ExtensionSettingsHandler
......@@ -467,7 +436,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
const ExtensionSet* extensions = extension_service_->extensions();
for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
if ((*extension)->ShouldDisplayInExtensionSettings()) {
extensions_list->Append(CreateExtensionDetailValue(
*extension,
GetInspectablePagesForExtension(*extension, true),
......@@ -477,7 +446,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
extensions = extension_service_->disabled_extensions();
for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
if ((*extension)->ShouldDisplayInExtensionSettings()) {
extensions_list->Append(CreateExtensionDetailValue(
*extension,
GetInspectablePagesForExtension(*extension, false),
......@@ -488,7 +457,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
std::vector<ExtensionPage> empty_pages;
for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
if ((*extension)->ShouldDisplayInExtensionSettings()) {
extensions_list->Append(CreateExtensionDetailValue(
*extension,
empty_pages, // Terminated process has no active pages.
......
......@@ -2334,6 +2334,22 @@ bool Extension::LoadBrowserAction(string16* error) {
return true;
}
void Extension::GenerateBrowserActionIfPossible() {
// It only makes sense to generate brower actions for extensions that are
// shown in chrome://extensions.
if (!ShouldDisplayInExtensionSettings())
return;
// Hosted and platform apps are shown in extension settings, but we don't
// want to generate browser actions for those either, since they can't define
// browser actions.
if (is_app())
return;
browser_action_.reset(new ExtensionAction(id()));
browser_action_->SetTitle(ExtensionAction::kDefaultTabId, name());
}
bool Extension::LoadFileBrowserHandlers(string16* error) {
if (!manifest_->HasKey(keys::kFileBrowserHandlers))
return true;
......@@ -3083,6 +3099,12 @@ bool Extension::InitFromValue(int flags, string16* error) {
if (!LoadThemeFeatures(error))
return false;
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserActionsForAll) &&
!browser_action()) {
GenerateBrowserActionIfPossible();
}
if (HasMultipleUISurfaces()) {
*error = ASCIIToUTF16(errors::kOneUISurfaceOnly);
return false;
......@@ -3647,6 +3669,33 @@ ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest,
extension_manifest.reset(manifest->DeepCopy());
}
bool Extension::ShouldDisplayInExtensionSettings() const {
// Don't show for themes since the settings UI isn't really useful for them.
if (is_theme())
return false;
// Don't show component extensions because they are only extensions as an
// implementation detail of Chrome.
if (location() == Extension::COMPONENT &&
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kShowComponentExtensionOptions))
return false;
// Always show unpacked extensions and apps.
if (location() == Extension::LOAD)
return true;
// Unless they are unpacked, never show hosted apps. Note: We intentionally
// show packaged apps and platform apps because there are some pieces of
// functionality that are only available in chrome://extensions/ but which
// are needed for packaged and platform apps. For example, inspecting
// background pages. See http://crbug.com/116134.
if (is_hosted_app())
return false;
return true;
}
ExtensionInfo::~ExtensionInfo() {}
Extension::RuntimeData::RuntimeData() {}
......
......@@ -558,6 +558,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Returns true if the extension should be displayed in the launcher.
bool ShouldDisplayInLauncher() const;
// Returns true if the extension should be displayed in the extension
// settings page (i.e. chrome://extensions).
bool ShouldDisplayInExtensionSettings() const;
// Accessors:
const FilePath& path() const { return path_; }
......@@ -786,6 +790,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
bool LoadContentScripts(string16* error);
bool LoadPageAction(string16* error);
bool LoadBrowserAction(string16* error);
void GenerateBrowserActionIfPossible();
bool LoadFileBrowserHandlers(string16* error);
// Helper method to load a FileBrowserHandlerList from the manifest.
FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment