OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_menu_manager.h" | 5 #include "chrome/browser/extensions/extension_menu_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 13 #include "base/values.h" |
15 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
16 #include "chrome/browser/extensions/extension_message_service.h" | 15 #include "chrome/browser/extensions/extension_message_service.h" |
17 #include "chrome/browser/extensions/extension_tabs_module.h" | 16 #include "chrome/browser/extensions/extension_tabs_module.h" |
18 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
19 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 ExtensionMenuItem* child = *i; | 69 ExtensionMenuItem* child = *i; |
71 result.insert(child->id()); | 70 result.insert(child->id()); |
72 std::set<Id> removed = child->RemoveAllDescendants(); | 71 std::set<Id> removed = child->RemoveAllDescendants(); |
73 result.insert(removed.begin(), removed.end()); | 72 result.insert(removed.begin(), removed.end()); |
74 } | 73 } |
75 STLDeleteElements(&children_); | 74 STLDeleteElements(&children_); |
76 return result; | 75 return result; |
77 } | 76 } |
78 | 77 |
79 string16 ExtensionMenuItem::TitleWithReplacement( | 78 string16 ExtensionMenuItem::TitleWithReplacement( |
80 const string16& selection, size_t max_length) const { | 79 const string16& selection) const { |
81 string16 result = UTF8ToUTF16(title_); | 80 string16 result = UTF8ToUTF16(title_); |
82 // TODO(asargent) - Change this to properly handle %% escaping so you can | 81 // TODO(asargent) - Change this to properly handle %% escaping so you can |
83 // put "%s" in titles that won't get substituted. | 82 // put "%s" in titles that won't get substituted. |
84 ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16("%s"), selection); | 83 ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16("%s"), selection); |
85 | |
86 if (result.length() > max_length) { | |
87 result = WideToUTF16(l10n_util::TruncateString(UTF16ToWideHack(result), | |
88 max_length)); | |
89 } | |
90 return result; | 84 return result; |
91 } | 85 } |
92 | 86 |
93 bool ExtensionMenuItem::SetChecked(bool checked) { | 87 bool ExtensionMenuItem::SetChecked(bool checked) { |
94 if (type_ != CHECKBOX && type_ != RADIO) | 88 if (type_ != CHECKBOX && type_ != RADIO) |
95 return false; | 89 return false; |
96 checked_ = checked; | 90 checked_ = checked; |
97 return true; | 91 return true; |
98 } | 92 } |
99 | 93 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 const SkBitmap& ExtensionMenuManager::GetIconForExtension( | 448 const SkBitmap& ExtensionMenuManager::GetIconForExtension( |
455 const std::string& extension_id) { | 449 const std::string& extension_id) { |
456 return icon_manager_.GetIcon(extension_id); | 450 return icon_manager_.GetIcon(extension_id); |
457 } | 451 } |
458 | 452 |
459 // static | 453 // static |
460 bool ExtensionMenuManager::HasAllowedScheme(const GURL& url) { | 454 bool ExtensionMenuManager::HasAllowedScheme(const GURL& url) { |
461 URLPattern pattern(kAllowedSchemes); | 455 URLPattern pattern(kAllowedSchemes); |
462 return pattern.SetScheme(url.scheme()); | 456 return pattern.SetScheme(url.scheme()); |
463 } | 457 } |
OLD | NEW |