OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/guest_view/browser/guest_view_message_filter.h" | 5 #include "components/guest_view/browser/guest_view_message_filter.h" |
6 | 6 |
7 #include "components/guest_view/browser/guest_view_base.h" | 7 #include "components/guest_view/browser/guest_view_base.h" |
8 #include "components/guest_view/browser/guest_view_manager.h" | 8 #include "components/guest_view/browser/guest_view_manager.h" |
9 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 9 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
10 #include "components/guest_view/common/guest_view_messages.h" | 10 #include "components/guest_view/common/guest_view_messages.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void GuestViewMessageFilter::OnDestruct() const { | 67 void GuestViewMessageFilter::OnDestruct() const { |
68 // Destroy the filter on the IO thread since that's where its weak pointers | 68 // Destroy the filter on the IO thread since that's where its weak pointers |
69 // are being used. | 69 // are being used. |
70 BrowserThread::DeleteOnIOThread::Destruct(this); | 70 BrowserThread::DeleteOnIOThread::Destruct(this); |
71 } | 71 } |
72 | 72 |
73 bool GuestViewMessageFilter::OnMessageReceived(const IPC::Message& message) { | 73 bool GuestViewMessageFilter::OnMessageReceived(const IPC::Message& message) { |
74 bool handled = true; | 74 bool handled = true; |
75 IPC_BEGIN_MESSAGE_MAP(GuestViewMessageFilter, message) | 75 IPC_BEGIN_MESSAGE_MAP(GuestViewMessageFilter, message) |
76 IPC_MESSAGE_HANDLER(GuestViewHostMsg_AttachGuest, OnAttachGuest) | 76 IPC_MESSAGE_HANDLER(GuestViewHostMsg_AttachGuest, OnAttachGuest) |
| 77 IPC_MESSAGE_HANDLER(GuestViewHostMsg_AttachToEmbedderFrame, |
| 78 OnAttachToEmbedderFrame) |
77 IPC_MESSAGE_HANDLER(GuestViewHostMsg_ViewCreated, OnViewCreated) | 79 IPC_MESSAGE_HANDLER(GuestViewHostMsg_ViewCreated, OnViewCreated) |
78 IPC_MESSAGE_HANDLER(GuestViewHostMsg_ViewGarbageCollected, | 80 IPC_MESSAGE_HANDLER(GuestViewHostMsg_ViewGarbageCollected, |
79 OnViewGarbageCollected) | 81 OnViewGarbageCollected) |
80 IPC_MESSAGE_UNHANDLED(handled = false) | 82 IPC_MESSAGE_UNHANDLED(handled = false) |
81 IPC_END_MESSAGE_MAP() | 83 IPC_END_MESSAGE_MAP() |
82 return handled; | 84 return handled; |
83 } | 85 } |
84 | 86 |
85 void GuestViewMessageFilter::OnViewCreated(int view_instance_id, | 87 void GuestViewMessageFilter::OnViewCreated(int view_instance_id, |
86 const std::string& view_type) { | 88 const std::string& view_type) { |
(...skipping 18 matching lines...) Expand all Loading... |
105 // embedder is misbehaving. | 107 // embedder is misbehaving. |
106 if (!manager) | 108 if (!manager) |
107 return; | 109 return; |
108 | 110 |
109 manager->AttachGuest(render_process_id_, | 111 manager->AttachGuest(render_process_id_, |
110 element_instance_id, | 112 element_instance_id, |
111 guest_instance_id, | 113 guest_instance_id, |
112 params); | 114 params); |
113 } | 115 } |
114 | 116 |
| 117 void GuestViewMessageFilter::OnAttachToEmbedderFrame( |
| 118 int embedder_local_render_frame_id, |
| 119 int element_instance_id, |
| 120 int guest_instance_id, |
| 121 const base::DictionaryValue& params) { |
| 122 auto* manager = GuestViewManager::FromBrowserContext(browser_context_); |
| 123 DCHECK(manager); |
| 124 content::WebContents* guest_web_contents = |
| 125 manager->GetGuestByInstanceIDSafely(guest_instance_id, |
| 126 render_process_id_); |
| 127 if (!guest_web_contents) |
| 128 return; |
| 129 |
| 130 auto* guest = GuestViewBase::FromWebContents(guest_web_contents); |
| 131 content::WebContents* owner_web_contents = guest->owner_web_contents(); |
| 132 DCHECK(owner_web_contents); |
| 133 auto* embedder_frame = RenderFrameHost::FromID( |
| 134 render_process_id_, embedder_local_render_frame_id); |
| 135 |
| 136 // Attach this inner WebContents |guest_web_contents| to the outer |
| 137 // WebContents |owner_web_contents|. The outer WebContents's |
| 138 // frame |embedder_frame| hosts the inner WebContents. |
| 139 guest_web_contents->AttachToOuterWebContentsFrame(owner_web_contents, |
| 140 embedder_frame); |
| 141 |
| 142 // Update the guest manager about the attachment. |
| 143 // This sets up the embedder and guest pairing information inside |
| 144 // the manager. |
| 145 manager->AttachGuest(render_process_id_, element_instance_id, |
| 146 guest_instance_id, params); |
| 147 |
| 148 owner_web_contents->GetMainFrame()->Send( |
| 149 new GuestViewMsg_AttachToEmbedderFrame_ACK(element_instance_id)); |
| 150 |
| 151 guest->WillAttach( |
| 152 owner_web_contents, element_instance_id, false, |
| 153 base::Bind(&GuestViewMessageFilter::WillAttachCallback, this, guest)); |
| 154 } |
| 155 |
| 156 void GuestViewMessageFilter::WillAttachCallback(GuestViewBase* guest) { |
| 157 guest->DidAttach(MSG_ROUTING_NONE); |
| 158 } |
| 159 |
115 } // namespace guest_view | 160 } // namespace guest_view |
OLD | NEW |