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

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

Issue 261013005: BrowserPlugin: Move CreateGuest to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_simplify_api
Patch Set: Fixed content_browsertests after a change 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 next_permission_request_id_(browser_plugin::kInvalidPermissionRequestID), 214 next_permission_request_id_(browser_plugin::kInvalidPermissionRequestID),
215 has_render_view_(has_render_view), 215 has_render_view_(has_render_view),
216 last_seen_auto_size_enabled_(false), 216 last_seen_auto_size_enabled_(false),
217 is_in_destruction_(false), 217 is_in_destruction_(false),
218 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 218 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
219 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 219 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
220 last_can_compose_inline_(true), 220 last_can_compose_inline_(true),
221 weak_ptr_factory_(this) { 221 weak_ptr_factory_(this) {
222 DCHECK(web_contents); 222 DCHECK(web_contents);
223 web_contents->SetDelegate(this); 223 web_contents->SetDelegate(this);
224 GetBrowserPluginGuestManager()->AddGuest(instance_id_, GetWebContents());
225 } 224 }
226 225
227 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, 226 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source,
228 int32 level, 227 int32 level,
229 const base::string16& message, 228 const base::string16& message,
230 int32 line_no, 229 int32 line_no,
231 const base::string16& source_id) { 230 const base::string16& source_id) {
232 if (!delegate_) 231 if (!delegate_)
233 return false; 232 return false;
234 233
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 const OpenURLParams& params) { 308 const OpenURLParams& params) {
310 BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager(); 309 BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager();
311 310
312 // Allocate a new instance ID for the new guest. 311 // Allocate a new instance ID for the new guest.
313 int instance_id = guest_manager->GetNextInstanceID(); 312 int instance_id = guest_manager->GetNextInstanceID();
314 313
315 // Set the attach params to use the same partition as the opener. 314 // Set the attach params to use the same partition as the opener.
316 // We pull the partition information from the site's URL, which is of the form 315 // We pull the partition information from the site's URL, which is of the form
317 // guest://site/{persist}?{partition_name}. 316 // guest://site/{persist}?{partition_name}.
318 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); 317 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL();
319 BrowserPluginHostMsg_Attach_Params attach_params;
320 attach_params.storage_partition_id = site_url.query();
321 attach_params.persist_storage =
322 site_url.path().find("persist") != std::string::npos;
323 318
324 // The new guest gets a copy of this guest's extra params so that the content 319 // The new guest gets a copy of this guest's extra params so that the content
325 // embedder exposes the same API for this guest as its opener. 320 // embedder exposes the same API for this guest as its opener.
326 scoped_ptr<base::DictionaryValue> extra_params( 321 scoped_ptr<base::DictionaryValue> extra_params(
327 extra_attach_params_->DeepCopy()); 322 extra_attach_params_->DeepCopy());
323 const std::string& storage_partition_id = site_url.query();
324 bool persist_storage =
325 site_url.path().find("persist") != std::string::npos;
328 BrowserPluginGuest* new_guest = 326 BrowserPluginGuest* new_guest =
329 guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(), 327 guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(),
330 instance_id, 328 instance_id,
331 attach_params, 329 storage_partition_id,
330 persist_storage,
332 extra_params.Pass()); 331 extra_params.Pass());
333 if (new_guest->delegate_) 332 if (new_guest->delegate_)
334 new_guest->delegate_->SetOpener(GetWebContents()); 333 new_guest->delegate_->SetOpener(GetWebContents());
335 334
336 // Take ownership of |new_guest|. 335 // Take ownership of |new_guest|.
337 pending_new_windows_.insert( 336 pending_new_windows_.insert(
338 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); 337 std::make_pair(new_guest, NewWindowInfo(params.url, std::string())));
339 338
340 // Request permission to show the new window. 339 // Request permission to show the new window.
341 RequestNewWindowPermission(params.disposition, gfx::Rect(), 340 RequestNewWindowPermission(params.disposition, gfx::Rect(),
(...skipping 11 matching lines...) Expand all
353 if (delegate_) 352 if (delegate_)
354 delegate_->EmbedderDestroyed(); 353 delegate_->EmbedderDestroyed();
355 Destroy(); 354 Destroy();
356 } 355 }
357 356
358 void BrowserPluginGuest::Destroy() { 357 void BrowserPluginGuest::Destroy() {
359 is_in_destruction_ = true; 358 is_in_destruction_ = true;
360 if (!attached() && GetOpener()) 359 if (!attached() && GetOpener())
361 GetOpener()->pending_new_windows_.erase(this); 360 GetOpener()->pending_new_windows_.erase(this);
362 DestroyUnattachedWindows(); 361 DestroyUnattachedWindows();
363 GetBrowserPluginGuestManager()->RemoveGuest(instance_id_);
364 delete GetWebContents(); 362 delete GetWebContents();
365 } 363 }
366 364
367 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( 365 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
368 const IPC::Message& message) { 366 const IPC::Message& message) {
369 bool handled = true; 367 bool handled = true;
370 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 368 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
371 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, 369 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK,
372 OnCompositorFrameSwappedACK) 370 OnCompositorFrameSwappedACK)
373 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck, 371 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck,
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 const GURL& url) { 1555 const GURL& url) {
1558 if (!url.is_valid()) { 1556 if (!url.is_valid()) {
1559 callback.Run(false); 1557 callback.Run(false);
1560 return; 1558 return;
1561 } 1559 }
1562 1560
1563 delegate_->CanDownload(request_method, url, callback); 1561 delegate_->CanDownload(request_method, url, callback);
1564 } 1562 }
1565 1563
1566 } // namespace content 1564 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698