| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_browser_actions_api.h" | 5 #include "chrome/browser/extensions/extension_browser_actions_api.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/common/notification_service.h" | 9 #include "chrome/common/notification_service.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 // Errors. | 13 // Errors. |
| 14 const char kNoBrowserActionError[] = | 14 const char kNoBrowserActionError[] = |
| 15 "This extension has no browser action specified."; | 15 "This extension has no browser action specified."; |
| 16 const char kIconIndexOutOfBounds[] = | 16 const char kIconIndexOutOfBounds[] = |
| 17 "Browser action icon index out of bounds."; | 17 "Browser action icon index out of bounds."; |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool BrowserActionFunction::RunImpl() { | 20 bool BrowserActionFunction::RunImpl() { |
| 21 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 21 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 22 details_ = static_cast<DictionaryValue*>(args_); | 22 details_ = args_as_dictionary(); |
| 23 | 23 |
| 24 if (details_->HasKey(L"tabId")) | 24 if (details_->HasKey(L"tabId")) |
| 25 EXTENSION_FUNCTION_VALIDATE(details_->GetInteger(L"tabId", &tab_id_)); | 25 EXTENSION_FUNCTION_VALIDATE(details_->GetInteger(L"tabId", &tab_id_)); |
| 26 | 26 |
| 27 Extension* extension = dispatcher()->GetExtension(); | 27 Extension* extension = dispatcher()->GetExtension(); |
| 28 browser_action_ = extension->browser_action(); | 28 browser_action_ = extension->browser_action(); |
| 29 if (!browser_action_) { | 29 if (!browser_action_) { |
| 30 error_ = kNoBrowserActionError; | 30 error_ = kNoBrowserActionError; |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 for (size_t i = 0; i < arraysize(color_array); ++i) { | 76 for (size_t i = 0; i < arraysize(color_array); ++i) { |
| 77 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); | 77 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); |
| 78 } | 78 } |
| 79 | 79 |
| 80 SkColor color = SkColorSetARGB(color_array[3], color_array[0], color_array[1], | 80 SkColor color = SkColorSetARGB(color_array[3], color_array[0], color_array[1], |
| 81 color_array[2]); | 81 color_array[2]); |
| 82 browser_action_->SetBadgeBackgroundColor(tab_id_, color); | 82 browser_action_->SetBadgeBackgroundColor(tab_id_, color); |
| 83 | 83 |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| OLD | NEW |