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

Unified Diff: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc

Issue 8702002: Strip invalid characters (line breaks, tabs), javascript:schemes from the copied text while pasti... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc
===================================================================
--- chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc (revision 110898)
+++ chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc (working copy)
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/utf_string_conversion_utils.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
@@ -878,9 +879,7 @@
if (data.GetURLAndTitle(&url, &title))
text = UTF8ToUTF16(url.spec());
} else {
- string16 data_string;
- if (data.GetString(&data_string))
- text = CollapseWhitespace(data_string, true);
+ data.GetString(&text);
}
if (!text.empty() && OnPerformDropImpl(text))
@@ -1444,10 +1443,14 @@
// back after shutdown, and similar issues.
GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gchar* text = gtk_clipboard_wait_for_text(x_clipboard);
- string16 text_wstr = UTF8ToUTF16(text ? text : "");
+ string16 sanitized_text(text ?
+ StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) :
+ string16());
g_free(text);
- // Paste and Go menu item.
+ // Paste and Go menu item. Note that CanPasteAndGo() needs to be called
+ // before is_paste_and_search() in order to set up the paste-and-go state.
+ bool can_paste_and_go = model_->CanPasteAndGo(sanitized_text);
GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic(
gfx::ConvertAcceleratorsFromWindowsStyle(
l10n_util::GetStringUTF8(model_->is_paste_and_search() ?
@@ -1455,8 +1458,7 @@
gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste_go_menuitem);
g_signal_connect(paste_go_menuitem, "activate",
G_CALLBACK(HandlePasteAndGoThunk), this);
- gtk_widget_set_sensitive(paste_go_menuitem,
- model_->CanPasteAndGo(text_wstr));
+ gtk_widget_set_sensitive(paste_go_menuitem, can_paste_and_go);
gtk_widget_show(paste_go_menuitem);
g_signal_connect(menu, "deactivate",
@@ -1632,7 +1634,7 @@
GtkTextIter* location,
const gchar* text,
gint len) {
- std::string filtered_text;
+ string16 filtered_text;
filtered_text.reserve(len);
// Filter out new line and tab characters.
@@ -1646,29 +1648,31 @@
if (len == 1 && (text[0] == '\n' || text[0] == '\r'))
enter_was_inserted_ = true;
- const gchar* p = text;
- while (*p && (p - text) < len) {
+ for (const gchar* p = text; *p && (p - text) < len;
+ p = g_utf8_next_char(p)) {
gunichar c = g_utf8_get_char(p);
- const gchar* next = g_utf8_next_char(p);
// 0x200B is Zero Width Space, which is inserted just before the instant
// anchor for working around the GtkTextView's misalignment bug.
// This character might be captured and inserted into the content by undo
// manager, so we need to filter it out here.
- if (c != L'\n' && c != L'\r' && c != L'\t' && c != 0x200B)
- filtered_text.append(p, next);
-
- p = next;
+ if (c != 0x200B)
+ base::WriteUnicodeCharacter(c, &filtered_text);
}
- if (filtered_text.length()) {
+ if (model_->is_pasting())
+ filtered_text = StripJavascriptSchemas(
+ CollapseWhitespace(filtered_text, true));
+
+ if (!filtered_text.empty()) {
// Avoid inserting the text after the instant anchor.
ValidateTextBufferIter(location);
// Call the default handler to insert filtered text.
GtkTextBufferClass* klass = GTK_TEXT_BUFFER_GET_CLASS(buffer);
- klass->insert_text(buffer, location, filtered_text.data(),
- static_cast<gint>(filtered_text.length()));
+ std::string utf8_text = UTF16ToUTF8(filtered_text);
+ klass->insert_text(buffer, location, utf8_text.data(),
+ static_cast<gint>(utf8_text.length()));
}
// Stop propagating the signal emission to prevent the default handler from
@@ -1795,7 +1799,8 @@
}
bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) {
- if (model_->CanPasteAndGo(CollapseWhitespace(text, true))) {
+ if (model_->CanPasteAndGo(StripJavascriptSchemas(
+ CollapseWhitespace(text, true)))) {
model_->PasteAndGo();
return true;
}
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit.h ('k') | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698