summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui/html_dialog_ui.h
blob: 29895d2d7cc3e98b9120077adb09c543c0ca437a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_
#define CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_

#include "base/gfx/size.h"
#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/common/property_bag.h"
#include "googleurl/src/gurl.h"

// Implement this class to receive notifications.
class HtmlDialogUIDelegate {
 public:
   // Returns true if the contents needs to be run in a modal dialog.
   virtual bool IsDialogModal() const = 0;

   // Returns the title of the dialog.
   virtual std::wstring GetDialogTitle() const = 0;

   // Get the HTML file path for the content to load in the dialog.
   virtual GURL GetDialogContentURL() const = 0;

   // Get the size of the dialog.
   virtual void GetDialogSize(gfx::Size* size) const = 0;

   // Gets the JSON string input to use when showing the dialog.
   virtual std::string GetDialogArgs() const = 0;

   // A callback to notify the delegate that the dialog closed.
   virtual void OnDialogClosed(const std::string& json_retval) = 0;

  protected:
   ~HtmlDialogUIDelegate() {}
};

// Displays file URL contents inside a modal HTML dialog.
//
// This application really should not use TabContents + DOMUI. It should instead
// just embed a RenderView in a dialog and be done with it.
//
// Before loading a URL corresponding to this DOMUI, the caller should set its
// delegate as a property on the TabContents. This DOMUI will pick it up from
// there and call it back. This is a bit of a hack to allow the dialog to pass
// its delegate to the DOM UI without having nasty accessors on the TabContents.
// The correct design using RVH directly would avoid all of this.
class HtmlDialogUI : public DOMUI {
 public:
  struct HtmlDialogParams {
    // 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 property should already be set on the TabContents.
  HtmlDialogUI(TabContents* tab_contents);
  virtual ~HtmlDialogUI();

  // Returns the PropertyBag accessor object used to write the delegate pointer
  // into the TabContents (see class-level comment above).
  static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor();

 private:
  // DOMUI overrides.
  virtual void RenderViewCreated(RenderViewHost* render_view_host);

  // JS message handler.
  void OnDialogClosed(const Value* content);

  DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI);
};

#endif  // CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_