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 UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 5 #ifndef UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
6 #define UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 6 #define UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "content/public/browser/web_contents_delegate.h" | 10 #include "content/public/browser/web_contents_delegate.h" |
11 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
12 #include "ui/views/accessibility/native_view_accessibility.h" | 12 #include "ui/views/accessibility/native_view_accessibility.h" |
13 #include "ui/views/controls/webview/webview_export.h" | 13 #include "ui/views/controls/webview/webview_export.h" |
14 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
15 | 15 |
16 namespace content { | |
17 class SiteInstance; | |
18 } | |
19 | |
20 namespace views { | 16 namespace views { |
21 | 17 |
22 class NativeViewHost; | 18 class NativeViewHost; |
23 | 19 |
24 class WEBVIEW_EXPORT WebView : public View, | 20 class WEBVIEW_EXPORT WebView : public View, |
25 public content::WebContentsDelegate, | 21 public content::WebContentsDelegate, |
26 public content::WebContentsObserver { | 22 public content::WebContentsObserver { |
27 public: | 23 public: |
28 static const char kViewClassName[]; | 24 static const char kViewClassName[]; |
29 | 25 |
30 explicit WebView(content::BrowserContext* browser_context); | 26 explicit WebView(content::BrowserContext* browser_context); |
31 virtual ~WebView(); | 27 virtual ~WebView(); |
32 | 28 |
33 // This creates a WebContents if none is yet associated with this WebView. The | 29 // This creates a WebContents if none is yet associated with this WebView. The |
34 // WebView owns this implicitly created WebContents. | 30 // WebView owns this implicitly created WebContents. |
35 content::WebContents* GetWebContents(); | 31 content::WebContents* GetWebContents(); |
36 | 32 |
37 // Creates a WebContents if none is yet assocaited with this WebView, with the | |
38 // specified site instance. The WebView owns this WebContents. | |
39 void CreateWebContentsWithSiteInstance(content::SiteInstance* site_instance); | |
40 | |
41 // WebView does not assume ownership of WebContents set via this method, only | 33 // WebView does not assume ownership of WebContents set via this method, only |
42 // those it implicitly creates via GetWebContents() above. | 34 // those it implicitly creates via GetWebContents() above. |
43 void SetWebContents(content::WebContents* web_contents); | 35 void SetWebContents(content::WebContents* web_contents); |
44 | 36 |
45 // If |mode| is true, WebView will register itself with WebContents as a | 37 // If |mode| is true, WebView will register itself with WebContents as a |
46 // WebContentsObserver, monitor for the showing/destruction of fullscreen | 38 // WebContentsObserver, monitor for the showing/destruction of fullscreen |
47 // render widgets, and alter its child view hierarchy to embed the fullscreen | 39 // render widgets, and alter its child view hierarchy to embed the fullscreen |
48 // widget or restore the normal WebContentsView. | 40 // widget or restore the normal WebContentsView. |
49 void SetEmbedFullscreenWidgetMode(bool mode); | 41 void SetEmbedFullscreenWidgetMode(bool mode); |
50 | 42 |
51 content::WebContents* web_contents() { return web_contents_; } | 43 content::WebContents* web_contents() const { |
| 44 return content::WebContentsObserver::web_contents(); |
| 45 } |
52 | 46 |
53 content::BrowserContext* browser_context() { return browser_context_; } | 47 content::BrowserContext* browser_context() { return browser_context_; } |
54 | 48 |
55 // Loads the initial URL to display in the attached WebContents. Creates the | 49 // Loads the initial URL to display in the attached WebContents. Creates the |
56 // WebContents if none is attached yet. Note that this is intended as a | 50 // WebContents if none is attached yet. Note that this is intended as a |
57 // convenience for loading the initial URL, and so URLs are navigated with | 51 // convenience for loading the initial URL, and so URLs are navigated with |
58 // PAGE_TRANSITION_AUTO_TOPLEVEL, so this is not intended as a general purpose | 52 // PAGE_TRANSITION_AUTO_TOPLEVEL, so this is not intended as a general purpose |
59 // navigation method - use WebContents' API directly. | 53 // navigation method - use WebContents' API directly. |
60 void LoadInitialURL(const GURL& url); | 54 void LoadInitialURL(const GURL& url); |
61 | 55 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 virtual void OnChannelConnected(int32 peer_id) OVERRIDE {} | 112 virtual void OnChannelConnected(int32 peer_id) OVERRIDE {} |
119 virtual void OnChannelError() OVERRIDE {} | 113 virtual void OnChannelError() OVERRIDE {} |
120 | 114 |
121 void AttachWebContents(); | 115 void AttachWebContents(); |
122 void DetachWebContents(); | 116 void DetachWebContents(); |
123 void ReattachForFullscreenChange(bool enter_fullscreen); | 117 void ReattachForFullscreenChange(bool enter_fullscreen); |
124 | 118 |
125 // Create a regular or test web contents (based on whether we're running | 119 // Create a regular or test web contents (based on whether we're running |
126 // in a unit test or not). | 120 // in a unit test or not). |
127 content::WebContents* CreateWebContents( | 121 content::WebContents* CreateWebContents( |
128 content::BrowserContext* browser_context, | 122 content::BrowserContext* browser_context); |
129 content::SiteInstance* site_instance); | |
130 | 123 |
131 NativeViewHost* wcv_holder_; | 124 NativeViewHost* wcv_holder_; |
| 125 // Non-NULL if |web_contents()| was created and is owned by this WebView. |
132 scoped_ptr<content::WebContents> wc_owner_; | 126 scoped_ptr<content::WebContents> wc_owner_; |
133 content::WebContents* web_contents_; | |
134 // When true, WebView auto-embeds fullscreen widgets as a child view. | 127 // When true, WebView auto-embeds fullscreen widgets as a child view. |
135 bool embed_fullscreen_widget_mode_enabled_; | 128 bool embed_fullscreen_widget_mode_enabled_; |
136 // Set to true while WebView is embedding a fullscreen widget view as a child | 129 // Set to true while WebView is embedding a fullscreen widget view as a child |
137 // view instead of the normal WebContentsView render view. | 130 // view instead of the normal WebContentsView render view. |
138 bool is_embedding_fullscreen_widget_; | 131 bool is_embedding_fullscreen_widget_; |
139 content::BrowserContext* browser_context_; | 132 content::BrowserContext* browser_context_; |
140 bool allow_accelerators_; | 133 bool allow_accelerators_; |
141 gfx::Size preferred_size_; | 134 gfx::Size preferred_size_; |
142 | 135 |
143 DISALLOW_COPY_AND_ASSIGN(WebView); | 136 DISALLOW_COPY_AND_ASSIGN(WebView); |
144 }; | 137 }; |
145 | 138 |
146 } // namespace views | 139 } // namespace views |
147 | 140 |
148 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 141 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
OLD | NEW |