blob: 070315f94a63ef8e6a9564d4c0bf72bb20b3314f [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
8#include "base/gfx/size.h"
9#include "chrome/browser/dom_ui/dom_ui.h"
10#include "chrome/common/property_bag.h"
11#include "googleurl/src/gurl.h"
12
13// Implement this class to receive notifications.
14class HtmlDialogUIDelegate {
15 public:
16 // Returns true if the contents needs to be run in a modal dialog.
17 virtual bool IsDialogModal() const = 0;
18
19 // Returns the title of the dialog.
20 virtual std::wstring GetDialogTitle() const = 0;
21
22 // Get the HTML file path for the content to load in the dialog.
23 virtual GURL GetDialogContentURL() const = 0;
24
25 // Get the size of the dialog.
26 virtual void GetDialogSize(gfx::Size* size) const = 0;
27
28 // Gets the JSON string input to use when showing the dialog.
29 virtual std::string GetDialogArgs() const = 0;
30
31 // A callback to notify the delegate that the dialog closed.
32 virtual void OnDialogClosed(const std::string& json_retval) = 0;
33
34 protected:
35 ~HtmlDialogUIDelegate() {}
36};
37
38// Displays file URL contents inside a modal HTML dialog.
39//
40// This application really should not use WebContents + DOMUI. It should instead
41// just embed a RenderView in a dialog and be done with it.
42//
43// Before loading a URL corresponding to this DOMUI, the caller should set its
44// delegate as a property on the WebContents. This DOMUI will pick it up from
45// there and call it back. This is a bit of a hack to allow the dialog to pass
46// its delegate to the DOM UI without having nasty accessors on the WebContents.
47// The correct design using RVH directly would avoid all of this.
48class HtmlDialogUI : public DOMUI {
49 public:
50 struct HtmlDialogParams {
51 // The URL for the content that will be loaded in the dialog.
52 GURL url;
53 // Width of the dialog.
54 int width;
55 // Height of the dialog.
56 int height;
57 // The JSON input to pass to the dialog when showing it.
58 std::string json_input;
59 };
60
61 // When created, the property should already be set on the WebContents.
62 HtmlDialogUI(WebContents* web_contents);
63 virtual ~HtmlDialogUI();
64
65 // Returns the PropertyBag accessor object used to write the delegate pointer
66 // into the WebContents (see class-level comment above).
67 static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor();
68
69 private:
70 // DOMUI overrides.
71 virtual void RenderViewCreated(RenderViewHost* render_view_host);
72
73 // JS message handler.
74 void OnDialogClosed(const Value* content);
75
76 DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI);
77};
78
79#endif // CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_