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

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

Issue 10855090: extensions: Fix crash on empty extension action icons (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase more Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/extensions/extension.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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (dict->GetString(kBadgeTextStorageKey, &str_value)) 97 if (dict->GetString(kBadgeTextStorageKey, &str_value))
98 action->SetBadgeText(kTabId, str_value); 98 action->SetBadgeText(kTabId, str_value);
99 if (dict->GetString(kBadgeBackgroundColorStorageKey, &str_value)) 99 if (dict->GetString(kBadgeBackgroundColorStorageKey, &str_value))
100 action->SetBadgeBackgroundColor(kTabId, RawStringToSkColor(str_value)); 100 action->SetBadgeBackgroundColor(kTabId, RawStringToSkColor(str_value));
101 if (dict->GetString(kBadgeTextColorStorageKey, &str_value)) 101 if (dict->GetString(kBadgeTextColorStorageKey, &str_value))
102 action->SetBadgeTextColor(kTabId, RawStringToSkColor(str_value)); 102 action->SetBadgeTextColor(kTabId, RawStringToSkColor(str_value));
103 if (dict->GetInteger(kAppearanceStorageKey, &int_value)) 103 if (dict->GetInteger(kAppearanceStorageKey, &int_value))
104 action->SetAppearance(kTabId, 104 action->SetAppearance(kTabId,
105 static_cast<ExtensionAction::Appearance>(int_value)); 105 static_cast<ExtensionAction::Appearance>(int_value));
106 if (dict->GetString(kIconStorageKey, &str_value) && 106 if (dict->GetString(kIconStorageKey, &str_value) &&
107 StringToSkBitmap(str_value, &bitmap)) 107 StringToSkBitmap(str_value, &bitmap)) {
108 action->SetIcon(kTabId, bitmap); 108 CHECK(!bitmap.isNull());
109 action->SetIcon(kTabId, gfx::Image(bitmap));
110 }
109 } 111 }
110 112
111 // Store |action|'s default values in a DictionaryValue for use in storing to 113 // Store |action|'s default values in a DictionaryValue for use in storing to
112 // disk. 114 // disk.
113 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { 115 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) {
114 const int kTabId = ExtensionAction::kDefaultTabId; 116 const int kTabId = ExtensionAction::kDefaultTabId;
115 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue()); 117 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue());
116 118
117 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); 119 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec());
118 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId)); 120 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId));
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 bool ExtensionActionSetIconFunction::RunExtensionAction() { 404 bool ExtensionActionSetIconFunction::RunExtensionAction() {
403 // setIcon can take a variant argument: either a canvas ImageData, or an 405 // setIcon can take a variant argument: either a canvas ImageData, or an
404 // icon index. 406 // icon index.
405 base::BinaryValue* binary = NULL; 407 base::BinaryValue* binary = NULL;
406 int icon_index; 408 int icon_index;
407 if (details_->GetBinary("imageData", &binary)) { 409 if (details_->GetBinary("imageData", &binary)) {
408 IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize()); 410 IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize());
409 PickleIterator iter(bitmap_pickle); 411 PickleIterator iter(bitmap_pickle);
410 SkBitmap bitmap; 412 SkBitmap bitmap;
411 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&bitmap_pickle, &iter, &bitmap)); 413 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&bitmap_pickle, &iter, &bitmap));
412 extension_action_->SetIcon(tab_id_, bitmap); 414 CHECK(!bitmap.isNull());
415 extension_action_->SetIcon(tab_id_, gfx::Image(bitmap));
413 } else if (details_->GetInteger("iconIndex", &icon_index)) { 416 } else if (details_->GetInteger("iconIndex", &icon_index)) {
414 // If --enable-script-badges is on there might legitimately be an iconIndex 417 // If --enable-script-badges is on there might legitimately be an iconIndex
415 // set. Until we decide what to do with that, ignore. 418 // set. Until we decide what to do with that, ignore.
416 if (!GetExtension()->page_action()) 419 if (!GetExtension()->page_action())
417 return true; 420 return true;
418 if (icon_index < 0 || 421 if (icon_index < 0 ||
419 static_cast<size_t>(icon_index) >= 422 static_cast<size_t>(icon_index) >=
420 extension_action_->icon_paths()->size()) { 423 extension_action_->icon_paths()->size()) {
421 error_ = kIconIndexOutOfBounds; 424 error_ = kIconIndexOutOfBounds;
422 return false; 425 return false;
423 } 426 }
424 extension_action_->SetIcon(tab_id_, SkBitmap()); 427 extension_action_->SetIcon(tab_id_, gfx::Image());
425 extension_action_->SetIconIndex(tab_id_, icon_index); 428 extension_action_->SetIconIndex(tab_id_, icon_index);
426 } else { 429 } else {
427 EXTENSION_FUNCTION_VALIDATE(false); 430 EXTENSION_FUNCTION_VALIDATE(false);
428 } 431 }
429 NotifyChange(); 432 NotifyChange();
430 return true; 433 return true;
431 } 434 }
432 435
433 bool ExtensionActionSetTitleFunction::RunExtensionAction() { 436 bool ExtensionActionSetTitleFunction::RunExtensionAction() {
434 std::string title; 437 std::string title;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { 509 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() {
507 ListValue* list = new ListValue(); 510 ListValue* list = new ListValue();
508 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); 511 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_);
509 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); 512 list->Append(Value::CreateIntegerValue(SkColorGetR(color)));
510 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); 513 list->Append(Value::CreateIntegerValue(SkColorGetG(color)));
511 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); 514 list->Append(Value::CreateIntegerValue(SkColorGetB(color)));
512 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); 515 list->Append(Value::CreateIntegerValue(SkColorGetA(color)));
513 SetResult(list); 516 SetResult(list);
514 return true; 517 return true;
515 } 518 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698