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

Side by Side Diff: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc

Issue 8513002: Strip invalid characters (line breaks, tabs), javascript:schemes from the copied text before pasting (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit.h ('k') | no next file » | 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/gtk/omnibox/omnibox_view_gtk.h" 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 int OmniboxViewGtk::OnPerformDrop( 871 int OmniboxViewGtk::OnPerformDrop(
872 const views::DropTargetEvent& event) { 872 const views::DropTargetEvent& event) {
873 string16 text; 873 string16 text;
874 const ui::OSExchangeData& data = event.data(); 874 const ui::OSExchangeData& data = event.data();
875 if (data.HasURL()) { 875 if (data.HasURL()) {
876 GURL url; 876 GURL url;
877 string16 title; 877 string16 title;
878 if (data.GetURLAndTitle(&url, &title)) 878 if (data.GetURLAndTitle(&url, &title))
879 text = UTF8ToUTF16(url.spec()); 879 text = UTF8ToUTF16(url.spec());
880 } else { 880 } else {
881 string16 data_string; 881 data.GetString(&text);
882 if (data.GetString(&data_string))
883 text = CollapseWhitespace(data_string, true);
884 } 882 }
885 883
886 if (!text.empty() && OnPerformDropImpl(text)) 884 if (!text.empty() && OnPerformDropImpl(text))
887 return CopyOrLinkDragOperation(event.source_operations()); 885 return CopyOrLinkDragOperation(event.source_operations());
888 886
889 return ui::DragDropTypes::DRAG_NONE; 887 return ui::DragDropTypes::DRAG_NONE;
890 } 888 }
891 #endif // defined(TOOLKIT_VIEWS) 889 #endif // defined(TOOLKIT_VIEWS)
892 890
893 void OmniboxViewGtk::Observe(int type, 891 void OmniboxViewGtk::Observe(int type,
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 gtk_widget_set_sensitive(search_engine_menuitem, 1435 gtk_widget_set_sensitive(search_engine_menuitem,
1438 command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); 1436 command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES));
1439 gtk_widget_show(search_engine_menuitem); 1437 gtk_widget_show(search_engine_menuitem);
1440 1438
1441 // We need to update the paste and go controller before we know what text 1439 // We need to update the paste and go controller before we know what text
1442 // to show. We could do this all asynchronously, but it would be elaborate 1440 // to show. We could do this all asynchronously, but it would be elaborate
1443 // because we'd have to account for multiple menus showing, getting called 1441 // because we'd have to account for multiple menus showing, getting called
1444 // back after shutdown, and similar issues. 1442 // back after shutdown, and similar issues.
1445 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); 1443 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
1446 gchar* text = gtk_clipboard_wait_for_text(x_clipboard); 1444 gchar* text = gtk_clipboard_wait_for_text(x_clipboard);
1447 string16 text_wstr = UTF8ToUTF16(text ? text : ""); 1445 string16 sanitized_text(text ?
1446 StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) :
1447 string16());
1448 g_free(text); 1448 g_free(text);
1449 1449
1450 // Paste and Go menu item. 1450 // Paste and Go menu item.
1451 bool can_paste_and_go = model_->CanPasteAndGo(sanitized_text);
1451 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic( 1452 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic(
1452 gfx::ConvertAcceleratorsFromWindowsStyle( 1453 gfx::ConvertAcceleratorsFromWindowsStyle(
1453 l10n_util::GetStringUTF8(model_->is_paste_and_search() ? 1454 l10n_util::GetStringUTF8(model_->is_paste_and_search() ?
1454 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str()); 1455 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str());
1455 gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste_go_menuitem); 1456 gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste_go_menuitem);
1456 g_signal_connect(paste_go_menuitem, "activate", 1457 g_signal_connect(paste_go_menuitem, "activate",
1457 G_CALLBACK(HandlePasteAndGoThunk), this); 1458 G_CALLBACK(HandlePasteAndGoThunk), this);
1458 gtk_widget_set_sensitive(paste_go_menuitem, 1459 gtk_widget_set_sensitive(paste_go_menuitem, can_paste_and_go);
1459 model_->CanPasteAndGo(text_wstr));
1460 gtk_widget_show(paste_go_menuitem); 1460 gtk_widget_show(paste_go_menuitem);
1461 1461
1462 g_signal_connect(menu, "deactivate", 1462 g_signal_connect(menu, "deactivate",
1463 G_CALLBACK(HandlePopupMenuDeactivateThunk), this); 1463 G_CALLBACK(HandlePopupMenuDeactivateThunk), this);
1464 } 1464 }
1465 1465
1466 void OmniboxViewGtk::HandleEditSearchEngines(GtkWidget* sender) { 1466 void OmniboxViewGtk::HandleEditSearchEngines(GtkWidget* sender) {
1467 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); 1467 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES);
1468 } 1468 }
1469 1469
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 1648
1649 const gchar* p = text; 1649 const gchar* p = text;
1650 while (*p && (p - text) < len) { 1650 while (*p && (p - text) < len) {
1651 gunichar c = g_utf8_get_char(p); 1651 gunichar c = g_utf8_get_char(p);
1652 const gchar* next = g_utf8_next_char(p); 1652 const gchar* next = g_utf8_next_char(p);
1653 1653
1654 // 0x200B is Zero Width Space, which is inserted just before the instant 1654 // 0x200B is Zero Width Space, which is inserted just before the instant
1655 // anchor for working around the GtkTextView's misalignment bug. 1655 // anchor for working around the GtkTextView's misalignment bug.
1656 // This character might be captured and inserted into the content by undo 1656 // This character might be captured and inserted into the content by undo
1657 // manager, so we need to filter it out here. 1657 // manager, so we need to filter it out here.
1658 if (c != L'\n' && c != L'\r' && c != L'\t' && c != 0x200B) 1658 if (c != 0x200B)
1659 filtered_text.append(p, next); 1659 filtered_text.append(p, next);
Alexei Svitkine (slow) 2011/11/23 14:35:47 Now, this isn't right anymore - since it doesn't m
1660 1660
1661 p = next; 1661 p = next;
1662 } 1662 }
1663 1663
1664 if (filtered_text.length()) { 1664 std::string sanitized_text;
1665 if (model_->is_pasting())
1666 sanitized_text =
1667 UTF16ToUTF8(StripJavascriptSchemas(
1668 CollapseWhitespace(UTF8ToUTF16(filtered_text), true)));
Alexei Svitkine (slow) 2011/11/23 04:26:41 Nit: Can all the text - including |filtered_text|
SanjoyPal 2011/11/23 05:56:11 Done.
1669 else
1670 sanitized_text = filtered_text;
1671
1672 if (!sanitized_text.empty()) {
1665 // Avoid inserting the text after the instant anchor. 1673 // Avoid inserting the text after the instant anchor.
1666 ValidateTextBufferIter(location); 1674 ValidateTextBufferIter(location);
1667 1675
1668 // Call the default handler to insert filtered text. 1676 // Call the default handler to insert filtered text.
1669 GtkTextBufferClass* klass = GTK_TEXT_BUFFER_GET_CLASS(buffer); 1677 GtkTextBufferClass* klass = GTK_TEXT_BUFFER_GET_CLASS(buffer);
1670 klass->insert_text(buffer, location, filtered_text.data(), 1678 klass->insert_text(buffer, location, sanitized_text.data(),
1671 static_cast<gint>(filtered_text.length())); 1679 static_cast<gint>(sanitized_text.length()));
1672 } 1680 }
1673 1681
1674 // Stop propagating the signal emission to prevent the default handler from 1682 // Stop propagating the signal emission to prevent the default handler from
1675 // being called again. 1683 // being called again.
1676 static guint signal_id = g_signal_lookup("insert-text", GTK_TYPE_TEXT_BUFFER); 1684 static guint signal_id = g_signal_lookup("insert-text", GTK_TYPE_TEXT_BUFFER);
1677 g_signal_stop_emission(buffer, signal_id, 0); 1685 g_signal_stop_emission(buffer, signal_id, 0);
1678 } 1686 }
1679 1687
1680 void OmniboxViewGtk::HandleBackSpace(GtkWidget* sender) { 1688 void OmniboxViewGtk::HandleBackSpace(GtkWidget* sender) {
1681 // Checks if it's currently in keyword search mode. 1689 // Checks if it's currently in keyword search mode.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 0); 1796 0);
1789 1797
1790 if (!copy && gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view_))) 1798 if (!copy && gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view_)))
1791 gtk_text_buffer_delete_selection(text_buffer_, true, true); 1799 gtk_text_buffer_delete_selection(text_buffer_, true, true);
1792 } 1800 }
1793 1801
1794 OwnPrimarySelection(UTF16ToUTF8(text)); 1802 OwnPrimarySelection(UTF16ToUTF8(text));
1795 } 1803 }
1796 1804
1797 bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) { 1805 bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) {
1798 if (model_->CanPasteAndGo(CollapseWhitespace(text, true))) { 1806 if (model_->CanPasteAndGo(StripJavascriptSchemas
1807 (CollapseWhitespace(text, true)))) {
1799 model_->PasteAndGo(); 1808 model_->PasteAndGo();
1800 return true; 1809 return true;
1801 } 1810 }
1802 1811
1803 return false; 1812 return false;
1804 } 1813 }
1805 1814
1806 gfx::Font OmniboxViewGtk::GetFont() { 1815 gfx::Font OmniboxViewGtk::GetFont() {
1807 #if defined(TOOLKIT_VIEWS) 1816 #if defined(TOOLKIT_VIEWS)
1808 bool use_gtk = false; 1817 bool use_gtk = false;
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 2403
2395 // Make all the children of the widget visible. NOTE: this won't display 2404 // Make all the children of the widget visible. NOTE: this won't display
2396 // anything, it just toggles the visible flag. 2405 // anything, it just toggles the visible flag.
2397 gtk_widget_show_all(omnibox_view->GetNativeView()); 2406 gtk_widget_show_all(omnibox_view->GetNativeView());
2398 // Hide the widget. NativeViewHostGtk will make it visible again as necessary. 2407 // Hide the widget. NativeViewHostGtk will make it visible again as necessary.
2399 gtk_widget_hide(omnibox_view->GetNativeView()); 2408 gtk_widget_hide(omnibox_view->GetNativeView());
2400 2409
2401 return omnibox_view; 2410 return omnibox_view;
2402 } 2411 }
2403 #endif 2412 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698