| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/clipboard.h" | 8 #include "base/clipboard.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/platform_util.h" | 26 #include "chrome/common/platform_util.h" |
| 27 #include "chrome/common/pref_service.h" | 27 #include "chrome/common/pref_service.h" |
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 30 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 31 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
| 32 #include "webkit/glue/media_player_action.h" | 32 #include "webkit/glue/media_player_action.h" |
| 33 | 33 |
| 34 namespace { |
| 35 |
| 36 string16 EscapeAmpersands(const string16& text) { |
| 37 string16 ret; |
| 38 ret.reserve(text.length() * 2); |
| 39 for (string16::const_iterator i = text.begin(); |
| 40 i != text.end(); ++i) { |
| 41 // The escape for an ampersand is two ampersands. |
| 42 if ('&' == *i) |
| 43 ret.push_back(*i); |
| 44 |
| 45 ret.push_back(*i); |
| 46 } |
| 47 |
| 48 return ret; |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
| 34 RenderViewContextMenu::RenderViewContextMenu( | 53 RenderViewContextMenu::RenderViewContextMenu( |
| 35 TabContents* tab_contents, | 54 TabContents* tab_contents, |
| 36 const ContextMenuParams& params) | 55 const ContextMenuParams& params) |
| 37 : params_(params), | 56 : params_(params), |
| 38 source_tab_contents_(tab_contents), | 57 source_tab_contents_(tab_contents), |
| 39 profile_(tab_contents->profile()) { | 58 profile_(tab_contents->profile()) { |
| 40 } | 59 } |
| 41 | 60 |
| 42 RenderViewContextMenu::~RenderViewContextMenu() { | 61 RenderViewContextMenu::~RenderViewContextMenu() { |
| 43 } | 62 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 201 |
| 183 void RenderViewContextMenu::AppendCopyItem() { | 202 void RenderViewContextMenu::AppendCopyItem() { |
| 184 AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); | 203 AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); |
| 185 } | 204 } |
| 186 | 205 |
| 187 void RenderViewContextMenu::AppendSearchProvider() { | 206 void RenderViewContextMenu::AppendSearchProvider() { |
| 188 DCHECK(profile_); | 207 DCHECK(profile_); |
| 189 const TemplateURL* const default_provider = | 208 const TemplateURL* const default_provider = |
| 190 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); | 209 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); |
| 191 if (default_provider != NULL) { | 210 if (default_provider != NULL) { |
| 192 std::wstring selection_text = | 211 string16 selection_text = EscapeAmpersands(WideToUTF16( |
| 193 l10n_util::TruncateString(params_.selection_text, 50); | 212 l10n_util::TruncateString(params_.selection_text, 50))); |
| 194 if (!selection_text.empty()) { | 213 if (!selection_text.empty()) { |
| 195 string16 label(WideToUTF16( | 214 string16 label(l10n_util::GetStringFUTF16( |
| 196 l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, | 215 IDS_CONTENT_CONTEXT_SEARCHWEBFOR, |
| 197 default_provider->short_name(), | 216 WideToUTF16(default_provider->short_name()), |
| 198 selection_text))); | 217 selection_text)); |
| 199 AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label); | 218 AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label); |
| 200 } | 219 } |
| 201 } | 220 } |
| 202 } | 221 } |
| 203 | 222 |
| 204 void RenderViewContextMenu::AppendEditableItems() { | 223 void RenderViewContextMenu::AppendEditableItems() { |
| 205 // Append Dictionary spell check suggestions. | 224 // Append Dictionary spell check suggestions. |
| 206 for (size_t i = 0; i < params_.dictionary_suggestions.size() && | 225 for (size_t i = 0; i < params_.dictionary_suggestions.size() && |
| 207 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; | 226 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; |
| 208 ++i) { | 227 ++i) { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 WriteTextToClipboard(UTF8ToUTF16(utf8_text)); | 824 WriteTextToClipboard(UTF8ToUTF16(utf8_text)); |
| 806 DidWriteURLToClipboard(utf8_text); | 825 DidWriteURLToClipboard(utf8_text); |
| 807 } | 826 } |
| 808 | 827 |
| 809 void RenderViewContextMenu::MediaPlayerActionAt( | 828 void RenderViewContextMenu::MediaPlayerActionAt( |
| 810 int x, | 829 int x, |
| 811 int y, | 830 int y, |
| 812 const MediaPlayerAction& action) { | 831 const MediaPlayerAction& action) { |
| 813 source_tab_contents_->render_view_host()->MediaPlayerActionAt(x, y, action); | 832 source_tab_contents_->render_view_host()->MediaPlayerActionAt(x, y, action); |
| 814 } | 833 } |
| OLD | NEW |