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 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 content::NotificationService::current()->Notify( | 624 content::NotificationService::current()->Notify( |
625 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 625 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
626 content::Source<Profile>(GetProfile()), | 626 content::Source<Profile>(GetProfile()), |
627 content::Details<ExtensionAction>(extension_action_)); | 627 content::Details<ExtensionAction>(extension_action_)); |
628 } | 628 } |
629 | 629 |
630 // static | 630 // static |
631 bool ExtensionActionFunction::ParseCSSColorString( | 631 bool ExtensionActionFunction::ParseCSSColorString( |
632 const std::string& color_string, | 632 const std::string& color_string, |
633 SkColor* result) { | 633 SkColor* result) { |
634 std::string formatted_color = "#"; | 634 std::string formatted_color; |
635 // Check the string for incorrect formatting. | 635 // Check the string for incorrect formatting. |
636 if (color_string[0] != '#') | 636 if (color_string.empty() || color_string[0] != '#') |
637 return false; | 637 return false; |
638 | 638 |
639 // Convert the string from #FFF format to #FFFFFF format. | 639 // Convert the string from #FFF format to #FFFFFF format. |
640 if (color_string.length() == 4) { | 640 if (color_string.length() == 4) { |
641 for (size_t i = 1; i < color_string.length(); i++) { | 641 for (size_t i = 1; i < 4; ++i) { |
642 formatted_color += color_string[i]; | 642 formatted_color += color_string[i]; |
643 formatted_color += color_string[i]; | 643 formatted_color += color_string[i]; |
644 } | 644 } |
645 } else if (color_string.length() == 7) { | |
646 formatted_color = color_string.substr(1, 6); | |
645 } else { | 647 } else { |
646 formatted_color = color_string; | 648 return false; |
647 } | 649 } |
648 | 650 |
649 if (formatted_color.length() != 7) | |
650 return false; | |
651 | |
652 // Convert the string to an integer and make sure it is in the correct value | 651 // Convert the string to an integer and make sure it is in the correct value |
653 // range. | 652 // range. |
654 int color_ints[3] = {0}; | 653 std::vector<uint8> color_bytes; |
655 for (int i = 0; i < 3; i++) { | 654 if (!base::HexStringToBytes(formatted_color, &color_bytes)) |
656 if (!base::HexStringToInt(formatted_color.substr(1 + (2 * i), 2), | 655 return false; |
657 color_ints + i)) | |
658 return false; | |
659 if (color_ints[i] > 255 || color_ints[i] < 0) | |
660 return false; | |
661 } | |
662 | 656 |
663 *result = SkColorSetARGB(255, color_ints[0], color_ints[1], color_ints[2]); | 657 *result = SkColorSetARGB(255, color_bytes[0], color_bytes[1], color_bytes[2]); |
Matt Giuca
2014/02/19 02:26:43
Nit: DCHECK_EQ(3, color_bytes.size());
benwells
2014/02/19 05:28:30
Done.
| |
664 return true; | 658 return true; |
665 } | 659 } |
666 | 660 |
667 bool ExtensionActionFunction::SetVisible(bool visible) { | 661 bool ExtensionActionFunction::SetVisible(bool visible) { |
668 if (extension_action_->GetIsVisible(tab_id_) == visible) | 662 if (extension_action_->GetIsVisible(tab_id_) == visible) |
669 return true; | 663 return true; |
670 extension_action_->SetIsVisible(tab_id_, visible); | 664 extension_action_->SetIsVisible(tab_id_, visible); |
671 NotifyChange(); | 665 NotifyChange(); |
672 return true; | 666 return true; |
673 } | 667 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
936 return true; | 930 return true; |
937 } | 931 } |
938 | 932 |
939 bool EnablePageActionsFunction::RunImpl() { | 933 bool EnablePageActionsFunction::RunImpl() { |
940 return SetPageActionEnabled(true); | 934 return SetPageActionEnabled(true); |
941 } | 935 } |
942 | 936 |
943 bool DisablePageActionsFunction::RunImpl() { | 937 bool DisablePageActionsFunction::RunImpl() { |
944 return SetPageActionEnabled(false); | 938 return SetPageActionEnabled(false); |
945 } | 939 } |
OLD | NEW |