Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / web_dialogs / web_dialog_ui.h
1 // Copyright (c) 2012 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 UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
6 #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/strings/string16.h"
13 #include "content/public/browser/web_contents_delegate.h"
14 #include "content/public/browser/web_ui_controller.h"
15 #include "ui/base/ui_base_types.h"
16 #include "ui/web_dialogs/web_dialogs_export.h"
17 #include "url/gurl.h"
18
19 namespace content {
20 class WebContents;
21 class WebUIMessageHandler;
22 struct ContextMenuParams;
23 }
24
25 namespace gfx {
26 class Size;
27 }
28
29 namespace ui {
30
31 class WebDialogDelegate;
32
33 // Displays file URL contents inside a modal web dialog.
34 //
35 // This application really should not use WebContents + WebUI. It should instead
36 // just embed a RenderView in a dialog and be done with it.
37 //
38 // Before loading a URL corresponding to this WebUI, the caller should set its
39 // delegate as user data on the WebContents by calling SetDelegate(). This WebUI
40 // will pick it up from there and call it back. This is a bit of a hack to allow
41 // the dialog to pass its delegate to the Web UI without having nasty accessors
42 // on the WebContents. The correct design using RVH directly would avoid all of
43 // this.
44 class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController {
45  public:
46   struct WebDialogParams {
47     // The URL for the content that will be loaded in the dialog.
48     GURL url;
49     // Width of the dialog.
50     int width;
51     // Height of the dialog.
52     int height;
53     // The JSON input to pass to the dialog when showing it.
54     std::string json_input;
55   };
56
57   // When created, the delegate should already be set as user data on the
58   // WebContents.
59   explicit WebDialogUI(content::WebUI* web_ui);
60   ~WebDialogUI() override;
61
62   // Close the dialog, passing the specified arguments to the close handler.
63   void CloseDialog(const base::ListValue* args);
64
65   // Sets the delegate on the WebContents.
66   static void SetDelegate(content::WebContents* web_contents,
67                           WebDialogDelegate* delegate);
68
69  private:
70   // WebUIController
71   void RenderViewCreated(content::RenderViewHost* render_view_host) override;
72
73   // Gets the delegate for the WebContent set with SetDelegate.
74   static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
75
76   // JS message handler.
77   void OnDialogClosed(const base::ListValue* args);
78
79   DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
80 };
81
82 // Displays external URL contents inside a modal web dialog.
83 //
84 // Intended to be the place to collect the settings and lockdowns
85 // necessary for running external UI components securely (e.g., the
86 // cloud print dialog).
87 class WEB_DIALOGS_EXPORT ExternalWebDialogUI : public WebDialogUI {
88  public:
89   explicit ExternalWebDialogUI(content::WebUI* web_ui);
90   ~ExternalWebDialogUI() override;
91 };
92
93 }  // namespace ui
94
95 #endif  // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_