html_dialog_ui.h revision ddb351dbec246cf1fab5ec20d2d5520909041de1
1// Copyright (c) 2011 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_HTML_DIALOG_UI_H_ 6#define CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_ 7#pragma once 8 9#include <string> 10#include <vector> 11 12#include "content/browser/webui/web_ui.h" 13#include "content/common/property_bag.h" 14#include "googleurl/src/gurl.h" 15 16namespace gfx { 17class Size; 18} 19 20struct ContextMenuParams; 21 22// Implement this class to receive notifications. 23class HtmlDialogUIDelegate { 24 public: 25 // Returns true if the contents needs to be run in a modal dialog. 26 virtual bool IsDialogModal() const = 0; 27 28 // Returns the title of the dialog. 29 virtual std::wstring GetDialogTitle() const = 0; 30 31 // Get the HTML file path for the content to load in the dialog. 32 virtual GURL GetDialogContentURL() const = 0; 33 34 // Get WebUIMessageHandler objects to handle messages from the HTML/JS page. 35 // The handlers are used to send and receive messages from the page while it 36 // is still open. Ownership of each handler is taken over by the WebUI 37 // hosting the page. 38 virtual void GetWebUIMessageHandlers( 39 std::vector<WebUIMessageHandler*>* handlers) const = 0; 40 41 // Get the size of the dialog. 42 virtual void GetDialogSize(gfx::Size* size) const = 0; 43 44 // Gets the JSON string input to use when showing the dialog. 45 virtual std::string GetDialogArgs() const = 0; 46 47 // A callback to notify the delegate that the dialog closed. 48 virtual void OnDialogClosed(const std::string& json_retval) = 0; 49 50 // Notifies the delegate that the dialog's containing window has been 51 // closed, and that OnDialogClosed() will be called shortly. 52 // TODO(jamescook): Make this pure virtual. 53 virtual void OnWindowClosed(); 54 55 // A callback to notify the delegate that the contents have gone 56 // away. Only relevant if your dialog hosts code that calls 57 // windows.close() and you've allowed that. If the output parameter 58 // is set to true, then the dialog is closed. The default is false. 59 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) = 0; 60 61 // A callback to allow the delegate to dictate that the window should not 62 // have a title bar. This is useful when presenting branded interfaces. 63 virtual bool ShouldShowDialogTitle() const = 0; 64 65 // A callback to allow the delegate to inhibit context menu or show 66 // customized menu. 67 virtual bool HandleContextMenu(const ContextMenuParams& params); 68 69 protected: 70 virtual ~HtmlDialogUIDelegate() {} 71}; 72 73// Displays file URL contents inside a modal HTML dialog. 74// 75// This application really should not use TabContents + WebUI. It should instead 76// just embed a RenderView in a dialog and be done with it. 77// 78// Before loading a URL corresponding to this WebUI, the caller should set its 79// delegate as a property on the TabContents. This WebUI will pick it up from 80// there and call it back. This is a bit of a hack to allow the dialog to pass 81// its delegate to the Web UI without having nasty accessors on the TabContents. 82// The correct design using RVH directly would avoid all of this. 83class HtmlDialogUI : public WebUI { 84 public: 85 struct HtmlDialogParams { 86 // The URL for the content that will be loaded in the dialog. 87 GURL url; 88 // Width of the dialog. 89 int width; 90 // Height of the dialog. 91 int height; 92 // The JSON input to pass to the dialog when showing it. 93 std::string json_input; 94 }; 95 96 // When created, the property should already be set on the TabContents. 97 explicit HtmlDialogUI(TabContents* tab_contents); 98 virtual ~HtmlDialogUI(); 99 100 // Returns the PropertyBag accessor object used to write the delegate pointer 101 // into the TabContents (see class-level comment above). 102 static PropertyAccessor<HtmlDialogUIDelegate*>& GetPropertyAccessor(); 103 104 private: 105 // WebUI 106 virtual void RenderViewCreated(RenderViewHost* render_view_host); 107 108 // JS message handler. 109 void OnDialogClosed(const ListValue* args); 110 111 DISALLOW_COPY_AND_ASSIGN(HtmlDialogUI); 112}; 113 114// Displays external URL contents inside a modal HTML dialog. 115// 116// Intended to be the place to collect the settings and lockdowns 117// necessary for running external UI conponents securely (e.g., the 118// cloud print dialog). 119class ExternalHtmlDialogUI : public HtmlDialogUI { 120 public: 121 explicit ExternalHtmlDialogUI(TabContents* tab_contents); 122 virtual ~ExternalHtmlDialogUI(); 123}; 124 125#endif // CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_UI_H_ 126