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_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 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/extensions/tab_helper.h" | 21 #include "chrome/browser/extensions/tab_helper.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/common/extensions/api/extension_action/action_info.h" | 23 #include "chrome/common/extensions/api/extension_action/action_info.h" |
24 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
28 #include "extensions/browser/extension_function_registry.h" | 28 #include "extensions/browser/extension_function_registry.h" |
29 #include "extensions/browser/extension_host.h" | 29 #include "extensions/browser/extension_host.h" |
30 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 31 #include "extensions/browser/image_util.h" |
31 #include "extensions/common/error_utils.h" | 32 #include "extensions/common/error_utils.h" |
32 #include "ui/gfx/codec/png_codec.h" | 33 #include "ui/gfx/codec/png_codec.h" |
33 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
34 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
35 | 36 |
36 using content::WebContents; | 37 using content::WebContents; |
37 | 38 |
38 namespace page_actions_keys = extension_page_actions_api_constants; | 39 namespace page_actions_keys = extension_page_actions_api_constants; |
39 | 40 |
40 namespace extensions { | 41 namespace extensions { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 location_bar_controller()->NotifyChange(); | 641 location_bar_controller()->NotifyChange(); |
641 } | 642 } |
642 | 643 |
643 void ExtensionActionFunction::NotifySystemIndicatorChange() { | 644 void ExtensionActionFunction::NotifySystemIndicatorChange() { |
644 content::NotificationService::current()->Notify( | 645 content::NotificationService::current()->Notify( |
645 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 646 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
646 content::Source<Profile>(GetProfile()), | 647 content::Source<Profile>(GetProfile()), |
647 content::Details<ExtensionAction>(extension_action_)); | 648 content::Details<ExtensionAction>(extension_action_)); |
648 } | 649 } |
649 | 650 |
650 // static | |
651 bool ExtensionActionFunction::ParseCSSColorString( | |
652 const std::string& color_string, | |
653 SkColor* result) { | |
654 std::string formatted_color; | |
655 // Check the string for incorrect formatting. | |
656 if (color_string.empty() || color_string[0] != '#') | |
657 return false; | |
658 | |
659 // Convert the string from #FFF format to #FFFFFF format. | |
660 if (color_string.length() == 4) { | |
661 for (size_t i = 1; i < 4; ++i) { | |
662 formatted_color += color_string[i]; | |
663 formatted_color += color_string[i]; | |
664 } | |
665 } else if (color_string.length() == 7) { | |
666 formatted_color = color_string.substr(1, 6); | |
667 } else { | |
668 return false; | |
669 } | |
670 | |
671 // Convert the string to an integer and make sure it is in the correct value | |
672 // range. | |
673 std::vector<uint8> color_bytes; | |
674 if (!base::HexStringToBytes(formatted_color, &color_bytes)) | |
675 return false; | |
676 | |
677 DCHECK_EQ(3u, color_bytes.size()); | |
678 *result = SkColorSetARGB(255, color_bytes[0], color_bytes[1], color_bytes[2]); | |
679 return true; | |
680 } | |
681 | |
682 bool ExtensionActionFunction::SetVisible(bool visible) { | 651 bool ExtensionActionFunction::SetVisible(bool visible) { |
683 if (extension_action_->GetIsVisible(tab_id_) == visible) | 652 if (extension_action_->GetIsVisible(tab_id_) == visible) |
684 return true; | 653 return true; |
685 extension_action_->SetIsVisible(tab_id_, visible); | 654 extension_action_->SetIsVisible(tab_id_, visible); |
686 NotifyChange(); | 655 NotifyChange(); |
687 return true; | 656 return true; |
688 } | 657 } |
689 | 658 |
690 TabHelper& ExtensionActionFunction::tab_helper() const { | 659 TabHelper& ExtensionActionFunction::tab_helper() const { |
691 CHECK(contents_); | 660 CHECK(contents_); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 int color_array[4] = {0}; | 748 int color_array[4] = {0}; |
780 for (size_t i = 0; i < arraysize(color_array); ++i) { | 749 for (size_t i = 0; i < arraysize(color_array); ++i) { |
781 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); | 750 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); |
782 } | 751 } |
783 | 752 |
784 color = SkColorSetARGB(color_array[3], color_array[0], | 753 color = SkColorSetARGB(color_array[3], color_array[0], |
785 color_array[1], color_array[2]); | 754 color_array[1], color_array[2]); |
786 } else if (color_value->IsType(base::Value::TYPE_STRING)) { | 755 } else if (color_value->IsType(base::Value::TYPE_STRING)) { |
787 std::string color_string; | 756 std::string color_string; |
788 EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string)); | 757 EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string)); |
789 if (!ParseCSSColorString(color_string, &color)) | 758 if (!image_util::ParseCSSColorString(color_string, &color)) |
790 return false; | 759 return false; |
791 } | 760 } |
792 | 761 |
793 extension_action_->SetBadgeBackgroundColor(tab_id_, color); | 762 extension_action_->SetBadgeBackgroundColor(tab_id_, color); |
794 NotifyChange(); | 763 NotifyChange(); |
795 return true; | 764 return true; |
796 } | 765 } |
797 | 766 |
798 bool ExtensionActionGetTitleFunction::RunExtensionAction() { | 767 bool ExtensionActionGetTitleFunction::RunExtensionAction() { |
799 SetResult(new base::StringValue(extension_action_->GetTitle(tab_id_))); | 768 SetResult(new base::StringValue(extension_action_->GetTitle(tab_id_))); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 return true; | 920 return true; |
952 } | 921 } |
953 | 922 |
954 bool EnablePageActionsFunction::RunImpl() { | 923 bool EnablePageActionsFunction::RunImpl() { |
955 return SetPageActionEnabled(true); | 924 return SetPageActionEnabled(true); |
956 } | 925 } |
957 | 926 |
958 bool DisablePageActionsFunction::RunImpl() { | 927 bool DisablePageActionsFunction::RunImpl() { |
959 return SetPageActionEnabled(false); | 928 return SetPageActionEnabled(false); |
960 } | 929 } |
OLD | NEW |