15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string16.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ui_base_types.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/web_dialogs/web_dialogs_export.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHost;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebUI;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebUIMessageHandler;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct ContextMenuParams;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct OpenURLParams;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Rect;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Size;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Implement this class to receive notifications.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WEB_DIALOGS_EXPORT WebDialogDelegate {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the contents needs to be run in a modal dialog.
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ModalType GetDialogModalType() const = 0;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the title of the dialog.
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual base::string16 GetDialogTitle() const = 0;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the dialog's name identifier. Used to identify this dialog for
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // state restoration.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual std::string GetDialogName() const;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the HTML file path for the content to load in the dialog.
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual GURL GetDialogContentURL() const = 0;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get WebUIMessageHandler objects to handle messages from the HTML/JS page.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The handlers are used to send and receive messages from the page while it
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is still open.  Ownership of each handler is taken over by the WebUI
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // hosting the page.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetWebUIMessageHandlers(
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      std::vector<content::WebUIMessageHandler*>* handlers) const = 0;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the size of the dialog.
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetDialogSize(gfx::Size* size) const = 0;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the size of the dialog.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetMinimumDialogSize(gfx::Size* size) const;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the JSON string input to use when showing the dialog.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual std::string GetDialogArgs() const = 0;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns true to signal that the dialog can be closed. Specialized
67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // WebDialogDelegate subclasses can override this default behavior to allow
68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // the close to be blocked until the user corrects mistakes, accepts an
69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // agreement, etc.
70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool CanCloseDialog() const;
71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns true if the dialog can ever be resized. Default implementation
73cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // returns |true|.
74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual bool CanResizeDialog() const;
75cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that |source|'s loading state has
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // changed.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnLoadingStateChanged(content::WebContents* source) {}
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that a web dialog has been shown.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |webui| is the WebUI with which the dialog is associated.
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |render_view_host| is the RenderViewHost for the shown dialog.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDialogShown(content::WebUI* webui,
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             content::RenderViewHost* render_view_host) {}
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that the dialog closed.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // IMPORTANT: Implementations should delete |this| here (unless they've
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // arranged for the delegate to be deleted in some other way, e.g. by
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // registering it as a message handler in the WebUI object).
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDialogClosed(const std::string& json_retval) = 0;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A callback to notify the delegate that the dialog is being closed in
935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // response to a "dialogClose" message from WebUI.
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnDialogCloseFromWebUI(const std::string& json_retval);
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that the contents have gone
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // away. Only relevant if your dialog hosts code that calls
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // windows.close() and you've allowed that.  If the output parameter
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is set to true, then the dialog is closed.  The default is false.
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnCloseContents(content::WebContents* source,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               bool* out_close_dialog) = 0;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to allow the delegate to dictate that the window should not
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // have a title bar.  This is useful when presenting branded interfaces.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ShouldShowDialogTitle() const = 0;
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to allow the delegate to inhibit context menu or show
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // customized menu.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true iff you do NOT want the standard context menu to be
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // shown (because you want to handle it yourself).
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleContextMenu(const content::ContextMenuParams& params);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to allow the delegate to open a new URL inside |source|.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On return |out_new_contents| should contain the WebContents the URL
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is opened in. Return false to use the default handler.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleOpenURLFromTab(content::WebContents* source,
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const content::OpenURLParams& params,
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    content::WebContents** out_new_contents);
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to create a new tab with |new_contents|. |source| is the
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WebContent where the operation originated. |disposition| controls how the
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new tab should be opened. |initial_pos| is the position of the window if a
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new window is created. |user_gesture| is true if the operation was started
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // by a user gesture. Return false to use the default handler.
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleAddNewContents(content::WebContents* source,
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    content::WebContents* new_contents,
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    WindowOpenDisposition disposition,
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const gfx::Rect& initial_pos,
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    bool user_gesture);
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores the dialog bounds.
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StoreDialogSize(const gfx::Size& dialog_size) {}
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebDialogDelegate() {}
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ui
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_
140