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

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(views::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 2361 string16 stripped_text(views::StripJavascriptSchemas(text));
Peter Kasting 2011/05/24 00:15:18 Nit: Just inline this into the next statement
Cris Neckar 2011/05/24 17:09:40 Done.
2360 // Note: Unlike in the find popup and textfield view, here we completely 2362 // Note: Unlike in the find popup and textfield view, here we completely
2361 // remove whitespace strings containing newlines. We assume users are 2363 // remove whitespace strings containing newlines. We assume users are
2362 // most likely pasting in URLs that may have been split into multiple 2364 // most likely pasting in URLs that may have been split into multiple
2363 // lines in terminals, email programs, etc., and so linebreaks indicate 2365 // lines in terminals, email programs, etc., and so linebreaks indicate
2364 // completely bogus whitespace that would just cause the input to be 2366 // completely bogus whitespace that would just cause the input to be
2365 // invalid. 2367 // invalid.
2366 return CollapseWhitespace(text, true); 2368 return CollapseWhitespace(stripped_text, true);
2367 } 2369 }
2368 2370
2369 // Try bookmark format. 2371 // Try bookmark format.
2370 // 2372 //
2371 // It is tempting to try bookmark format first, but the URL we get out of a 2373 // 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 2374 // 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 2375 // 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 2376 // cannonicalized, which is not what the user expects. By pasting in this
2375 // order, we are sure to paste what the user copied. 2377 // order, we are sure to paste what the user copied.
2376 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), 2378 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
2377 ui::Clipboard::BUFFER_STANDARD)) { 2379 ui::Clipboard::BUFFER_STANDARD)) {
2378 std::string url_str; 2380 std::string url_str;
2379 clipboard->ReadBookmark(NULL, &url_str); 2381 clipboard->ReadBookmark(NULL, &url_str);
2380 // pass resulting url string through GURL to normalize 2382 // pass resulting url string through GURL to normalize
2381 GURL url(url_str); 2383 GURL url(url_str);
2382 if (url.is_valid()) 2384 if (url.is_valid())
2383 return UTF8ToWide(url.spec()); 2385 return views::StripJavascriptSchemas(UTF8ToUTF16(url.spec()));
2384 } 2386 }
2385 2387
2386 return string16(); 2388 return string16();
2387 } 2389 }
2388 2390
2389 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const { 2391 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const {
2390 return !popup_window_mode_ && model_->CanPasteAndGo(text); 2392 return !popup_window_mode_ && model_->CanPasteAndGo(text);
2391 } 2393 }
2392 2394
2393 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { 2395 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. 2597 // PosFromChar(i) might return 0 when i is greater than 1.
2596 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2598 return font_.GetStringWidth(text) + GetHorizontalMargin();
2597 } 2599 }
2598 2600
2599 bool OmniboxViewWin::IsCaretAtEnd() const { 2601 bool OmniboxViewWin::IsCaretAtEnd() const {
2600 long length = GetTextLength(); 2602 long length = GetTextLength();
2601 CHARRANGE sel; 2603 CHARRANGE sel;
2602 GetSelection(sel); 2604 GetSelection(sel);
2603 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2605 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2604 } 2606 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698