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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest_manager.cc

Issue 264943006: BrowserPlugin: Simplify content/public API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_v1
Patch Set: Created 6 years, 7 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) 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
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(
lazyboy 2014/05/01 23:27:58 Again, OnGuestRetrieved might be better describing
Fady Samuel 2014/05/06 16:51:36 Skipping. This file is going away very soon.
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,
138 const GuestByInstanceIDCallback& callback) const {
127 if (!GetDelegate()) 139 if (!GetDelegate())
lazyboy 2014/05/01 23:27:58 Consider callback.Run(NULL) to be more consistent,
Fady Samuel 2014/05/06 16:51:36 Done.
128 return NULL; 140 return;
129 141
130 WebContentsImpl* guest_web_contents = static_cast<WebContentsImpl*>( 142 GetDelegate()->MaybeGetGuestByInstanceIDOrKill(
131 GetDelegate()->GetGuestByInstanceID(instance_id, 143 instance_id,
132 embedder_render_process_id)); 144 embedder_render_process_id,
133 145 base::Bind(&BrowserPluginGuestByInstanceIDCallback,
134 return guest_web_contents ? 146 callback));
135 guest_web_contents->GetBrowserPluginGuest() : NULL;
136 } 147 }
137 148
138 void BrowserPluginGuestManager::AddGuest(int instance_id, 149 void BrowserPluginGuestManager::AddGuest(int instance_id,
139 WebContents* guest_web_contents) { 150 WebContents* guest_web_contents) {
140 if (!GetDelegate()) 151 if (!GetDelegate())
141 return; 152 return;
142 GetDelegate()->AddGuest(instance_id, guest_web_contents); 153 GetDelegate()->AddGuest(instance_id, guest_web_contents);
143 } 154 }
144 155
145 void BrowserPluginGuestManager::RemoveGuest(int instance_id) { 156 void BrowserPluginGuestManager::RemoveGuest(int instance_id) {
146 if (!GetDelegate()) 157 if (!GetDelegate())
147 return; 158 return;
148 GetDelegate()->RemoveGuest(instance_id); 159 GetDelegate()->RemoveGuest(instance_id);
149 } 160 }
150 161
151 bool BrowserPluginGuestManager::CanEmbedderAccessInstanceIDMaybeKill( 162 static void BrowserPluginGuestMessageCallback(const IPC::Message& message,
152 int embedder_render_process_id, 163 BrowserPluginGuest* guest) {
153 int instance_id) const { 164 if (!guest)
154 if (!GetDelegate()) 165 return;
155 return false; 166 guest->OnMessageReceivedFromEmbedder(message);
156
157 return GetDelegate()->CanEmbedderAccessInstanceIDMaybeKill(
158 embedder_render_process_id, instance_id);
159 } 167 }
160 168
161 void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message, 169 void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message,
162 int render_process_id) { 170 int render_process_id) {
163 DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)); 171 DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message));
164 int instance_id = 0; 172 int instance_id = 0;
165 // All allowed messages must have instance_id as their first parameter. 173 // All allowed messages must have instance_id as their first parameter.
166 PickleIterator iter(message); 174 PickleIterator iter(message);
167 bool success = iter.ReadInt(&instance_id); 175 bool success = iter.ReadInt(&instance_id);
168 DCHECK(success); 176 DCHECK(success);
169 BrowserPluginGuest* guest = 177 MaybeGetGuestByInstanceIDOrKill(instance_id,
170 GetGuestByInstanceID(instance_id, render_process_id); 178 render_process_id,
171 if (!guest) 179 base::Bind(&BrowserPluginGuestMessageCallback,
172 return; 180 message));
173 guest->OnMessageReceivedFromEmbedder(message);
174 } 181 }
175 182
176 SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance( 183 SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance(
177 const GURL& guest_site) { 184 const GURL& guest_site) {
178 if (!GetDelegate()) 185 if (!GetDelegate())
179 return NULL; 186 return NULL;
180 return GetDelegate()->GetGuestSiteInstance(guest_site); 187 return GetDelegate()->GetGuestSiteInstance(guest_site);
181 } 188 }
182 189
183 static bool BrowserPluginGuestCallback( 190 static bool BrowserPluginGuestCallback(
184 const BrowserPluginGuestManager::GuestCallback& callback, 191 const BrowserPluginGuestManager::GuestCallback& callback,
185 WebContents* guest_web_contents) { 192 WebContents* guest_web_contents) {
186 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents) 193 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)
187 ->GetBrowserPluginGuest()); 194 ->GetBrowserPluginGuest());
188 } 195 }
189 196
190 bool BrowserPluginGuestManager::ForEachGuest( 197 bool BrowserPluginGuestManager::ForEachGuest(
191 WebContents* embedder_web_contents, const GuestCallback& callback) { 198 WebContents* embedder_web_contents, const GuestCallback& callback) {
192 if (!GetDelegate()) 199 if (!GetDelegate())
193 return false; 200 return false;
194 return GetDelegate()->ForEachGuest(embedder_web_contents, 201 return GetDelegate()->ForEachGuest(embedder_web_contents,
195 base::Bind(&BrowserPluginGuestCallback, 202 base::Bind(&BrowserPluginGuestCallback,
196 callback)); 203 callback));
197 } 204 }
198 205
199 } // namespace content 206 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698