diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 21:17:44 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 21:17:44 +0000 |
commit | 9bad8b71cdba78c88b2ad33fc5f601c21d8818a5 (patch) | |
tree | 457bc082ae2b626aca9ad3e985d5f24d6d873872 /chrome | |
parent | 7f3d178dfdfc2a7f281b64471d13244e2e3c11fd (diff) | |
download | chromium_src-9bad8b71cdba78c88b2ad33fc5f601c21d8818a5.zip chromium_src-9bad8b71cdba78c88b2ad33fc5f601c21d8818a5.tar.gz chromium_src-9bad8b71cdba78c88b2ad33fc5f601c21d8818a5.tar.bz2 |
Move GenericHandler back to Chrome since it was really Chrome specific (i.e. chrome's mapping of click to disposition).
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9481008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/disposition_utils.cc | 30 | ||||
-rw-r--r-- | chrome/browser/disposition_utils.h | 24 | ||||
-rw-r--r-- | chrome/browser/event_disposition.cc | 3 | ||||
-rw-r--r-- | chrome/browser/memory_details_mac.cc | 1 | ||||
-rw-r--r-- | chrome/browser/memory_details_win.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/event_utils.mm | 1 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/gtk_util.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/event_utils.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/webui/generic_handler.cc | 59 | ||||
-rw-r--r-- | chrome/browser/ui/webui/generic_handler.h | 31 | ||||
-rw-r--r-- | chrome/browser/ui/webui/web_ui_util.cc | 3 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
14 files changed, 158 insertions, 11 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index cf7c068..6b70821 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -34,7 +34,6 @@ include_rules = [ "+content/browser/accessibility/browser_accessibility_manager.h", "+content/browser/browser_url_handler.h", "+content/browser/cert_store.h", - "+content/browser/disposition_utils.h", "+content/browser/download/download_buffer.h", "+content/browser/download/download_create_info.h", "+content/browser/download/download_file_manager.h", diff --git a/chrome/browser/disposition_utils.cc b/chrome/browser/disposition_utils.cc new file mode 100644 index 0000000..326a323 --- /dev/null +++ b/chrome/browser/disposition_utils.cc @@ -0,0 +1,30 @@ +// 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 "chrome/browser/disposition_utils.h" + +#include "build/build_config.h" + +namespace disposition_utils { + +WindowOpenDisposition DispositionFromClick(bool middle_button, + bool alt_key, + bool ctrl_key, + bool meta_key, + bool shift_key) { + // MacOS uses meta key (Command key) to spawn new tabs. +#if defined(OS_MACOSX) + if (middle_button || meta_key) +#else + if (middle_button || ctrl_key) +#endif + return shift_key ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; + if (shift_key) + return NEW_WINDOW; + if (alt_key) + return SAVE_TO_DISK; + return CURRENT_TAB; +} + +} diff --git a/chrome/browser/disposition_utils.h b/chrome/browser/disposition_utils.h new file mode 100644 index 0000000..eb847f9 --- /dev/null +++ b/chrome/browser/disposition_utils.h @@ -0,0 +1,24 @@ +// 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 CHROME_BROWSER_DISPOSITION_UTILS_H_ +#define CHROME_BROWSER_DISPOSITION_UTILS_H_ +#pragma once + +#include "webkit/glue/window_open_disposition.h" + +namespace disposition_utils { + +// Translates event flags from a click on a link into the user's desired +// window disposition. For example, a middle click would mean to open +// a background tab. +WindowOpenDisposition DispositionFromClick(bool middle_button, + bool alt_key, + bool ctrl_key, + bool meta_key, + bool shift_key); + +} + +#endif // CHROME_BROWSER_DISPOSITION_UTILS_H_ diff --git a/chrome/browser/event_disposition.cc b/chrome/browser/event_disposition.cc index c45841a..82aa965 100644 --- a/chrome/browser/event_disposition.cc +++ b/chrome/browser/event_disposition.cc @@ -3,7 +3,8 @@ // found in the LICENSE file. #include "chrome/browser/event_disposition.h" -#include "content/browser/disposition_utils.h" + +#include "chrome/browser/disposition_utils.h" #include "ui/base/events.h" namespace browser { diff --git a/chrome/browser/memory_details_mac.cc b/chrome/browser/memory_details_mac.cc index d005150..36f29f2 100644 --- a/chrome/browser/memory_details_mac.cc +++ b/chrome/browser/memory_details_mac.cc @@ -20,7 +20,6 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" -#include "content/browser/renderer_host/backing_store_manager.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/process_type.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/memory_details_win.cc b/chrome/browser/memory_details_win.cc index 0e1da5e4..92355c9 100644 --- a/chrome/browser/memory_details_win.cc +++ b/chrome/browser/memory_details_win.cc @@ -15,7 +15,6 @@ #include "base/win/windows_version.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" -#include "content/browser/renderer_host/backing_store_manager.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/process_type.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/ui/cocoa/event_utils.mm b/chrome/browser/ui/cocoa/event_utils.mm index e488d2d..2952cad 100644 --- a/chrome/browser/ui/cocoa/event_utils.mm +++ b/chrome/browser/ui/cocoa/event_utils.mm @@ -5,7 +5,6 @@ #import "chrome/browser/ui/cocoa/event_utils.h" #include "chrome/browser/event_disposition.h" -#include "content/browser/disposition_utils.h" #include "ui/base/events.h" namespace { diff --git a/chrome/browser/ui/gtk/gtk_util.cc b/chrome/browser/ui/gtk/gtk_util.cc index a24743a..5614e1f 100644 --- a/chrome/browser/ui/gtk/gtk_util.cc +++ b/chrome/browser/ui/gtk/gtk_util.cc @@ -27,7 +27,6 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/gtk/theme_service_gtk.h" -#include "content/browser/disposition_utils.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/common/renderer_preferences.h" diff --git a/chrome/browser/ui/views/event_utils.cc b/chrome/browser/ui/views/event_utils.cc index 19a35af..3a1078e 100644 --- a/chrome/browser/ui/views/event_utils.cc +++ b/chrome/browser/ui/views/event_utils.cc @@ -4,7 +4,6 @@ #include "chrome/browser/event_disposition.h" #include "chrome/browser/ui/views/event_utils.h" -#include "content/browser/disposition_utils.h" #include "ui/views/events/event.h" using views::Event; diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index 58735f2..209a6bb 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -26,6 +26,7 @@ #include "chrome/browser/ui/webui/task_manager_ui.h" #include "chrome/browser/ui/webui/flags_ui.h" #include "chrome/browser/ui/webui/flash_ui.h" +#include "chrome/browser/ui/webui/generic_handler.h" #include "chrome/browser/ui/webui/gpu_internals_ui.h" #include "chrome/browser/ui/webui/history_ui.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" @@ -404,12 +405,14 @@ WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( content::WebUI* web_ui, const GURL& url) const { Profile* profile = Profile::FromWebUI(web_ui); - WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, - profile, url); + WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); if (!function) return NULL; - return (*function)(web_ui, url); + WebUIController* controller = (*function)(web_ui, url); + if (controller) + web_ui->AddMessageHandler(new GenericHandler()); + return controller; } void ChromeWebUIControllerFactory::GetFaviconForURL( diff --git a/chrome/browser/ui/webui/generic_handler.cc b/chrome/browser/ui/webui/generic_handler.cc new file mode 100644 index 0000000..dabeeb2 --- /dev/null +++ b/chrome/browser/ui/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 "chrome/browser/ui/webui/generic_handler.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/logging.h" +#include "base/values.h" +#include "chrome/browser/disposition_utils.h" +#include "content/public/browser//web_ui.h" +#include "content/public/browser/web_contents.h" + +using content::OpenURLParams; + +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 = + disposition_utils::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), content::Referrer(), disposition, + content::PAGE_TRANSITION_LINK, false)); + + // This may delete us! +} diff --git a/chrome/browser/ui/webui/generic_handler.h b/chrome/browser/ui/webui/generic_handler.h new file mode 100644 index 0000000..d800602 --- /dev/null +++ b/chrome/browser/ui/webui/generic_handler.h @@ -0,0 +1,31 @@ +// 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_UI_WEBUI_GENERIC_HANDLER_H_ +#define CONTENT_BROWSER_UI_WEBUI_GENERIC_HANDLER_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "content/public/browser/web_ui_message_handler.h" + +namespace base { +class ListValue; +} + +// A place to add handlers for messages shared across all WebUI pages. +class GenericHandler : public content::WebUIMessageHandler { + public: + GenericHandler(); + virtual ~GenericHandler(); + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + private: + void HandleNavigateToUrl(const base::ListValue* args); + + DISALLOW_COPY_AND_ASSIGN(GenericHandler); +}; + +#endif // CONTENT_BROWSER_UI_WEBUI_GENERIC_HANDLER_H_ diff --git a/chrome/browser/ui/webui/web_ui_util.cc b/chrome/browser/ui/webui/web_ui_util.cc index 4914de6..e9b96fb 100644 --- a/chrome/browser/ui/webui/web_ui_util.cc +++ b/chrome/browser/ui/webui/web_ui_util.cc @@ -7,8 +7,9 @@ #include <vector> #include "base/base64.h" +#include "base/logging.h" #include "base/values.h" -#include "content/browser/disposition_utils.h" +#include "chrome/browser/disposition_utils.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/codec/png_codec.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5f48d90..5d7ed5f 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -942,6 +942,8 @@ 'browser/diagnostics/recon_diagnostics.h', 'browser/diagnostics/sqlite_diagnostics.cc', 'browser/diagnostics/sqlite_diagnostics.h', + 'browser/disposition_utils.cc', + 'browser/disposition_utils.h', 'browser/download/chrome_download_manager_delegate.cc', 'browser/download/chrome_download_manager_delegate.h', 'browser/download/download_crx_util.cc', @@ -3956,6 +3958,8 @@ 'browser/ui/webui/flags_ui.h', 'browser/ui/webui/flash_ui.cc', 'browser/ui/webui/flash_ui.h', + 'browser/ui/webui/generic_handler.cc', + 'browser/ui/webui/generic_handler.h', 'browser/ui/webui/gpu_internals_ui.cc', 'browser/ui/webui/gpu_internals_ui.h', 'browser/ui/webui/help/help_handler.cc', |