summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-17 05:55:32 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-17 05:55:32 +0000
commitc690a981436bb6a6d69ab8df959ffa5b116bf356 (patch)
treedfb4134472778bdb6409679faec3fea2e4946633 /chrome/browser/extensions
parent5d39e314de21a384eaa226d4875b6a6e8e1bea17 (diff)
downloadchromium_src-c690a981436bb6a6d69ab8df959ffa5b116bf356.zip
chromium_src-c690a981436bb6a6d69ab8df959ffa5b116bf356.tar.gz
chromium_src-c690a981436bb6a6d69ab8df959ffa5b116bf356.tar.bz2
Add the right-click context menu for Browser actions and Page Actions.
BUG=29538 TEST=Right-click an extension icon and make sure all the options work for both Page and Browser actions (Options should be grayed out when there is no Options page specified in the manifest). Review URL: http://codereview.chromium.org/486022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/crx_installer.cc41
-rw-r--r--chrome/browser/extensions/crx_installer.h5
-rw-r--r--chrome/browser/extensions/extension_action_context_menu_model.cc105
-rw-r--r--chrome/browser/extensions/extension_action_context_menu_model.h40
-rw-r--r--chrome/browser/extensions/extension_disabled_infobar_delegate.cc4
-rw-r--r--chrome/browser/extensions/extensions_ui.cc5
6 files changed, 151 insertions, 49 deletions
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc
index bfd6ef4..ca01297 100644
--- a/chrome/browser/extensions/crx_installer.cc
+++ b/chrome/browser/extensions/crx_installer.cc
@@ -18,7 +18,6 @@
#include "chrome/common/notification_type.h"
#include "grit/chromium_strings.h"
#include "third_party/skia/include/core/SkBitmap.h"
-#include "webkit/glue/image_decoder.h"
namespace {
// Helper function to delete files. This is used to avoid ugly casts which
@@ -155,50 +154,14 @@ void CrxInstaller::OnUnpackSuccess(const FilePath& temp_dir,
}
if (client_.get()) {
- FilePath icon_path =
- extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE).GetFilePath();
- DecodeInstallIcon(icon_path, &install_icon_);
+ Extension::DecodeIcon(extension_.get(), Extension::EXTENSION_ICON_LARGE,
+ &install_icon_);
}
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &CrxInstaller::ConfirmInstall));
}
-// static
-void CrxInstaller::DecodeInstallIcon(const FilePath& large_icon_path,
- scoped_ptr<SkBitmap>* result) {
- if (large_icon_path.empty())
- return;
-
- std::string file_contents;
- if (!file_util::ReadFileToString(large_icon_path, &file_contents)) {
- LOG(ERROR) << "Could not read icon file: "
- << WideToUTF8(large_icon_path.ToWStringHack());
- return;
- }
-
- // Decode the image using WebKit's image decoder.
- const unsigned char* data =
- reinterpret_cast<const unsigned char*>(file_contents.data());
- webkit_glue::ImageDecoder decoder;
- scoped_ptr<SkBitmap> decoded(new SkBitmap());
- *decoded = decoder.Decode(data, file_contents.length());
- if (decoded->empty()) {
- LOG(ERROR) << "Could not decode icon file: "
- << WideToUTF8(large_icon_path.ToWStringHack());
- return;
- }
-
- if (decoded->width() != 128 || decoded->height() != 128) {
- LOG(ERROR) << "Icon file has unexpected size: "
- << IntToString(decoded->width()) << "x"
- << IntToString(decoded->height());
- return;
- }
-
- result->swap(decoded);
-}
-
void CrxInstaller::ConfirmInstall() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) {
diff --git a/chrome/browser/extensions/crx_installer.h b/chrome/browser/extensions/crx_installer.h
index 2f0843e..30f0cd5 100644
--- a/chrome/browser/extensions/crx_installer.h
+++ b/chrome/browser/extensions/crx_installer.h
@@ -71,11 +71,6 @@ class CrxInstaller
ExtensionsService* frontend,
ExtensionInstallUI* client);
- // Given the path to the large icon from an extension, read it if present and
- // decode it into result.
- static void DecodeInstallIcon(const FilePath& large_icon_path,
- scoped_ptr<SkBitmap>* result);
-
// ExtensionInstallUI::Delegate
virtual void InstallUIProceed();
virtual void InstallUIAbort();
diff --git a/chrome/browser/extensions/extension_action_context_menu_model.cc b/chrome/browser/extensions/extension_action_context_menu_model.cc
new file mode 100644
index 0000000..e2713f7
--- /dev/null
+++ b/chrome/browser/extensions/extension_action_context_menu_model.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2009 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_action_context_menu_model.h"
+
+#include "app/l10n_util.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/url_constants.h"
+#include "grit/generated_resources.h"
+
+enum MenuEntries {
+ NAME = 0,
+ CONFIGURE,
+ DISABLE,
+ UNINSTALL,
+ MANAGE,
+};
+
+ExtensionActionContextMenuModel::ExtensionActionContextMenuModel(
+ Extension* extension, ExtensionInstallUI::Delegate* delegate)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)),
+ extension_(extension),
+ delegate_(delegate) {
+ AddItem(NAME, ASCIIToUTF16(extension->name()));
+ AddSeparator();
+ AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS);
+ AddItemWithStringId(DISABLE, IDS_EXTENSIONS_DISABLE);
+ AddItemWithStringId(UNINSTALL, IDS_EXTENSIONS_UNINSTALL);
+ AddSeparator();
+
+ // TODO(finnur): It is too late in the process to do another round of
+ // translations, so we'll switch fully to IDS_MANAGE_EXTENSIONS after merging
+ // this to the beta branch. :/
+ std::string locale = g_browser_process->GetApplicationLocale();
+ if (locale.find_first_of("en-") == 0)
+ AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS);
+ else
+ AddItemWithStringId(MANAGE, IDS_SHOW_EXTENSIONS);
+}
+
+ExtensionActionContextMenuModel::~ExtensionActionContextMenuModel() {
+}
+
+bool ExtensionActionContextMenuModel::IsCommandIdChecked(int command_id) const {
+ return false;
+}
+
+bool ExtensionActionContextMenuModel::IsCommandIdEnabled(int command_id) const {
+ if (command_id == CONFIGURE)
+ return extension_->options_url().spec().length() > 0;
+ return true;
+}
+
+bool ExtensionActionContextMenuModel::GetAcceleratorForCommandId(
+ int command_id, menus::Accelerator* accelerator) {
+ return false;
+}
+
+void ExtensionActionContextMenuModel::ExecuteCommand(int command_id) {
+ // TODO(finnur): GetLastActive returns NULL in unit tests.
+ Browser* browser = BrowserList::GetLastActive();
+ Profile* profile = browser->profile();
+
+ switch (command_id) {
+ case NAME: {
+ GURL url(std::string(extension_urls::kGalleryBrowsePrefix) +
+ std::string("/detail/") + extension_->id());
+ browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
+ break;
+ }
+ case CONFIGURE:
+ DCHECK(!extension_->options_url().is_empty());
+ browser->OpenURL(extension_->options_url(), GURL(),
+ NEW_FOREGROUND_TAB, PageTransition::LINK);
+ break;
+ case DISABLE: {
+ ExtensionsService* extension_service = profile->GetExtensionsService();
+ extension_service->DisableExtension(extension_->id());
+ break;
+ }
+ case UNINSTALL: {
+ scoped_ptr<SkBitmap> uninstall_icon;
+ Extension::DecodeIcon(extension_, Extension::EXTENSION_ICON_LARGE,
+ &uninstall_icon);
+
+ ExtensionInstallUI client(profile);
+ client.ConfirmUninstall(delegate_, extension_, uninstall_icon.get());
+ break;
+ }
+ case MANAGE: {
+ browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(),
+ NEW_FOREGROUND_TAB, PageTransition::LINK);
+ break;
+ }
+ default:
+ NOTREACHED() << "Unknown option";
+ break;
+ }
+}
diff --git a/chrome/browser/extensions/extension_action_context_menu_model.h b/chrome/browser/extensions/extension_action_context_menu_model.h
new file mode 100644
index 0000000..62bfdc6
--- /dev/null
+++ b/chrome/browser/extensions/extension_action_context_menu_model.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2009 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_ACTION_CONTEXT_MENU_MODEL_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_
+
+#include "app/menus/simple_menu_model.h"
+#include "chrome/browser/extensions/extension_install_ui.h"
+
+class Extension;
+
+// The menu model for the context menu for extension action icons (browser and
+// page actions).
+class ExtensionActionContextMenuModel
+ : public menus::SimpleMenuModel,
+ public menus::SimpleMenuModel::Delegate {
+ public:
+ ExtensionActionContextMenuModel(Extension* extension,
+ ExtensionInstallUI::Delegate* delegate);
+ ~ExtensionActionContextMenuModel();
+
+ // SimpleMenuModel behavior overrides.
+ virtual bool IsCommandIdChecked(int command_id) const;
+ virtual bool IsCommandIdEnabled(int command_id) const;
+ virtual bool GetAcceleratorForCommandId(int command_id,
+ menus::Accelerator* accelerator);
+ virtual void ExecuteCommand(int command_id);
+
+ private:
+ // The extension we are displaying the context menu for.
+ Extension* extension_;
+
+ // The delegate that handles the extension Uninstall operation.
+ ExtensionInstallUI::Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionActionContextMenuModel);
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_
diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
index 54d2ed9..a1012c0 100644
--- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
@@ -6,7 +6,6 @@
#include "app/l10n_util.h"
#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_file_util.h"
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/extensions_service.h"
@@ -55,7 +54,8 @@ class ExtensionDisabledDialogDelegate
void Start() {
// We start on the file thread so we can decode the install icon.
FilePath install_icon_path = install_icon_resource_.GetFilePath();
- CrxInstaller::DecodeInstallIcon(install_icon_path, &install_icon_);
+ Extension::DecodeIconFromPath(
+ install_icon_path, Extension::EXTENSION_ICON_LARGE, &install_icon_);
// Then we display the UI on the UI thread.
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index b762d1f..a18cb7a 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -404,10 +404,9 @@ void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) {
if (!extension)
return;
- FilePath icon_path =
- extension->GetIconPath(Extension::EXTENSION_ICON_LARGE).GetFilePath();
scoped_ptr<SkBitmap> uninstall_icon;
- CrxInstaller::DecodeInstallIcon(icon_path, &uninstall_icon);
+ Extension::DecodeIcon(extension, Extension::EXTENSION_ICON_LARGE,
+ &uninstall_icon);
extension_id_uninstalling_ = extension_id;
ExtensionInstallUI client(dom_ui_->GetProfile());