web_dialog_delegate.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/string16.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ui_base_types.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/web_dialogs/web_dialogs_export.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "webkit/glue/window_open_disposition.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.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual 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)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that |source|'s loading state has
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // changed.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnLoadingStateChanged(content::WebContents* source) {}
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that a web dialog has been shown.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |webui| is the WebUI with which the dialog is associated.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |render_view_host| is the RenderViewHost for the shown dialog.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDialogShown(content::WebUI* webui,
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             content::RenderViewHost* render_view_host) {}
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that the dialog closed.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // IMPORTANT: Implementations should delete |this| here (unless they've
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // arranged for the delegate to be deleted in some other way, e.g. by
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // registering it as a message handler in the WebUI object).
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDialogClosed(const std::string& json_retval) = 0;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to notify the delegate that the contents have gone
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // away. Only relevant if your dialog hosts code that calls
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // windows.close() and you've allowed that.  If the output parameter
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is set to true, then the dialog is closed.  The default is false.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnCloseContents(content::WebContents* source,
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               bool* out_close_dialog) = 0;
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to allow the delegate to dictate that the window should not
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // have a title bar.  This is useful when presenting branded interfaces.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ShouldShowDialogTitle() const = 0;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to allow the delegate to inhibit context menu or show
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // customized menu.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true iff you do NOT want the standard context menu to be
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // shown (because you want to handle it yourself).
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleContextMenu(const content::ContextMenuParams& params);
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to allow the delegate to open a new URL inside |source|.
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On return |out_new_contents| should contain the WebContents the URL
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is opened in. Return false to use the default handler.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleOpenURLFromTab(content::WebContents* source,
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const content::OpenURLParams& params,
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    content::WebContents** out_new_contents);
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A callback to create a new tab with |new_contents|. |source| is the
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WebContent where the operation originated. |disposition| controls how the
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new tab should be opened. |initial_pos| is the position of the window if a
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new window is created. |user_gesture| is true if the operation was started
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // by a user gesture. Return false to use the default handler.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleAddNewContents(content::WebContents* source,
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    content::WebContents* new_contents,
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    WindowOpenDisposition disposition,
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const gfx::Rect& initial_pos,
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    bool user_gesture);
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores the dialog bounds.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StoreDialogSize(const gfx::Size& dialog_size) {}
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebDialogDelegate() {}
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ui
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_
126