blob: 322242e89c9baff679bcc906b4a9e805dedf5551 [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]265a1492011-02-27 05:58:075#ifndef CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_
6#define CHROME_BROWSER_UI_WEBUI_HTML_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]bdae5c12011-08-05 21:49:0612#include "base/string16.h"
[email protected]21e6caf82012-01-06 23:44:2013#include "content/browser/webui/web_ui.h"
[email protected]e14c959122012-01-13 16:58:2514#include "content/public/browser/web_ui_controller.h"
[email protected]4acc19a62009-04-03 03:05:1115#include "googleurl/src/gurl.h"
[email protected]707d6be62012-01-12 03:56:1516#include "ui/base/ui_base_types.h"
[email protected]ef1c7df2011-12-06 13:49:4917#include "ui/gfx/rect.h"
[email protected]4acc19a62009-04-03 03:05:1118
[email protected]9a80e222010-11-22 11:27:2619struct ContextMenuParams;
20
[email protected]f3a1c642011-07-12 19:15:0321namespace base {
22class ListValue;
[email protected]45644f62011-11-23 00:58:2323template<class T> class PropertyAccessor;
24}
25
[email protected]a81343d232011-12-27 07:39:2026namespace content {
27class WebContents;
28}
29
[email protected]45644f62011-11-23 00:58:2330namespace gfx {
31class Size;
[email protected]f3a1c642011-07-12 19:15:0332}
33
[email protected]4acc19a62009-04-03 03:05:1134// Implement this class to receive notifications.
35class HtmlDialogUIDelegate {
36 public:
[email protected]038d52e12009-10-14 16:53:4137 // Returns true if the contents needs to be run in a modal dialog.
[email protected]707d6be62012-01-12 03:56:1538 virtual ui::ModalType GetDialogModalType() const = 0;
[email protected]4acc19a62009-04-03 03:05:1139
[email protected]038d52e12009-10-14 16:53:4140 // Returns the title of the dialog.
[email protected]bdae5c12011-08-05 21:49:0641 virtual string16 GetDialogTitle() const = 0;
[email protected]4acc19a62009-04-03 03:05:1142
[email protected]038d52e12009-10-14 16:53:4143 // Get the HTML file path for the content to load in the dialog.
44 virtual GURL GetDialogContentURL() const = 0;
[email protected]4acc19a62009-04-03 03:05:1145
[email protected]36e12172011-02-08 23:46:0246 // Get WebUIMessageHandler objects to handle messages from the HTML/JS page.
[email protected]038d52e12009-10-14 16:53:4147 // The handlers are used to send and receive messages from the page while it
[email protected]d21cdb12011-02-10 01:22:3248 // is still open. Ownership of each handler is taken over by the WebUI
[email protected]038d52e12009-10-14 16:53:4149 // hosting the page.
[email protected]36e12172011-02-08 23:46:0250 virtual void GetWebUIMessageHandlers(
[email protected]26e2632a2011-12-31 04:02:5551 std::vector<content::WebUIMessageHandler*>* handlers) const = 0;
[email protected]2bc2de62009-06-29 23:37:4252
[email protected]038d52e12009-10-14 16:53:4153 // Get the size of the dialog.
54 virtual void GetDialogSize(gfx::Size* size) const = 0;
[email protected]4acc19a62009-04-03 03:05:1155
[email protected]038d52e12009-10-14 16:53:4156 // Gets the JSON string input to use when showing the dialog.
57 virtual std::string GetDialogArgs() const = 0;
[email protected]4acc19a62009-04-03 03:05:1158
[email protected]038d52e12009-10-14 16:53:4159 // A callback to notify the delegate that the dialog closed.
[email protected]0a02984032011-09-02 20:35:4660 // IMPORTANT: Implementations should delete |this| here (unless they've
61 // arranged for the delegate to be deleted in some other way, e.g. by
62 // registering it as a message handler in the WebUI object).
[email protected]038d52e12009-10-14 16:53:4163 virtual void OnDialogClosed(const std::string& json_retval) = 0;
[email protected]4acc19a62009-04-03 03:05:1164
[email protected]73852b8f2010-05-14 00:38:1265 // A callback to notify the delegate that the contents have gone
66 // away. Only relevant if your dialog hosts code that calls
67 // windows.close() and you've allowed that. If the output parameter
68 // is set to true, then the dialog is closed. The default is false.
[email protected]a81343d232011-12-27 07:39:2069 virtual void OnCloseContents(content::WebContents* source,
70 bool* out_close_dialog) = 0;
[email protected]73852b8f2010-05-14 00:38:1271
[email protected]ea161da2010-11-02 21:57:3572 // A callback to allow the delegate to dictate that the window should not
73 // have a title bar. This is useful when presenting branded interfaces.
74 virtual bool ShouldShowDialogTitle() const = 0;
75
[email protected]9a80e222010-11-22 11:27:2676 // A callback to allow the delegate to inhibit context menu or show
77 // customized menu.
[email protected]eb929d62011-12-23 21:58:2678 // Returns true iff you do NOT want the standard context menu to be
79 // shown (because you want to handle it yourself).
[email protected]9a80e222010-11-22 11:27:2680 virtual bool HandleContextMenu(const ContextMenuParams& params);
81
[email protected]ef1c7df2011-12-06 13:49:4982 // Stores the dialog bounds.
83 virtual void StoreDialogSize(const gfx::Rect dialog_bounds) {}
84
[email protected]038d52e12009-10-14 16:53:4185 protected:
[email protected]1bc6c552010-07-30 20:39:3186 virtual ~HtmlDialogUIDelegate() {}
[email protected]4acc19a62009-04-03 03:05:1187};
88
89// Displays file URL contents inside a modal HTML dialog.
90//
[email protected]0ec4898e2011-12-30 21:09:2491// This application really should not use WebContents + WebUI. It should instead
[email protected]4acc19a62009-04-03 03:05:1192// just embed a RenderView in a dialog and be done with it.
93//
[email protected]d21cdb12011-02-10 01:22:3294// Before loading a URL corresponding to this WebUI, the caller should set its
[email protected]0ec4898e2011-12-30 21:09:2495// delegate as a property on the WebContents. This WebUI will pick it up from
[email protected]4acc19a62009-04-03 03:05:1196// 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:2497// its delegate to the Web UI without having nasty accessors on the WebContents.
[email protected]4acc19a62009-04-03 03:05:1198// The correct design using RVH directly would avoid all of this.
[email protected]e14c959122012-01-13 16:58:2599class HtmlDialogUI : public WebUI, public content::WebUIController {
[email protected]4acc19a62009-04-03 03:05:11100 public:
101 struct HtmlDialogParams {
102 // The URL for the content that will be loaded in the dialog.
103 GURL url;
104 // Width of the dialog.
105 int width;
106 // Height of the dialog.
107 int height;
108 // The JSON input to pass to the dialog when showing it.
109 std::string json_input;
110 };
111
[email protected]0ec4898e2011-12-30 21:09:24112 // When created, the property should already be set on the WebContents.
113 explicit HtmlDialogUI(content::WebContents* web_contents);
[email protected]4acc19a62009-04-03 03:05:11114 virtual ~HtmlDialogUI();
115
[email protected]8befa1a2011-09-21 02:03:38116 // Close the dialog, passing the specified arguments to the close handler.
117 void CloseDialog(const base::ListValue* args);
118
[email protected]4acc19a62009-04-03 03:05:11119 // Returns the PropertyBag accessor object used to write the delegate pointer
[email protected]0ec4898e2011-12-30 21:09:24120 // into the WebContents (see class-level comment above).
[email protected]45644f62011-11-23 00:58:23121 static base::PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor();
[email protected]4acc19a62009-04-03 03:05:11122
123 private:
[email protected]e14c959122012-01-13 16:58:25124 // WebUIController
[email protected]3abbed002011-08-01 16:02:20125 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
[email protected]4acc19a62009-04-03 03:05:11126
127 // JS message handler.
[email protected]f3a1c642011-07-12 19:15:03128 void OnDialogClosed(const base::ListValue* args);
[email protected]4acc19a62009-04-03 03:05:11129
130 DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI);
131};
132
[email protected]73852b8f2010-05-14 00:38:12133// Displays external URL contents inside a modal HTML dialog.
134//
135// Intended to be the place to collect the settings and lockdowns
[email protected]78637b22011-12-02 20:51:52136// necessary for running external UI components securely (e.g., the
[email protected]73852b8f2010-05-14 00:38:12137// cloud print dialog).
138class ExternalHtmlDialogUI : public HtmlDialogUI {
139 public:
[email protected]0ec4898e2011-12-30 21:09:24140 explicit ExternalHtmlDialogUI(content::WebContents* web_contents);
[email protected]73852b8f2010-05-14 00:38:12141 virtual ~ExternalHtmlDialogUI();
142};
143
[email protected]265a1492011-02-27 05:58:07144#endif // CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_