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 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h" |
13 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/common/browser_plugin_messages.h" | |
17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
20 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/web_contents_view.h" | 22 #include "content/public/browser/web_contents_view.h" |
22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
24 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
25 #include "ui/surface/transport_dib.h" | 26 #include "ui/surface/transport_dib.h" |
26 | 27 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 71 } |
71 | 72 |
72 void BrowserPluginEmbedder::AddGuest(int instance_id, | 73 void BrowserPluginEmbedder::AddGuest(int instance_id, |
73 WebContents* guest_web_contents, | 74 WebContents* guest_web_contents, |
74 int64 frame_id) { | 75 int64 frame_id) { |
75 DCHECK(guest_web_contents_by_instance_id_.find(instance_id) == | 76 DCHECK(guest_web_contents_by_instance_id_.find(instance_id) == |
76 guest_web_contents_by_instance_id_.end()); | 77 guest_web_contents_by_instance_id_.end()); |
77 guest_web_contents_by_instance_id_[instance_id] = guest_web_contents; | 78 guest_web_contents_by_instance_id_[instance_id] = guest_web_contents; |
78 } | 79 } |
79 | 80 |
80 void BrowserPluginEmbedder::NavigateGuest(RenderViewHost* render_view_host, | 81 void BrowserPluginEmbedder::NavigateGuest( |
81 int instance_id, | 82 RenderViewHost* render_view_host, |
82 int64 frame_id, | 83 int instance_id, |
83 const std::string& src, | 84 int64 frame_id, |
84 const gfx::Size& size) { | 85 const std::string& src, |
86 const BrowserPluginHostMsg_ResizeGuest_Params& resize_params) { | |
85 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 87 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
86 WebContentsImpl* guest_web_contents = NULL; | 88 WebContentsImpl* guest_web_contents = NULL; |
87 GURL url(src); | 89 GURL url(src); |
88 if (!guest) { | 90 if (!guest) { |
89 const std::string& host = | 91 const std::string& host = |
90 render_view_host->GetSiteInstance()->GetSite().host(); | 92 render_view_host->GetSiteInstance()->GetSite().host(); |
91 guest_web_contents = WebContentsImpl::CreateGuest( | 93 guest_web_contents = WebContentsImpl::CreateGuest( |
92 web_contents()->GetBrowserContext(), | 94 web_contents()->GetBrowserContext(), |
93 host, | 95 host, |
94 instance_id); | 96 instance_id); |
(...skipping 16 matching lines...) Expand all Loading... | |
111 // non-empty page, the action is considered no-op. | 113 // non-empty page, the action is considered no-op. |
112 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty | 114 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty |
113 // src ignoring in the shadow DOM element: http://crbug.com/149001. | 115 // src ignoring in the shadow DOM element: http://crbug.com/149001. |
114 if (!src.empty()) { | 116 if (!src.empty()) { |
115 guest_web_contents->GetController().LoadURL(url, | 117 guest_web_contents->GetController().LoadURL(url, |
116 Referrer(), | 118 Referrer(), |
117 PAGE_TRANSITION_AUTO_SUBFRAME, | 119 PAGE_TRANSITION_AUTO_SUBFRAME, |
118 std::string()); | 120 std::string()); |
119 } | 121 } |
120 | 122 |
121 if (!size.IsEmpty()) | 123 // Resize the guest if the resize parameter was set from the renderer. |
122 guest_web_contents->GetView()->SizeContents(size); | 124 ResizeGuest(instance_id, resize_params); |
123 } | 125 } |
124 | 126 |
125 void BrowserPluginEmbedder::UpdateRectACK(int instance_id, | 127 void BrowserPluginEmbedder::UpdateRectACK(int instance_id, |
126 int message_id, | 128 int message_id, |
127 const gfx::Size& size) { | 129 const gfx::Size& size) { |
128 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 130 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
129 if (guest) | 131 if (guest) |
130 guest->UpdateRectACK(message_id, size); | 132 guest->UpdateRectACK(message_id, size); |
131 } | 133 } |
132 | 134 |
133 void BrowserPluginEmbedder::ResizeGuest(int instance_id, | 135 void BrowserPluginEmbedder::ResizeGuest( |
134 TransportDIB* damage_buffer, | 136 int instance_id, |
135 #if defined(OS_WIN) | 137 const BrowserPluginHostMsg_ResizeGuest_Params& params) { |
136 int damage_buffer_size, | 138 // TODO(fsamuel): Schedule this later so that we don't stall the embedder for |
137 #endif | 139 // too long. |
Charlie Reis
2012/09/25 22:44:24
How would you delay the ResizeGuest? Would that r
Fady Samuel
2012/09/25 22:49:38
This TODO is outdated actually. SetDamageBuffer ne
lazyboy
2012/09/25 23:15:30
Removed the TODO.
On 2012/09/25 22:49:38, Fady
| |
138 int width, | |
139 int height, | |
140 bool resize_pending, | |
141 float scale_factor) { | |
142 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 140 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
143 if (!guest) | 141 if (!guest) |
144 return; | 142 return; |
145 WebContentsImpl* guest_web_contents = | 143 WebContentsImpl* guest_web_contents = |
146 static_cast<WebContentsImpl*>(guest->GetWebContents()); | 144 static_cast<WebContentsImpl*>(guest->GetWebContents()); |
145 | |
146 if (!TransportDIB::is_valid_id(params.damage_buffer_id)) { | |
147 // Invalid transport dib, just resize the WebContents. | |
Charlie Reis
2012/09/25 22:44:24
nit: so just
lazyboy
2012/09/25 23:15:30
Done.
| |
148 if (params.width && params.height) { | |
149 guest_web_contents->GetView()->SizeContents(gfx::Size(params.width, | |
150 params.height)); | |
151 } | |
152 return; | |
153 } | |
154 | |
155 TransportDIB* damage_buffer = GetDamageBuffer(params.damage_buffer_id); | |
147 guest->SetDamageBuffer(damage_buffer, | 156 guest->SetDamageBuffer(damage_buffer, |
148 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
149 damage_buffer_size, | 158 params.damage_buffer_size, |
150 #endif | 159 #endif |
151 gfx::Size(width, height), | 160 gfx::Size(params.width, params.height), |
152 scale_factor); | 161 params.scale_factor); |
153 if (!resize_pending) | 162 if (!params.resize_pending) { |
154 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); | 163 guest_web_contents->GetView()->SizeContents(gfx::Size(params.width, |
164 params.height)); | |
165 } | |
166 } | |
167 | |
168 TransportDIB* BrowserPluginEmbedder::GetDamageBuffer( | |
169 const TransportDIB::Id& damage_buffer_id) { | |
170 TransportDIB* damage_buffer = NULL; | |
171 #if defined(OS_WIN) | |
172 // On Windows we need to duplicate the handle from the remote process. | |
173 HANDLE section; | |
174 DuplicateHandle(render_view_host()->GetProcess()->GetHandle(), | |
175 damage_buffer_id.handle, | |
176 GetCurrentProcess(), | |
177 §ion, | |
178 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE, | |
179 FALSE, | |
180 0); | |
181 damage_buffer = TransportDIB::Map(section); | |
182 #elif defined(OS_MACOSX) | |
183 // On OSX, the browser allocates all DIBs and keeps a file descriptor around | |
184 // for each. | |
185 damage_buffer = render_view_host()->GetProcess()-> | |
186 GetTransportDIB(damage_buffer_id); | |
187 #elif defined(OS_ANDROID) | |
188 damage_buffer = TransportDIB::Map(damage_buffer_id); | |
189 #elif defined(OS_POSIX) | |
190 damage_buffer = TransportDIB::Map(damage_buffer_id.shmkey); | |
191 #endif // defined(OS_POSIX) | |
192 DCHECK(damage_buffer); | |
193 return damage_buffer; | |
155 } | 194 } |
156 | 195 |
157 void BrowserPluginEmbedder::SetFocus(int instance_id, | 196 void BrowserPluginEmbedder::SetFocus(int instance_id, |
158 bool focused) { | 197 bool focused) { |
159 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 198 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
160 if (guest) | 199 if (guest) |
161 guest->SetFocus(focused); | 200 guest->SetFocus(focused); |
162 } | 201 } |
163 | 202 |
164 void BrowserPluginEmbedder::DestroyGuests() { | 203 void BrowserPluginEmbedder::DestroyGuests() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 bool visible = *Details<bool>(details).ptr(); | 274 bool visible = *Details<bool>(details).ptr(); |
236 WebContentsVisibilityChanged(visible); | 275 WebContentsVisibilityChanged(visible); |
237 break; | 276 break; |
238 } | 277 } |
239 default: | 278 default: |
240 NOTREACHED() << "Unexpected notification type: " << type; | 279 NOTREACHED() << "Unexpected notification type: " << type; |
241 } | 280 } |
242 } | 281 } |
243 | 282 |
244 } // namespace content | 283 } // namespace content |
OLD | NEW |