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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

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/cocoa/omnibox/omnibox_view_mac.h" 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
6 6
7 #include <Carbon/Carbon.h> // kVK_Return 7 #include <Carbon/Carbon.h> // kVK_Return
8 8
9 #include "app/mac/nsimage_cache.h" 9 #include "app/mac/nsimage_cache.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 // TODO(shess): Copied from omnibox_view_win.cc. Could this be pushed into the 1056 // TODO(shess): Copied from omnibox_view_win.cc. Could this be pushed into the
1057 // model? 1057 // model?
1058 string16 OmniboxViewMac::GetClipboardText(ui::Clipboard* clipboard) { 1058 string16 OmniboxViewMac::GetClipboardText(ui::Clipboard* clipboard) {
1059 // omnibox_view_win.cc assumes this can never happen, we will too. 1059 // omnibox_view_win.cc assumes this can never happen, we will too.
1060 DCHECK(clipboard); 1060 DCHECK(clipboard);
1061 1061
1062 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), 1062 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
1063 ui::Clipboard::BUFFER_STANDARD)) { 1063 ui::Clipboard::BUFFER_STANDARD)) {
1064 string16 text16; 1064 string16 text16;
1065 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text16); 1065 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text16);
1066 StripJavascriptSchema(text16, &text16);
1066 1067
1067 // Note: Unlike in the find popup and textfield view, here we completely 1068 // Note: Unlike in the find popup and textfield view, here we completely
1068 // remove whitespace strings containing newlines. We assume users are 1069 // remove whitespace strings containing newlines. We assume users are
1069 // most likely pasting in URLs that may have been split into multiple 1070 // most likely pasting in URLs that may have been split into multiple
1070 // lines in terminals, email programs, etc., and so linebreaks indicate 1071 // lines in terminals, email programs, etc., and so linebreaks indicate
1071 // completely bogus whitespace that would just cause the input to be 1072 // completely bogus whitespace that would just cause the input to be
1072 // invalid. 1073 // invalid.
1073 return CollapseWhitespace(text16, true); 1074 return CollapseWhitespace(text16, true);
1074 } 1075 }
1075 1076
1076 // Try bookmark format. 1077 // Try bookmark format.
1077 // 1078 //
1078 // It is tempting to try bookmark format first, but the URL we get out of a 1079 // It is tempting to try bookmark format first, but the URL we get out of a
1079 // bookmark has been cannonicalized via GURL. This means if a user copies 1080 // bookmark has been cannonicalized via GURL. This means if a user copies
1080 // and pastes from the URL bar to itself, the text will get fixed up and 1081 // and pastes from the URL bar to itself, the text will get fixed up and
1081 // cannonicalized, which is not what the user expects. By pasting in this 1082 // cannonicalized, which is not what the user expects. By pasting in this
1082 // order, we are sure to paste what the user copied. 1083 // order, we are sure to paste what the user copied.
1083 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), 1084 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
1084 ui::Clipboard::BUFFER_STANDARD)) { 1085 ui::Clipboard::BUFFER_STANDARD)) {
1085 std::string url_str; 1086 std::string url_str;
1087 string16 text;
1086 clipboard->ReadBookmark(NULL, &url_str); 1088 clipboard->ReadBookmark(NULL, &url_str);
1087 // pass resulting url string through GURL to normalize 1089 // pass resulting url string through GURL to normalize
1088 GURL url(url_str); 1090 GURL url(url_str);
1089 if (url.is_valid()) { 1091 if (url.is_valid()) {
1090 return UTF8ToUTF16(url.spec()); 1092 StripJavascriptSchema(UTF8ToUTF16(url.spec()), &text);
1093 return text;
1091 } 1094 }
1092 } 1095 }
1093 1096
1094 return string16(); 1097 return string16();
1095 } 1098 }
1096 1099
1097 // static 1100 // static
1098 NSFont* OmniboxViewMac::GetFieldFont() { 1101 NSFont* OmniboxViewMac::GetFieldFont() {
1099 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1102 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1100 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont(); 1103 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont();
1101 } 1104 }
1102 1105
1103 NSUInteger OmniboxViewMac::GetTextLength() const { 1106 NSUInteger OmniboxViewMac::GetTextLength() const {
1104 return ([field_ currentEditor] ? 1107 return ([field_ currentEditor] ?
1105 [[[field_ currentEditor] string] length] : 1108 [[[field_ currentEditor] string] length] :
1106 [[field_ stringValue] length]) - suggest_text_length_; 1109 [[field_ stringValue] length]) - suggest_text_length_;
1107 } 1110 }
1108 1111
1109 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { 1112 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) {
1110 DCHECK(pos <= GetTextLength()); 1113 DCHECK(pos <= GetTextLength());
1111 SetSelectedRange(NSMakeRange(pos, pos)); 1114 SetSelectedRange(NSMakeRange(pos, pos));
1112 } 1115 }
1113 1116
1114 bool OmniboxViewMac::IsCaretAtEnd() const { 1117 bool OmniboxViewMac::IsCaretAtEnd() const {
1115 const NSRange selection = GetSelectedRange(); 1118 const NSRange selection = GetSelectedRange();
1116 return selection.length == 0 && selection.location == GetTextLength(); 1119 return selection.length == 0 && selection.location == GetTextLength();
1117 } 1120 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm » ('j') | chrome/browser/ui/omnibox/omnibox_view.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698