Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 1594039: Trim whitespace and check for unsafe scheme before adding a url in context me... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <functional> 5 #include <functional>
6 6
7 #include "chrome/browser/tab_contents/render_view_context_menu.h" 7 #include "chrome/browser/tab_contents/render_view_context_menu.h"
8 8
9 #include "app/clipboard/clipboard.h" 9 #include "app/clipboard/clipboard.h"
10 #include "app/clipboard/scoped_clipboard_writer.h" 10 #include "app/clipboard/scoped_clipboard_writer.h"
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/string_util.h"
14 #include "chrome/app/chrome_dll_resource.h" 15 #include "chrome/app/chrome_dll_resource.h"
15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/child_process_security_policy.h"
17 #include "chrome/browser/debugger/devtools_manager.h" 19 #include "chrome/browser/debugger/devtools_manager.h"
18 #include "chrome/browser/debugger/devtools_window.h" 20 #include "chrome/browser/debugger/devtools_window.h"
19 #include "chrome/browser/download/download_manager.h" 21 #include "chrome/browser/download/download_manager.h"
20 #include "chrome/browser/extensions/extension_menu_manager.h" 22 #include "chrome/browser/extensions/extension_menu_manager.h"
21 #include "chrome/browser/extensions/extensions_service.h" 23 #include "chrome/browser/extensions/extensions_service.h"
22 #include "chrome/browser/fonts_languages_window.h" 24 #include "chrome/browser/fonts_languages_window.h"
23 #include "chrome/browser/metrics/user_metrics.h" 25 #include "chrome/browser/metrics/user_metrics.h"
24 #include "chrome/browser/net/browser_url_util.h" 26 #include "chrome/browser/net/browser_url_util.h"
25 #include "chrome/browser/page_info_window.h" 27 #include "chrome/browser/page_info_window.h"
26 #include "chrome/browser/pref_service.h" 28 #include "chrome/browser/pref_service.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); 434 AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO);
433 } 435 }
434 436
435 void RenderViewContextMenu::AppendCopyItem() { 437 void RenderViewContextMenu::AppendCopyItem() {
436 AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); 438 AppendMenuItem(IDS_CONTENT_CONTEXT_COPY);
437 } 439 }
438 440
439 void RenderViewContextMenu::AppendSearchProvider() { 441 void RenderViewContextMenu::AppendSearchProvider() {
440 DCHECK(profile_); 442 DCHECK(profile_);
441 443
444 TrimWhitespace(params_.selection_text, TRIM_ALL, &params_.selection_text);
445
Peter Kasting 2010/04/20 18:25:32 Nit: You could probably remove this blank line.
442 if (params_.selection_text.empty()) 446 if (params_.selection_text.empty())
443 return; 447 return;
444 448
445 AutocompleteMatch match; 449 AutocompleteMatch match;
446 profile_->GetAutocompleteClassifier()->Classify(params_.selection_text, 450 profile_->GetAutocompleteClassifier()->Classify(params_.selection_text,
447 std::wstring(), &match, NULL); 451 std::wstring(), &match, NULL);
448 selection_navigation_url_ = match.destination_url; 452 selection_navigation_url_ = match.destination_url;
449 if (!selection_navigation_url_.is_valid()) 453 if (!selection_navigation_url_.is_valid())
450 return; 454 return;
451 455
452 string16 printable_selection_text = PrintableSelectionText(); 456 string16 printable_selection_text = PrintableSelectionText();
453 // Escape "&" as "&&". 457 // Escape "&" as "&&".
454 for (size_t i = printable_selection_text.find('&'); i != string16::npos; 458 for (size_t i = printable_selection_text.find('&'); i != string16::npos;
455 i = printable_selection_text.find('&', i + 2)) 459 i = printable_selection_text.find('&', i + 2))
456 printable_selection_text.insert(i, 1, '&'); 460 printable_selection_text.insert(i, 1, '&');
457 461
458 if (match.transition == PageTransition::TYPED) { 462 if (match.transition == PageTransition::TYPED) {
459 AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL, 463 if (ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme(
460 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL, 464 selection_navigation_url_.scheme())) {
461 printable_selection_text)); 465 AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL,
466 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL,
467 printable_selection_text));
468 }
462 } else { 469 } else {
463 const TemplateURL* const default_provider = 470 const TemplateURL* const default_provider =
464 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); 471 profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
465 if (!default_provider) 472 if (!default_provider)
466 return; 473 return;
467 AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, 474 AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
468 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, 475 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
469 WideToUTF16(default_provider->short_name()), 476 WideToUTF16(default_provider->short_name()),
470 printable_selection_text)); 477 printable_selection_text));
471 } 478 }
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1292 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1286 g_browser_process->clipboard()); 1293 g_browser_process->clipboard());
1287 } 1294 }
1288 1295
1289 void RenderViewContextMenu::MediaPlayerActionAt( 1296 void RenderViewContextMenu::MediaPlayerActionAt(
1290 const gfx::Point& location, 1297 const gfx::Point& location,
1291 const WebMediaPlayerAction& action) { 1298 const WebMediaPlayerAction& action) {
1292 source_tab_contents_->render_view_host()->MediaPlayerActionAt( 1299 source_tab_contents_->render_view_host()->MediaPlayerActionAt(
1293 location, action); 1300 location, action);
1294 } 1301 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698