summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/gtk_util.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-16 20:25:58 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-16 20:25:58 +0000
commit126f5006bc8aa83e8e83f4917f33333f10633f21 (patch)
treeebd4984af98c3ed198866c443f315fc461d0b741 /chrome/browser/gtk/gtk_util.cc
parentfff4f6fffb6eb1cf1993beade81577d04198fe75 (diff)
downloadchromium_src-126f5006bc8aa83e8e83f4917f33333f10633f21.zip
chromium_src-126f5006bc8aa83e8e83f4917f33333f10633f21.tar.gz
chromium_src-126f5006bc8aa83e8e83f4917f33333f10633f21.tar.bz2
GTK: navigate to URL on PRIMARY when middle-clicking the location icon.
BUG=40610 TEST=manual Review URL: http://codereview.chromium.org/1549043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44814 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/gtk_util.cc')
-rw-r--r--chrome/browser/gtk/gtk_util.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc
index 15941cc..0f8b629 100644
--- a/chrome/browser/gtk/gtk_util.cc
+++ b/chrome/browser/gtk/gtk_util.cc
@@ -17,11 +17,13 @@
#include "base/i18n/rtl.h"
#include "base/linux_util.h"
#include "base/logging.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/common/renderer_preferences.h"
+#include "googleurl/src/gurl.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -859,4 +861,32 @@ gfx::Rect WidgetBounds(GtkWidget* widget) {
return gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height);
}
+bool URLFromPrimarySelection(Profile* profile, GURL* url) {
+ GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+ DCHECK(clipboard);
+ gchar* selection_text = gtk_clipboard_wait_for_text(clipboard);
+ if (!selection_text)
+ return false;
+
+ // Use autocomplete to clean up the text, going so far as to turn it into
+ // a search query if necessary.
+ AutocompleteController controller(profile);
+ controller.Start(UTF8ToWide(selection_text),
+ std::wstring(), // desired_tld
+ true, // prevent_inline_autocomplete
+ false, // prefer_keyword
+ true); // synchronous_only
+ g_free(selection_text);
+ const AutocompleteResult& result = controller.result();
+ AutocompleteResult::const_iterator it = result.default_match();
+ if (it == result.end())
+ return false;
+
+ if (!it->destination_url.is_valid())
+ return false;
+
+ *url = it->destination_url;
+ return true;
+}
+
} // namespace gtk_util