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

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
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(UTF8ToUTF16(url.spec()));
962 model()->AcceptInput(CURRENT_TAB, true); 962 bool changed = StripJavascriptSchema(text, &text);
963 SetUserText(text);
964 if (!changed)
965 model()->AcceptInput(CURRENT_TAB, true);
963 return CopyOrLinkDragOperation(event.source_operations()); 966 return CopyOrLinkDragOperation(event.source_operations());
964 } 967 }
965 } else if (data.HasString()) { 968 } else if (data.HasString()) {
966 int string_drop_position = drop_highlight_position(); 969 int string_drop_position = drop_highlight_position();
967 string16 text; 970 string16 text;
968 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) { 971 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) {
969 DCHECK(string_drop_position == -1 || 972 DCHECK(string_drop_position == -1 ||
970 ((string_drop_position >= 0) && 973 ((string_drop_position >= 0) &&
971 (string_drop_position <= GetTextLength()))); 974 (string_drop_position <= GetTextLength())));
972 if (in_drag) { 975 if (in_drag) {
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 model_->OnChanged(); 2352 model_->OnChanged();
2350 } 2353 }
2351 2354
2352 string16 OmniboxViewWin::GetClipboardText() const { 2355 string16 OmniboxViewWin::GetClipboardText() const {
2353 // Try text format. 2356 // Try text format.
2354 ui::Clipboard* clipboard = g_browser_process->clipboard(); 2357 ui::Clipboard* clipboard = g_browser_process->clipboard();
2355 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), 2358 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
2356 ui::Clipboard::BUFFER_STANDARD)) { 2359 ui::Clipboard::BUFFER_STANDARD)) {
2357 string16 text; 2360 string16 text;
2358 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 2361 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
2359 2362 StripJavascriptSchema(text, &text);
2360 // Note: Unlike in the find popup and textfield view, here we completely 2363 // Note: Unlike in the find popup and textfield view, here we completely
2361 // remove whitespace strings containing newlines. We assume users are 2364 // remove whitespace strings containing newlines. We assume users are
2362 // most likely pasting in URLs that may have been split into multiple 2365 // most likely pasting in URLs that may have been split into multiple
2363 // lines in terminals, email programs, etc., and so linebreaks indicate 2366 // lines in terminals, email programs, etc., and so linebreaks indicate
2364 // completely bogus whitespace that would just cause the input to be 2367 // completely bogus whitespace that would just cause the input to be
2365 // invalid. 2368 // invalid.
2366 return CollapseWhitespace(text, true); 2369 return CollapseWhitespace(text, true);
2367 } 2370 }
2368 2371
2369 // Try bookmark format. 2372 // Try bookmark format.
2370 // 2373 //
2371 // It is tempting to try bookmark format first, but the URL we get out of a 2374 // 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 2375 // 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 2376 // 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 2377 // cannonicalized, which is not what the user expects. By pasting in this
2375 // order, we are sure to paste what the user copied. 2378 // order, we are sure to paste what the user copied.
2376 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), 2379 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
2377 ui::Clipboard::BUFFER_STANDARD)) { 2380 ui::Clipboard::BUFFER_STANDARD)) {
2378 std::string url_str; 2381 std::string url_str;
2382 string16 text;
2379 clipboard->ReadBookmark(NULL, &url_str); 2383 clipboard->ReadBookmark(NULL, &url_str);
2380 // pass resulting url string through GURL to normalize 2384 // pass resulting url string through GURL to normalize
2381 GURL url(url_str); 2385 GURL url(url_str);
2382 if (url.is_valid()) 2386 if (url.is_valid())
2383 return UTF8ToWide(url.spec()); 2387 StripJavascriptSchema(UTF8ToUTF16(url.spec()), &text);
2388 return text;
2384 } 2389 }
2385 2390
2386 return string16(); 2391 return string16();
2387 } 2392 }
2388 2393
2389 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const { 2394 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const {
2390 return !popup_window_mode_ && model_->CanPasteAndGo(text); 2395 return !popup_window_mode_ && model_->CanPasteAndGo(text);
2391 } 2396 }
2392 2397
2393 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { 2398 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. 2600 // PosFromChar(i) might return 0 when i is greater than 1.
2596 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2601 return font_.GetStringWidth(text) + GetHorizontalMargin();
2597 } 2602 }
2598 2603
2599 bool OmniboxViewWin::IsCaretAtEnd() const { 2604 bool OmniboxViewWin::IsCaretAtEnd() const {
2600 long length = GetTextLength(); 2605 long length = GetTextLength();
2601 CHARRANGE sel; 2606 CHARRANGE sel;
2602 GetSelection(sel); 2607 GetSelection(sel);
2603 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2608 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2604 } 2609 }
OLDNEW
« chrome/browser/ui/omnibox/omnibox_view.h ('K') | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698