| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_manager.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
| 6 | 6 |
| 7 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 7 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 embedder_site_instance->GetBrowserContext(), guest_site); | 114 embedder_site_instance->GetBrowserContext(), guest_site); |
| 115 } | 115 } |
| 116 | 116 |
| 117 return WebContentsImpl::CreateGuest( | 117 return WebContentsImpl::CreateGuest( |
| 118 embedder_site_instance->GetBrowserContext(), | 118 embedder_site_instance->GetBrowserContext(), |
| 119 guest_site_instance, | 119 guest_site_instance, |
| 120 instance_id, | 120 instance_id, |
| 121 extra_params.Pass()); | 121 extra_params.Pass()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 BrowserPluginGuest* BrowserPluginGuestManager::GetGuestByInstanceID( | 124 static void BrowserPluginGuestByInstanceIDCallback( |
| 125 const BrowserPluginGuestManager::GuestByInstanceIDCallback& callback, |
| 126 WebContents* guest_web_contents) { |
| 127 if (!guest_web_contents) { |
| 128 callback.Run(NULL); |
| 129 return; |
| 130 } |
| 131 callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)-> |
| 132 GetBrowserPluginGuest()); |
| 133 } |
| 134 |
| 135 void BrowserPluginGuestManager::MaybeGetGuestByInstanceIDOrKill( |
| 125 int instance_id, | 136 int instance_id, |
| 126 int embedder_render_process_id) const { | 137 int embedder_render_process_id, |
| 127 if (!GetDelegate()) | 138 const GuestByInstanceIDCallback& callback) const { |
| 128 return NULL; | 139 if (!GetDelegate()) { |
| 140 callback.Run(NULL); |
| 141 return; |
| 142 } |
| 129 | 143 |
| 130 WebContentsImpl* guest_web_contents = static_cast<WebContentsImpl*>( | 144 GetDelegate()->MaybeGetGuestByInstanceIDOrKill( |
| 131 GetDelegate()->GetGuestByInstanceID(instance_id, | 145 instance_id, |
| 132 embedder_render_process_id)); | 146 embedder_render_process_id, |
| 133 | 147 base::Bind(&BrowserPluginGuestByInstanceIDCallback, |
| 134 return guest_web_contents ? | 148 callback)); |
| 135 guest_web_contents->GetBrowserPluginGuest() : NULL; | |
| 136 } | 149 } |
| 137 | 150 |
| 138 void BrowserPluginGuestManager::AddGuest(int instance_id, | 151 void BrowserPluginGuestManager::AddGuest(int instance_id, |
| 139 WebContents* guest_web_contents) { | 152 WebContents* guest_web_contents) { |
| 140 if (!GetDelegate()) | 153 if (!GetDelegate()) |
| 141 return; | 154 return; |
| 142 GetDelegate()->AddGuest(instance_id, guest_web_contents); | 155 GetDelegate()->AddGuest(instance_id, guest_web_contents); |
| 143 } | 156 } |
| 144 | 157 |
| 145 void BrowserPluginGuestManager::RemoveGuest(int instance_id) { | 158 void BrowserPluginGuestManager::RemoveGuest(int instance_id) { |
| 146 if (!GetDelegate()) | 159 if (!GetDelegate()) |
| 147 return; | 160 return; |
| 148 GetDelegate()->RemoveGuest(instance_id); | 161 GetDelegate()->RemoveGuest(instance_id); |
| 149 } | 162 } |
| 150 | 163 |
| 151 bool BrowserPluginGuestManager::CanEmbedderAccessInstanceIDMaybeKill( | 164 static void BrowserPluginGuestMessageCallback(const IPC::Message& message, |
| 152 int embedder_render_process_id, | 165 BrowserPluginGuest* guest) { |
| 153 int instance_id) const { | 166 if (!guest) |
| 154 if (!GetDelegate()) | 167 return; |
| 155 return false; | 168 guest->OnMessageReceivedFromEmbedder(message); |
| 156 | |
| 157 return GetDelegate()->CanEmbedderAccessInstanceIDMaybeKill( | |
| 158 embedder_render_process_id, instance_id); | |
| 159 } | 169 } |
| 160 | 170 |
| 161 void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message, | 171 void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message, |
| 162 int render_process_id) { | 172 int render_process_id) { |
| 163 DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)); | 173 DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)); |
| 164 int instance_id = 0; | 174 int instance_id = 0; |
| 165 // All allowed messages must have instance_id as their first parameter. | 175 // All allowed messages must have instance_id as their first parameter. |
| 166 PickleIterator iter(message); | 176 PickleIterator iter(message); |
| 167 bool success = iter.ReadInt(&instance_id); | 177 bool success = iter.ReadInt(&instance_id); |
| 168 DCHECK(success); | 178 DCHECK(success); |
| 169 BrowserPluginGuest* guest = | 179 MaybeGetGuestByInstanceIDOrKill(instance_id, |
| 170 GetGuestByInstanceID(instance_id, render_process_id); | 180 render_process_id, |
| 171 if (!guest) | 181 base::Bind(&BrowserPluginGuestMessageCallback, |
| 172 return; | 182 message)); |
| 173 guest->OnMessageReceivedFromEmbedder(message); | |
| 174 } | 183 } |
| 175 | 184 |
| 176 SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance( | 185 SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance( |
| 177 const GURL& guest_site) { | 186 const GURL& guest_site) { |
| 178 if (!GetDelegate()) | 187 if (!GetDelegate()) |
| 179 return NULL; | 188 return NULL; |
| 180 return GetDelegate()->GetGuestSiteInstance(guest_site); | 189 return GetDelegate()->GetGuestSiteInstance(guest_site); |
| 181 } | 190 } |
| 182 | 191 |
| 183 static bool BrowserPluginGuestCallback( | 192 static bool BrowserPluginGuestCallback( |
| 184 const BrowserPluginGuestManager::GuestCallback& callback, | 193 const BrowserPluginGuestManager::GuestCallback& callback, |
| 185 WebContents* guest_web_contents) { | 194 WebContents* guest_web_contents) { |
| 186 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents) | 195 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents) |
| 187 ->GetBrowserPluginGuest()); | 196 ->GetBrowserPluginGuest()); |
| 188 } | 197 } |
| 189 | 198 |
| 190 bool BrowserPluginGuestManager::ForEachGuest( | 199 bool BrowserPluginGuestManager::ForEachGuest( |
| 191 WebContents* embedder_web_contents, const GuestCallback& callback) { | 200 WebContents* embedder_web_contents, const GuestCallback& callback) { |
| 192 if (!GetDelegate()) | 201 if (!GetDelegate()) |
| 193 return false; | 202 return false; |
| 194 return GetDelegate()->ForEachGuest(embedder_web_contents, | 203 return GetDelegate()->ForEachGuest(embedder_web_contents, |
| 195 base::Bind(&BrowserPluginGuestCallback, | 204 base::Bind(&BrowserPluginGuestCallback, |
| 196 callback)); | 205 callback)); |
| 197 } | 206 } |
| 198 | 207 |
| 199 } // namespace content | 208 } // namespace content |
| OLD | NEW |