Commit 97008dbc authored by cduvall@chromium.org's avatar cduvall@chromium.org

Fixed pageActions.enableForTab

pageActions.enableForTab was using the same framework as the newer pageAction
API, which expects a tab ID for the first argument.

BUG=122833
TEST=Load the extension from the bug.


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132321 0039d316-1c4b-4281-b951-d872f2087c98
parent fd162f77
...@@ -34,6 +34,12 @@ const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds."; ...@@ -34,6 +34,12 @@ const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds.";
const char kNoIconSpecified[] = "Page action has no icons to show."; const char kNoIconSpecified[] = "Page action has no icons to show.";
} }
PageActionsFunction::PageActionsFunction() {
}
PageActionsFunction::~PageActionsFunction() {
}
bool PageActionFunction::RunImpl() { bool PageActionFunction::RunImpl() {
ExtensionActionFunction::RunImpl(); ExtensionActionFunction::RunImpl();
...@@ -67,12 +73,14 @@ bool PageActionFunction::RunImpl() { ...@@ -67,12 +73,14 @@ bool PageActionFunction::RunImpl() {
return true; return true;
} }
bool PageActionFunction::SetPageActionEnabled(bool enable) { bool PageActionsFunction::SetPageActionEnabled(bool enable) {
std::string extension_action_id; std::string extension_action_id;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_action_id)); EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_action_id));
DictionaryValue* action = NULL; DictionaryValue* action = NULL;
EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action)); EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kTabIdKey, &tab_id));
std::string url; std::string url;
EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url)); EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url));
...@@ -103,10 +111,10 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) { ...@@ -103,10 +111,10 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) {
// Find the TabContents that contains this tab id. // Find the TabContents that contains this tab id.
TabContentsWrapper* contents = NULL; TabContentsWrapper* contents = NULL;
bool result = ExtensionTabUtil::GetTabById( bool result = ExtensionTabUtil::GetTabById(
tab_id_, profile(), include_incognito(), NULL, NULL, &contents, NULL); tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL);
if (!result || !contents) { if (!result || !contents) {
error_ = ExtensionErrorUtils::FormatErrorMessage( error_ = ExtensionErrorUtils::FormatErrorMessage(
kNoTabError, base::IntToString(tab_id_)); kNoTabError, base::IntToString(tab_id));
return false; return false;
} }
...@@ -119,9 +127,9 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) { ...@@ -119,9 +127,9 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) {
} }
// Set visibility and broadcast notifications that the UI should be updated. // Set visibility and broadcast notifications that the UI should be updated.
page_action->SetIsVisible(tab_id_, enable); page_action->SetIsVisible(tab_id, enable);
page_action->SetTitle(tab_id_, title); page_action->SetTitle(tab_id, title);
page_action->SetIconIndex(tab_id_, icon_id); page_action->SetIconIndex(tab_id, icon_id);
contents->extension_tab_helper()->PageActionStateChanged(); contents->extension_tab_helper()->PageActionStateChanged();
return true; return true;
...@@ -133,11 +141,11 @@ bool PageActionFunction::SetVisible(bool visible) { ...@@ -133,11 +141,11 @@ bool PageActionFunction::SetVisible(bool visible) {
return true; return true;
} }
bool EnablePageActionFunction::RunExtensionAction() { bool EnablePageActionsFunction::RunImpl() {
return SetPageActionEnabled(true); return SetPageActionEnabled(true);
} }
bool DisablePageActionFunction::RunExtensionAction() { bool DisablePageActionsFunction::RunImpl() {
return SetPageActionEnabled(false); return SetPageActionEnabled(false);
} }
......
...@@ -15,70 +15,77 @@ class TabContentsWrapper; ...@@ -15,70 +15,77 @@ class TabContentsWrapper;
class PageActionFunction : public ExtensionActionFunction { class PageActionFunction : public ExtensionActionFunction {
protected: protected:
virtual ~PageActionFunction() {} virtual ~PageActionFunction() {}
bool SetPageActionEnabled(bool enable);
bool SetVisible(bool visible); bool SetVisible(bool visible);
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
TabContentsWrapper* contents_; TabContentsWrapper* contents_;
}; };
// Base class for deprecated page actions APIs
class PageActionsFunction : public SyncExtensionFunction {
protected:
PageActionsFunction();
virtual ~PageActionsFunction();
bool SetPageActionEnabled(bool enable);
};
// Implement chrome.pageActions.enableForTab(). // Implement chrome.pageActions.enableForTab().
class EnablePageActionFunction : public PageActionFunction { class EnablePageActionsFunction : public PageActionsFunction {
virtual ~EnablePageActionFunction() {} virtual ~EnablePageActionsFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageActions.enableForTab") DECLARE_EXTENSION_FUNCTION_NAME("pageActions.enableForTab")
}; };
// Implement chrome.pageActions.disableForTab(). // Implement chrome.pageActions.disableForTab().
class DisablePageActionFunction : public PageActionFunction { class DisablePageActionsFunction : public PageActionsFunction {
virtual ~DisablePageActionFunction() {} virtual ~DisablePageActionsFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageActions.disableForTab") DECLARE_EXTENSION_FUNCTION_NAME("pageActions.disableForTab")
}; };
// Implement chrome.pageActions.show(). // Implement chrome.pageAction.show().
class PageActionShowFunction : public PageActionFunction { class PageActionShowFunction : public PageActionFunction {
virtual ~PageActionShowFunction() {} virtual ~PageActionShowFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageAction.show") DECLARE_EXTENSION_FUNCTION_NAME("pageAction.show")
}; };
// Implement chrome.pageActions.hide(). // Implement chrome.pageAction.hide().
class PageActionHideFunction : public PageActionFunction { class PageActionHideFunction : public PageActionFunction {
virtual ~PageActionHideFunction() {} virtual ~PageActionHideFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageAction.hide") DECLARE_EXTENSION_FUNCTION_NAME("pageAction.hide")
}; };
// Implement chrome.pageActions.setIcon(). // Implement chrome.pageAction.setIcon().
class PageActionSetIconFunction : public PageActionFunction { class PageActionSetIconFunction : public PageActionFunction {
virtual ~PageActionSetIconFunction() {} virtual ~PageActionSetIconFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setIcon") DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setIcon")
}; };
// Implement chrome.pageActions.setTitle(). // Implement chrome.pageAction.setTitle().
class PageActionSetTitleFunction : public PageActionFunction { class PageActionSetTitleFunction : public PageActionFunction {
virtual ~PageActionSetTitleFunction() {} virtual ~PageActionSetTitleFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setTitle") DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setTitle")
}; };
// Implement chrome.pageActions.setPopup(). // Implement chrome.pageAction.setPopup().
class PageActionSetPopupFunction : public PageActionFunction { class PageActionSetPopupFunction : public PageActionFunction {
virtual ~PageActionSetPopupFunction() {} virtual ~PageActionSetPopupFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setPopup") DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setPopup")
}; };
// Implement chrome.pageActions.setBadgeBackgroundColor(). // Implement chrome.pageAction.setBadgeBackgroundColor().
class PageActionSetBadgeBackgroundColorFunction : public PageActionFunction { class PageActionSetBadgeBackgroundColorFunction : public PageActionFunction {
virtual ~PageActionSetBadgeBackgroundColorFunction() {} virtual ~PageActionSetBadgeBackgroundColorFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setBadgeBackgroundColor") DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setBadgeBackgroundColor")
}; };
// Implement chrome.pageActions.setBadgeTextColor(). // Implement chrome.pageAction.setBadgeTextColor().
class PageActionSetBadgeTextColorFunction : public PageActionFunction { class PageActionSetBadgeTextColorFunction : public PageActionFunction {
virtual ~PageActionSetBadgeTextColorFunction() {} virtual ~PageActionSetBadgeTextColorFunction() {}
virtual bool RunExtensionAction() OVERRIDE; virtual bool RunExtensionAction() OVERRIDE;
......
...@@ -121,8 +121,8 @@ void ExtensionFunctionRegistry::ResetFunctions() { ...@@ -121,8 +121,8 @@ void ExtensionFunctionRegistry::ResetFunctions() {
RegisterFunction<TabsInsertCSSFunction>(); RegisterFunction<TabsInsertCSSFunction>();
// Page Actions. // Page Actions.
RegisterFunction<EnablePageActionFunction>(); RegisterFunction<EnablePageActionsFunction>();
RegisterFunction<DisablePageActionFunction>(); RegisterFunction<DisablePageActionsFunction>();
RegisterFunction<PageActionShowFunction>(); RegisterFunction<PageActionShowFunction>();
RegisterFunction<PageActionHideFunction>(); RegisterFunction<PageActionHideFunction>();
RegisterFunction<PageActionSetIconFunction>(); RegisterFunction<PageActionSetIconFunction>();
......
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