summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_page_actions_module.cc
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 02:12:34 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 02:12:34 +0000
commit84954ce77558a87d6bd20d5691bbc4ce9bfb6887 (patch)
treee03a8bd4148aadf4d4880e73912c4f5398ad953c /chrome/browser/extensions/extension_page_actions_module.cc
parent70853b00ae4f3a0b3c96978cfa4a5caeabacb60b (diff)
downloadchromium_src-84954ce77558a87d6bd20d5691bbc4ce9bfb6887.zip
chromium_src-84954ce77558a87d6bd20d5691bbc4ce9bfb6887.tar.gz
chromium_src-84954ce77558a87d6bd20d5691bbc4ce9bfb6887.tar.bz2
Page actions that don't specify an icon (ie.
have a spelling error in the manifest, such as icon instead of icons/default_icon) caused a crash when they try to display their icon. We now check when the extension tries to enable the page action whether there are any icons to display. If not, we don't proceed and log an error to the console. BUG=25562 TEST=Covered by browser test. Review URL: http://codereview.chromium.org/316018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29861 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_page_actions_module.cc')
-rw-r--r--chrome/browser/extensions/extension_page_actions_module.cc31
1 files changed, 14 insertions, 17 deletions
diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc
index 743e0a5..4738891 100644
--- a/chrome/browser/extensions/extension_page_actions_module.cc
+++ b/chrome/browser/extensions/extension_page_actions_module.cc
@@ -21,12 +21,12 @@ namespace keys = extension_page_actions_module_constants;
namespace {
// Errors.
-const char kNoExtensionError[] = "No extension with id: *.";
const char kNoTabError[] = "No tab with id: *.";
const char kNoPageActionError[] =
"This extension has no page action specified.";
const char kUrlNotActiveError[] = "This url is no longer active: *.";
const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds.";
+const char kNoIconSpecified[] = "Page action has no icons to show.";
}
// TODO(EXTENSIONS_DEPRECATED): obsolete API.
@@ -56,6 +56,19 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) {
}
}
+ const ExtensionAction* page_action =
+ dispatcher()->GetExtension()->page_action();
+ if (!page_action) {
+ error_ = kNoPageActionError;
+ return false;
+ }
+
+ if (icon_id < 0 ||
+ static_cast<size_t>(icon_id) >= page_action->icon_paths().size()) {
+ error_ = (icon_id == 0) ? kNoIconSpecified : kIconIndexOutOfBounds;
+ return false;
+ }
+
// Find the TabContents that contains this tab id.
TabContents* contents = NULL;
ExtensionTabUtil::GetTabById(tab_id, profile(), NULL, NULL, &contents, NULL);
@@ -72,22 +85,6 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) {
return false;
}
- // Find our extension.
- Extension* extension = NULL;
- ExtensionsService* service = profile()->GetExtensionsService();
- extension = service->GetExtensionById(extension_id());
- if (!extension) {
- error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
- extension_id());
- return false;
- }
-
- const ExtensionAction* page_action = extension->page_action();
- if (!page_action) {
- error_ = kNoPageActionError;
- return false;
- }
-
// Set visibility and broadcast notifications that the UI should be updated.
contents->SetPageActionEnabled(page_action, enable, title, icon_id);
contents->PageActionStateChanged();