summaryrefslogtreecommitdiff
path: root/chromium/ui/web_dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/web_dialogs')
-rw-r--r--chromium/ui/web_dialogs/BUILD.gn3
-rw-r--r--chromium/ui/web_dialogs/DEPS3
-rw-r--r--chromium/ui/web_dialogs/web_dialog_ui.cc72
-rw-r--r--chromium/ui/web_dialogs/web_dialog_ui.h81
-rw-r--r--chromium/ui/web_dialogs/web_dialog_web_contents_delegate.cc2
5 files changed, 99 insertions, 62 deletions
diff --git a/chromium/ui/web_dialogs/BUILD.gn b/chromium/ui/web_dialogs/BUILD.gn
index 63923b1f1ed..54a3320caef 100644
--- a/chromium/ui/web_dialogs/BUILD.gn
+++ b/chromium/ui/web_dialogs/BUILD.gn
@@ -24,11 +24,12 @@ jumbo_component("web_dialogs") {
"//content/public/common",
"//skia",
"//ui/base",
+ "//ui/webui",
"//url",
]
if (!is_ios) {
- deps += [ "//third_party/WebKit/public:blink_headers" ]
+ deps += [ "//third_party/blink/public:blink_headers" ]
}
}
diff --git a/chromium/ui/web_dialogs/DEPS b/chromium/ui/web_dialogs/DEPS
index d988b2ff7e0..6bcf66b60ac 100644
--- a/chromium/ui/web_dialogs/DEPS
+++ b/chromium/ui/web_dialogs/DEPS
@@ -1,6 +1,7 @@
include_rules = [
"+content/public",
- "+third_party/WebKit/public/platform/WebGestureEvent.h",
+ "+third_party/blink/public/platform/web_gesture_event.h",
"+ui/base",
"+ui/gfx",
+ "+ui/webui",
]
diff --git a/chromium/ui/web_dialogs/web_dialog_ui.cc b/chromium/ui/web_dialogs/web_dialog_ui.cc
index 5b72e0c04f9..9b1d765ce2d 100644
--- a/chromium/ui/web_dialogs/web_dialog_ui.cc
+++ b/chromium/ui/web_dialogs/web_dialog_ui.cc
@@ -39,37 +39,31 @@ class WebDialogDelegateUserData : public base::SupportsUserData::Data {
} // namespace
-WebDialogUI::WebDialogUI(content::WebUI* web_ui)
- : WebUIController(web_ui) {
-}
-
-WebDialogUI::~WebDialogUI() {
- // Don't unregister our user data. During the teardown of the WebContents,
- // this will be deleted, but the WebContents will already be destroyed.
- //
- // This object is owned indirectly by the WebContents. WebUIs can change, so
- // it's scary if this WebUI is changed out and replaced with something else,
- // since the user data will still point to the old delegate. But the delegate
- // is itself the owner of the WebContents for a dialog so will be in scope,
- // and the HTML dialogs won't swap WebUIs anyway since they don't navigate.
-}
-
-void WebDialogUI::CloseDialog(const base::ListValue* args) {
- OnDialogClosed(args);
-}
-
// static
-void WebDialogUI::SetDelegate(content::WebContents* web_contents,
- WebDialogDelegate* delegate) {
+void WebDialogUIBase::SetDelegate(content::WebContents* web_contents,
+ WebDialogDelegate* delegate) {
web_contents->SetUserData(
&kWebDialogDelegateUserDataKey,
std::make_unique<WebDialogDelegateUserData>(delegate));
}
-////////////////////////////////////////////////////////////////////////////////
-// Private:
+WebDialogUIBase::WebDialogUIBase(content::WebUI* web_ui) : web_ui_(web_ui) {}
+
+// Don't unregister our user data. During the teardown of the WebContents, this
+// will be deleted, but the WebContents will already be destroyed.
+//
+// This object is owned indirectly by the WebContents. WebUIs can change, so
+// it's scary if this WebUI is changed out and replaced with something else,
+// since the user data will still point to the old delegate. But the delegate is
+// itself the owner of the WebContents for a dialog so will be in scope, and the
+// HTML dialogs won't swap WebUIs anyway since they don't navigate.
+WebDialogUIBase::~WebDialogUIBase() = default;
+
+void WebDialogUIBase::CloseDialog(const base::ListValue* args) {
+ OnDialogClosed(args);
+}
-WebDialogDelegate* WebDialogUI::GetDelegate(
+WebDialogDelegate* WebDialogUIBase::GetDelegate(
content::WebContents* web_contents) {
WebDialogDelegateUserData* user_data =
static_cast<WebDialogDelegateUserData*>(
@@ -78,17 +72,18 @@ WebDialogDelegate* WebDialogUI::GetDelegate(
return user_data ? user_data->delegate() : NULL;
}
-
-void WebDialogUI::RenderFrameCreated(RenderFrameHost* render_frame_host) {
+void WebDialogUIBase::HandleRenderFrameCreated(
+ RenderFrameHost* render_frame_host) {
// Hook up the javascript function calls, also known as chrome.send("foo")
// calls in the HTML, to the actual C++ functions.
- web_ui()->RegisterMessageCallback("dialogClose",
- base::Bind(&WebDialogUI::OnDialogClosed, base::Unretained(this)));
+ web_ui_->RegisterMessageCallback(
+ "dialogClose", base::BindRepeating(&WebDialogUIBase::OnDialogClosed,
+ base::Unretained(this)));
// Pass the arguments to the renderer supplied by the delegate.
std::string dialog_args;
std::vector<WebUIMessageHandler*> handlers;
- WebDialogDelegate* delegate = GetDelegate(web_ui()->GetWebContents());
+ WebDialogDelegate* delegate = GetDelegate(web_ui_->GetWebContents());
if (delegate) {
dialog_args = delegate->GetDialogArgs();
delegate->GetWebUIMessageHandlers(&handlers);
@@ -96,17 +91,17 @@ void WebDialogUI::RenderFrameCreated(RenderFrameHost* render_frame_host) {
content::RenderViewHost* render_view_host =
render_frame_host->GetRenderViewHost();
- if (0 != (web_ui()->GetBindings() & content::BINDINGS_POLICY_WEB_UI))
+ if (0 != (web_ui_->GetBindings() & content::BINDINGS_POLICY_WEB_UI))
render_view_host->SetWebUIProperty("dialogArguments", dialog_args);
for (WebUIMessageHandler* handler : handlers)
- web_ui()->AddMessageHandler(base::WrapUnique(handler));
+ web_ui_->AddMessageHandler(base::WrapUnique(handler));
if (delegate)
- delegate->OnDialogShown(web_ui(), render_view_host);
+ delegate->OnDialogShown(web_ui_, render_view_host);
}
-void WebDialogUI::OnDialogClosed(const base::ListValue* args) {
- WebDialogDelegate* delegate = GetDelegate(web_ui()->GetWebContents());
+void WebDialogUIBase::OnDialogClosed(const base::ListValue* args) {
+ WebDialogDelegate* delegate = GetDelegate(web_ui_->GetWebContents());
if (delegate) {
std::string json_retval;
if (args && !args->empty() && !args->GetString(0, &json_retval))
@@ -116,4 +111,13 @@ void WebDialogUI::OnDialogClosed(const base::ListValue* args) {
}
}
+WebDialogUI::WebDialogUI(content::WebUI* web_ui)
+ : WebDialogUIBase(web_ui), content::WebUIController(web_ui) {}
+
+WebDialogUI::~WebDialogUI() = default;
+
+void WebDialogUI::RenderFrameCreated(RenderFrameHost* render_frame_host) {
+ HandleRenderFrameCreated(render_frame_host);
+}
+
} // namespace ui
diff --git a/chromium/ui/web_dialogs/web_dialog_ui.h b/chromium/ui/web_dialogs/web_dialog_ui.h
index 001de1956e7..8c1c726a2be 100644
--- a/chromium/ui/web_dialogs/web_dialog_ui.h
+++ b/chromium/ui/web_dialogs/web_dialog_ui.h
@@ -15,6 +15,7 @@
#include "content/public/browser/web_ui_controller.h"
#include "ui/base/ui_base_types.h"
#include "ui/web_dialogs/web_dialogs_export.h"
+#include "ui/webui/mojo_web_ui_controller.h"
#include "url/gurl.h"
namespace content {
@@ -25,6 +26,35 @@ namespace ui {
class WebDialogDelegate;
+class WEB_DIALOGS_EXPORT WebDialogUIBase {
+ public:
+ // Sets the delegate on the WebContents.
+ static void SetDelegate(content::WebContents* web_contents,
+ WebDialogDelegate* delegate);
+
+ WebDialogUIBase(content::WebUI* web_ui);
+
+ // Close the dialog, passing the specified arguments to the close handler.
+ void CloseDialog(const base::ListValue* args);
+
+ protected:
+ virtual ~WebDialogUIBase();
+
+ // Prepares |render_frame_host| to host a dialog.
+ void HandleRenderFrameCreated(content::RenderFrameHost* render_frame_host);
+
+ private:
+ // Gets the delegate for the WebContent set with SetDelegate.
+ static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
+
+ // JS message handler.
+ void OnDialogClosed(const base::ListValue* args);
+
+ content::WebUI* web_ui_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebDialogUIBase);
+};
+
// Displays file URL contents inside a modal web dialog.
//
// This application really should not use WebContents + WebUI. It should instead
@@ -36,42 +66,43 @@ class WebDialogDelegate;
// the dialog to pass its delegate to the Web UI without having nasty accessors
// on the WebContents. The correct design using RVH directly would avoid all of
// this.
-class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController {
+class WEB_DIALOGS_EXPORT WebDialogUI : public WebDialogUIBase,
+ public content::WebUIController {
public:
- struct WebDialogParams {
- // The URL for the content that will be loaded in the dialog.
- GURL url;
- // Width of the dialog.
- int width;
- // Height of the dialog.
- int height;
- // The JSON input to pass to the dialog when showing it.
- std::string json_input;
- };
-
// When created, the delegate should already be set as user data on the
// WebContents.
explicit WebDialogUI(content::WebUI* web_ui);
~WebDialogUI() override;
- // Close the dialog, passing the specified arguments to the close handler.
- void CloseDialog(const base::ListValue* args);
-
- // Sets the delegate on the WebContents.
- static void SetDelegate(content::WebContents* web_contents,
- WebDialogDelegate* delegate);
-
private:
- // WebUIController
+ // content::WebUIController:
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
- // Gets the delegate for the WebContent set with SetDelegate.
- static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
+ DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
+};
- // JS message handler.
- void OnDialogClosed(const base::ListValue* args);
+// Displays file URL contents inside a modal web dialog while also enabling
+// Mojo calls to be made from within the dialog.
+template <typename Interface>
+class WEB_DIALOGS_EXPORT MojoWebDialogUI
+ : public WebDialogUIBase,
+ public MojoWebUIController<Interface> {
+ public:
+ // When created, the delegate should already be set as user data on the
+ // WebContents.
+ explicit MojoWebDialogUI(content::WebUI* web_ui)
+ : WebDialogUIBase(web_ui), MojoWebUIController<Interface>(web_ui) {}
+ ~MojoWebDialogUI() override {}
- DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
+ private:
+ // content::WebUIController:
+ void RenderFrameCreated(
+ content::RenderFrameHost* render_frame_host) override {
+ MojoWebUIControllerBase::RenderFrameCreated(render_frame_host);
+ HandleRenderFrameCreated(render_frame_host);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(MojoWebDialogUI);
};
} // namespace ui
diff --git a/chromium/ui/web_dialogs/web_dialog_web_contents_delegate.cc b/chromium/ui/web_dialogs/web_dialog_web_contents_delegate.cc
index 59f1658492f..758974b6279 100644
--- a/chromium/ui/web_dialogs/web_dialog_web_contents_delegate.cc
+++ b/chromium/ui/web_dialogs/web_dialog_web_contents_delegate.cc
@@ -6,7 +6,7 @@
#include "base/logging.h"
#include "content/public/browser/web_contents.h"
-#include "third_party/WebKit/public/platform/WebGestureEvent.h"
+#include "third_party/blink/public/platform/web_gesture_event.h"
using content::BrowserContext;
using content::OpenURLParams;