Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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."; | 45 const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds."; |
|
Yoyo Zhou
2012/09/13 20:42:39
Can be removed.
Matt Perry
2012/09/13 21:39:28
Done.
| |
| 46 | 46 |
| 47 struct IconRepresentationInfo { | 47 struct IconRepresentationInfo { |
| 48 // Size as a string that will be used to retrieve representation value from | 48 // Size as a string that will be used to retrieve representation value from |
| 49 // SetIcon function arguments. | 49 // SetIcon function arguments. |
| 50 const char* size_string; | 50 const char* size_string; |
| 51 // Scale factor for which the represantion should be used. | 51 // Scale factor for which the represantion should be used. |
| 52 ui::ScaleFactor scale; | 52 ui::ScaleFactor scale; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 | 55 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 return SetVisible(true); | 433 return SetVisible(true); |
| 434 } | 434 } |
| 435 | 435 |
| 436 bool ExtensionActionHideFunction::RunExtensionAction() { | 436 bool ExtensionActionHideFunction::RunExtensionAction() { |
| 437 return SetVisible(false); | 437 return SetVisible(false); |
| 438 } | 438 } |
| 439 | 439 |
| 440 bool ExtensionActionSetIconFunction::RunExtensionAction() { | 440 bool ExtensionActionSetIconFunction::RunExtensionAction() { |
| 441 // setIcon can take a variant argument: either a dictionary of canvas | 441 // setIcon can take a variant argument: either a dictionary of canvas |
| 442 // ImageData, or an icon index. | 442 // ImageData, or an icon index. |
| 443 int icon_index; | |
| 444 base::DictionaryValue* canvas_set = NULL; | 443 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)) { | |
| 462 // If --enable-script-badges is on there might legitimately be an iconIndex | |
| 463 // set. Until we decide what to do with that, ignore. | |
| 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 { | 460 } else { |
| 475 EXTENSION_FUNCTION_VALIDATE(false); | 461 EXTENSION_FUNCTION_VALIDATE(false); |
| 476 } | 462 } |
| 477 NotifyChange(); | 463 NotifyChange(); |
| 478 return true; | 464 return true; |
| 479 } | 465 } |
| 480 | 466 |
| 481 bool ExtensionActionSetTitleFunction::RunExtensionAction() { | 467 bool ExtensionActionSetTitleFunction::RunExtensionAction() { |
| 482 std::string title; | 468 std::string title; |
| 483 EXTENSION_FUNCTION_VALIDATE(details_->GetString("title", &title)); | 469 EXTENSION_FUNCTION_VALIDATE(details_->GetString("title", &title)); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | 540 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { |
| 555 ListValue* list = new ListValue(); | 541 ListValue* list = new ListValue(); |
| 556 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); | 542 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); |
| 557 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); | 543 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); |
| 558 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); | 544 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); |
| 559 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); | 545 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); |
| 560 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); | 546 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); |
| 561 SetResult(list); | 547 SetResult(list); |
| 562 return true; | 548 return true; |
| 563 } | 549 } |
| OLD | NEW |