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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 content::NotificationService::current()->Notify( | 631 content::NotificationService::current()->Notify( |
632 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 632 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
633 content::Source<Profile>(GetProfile()), | 633 content::Source<Profile>(GetProfile()), |
634 content::Details<ExtensionAction>(extension_action_)); | 634 content::Details<ExtensionAction>(extension_action_)); |
635 } | 635 } |
636 | 636 |
637 // static | 637 // static |
638 bool ExtensionActionFunction::ParseCSSColorString( | 638 bool ExtensionActionFunction::ParseCSSColorString( |
639 const std::string& color_string, | 639 const std::string& color_string, |
640 SkColor* result) { | 640 SkColor* result) { |
641 std::string formatted_color = "#"; | 641 std::string formatted_color; |
642 // Check the string for incorrect formatting. | 642 // Check the string for incorrect formatting. |
643 if (color_string[0] != '#') | 643 if (color_string.empty() || color_string[0] != '#') |
644 return false; | 644 return false; |
645 | 645 |
646 // Convert the string from #FFF format to #FFFFFF format. | 646 // Convert the string from #FFF format to #FFFFFF format. |
647 if (color_string.length() == 4) { | 647 if (color_string.length() == 4) { |
648 for (size_t i = 1; i < color_string.length(); i++) { | 648 for (size_t i = 1; i < 4; ++i) { |
649 formatted_color += color_string[i]; | 649 formatted_color += color_string[i]; |
650 formatted_color += color_string[i]; | 650 formatted_color += color_string[i]; |
651 } | 651 } |
| 652 } else if (color_string.length() == 7) { |
| 653 formatted_color = color_string.substr(1, 6); |
652 } else { | 654 } else { |
653 formatted_color = color_string; | 655 return false; |
654 } | 656 } |
655 | 657 |
656 if (formatted_color.length() != 7) | |
657 return false; | |
658 | |
659 // Convert the string to an integer and make sure it is in the correct value | 658 // Convert the string to an integer and make sure it is in the correct value |
660 // range. | 659 // range. |
661 int color_ints[3] = {0}; | 660 std::vector<uint8> color_bytes; |
662 for (int i = 0; i < 3; i++) { | 661 if (!base::HexStringToBytes(formatted_color, &color_bytes)) |
663 if (!base::HexStringToInt(formatted_color.substr(1 + (2 * i), 2), | 662 return false; |
664 color_ints + i)) | |
665 return false; | |
666 if (color_ints[i] > 255 || color_ints[i] < 0) | |
667 return false; | |
668 } | |
669 | 663 |
670 *result = SkColorSetARGB(255, color_ints[0], color_ints[1], color_ints[2]); | 664 DCHECK_EQ(3u, color_bytes.size()); |
| 665 *result = SkColorSetARGB(255, color_bytes[0], color_bytes[1], color_bytes[2]); |
671 return true; | 666 return true; |
672 } | 667 } |
673 | 668 |
674 bool ExtensionActionFunction::SetVisible(bool visible) { | 669 bool ExtensionActionFunction::SetVisible(bool visible) { |
675 if (extension_action_->GetIsVisible(tab_id_) == visible) | 670 if (extension_action_->GetIsVisible(tab_id_) == visible) |
676 return true; | 671 return true; |
677 extension_action_->SetIsVisible(tab_id_, visible); | 672 extension_action_->SetIsVisible(tab_id_, visible); |
678 NotifyChange(); | 673 NotifyChange(); |
679 return true; | 674 return true; |
680 } | 675 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 return true; | 938 return true; |
944 } | 939 } |
945 | 940 |
946 bool EnablePageActionsFunction::RunImpl() { | 941 bool EnablePageActionsFunction::RunImpl() { |
947 return SetPageActionEnabled(true); | 942 return SetPageActionEnabled(true); |
948 } | 943 } |
949 | 944 |
950 bool DisablePageActionsFunction::RunImpl() { | 945 bool DisablePageActionsFunction::RunImpl() { |
951 return SetPageActionEnabled(false); | 946 return SetPageActionEnabled(false); |
952 } | 947 } |
OLD | NEW |