summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 04:27:58 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 04:27:58 +0000
commiteb2ef21c332ae0de01e236699e1a46003941897c (patch)
tree23e27458fb0f7f34e20f368a4c073d1ca489eac7 /content
parentba23e67a80f782d126f59f1a33555c16f7843605 (diff)
downloadchromium_src-eb2ef21c332ae0de01e236699e1a46003941897c.zip
chromium_src-eb2ef21c332ae0de01e236699e1a46003941897c.tar.gz
chromium_src-eb2ef21c332ae0de01e236699e1a46003941897c.tar.bz2
Move generic_handler.* to content\browser\webui since it's needed by all webui pages.
BUG=169170 Review URL: https://codereview.chromium.org/12087040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/web_contents/web_contents_impl.cc2
-rw-r--r--content/browser/webui/generic_handler.cc59
-rw-r--r--content/browser/webui/generic_handler.h34
-rw-r--r--content/content_browser.gypi2
4 files changed, 97 insertions, 0 deletions
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index bb1238f..8b1f8e9 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -37,6 +37,7 @@
#include "content/browser/web_contents/interstitial_page_impl.h"
#include "content/browser/web_contents/navigation_entry_impl.h"
#include "content/browser/web_contents/web_contents_view_guest.h"
+#include "content/browser/webui/generic_handler.h"
#include "content/browser/webui/web_ui_controller_factory_registry.h"
#include "content/browser/webui/web_ui_impl.h"
#include "content/common/browser_plugin_messages.h"
@@ -860,6 +861,7 @@ WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
CreateWebUIControllerForURL(web_ui, url);
if (controller) {
+ web_ui->AddMessageHandler(new GenericHandler());
web_ui->SetController(controller);
return web_ui;
}
diff --git a/content/browser/webui/generic_handler.cc b/content/browser/webui/generic_handler.cc
new file mode 100644
index 0000000..56b9e07
--- /dev/null
+++ b/content/browser/webui/generic_handler.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/webui/generic_handler.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/values.h"
+#include "content/public/browser/web_ui.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/base/window_open_disposition.h"
+
+namespace content {
+
+GenericHandler::GenericHandler() {
+}
+
+GenericHandler::~GenericHandler() {
+}
+
+void GenericHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("navigateToUrl",
+ base::Bind(&GenericHandler::HandleNavigateToUrl, base::Unretained(this)));
+}
+
+void GenericHandler::HandleNavigateToUrl(const ListValue* args) {
+ std::string url_string;
+ std::string target_string;
+ double button;
+ bool alt_key;
+ bool ctrl_key;
+ bool meta_key;
+ bool shift_key;
+
+ CHECK(args->GetString(0, &url_string));
+ CHECK(args->GetString(1, &target_string));
+ CHECK(args->GetDouble(2, &button));
+ CHECK(args->GetBoolean(3, &alt_key));
+ CHECK(args->GetBoolean(4, &ctrl_key));
+ CHECK(args->GetBoolean(5, &meta_key));
+ CHECK(args->GetBoolean(6, &shift_key));
+
+ CHECK(button == 0.0 || button == 1.0);
+ bool middle_button = (button == 1.0);
+
+ WindowOpenDisposition disposition = ui::DispositionFromClick(
+ middle_button, alt_key, ctrl_key, meta_key, shift_key);
+ if (disposition == CURRENT_TAB && target_string == "_blank")
+ disposition = NEW_FOREGROUND_TAB;
+
+ web_ui()->GetWebContents()->OpenURL(OpenURLParams(
+ GURL(url_string), Referrer(), disposition, PAGE_TRANSITION_LINK, false));
+
+ // This may delete us!
+}
+
+} // namespace content
diff --git a/content/browser/webui/generic_handler.h b/content/browser/webui/generic_handler.h
new file mode 100644
index 0000000..431373d
--- /dev/null
+++ b/content/browser/webui/generic_handler.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_WEBUI_GENERIC_HANDLER_H_
+#define CONTENT_BROWSER_WEBUI_GENERIC_HANDLER_H_
+
+#include "base/compiler_specific.h"
+#include "content/public/browser/web_ui_message_handler.h"
+
+namespace base {
+class ListValue;
+}
+
+namespace content {
+
+// A place to add handlers for messages shared across all WebUI pages.
+class GenericHandler : public WebUIMessageHandler {
+ public:
+ GenericHandler();
+ virtual ~GenericHandler();
+
+ // WebUIMessageHandler implementation.
+ virtual void RegisterMessages() OVERRIDE;
+
+ private:
+ void HandleNavigateToUrl(const base::ListValue* args);
+
+ DISALLOW_COPY_AND_ASSIGN(GenericHandler);
+};
+
+} // namespace content
+
+#endif // namespace content
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 00bdf03..078238a 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -885,6 +885,8 @@
'browser/web_contents/web_drag_source_win.h',
'browser/web_contents/web_drag_utils_win.cc',
'browser/web_contents/web_drag_utils_win.h',
+ 'browser/webui/generic_handler.cc',
+ 'browser/webui/generic_handler.h',
'browser/webui/shared_resources_data_source.cc',
'browser/webui/shared_resources_data_source.h',
'browser/webui/url_data_manager.cc',