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

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

Issue 11361189: Initial skeleton for System Indicator API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add manifest parsing and integrate with extension action api handlers. Created 8 years, 1 month 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_actions_api.h " 5 #include "chrome/browser/extensions/api/extension_action/extension_actions_api.h "
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 extension_action_(NULL) { 279 extension_action_(NULL) {
280 } 280 }
281 281
282 ExtensionActionFunction::~ExtensionActionFunction() { 282 ExtensionActionFunction::~ExtensionActionFunction() {
283 } 283 }
284 284
285 bool ExtensionActionFunction::RunImpl() { 285 bool ExtensionActionFunction::RunImpl() {
286 if (base::StringPiece(name()).starts_with("scriptBadge.")) { 286 if (base::StringPiece(name()).starts_with("scriptBadge.")) {
287 extension_action_ = extensions::ExtensionActionManager::Get(profile_)-> 287 extension_action_ = extensions::ExtensionActionManager::Get(profile_)->
288 GetScriptBadge(*GetExtension()); 288 GetScriptBadge(*GetExtension());
289 } else if (base::StringPiece(name()).starts_with("systemIndicator.")) {
290 extension_action_ = extensions::ExtensionActionManager::Get(profile_)->
291 GetSystemIndicator(*GetExtension());
289 } else { 292 } else {
290 extension_action_ = extensions::ExtensionActionManager::Get(profile_)-> 293 extension_action_ = extensions::ExtensionActionManager::Get(profile_)->
291 GetBrowserAction(*GetExtension()); 294 GetBrowserAction(*GetExtension());
292 if (!extension_action_) { 295 if (!extension_action_) {
293 extension_action_ = extensions::ExtensionActionManager::Get(profile_)-> 296 extension_action_ = extensions::ExtensionActionManager::Get(profile_)->
294 GetPageAction(*GetExtension()); 297 GetPageAction(*GetExtension());
295 } 298 }
296 } 299 }
297 if (!extension_action_) { 300 if (!extension_action_) {
298 // TODO(kalman): ideally the browserAction/pageAction APIs wouldn't event 301 // TODO(kalman): ideally the browserAction/pageAction APIs wouldn't event
299 // exist for extensions that don't have one declared. This should come as 302 // exist for extensions that don't have one declared. This should come as
300 // part of the Feature system. 303 // part of the Feature system.
not at google - send to devlin 2012/11/21 23:39:23 This can be convered to a EXTENSION_FUNCTION_VALID
dewittj 2012/11/26 18:32:58 OK
301 error_ = kNoExtensionActionError; 304 error_ = kNoExtensionActionError;
302 return false; 305 return false;
303 } 306 }
304 307
305 // There may or may not be details (depends on the function). 308 if (!ValidateArguments()) {
306 // The tabId might appear in details (if it exists) or as the first 309 return false;
not at google - send to devlin 2012/11/21 23:39:23 EXTENSION_FUNCTION_VALIDATE(ValidateArguments())
dewittj 2012/11/26 18:32:58 Done. Renamed to more accurately reflect what's g
307 // argument besides the action type (depends on the function).
308 {
309 base::Value* first_arg = NULL;
310 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &first_arg));
311
312 switch (first_arg->GetType()) {
313 case Value::TYPE_INTEGER:
314 CHECK(first_arg->GetAsInteger(&tab_id_));
315 break;
316
317 case Value::TYPE_DICTIONARY: {
318 details_ = static_cast<base::DictionaryValue*>(first_arg);
319 base::Value* tab_id_value = NULL;
320 if (details_->Get("tabId", &tab_id_value)) {
321 switch (tab_id_value->GetType()) {
322 case Value::TYPE_NULL:
323 // Fine, equivalent to it being not-there, and tabId is optional.
324 break;
325 case Value::TYPE_INTEGER:
326 CHECK(tab_id_value->GetAsInteger(&tab_id_));
327 break;
328 default:
329 // Boom.
330 EXTENSION_FUNCTION_VALIDATE(false);
331 }
332 }
333 break;
334 }
335
336 case Value::TYPE_NULL:
337 // The tabId might be an optional argument.
338 break;
339
340 default:
341 EXTENSION_FUNCTION_VALIDATE(false);
342 }
343 } 310 }
344 311
345 // Find the WebContents that contains this tab id if one is required. 312 // Find the WebContents that contains this tab id if one is required.
346 if (tab_id_ == ExtensionAction::kDefaultTabId) { 313 if (tab_id_ == ExtensionAction::kDefaultTabId) {
347 EXTENSION_FUNCTION_VALIDATE( 314 extensions::ExtensionActionManager* mgr =
348 extensions::ExtensionActionManager::Get(profile_)-> 315 extensions::ExtensionActionManager::Get(profile_);
not at google - send to devlin 2012/11/21 23:39:23 nit: do this at top, then re-use is everywhere els
dewittj 2012/11/26 18:32:58 Done.
349 GetBrowserAction(*GetExtension())); 316 if (extension_action_->action_type() ==
317 extensions::Extension::ActionInfo::TYPE_BROWSER) {
318 EXTENSION_FUNCTION_VALIDATE(mgr->GetBrowserAction(*GetExtension()));
319 } else {
320 EXTENSION_FUNCTION_VALIDATE(mgr->GetSystemIndicator(*GetExtension()));
not at google - send to devlin 2012/11/21 23:39:23 actually... a more sensible check here is probably
dewittj 2012/11/26 18:32:58 Good idea. Done.
321 }
350 } else { 322 } else {
351 ExtensionTabUtil::GetTabById( 323 ExtensionTabUtil::GetTabById(
352 tab_id_, profile(), include_incognito(), NULL, NULL, &contents_, NULL); 324 tab_id_, profile(), include_incognito(), NULL, NULL, &contents_, NULL);
353 if (!contents_) { 325 if (!contents_) {
354 error_ = extensions::ErrorUtils::FormatErrorMessage( 326 error_ = extensions::ErrorUtils::FormatErrorMessage(
355 kNoTabError, base::IntToString(tab_id_)); 327 kNoTabError, base::IntToString(tab_id_));
356 return false; 328 return false;
357 } 329 }
358 } 330 }
359 331
360 return RunExtensionAction(); 332 return RunExtensionAction();
361 } 333 }
362 334
335 bool ExtensionActionFunction::ValidateArguments() {
336 // There may or may not be details (depends on the function).
337 // The tabId might appear in details (if it exists) or as the first
338 // argument besides the action type (depends on the function).
339 base::Value* first_arg = NULL;
340 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &first_arg));
not at google - send to devlin 2012/11/21 23:39:23 let's push up the call to EXTENSION_FUNCTION_VALID
dewittj 2012/11/26 18:32:58 Done.
341
342 switch (first_arg->GetType()) {
343 case Value::TYPE_INTEGER:
344 CHECK(first_arg->GetAsInteger(&tab_id_));
345 break;
346
347 case Value::TYPE_DICTIONARY: {
348 details_ = static_cast<base::DictionaryValue*>(first_arg);
349 base::Value* tab_id_value = NULL;
350 if (details_->Get("tabId", &tab_id_value)) {
351 switch (tab_id_value->GetType()) {
352 case Value::TYPE_NULL:
353 // Fine, equivalent to it being not-there, and tabId is optional.
354 break;
355 case Value::TYPE_INTEGER:
356 CHECK(tab_id_value->GetAsInteger(&tab_id_));
357 break;
358 default:
359 // Boom.
360 EXTENSION_FUNCTION_VALIDATE(false);
361 }
362 }
363 break;
364 }
365
366 case Value::TYPE_NULL:
367 // The tabId might be an optional argument.
368 break;
369
370 default:
371 EXTENSION_FUNCTION_VALIDATE(false);
372 }
373
374 return true;
375 }
376
363 void ExtensionActionFunction::NotifyChange() { 377 void ExtensionActionFunction::NotifyChange() {
364 switch (extension_action_->action_type()) { 378 switch (extension_action_->action_type()) {
365 case extensions::Extension::ActionInfo::TYPE_BROWSER: 379 case extensions::Extension::ActionInfo::TYPE_BROWSER:
366 case extensions::Extension::ActionInfo::TYPE_PAGE: 380 case extensions::Extension::ActionInfo::TYPE_PAGE:
367 if (extensions::ExtensionActionManager::Get(profile_)-> 381 if (extensions::ExtensionActionManager::Get(profile_)->
368 GetBrowserAction(*extension_)) { 382 GetBrowserAction(*extension_)) {
369 NotifyBrowserActionChange(); 383 NotifyBrowserActionChange();
370 } else if (extensions::ExtensionActionManager::Get(profile_)-> 384 } else if (extensions::ExtensionActionManager::Get(profile_)->
371 GetPageAction(*extension_)) { 385 GetPageAction(*extension_)) {
372 NotifyLocationBarChange(); 386 NotifyLocationBarChange();
373 } 387 }
374 return; 388 return;
375 case extensions::Extension::ActionInfo::TYPE_SCRIPT_BADGE: 389 case extensions::Extension::ActionInfo::TYPE_SCRIPT_BADGE:
376 NotifyLocationBarChange(); 390 NotifyLocationBarChange();
377 return; 391 return;
392 case extensions::Extension::ActionInfo::TYPE_SYSTEM_INDICATOR:
393 NotifyStatusTrayChange();
394 return;
378 } 395 }
379 NOTREACHED(); 396 NOTREACHED();
380 } 397 }
381 398
382 void ExtensionActionFunction::NotifyBrowserActionChange() { 399 void ExtensionActionFunction::NotifyBrowserActionChange() {
383 content::NotificationService::current()->Notify( 400 content::NotificationService::current()->Notify(
384 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, 401 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
385 content::Source<ExtensionAction>(extension_action_), 402 content::Source<ExtensionAction>(extension_action_),
386 content::Details<Profile>(profile())); 403 content::Details<Profile>(profile()));
387 } 404 }
388 405
389 void ExtensionActionFunction::NotifyLocationBarChange() { 406 void ExtensionActionFunction::NotifyLocationBarChange() {
390 extensions::TabHelper::FromWebContents(contents_)-> 407 extensions::TabHelper::FromWebContents(contents_)->
391 location_bar_controller()->NotifyChange(); 408 location_bar_controller()->NotifyChange();
392 } 409 }
393 410
411 void ExtensionActionFunction::NotifyStatusTrayChange() {
not at google - send to devlin 2012/11/21 23:39:23 TODO(dewittj): implement (see http://crbug.com/142
dewittj 2012/11/26 18:32:58 Done.
412 }
413
394 // static 414 // static
395 bool ExtensionActionFunction::ParseCSSColorString( 415 bool ExtensionActionFunction::ParseCSSColorString(
396 const std::string& color_string, 416 const std::string& color_string,
397 SkColor* result) { 417 SkColor* result) {
398 std::string formatted_color = "#"; 418 std::string formatted_color = "#";
399 // Check the string for incorrect formatting. 419 // Check the string for incorrect formatting.
400 if (color_string[0] != '#') 420 if (color_string[0] != '#')
401 return false; 421 return false;
402 422
403 // Convert the string from #FFF format to #FFFFFF format. 423 // Convert the string from #FFF format to #FFFFFF format.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { 575 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() {
556 ListValue* list = new ListValue(); 576 ListValue* list = new ListValue();
557 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); 577 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_);
558 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); 578 list->Append(Value::CreateIntegerValue(SkColorGetR(color)));
559 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); 579 list->Append(Value::CreateIntegerValue(SkColorGetG(color)));
560 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); 580 list->Append(Value::CreateIntegerValue(SkColorGetB(color)));
561 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); 581 list->Append(Value::CreateIntegerValue(SkColorGetA(color)));
562 SetResult(list); 582 SetResult(list);
563 return true; 583 return true;
564 } 584 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698