diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 21:23:24 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 21:23:24 +0000 |
commit | d7240f6f223109095bc64589d313a1331c445689 (patch) | |
tree | 80051f382116e9a2a7ce9a49e0f1a9fb4a24dca8 /chrome/browser/extensions/extension_page_actions_module.cc | |
parent | 6277eaded1883e224015efcc5456e3c265e8b633 (diff) | |
download | chromium_src-d7240f6f223109095bc64589d313a1331c445689.zip chromium_src-d7240f6f223109095bc64589d313a1331c445689.tar.gz chromium_src-d7240f6f223109095bc64589d313a1331c445689.tar.bz2 |
Add error handling to PageAction extension API.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/113415
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16101 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.cc | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc index bf23f65..d1fa723 100644 --- a/chrome/browser/extensions/extension_page_actions_module.cc +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -8,10 +8,19 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/profile.h" #include "chrome/browser/extensions/extension.h" +#include "chrome/browser/extensions/extension_error_utils.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/tab_contents/navigation_entry.h" +namespace { + // Error messages. + const char* kNoExtensionError = "No extension with id: *."; + const char* kNoTabError = "No tab with id: *."; + const char* kNoPageActionError = "No PageAction with id: *."; + const char* kUrlNotActiveError = "This url is no longer active: *."; +} + bool EnablePageActionFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); const ListValue* args = static_cast<const ListValue*>(args_); @@ -29,27 +38,34 @@ bool EnablePageActionFunction::RunImpl() { // Find the TabContents that contains this tab id. TabContents* contents = NULL; ExtensionTabUtil::GetTabById(tab_id, profile(), NULL, NULL, &contents, NULL); - if (!contents) + if (!contents) { + error_ = ExtensionErrorUtils::FormatErrorMessage(kNoTabError, + IntToString(tab_id)); return false; + } // Make sure the URL hasn't changed. - // TODO(finnur): Add an error message here when there is a way to. - if (url != contents->controller().GetActiveEntry()->url().spec()) + if (url != contents->controller().GetActiveEntry()->url().spec()) { + error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); return false; + } // Find our extension. Extension* extension = NULL; ExtensionsService* service = profile()->GetExtensionsService(); - if (service) - extension = service->GetExtensionByID(extension_id()); - else - NOTREACHED(); - if (!extension) + extension = service->GetExtensionByID(extension_id()); + if (!extension) { + error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError, + extension_id()); return false; + } const PageAction* page_action = extension->GetPageAction(page_action_id); - if (!page_action) + if (!page_action) { + error_ = ExtensionErrorUtils::FormatErrorMessage(kNoPageActionError, + page_action_id); return false; + } // Set visible and broadcast notifications that the UI should be updated. contents->EnablePageAction(page_action); |