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

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

Issue 299753011: Move allocate instance id to chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove debug logs Created 6 years, 6 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
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_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 OnExecuteEditCommand) 133 OnExecuteEditCommand)
134 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, 134 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete,
135 OnExtendSelectionAndDelete) 135 OnExtendSelectionAndDelete)
136 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, 136 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
137 OnHandleInputEvent) 137 OnHandleInputEvent)
138 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, 138 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition,
139 OnImeConfirmComposition) 139 OnImeConfirmComposition)
140 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, 140 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition,
141 OnImeSetComposition) 141 OnImeSetComposition)
142 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) 142 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck)
143 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest)
144 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) 143 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed)
145 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, 144 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources,
146 OnReclaimCompositorResources) 145 OnReclaimCompositorResources)
147 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) 146 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
148 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) 147 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize)
149 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, 148 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent,
150 OnSetEditCommandsForNextKeyEvent) 149 OnSetEditCommandsForNextKeyEvent)
151 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) 150 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
152 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetContentsOpaque, 151 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetContentsOpaque,
153 OnSetContentsOpaque) 152 OnSetContentsOpaque)
154 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) 153 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
155 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) 154 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
156 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) 155 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
157 IPC_MESSAGE_UNHANDLED(handled = false) 156 IPC_MESSAGE_UNHANDLED(handled = false)
158 IPC_END_MESSAGE_MAP() 157 IPC_END_MESSAGE_MAP()
159 return handled; 158 return handled;
160 } 159 }
161 160
162 void BrowserPluginGuest::Initialize( 161 void BrowserPluginGuest::Initialize(
163 const BrowserPluginHostMsg_Attach_Params& params, 162 const BrowserPluginHostMsg_Attach_Params& params,
164 WebContentsImpl* embedder_web_contents) { 163 WebContentsImpl* embedder_web_contents,
164 const base::DictionaryValue& extra_params) {
165 focused_ = params.focused; 165 focused_ = params.focused;
166 guest_visible_ = params.visible; 166 guest_visible_ = params.visible;
167 guest_opaque_ = params.opaque; 167 guest_opaque_ = params.opaque;
168 guest_window_rect_ = params.resize_guest_params.view_rect; 168 guest_window_rect_ = params.resize_guest_params.view_rect;
169 169
170 auto_size_enabled_ = params.auto_size_params.enable; 170 auto_size_enabled_ = params.auto_size_params.enable;
171 max_auto_size_ = params.auto_size_params.max_size; 171 max_auto_size_ = params.auto_size_params.max_size;
172 min_auto_size_ = params.auto_size_params.min_size; 172 min_auto_size_ = params.auto_size_params.min_size;
173 173
174 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to 174 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 // Create a swapped out RenderView for the guest in the embedder render 208 // Create a swapped out RenderView for the guest in the embedder render
209 // process, so that the embedder can access the guest's window object. 209 // process, so that the embedder can access the guest's window object.
210 int guest_routing_id = 210 int guest_routing_id =
211 GetWebContents()->CreateSwappedOutRenderView( 211 GetWebContents()->CreateSwappedOutRenderView(
212 embedder_web_contents_->GetSiteInstance()); 212 embedder_web_contents_->GetSiteInstance());
213 SendMessageToEmbedder( 213 SendMessageToEmbedder(
214 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, 214 new BrowserPluginMsg_GuestContentWindowReady(instance_id_,
215 guest_routing_id)); 215 guest_routing_id));
216 216
217 if (!params.src.empty()) {
218 // params.src will be validated in BrowserPluginGuest::OnNavigateGuest.
219 OnNavigateGuest(instance_id_, params.src);
220 has_render_view_ = true;
221 }
222
223 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); 217 WebPreferences prefs = GetWebContents()->GetWebkitPrefs();
224 prefs.navigate_on_drag_drop = false; 218 prefs.navigate_on_drag_drop = false;
225 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); 219 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
226 220
227 // Enable input method for guest if it's enabled for the embedder. 221 // Enable input method for guest if it's enabled for the embedder.
228 if (static_cast<RenderViewHostImpl*>( 222 if (static_cast<RenderViewHostImpl*>(
229 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { 223 embedder_web_contents_->GetRenderViewHost())->input_method_active()) {
230 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 224 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
231 GetWebContents()->GetRenderViewHost()); 225 GetWebContents()->GetRenderViewHost());
232 guest_rvh->SetInputMethodActive(true); 226 guest_rvh->SetInputMethodActive(true);
233 } 227 }
234 228
235 // Inform the embedder of the guest's information. 229 // Inform the embedder of the guest's attachment.
236 // We pull the partition information from the site's URL, which is of the form 230 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_));
237 // guest://site/{persist}?{partition_name}.
238 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL();
239 BrowserPluginMsg_Attach_ACK_Params ack_params;
240 ack_params.storage_partition_id = site_url.query();
241 ack_params.persist_storage =
242 site_url.path().find("persist") != std::string::npos;
243 SendMessageToEmbedder(
244 new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params));
245 231
246 if (delegate_) 232 if (delegate_) {
247 delegate_->DidAttach(); 233 delegate_->DidAttach(extra_params);
234 has_render_view_ = true;
235 }
248 } 236 }
249 237
250 BrowserPluginGuest::~BrowserPluginGuest() { 238 BrowserPluginGuest::~BrowserPluginGuest() {
251 while (!pending_messages_.empty()) {
252 delete pending_messages_.front();
253 pending_messages_.pop();
254 }
255 } 239 }
256 240
257 // static 241 // static
258 BrowserPluginGuest* BrowserPluginGuest::Create( 242 BrowserPluginGuest* BrowserPluginGuest::Create(
259 int instance_id, 243 int instance_id,
260 SiteInstance* guest_site_instance, 244 SiteInstance* guest_site_instance,
261 WebContentsImpl* web_contents, 245 WebContentsImpl* web_contents,
262 scoped_ptr<base::DictionaryValue> extra_params, 246 scoped_ptr<base::DictionaryValue> extra_params,
263 BrowserPluginGuest* opener) { 247 BrowserPluginGuest* opener) {
264 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 248 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 size.height() <= max_auto_size_.height(); 347 size.height() <= max_auto_size_.height();
364 } 348 }
365 349
366 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 350 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
367 if (!attached()) { 351 if (!attached()) {
368 // Some pages such as data URLs, javascript URLs, and about:blank 352 // Some pages such as data URLs, javascript URLs, and about:blank
369 // do not load external resources and so they load prior to attachment. 353 // do not load external resources and so they load prior to attachment.
370 // As a result, we must save all these IPCs until attachment and then 354 // As a result, we must save all these IPCs until attachment and then
371 // forward them so that the embedder gets a chance to see and process 355 // forward them so that the embedder gets a chance to see and process
372 // the load events. 356 // the load events.
373 pending_messages_.push(msg); 357 pending_messages_.push_back(linked_ptr<IPC::Message>(msg));
374 return; 358 return;
375 } 359 }
376 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); 360 msg->set_routing_id(embedder_web_contents_->GetRoutingID());
377 embedder_web_contents_->Send(msg); 361 embedder_web_contents_->Send(msg);
378 } 362 }
379 363
380 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, 364 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
381 int screen_x, int screen_y, blink::WebDragOperation operation) { 365 int screen_x, int screen_y, blink::WebDragOperation operation) {
382 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 366 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
383 screen_x, screen_y, operation); 367 screen_x, screen_y, operation);
384 } 368 }
385 369
386 void BrowserPluginGuest::EndSystemDrag() { 370 void BrowserPluginGuest::EndSystemDrag() {
387 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 371 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
388 GetWebContents()->GetRenderViewHost()); 372 GetWebContents()->GetRenderViewHost());
389 guest_rvh->DragSourceSystemDragEnded(); 373 guest_rvh->DragSourceSystemDragEnded();
390 } 374 }
391 375
392 void BrowserPluginGuest::SendQueuedMessages() { 376 void BrowserPluginGuest::SendQueuedMessages() {
393 if (!attached()) 377 if (!attached())
394 return; 378 return;
395 379
396 while (!pending_messages_.empty()) { 380 while (!pending_messages_.empty()) {
397 IPC::Message* message = pending_messages_.front(); 381 linked_ptr<IPC::Message> message_ptr = pending_messages_.front();
398 pending_messages_.pop(); 382 pending_messages_.pop_front();
399 SendMessageToEmbedder(message); 383 SendMessageToEmbedder(message_ptr.release());
400 } 384 }
401 } 385 }
402 386
403 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( 387 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame(
404 int64 frame_id, 388 int64 frame_id,
405 const base::string16& frame_unique_name, 389 const base::string16& frame_unique_name,
406 bool is_main_frame, 390 bool is_main_frame,
407 const GURL& url, 391 const GURL& url,
408 PageTransition transition_type, 392 PageTransition transition_type,
409 RenderViewHost* render_view_host) { 393 RenderViewHost* render_view_host) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 switch (message.type()) { 435 switch (message.type()) {
452 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: 436 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID:
453 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID: 437 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID:
454 case BrowserPluginHostMsg_DragStatusUpdate::ID: 438 case BrowserPluginHostMsg_DragStatusUpdate::ID:
455 case BrowserPluginHostMsg_ExecuteEditCommand::ID: 439 case BrowserPluginHostMsg_ExecuteEditCommand::ID:
456 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: 440 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID:
457 case BrowserPluginHostMsg_HandleInputEvent::ID: 441 case BrowserPluginHostMsg_HandleInputEvent::ID:
458 case BrowserPluginHostMsg_ImeConfirmComposition::ID: 442 case BrowserPluginHostMsg_ImeConfirmComposition::ID:
459 case BrowserPluginHostMsg_ImeSetComposition::ID: 443 case BrowserPluginHostMsg_ImeSetComposition::ID:
460 case BrowserPluginHostMsg_LockMouse_ACK::ID: 444 case BrowserPluginHostMsg_LockMouse_ACK::ID:
461 case BrowserPluginHostMsg_NavigateGuest::ID:
462 case BrowserPluginHostMsg_PluginDestroyed::ID: 445 case BrowserPluginHostMsg_PluginDestroyed::ID:
463 case BrowserPluginHostMsg_ReclaimCompositorResources::ID: 446 case BrowserPluginHostMsg_ReclaimCompositorResources::ID:
464 case BrowserPluginHostMsg_ResizeGuest::ID: 447 case BrowserPluginHostMsg_ResizeGuest::ID:
465 case BrowserPluginHostMsg_SetAutoSize::ID: 448 case BrowserPluginHostMsg_SetAutoSize::ID:
466 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: 449 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID:
467 case BrowserPluginHostMsg_SetFocus::ID: 450 case BrowserPluginHostMsg_SetFocus::ID:
468 case BrowserPluginHostMsg_SetContentsOpaque::ID: 451 case BrowserPluginHostMsg_SetContentsOpaque::ID:
469 case BrowserPluginHostMsg_SetVisibility::ID: 452 case BrowserPluginHostMsg_SetVisibility::ID:
470 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: 453 case BrowserPluginHostMsg_UnlockMouse_ACK::ID:
471 case BrowserPluginHostMsg_UpdateGeometry::ID: 454 case BrowserPluginHostMsg_UpdateGeometry::ID:
(...skipping 28 matching lines...) Expand all
500 #endif 483 #endif
501 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) 484 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse)
502 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) 485 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect)
503 IPC_MESSAGE_UNHANDLED(handled = false) 486 IPC_MESSAGE_UNHANDLED(handled = false)
504 IPC_END_MESSAGE_MAP() 487 IPC_END_MESSAGE_MAP()
505 return handled; 488 return handled;
506 } 489 }
507 490
508 void BrowserPluginGuest::Attach( 491 void BrowserPluginGuest::Attach(
509 WebContentsImpl* embedder_web_contents, 492 WebContentsImpl* embedder_web_contents,
510 BrowserPluginHostMsg_Attach_Params params, 493 const BrowserPluginHostMsg_Attach_Params& params,
511 const base::DictionaryValue& extra_params) { 494 const base::DictionaryValue& extra_params) {
512 if (attached()) 495 if (attached())
513 return; 496 return;
514 497
515 // Clear parameters that get inherited from the opener.
516 params.storage_partition_id.clear();
517 params.persist_storage = false;
518 params.src.clear();
519
520 // If a RenderView has already been created for this new window, then we need 498 // If a RenderView has already been created for this new window, then we need
521 // to initialize the browser-side state now so that the RenderFrameHostManager 499 // to initialize the browser-side state now so that the RenderFrameHostManager
522 // does not create a new RenderView on navigation. 500 // does not create a new RenderView on navigation.
523 if (has_render_view_) { 501 if (has_render_view_) {
524 static_cast<RenderViewHostImpl*>( 502 static_cast<RenderViewHostImpl*>(
525 GetWebContents()->GetRenderViewHost())->Init(); 503 GetWebContents()->GetRenderViewHost())->Init();
526 WebContentsViewGuest* new_view = 504 WebContentsViewGuest* new_view =
527 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 505 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
528 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); 506 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost());
529 } 507 }
530 508
531 Initialize(params, embedder_web_contents); 509 Initialize(params, embedder_web_contents, extra_params);
532 510
533 SendQueuedMessages(); 511 SendQueuedMessages();
534 512
535 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); 513 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached"));
536 } 514 }
537 515
538 void BrowserPluginGuest::OnCompositorFrameSwappedACK( 516 void BrowserPluginGuest::OnCompositorFrameSwappedACK(
539 int instance_id, 517 int instance_id,
540 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { 518 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
541 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, 519 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 weak_ptr_factory_.GetWeakPtr())); 672 weak_ptr_factory_.GetWeakPtr()));
695 } 673 }
696 674
697 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { 675 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) {
698 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); 676 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded));
699 pending_lock_request_ = false; 677 pending_lock_request_ = false;
700 if (succeeded) 678 if (succeeded)
701 mouse_locked_ = true; 679 mouse_locked_ = true;
702 } 680 }
703 681
704 void BrowserPluginGuest::OnNavigateGuest(int instance_id,
705 const std::string& src) {
706 if (!delegate_)
707 return;
708 delegate_->NavigateGuest(src);
709 }
710
711 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) { 682 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) {
712 Destroy(); 683 Destroy();
713 } 684 }
714 685
715 void BrowserPluginGuest::OnResizeGuest( 686 void BrowserPluginGuest::OnResizeGuest(
716 int instance_id, 687 int instance_id,
717 const BrowserPluginHostMsg_ResizeGuest_Params& params) { 688 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
718 if (!params.size_changed) 689 if (!params.size_changed)
719 return; 690 return;
720 // BrowserPlugin manages resize flow control itself and does not depend 691 // BrowserPlugin manages resize flow control itself and does not depend
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 void BrowserPluginGuest::OnImeCompositionRangeChanged( 901 void BrowserPluginGuest::OnImeCompositionRangeChanged(
931 const gfx::Range& range, 902 const gfx::Range& range,
932 const std::vector<gfx::Rect>& character_bounds) { 903 const std::vector<gfx::Rect>& character_bounds) {
933 static_cast<RenderWidgetHostViewBase*>( 904 static_cast<RenderWidgetHostViewBase*>(
934 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 905 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
935 range, character_bounds); 906 range, character_bounds);
936 } 907 }
937 #endif 908 #endif
938 909
939 } // namespace content 910 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698