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

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

Issue 477193003: Refactor setIcon to allow for more general use of imageData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
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_action_api.h" 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 bool ExtensionActionHideFunction::RunExtensionAction() { 664 bool ExtensionActionHideFunction::RunExtensionAction() {
665 return SetVisible(false); 665 return SetVisible(false);
666 } 666 }
667 667
668 bool ExtensionActionSetIconFunction::RunExtensionAction() { 668 bool ExtensionActionSetIconFunction::RunExtensionAction() {
669 EXTENSION_FUNCTION_VALIDATE(details_); 669 EXTENSION_FUNCTION_VALIDATE(details_);
670 670
671 // setIcon can take a variant argument: either a dictionary of canvas 671 // setIcon can take a variant argument: either a dictionary of canvas
672 // ImageData, or an icon index. 672 // ImageData, or an icon index.
673 base::DictionaryValue* canvas_set = NULL; 673 base::DictionaryValue* canvas_set = NULL;
674 int icon_index;
675 if (details_->GetDictionary("imageData", &canvas_set)) { 674 if (details_->GetDictionary("imageData", &canvas_set)) {
676 gfx::ImageSkia icon; 675 gfx::ImageSkia icon;
677 // Extract icon representations from the ImageDataSet dictionary. 676 // Extract icon representations from the ImageDataSet dictionary.
678 for (size_t i = 0; i < arraysize(kIconSizes); i++) { 677 for (size_t i = 0; i < arraysize(kIconSizes); i++) {
679 base::BinaryValue* binary; 678 std::string binary_string64;
680 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { 679 if (canvas_set->GetString(kIconSizes[i].size_string, &binary_string64)) {
681 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); 680 std::string binary_data;
681 if (!base::Base64Decode(binary_string64, &binary_data))
682 return false;
683
684 IPC::Message pickle(binary_data.c_str(), binary_data.length());
not at google - send to devlin 2014/08/19 00:04:43 You should only need to do this Binary -> std::str
gpdavis 2014/08/19 00:54:15 You don't think we should keep it this way so it w
not at google - send to devlin 2014/08/19 17:32:29 There are 2 things here: (1) The serialization for
682 PickleIterator iter(pickle); 685 PickleIterator iter(pickle);
683 SkBitmap bitmap; 686 SkBitmap bitmap;
684 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); 687 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap));
685 CHECK(!bitmap.isNull()); 688 CHECK(!bitmap.isNull());
686 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale); 689 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale);
687 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); 690 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
688 } 691 }
689 } 692 }
690 693
691 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); 694 extension_action_->SetIcon(tab_id_, gfx::Image(icon));
692 } else if (details_->GetInteger("iconIndex", &icon_index)) { 695 } else if (details_->HasKey("iconIndex")) {
693 // Obsolete argument: ignore it. 696 // Obsolete argument: ignore it.
694 return true; 697 return true;
695 } else { 698 } else {
696 EXTENSION_FUNCTION_VALIDATE(false); 699 EXTENSION_FUNCTION_VALIDATE(false);
697 } 700 }
698 NotifyChange(); 701 NotifyChange();
699 return true; 702 return true;
700 } 703 }
701 704
702 bool ExtensionActionSetTitleFunction::RunExtensionAction() { 705 bool ExtensionActionSetTitleFunction::RunExtensionAction() {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 return true; 918 return true;
916 } 919 }
917 920
918 bool EnablePageActionsFunction::RunSync() { 921 bool EnablePageActionsFunction::RunSync() {
919 return SetPageActionEnabled(true); 922 return SetPageActionEnabled(true);
920 } 923 }
921 924
922 bool DisablePageActionsFunction::RunSync() { 925 bool DisablePageActionsFunction::RunSync() {
923 return SetPageActionEnabled(false); 926 return SetPageActionEnabled(false);
924 } 927 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698