 Chromium Code Reviews
 Chromium Code Reviews Issue 258373002:
  Towards moving guest management to chrome: Introduce GuestViewManager  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 258373002:
  Towards moving guest management to chrome: Introduce GuestViewManager  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: content/browser/browser_plugin/browser_plugin_embedder.cc | 
| diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc | 
| index cb4fcf2add52afd49b81dbcc71536be726e05d86..82e12d2b6372f35389575a6af4725ac934a6d924 100644 | 
| --- a/content/browser/browser_plugin/browser_plugin_embedder.cc | 
| +++ b/content/browser/browser_plugin/browser_plugin_embedder.cc | 
| @@ -31,7 +31,8 @@ namespace content { | 
| BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 
| BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) | 
| - : WebContentsObserver(web_contents) { | 
| + : WebContentsObserver(web_contents), | 
| + weak_ptr_factory_(this) { | 
| } | 
| BrowserPluginEmbedder::~BrowserPluginEmbedder() { | 
| @@ -65,6 +66,12 @@ WebContentsImpl* BrowserPluginEmbedder::GetWebContents() { | 
| return static_cast<WebContentsImpl*>(web_contents()); | 
| } | 
| +void BrowserPluginEmbedder::AllocateInstanceIDResponse(int request_id, | 
| 
lazyboy
2014/05/01 20:06:59
SendAllocateInstanceIDResponse
 
Fady Samuel
2014/05/01 21:05:28
I removed this entirely.
 | 
| + int instance_id) { | 
| + Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | 
| + routing_id(), request_id, instance_id)); | 
| +} | 
| + | 
| bool BrowserPluginEmbedder::DidSendScreenRectsCallback( | 
| BrowserPluginGuest* guest) { | 
| static_cast<RenderViewHostImpl*>( | 
| @@ -74,9 +81,11 @@ bool BrowserPluginEmbedder::DidSendScreenRectsCallback( | 
| } | 
| void BrowserPluginEmbedder::DidSendScreenRects() { | 
| - GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( | 
| - &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 
| - base::Unretained(this))); | 
| + BrowserPluginGuestManager::FromBrowserContext( | 
| 
lazyboy
2014/05/01 20:06:59
Can we keep GetBrowserPluginGuestManager() functio
 
Fady Samuel
2014/05/01 21:05:28
Done.
 | 
| + GetWebContents()->GetBrowserContext())->ForEachGuest( | 
| + GetWebContents(), base::Bind( | 
| + &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 
| + base::Unretained(this))); | 
| } | 
| bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( | 
| @@ -93,10 +102,12 @@ bool BrowserPluginEmbedder::HandleKeyboardEvent( | 
| return false; | 
| } | 
| - return GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), | 
| - base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, | 
| - base::Unretained(this), | 
| - event)); | 
| + return BrowserPluginGuestManager::FromBrowserContext( | 
| + GetWebContents()->GetBrowserContext())->ForEachGuest( | 
| + GetWebContents(), | 
| + base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, | 
| + base::Unretained(this), | 
| + event)); | 
| } | 
| bool BrowserPluginEmbedder::SetZoomLevelCallback( | 
| @@ -108,10 +119,12 @@ bool BrowserPluginEmbedder::SetZoomLevelCallback( | 
| } | 
| void BrowserPluginEmbedder::SetZoomLevel(double level) { | 
| - GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( | 
| - &BrowserPluginEmbedder::SetZoomLevelCallback, | 
| - base::Unretained(this), | 
| - level)); | 
| + BrowserPluginGuestManager::FromBrowserContext( | 
| + GetWebContents()->GetBrowserContext())->ForEachGuest( | 
| + GetWebContents(), base::Bind( | 
| + &BrowserPluginEmbedder::SetZoomLevelCallback, | 
| + base::Unretained(this), | 
| + level)); | 
| } | 
| bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 
| @@ -151,34 +164,28 @@ void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | 
| *handled = (guest_dragging_over_.get() != NULL); | 
| } | 
| -BrowserPluginGuestManager* | 
| - BrowserPluginEmbedder::GetBrowserPluginGuestManager() { | 
| - BrowserPluginGuestManager* guest_manager = | 
| - GetWebContents()->GetBrowserPluginGuestManager(); | 
| - if (!guest_manager) { | 
| - guest_manager = BrowserPluginGuestManager::Create(); | 
| - GetWebContents()->GetBrowserContext()->SetUserData( | 
| - browser_plugin::kBrowserPluginGuestManagerKeyName, guest_manager); | 
| - } | 
| - return guest_manager; | 
| -} | 
| - | 
| -void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { | 
| - int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id(); | 
| - Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | 
| - routing_id(), request_id, instance_id)); | 
| +void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id, | 
| + const std::string& src) { | 
| + BrowserPluginGuestManager::FromBrowserContext( | 
| + GetWebContents()->GetBrowserContext())->RequestInstanceID( | 
| + src, base::Bind(&BrowserPluginEmbedder::AllocateInstanceIDResponse, | 
| + weak_ptr_factory_.GetWeakPtr(), | 
| 
lazyboy
2014/05/01 20:06:59
indentation is off
 
Fady Samuel
2014/05/01 21:05:28
Done.
 | 
| + request_id)); | 
| } | 
| void BrowserPluginEmbedder::OnAttach( | 
| int instance_id, | 
| const BrowserPluginHostMsg_Attach_Params& params, | 
| const base::DictionaryValue& extra_params) { | 
| - if (!GetBrowserPluginGuestManager()->CanEmbedderAccessInstanceIDMaybeKill( | 
| + BrowserPluginGuestManager* guest_manager = | 
| + BrowserPluginGuestManager::FromBrowserContext( | 
| + GetWebContents()->GetBrowserContext()); | 
| + if (!guest_manager->CanEmbedderAccessInstanceIDMaybeKill( | 
| GetWebContents()->GetRenderProcessHost()->GetID(), instance_id)) | 
| return; | 
| BrowserPluginGuest* guest = | 
| - GetBrowserPluginGuestManager()->GetGuestByInstanceID( | 
| + guest_manager->GetGuestByInstanceID( | 
| instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); | 
| if (guest) { | 
| @@ -196,7 +203,7 @@ void BrowserPluginEmbedder::OnAttach( | 
| } | 
| scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); | 
| - guest = GetBrowserPluginGuestManager()->CreateGuest( | 
| + guest = guest_manager->CreateGuest( | 
| GetWebContents()->GetSiteInstance(), | 
| instance_id, params, | 
| copy_extra_params.Pass()); |