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 13namespace content { 14class BrowserContext; 15class RenderViewHost; 16class WebContents; 17} 18 19namespace ui { 20class WebDialogDelegate; 21class WebDialogWebContentsDelegate; 22} 23 24class 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. 54class ConstrainedWebDialogUI : public content::WebUIController { 55 public: 56 explicit ConstrainedWebDialogUI(content::WebUI* web_ui); 57 virtual ~ConstrainedWebDialogUI(); 58 59 // WebUIController implementation: 60 virtual void RenderViewCreated( 61 content::RenderViewHost* render_view_host) OVERRIDE; 62 63 // Sets the delegate on the WebContents. 64 static void SetConstrainedDelegate(content::WebContents* web_contents, 65 ConstrainedWebDialogDelegate* delegate); 66 67 protected: 68 // Returns the ConstrainedWebDialogDelegate saved with the WebContents. 69 // Returns NULL if no such delegate is set. 70 ConstrainedWebDialogDelegate* GetConstrainedDelegate(); 71 72 private: 73 // JS Message Handler 74 void OnDialogCloseMessage(const base::ListValue* args); 75 76 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogUI); 77}; 78 79// Create a constrained HTML dialog. The actual object that gets created 80// is a ConstrainedWebDialogDelegate, which later triggers construction of a 81// ConstrainedWebDialogUI object. 82// |browser_context| is used to construct the constrained HTML dialog's 83// WebContents. 84// |delegate| controls the behavior of the dialog. 85// |overshadowed| is the tab being overshadowed by the dialog. 86ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( 87 content::BrowserContext* browser_context, 88 ui::WebDialogDelegate* delegate, 89 content::WebContents* overshadowed); 90 91#endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_UI_H_ 92