OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/browser/tab_render_watcher.h" | 14 #include "chrome/browser/tab_render_watcher.h" |
15 #include "chrome/browser/ui/views/dom_view.h" | |
16 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" | 15 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" |
17 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 16 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
18 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
| 18 #include "ui/views/view.h" |
19 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/views/widget/widget_delegate.h" |
20 | 20 |
21 class Browser; | 21 class Browser; |
22 class HtmlDialogController; | 22 class HtmlDialogController; |
23 class Profile; | 23 class Profile; |
24 | 24 |
| 25 namespace views { |
| 26 class WebView; |
| 27 } |
| 28 |
25 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
26 // | 30 // |
27 // HtmlDialogView is a view used to display an HTML dialog to the user. The | 31 // HtmlDialogView is a view used to display an HTML dialog to the user. The |
28 // content of the dialogs is determined by the delegate | 32 // content of the dialogs is determined by the delegate |
29 // (HtmlDialogUIDelegate), but is basically a file URL along with a | 33 // (HtmlDialogUIDelegate), but is basically a file URL along with a |
30 // JSON input string. The HTML is supposed to show a UI to the user and is | 34 // JSON input string. The HTML is supposed to show a UI to the user and is |
31 // expected to send back a JSON file as a return value. | 35 // expected to send back a JSON file as a return value. |
32 // | 36 // |
33 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
34 // | 38 // |
35 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate | 39 // TODO(akalin): Make HtmlDialogView contain an HtmlDialogTabContentsDelegate |
36 // instead of inheriting from it to avoid violating the "no multiple | 40 // instead of inheriting from it to avoid violating the "no multiple |
37 // inheritance" rule. | 41 // inheritance" rule. |
| 42 // TODO(beng): This class should not depend on Browser or Profile, only |
| 43 // content::BrowserContext. |
38 class HtmlDialogView | 44 class HtmlDialogView |
39 : public DOMView, | 45 : public views::View, |
40 public HtmlDialogTabContentsDelegate, | 46 public HtmlDialogTabContentsDelegate, |
41 public HtmlDialogUIDelegate, | 47 public HtmlDialogUIDelegate, |
42 public views::WidgetDelegate, | 48 public views::WidgetDelegate, |
43 public TabRenderWatcher::Delegate { | 49 public TabRenderWatcher::Delegate { |
44 public: | 50 public: |
45 HtmlDialogView(Profile* profile, | 51 HtmlDialogView(Profile* profile, |
46 Browser* browser, | 52 Browser* browser, |
47 HtmlDialogUIDelegate* delegate); | 53 HtmlDialogUIDelegate* delegate); |
48 virtual ~HtmlDialogView(); | 54 virtual ~HtmlDialogView(); |
49 | 55 |
50 // Initializes the contents of the dialog (the DOMView and the callbacks). | |
51 void InitDialog(); | |
52 | |
53 // Overridden from views::View: | 56 // Overridden from views::View: |
54 virtual gfx::Size GetPreferredSize() OVERRIDE; | 57 virtual gfx::Size GetPreferredSize() OVERRIDE; |
55 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) | 58 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) |
56 OVERRIDE; | 59 OVERRIDE; |
57 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child) | 60 virtual void ViewHierarchyChanged(bool is_add, |
58 OVERRIDE; | 61 views::View* parent, |
| 62 views::View* child) OVERRIDE; |
59 | 63 |
60 // Overridden from views::WidgetDelegate: | 64 // Overridden from views::WidgetDelegate: |
61 virtual bool CanResize() const OVERRIDE; | 65 virtual bool CanResize() const OVERRIDE; |
62 virtual ui::ModalType GetModalType() const OVERRIDE; | 66 virtual ui::ModalType GetModalType() const OVERRIDE; |
63 virtual string16 GetWindowTitle() const OVERRIDE; | 67 virtual string16 GetWindowTitle() const OVERRIDE; |
64 virtual std::string GetWindowName() const OVERRIDE; | 68 virtual std::string GetWindowName() const OVERRIDE; |
65 virtual void WindowClosing() OVERRIDE; | 69 virtual void WindowClosing() OVERRIDE; |
66 virtual views::View* GetContentsView() OVERRIDE; | 70 virtual views::View* GetContentsView() OVERRIDE; |
67 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | 71 virtual views::View* GetInitiallyFocusedView() OVERRIDE; |
68 virtual bool ShouldShowWindowTitle() const OVERRIDE; | 72 virtual bool ShouldShowWindowTitle() const OVERRIDE; |
(...skipping 26 matching lines...) Expand all Loading... |
95 content::WebContents* source, | 99 content::WebContents* source, |
96 const content::OpenURLParams& params) OVERRIDE; | 100 const content::OpenURLParams& params) OVERRIDE; |
97 virtual void AddNewContents(content::WebContents* source, | 101 virtual void AddNewContents(content::WebContents* source, |
98 content::WebContents* new_contents, | 102 content::WebContents* new_contents, |
99 WindowOpenDisposition disposition, | 103 WindowOpenDisposition disposition, |
100 const gfx::Rect& initial_pos, | 104 const gfx::Rect& initial_pos, |
101 bool user_gesture) OVERRIDE; | 105 bool user_gesture) OVERRIDE; |
102 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | 106 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; |
103 | 107 |
104 protected: | 108 protected: |
105 // Register accelerators for this dialog. | |
106 virtual void RegisterDialogAccelerators(); | |
107 | |
108 // TabRenderWatcher::Delegate implementation. | 109 // TabRenderWatcher::Delegate implementation. |
109 virtual void OnRenderHostCreated(content::RenderViewHost* host) OVERRIDE; | 110 virtual void OnRenderHostCreated(content::RenderViewHost* host) OVERRIDE; |
110 virtual void OnTabMainFrameLoaded() OVERRIDE; | 111 virtual void OnTabMainFrameLoaded() OVERRIDE; |
111 virtual void OnTabMainFrameRender() OVERRIDE; | 112 virtual void OnTabMainFrameRender() OVERRIDE; |
112 | 113 |
113 private: | 114 private: |
114 FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered); | 115 FRIEND_TEST_ALL_PREFIXES(HtmlDialogBrowserTest, WebContentRendered); |
115 | 116 |
116 // Whether the view is initialized. That is, dialog acceleartors is registered | 117 // Initializes the contents of the dialog. |
| 118 void InitDialog(); |
| 119 |
| 120 // Whether the view is initialized. That is, dialog accelerators is registered |
117 // and FreezeUpdates property is set to prevent WM from showing the window | 121 // and FreezeUpdates property is set to prevent WM from showing the window |
118 // until the property is removed. | 122 // until the property is removed. |
119 bool initialized_; | 123 bool initialized_; |
120 | 124 |
121 // Watches for WebContents rendering. | 125 // Watches for WebContents rendering. |
122 scoped_ptr<TabRenderWatcher> tab_watcher_; | 126 scoped_ptr<TabRenderWatcher> tab_watcher_; |
123 | 127 |
124 // This view is a delegate to the HTML content since it needs to get notified | 128 // This view is a delegate to the HTML content since it needs to get notified |
125 // about when the dialog is closing. For all other actions (besides dialog | 129 // about when the dialog is closing. For all other actions (besides dialog |
126 // closing) we delegate to the creator of this view, which we keep track of | 130 // closing) we delegate to the creator of this view, which we keep track of |
127 // using this variable. | 131 // using this variable. |
128 HtmlDialogUIDelegate* delegate_; | 132 HtmlDialogUIDelegate* delegate_; |
129 | 133 |
130 // Controls lifetime of dialog. | 134 // Controls lifetime of dialog. |
131 scoped_ptr<HtmlDialogController> dialog_controller_; | 135 scoped_ptr<HtmlDialogController> dialog_controller_; |
132 | 136 |
| 137 views::WebView* web_view_; |
| 138 |
133 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); | 139 DISALLOW_COPY_AND_ASSIGN(HtmlDialogView); |
134 }; | 140 }; |
135 | 141 |
136 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ | 142 #endif // CHROME_BROWSER_UI_VIEWS_HTML_DIALOG_VIEW_H_ |
OLD | NEW |