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 CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "components/web_modal/native_web_contents_modal_dialog.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_ui_controller.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/native_widget_types.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class BrowserContext; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHost; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebDialogDelegate; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebDialogWebContentsDelegate; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ConstrainedWebDialogDelegate { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual const ui::WebDialogDelegate* GetWebDialogDelegate() const = 0; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ui::WebDialogDelegate* GetWebDialogDelegate() = 0; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the dialog is being closed in response to a "dialogClose" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // message from WebUI. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnDialogCloseFromWebUI() = 0; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If called, on dialog closure, the dialog will release its WebContents 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instead of destroying it. After which point, the caller will own the 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // released WebContents. 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ReleaseWebContentsOnDialogClose() = 0; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the WebContents owned by the constrained window. 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual content::WebContents* GetWebContents() = 0; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the native type used to display the dialog. 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() = 0; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~ConstrainedWebDialogDelegate() {} 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ConstrainedWebDialogUI is a facility to show HTML WebUI content 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in a tab-modal constrained dialog. It is implemented as an adapter 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// between an WebDialogUI object and a web contents modal dialog. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Since the web contents modal dialog requires platform-specific delegate 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// implementations, this class is just a factory stub. 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ConstrainedWebDialogUI : public content::WebUIController { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ConstrainedWebDialogUI(content::WebUI* web_ui); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~ConstrainedWebDialogUI(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WebUIController implementation: 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RenderViewCreated( 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RenderViewHost* render_view_host) OVERRIDE; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the delegate on the WebContents. 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void SetConstrainedDelegate(content::WebContents* web_contents, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConstrainedWebDialogDelegate* delegate); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the ConstrainedWebDialogDelegate saved with the WebContents. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns NULL if no such delegate is set. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConstrainedWebDialogDelegate* GetConstrainedDelegate(); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // JS Message Handler 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnDialogCloseMessage(const base::ListValue* args); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogUI); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create a constrained HTML dialog. The actual object that gets created 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is a ConstrainedWebDialogDelegate, which later triggers construction of a 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ConstrainedWebDialogUI object. 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// |browser_context| is used to construct the constrained HTML dialog's 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WebContents. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |delegate| controls the behavior of the dialog. 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |overshadowed| is the tab being overshadowed by the dialog. 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::BrowserContext* browser_context, 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::WebDialogDelegate* delegate, 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* overshadowed); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 92