OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/debug/stack_trace.h" |
Charlie Reis
2016/10/18 22:52:20
This belongs below.
EhsanK
2016/10/20 21:41:17
Sorry for leaving this behind. Will remove it.
| |
5 #include "components/guest_view/browser/guest_view_manager.h" | 5 #include "components/guest_view/browser/guest_view_manager.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "components/guest_view/browser/guest_view_base.h" | 12 #include "components/guest_view/browser/guest_view_base.h" |
13 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 13 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
14 #include "components/guest_view/browser/guest_view_manager_factory.h" | 14 #include "components/guest_view/browser/guest_view_manager_factory.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // static | 64 // static |
65 GuestViewManagerFactory* GuestViewManager::factory_ = nullptr; | 65 GuestViewManagerFactory* GuestViewManager::factory_ = nullptr; |
66 | 66 |
67 GuestViewManager::GuestViewManager( | 67 GuestViewManager::GuestViewManager( |
68 content::BrowserContext* context, | 68 content::BrowserContext* context, |
69 std::unique_ptr<GuestViewManagerDelegate> delegate) | 69 std::unique_ptr<GuestViewManagerDelegate> delegate) |
70 : current_instance_id_(0), | 70 : current_instance_id_(0), |
71 last_instance_id_removed_(0), | 71 last_instance_id_removed_(0), |
72 context_(context), | 72 context_(context), |
73 delegate_(std::move(delegate)), | 73 delegate_(std::move(delegate)), |
74 attaching_guest_embedder_routing_id_(MSG_ROUTING_NONE), | |
74 weak_ptr_factory_(this) {} | 75 weak_ptr_factory_(this) {} |
75 | 76 |
76 GuestViewManager::~GuestViewManager() {} | 77 GuestViewManager::~GuestViewManager() {} |
77 | 78 |
78 // static | 79 // static |
79 GuestViewManager* GuestViewManager::CreateWithDelegate( | 80 GuestViewManager* GuestViewManager::CreateWithDelegate( |
80 BrowserContext* context, | 81 BrowserContext* context, |
81 std::unique_ptr<GuestViewManagerDelegate> delegate) { | 82 std::unique_ptr<GuestViewManagerDelegate> delegate) { |
82 GuestViewManager* guest_manager = FromBrowserContext(context); | 83 GuestViewManager* guest_manager = FromBrowserContext(context); |
83 if (!guest_manager) { | 84 if (!guest_manager) { |
(...skipping 19 matching lines...) Expand all Loading... | |
103 int guest_instance_id, | 104 int guest_instance_id, |
104 int embedder_render_process_id) { | 105 int embedder_render_process_id) { |
105 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, | 106 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, |
106 guest_instance_id)) { | 107 guest_instance_id)) { |
107 return nullptr; | 108 return nullptr; |
108 } | 109 } |
109 return GetGuestByInstanceID(guest_instance_id); | 110 return GetGuestByInstanceID(guest_instance_id); |
110 } | 111 } |
111 | 112 |
112 void GuestViewManager::AttachGuest(int embedder_process_id, | 113 void GuestViewManager::AttachGuest(int embedder_process_id, |
114 int embedder_routing_id, | |
113 int element_instance_id, | 115 int element_instance_id, |
114 int guest_instance_id, | 116 int guest_instance_id, |
115 const base::DictionaryValue& attach_params) { | 117 const base::DictionaryValue& attach_params) { |
118 DCHECK_EQ(attaching_guest_embedder_routing_id_, MSG_ROUTING_NONE); | |
119 attaching_guest_embedder_routing_id_ = embedder_routing_id; | |
120 | |
116 auto* guest_view = | 121 auto* guest_view = |
117 GuestViewBase::From(embedder_process_id, guest_instance_id); | 122 GuestViewBase::From(embedder_process_id, guest_instance_id); |
118 if (!guest_view) | 123 if (!guest_view) |
119 return; | 124 return; |
120 | 125 |
121 ElementInstanceKey key(embedder_process_id, element_instance_id); | 126 ElementInstanceKey key(embedder_process_id, element_instance_id); |
122 auto it = instance_id_map_.find(key); | 127 auto it = instance_id_map_.find(key); |
123 // If there is an existing guest attached to the element, then destroy the | 128 // If there is an existing guest attached to the element, then destroy the |
124 // existing guest. | 129 // existing guest. |
125 if (it != instance_id_map_.end()) { | 130 if (it != instance_id_map_.end()) { |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 // We might get some late arriving messages at tear down. Let's let the | 461 // We might get some late arriving messages at tear down. Let's let the |
457 // embedder tear down in peace. | 462 // embedder tear down in peace. |
458 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); | 463 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); |
459 if (it == guest_web_contents_by_instance_id_.end()) | 464 if (it == guest_web_contents_by_instance_id_.end()) |
460 return true; | 465 return true; |
461 | 466 |
462 auto* guest_view = GuestViewBase::FromWebContents(it->second); | 467 auto* guest_view = GuestViewBase::FromWebContents(it->second); |
463 if (!guest_view) | 468 if (!guest_view) |
464 return false; | 469 return false; |
465 | 470 |
466 return embedder_render_process_id == | 471 int render_frame_routing_id = attaching_guest_embedder_routing_id_; |
467 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID(); | 472 if (render_frame_routing_id == MSG_ROUTING_NONE) { |
473 render_frame_routing_id = | |
474 guest_view->owner_web_contents()->GetMainFrame()->GetRoutingID(); | |
475 } | |
476 | |
477 if (embedder_render_process_id != | |
478 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID() && | |
479 !guest_view->IsViewType("mimehandler")) { | |
480 // Only MimeHandlerViewGuest can be embedded in a cross origin frame. | |
481 return false; | |
482 } | |
483 | |
484 content::WebContents* web_contents = guest_view->host()->RegisterEmbedderID( | |
485 embedder_render_process_id, render_frame_routing_id); | |
Charlie Reis
2016/10/18 22:52:20
This doesn't seem obviously safe to me-- we're mix
EhsanK
2016/10/20 21:41:17
This variable and logic is removed form here. I no
| |
486 attaching_guest_embedder_routing_id_ = MSG_ROUTING_NONE; | |
487 | |
488 return web_contents->GetRenderProcessHost()->GetID() == | |
489 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID(); | |
Charlie Reis
2016/10/18 22:52:20
nit: No need for the GetID() calls, since you can
EhsanK
2016/10/20 21:41:17
Acknowledged.
| |
468 } | 490 } |
469 | 491 |
470 GuestViewManager::ElementInstanceKey::ElementInstanceKey() | 492 GuestViewManager::ElementInstanceKey::ElementInstanceKey() |
471 : embedder_process_id(content::ChildProcessHost::kInvalidUniqueID), | 493 : embedder_process_id(content::ChildProcessHost::kInvalidUniqueID), |
472 element_instance_id(content::ChildProcessHost::kInvalidUniqueID) { | 494 element_instance_id(content::ChildProcessHost::kInvalidUniqueID) { |
473 } | 495 } |
474 | 496 |
475 GuestViewManager::ElementInstanceKey::ElementInstanceKey( | 497 GuestViewManager::ElementInstanceKey::ElementInstanceKey( |
476 int embedder_process_id, | 498 int embedder_process_id, |
477 int element_instance_id) | 499 int element_instance_id) |
(...skipping 17 matching lines...) Expand all Loading... | |
495 const GuestViewCreateFunction& create_function, | 517 const GuestViewCreateFunction& create_function, |
496 const GuestViewCleanUpFunction& cleanup_function) | 518 const GuestViewCleanUpFunction& cleanup_function) |
497 : create_function(create_function), cleanup_function(cleanup_function) {} | 519 : create_function(create_function), cleanup_function(cleanup_function) {} |
498 | 520 |
499 GuestViewManager::GuestViewData::GuestViewData(const GuestViewData& other) = | 521 GuestViewManager::GuestViewData::GuestViewData(const GuestViewData& other) = |
500 default; | 522 default; |
501 | 523 |
502 GuestViewManager::GuestViewData::~GuestViewData() {} | 524 GuestViewManager::GuestViewData::~GuestViewData() {} |
503 | 525 |
504 } // namespace guest_view | 526 } // namespace guest_view |
OLD | NEW |