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

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

Issue 10914244: Remove support for page_action.icons, and the legacy code surrounding it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: constants removed Created 8 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 24 matching lines...) Expand all
35 const char kIconStorageKey[] = "icon"; 35 const char kIconStorageKey[] = "icon";
36 const char kBadgeTextStorageKey[] = "badge_text"; 36 const char kBadgeTextStorageKey[] = "badge_text";
37 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; 37 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color";
38 const char kBadgeTextColorStorageKey[] = "badge_text_color"; 38 const char kBadgeTextColorStorageKey[] = "badge_text_color";
39 const char kAppearanceStorageKey[] = "appearance"; 39 const char kAppearanceStorageKey[] = "appearance";
40 40
41 // Errors. 41 // Errors.
42 const char kNoExtensionActionError[] = 42 const char kNoExtensionActionError[] =
43 "This extension has no action specified."; 43 "This extension has no action specified.";
44 const char kNoTabError[] = "No tab with id: *."; 44 const char kNoTabError[] = "No tab with id: *.";
45 const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds.";
46 45
47 struct IconRepresentationInfo { 46 struct IconRepresentationInfo {
48 // Size as a string that will be used to retrieve representation value from 47 // Size as a string that will be used to retrieve representation value from
49 // SetIcon function arguments. 48 // SetIcon function arguments.
50 const char* size_string; 49 const char* size_string;
51 // Scale factor for which the represantion should be used. 50 // Scale factor for which the represantion should be used.
52 ui::ScaleFactor scale; 51 ui::ScaleFactor scale;
53 }; 52 };
54 53
55 54
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 return SetVisible(true); 432 return SetVisible(true);
434 } 433 }
435 434
436 bool ExtensionActionHideFunction::RunExtensionAction() { 435 bool ExtensionActionHideFunction::RunExtensionAction() {
437 return SetVisible(false); 436 return SetVisible(false);
438 } 437 }
439 438
440 bool ExtensionActionSetIconFunction::RunExtensionAction() { 439 bool ExtensionActionSetIconFunction::RunExtensionAction() {
441 // setIcon can take a variant argument: either a dictionary of canvas 440 // setIcon can take a variant argument: either a dictionary of canvas
442 // ImageData, or an icon index. 441 // ImageData, or an icon index.
442 base::DictionaryValue* canvas_set = NULL;
443 int icon_index; 443 int icon_index;
444 base::DictionaryValue* canvas_set = NULL;
445 if (details_->GetDictionary("imageData", &canvas_set)) { 444 if (details_->GetDictionary("imageData", &canvas_set)) {
446 gfx::ImageSkia icon; 445 gfx::ImageSkia icon;
447 // Extract icon representations from the ImageDataSet dictionary. 446 // Extract icon representations from the ImageDataSet dictionary.
448 for (size_t i = 0; i < arraysize(kIconSizes); i++) { 447 for (size_t i = 0; i < arraysize(kIconSizes); i++) {
449 base::BinaryValue* binary; 448 base::BinaryValue* binary;
450 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { 449 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) {
451 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); 450 IPC::Message pickle(binary->GetBuffer(), binary->GetSize());
452 PickleIterator iter(pickle); 451 PickleIterator iter(pickle);
453 SkBitmap bitmap; 452 SkBitmap bitmap;
454 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); 453 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap));
455 CHECK(!bitmap.isNull()); 454 CHECK(!bitmap.isNull());
456 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); 455 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
457 } 456 }
458 } 457 }
459 458
460 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); 459 extension_action_->SetIcon(tab_id_, gfx::Image(icon));
461 } else if (details_->GetInteger("iconIndex", &icon_index)) { 460 } else if (details_->GetInteger("iconIndex", &icon_index)) {
462 // If --enable-script-badges is on there might legitimately be an iconIndex 461 // Obsolete argument: ignore it.
463 // set. Until we decide what to do with that, ignore. 462 return true;
464 if (!GetExtension()->page_action())
465 return true;
466 if (icon_index < 0 ||
467 static_cast<size_t>(icon_index) >=
468 extension_action_->icon_paths()->size()) {
469 error_ = kIconIndexOutOfBounds;
470 return false;
471 }
472 extension_action_->SetIcon(tab_id_, gfx::Image());
473 extension_action_->SetIconIndex(tab_id_, icon_index);
474 } else { 463 } else {
475 EXTENSION_FUNCTION_VALIDATE(false); 464 EXTENSION_FUNCTION_VALIDATE(false);
476 } 465 }
477 NotifyChange(); 466 NotifyChange();
478 return true; 467 return true;
479 } 468 }
480 469
481 bool ExtensionActionSetTitleFunction::RunExtensionAction() { 470 bool ExtensionActionSetTitleFunction::RunExtensionAction() {
482 std::string title; 471 std::string title;
483 EXTENSION_FUNCTION_VALIDATE(details_->GetString("title", &title)); 472 EXTENSION_FUNCTION_VALIDATE(details_->GetString("title", &title));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { 543 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() {
555 ListValue* list = new ListValue(); 544 ListValue* list = new ListValue();
556 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); 545 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_);
557 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); 546 list->Append(Value::CreateIntegerValue(SkColorGetR(color)));
558 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); 547 list->Append(Value::CreateIntegerValue(SkColorGetG(color)));
559 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); 548 list->Append(Value::CreateIntegerValue(SkColorGetB(color)));
560 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); 549 list->Append(Value::CreateIntegerValue(SkColorGetA(color)));
561 SetResult(list); 550 SetResult(list);
562 return true; 551 return true;
563 } 552 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698