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_DELEGATE_H_
6 #define UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_
11 #include "base/strings/string16.h"
12 #include "content/public/browser/web_contents_delegate.h"
13 #include "ui/base/ui_base_types.h"
14 #include "ui/base/window_open_disposition.h"
15 #include "ui/web_dialogs/web_dialogs_export.h"
23 class WebUIMessageHandler
;
24 struct ContextMenuParams
;
35 // Implement this class to receive notifications.
36 class WEB_DIALOGS_EXPORT WebDialogDelegate
{
38 // Returns true if the contents needs to be run in a modal dialog.
39 virtual ModalType
GetDialogModalType() const = 0;
41 // Returns the title of the dialog.
42 virtual base::string16
GetDialogTitle() const = 0;
44 // Returns the dialog's name identifier. Used to identify this dialog for
46 virtual std::string
GetDialogName() const;
48 // Get the HTML file path for the content to load in the dialog.
49 virtual GURL
GetDialogContentURL() const = 0;
51 // Get WebUIMessageHandler objects to handle messages from the HTML/JS page.
52 // The handlers are used to send and receive messages from the page while it
53 // is still open. Ownership of each handler is taken over by the WebUI
55 virtual void GetWebUIMessageHandlers(
56 std::vector
<content::WebUIMessageHandler
*>* handlers
) const = 0;
58 // Get the size of the dialog.
59 virtual void GetDialogSize(gfx::Size
* size
) const = 0;
61 // Get the size of the dialog.
62 virtual void GetMinimumDialogSize(gfx::Size
* size
) const;
64 // Gets the JSON string input to use when showing the dialog.
65 virtual std::string
GetDialogArgs() const = 0;
67 // Returns true to signal that the dialog can be closed. Specialized
68 // WebDialogDelegate subclasses can override this default behavior to allow
69 // the close to be blocked until the user corrects mistakes, accepts an
71 virtual bool CanCloseDialog() const;
73 // Returns true if the dialog can ever be resized. Default implementation
75 virtual bool CanResizeDialog() const;
77 // A callback to notify the delegate that |source|'s loading state has
79 virtual void OnLoadingStateChanged(content::WebContents
* source
) {}
81 // A callback to notify the delegate that a web dialog has been shown.
82 // |webui| is the WebUI with which the dialog is associated.
83 // |render_view_host| is the RenderViewHost for the shown dialog.
84 virtual void OnDialogShown(content::WebUI
* webui
,
85 content::RenderViewHost
* render_view_host
) {}
87 // A callback to notify the delegate that the dialog closed.
88 // IMPORTANT: Implementations should delete |this| here (unless they've
89 // arranged for the delegate to be deleted in some other way, e.g. by
90 // registering it as a message handler in the WebUI object).
91 virtual void OnDialogClosed(const std::string
& json_retval
) = 0;
93 // A callback to notify the delegate that the dialog is being closed in
94 // response to a "dialogClose" message from WebUI.
95 virtual void OnDialogCloseFromWebUI(const std::string
& json_retval
);
97 // A callback to notify the delegate that the contents have gone
98 // away. Only relevant if your dialog hosts code that calls
99 // windows.close() and you've allowed that. If the output parameter
100 // is set to true, then the dialog is closed. The default is false.
101 virtual void OnCloseContents(content::WebContents
* source
,
102 bool* out_close_dialog
) = 0;
104 // A callback to allow the delegate to dictate that the window should not
105 // have a title bar. This is useful when presenting branded interfaces.
106 virtual bool ShouldShowDialogTitle() const = 0;
108 // A callback to allow the delegate to inhibit context menu or show
110 // Returns true iff you do NOT want the standard context menu to be
111 // shown (because you want to handle it yourself).
112 virtual bool HandleContextMenu(const content::ContextMenuParams
& params
);
114 // A callback to allow the delegate to open a new URL inside |source|.
115 // On return |out_new_contents| should contain the WebContents the URL
116 // is opened in. Return false to use the default handler.
117 virtual bool HandleOpenURLFromTab(content::WebContents
* source
,
118 const content::OpenURLParams
& params
,
119 content::WebContents
** out_new_contents
);
121 // A callback to create a new tab with |new_contents|. |source| is the
122 // WebContent where the operation originated. |disposition| controls how the
123 // new tab should be opened. |initial_rect| is the position and size of the
124 // window if a new window is created. |user_gesture| is true if the operation
125 // was started by a user gesture. Return false to use the default handler.
126 virtual bool HandleAddNewContents(content::WebContents
* source
,
127 content::WebContents
* new_contents
,
128 WindowOpenDisposition disposition
,
129 const gfx::Rect
& initial_rect
,
132 // A callback to control whether a WebContents will be created. Returns
133 // false to disallow the creation. Return true to use the default handler.
134 virtual bool HandleShouldCreateWebContents();
136 // Stores the dialog bounds.
137 virtual void StoreDialogSize(const gfx::Size
& dialog_size
) {}
139 virtual ~WebDialogDelegate() {}
144 #endif // UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_