blob: ffc5196429ee2a8f0be853414b20accc46dd318c [file] [log] [blame]
[email protected]4acc19a62009-04-03 03:05:111// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_
6#define CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_
7
[email protected]038d52e12009-10-14 16:53:418#include <string>
[email protected]2bc2de62009-06-29 23:37:429#include <vector>
10
[email protected]4acc19a62009-04-03 03:05:1111#include "chrome/browser/dom_ui/dom_ui.h"
12#include "chrome/common/property_bag.h"
13#include "googleurl/src/gurl.h"
14
[email protected]5c238752009-06-13 10:29:0715namespace gfx {
16class Size;
17}
18
[email protected]4acc19a62009-04-03 03:05:1119// Implement this class to receive notifications.
20class HtmlDialogUIDelegate {
21 public:
[email protected]038d52e12009-10-14 16:53:4122 // Returns true if the contents needs to be run in a modal dialog.
23 virtual bool IsDialogModal() const = 0;
[email protected]4acc19a62009-04-03 03:05:1124
[email protected]038d52e12009-10-14 16:53:4125 // Returns the title of the dialog.
26 virtual std::wstring GetDialogTitle() const = 0;
[email protected]4acc19a62009-04-03 03:05:1127
[email protected]038d52e12009-10-14 16:53:4128 // Get the HTML file path for the content to load in the dialog.
29 virtual GURL GetDialogContentURL() const = 0;
[email protected]4acc19a62009-04-03 03:05:1130
[email protected]038d52e12009-10-14 16:53:4131 // Get DOMMessageHandler objects to handle messages from the HTML/JS page.
32 // The handlers are used to send and receive messages from the page while it
33 // is still open. Ownership of each handler is taken over by the DOMUI
34 // hosting the page.
35 virtual void GetDOMMessageHandlers(
36 std::vector<DOMMessageHandler*>* handlers) const = 0;
[email protected]2bc2de62009-06-29 23:37:4237
[email protected]038d52e12009-10-14 16:53:4138 // Get the size of the dialog.
39 virtual void GetDialogSize(gfx::Size* size) const = 0;
[email protected]4acc19a62009-04-03 03:05:1140
[email protected]038d52e12009-10-14 16:53:4141 // Gets the JSON string input to use when showing the dialog.
42 virtual std::string GetDialogArgs() const = 0;
[email protected]4acc19a62009-04-03 03:05:1143
[email protected]038d52e12009-10-14 16:53:4144 // A callback to notify the delegate that the dialog closed.
45 virtual void OnDialogClosed(const std::string& json_retval) = 0;
[email protected]4acc19a62009-04-03 03:05:1146
[email protected]038d52e12009-10-14 16:53:4147 protected:
48 ~HtmlDialogUIDelegate() {}
[email protected]4acc19a62009-04-03 03:05:1149};
50
51// Displays file URL contents inside a modal HTML dialog.
52//
[email protected]57c6a652009-05-04 07:58:3453// This application really should not use TabContents + DOMUI. It should instead
[email protected]4acc19a62009-04-03 03:05:1154// just embed a RenderView in a dialog and be done with it.
55//
56// Before loading a URL corresponding to this DOMUI, the caller should set its
[email protected]57c6a652009-05-04 07:58:3457// delegate as a property on the TabContents. This DOMUI will pick it up from
[email protected]4acc19a62009-04-03 03:05:1158// there and call it back. This is a bit of a hack to allow the dialog to pass
[email protected]57c6a652009-05-04 07:58:3459// its delegate to the DOM UI without having nasty accessors on the TabContents.
[email protected]4acc19a62009-04-03 03:05:1160// The correct design using RVH directly would avoid all of this.
61class HtmlDialogUI : public DOMUI {
62 public:
63 struct HtmlDialogParams {
64 // The URL for the content that will be loaded in the dialog.
65 GURL url;
66 // Width of the dialog.
67 int width;
68 // Height of the dialog.
69 int height;
70 // The JSON input to pass to the dialog when showing it.
71 std::string json_input;
72 };
73
[email protected]57c6a652009-05-04 07:58:3474 // When created, the property should already be set on the TabContents.
[email protected]038d52e12009-10-14 16:53:4175 explicit HtmlDialogUI(TabContents* tab_contents);
[email protected]4acc19a62009-04-03 03:05:1176 virtual ~HtmlDialogUI();
77
78 // Returns the PropertyBag accessor object used to write the delegate pointer
[email protected]57c6a652009-05-04 07:58:3479 // into the TabContents (see class-level comment above).
[email protected]4acc19a62009-04-03 03:05:1180 static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor();
81
82 private:
83 // DOMUI overrides.
84 virtual void RenderViewCreated(RenderViewHost* render_view_host);
85
86 // JS message handler.
87 void OnDialogClosed(const Value* content);
88
89 DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI);
90};
91
92#endif // CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_