web_dialog_delegate.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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> 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/string16.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/ui_base_types.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/window_open_disposition.h" 14bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "ui/web_dialogs/web_dialogs_export.h" 15bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class GURL; 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content { 19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass RenderViewHost; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebUI; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebUIMessageHandler; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct ContextMenuParams; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct OpenURLParams; 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 27868fa2fe829687343ffae624259930155e16dbd8Torne (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) 3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (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; 39d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the title of the dialog. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (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. 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual std::string GetDialogName() const; 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get the HTML file path for the content to load in the dialog. 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual GURL GetDialogContentURL() const = 0; 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get WebUIMessageHandler objects to handle messages from the HTML/JS page. 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The handlers are used to send and receive messages from the page while it 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // is still open. Ownership of each handler is taken over by the WebUI 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // hosting the page. 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void GetWebUIMessageHandlers( 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<content::WebUIMessageHandler*>* handlers) const = 0; 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Get the size of the dialog. 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void GetDialogSize(gfx::Size* size) const = 0; 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get the size of the dialog. 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void GetMinimumDialogSize(gfx::Size* size) const; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets the JSON string input to use when showing the dialog. 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual std::string GetDialogArgs() const = 0; 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns true to signal that the dialog can be closed. Specialized 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // WebDialogDelegate subclasses can override this default behavior to allow 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the close to be blocked until the user corrects mistakes, accepts an 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // agreement, etc. 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool CanCloseDialog() const; 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A callback to notify the delegate that |source|'s loading state has 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // changed. 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnLoadingStateChanged(content::WebContents* source) {} 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // A callback to notify the delegate that a web dialog has been shown. 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |webui| is the WebUI with which the dialog is associated. 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |render_view_host| is the RenderViewHost for the shown dialog. 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnDialogShown(content::WebUI* webui, 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::RenderViewHost* render_view_host) {} 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A callback to notify the delegate that the dialog closed. 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // IMPORTANT: Implementations should delete |this| here (unless they've 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // arranged for the delegate to be deleted in some other way, e.g. by 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // registering it as a message handler in the WebUI object). 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnDialogClosed(const std::string& json_retval) = 0; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A callback to notify the delegate that the dialog is being closed in 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // response to a "DialogClose" message from WebUI. 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnDialogCloseFromWebUI(const std::string& json_retval); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A callback to notify the delegate that the contents have gone 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // away. Only relevant if your dialog hosts code that calls 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // windows.close() and you've allowed that. If the output parameter 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is set to true, then the dialog is closed. The default is false. 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnCloseContents(content::WebContents* source, 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* out_close_dialog) = 0; 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A callback to allow the delegate to dictate that the window should not 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have a title bar. This is useful when presenting branded interfaces. 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool ShouldShowDialogTitle() const = 0; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A callback to allow the delegate to inhibit context menu or show 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // customized menu. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true iff you do NOT want the standard context menu to be 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shown (because you want to handle it yourself). 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool HandleContextMenu(const content::ContextMenuParams& params); 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A callback to allow the delegate to open a new URL inside |source|. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On return |out_new_contents| should contain the WebContents the URL 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is opened in. Return false to use the default handler. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool HandleOpenURLFromTab(content::WebContents* source, 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::OpenURLParams& params, 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents** out_new_contents); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A callback to create a new tab with |new_contents|. |source| is the 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WebContent where the operation originated. |disposition| controls how the 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // new tab should be opened. |initial_pos| is the position of the window if a 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // new window is created. |user_gesture| is true if the operation was started 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by a user gesture. Return false to use the default handler. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool HandleAddNewContents(content::WebContents* source, 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* new_contents, 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowOpenDisposition disposition, 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& initial_pos, 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool user_gesture); 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stores the dialog bounds. 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void StoreDialogSize(const gfx::Size& dialog_size) {} 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~WebDialogDelegate() {} 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif // UI_WEB_DIALOGS_WEB_DIALOG_DELEGATE_H_ 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)