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/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
12 #include "content/public/browser/web_contents_delegate.h" | 12 #include "content/public/browser/web_contents_delegate.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
13 #include "ui/views/accessibility/native_view_accessibility.h" | 14 #include "ui/views/accessibility/native_view_accessibility.h" |
14 #include "ui/views/controls/webview/webview_export.h" | 15 #include "ui/views/controls/webview/webview_export.h" |
15 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class SiteInstance; | 19 class SiteInstance; |
19 } | 20 } |
20 | 21 |
21 namespace views { | 22 namespace views { |
22 | 23 |
23 class NativeViewHost; | 24 class NativeViewHost; |
24 | 25 |
25 class WEBVIEW_EXPORT WebView : public View, | 26 class WEBVIEW_EXPORT WebView : public View, |
26 public content::NotificationObserver, | 27 public content::NotificationObserver, |
27 public content::WebContentsDelegate { | 28 public content::WebContentsDelegate, |
| 29 public content::WebContentsObserver { |
28 public: | 30 public: |
29 static const char kViewClassName[]; | 31 static const char kViewClassName[]; |
30 | 32 |
31 explicit WebView(content::BrowserContext* browser_context); | 33 explicit WebView(content::BrowserContext* browser_context); |
32 virtual ~WebView(); | 34 virtual ~WebView(); |
33 | 35 |
34 // This creates a WebContents if none is yet associated with this WebView. The | 36 // This creates a WebContents if none is yet associated with this WebView. The |
35 // WebView owns this implicitly created WebContents. | 37 // WebView owns this implicitly created WebContents. |
36 content::WebContents* GetWebContents(); | 38 content::WebContents* GetWebContents(); |
37 | 39 |
38 // Creates a WebContents if none is yet assocaited with this WebView, with the | 40 // Creates a WebContents if none is yet assocaited with this WebView, with the |
39 // specified site instance. The WebView owns this WebContents. | 41 // specified site instance. The WebView owns this WebContents. |
40 void CreateWebContentsWithSiteInstance(content::SiteInstance* site_instance); | 42 void CreateWebContentsWithSiteInstance(content::SiteInstance* site_instance); |
41 | 43 |
42 // WebView does not assume ownership of WebContents set via this method, only | 44 // WebView does not assume ownership of WebContents set via this method, only |
43 // those it implicitly creates via GetWebContents() above. | 45 // those it implicitly creates via GetWebContents() above. |
44 void SetWebContents(content::WebContents* web_contents); | 46 void SetWebContents(content::WebContents* web_contents); |
45 | 47 |
| 48 // If |mode| is true, WebView will register itself with WebContents as a |
| 49 // WebContentsObserver, monitor for the showing/destruction of fullscreen |
| 50 // render widgets, and alter its child view hierarchy to embed the fullscreen |
| 51 // widget or restore the normal WebContentsView. |
| 52 void SetEmbedFullscreenWidgetMode(bool mode); |
| 53 |
46 content::WebContents* web_contents() { return web_contents_; } | 54 content::WebContents* web_contents() { return web_contents_; } |
47 | 55 |
48 content::BrowserContext* browser_context() { return browser_context_; } | 56 content::BrowserContext* browser_context() { return browser_context_; } |
49 | 57 |
50 // Loads the initial URL to display in the attached WebContents. Creates the | 58 // Loads the initial URL to display in the attached WebContents. Creates the |
51 // WebContents if none is attached yet. Note that this is intended as a | 59 // WebContents if none is attached yet. Note that this is intended as a |
52 // convenience for loading the initial URL, and so URLs are navigated with | 60 // convenience for loading the initial URL, and so URLs are navigated with |
53 // PAGE_TRANSITION_AUTO_TOPLEVEL, so this is not intended as a general purpose | 61 // PAGE_TRANSITION_AUTO_TOPLEVEL, so this is not intended as a general purpose |
54 // navigation method - use WebContents' API directly. | 62 // navigation method - use WebContents' API directly. |
55 void LoadInitialURL(const GURL& url); | 63 void LoadInitialURL(const GURL& url); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; | 104 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; |
97 virtual gfx::Size GetPreferredSize() OVERRIDE; | 105 virtual gfx::Size GetPreferredSize() OVERRIDE; |
98 | 106 |
99 // Overridden from content::NotificationObserver: | 107 // Overridden from content::NotificationObserver: |
100 virtual void Observe(int type, | 108 virtual void Observe(int type, |
101 const content::NotificationSource& source, | 109 const content::NotificationSource& source, |
102 const content::NotificationDetails& details) OVERRIDE; | 110 const content::NotificationDetails& details) OVERRIDE; |
103 | 111 |
104 // Overridden from content::WebContentsDelegate: | 112 // Overridden from content::WebContentsDelegate: |
105 virtual void WebContentsFocused(content::WebContents* web_contents) OVERRIDE; | 113 virtual void WebContentsFocused(content::WebContents* web_contents) OVERRIDE; |
| 114 virtual bool EmbedsFullscreenWidget() const OVERRIDE; |
| 115 |
| 116 // Overridden from content::WebContentsObserver: |
| 117 virtual void DidShowFullscreenWidget(int routing_id) OVERRIDE; |
| 118 virtual void DidDestroyFullscreenWidget(int routing_id) OVERRIDE; |
| 119 // Workaround for MSVC++ linker bug/feature that requires |
| 120 // instantiation of the inline IPC::Listener methods in all translation units. |
| 121 virtual void OnChannelConnected(int32 peer_id) OVERRIDE {} |
| 122 virtual void OnChannelError() OVERRIDE {} |
106 | 123 |
107 void AttachWebContents(); | 124 void AttachWebContents(); |
108 void DetachWebContents(); | 125 void DetachWebContents(); |
109 | 126 void ReattachForFullscreenChange(bool enter_fullscreen); |
110 void RenderViewHostChanged(content::RenderViewHost* old_host, | |
111 content::RenderViewHost* new_host); | |
112 void WebContentsDestroyed(content::WebContents* web_contents); | |
113 | 127 |
114 // Create a regular or test web contents (based on whether we're running | 128 // Create a regular or test web contents (based on whether we're running |
115 // in a unit test or not). | 129 // in a unit test or not). |
116 content::WebContents* CreateWebContents( | 130 content::WebContents* CreateWebContents( |
117 content::BrowserContext* browser_context, | 131 content::BrowserContext* browser_context, |
118 content::SiteInstance* site_instance); | 132 content::SiteInstance* site_instance); |
119 | 133 |
120 NativeViewHost* wcv_holder_; | 134 NativeViewHost* wcv_holder_; |
121 scoped_ptr<content::WebContents> wc_owner_; | 135 scoped_ptr<content::WebContents> wc_owner_; |
122 content::WebContents* web_contents_; | 136 content::WebContents* web_contents_; |
| 137 // When true, WebView observes WebContents and auto-embeds fullscreen widgets |
| 138 // as a child view. |
| 139 bool embed_fullscreen_widget_mode_enabled_; |
| 140 // Set to true while WebView is embedding a fullscreen widget view as a child |
| 141 // view instead of the normal WebContentsView render view. |
| 142 bool is_embedding_fullscreen_widget_; |
123 content::BrowserContext* browser_context_; | 143 content::BrowserContext* browser_context_; |
124 content::NotificationRegistrar registrar_; | 144 content::NotificationRegistrar registrar_; |
125 bool allow_accelerators_; | 145 bool allow_accelerators_; |
126 gfx::Size preferred_size_; | 146 gfx::Size preferred_size_; |
127 | 147 |
128 DISALLOW_COPY_AND_ASSIGN(WebView); | 148 DISALLOW_COPY_AND_ASSIGN(WebView); |
129 }; | 149 }; |
130 | 150 |
131 } // namespace views | 151 } // namespace views |
132 | 152 |
133 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 153 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
OLD | NEW |