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 422 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 base::DictionaryValue* canvas_set = NULL; | |
| 443 int icon_index; | 444 int icon_index; |
| 444 base::DictionaryValue* canvas_set = NULL; | |
| 445 if (details_->GetDictionary("imageData", &canvas_set)) { | 445 if (details_->GetDictionary("imageData", &canvas_set)) { |
| 446 gfx::ImageSkia icon; | 446 gfx::ImageSkia icon; |
| 447 // Extract icon representations from the ImageDataSet dictionary. | 447 // Extract icon representations from the ImageDataSet dictionary. |
| 448 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 448 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
| 449 base::BinaryValue* binary; | 449 base::BinaryValue* binary; |
| 450 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { | 450 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { |
| 451 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); | 451 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); |
| 452 PickleIterator iter(pickle); | 452 PickleIterator iter(pickle); |
| 453 SkBitmap bitmap; | 453 SkBitmap bitmap; |
| 454 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); | 454 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); |
| 455 CHECK(!bitmap.isNull()); | 455 CHECK(!bitmap.isNull()); |
| 456 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); | 456 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 | 459 |
| 460 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); | 460 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); |
| 461 } else if (details_->GetInteger("iconIndex", &icon_index)) { | 461 } else if (details_->GetInteger("iconIndex", &icon_index)) { |
| 462 // If --enable-script-badges is on there might legitimately be an iconIndex | 462 // Obsolete argument: ignore it. |
| 463 // set. Until we decide what to do with that, ignore. | 463 return true; |
|
Matt Perry
2012/09/13 19:16:32
Added this back to avoid a browser crash when exte
| |
| 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 { | 464 } else { |
| 475 EXTENSION_FUNCTION_VALIDATE(false); | 465 EXTENSION_FUNCTION_VALIDATE(false); |
| 476 } | 466 } |
| 477 NotifyChange(); | 467 NotifyChange(); |
| 478 return true; | 468 return true; |
| 479 } | 469 } |
| 480 | 470 |
| 481 bool ExtensionActionSetTitleFunction::RunExtensionAction() { | 471 bool ExtensionActionSetTitleFunction::RunExtensionAction() { |
| 482 std::string title; | 472 std::string title; |
| 483 EXTENSION_FUNCTION_VALIDATE(details_->GetString("title", &title)); | 473 EXTENSION_FUNCTION_VALIDATE(details_->GetString("title", &title)); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | 544 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { |
| 555 ListValue* list = new ListValue(); | 545 ListValue* list = new ListValue(); |
| 556 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); | 546 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); |
| 557 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); | 547 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); |
| 558 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); | 548 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); |
| 559 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); | 549 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); |
| 560 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); | 550 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); |
| 561 SetResult(list); | 551 SetResult(list); |
| 562 return true; | 552 return true; |
| 563 } | 553 } |
| OLD | NEW |