| 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 b3bd05a6b214e08d5efe3022f6397a1e9712cdbd..4cf4fb60b58be878fe4d2c87a87d39df1e137c20 100644 | 
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc | 
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc | 
| @@ -68,7 +68,8 @@ class BrowserPluginGuest::EmbedderWebContentsObserver | 
| BrowserPluginGuest::BrowserPluginGuest( | 
| int instance_id, | 
| bool has_render_view, | 
| -    WebContentsImpl* web_contents) | 
| +    WebContentsImpl* web_contents, | 
| +    BrowserPluginGuestDelegate* delegate) | 
| : WebContentsObserver(web_contents), | 
| embedder_web_contents_(NULL), | 
| instance_id_(instance_id), | 
| @@ -87,15 +88,19 @@ BrowserPluginGuest::BrowserPluginGuest( | 
| last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 
| last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 
| last_can_compose_inline_(true), | 
| -      delegate_(NULL), | 
| +      delegate_(delegate), | 
| weak_ptr_factory_(this) { | 
| DCHECK(web_contents); | 
| +  DCHECK(delegate); | 
| +  RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 
| +  web_contents->SetBrowserPluginGuest(this); | 
| +  delegate->RegisterDestructionCallback( | 
| +      base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); | 
| } | 
|  | 
| void BrowserPluginGuest::WillDestroy() { | 
| is_in_destruction_ = true; | 
| embedder_web_contents_ = NULL; | 
| -  delegate_ = NULL; | 
| } | 
|  | 
| base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { | 
| @@ -110,11 +115,17 @@ bool BrowserPluginGuest::LockMouse(bool allowed) { | 
| } | 
|  | 
| void BrowserPluginGuest::Destroy() { | 
| -  if (!delegate_) | 
| -    return; | 
| delegate_->Destroy(); | 
| } | 
|  | 
| +WebContentsImpl* BrowserPluginGuest::CreateNewGuestWindow( | 
| +    const WebContents::CreateParams& params) { | 
| +  WebContentsImpl* new_contents = | 
| +      static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); | 
| +  DCHECK(new_contents); | 
| +  return new_contents; | 
| +} | 
| + | 
| bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 
| const IPC::Message& message) { | 
| bool handled = true; | 
| @@ -234,34 +245,10 @@ BrowserPluginGuest::~BrowserPluginGuest() { | 
| // static | 
| BrowserPluginGuest* BrowserPluginGuest::Create( | 
| int instance_id, | 
| -    SiteInstance* guest_site_instance, | 
| WebContentsImpl* web_contents, | 
| -    scoped_ptr<base::DictionaryValue> extra_params, | 
| -    BrowserPluginGuest* opener) { | 
| -  RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 
| -  BrowserPluginGuest* guest = new BrowserPluginGuest( | 
| -      instance_id, web_contents->opener() != NULL, web_contents); | 
| -  web_contents->SetBrowserPluginGuest(guest); | 
| -  WebContents* opener_web_contents = NULL; | 
| -  if (opener) { | 
| -    opener_web_contents = opener->GetWebContents(); | 
| -    guest_site_instance = opener_web_contents->GetSiteInstance(); | 
| -  } | 
| -  BrowserPluginGuestDelegate* delegate = NULL; | 
| -  GetContentClient()->browser()->GuestWebContentsCreated( | 
| -      instance_id, | 
| -      guest_site_instance, | 
| -      web_contents, | 
| -      opener_web_contents, | 
| -      &delegate, | 
| -      extra_params.Pass()); | 
| -  if (delegate) { | 
| -    delegate->RegisterDestructionCallback( | 
| -        base::Bind(&BrowserPluginGuest::WillDestroy, | 
| -                   base::Unretained(guest))); | 
| -    guest->set_delegate(delegate); | 
| -  } | 
| -  return guest; | 
| +    BrowserPluginGuestDelegate* delegate) { | 
| +  return new BrowserPluginGuest( | 
| +      instance_id, web_contents->opener() != NULL, web_contents, delegate); | 
| } | 
|  | 
| // static | 
| @@ -653,9 +640,6 @@ void BrowserPluginGuest::OnLockMouse(bool user_gesture, | 
| return; | 
| } | 
|  | 
| -  if (!delegate_) | 
| -    return; | 
| - | 
| pending_lock_request_ = true; | 
|  | 
| delegate_->RequestPointerLockPermission( | 
| @@ -698,7 +682,7 @@ void BrowserPluginGuest::OnResizeGuest( | 
| // When autosize is turned off and as a result there is a layout change, we | 
| // send a sizechanged event. | 
| if (!auto_size_enabled_ && last_seen_auto_size_enabled_ && | 
| -      !params.view_size.IsEmpty() && delegate_) { | 
| +      !params.view_size.IsEmpty()) { | 
| delegate_->SizeChanged(last_seen_view_size_, params.view_size); | 
| last_seen_auto_size_enabled_ = false; | 
| } | 
| @@ -866,7 +850,7 @@ void BrowserPluginGuest::OnUpdateRect( | 
| last_seen_view_size_ = params.view_size; | 
|  | 
| if ((auto_size_enabled_ || last_seen_auto_size_enabled_) && | 
| -      size_changed && delegate_) { | 
| +      size_changed) { | 
| delegate_->SizeChanged(old_size, last_seen_view_size_); | 
| } | 
| last_seen_auto_size_enabled_ = auto_size_enabled_; | 
|  |