Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / web_dialogs / web_dialog_ui.h
blobe210bf8a8cbb83c9829e266b62ea3df46ec6da8a
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.
5 #ifndef UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
6 #define UI_WEB_DIALOGS_WEB_DIALOG_UI_H_
8 #include <string>
9 #include <vector>
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"
19 namespace content {
20 class WebContents;
21 class WebUIMessageHandler;
22 struct ContextMenuParams;
25 namespace gfx {
26 class Size;
29 namespace ui {
31 class WebDialogDelegate;
33 // Displays file URL contents inside a modal web dialog.
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.
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;
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;
62 // Close the dialog, passing the specified arguments to the close handler.
63 void CloseDialog(const base::ListValue* args);
65 // Sets the delegate on the WebContents.
66 static void SetDelegate(content::WebContents* web_contents,
67 WebDialogDelegate* delegate);
69 private:
70 // WebUIController
71 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
73 // Gets the delegate for the WebContent set with SetDelegate.
74 static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
76 // JS message handler.
77 void OnDialogClosed(const base::ListValue* args);
79 DISALLOW_COPY_AND_ASSIGN(WebDialogUI);
82 } // namespace ui
84 #endif // UI_WEB_DIALOGS_WEB_DIALOG_UI_H_