Chromium Code Reviews| Index: content/browser/browser_plugin/browser_plugin_guest.cc |
| diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc |
| index 7e7f97ea95442f030875f3d341648fc6da8816b6..c82366b1a34036afe9f701d78639cce0bd1ca3e6 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
| @@ -99,8 +99,9 @@ class BrowserPluginGuest::NewWindowRequest : public PermissionRequest { |
| int embedder_render_process_id = |
| guest_->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
| BrowserPluginGuest* guest = |
| - guest_->GetWebContents()->GetBrowserPluginGuestManager()-> |
| - GetGuestByInstanceID(instance_id_, embedder_render_process_id); |
| + BrowserPluginGuestManager::FromBrowserContext( |
| + guest_->GetWebContents()->GetBrowserContext())-> |
| + GetGuestByInstanceID(instance_id_, embedder_render_process_id); |
| if (!guest) { |
| VLOG(0) << "Guest not found. Instance ID: " << instance_id_; |
| return; |
| @@ -189,8 +190,7 @@ class BrowserPluginGuest::EmbedderWebContentsObserver |
| BrowserPluginGuest::BrowserPluginGuest( |
| int instance_id, |
| bool has_render_view, |
| - WebContentsImpl* web_contents, |
| - BrowserPluginGuest* opener) |
| + WebContentsImpl* web_contents) |
| : WebContentsObserver(web_contents), |
| embedder_web_contents_(NULL), |
| instance_id_(instance_id), |
| @@ -213,10 +213,9 @@ BrowserPluginGuest::BrowserPluginGuest( |
| weak_ptr_factory_(this) { |
| DCHECK(web_contents); |
| web_contents->SetDelegate(this); |
| - if (opener) |
| - opener_ = opener->AsWeakPtr(); |
| - GetWebContents()->GetBrowserPluginGuestManager()->AddGuest(instance_id_, |
| - GetWebContents()); |
| + BrowserPluginGuestManager::FromBrowserContext( |
| + GetWebContents()->GetBrowserContext())->AddGuest(instance_id_, |
| + GetWebContents()); |
| } |
| bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, |
| @@ -303,10 +302,11 @@ void BrowserPluginGuest::RequestPermission( |
| BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( |
| const OpenURLParams& params) { |
| BrowserPluginGuestManager* guest_manager = |
| - GetWebContents()->GetBrowserPluginGuestManager(); |
| + BrowserPluginGuestManager::FromBrowserContext( |
| + GetWebContents()->GetBrowserContext()); |
| // Allocate a new instance ID for the new guest. |
| - int instance_id = guest_manager->get_next_instance_id(); |
| + int instance_id = guest_manager->GetNextInstanceID(); |
| // Set the attach params to use the same partition as the opener. |
| // We pull the partition information from the site's URL, which is of the form |
| @@ -322,10 +322,12 @@ BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( |
| scoped_ptr<base::DictionaryValue> extra_params( |
| extra_attach_params_->DeepCopy()); |
| BrowserPluginGuest* new_guest = |
| - GetWebContents()->GetBrowserPluginGuestManager()->CreateGuest( |
| - GetWebContents()->GetSiteInstance(), instance_id, |
| - attach_params, extra_params.Pass()); |
| - new_guest->opener_ = AsWeakPtr(); |
| + guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(), |
| + instance_id, |
| + attach_params, |
| + extra_params.Pass()); |
| + if (new_guest->delegate_) |
| + new_guest->delegate_->SetOpener(GetWebContents()); |
| // Take ownership of |new_guest|. |
| pending_new_windows_.insert( |
| @@ -351,10 +353,11 @@ void BrowserPluginGuest::EmbedderDestroyed() { |
| void BrowserPluginGuest::Destroy() { |
| is_in_destruction_ = true; |
| - if (!attached() && opener()) |
| - opener()->pending_new_windows_.erase(this); |
| + if (!attached() && GetOpener()) |
| + GetOpener()->pending_new_windows_.erase(this); |
| DestroyUnattachedWindows(); |
| - GetWebContents()->GetBrowserPluginGuestManager()->RemoveGuest(instance_id_); |
| + BrowserPluginGuestManager::FromBrowserContext( |
|
lazyboy
2014/05/01 20:06:59
Same for this file, add BrowserPluginGuest::GetBro
Fady Samuel
2014/05/01 21:05:28
Done.
|
| + GetWebContents()->GetBrowserContext())->RemoveGuest(instance_id_); |
| delete GetWebContents(); |
| } |
| @@ -509,7 +512,7 @@ BrowserPluginGuest* BrowserPluginGuest::Create( |
| if (factory_) { |
| guest = factory_->CreateBrowserPluginGuest(instance_id, web_contents); |
| } else { |
| - guest = new BrowserPluginGuest(instance_id, false, web_contents, NULL); |
| + guest = new BrowserPluginGuest(instance_id, false, web_contents); |
| } |
| guest->extra_attach_params_.reset(extra_params->DeepCopy()); |
| web_contents->SetBrowserPluginGuest(guest); |
| @@ -528,7 +531,7 @@ BrowserPluginGuest* BrowserPluginGuest::CreateWithOpener( |
| BrowserPluginGuest* opener) { |
| BrowserPluginGuest* guest = |
| new BrowserPluginGuest( |
| - instance_id, has_render_view, web_contents, opener); |
| + instance_id, has_render_view, web_contents); |
| web_contents->SetBrowserPluginGuest(guest); |
| BrowserPluginGuestDelegate* delegate = NULL; |
| GetContentClient()->browser()->GuestWebContentsCreated( |
| @@ -545,6 +548,17 @@ RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { |
| return embedder_web_contents_->GetRenderWidgetHostView(); |
| } |
| +BrowserPluginGuest* BrowserPluginGuest::GetOpener() { |
| + if (!delegate_) |
| + return NULL; |
| + |
| + WebContents* opener = delegate_->GetOpener(); |
| + if (!opener) |
| + return NULL; |
| + |
| + return static_cast<WebContentsImpl*>(opener)->GetBrowserPluginGuest(); |
| +} |
| + |
| void BrowserPluginGuest::UpdateVisibility() { |
| OnSetVisibility(instance_id_, visible()); |
| } |
| @@ -697,8 +711,9 @@ WebContents* BrowserPluginGuest::OpenURLFromTab(WebContents* source, |
| // Navigation also resumes resource loading which we don't want to allow |
| // until attachment. |
| if (!attached()) { |
| - PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); |
| - if (it == opener()->pending_new_windows_.end()) |
| + PendingWindowMap::iterator it = |
| + GetOpener()->pending_new_windows_.find(this); |
| + if (it == GetOpener()->pending_new_windows_.end()) |
| return NULL; |
| const NewWindowInfo& old_target_url = it->second; |
| NewWindowInfo new_window_info(params.url, old_target_url.name); |
| @@ -723,7 +738,8 @@ void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
| WebContentsImpl* new_contents_impl = |
| static_cast<WebContentsImpl*>(new_contents); |
| BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); |
| - guest->opener_ = AsWeakPtr(); |
| + if (guest->delegate_) |
| + guest->delegate_->SetOpener(GetWebContents()); |
| std::string guest_name = base::UTF16ToUTF8(frame_name); |
| guest->name_ = guest_name; |
| // Take ownership of the new guest until it is attached to the embedder's DOM |
| @@ -1020,8 +1036,8 @@ void BrowserPluginGuest::Attach( |
| // the time the WebContents was created and the time it was attached. |
| // We also need to do an initial navigation if a RenderView was never |
| // created for the new window in cases where there is no referrer. |
| - PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); |
| - if (it != opener()->pending_new_windows_.end()) { |
| + PendingWindowMap::iterator it = GetOpener()->pending_new_windows_.find(this); |
| + if (it != GetOpener()->pending_new_windows_.end()) { |
| const NewWindowInfo& new_window_info = it->second; |
| if (new_window_info.changed || !has_render_view_) |
| params.src = it->second.url.spec(); |
| @@ -1031,7 +1047,7 @@ void BrowserPluginGuest::Attach( |
| // Once a new guest is attached to the DOM of the embedder page, then the |
| // lifetime of the new guest is no longer managed by the opener guest. |
| - opener()->pending_new_windows_.erase(this); |
| + GetOpener()->pending_new_windows_.erase(this); |
| // The guest's frame name takes precedence over the BrowserPlugin's name. |
| // The guest's frame name is assigned in |