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 DCHECK(guest_web_contents); | |
Fady Samuel
2015/06/24 22:01:10
I would consider CHECK'ing here. If the above fail
lazyboy
2015/06/24 23:01:50
I'm doing early exit.
Done.
| |
128 auto* guest = GuestViewBase::FromWebContents(guest_web_contents); | |
129 DCHECK(guest); | |
130 content::WebContents* owner_web_contents = guest->owner_web_contents(); | |
131 DCHECK(owner_web_contents); | |
132 auto* embedder_frame = RenderFrameHost::FromID( | |
133 render_process_id_, embedder_local_render_frame_id); | |
134 guest_web_contents->AttachToOuterWebContentsFrame(owner_web_contents, | |
Fady Samuel
2015/06/24 22:01:10
Comment above this explaining briefly what it does
lazyboy
2015/06/24 23:01:50
Done.
| |
135 embedder_frame); | |
136 | |
137 manager->AttachGuest(render_process_id_, element_instance_id, | |
Fady Samuel
2015/06/24 22:01:10
Comment above this explaining briefly what it does
lazyboy
2015/06/24 23:01:50
Done.
| |
138 guest_instance_id, params); | |
139 | |
140 owner_web_contents->GetMainFrame()->Send( | |
141 new GuestViewMsg_AttachToEmbedderFrame_ACK(element_instance_id)); | |
142 | |
143 guest->WillAttach( | |
144 owner_web_contents, element_instance_id, false, | |
145 base::Bind(&GuestViewMessageFilter::WillAttachCallback, this, guest)); | |
Fady Samuel
2015/06/24 22:01:10
nit: Can you bind directly? base::Bind(&GuestView
lazyboy
2015/06/24 23:01:50
passing |guest| as |this| wouldn't work as |guest|
| |
146 } | |
147 | |
148 void GuestViewMessageFilter::WillAttachCallback(GuestViewBase* guest) { | |
149 guest->DidAttach(MSG_ROUTING_NONE); | |
150 } | |
151 | |
115 } // namespace guest_view | 152 } // namespace guest_view |
OLD | NEW |