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

Side by Side Diff: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.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/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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 650
651 void OmniboxViewGtk::OnRevertTemporaryText() { 651 void OmniboxViewGtk::OnRevertTemporaryText() {
652 StartUpdatingHighlightedText(); 652 StartUpdatingHighlightedText();
653 SetSelectedRange(saved_temporary_selection_); 653 SetSelectedRange(saved_temporary_selection_);
654 FinishUpdatingHighlightedText(); 654 FinishUpdatingHighlightedText();
655 TextChanged(); 655 TextChanged();
656 } 656 }
657 657
658 void OmniboxViewGtk::OnBeforePossibleChange() { 658 void OmniboxViewGtk::OnBeforePossibleChange() {
659 // Record this paste, so we can do different behavior. 659 // Record this paste, so we can do different behavior.
660 if (paste_clipboard_requested_) { 660 if (paste_clipboard_requested_)
661 paste_clipboard_requested_ = false;
662 model_->on_paste(); 661 model_->on_paste();
663 }
664 662
665 // This method will be called in HandleKeyPress() method just before 663 // This method will be called in HandleKeyPress() method just before
666 // handling a key press event. So we should prevent it from being called 664 // handling a key press event. So we should prevent it from being called
667 // when handling the key press event. 665 // when handling the key press event.
668 if (handling_key_press_) 666 if (handling_key_press_)
669 return; 667 return;
670 668
671 // Record our state. 669 // Record our state.
672 text_before_change_ = GetText(); 670 text_before_change_ = GetText();
673 sel_before_change_ = GetSelection(); 671 sel_before_change_ = GetSelection();
674 #if GTK_CHECK_VERSION(2, 20, 0) 672 #if GTK_CHECK_VERSION(2, 20, 0)
675 pre_edit_size_before_change_ = pre_edit_.size(); 673 pre_edit_size_before_change_ = pre_edit_.size();
676 #endif 674 #endif
677 } 675 }
678 676
679 // TODO(deanm): This is mostly stolen from Windows, and will need some work. 677 // TODO(deanm): This is mostly stolen from Windows, and will need some work.
680 bool OmniboxViewGtk::OnAfterPossibleChange() { 678 bool OmniboxViewGtk::OnAfterPossibleChange() {
681 // This method will be called in HandleKeyPress() method just after 679 // This method will be called in HandleKeyPress() method just after
682 // handling a key press event. So we should prevent it from being called 680 // handling a key press event. So we should prevent it from being called
683 // when handling the key press event. 681 // when handling the key press event.
684 if (handling_key_press_) { 682 if (handling_key_press_) {
685 content_maybe_changed_by_key_press_ = true; 683 content_maybe_changed_by_key_press_ = true;
686 return false; 684 return false;
687 } 685 }
688 686
687 if (paste_clipboard_requested_) {
Peter Kasting 2011/05/10 23:27:42 I don't think this is the right place for this. W
Cris Neckar 2011/05/11 21:42:36 The problem is that this is handled within the gtk
688 paste_clipboard_requested_ = false;
689 string16 text(GetText());
690 if (StripJavascriptSchema(text, &text))
691 SetUserText(text);
692 }
693
689 // If the change is caused by an Enter key press event, and the event was not 694 // If the change is caused by an Enter key press event, and the event was not
690 // handled by IME, then it's an unexpected change and shall be reverted here. 695 // handled by IME, then it's an unexpected change and shall be reverted here.
691 // {Start|Finish}UpdatingHighlightedText() are called here to prevent the 696 // {Start|Finish}UpdatingHighlightedText() are called here to prevent the
692 // PRIMARY selection from being changed. 697 // PRIMARY selection from being changed.
693 if (enter_was_pressed_ && enter_was_inserted_) { 698 if (enter_was_pressed_ && enter_was_inserted_) {
694 StartUpdatingHighlightedText(); 699 StartUpdatingHighlightedText();
695 SetTextAndSelectedRange(text_before_change_, sel_before_change_); 700 SetTextAndSelectedRange(text_before_change_, sel_before_change_);
696 FinishUpdatingHighlightedText(); 701 FinishUpdatingHighlightedText();
697 return false; 702 return false;
698 } 703 }
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 // allow default behavior for such drags. 1576 // allow default behavior for such drags.
1572 if (context->source_window == text_view_->window) 1577 if (context->source_window == text_view_->window)
1573 return; 1578 return;
1574 1579
1575 guchar* text = gtk_selection_data_get_text(selection_data); 1580 guchar* text = gtk_selection_data_get_text(selection_data);
1576 if (!text) 1581 if (!text)
1577 return; 1582 return;
1578 1583
1579 string16 possible_url = UTF8ToUTF16(reinterpret_cast<char*>(text)); 1584 string16 possible_url = UTF8ToUTF16(reinterpret_cast<char*>(text));
1580 g_free(text); 1585 g_free(text);
1581 if (OnPerformDropImpl(possible_url)) { 1586
1587 string16 stripped_url(possible_url);
1588 bool stripped = StripJavascriptSchema(stripped_url, &stripped_url);
1589 if (OnPerformDropImpl(possible_url) || stripped) {
1582 gtk_drag_finish(context, TRUE, TRUE, time); 1590 gtk_drag_finish(context, TRUE, TRUE, time);
1583
1584 static guint signal_id = 1591 static guint signal_id =
1585 g_signal_lookup("drag-data-received", GTK_TYPE_WIDGET); 1592 g_signal_lookup("drag-data-received", GTK_TYPE_WIDGET);
1586 g_signal_stop_emission(text_view_, signal_id, 0); 1593 g_signal_stop_emission(text_view_, signal_id, 0);
1594 if (stripped)
1595 SetUserText(stripped_url);
Peter Kasting 2011/05/10 23:27:42 Does GTK navigate on drop? If so, where does that
Cris Neckar 2011/05/11 21:42:36 If the dragged text is a url it occurs in OnPerfor
1587 } 1596 }
1588 } 1597 }
1589 1598
1590 void OmniboxViewGtk::HandleDragDataGet(GtkWidget* widget, 1599 void OmniboxViewGtk::HandleDragDataGet(GtkWidget* widget,
1591 GdkDragContext* context, 1600 GdkDragContext* context,
1592 GtkSelectionData* selection_data, 1601 GtkSelectionData* selection_data,
1593 guint target_type, 1602 guint target_type,
1594 guint time) { 1603 guint time) {
1595 DCHECK(text_view_); 1604 DCHECK(text_view_);
1596 // If GTK put the normal textual version of the selection in our drag data, 1605 // If GTK put the normal textual version of the selection in our drag data,
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 // baseline, so we need to move the |instant_view_| down to make sure it 2341 // baseline, so we need to move the |instant_view_| down to make sure it
2333 // has the same baseline as the |text_view_|. 2342 // has the same baseline as the |text_view_|.
2334 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2343 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2335 int height; 2344 int height;
2336 pango_layout_get_size(layout, NULL, &height); 2345 pango_layout_get_size(layout, NULL, &height);
2337 PangoLayoutIter* iter = pango_layout_get_iter(layout); 2346 PangoLayoutIter* iter = pango_layout_get_iter(layout);
2338 int baseline = pango_layout_iter_get_baseline(iter); 2347 int baseline = pango_layout_iter_get_baseline(iter);
2339 pango_layout_iter_free(iter); 2348 pango_layout_iter_free(iter);
2340 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2349 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2341 } 2350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698