Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder.cc

Issue 10965048: [BrowserTag] Send dib info with NavigateGuest message, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync @tott, correct rebase, bring back two lost comments from previous rounds Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return NULL; 70 return NULL;
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 DCHECK(guest_web_contents_by_instance_id_.find(instance_id) == 75 DCHECK(guest_web_contents_by_instance_id_.find(instance_id) ==
75 guest_web_contents_by_instance_id_.end()); 76 guest_web_contents_by_instance_id_.end());
76 guest_web_contents_by_instance_id_[instance_id] = guest_web_contents; 77 guest_web_contents_by_instance_id_[instance_id] = guest_web_contents;
77 } 78 }
78 79
79 void BrowserPluginEmbedder::NavigateGuest(RenderViewHost* render_view_host, 80 void BrowserPluginEmbedder::NavigateGuest(
80 int instance_id, 81 RenderViewHost* render_view_host,
81 const std::string& src, 82 int instance_id,
82 const gfx::Size& size) { 83 const std::string& src,
84 const BrowserPluginHostMsg_ResizeGuest_Params& resize_params) {
83 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); 85 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
84 WebContentsImpl* guest_web_contents = NULL; 86 WebContentsImpl* guest_web_contents = NULL;
85 GURL url(src); 87 GURL url(src);
86 if (!guest) { 88 if (!guest) {
87 const std::string& host = 89 const std::string& host =
88 render_view_host->GetSiteInstance()->GetSiteURL().host(); 90 render_view_host->GetSiteInstance()->GetSiteURL().host();
89 guest_web_contents = WebContentsImpl::CreateGuest( 91 guest_web_contents = WebContentsImpl::CreateGuest(
90 web_contents()->GetBrowserContext(), 92 web_contents()->GetBrowserContext(),
91 host, 93 host,
92 instance_id); 94 instance_id);
(...skipping 25 matching lines...) Expand all
118 // non-empty page, the action is considered no-op. 120 // non-empty page, the action is considered no-op.
119 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty 121 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty
120 // src ignoring in the shadow DOM element: http://crbug.com/149001. 122 // src ignoring in the shadow DOM element: http://crbug.com/149001.
121 if (!src.empty()) { 123 if (!src.empty()) {
122 guest_web_contents->GetController().LoadURL(url, 124 guest_web_contents->GetController().LoadURL(url,
123 Referrer(), 125 Referrer(),
124 PAGE_TRANSITION_AUTO_SUBFRAME, 126 PAGE_TRANSITION_AUTO_SUBFRAME,
125 std::string()); 127 std::string());
126 } 128 }
127 129
128 if (!size.IsEmpty()) 130 // Resize the guest if the resize parameter was set from the renderer.
129 guest_web_contents->GetView()->SizeContents(size); 131 ResizeGuest(render_view_host, instance_id, resize_params);
130 } 132 }
131 133
132 void BrowserPluginEmbedder::UpdateRectACK(int instance_id, 134 void BrowserPluginEmbedder::UpdateRectACK(int instance_id,
133 int message_id, 135 int message_id,
134 const gfx::Size& size) { 136 const gfx::Size& size) {
135 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); 137 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
136 if (guest) 138 if (guest)
137 guest->UpdateRectACK(message_id, size); 139 guest->UpdateRectACK(message_id, size);
138 } 140 }
139 141
140 void BrowserPluginEmbedder::ResizeGuest(int instance_id, 142 void BrowserPluginEmbedder::ResizeGuest(
141 TransportDIB* damage_buffer, 143 RenderViewHost* render_view_host,
142 #if defined(OS_WIN) 144 int instance_id,
143 int damage_buffer_size, 145 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
144 #endif
145 int width,
146 int height,
147 bool resize_pending,
148 float scale_factor) {
149 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); 146 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
150 if (!guest) 147 if (!guest)
151 return; 148 return;
152 WebContentsImpl* guest_web_contents = 149 WebContentsImpl* guest_web_contents =
153 static_cast<WebContentsImpl*>(guest->GetWebContents()); 150 static_cast<WebContentsImpl*>(guest->GetWebContents());
151
152 if (!TransportDIB::is_valid_id(params.damage_buffer_id)) {
153 // Invalid transport dib, so just resize the WebContents.
154 if (params.width && params.height) {
155 guest_web_contents->GetView()->SizeContents(gfx::Size(params.width,
156 params.height));
157 }
158 return;
159 }
160
161 TransportDIB* damage_buffer = GetDamageBuffer(render_view_host, params);
154 guest->SetDamageBuffer(damage_buffer, 162 guest->SetDamageBuffer(damage_buffer,
155 #if defined(OS_WIN) 163 #if defined(OS_WIN)
156 damage_buffer_size, 164 params.damage_buffer_size,
157 #endif 165 #endif
158 gfx::Size(width, height), 166 gfx::Size(params.width, params.height),
159 scale_factor); 167 params.scale_factor);
160 if (!resize_pending) 168 if (!params.resize_pending) {
161 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); 169 guest_web_contents->GetView()->SizeContents(gfx::Size(params.width,
170 params.height));
171 }
172 }
173
174 TransportDIB* BrowserPluginEmbedder::GetDamageBuffer(
175 RenderViewHost* render_view_host,
176 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
177 TransportDIB* damage_buffer = NULL;
178 #if defined(OS_WIN)
179 // On Windows we need to duplicate the handle from the remote process.
180 HANDLE section;
181 DuplicateHandle(render_view_host->GetProcess()->GetHandle(),
182 params.damage_buffer_id.handle,
183 GetCurrentProcess(),
184 &section,
185 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE,
186 FALSE,
187 0);
188 damage_buffer = TransportDIB::Map(section);
189 #elif defined(OS_MACOSX)
190 // On OSX, we need the handle to map the transport dib.
191 damage_buffer = TransportDIB::Map(params.damage_buffer_handle);
192 #elif defined(OS_ANDROID)
193 damage_buffer = TransportDIB::Map(params.damage_buffer_id);
194 #elif defined(OS_POSIX)
195 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey);
196 #endif // defined(OS_POSIX)
197 DCHECK(damage_buffer);
198 return damage_buffer;
162 } 199 }
163 200
164 void BrowserPluginEmbedder::SetFocus(int instance_id, 201 void BrowserPluginEmbedder::SetFocus(int instance_id,
165 bool focused) { 202 bool focused) {
166 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); 203 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
167 if (guest) 204 if (guest)
168 guest->SetFocus(focused); 205 guest->SetFocus(focused);
169 } 206 }
170 207
171 void BrowserPluginEmbedder::DestroyGuests() { 208 void BrowserPluginEmbedder::DestroyGuests() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 bool visible = *Details<bool>(details).ptr(); 285 bool visible = *Details<bool>(details).ptr();
249 WebContentsVisibilityChanged(visible); 286 WebContentsVisibilityChanged(visible);
250 break; 287 break;
251 } 288 }
252 default: 289 default:
253 NOTREACHED() << "Unexpected notification type: " << type; 290 NOTREACHED() << "Unexpected notification type: " << type;
254 } 291 }
255 } 292 }
256 293
257 } // namespace content 294 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698