Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc

Issue 10034037: Fixed pageActions.enableForTab (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api.h" 5 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" 10 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return false; 60 return false;
61 } 61 }
62 contents_ = wrapper; 62 contents_ = wrapper;
63 63
64 if (!RunExtensionAction()) 64 if (!RunExtensionAction())
65 return false; 65 return false;
66 66
67 return true; 67 return true;
68 } 68 }
69 69
70 bool PageActionFunction::SetPageActionEnabled(bool enable) { 70 bool PageActionsFunction::SetPageActionEnabled(bool enable) {
71 std::string extension_action_id; 71 std::string extension_action_id;
72 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_action_id)); 72 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_action_id));
73 DictionaryValue* action = NULL; 73 DictionaryValue* action = NULL;
74 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action)); 74 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action));
75 75
76 int tab_id;
77 EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kTabIdKey, &tab_id));
76 std::string url; 78 std::string url;
77 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url)); 79 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url));
78 80
79 std::string title; 81 std::string title;
80 int icon_id = 0; 82 int icon_id = 0;
81 if (enable) { 83 if (enable) {
82 // Both of those are optional. 84 // Both of those are optional.
83 if (action->HasKey(keys::kTitleKey)) 85 if (action->HasKey(keys::kTitleKey))
84 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kTitleKey, &title)); 86 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kTitleKey, &title));
85 if (action->HasKey(keys::kIconIdKey)) { 87 if (action->HasKey(keys::kIconIdKey)) {
(...skipping 10 matching lines...) Expand all
96 98
97 if (icon_id < 0 || 99 if (icon_id < 0 ||
98 static_cast<size_t>(icon_id) >= page_action->icon_paths()->size()) { 100 static_cast<size_t>(icon_id) >= page_action->icon_paths()->size()) {
99 error_ = (icon_id == 0) ? kNoIconSpecified : kIconIndexOutOfBounds; 101 error_ = (icon_id == 0) ? kNoIconSpecified : kIconIndexOutOfBounds;
100 return false; 102 return false;
101 } 103 }
102 104
103 // Find the TabContents that contains this tab id. 105 // Find the TabContents that contains this tab id.
104 TabContentsWrapper* contents = NULL; 106 TabContentsWrapper* contents = NULL;
105 bool result = ExtensionTabUtil::GetTabById( 107 bool result = ExtensionTabUtil::GetTabById(
106 tab_id_, profile(), include_incognito(), NULL, NULL, &contents, NULL); 108 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL);
107 if (!result || !contents) { 109 if (!result || !contents) {
108 error_ = ExtensionErrorUtils::FormatErrorMessage( 110 error_ = ExtensionErrorUtils::FormatErrorMessage(
109 kNoTabError, base::IntToString(tab_id_)); 111 kNoTabError, base::IntToString(tab_id));
110 return false; 112 return false;
111 } 113 }
112 114
113 // Make sure the URL hasn't changed. 115 // Make sure the URL hasn't changed.
114 NavigationEntry* entry = 116 NavigationEntry* entry =
115 contents->web_contents()->GetController().GetActiveEntry(); 117 contents->web_contents()->GetController().GetActiveEntry();
116 if (!entry || url != entry->GetURL().spec()) { 118 if (!entry || url != entry->GetURL().spec()) {
117 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); 119 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url);
118 return false; 120 return false;
119 } 121 }
120 122
121 // Set visibility and broadcast notifications that the UI should be updated. 123 // Set visibility and broadcast notifications that the UI should be updated.
122 page_action->SetIsVisible(tab_id_, enable); 124 page_action->SetIsVisible(tab_id, enable);
123 page_action->SetTitle(tab_id_, title); 125 page_action->SetTitle(tab_id, title);
124 page_action->SetIconIndex(tab_id_, icon_id); 126 page_action->SetIconIndex(tab_id, icon_id);
125 contents->extension_tab_helper()->PageActionStateChanged(); 127 contents->extension_tab_helper()->PageActionStateChanged();
126 128
127 return true; 129 return true;
128 } 130 }
129 131
130 bool PageActionFunction::SetVisible(bool visible) { 132 bool PageActionFunction::SetVisible(bool visible) {
131 extension_action_->SetIsVisible(tab_id_, visible); 133 extension_action_->SetIsVisible(tab_id_, visible);
132 contents_->extension_tab_helper()->PageActionStateChanged(); 134 contents_->extension_tab_helper()->PageActionStateChanged();
133 return true; 135 return true;
134 } 136 }
135 137
136 bool EnablePageActionFunction::RunExtensionAction() { 138 PageActionsFunction::PageActionsFunction() {
Aaron Boodman 2012/04/13 22:52:52 can you move the constructor and destructor impls
cduvall 2012/04/13 22:59:19 Done.
139 }
140
141 PageActionsFunction::~PageActionsFunction() {
142 }
143
144 bool EnablePageActionsFunction::RunImpl() {
137 return SetPageActionEnabled(true); 145 return SetPageActionEnabled(true);
138 } 146 }
139 147
140 bool DisablePageActionFunction::RunExtensionAction() { 148 bool DisablePageActionsFunction::RunImpl() {
141 return SetPageActionEnabled(false); 149 return SetPageActionEnabled(false);
142 } 150 }
143 151
144 bool PageActionShowFunction::RunExtensionAction() { 152 bool PageActionShowFunction::RunExtensionAction() {
145 return SetVisible(true); 153 return SetVisible(true);
146 } 154 }
147 155
148 bool PageActionHideFunction::RunExtensionAction() { 156 bool PageActionHideFunction::RunExtensionAction() {
149 return SetVisible(false); 157 return SetVisible(false);
150 } 158 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // extension_function_dispatcher. 243 // extension_function_dispatcher.
236 bool PageActionGetBadgeBackgroundColorFunction::RunExtensionAction() { 244 bool PageActionGetBadgeBackgroundColorFunction::RunExtensionAction() {
237 return GetBadgeBackgroundColor(); 245 return GetBadgeBackgroundColor();
238 } 246 }
239 247
240 // Not currently exposed to extensions. To re-enable, add mapping in 248 // Not currently exposed to extensions. To re-enable, add mapping in
241 // extension_function_dispatcher. 249 // extension_function_dispatcher.
242 bool PageActionGetBadgeTextFunction::RunExtensionAction() { 250 bool PageActionGetBadgeTextFunction::RunExtensionAction() {
243 return GetBadgeText(); 251 return GetBadgeText();
244 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698