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

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: HasPermission function moved 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 OnExecuteEditCommand) 129 OnExecuteEditCommand)
130 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, 130 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete,
131 OnExtendSelectionAndDelete) 131 OnExtendSelectionAndDelete)
132 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, 132 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
133 OnHandleInputEvent) 133 OnHandleInputEvent)
134 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, 134 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition,
135 OnImeConfirmComposition) 135 OnImeConfirmComposition)
136 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, 136 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition,
137 OnImeSetComposition) 137 OnImeSetComposition)
138 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) 138 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck)
139 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest)
140 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) 139 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed)
141 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, 140 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources,
142 OnReclaimCompositorResources) 141 OnReclaimCompositorResources)
143 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) 142 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
144 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) 143 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize)
145 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, 144 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent,
146 OnSetEditCommandsForNextKeyEvent) 145 OnSetEditCommandsForNextKeyEvent)
147 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) 146 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
148 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetContentsOpaque, 147 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetContentsOpaque,
149 OnSetContentsOpaque) 148 OnSetContentsOpaque)
150 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) 149 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
151 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) 150 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
152 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) 151 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
153 IPC_MESSAGE_UNHANDLED(handled = false) 152 IPC_MESSAGE_UNHANDLED(handled = false)
154 IPC_END_MESSAGE_MAP() 153 IPC_END_MESSAGE_MAP()
155 return handled; 154 return handled;
156 } 155 }
157 156
158 void BrowserPluginGuest::Initialize( 157 void BrowserPluginGuest::Initialize(
159 const BrowserPluginHostMsg_Attach_Params& params, 158 const BrowserPluginHostMsg_Attach_Params& params,
160 WebContentsImpl* embedder_web_contents) { 159 WebContentsImpl* embedder_web_contents,
160 const base::DictionaryValue& extra_params) {
161 focused_ = params.focused; 161 focused_ = params.focused;
162 guest_visible_ = params.visible; 162 guest_visible_ = params.visible;
163 guest_opaque_ = params.opaque; 163 guest_opaque_ = params.opaque;
164 guest_window_rect_ = params.resize_guest_params.view_rect; 164 guest_window_rect_ = params.resize_guest_params.view_rect;
165 165
166 auto_size_enabled_ = params.auto_size_params.enable; 166 auto_size_enabled_ = params.auto_size_params.enable;
167 max_auto_size_ = params.auto_size_params.max_size; 167 max_auto_size_ = params.auto_size_params.max_size;
168 min_auto_size_ = params.auto_size_params.min_size; 168 min_auto_size_ = params.auto_size_params.min_size;
169 169
170 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to 170 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 // Create a swapped out RenderView for the guest in the embedder render 204 // Create a swapped out RenderView for the guest in the embedder render
205 // process, so that the embedder can access the guest's window object. 205 // process, so that the embedder can access the guest's window object.
206 int guest_routing_id = 206 int guest_routing_id =
207 GetWebContents()->CreateSwappedOutRenderView( 207 GetWebContents()->CreateSwappedOutRenderView(
208 embedder_web_contents_->GetSiteInstance()); 208 embedder_web_contents_->GetSiteInstance());
209 SendMessageToEmbedder( 209 SendMessageToEmbedder(
210 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, 210 new BrowserPluginMsg_GuestContentWindowReady(instance_id_,
211 guest_routing_id)); 211 guest_routing_id));
212 212
213 if (!params.src.empty()) {
214 // params.src will be validated in BrowserPluginGuest::OnNavigateGuest.
215 OnNavigateGuest(instance_id_, params.src);
216 has_render_view_ = true;
217 }
218
219 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); 213 WebPreferences prefs = GetWebContents()->GetWebkitPrefs();
220 prefs.navigate_on_drag_drop = false; 214 prefs.navigate_on_drag_drop = false;
221 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); 215 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
222 216
223 // Enable input method for guest if it's enabled for the embedder. 217 // Enable input method for guest if it's enabled for the embedder.
224 if (static_cast<RenderViewHostImpl*>( 218 if (static_cast<RenderViewHostImpl*>(
225 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { 219 embedder_web_contents_->GetRenderViewHost())->input_method_active()) {
226 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 220 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
227 GetWebContents()->GetRenderViewHost()); 221 GetWebContents()->GetRenderViewHost());
228 guest_rvh->SetInputMethodActive(true); 222 guest_rvh->SetInputMethodActive(true);
229 } 223 }
230 224
231 // Inform the embedder of the guest's information. 225 // Inform the embedder of the guest's attachment.
232 // We pull the partition information from the site's URL, which is of the form 226 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_));
233 // guest://site/{persist}?{partition_name}.
234 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL();
235 BrowserPluginMsg_Attach_ACK_Params ack_params;
236 ack_params.storage_partition_id = site_url.query();
237 ack_params.persist_storage =
238 site_url.path().find("persist") != std::string::npos;
239 SendMessageToEmbedder(
240 new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params));
241 227
242 if (delegate_) 228 if (delegate_) {
243 delegate_->DidAttach(); 229 delegate_->DidAttach(extra_params);
230 has_render_view_ = true;
231 }
244 } 232 }
245 233
246 BrowserPluginGuest::~BrowserPluginGuest() { 234 BrowserPluginGuest::~BrowserPluginGuest() {
247 while (!pending_messages_.empty()) {
248 delete pending_messages_.front();
249 pending_messages_.pop();
250 }
251 } 235 }
252 236
253 // static 237 // static
254 BrowserPluginGuest* BrowserPluginGuest::Create( 238 BrowserPluginGuest* BrowserPluginGuest::Create(
255 int instance_id, 239 int instance_id,
256 SiteInstance* guest_site_instance, 240 SiteInstance* guest_site_instance,
257 WebContentsImpl* web_contents, 241 WebContentsImpl* web_contents,
258 scoped_ptr<base::DictionaryValue> extra_params, 242 scoped_ptr<base::DictionaryValue> extra_params,
259 BrowserPluginGuest* opener) { 243 BrowserPluginGuest* opener) {
260 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 244 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 size.height() <= max_auto_size_.height(); 337 size.height() <= max_auto_size_.height();
354 } 338 }
355 339
356 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 340 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
357 if (!attached()) { 341 if (!attached()) {
358 // Some pages such as data URLs, javascript URLs, and about:blank 342 // Some pages such as data URLs, javascript URLs, and about:blank
359 // do not load external resources and so they load prior to attachment. 343 // do not load external resources and so they load prior to attachment.
360 // As a result, we must save all these IPCs until attachment and then 344 // As a result, we must save all these IPCs until attachment and then
361 // forward them so that the embedder gets a chance to see and process 345 // forward them so that the embedder gets a chance to see and process
362 // the load events. 346 // the load events.
363 pending_messages_.push(msg); 347 pending_messages_.push_back(linked_ptr<IPC::Message>(msg));
364 return; 348 return;
365 } 349 }
366 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); 350 msg->set_routing_id(embedder_web_contents_->GetRoutingID());
367 embedder_web_contents_->Send(msg); 351 embedder_web_contents_->Send(msg);
368 } 352 }
369 353
370 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, 354 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
371 int screen_x, int screen_y, blink::WebDragOperation operation) { 355 int screen_x, int screen_y, blink::WebDragOperation operation) {
372 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 356 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
373 screen_x, screen_y, operation); 357 screen_x, screen_y, operation);
374 } 358 }
375 359
376 void BrowserPluginGuest::EndSystemDrag() { 360 void BrowserPluginGuest::EndSystemDrag() {
377 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 361 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
378 GetWebContents()->GetRenderViewHost()); 362 GetWebContents()->GetRenderViewHost());
379 guest_rvh->DragSourceSystemDragEnded(); 363 guest_rvh->DragSourceSystemDragEnded();
380 } 364 }
381 365
382 void BrowserPluginGuest::SendQueuedMessages() { 366 void BrowserPluginGuest::SendQueuedMessages() {
383 if (!attached()) 367 if (!attached())
384 return; 368 return;
385 369
386 while (!pending_messages_.empty()) { 370 while (!pending_messages_.empty()) {
387 IPC::Message* message = pending_messages_.front(); 371 linked_ptr<IPC::Message> message_ptr = pending_messages_.front();
388 pending_messages_.pop(); 372 pending_messages_.pop_front();
389 SendMessageToEmbedder(message); 373 SendMessageToEmbedder(message_ptr.release());
390 } 374 }
391 } 375 }
392 376
393 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( 377 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame(
394 int64 frame_id, 378 int64 frame_id,
395 const base::string16& frame_unique_name, 379 const base::string16& frame_unique_name,
396 bool is_main_frame, 380 bool is_main_frame,
397 const GURL& url, 381 const GURL& url,
398 PageTransition transition_type, 382 PageTransition transition_type,
399 RenderViewHost* render_view_host) { 383 RenderViewHost* render_view_host) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 switch (message.type()) { 425 switch (message.type()) {
442 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: 426 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID:
443 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID: 427 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID:
444 case BrowserPluginHostMsg_DragStatusUpdate::ID: 428 case BrowserPluginHostMsg_DragStatusUpdate::ID:
445 case BrowserPluginHostMsg_ExecuteEditCommand::ID: 429 case BrowserPluginHostMsg_ExecuteEditCommand::ID:
446 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: 430 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID:
447 case BrowserPluginHostMsg_HandleInputEvent::ID: 431 case BrowserPluginHostMsg_HandleInputEvent::ID:
448 case BrowserPluginHostMsg_ImeConfirmComposition::ID: 432 case BrowserPluginHostMsg_ImeConfirmComposition::ID:
449 case BrowserPluginHostMsg_ImeSetComposition::ID: 433 case BrowserPluginHostMsg_ImeSetComposition::ID:
450 case BrowserPluginHostMsg_LockMouse_ACK::ID: 434 case BrowserPluginHostMsg_LockMouse_ACK::ID:
451 case BrowserPluginHostMsg_NavigateGuest::ID:
452 case BrowserPluginHostMsg_PluginDestroyed::ID: 435 case BrowserPluginHostMsg_PluginDestroyed::ID:
453 case BrowserPluginHostMsg_ReclaimCompositorResources::ID: 436 case BrowserPluginHostMsg_ReclaimCompositorResources::ID:
454 case BrowserPluginHostMsg_ResizeGuest::ID: 437 case BrowserPluginHostMsg_ResizeGuest::ID:
455 case BrowserPluginHostMsg_SetAutoSize::ID: 438 case BrowserPluginHostMsg_SetAutoSize::ID:
456 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: 439 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID:
457 case BrowserPluginHostMsg_SetFocus::ID: 440 case BrowserPluginHostMsg_SetFocus::ID:
458 case BrowserPluginHostMsg_SetContentsOpaque::ID: 441 case BrowserPluginHostMsg_SetContentsOpaque::ID:
459 case BrowserPluginHostMsg_SetVisibility::ID: 442 case BrowserPluginHostMsg_SetVisibility::ID:
460 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: 443 case BrowserPluginHostMsg_UnlockMouse_ACK::ID:
461 case BrowserPluginHostMsg_UpdateGeometry::ID: 444 case BrowserPluginHostMsg_UpdateGeometry::ID:
(...skipping 28 matching lines...) Expand all
490 #endif 473 #endif
491 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) 474 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) 475 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect)
493 IPC_MESSAGE_UNHANDLED(handled = false) 476 IPC_MESSAGE_UNHANDLED(handled = false)
494 IPC_END_MESSAGE_MAP() 477 IPC_END_MESSAGE_MAP()
495 return handled; 478 return handled;
496 } 479 }
497 480
498 void BrowserPluginGuest::Attach( 481 void BrowserPluginGuest::Attach(
499 WebContentsImpl* embedder_web_contents, 482 WebContentsImpl* embedder_web_contents,
500 BrowserPluginHostMsg_Attach_Params params, 483 const BrowserPluginHostMsg_Attach_Params& params,
501 const base::DictionaryValue& extra_params) { 484 const base::DictionaryValue& extra_params) {
502 if (attached()) 485 if (attached())
503 return; 486 return;
504 487
505 // Clear parameters that get inherited from the opener.
506 params.storage_partition_id.clear();
507 params.persist_storage = false;
508 params.src.clear();
509
510 // If a RenderView has already been created for this new window, then we need 488 // If a RenderView has already been created for this new window, then we need
511 // to initialize the browser-side state now so that the RenderFrameHostManager 489 // to initialize the browser-side state now so that the RenderFrameHostManager
512 // does not create a new RenderView on navigation. 490 // does not create a new RenderView on navigation.
513 if (has_render_view_) { 491 if (has_render_view_) {
514 static_cast<RenderViewHostImpl*>( 492 static_cast<RenderViewHostImpl*>(
515 GetWebContents()->GetRenderViewHost())->Init(); 493 GetWebContents()->GetRenderViewHost())->Init();
516 WebContentsViewGuest* new_view = 494 WebContentsViewGuest* new_view =
517 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 495 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
518 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); 496 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost());
519 } 497 }
520 498
521 Initialize(params, embedder_web_contents); 499 Initialize(params, embedder_web_contents, extra_params);
522 500
523 SendQueuedMessages(); 501 SendQueuedMessages();
524 502
525 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); 503 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached"));
526 } 504 }
527 505
528 void BrowserPluginGuest::OnCompositorFrameSwappedACK( 506 void BrowserPluginGuest::OnCompositorFrameSwappedACK(
529 int instance_id, 507 int instance_id,
530 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { 508 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
531 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, 509 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 weak_ptr_factory_.GetWeakPtr())); 662 weak_ptr_factory_.GetWeakPtr()));
685 } 663 }
686 664
687 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { 665 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) {
688 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); 666 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded));
689 pending_lock_request_ = false; 667 pending_lock_request_ = false;
690 if (succeeded) 668 if (succeeded)
691 mouse_locked_ = true; 669 mouse_locked_ = true;
692 } 670 }
693 671
694 void BrowserPluginGuest::OnNavigateGuest(int instance_id,
695 const std::string& src) {
696 if (!delegate_)
697 return;
698 delegate_->NavigateGuest(src);
699 }
700
701 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) { 672 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) {
702 Destroy(); 673 Destroy();
703 } 674 }
704 675
705 void BrowserPluginGuest::OnResizeGuest( 676 void BrowserPluginGuest::OnResizeGuest(
706 int instance_id, 677 int instance_id,
707 const BrowserPluginHostMsg_ResizeGuest_Params& params) { 678 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
708 if (!params.size_changed) 679 if (!params.size_changed)
709 return; 680 return;
710 // BrowserPlugin manages resize flow control itself and does not depend 681 // BrowserPlugin manages resize flow control itself and does not depend
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 void BrowserPluginGuest::OnImeCompositionRangeChanged( 891 void BrowserPluginGuest::OnImeCompositionRangeChanged(
921 const gfx::Range& range, 892 const gfx::Range& range,
922 const std::vector<gfx::Rect>& character_bounds) { 893 const std::vector<gfx::Rect>& character_bounds) {
923 static_cast<RenderWidgetHostViewBase*>( 894 static_cast<RenderWidgetHostViewBase*>(
924 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 895 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
925 range, character_bounds); 896 range, character_bounds);
926 } 897 }
927 #endif 898 #endif
928 899
929 } // namespace content 900 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698