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

Side by Side Diff: chrome/browser/extensions/extension_page_actions_module.cc

Issue 6693054: Get rid of extensions dependency from content\browser. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extension_page_actions_module.h" 5 #include "chrome/browser/extensions/extension_page_actions_module.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/browser_list.h" 10 #include "chrome/browser/browser_list.h"
11 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" 11 #include "chrome/browser/extensions/extension_page_actions_module_constants.h"
12 #include "chrome/browser/extensions/extension_tab_helper.h"
12 #include "chrome/browser/extensions/extension_tabs_module.h" 13 #include "chrome/browser/extensions/extension_tabs_module.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_action.h" 18 #include "chrome/common/extensions/extension_action.h"
18 #include "chrome/common/extensions/extension_error_utils.h" 19 #include "chrome/common/extensions/extension_error_utils.h"
19 #include "chrome/common/render_messages.h" 20 #include "chrome/common/render_messages.h"
20 #include "content/browser/tab_contents/navigation_entry.h" 21 #include "content/browser/tab_contents/navigation_entry.h"
21 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 NavigationEntry* entry = contents->controller().GetActiveEntry(); 83 NavigationEntry* entry = contents->controller().GetActiveEntry();
83 if (!entry || url != entry->url().spec()) { 84 if (!entry || url != entry->url().spec()) {
84 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); 85 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url);
85 return false; 86 return false;
86 } 87 }
87 88
88 // Set visibility and broadcast notifications that the UI should be updated. 89 // Set visibility and broadcast notifications that the UI should be updated.
89 page_action->SetIsVisible(tab_id, enable); 90 page_action->SetIsVisible(tab_id, enable);
90 page_action->SetTitle(tab_id, title); 91 page_action->SetTitle(tab_id, title);
91 page_action->SetIconIndex(tab_id, icon_id); 92 page_action->SetIconIndex(tab_id, icon_id);
92 contents->tab_contents()->PageActionStateChanged(); 93 contents->extension_tab_helper()->PageActionStateChanged();
93 94
94 return true; 95 return true;
95 } 96 }
96 97
97 bool PageActionFunction::InitCommon(int tab_id) { 98 bool PageActionFunction::InitCommon(int tab_id) {
98 page_action_ = GetExtension()->page_action(); 99 page_action_ = GetExtension()->page_action();
99 if (!page_action_) { 100 if (!page_action_) {
100 error_ = kNoPageActionError; 101 error_ = kNoPageActionError;
101 return false; 102 return false;
102 } 103 }
103 104
104 // Find the TabContents that contains this tab id. 105 // Find the TabContents that contains this tab id.
105 contents_ = NULL; 106 contents_ = NULL;
106 TabContentsWrapper* wrapper = NULL; 107 TabContentsWrapper* wrapper = NULL;
107 bool result = ExtensionTabUtil::GetTabById( 108 bool result = ExtensionTabUtil::GetTabById(
108 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL); 109 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL);
109 if (!result || !wrapper) { 110 if (!result || !wrapper) {
110 error_ = ExtensionErrorUtils::FormatErrorMessage( 111 error_ = ExtensionErrorUtils::FormatErrorMessage(
111 kNoTabError, base::IntToString(tab_id)); 112 kNoTabError, base::IntToString(tab_id));
112 return false; 113 return false;
113 } 114 }
114 contents_ = wrapper->tab_contents(); 115 contents_ = wrapper;
115 116
116 return true; 117 return true;
117 } 118 }
118 119
119 bool PageActionFunction::SetVisible(bool visible) { 120 bool PageActionFunction::SetVisible(bool visible) {
120 int tab_id; 121 int tab_id;
121 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 122 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
122 if (!InitCommon(tab_id)) 123 if (!InitCommon(tab_id))
123 return false; 124 return false;
124 125
125 page_action_->SetIsVisible(tab_id, visible); 126 page_action_->SetIsVisible(tab_id, visible);
126 contents_->PageActionStateChanged(); 127 contents_->extension_tab_helper()->PageActionStateChanged();
127 return true; 128 return true;
128 } 129 }
129 130
130 bool EnablePageActionFunction::RunImpl() { 131 bool EnablePageActionFunction::RunImpl() {
131 return SetPageActionEnabled(true); 132 return SetPageActionEnabled(true);
132 } 133 }
133 134
134 bool DisablePageActionFunction::RunImpl() { 135 bool DisablePageActionFunction::RunImpl() {
135 return SetPageActionEnabled(false); 136 return SetPageActionEnabled(false);
136 } 137 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 page_action_->icon_paths()->size()) { 169 page_action_->icon_paths()->size()) {
169 error_ = kIconIndexOutOfBounds; 170 error_ = kIconIndexOutOfBounds;
170 return false; 171 return false;
171 } 172 }
172 page_action_->SetIcon(tab_id, SkBitmap()); 173 page_action_->SetIcon(tab_id, SkBitmap());
173 page_action_->SetIconIndex(tab_id, icon_index); 174 page_action_->SetIconIndex(tab_id, icon_index);
174 } else { 175 } else {
175 EXTENSION_FUNCTION_VALIDATE(false); 176 EXTENSION_FUNCTION_VALIDATE(false);
176 } 177 }
177 178
178 contents_->PageActionStateChanged(); 179 contents_->extension_tab_helper()->PageActionStateChanged();
179 return true; 180 return true;
180 } 181 }
181 182
182 bool PageActionSetTitleFunction::RunImpl() { 183 bool PageActionSetTitleFunction::RunImpl() {
183 DictionaryValue* args; 184 DictionaryValue* args;
184 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 185 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
185 186
186 int tab_id; 187 int tab_id;
187 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id)); 188 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id));
188 if (!InitCommon(tab_id)) 189 if (!InitCommon(tab_id))
189 return false; 190 return false;
190 191
191 std::string title; 192 std::string title;
192 EXTENSION_FUNCTION_VALIDATE(args->GetString("title", &title)); 193 EXTENSION_FUNCTION_VALIDATE(args->GetString("title", &title));
193 194
194 page_action_->SetTitle(tab_id, title); 195 page_action_->SetTitle(tab_id, title);
195 contents_->PageActionStateChanged(); 196 contents_->extension_tab_helper()->PageActionStateChanged();
196 return true; 197 return true;
197 } 198 }
198 199
199 bool PageActionSetPopupFunction::RunImpl() { 200 bool PageActionSetPopupFunction::RunImpl() {
200 DictionaryValue* args; 201 DictionaryValue* args;
201 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 202 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
202 203
203 int tab_id; 204 int tab_id;
204 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id)); 205 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id));
205 if (!InitCommon(tab_id)) 206 if (!InitCommon(tab_id))
206 return false; 207 return false;
207 208
208 // TODO(skerner): Consider allowing null and undefined to mean the popup 209 // TODO(skerner): Consider allowing null and undefined to mean the popup
209 // should be removed. 210 // should be removed.
210 std::string popup_string; 211 std::string popup_string;
211 EXTENSION_FUNCTION_VALIDATE(args->GetString("popup", &popup_string)); 212 EXTENSION_FUNCTION_VALIDATE(args->GetString("popup", &popup_string));
212 213
213 GURL popup_url; 214 GURL popup_url;
214 if (!popup_string.empty()) 215 if (!popup_string.empty())
215 popup_url = GetExtension()->GetResourceURL(popup_string); 216 popup_url = GetExtension()->GetResourceURL(popup_string);
216 217
217 page_action_->SetPopupUrl(tab_id, popup_url); 218 page_action_->SetPopupUrl(tab_id, popup_url);
218 contents_->PageActionStateChanged(); 219 contents_->extension_tab_helper()->PageActionStateChanged();
219 return true; 220 return true;
220 } 221 }
221 222
222 // Not currently exposed to extensions. To re-enable, add mapping in 223 // Not currently exposed to extensions. To re-enable, add mapping in
223 // extension_function_dispatcher. 224 // extension_function_dispatcher.
224 bool PageActionSetBadgeBackgroundColorFunction::RunImpl() { 225 bool PageActionSetBadgeBackgroundColorFunction::RunImpl() {
225 DictionaryValue* args; 226 DictionaryValue* args;
226 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 227 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
227 228
228 int tab_id; 229 int tab_id;
229 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id)); 230 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id));
230 if (!InitCommon(tab_id)) 231 if (!InitCommon(tab_id))
231 return false; 232 return false;
232 233
233 ListValue* color_value; 234 ListValue* color_value;
234 EXTENSION_FUNCTION_VALIDATE(args->GetList("color", &color_value)); 235 EXTENSION_FUNCTION_VALIDATE(args->GetList("color", &color_value));
235 EXTENSION_FUNCTION_VALIDATE(color_value->GetSize() == 4); 236 EXTENSION_FUNCTION_VALIDATE(color_value->GetSize() == 4);
236 237
237 int color_array[4] = {0}; 238 int color_array[4] = {0};
238 for (size_t i = 0; i < arraysize(color_array); ++i) 239 for (size_t i = 0; i < arraysize(color_array); ++i)
239 EXTENSION_FUNCTION_VALIDATE(color_value->GetInteger(i, &color_array[i])); 240 EXTENSION_FUNCTION_VALIDATE(color_value->GetInteger(i, &color_array[i]));
240 241
241 SkColor color = SkColorSetARGB(color_array[3], color_array[0], color_array[1], 242 SkColor color = SkColorSetARGB(color_array[3], color_array[0], color_array[1],
242 color_array[2]); 243 color_array[2]);
243 page_action_->SetBadgeBackgroundColor(tab_id, color); 244 page_action_->SetBadgeBackgroundColor(tab_id, color);
244 contents_->PageActionStateChanged(); 245 contents_->extension_tab_helper()->PageActionStateChanged();
245 return true; 246 return true;
246 } 247 }
247 248
248 // Not currently exposed to extensions. To re-enable, add mapping in 249 // Not currently exposed to extensions. To re-enable, add mapping in
249 // extension_function_dispatcher. 250 // extension_function_dispatcher.
250 bool PageActionSetBadgeTextColorFunction::RunImpl() { 251 bool PageActionSetBadgeTextColorFunction::RunImpl() {
251 DictionaryValue* args; 252 DictionaryValue* args;
252 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 253 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
253 254
254 int tab_id; 255 int tab_id;
255 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id)); 256 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id));
256 if (!InitCommon(tab_id)) 257 if (!InitCommon(tab_id))
257 return false; 258 return false;
258 259
259 ListValue* color_value; 260 ListValue* color_value;
260 EXTENSION_FUNCTION_VALIDATE(args->GetList("color", &color_value)); 261 EXTENSION_FUNCTION_VALIDATE(args->GetList("color", &color_value));
261 EXTENSION_FUNCTION_VALIDATE(color_value->GetSize() == 4); 262 EXTENSION_FUNCTION_VALIDATE(color_value->GetSize() == 4);
262 263
263 int color_array[4] = {0}; 264 int color_array[4] = {0};
264 for (size_t i = 0; i < arraysize(color_array); ++i) 265 for (size_t i = 0; i < arraysize(color_array); ++i)
265 EXTENSION_FUNCTION_VALIDATE(color_value->GetInteger(i, &color_array[i])); 266 EXTENSION_FUNCTION_VALIDATE(color_value->GetInteger(i, &color_array[i]));
266 267
267 SkColor color = SkColorSetARGB(color_array[3], color_array[0], color_array[1], 268 SkColor color = SkColorSetARGB(color_array[3], color_array[0], color_array[1],
268 color_array[2]); 269 color_array[2]);
269 page_action_->SetBadgeTextColor(tab_id, color); 270 page_action_->SetBadgeTextColor(tab_id, color);
270 contents_->PageActionStateChanged(); 271 contents_->extension_tab_helper()->PageActionStateChanged();
271 return true; 272 return true;
272 } 273 }
273 274
274 // Not currently exposed to extensions. To re-enable, add mapping in 275 // Not currently exposed to extensions. To re-enable, add mapping in
275 // extension_function_dispatcher. 276 // extension_function_dispatcher.
276 bool PageActionSetBadgeTextFunction::RunImpl() { 277 bool PageActionSetBadgeTextFunction::RunImpl() {
277 DictionaryValue* args; 278 DictionaryValue* args;
278 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 279 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
279 280
280 int tab_id; 281 int tab_id;
281 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id)); 282 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id));
282 if (!InitCommon(tab_id)) 283 if (!InitCommon(tab_id))
283 return false; 284 return false;
284 285
285 std::string text; 286 std::string text;
286 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text)); 287 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text));
287 288
288 page_action_->SetBadgeText(tab_id, text); 289 page_action_->SetBadgeText(tab_id, text);
289 contents_->PageActionStateChanged(); 290 contents_->extension_tab_helper()->PageActionStateChanged();
290 return true; 291 return true;
291 } 292 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_page_actions_module.h ('k') | chrome/browser/extensions/extension_startup_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698