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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 6982011: Strip leading "javascript:" schemas from text pasted or dropped into the omnibox. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 | « chrome/browser/ui/omnibox/omnibox_view.cc ('k') | chrome/chrome_browser.gypi » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/views/omnibox/omnibox_view_win.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <locale> 8 #include <locale>
9 #include <string> 9 #include <string>
10 10
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 } 951 }
952 952
953 int OmniboxViewWin::OnPerformDropImpl(const views::DropTargetEvent& event, 953 int OmniboxViewWin::OnPerformDropImpl(const views::DropTargetEvent& event,
954 bool in_drag) { 954 bool in_drag) {
955 const ui::OSExchangeData& data = event.data(); 955 const ui::OSExchangeData& data = event.data();
956 956
957 if (data.HasURL()) { 957 if (data.HasURL()) {
958 GURL url; 958 GURL url;
959 string16 title; 959 string16 title;
960 if (data.GetURLAndTitle(&url, &title)) { 960 if (data.GetURLAndTitle(&url, &title)) {
961 SetUserText(UTF8ToWide(url.spec())); 961 string16 text(StripJavascriptSchemas(UTF8ToUTF16(url.spec())));
962 model()->AcceptInput(CURRENT_TAB, true); 962 SetUserText(text);
963 if (url.spec().length() == text.length())
964 model()->AcceptInput(CURRENT_TAB, true);
963 return CopyOrLinkDragOperation(event.source_operations()); 965 return CopyOrLinkDragOperation(event.source_operations());
964 } 966 }
965 } else if (data.HasString()) { 967 } else if (data.HasString()) {
966 int string_drop_position = drop_highlight_position(); 968 int string_drop_position = drop_highlight_position();
967 string16 text; 969 string16 text;
968 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) { 970 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) {
969 DCHECK(string_drop_position == -1 || 971 DCHECK(string_drop_position == -1 ||
970 ((string_drop_position >= 0) && 972 ((string_drop_position >= 0) &&
971 (string_drop_position <= GetTextLength()))); 973 (string_drop_position <= GetTextLength())));
972 if (in_drag) { 974 if (in_drag) {
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 model_->OnChanged(); 2351 model_->OnChanged();
2350 } 2352 }
2351 2353
2352 string16 OmniboxViewWin::GetClipboardText() const { 2354 string16 OmniboxViewWin::GetClipboardText() const {
2353 // Try text format. 2355 // Try text format.
2354 ui::Clipboard* clipboard = g_browser_process->clipboard(); 2356 ui::Clipboard* clipboard = g_browser_process->clipboard();
2355 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), 2357 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
2356 ui::Clipboard::BUFFER_STANDARD)) { 2358 ui::Clipboard::BUFFER_STANDARD)) {
2357 string16 text; 2359 string16 text;
2358 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 2360 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
2359
2360 // Note: Unlike in the find popup and textfield view, here we completely 2361 // Note: Unlike in the find popup and textfield view, here we completely
2361 // remove whitespace strings containing newlines. We assume users are 2362 // remove whitespace strings containing newlines. We assume users are
2362 // most likely pasting in URLs that may have been split into multiple 2363 // most likely pasting in URLs that may have been split into multiple
2363 // lines in terminals, email programs, etc., and so linebreaks indicate 2364 // lines in terminals, email programs, etc., and so linebreaks indicate
2364 // completely bogus whitespace that would just cause the input to be 2365 // completely bogus whitespace that would just cause the input to be
2365 // invalid. 2366 // invalid.
2366 return CollapseWhitespace(text, true); 2367 return CollapseWhitespace(StripJavascriptSchemas(text), true);
2367 } 2368 }
2368 2369
2369 // Try bookmark format. 2370 // Try bookmark format.
2370 // 2371 //
2371 // It is tempting to try bookmark format first, but the URL we get out of a 2372 // It is tempting to try bookmark format first, but the URL we get out of a
2372 // bookmark has been cannonicalized via GURL. This means if a user copies 2373 // bookmark has been cannonicalized via GURL. This means if a user copies
2373 // and pastes from the URL bar to itself, the text will get fixed up and 2374 // and pastes from the URL bar to itself, the text will get fixed up and
2374 // cannonicalized, which is not what the user expects. By pasting in this 2375 // cannonicalized, which is not what the user expects. By pasting in this
2375 // order, we are sure to paste what the user copied. 2376 // order, we are sure to paste what the user copied.
2376 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), 2377 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
2377 ui::Clipboard::BUFFER_STANDARD)) { 2378 ui::Clipboard::BUFFER_STANDARD)) {
2378 std::string url_str; 2379 std::string url_str;
2379 clipboard->ReadBookmark(NULL, &url_str); 2380 clipboard->ReadBookmark(NULL, &url_str);
2380 // pass resulting url string through GURL to normalize 2381 // pass resulting url string through GURL to normalize
2381 GURL url(url_str); 2382 GURL url(url_str);
2382 if (url.is_valid()) 2383 if (url.is_valid())
2383 return UTF8ToWide(url.spec()); 2384 return StripJavascriptSchemas(UTF8ToUTF16(url.spec()));
2384 } 2385 }
2385 2386
2386 return string16(); 2387 return string16();
2387 } 2388 }
2388 2389
2389 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const { 2390 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const {
2390 return !popup_window_mode_ && model_->CanPasteAndGo(text); 2391 return !popup_window_mode_ && model_->CanPasteAndGo(text);
2391 } 2392 }
2392 2393
2393 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { 2394 ITextDocument* OmniboxViewWin::GetTextObjectModel() const {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 // PosFromChar(i) might return 0 when i is greater than 1. 2596 // PosFromChar(i) might return 0 when i is greater than 1.
2596 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2597 return font_.GetStringWidth(text) + GetHorizontalMargin();
2597 } 2598 }
2598 2599
2599 bool OmniboxViewWin::IsCaretAtEnd() const { 2600 bool OmniboxViewWin::IsCaretAtEnd() const {
2600 long length = GetTextLength(); 2601 long length = GetTextLength();
2601 CHARRANGE sel; 2602 CHARRANGE sel;
2602 GetSelection(sel); 2603 GetSelection(sel);
2603 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2604 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2604 } 2605 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698