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. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 6 #define CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 7 8 #include "base/compiler_specific.h" 9 #include "components/web_modal/native_web_contents_modal_dialog.h" 10 #include "content/public/browser/web_ui_controller.h" 11 #include "ui/gfx/native_widget_types.h" 12 13 namespace content { 14 class BrowserContext; 15 class RenderViewHost; 16 class WebContents; 17 } 18 19 namespace ui { 20 class WebDialogDelegate; 21 class WebDialogWebContentsDelegate; 22 } 23 24 class ConstrainedWebDialogDelegate { 25 public: 26 virtual const ui::WebDialogDelegate* GetWebDialogDelegate() const = 0; 27 virtual ui::WebDialogDelegate* GetWebDialogDelegate() = 0; 28 29 // Called when the dialog is being closed in response to a "DialogClose" 30 // message from WebUI. 31 virtual void OnDialogCloseFromWebUI() = 0; 32 33 // If called, on dialog closure, the dialog will release its WebContents 34 // instead of destroying it. After which point, the caller will own the 35 // released WebContents. 36 virtual void ReleaseWebContentsOnDialogClose() = 0; 37 38 // Returns the WebContents owned by the constrained window. 39 virtual content::WebContents* GetWebContents() = 0; 40 41 // Returns the native type used to display the dialog. 42 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() = 0; 43 44 protected: 45 virtual ~ConstrainedWebDialogDelegate() {} 46 }; 47 48 // ConstrainedWebDialogUI is a facility to show HTML WebUI content 49 // in a tab-modal constrained dialog. It is implemented as an adapter 50 // between an WebDialogUI object and a web contents modal dialog. 51 // 52 // Since the web contents modal dialog requires platform-specific delegate 53 // implementations, this class is just a factory stub. 54 class ConstrainedWebDialogUI 55 : public content::WebUIController { 56 public: 57 explicit ConstrainedWebDialogUI(content::WebUI* web_ui); 58 virtual ~ConstrainedWebDialogUI(); 59 60 // WebUIController implementation: 61 virtual void RenderViewCreated( 62 content::RenderViewHost* render_view_host) OVERRIDE; 63 64 // Sets the delegate on the WebContents. 65 static void SetConstrainedDelegate(content::WebContents* web_contents, 66 ConstrainedWebDialogDelegate* delegate); 67 68 protected: 69 // Returns the ConstrainedWebDialogDelegate saved with the WebContents. 70 // Returns NULL if no such delegate is set. 71 ConstrainedWebDialogDelegate* GetConstrainedDelegate(); 72 73 private: 74 // JS Message Handler 75 void OnDialogCloseMessage(const base::ListValue* args); 76 77 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogUI); 78 }; 79 80 // Create a constrained HTML dialog. The actual object that gets created 81 // is a ConstrainedWebDialogDelegate, which later triggers construction of a 82 // ConstrainedWebDialogUI object. 83 // |browser_context| is used to construct the constrained HTML dialog's 84 // WebContents. 85 // |delegate| controls the behavior of the dialog. 86 // |tab_delegate| is optional, pass one in to use a custom 87 // WebDialogWebContentsDelegate with the dialog, or NULL to 88 // use the default one. The dialog takes ownership of 89 // |tab_delegate|. 90 // |overshadowed| is the tab being overshadowed by the dialog. 91 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( 92 content::BrowserContext* browser_context, 93 ui::WebDialogDelegate* delegate, 94 ui::WebDialogWebContentsDelegate* tab_delegate, 95 content::WebContents* overshadowed); 96 97 #endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 98