blob: 43f1e5b0b0c53a1cd514cdb3019d1ceb47263b04 [file] [log] [blame]
[email protected]707d6be62012-01-12 03:56:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]4acc19a62009-04-03 03:05:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5835871a2012-04-25 21:56:555#ifndef CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_UI_H_
6#define CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_UI_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]4acc19a62009-04-03 03:05:118
[email protected]038d52e12009-10-14 16:53:419#include <string>
[email protected]2bc2de62009-06-29 23:37:4210#include <vector>
11
[email protected]c63cedf22012-01-17 18:42:2212#include "base/compiler_specific.h"
[email protected]bdae5c12011-08-05 21:49:0613#include "base/string16.h"
[email protected]6936ace2012-01-31 02:48:1214#include "content/public/browser/web_contents_delegate.h"
[email protected]e14c959122012-01-13 16:58:2515#include "content/public/browser/web_ui_controller.h"
[email protected]4acc19a62009-04-03 03:05:1116#include "googleurl/src/gurl.h"
[email protected]707d6be62012-01-12 03:56:1517#include "ui/base/ui_base_types.h"
[email protected]4acc19a62009-04-03 03:05:1118
[email protected]9a80e222010-11-22 11:27:2619
[email protected]f3a1c642011-07-12 19:15:0320namespace base {
21class ListValue;
[email protected]45644f62011-11-23 00:58:2322template<class T> class PropertyAccessor;
23}
24
[email protected]a81343d232011-12-27 07:39:2025namespace content {
26class WebContents;
[email protected]c63cedf22012-01-17 18:42:2227class WebUIMessageHandler;
[email protected]35be7ec2012-02-12 20:42:5128struct ContextMenuParams;
[email protected]a81343d232011-12-27 07:39:2029}
30
[email protected]45644f62011-11-23 00:58:2331namespace gfx {
32class Size;
[email protected]f3a1c642011-07-12 19:15:0333}
34
[email protected]4acc19a62009-04-03 03:05:1135// Implement this class to receive notifications.
[email protected]5835871a2012-04-25 21:56:5536class WebDialogDelegate {
[email protected]4acc19a62009-04-03 03:05:1137 public:
[email protected]038d52e12009-10-14 16:53:4138 // Returns true if the contents needs to be run in a modal dialog.
[email protected]707d6be62012-01-12 03:56:1539 virtual ui::ModalType GetDialogModalType() const = 0;
[email protected]4acc19a62009-04-03 03:05:1140
[email protected]038d52e12009-10-14 16:53:4141 // Returns the title of the dialog.
[email protected]bdae5c12011-08-05 21:49:0642 virtual string16 GetDialogTitle() const = 0;
[email protected]4acc19a62009-04-03 03:05:1143
[email protected]875c47f2012-03-23 01:27:4944 // Returns the dialog's name identifier. Used to identify this dialog for
45 // state restoration.
46 virtual std::string GetDialogName() const;
47
[email protected]038d52e12009-10-14 16:53:4148 // Get the HTML file path for the content to load in the dialog.
49 virtual GURL GetDialogContentURL() const = 0;
[email protected]4acc19a62009-04-03 03:05:1150
[email protected]36e12172011-02-08 23:46:0251 // Get WebUIMessageHandler objects to handle messages from the HTML/JS page.
[email protected]038d52e12009-10-14 16:53:4152 // The handlers are used to send and receive messages from the page while it
[email protected]d21cdb12011-02-10 01:22:3253 // is still open. Ownership of each handler is taken over by the WebUI
[email protected]038d52e12009-10-14 16:53:4154 // hosting the page.
[email protected]36e12172011-02-08 23:46:0255 virtual void GetWebUIMessageHandlers(
[email protected]26e2632a2011-12-31 04:02:5556 std::vector<content::WebUIMessageHandler*>* handlers) const = 0;
[email protected]2bc2de62009-06-29 23:37:4257
[email protected]038d52e12009-10-14 16:53:4158 // Get the size of the dialog.
59 virtual void GetDialogSize(gfx::Size* size) const = 0;
[email protected]4acc19a62009-04-03 03:05:1160
[email protected]875c47f2012-03-23 01:27:4961 // Get the size of the dialog.
62 virtual void GetMinimumDialogSize(gfx::Size* size) const;
63
[email protected]038d52e12009-10-14 16:53:4164 // Gets the JSON string input to use when showing the dialog.
65 virtual std::string GetDialogArgs() const = 0;
[email protected]4acc19a62009-04-03 03:05:1166
[email protected]82539272012-02-03 20:39:4567 // A callback to notify the delegate that |source|'s loading state has
68 // changed.
69 virtual void OnLoadingStateChanged(content::WebContents* source) {}
70
[email protected]038d52e12009-10-14 16:53:4171 // A callback to notify the delegate that the dialog closed.
[email protected]0a02984032011-09-02 20:35:4672 // IMPORTANT: Implementations should delete |this| here (unless they've
73 // arranged for the delegate to be deleted in some other way, e.g. by
74 // registering it as a message handler in the WebUI object).
[email protected]038d52e12009-10-14 16:53:4175 virtual void OnDialogClosed(const std::string& json_retval) = 0;
[email protected]4acc19a62009-04-03 03:05:1176
[email protected]73852b8f2010-05-14 00:38:1277 // A callback to notify the delegate that the contents have gone
78 // away. Only relevant if your dialog hosts code that calls
79 // windows.close() and you've allowed that. If the output parameter
80 // is set to true, then the dialog is closed. The default is false.
[email protected]a81343d232011-12-27 07:39:2081 virtual void OnCloseContents(content::WebContents* source,
82 bool* out_close_dialog) = 0;
[email protected]73852b8f2010-05-14 00:38:1283
[email protected]ea161da2010-11-02 21:57:3584 // A callback to allow the delegate to dictate that the window should not
85 // have a title bar. This is useful when presenting branded interfaces.
86 virtual bool ShouldShowDialogTitle() const = 0;
87
[email protected]9a80e222010-11-22 11:27:2688 // A callback to allow the delegate to inhibit context menu or show
89 // customized menu.
[email protected]eb929d62011-12-23 21:58:2690 // Returns true iff you do NOT want the standard context menu to be
91 // shown (because you want to handle it yourself).
[email protected]35be7ec2012-02-12 20:42:5192 virtual bool HandleContextMenu(const content::ContextMenuParams& params);
[email protected]9a80e222010-11-22 11:27:2693
[email protected]6936ace2012-01-31 02:48:1294 // A callback to allow the delegate to open a new URL inside |source|.
95 // On return |out_new_contents| should contain the WebContents the URL
96 // is opened in. Return false to use the default handler.
97 virtual bool HandleOpenURLFromTab(content::WebContents* source,
98 const content::OpenURLParams& params,
99 content::WebContents** out_new_contents);
100
101 // A callback to create a new tab with |new_contents|. |source| is the
102 // WebContent where the operation originated. |disposition| controls how the
103 // new tab should be opened. |initial_pos| is the position of the window if a
104 // new window is created. |user_gesture| is true if the operation was started
105 // by a user gesture. Return false to use the default handler.
106 virtual bool HandleAddNewContents(content::WebContents* source,
107 content::WebContents* new_contents,
108 WindowOpenDisposition disposition,
109 const gfx::Rect& initial_pos,
110 bool user_gesture);
111
[email protected]ef1c7df2011-12-06 13:49:49112 // Stores the dialog bounds.
[email protected]1cd78a072012-01-27 08:59:13113 virtual void StoreDialogSize(const gfx::Size& dialog_size) {}
[email protected]ef1c7df2011-12-06 13:49:49114
[email protected]038d52e12009-10-14 16:53:41115 protected:
[email protected]5835871a2012-04-25 21:56:55116 virtual ~WebDialogDelegate() {}
[email protected]4acc19a62009-04-03 03:05:11117};
118
[email protected]5835871a2012-04-25 21:56:55119// Displays file URL contents inside a modal web dialog.
[email protected]4acc19a62009-04-03 03:05:11120//
[email protected]0ec4898e2011-12-30 21:09:24121// This application really should not use WebContents + WebUI. It should instead
[email protected]4acc19a62009-04-03 03:05:11122// just embed a RenderView in a dialog and be done with it.
123//
[email protected]d21cdb12011-02-10 01:22:32124// Before loading a URL corresponding to this WebUI, the caller should set its
[email protected]0ec4898e2011-12-30 21:09:24125// delegate as a property on the WebContents. This WebUI will pick it up from
[email protected]4acc19a62009-04-03 03:05:11126// there and call it back. This is a bit of a hack to allow the dialog to pass
[email protected]0ec4898e2011-12-30 21:09:24127// its delegate to the Web UI without having nasty accessors on the WebContents.
[email protected]4acc19a62009-04-03 03:05:11128// The correct design using RVH directly would avoid all of this.
[email protected]5835871a2012-04-25 21:56:55129class WebDialogUI : public content::WebUIController {
[email protected]4acc19a62009-04-03 03:05:11130 public:
[email protected]5835871a2012-04-25 21:56:55131 struct WebDialogParams {
[email protected]4acc19a62009-04-03 03:05:11132 // The URL for the content that will be loaded in the dialog.
133 GURL url;
134 // Width of the dialog.
135 int width;
136 // Height of the dialog.
137 int height;
138 // The JSON input to pass to the dialog when showing it.
139 std::string json_input;
140 };
141
[email protected]0ec4898e2011-12-30 21:09:24142 // When created, the property should already be set on the WebContents.
[email protected]5835871a2012-04-25 21:56:55143 explicit WebDialogUI(content::WebUI* web_ui);
144 virtual ~WebDialogUI();
[email protected]4acc19a62009-04-03 03:05:11145
[email protected]8befa1a2011-09-21 02:03:38146 // Close the dialog, passing the specified arguments to the close handler.
147 void CloseDialog(const base::ListValue* args);
148
[email protected]4acc19a62009-04-03 03:05:11149 // Returns the PropertyBag accessor object used to write the delegate pointer
[email protected]0ec4898e2011-12-30 21:09:24150 // into the WebContents (see class-level comment above).
[email protected]5835871a2012-04-25 21:56:55151 static base::PropertyAccessor<WebDialogDelegate*>& GetPropertyAccessor();
[email protected]4acc19a62009-04-03 03:05:11152
153 private:
[email protected]e14c959122012-01-13 16:58:25154 // WebUIController
[email protected]eaabba22012-03-07 15:02:11155 virtual void RenderViewCreated(
156 content::RenderViewHost* render_view_host) OVERRIDE;
[email protected]4acc19a62009-04-03 03:05:11157
158 // JS message handler.
[email protected]f3a1c642011-07-12 19:15:03159 void OnDialogClosed(const base::ListValue* args);
[email protected]4acc19a62009-04-03 03:05:11160
[email protected]5835871a2012-04-25 21:56:55161 DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
[email protected]4acc19a62009-04-03 03:05:11162};
163
[email protected]5835871a2012-04-25 21:56:55164// Displays external URL contents inside a modal web dialog.
[email protected]73852b8f2010-05-14 00:38:12165//
166// Intended to be the place to collect the settings and lockdowns
[email protected]78637b22011-12-02 20:51:52167// necessary for running external UI components securely (e.g., the
[email protected]73852b8f2010-05-14 00:38:12168// cloud print dialog).
[email protected]5835871a2012-04-25 21:56:55169class ExternalWebDialogUI : public WebDialogUI {
[email protected]73852b8f2010-05-14 00:38:12170 public:
[email protected]5835871a2012-04-25 21:56:55171 explicit ExternalWebDialogUI(content::WebUI* web_ui);
172 virtual ~ExternalWebDialogUI();
[email protected]73852b8f2010-05-14 00:38:12173};
174
[email protected]5835871a2012-04-25 21:56:55175#endif // CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_UI_H_