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. |
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. | |
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 = NULL; | |
Fady Samuel
2012/09/24 22:16:58
This makes this method a lot harder to read. Could
lazyboy
2012/09/25 17:57:22
Done.
| |
156 #if defined(OS_WIN) | |
157 // On Windows we need to duplicate the handle from the remote process. | |
158 HANDLE section; | |
159 DuplicateHandle(render_view_host()->GetProcess()->GetHandle(), | |
160 params.damage_buffer_id.handle, | |
161 GetCurrentProcess(), | |
162 §ion, | |
163 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE, | |
164 FALSE, 0); | |
165 damage_buffer = TransportDIB::Map(section); | |
166 #elif defined(OS_MACOSX) | |
167 // On OSX, the browser allocates all DIBs and keeps a file descriptor around | |
168 // for each. | |
169 damage_buffer = render_view_host()->GetProcess()-> | |
170 GetTransportDIB(params.damage_buffer_id); | |
171 #elif defined(OS_ANDROID) | |
172 damage_buffer = TransportDIB::Map(params.damage_buffer_id); | |
173 #elif defined(OS_POSIX) | |
174 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); | |
175 #endif // defined(OS_POSIX) | |
176 DCHECK(damage_buffer); | |
177 | |
147 guest->SetDamageBuffer(damage_buffer, | 178 guest->SetDamageBuffer(damage_buffer, |
148 #if defined(OS_WIN) | 179 #if defined(OS_WIN) |
149 damage_buffer_size, | 180 params.damage_buffer_size, |
150 #endif | 181 #endif |
151 gfx::Size(width, height), | 182 gfx::Size(params.width, params.height), |
152 scale_factor); | 183 params.scale_factor); |
153 if (!resize_pending) | 184 if (!params.resize_pending) { |
154 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); | 185 guest_web_contents->GetView()->SizeContents(gfx::Size(params.width, |
186 params.height)); | |
187 } | |
155 } | 188 } |
156 | 189 |
157 void BrowserPluginEmbedder::SetFocus(int instance_id, | 190 void BrowserPluginEmbedder::SetFocus(int instance_id, |
158 bool focused) { | 191 bool focused) { |
159 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 192 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
160 if (guest) | 193 if (guest) |
161 guest->SetFocus(focused); | 194 guest->SetFocus(focused); |
162 } | 195 } |
163 | 196 |
164 void BrowserPluginEmbedder::DestroyGuests() { | 197 void BrowserPluginEmbedder::DestroyGuests() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 bool visible = *Details<bool>(details).ptr(); | 268 bool visible = *Details<bool>(details).ptr(); |
236 WebContentsVisibilityChanged(visible); | 269 WebContentsVisibilityChanged(visible); |
237 break; | 270 break; |
238 } | 271 } |
239 default: | 272 default: |
240 NOTREACHED() << "Unexpected notification type: " << type; | 273 NOTREACHED() << "Unexpected notification type: " << type; |
241 } | 274 } |
242 } | 275 } |
243 | 276 |
244 } // namespace content | 277 } // namespace content |
OLD | NEW |