| OLD | NEW |
| (Empty) |
| 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_VIEWS_HTML_DIALOG_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "chrome/browser/tab_render_watcher.h" | |
| 15 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" | |
| 16 #include "chrome/browser/ui/webui/html_dialog_ui.h" | |
| 17 #include "ui/gfx/size.h" | |
| 18 #include "ui/views/view.h" | |
| 19 #include "ui/views/widget/widget_delegate.h" | |
| 20 | |
| 21 class Browser; | |
| 22 class HtmlDialogController; | |
| 23 class Profile; | |
| 24 | |
| 25 namespace views { | |
| 26 class WebView; | |
| 27 } | |
| 28 | |
| 29 //////////////////////////////////////////////////////////////////////////////// | |
| 30 // | |
| 31 // HtmlDialogView is a view used to display an HTML dialog to the user. The | |
| 32 // content of the dialogs is determined by the delegate | |
| 33 // (HtmlDialogUIDelegate), but is basically a file URL along with a | |
| 34 // JSON input string. The HTML is supposed to show a UI to the user and is | |
| 35 // expected to send back a JSON file as a return value. | |
| 36 // | |
| 37 //////////////////////////////////////////////////////////////////////////////// | |
| 38 // | |
| 39 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate | |
| 40 // instead of inheriting from it to avoid violating the "no multiple | |
| 41 // inheritance" rule. | |
| 42 // TODO(beng): This class should not depend on Browser or Profile, only | |
| 43 // content::BrowserContext. | |
| 44 class HtmlDialogView | |
| 45 : public views::View, | |
| 46 public HtmlDialogTabContentsDelegate, | |
| 47 public HtmlDialogUIDelegate, | |
| 48 public views::WidgetDelegate, | |
| 49 public TabRenderWatcher::Delegate { | |
| 50 public: | |
| 51 HtmlDialogView(Profile* profile, | |
| 52 Browser* browser, | |
| 53 HtmlDialogUIDelegate* delegate); | |
| 54 virtual ~HtmlDialogView(); | |
| 55 | |
| 56 // For testing. | |
| 57 content::WebContents* web_contents(); | |
| 58 | |
| 59 // Overridden from views::View: | |
| 60 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 61 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) | |
| 62 OVERRIDE; | |
| 63 virtual void ViewHierarchyChanged(bool is_add, | |
| 64 views::View* parent, | |
| 65 views::View* child) OVERRIDE; | |
| 66 | |
| 67 // Overridden from views::WidgetDelegate: | |
| 68 virtual bool CanResize() const OVERRIDE; | |
| 69 virtual ui::ModalType GetModalType() const OVERRIDE; | |
| 70 virtual string16 GetWindowTitle() const OVERRIDE; | |
| 71 virtual std::string GetWindowName() const OVERRIDE; | |
| 72 virtual void WindowClosing() OVERRIDE; | |
| 73 virtual views::View* GetContentsView() OVERRIDE; | |
| 74 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | |
| 75 virtual bool ShouldShowWindowTitle() const OVERRIDE; | |
| 76 virtual views::Widget* GetWidget() OVERRIDE; | |
| 77 virtual const views::Widget* GetWidget() const OVERRIDE; | |
| 78 | |
| 79 // Overridden from HtmlDialogUIDelegate: | |
| 80 virtual ui::ModalType GetDialogModalType() const OVERRIDE; | |
| 81 virtual string16 GetDialogTitle() const OVERRIDE; | |
| 82 virtual GURL GetDialogContentURL() const OVERRIDE; | |
| 83 virtual void GetWebUIMessageHandlers( | |
| 84 std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE; | |
| 85 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; | |
| 86 virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE; | |
| 87 virtual std::string GetDialogArgs() const OVERRIDE; | |
| 88 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | |
| 89 virtual void OnCloseContents(content::WebContents* source, | |
| 90 bool* out_close_dialog) OVERRIDE; | |
| 91 virtual bool ShouldShowDialogTitle() const OVERRIDE; | |
| 92 virtual bool HandleContextMenu( | |
| 93 const content::ContextMenuParams& params) OVERRIDE; | |
| 94 | |
| 95 // Overridden from content::WebContentsDelegate: | |
| 96 virtual void MoveContents(content::WebContents* source, | |
| 97 const gfx::Rect& pos) OVERRIDE; | |
| 98 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) | |
| 99 OVERRIDE; | |
| 100 virtual void CloseContents(content::WebContents* source) OVERRIDE; | |
| 101 virtual content::WebContents* OpenURLFromTab( | |
| 102 content::WebContents* source, | |
| 103 const content::OpenURLParams& params) OVERRIDE; | |
| 104 virtual void AddNewContents(content::WebContents* source, | |
| 105 content::WebContents* new_contents, | |
| 106 WindowOpenDisposition disposition, | |
| 107 const gfx::Rect& initial_pos, | |
| 108 bool user_gesture) OVERRIDE; | |
| 109 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | |
| 110 | |
| 111 protected: | |
| 112 // Overridden from TabRenderWatcher::Delegate: | |
| 113 virtual void OnRenderHostCreated(content::RenderViewHost* host) OVERRIDE; | |
| 114 virtual void OnTabMainFrameLoaded() OVERRIDE; | |
| 115 virtual void OnTabMainFrameRender() OVERRIDE; | |
| 116 | |
| 117 private: | |
| 118 FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered); | |
| 119 | |
| 120 // Initializes the contents of the dialog. | |
| 121 void InitDialog(); | |
| 122 | |
| 123 // Whether the view is initialized. That is, dialog accelerators is registered | |
| 124 // and FreezeUpdates property is set to prevent WM from showing the window | |
| 125 // until the property is removed. | |
| 126 bool initialized_; | |
| 127 | |
| 128 // Watches for WebContents rendering. | |
| 129 scoped_ptr<TabRenderWatcher> tab_watcher_; | |
| 130 | |
| 131 // This view is a delegate to the HTML content since it needs to get notified | |
| 132 // about when the dialog is closing. For all other actions (besides dialog | |
| 133 // closing) we delegate to the creator of this view, which we keep track of | |
| 134 // using this variable. | |
| 135 HtmlDialogUIDelegate* delegate_; | |
| 136 | |
| 137 // Controls lifetime of dialog. | |
| 138 scoped_ptr<HtmlDialogController> dialog_controller_; | |
| 139 | |
| 140 views::WebView* web_view_; | |
| 141 | |
| 142 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); | |
| 143 }; | |
| 144 | |
| 145 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | |
| OLD | NEW |