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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // If --enable-script-badges is on there might legitimately be an iconIndex |
463 // set. Until we decide what to do with that, ignore. | 463 // set. Until we decide what to do with that, ignore. |
464 if (!GetExtension()->page_action()) | 464 if (!GetExtension()->page_action()) |
465 return true; | 465 return true; |
466 if (icon_index < 0 || | 466 if (!extension_action_->IsValidIconIndex(icon_index)) { |
467 static_cast<size_t>(icon_index) >= | |
468 extension_action_->icon_paths()->size()) { | |
469 error_ = kIconIndexOutOfBounds; | 467 error_ = kIconIndexOutOfBounds; |
470 return false; | 468 return false; |
471 } | 469 } |
472 extension_action_->SetIcon(tab_id_, gfx::Image()); | 470 extension_action_->SetIcon(tab_id_, gfx::Image()); |
473 extension_action_->SetIconIndex(tab_id_, icon_index); | 471 extension_action_->SetIconIndex(tab_id_, icon_index); |
474 } else { | 472 } else { |
475 EXTENSION_FUNCTION_VALIDATE(false); | 473 EXTENSION_FUNCTION_VALIDATE(false); |
476 } | 474 } |
477 NotifyChange(); | 475 NotifyChange(); |
478 return true; | 476 return true; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | 552 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { |
555 ListValue* list = new ListValue(); | 553 ListValue* list = new ListValue(); |
556 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); | 554 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); |
557 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); | 555 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); |
558 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); | 556 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); |
559 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); | 557 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); |
560 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); | 558 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); |
561 SetResult(list); | 559 SetResult(list); |
562 return true; | 560 return true; |
563 } | 561 } |
OLD | NEW |