Remove APIPermission::kFileSystemWriteDirectory
[chromium-blink-merge.git] / ui / web_dialogs / web_dialog_delegate.h
blob640dfd02ccee3a2010fe6f0db3c9760c0478aecd
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_
8 #include <string>
9 #include <vector>
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"
17 class GURL;
19 namespace content {
20 class RenderViewHost;
21 class WebContents;
22 class WebUI;
23 class WebUIMessageHandler;
24 struct ContextMenuParams;
25 struct OpenURLParams;
28 namespace gfx {
29 class Rect;
30 class Size;
33 namespace ui {
35 // Implement this class to receive notifications.
36 class WEB_DIALOGS_EXPORT WebDialogDelegate {
37 public:
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
45 // state restoration.
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
54 // hosting the page.
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
70 // agreement, etc.
71 virtual bool CanCloseDialog() const;
73 // Returns true if the dialog can ever be resized. Default implementation
74 // returns |true|.
75 virtual bool CanResizeDialog() const;
77 // A callback to notify the delegate that |source|'s loading state has
78 // changed.
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 // |out_close_dialog| is never NULL.
102 virtual void OnCloseContents(content::WebContents* source,
103 bool* out_close_dialog) = 0;
105 // A callback to allow the delegate to dictate that the window should not
106 // have a title bar. This is useful when presenting branded interfaces.
107 virtual bool ShouldShowDialogTitle() const = 0;
109 // A callback to allow the delegate to inhibit context menu or show
110 // customized menu.
111 // Returns true iff you do NOT want the standard context menu to be
112 // shown (because you want to handle it yourself).
113 virtual bool HandleContextMenu(const content::ContextMenuParams& params);
115 // A callback to allow the delegate to open a new URL inside |source|.
116 // On return |out_new_contents| should contain the WebContents the URL
117 // is opened in. Return false to use the default handler.
118 virtual bool HandleOpenURLFromTab(content::WebContents* source,
119 const content::OpenURLParams& params,
120 content::WebContents** out_new_contents);
122 // A callback to create a new tab with |new_contents|. |source| is the
123 // WebContent where the operation originated. |disposition| controls how the
124 // new tab should be opened. |initial_rect| is the position and size of the
125 // window if a new window is created. |user_gesture| is true if the operation
126 // was started by a user gesture. Return false to use the default handler.
127 virtual bool HandleAddNewContents(content::WebContents* source,
128 content::WebContents* new_contents,
129 WindowOpenDisposition disposition,
130 const gfx::Rect& initial_rect,
131 bool user_gesture);
133 // A callback to control whether a WebContents will be created. Returns
134 // false to disallow the creation. Return true to use the default handler.
135 virtual bool HandleShouldCreateWebContents();
137 // Stores the dialog bounds.
138 virtual void StoreDialogSize(const gfx::Size& dialog_size) {}
140 virtual ~WebDialogDelegate() {}
143 } // namespace ui
145 #endif // UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_