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