Chromium Code Reviews| Index: chrome/browser/guest_view/guest_view_base.cc |
| diff --git a/chrome/browser/guest_view/guest_view_base.cc b/chrome/browser/guest_view/guest_view_base.cc |
| index 1c09be1cc2165918651a5bae984a929373b59af8..6448ac9dcfe86d10909629b0ab2e45d164f6eb2d 100644 |
| --- a/chrome/browser/guest_view/guest_view_base.cc |
| +++ b/chrome/browser/guest_view/guest_view_base.cc |
| @@ -66,17 +66,25 @@ class GuestViewBase::EmbedderWebContentsObserver : public WebContentsObserver { |
| DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); |
| }; |
| -GuestViewBase::GuestViewBase(int guest_instance_id, |
| - WebContents* guest_web_contents, |
| - const std::string& embedder_extension_id) |
| - : WebContentsObserver(guest_web_contents), |
| - embedder_web_contents_(NULL), |
| - embedder_extension_id_(embedder_extension_id), |
| +GuestViewBase::GuestViewBase(int guest_instance_id) |
| + : embedder_web_contents_(NULL), |
| embedder_render_process_id_(0), |
| - browser_context_(guest_web_contents->GetBrowserContext()), |
| + browser_context_(NULL), |
| guest_instance_id_(guest_instance_id), |
| view_instance_id_(guestview::kInstanceIDNone), |
| + initialized_(false), |
| weak_ptr_factory_(this) { |
| +} |
| + |
| +void GuestViewBase::Init(WebContents* guest_web_contents, |
|
lazyboy
2014/06/13 17:40:01
Let's add a comment/todo since it's not obvious wh
Fady Samuel
2014/06/16 14:35:40
Done.
|
| + const std::string& embedder_extension_id) { |
| + if (initialized_) |
| + return; |
| + initialized_ = true; |
| + browser_context_ = guest_web_contents->GetBrowserContext(); |
| + embedder_extension_id_ = embedder_extension_id; |
| + |
| + WebContentsObserver::Observe(guest_web_contents); |
| guest_web_contents->SetDelegate(this); |
| webcontents_guestview_map.Get().insert( |
| std::make_pair(guest_web_contents, this)); |
| @@ -155,15 +163,25 @@ bool GuestViewBase::IsDragAndDropEnabled() const { |
| return false; |
| } |
| -void GuestViewBase::Attach(content::WebContents* embedder_web_contents, |
| - const base::DictionaryValue& args) { |
| +void GuestViewBase::Destroy() { |
| + WillDestroy(); |
| + if (!destruction_callback_.is_null()) |
| + destruction_callback_.Run(); |
| + delete guest_web_contents(); |
| +} |
| + |
| +void GuestViewBase::DidAttach(content::WebContents* embedder_web_contents, |
| + const base::DictionaryValue& extra_params) { |
| embedder_web_contents_ = embedder_web_contents; |
| embedder_web_contents_observer_.reset( |
| new EmbedderWebContentsObserver(this)); |
| embedder_render_process_id_ = |
| embedder_web_contents->GetRenderProcessHost()->GetID(); |
| - args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); |
| - extra_params_.reset(args.DeepCopy()); |
| + extra_params.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); |
| + extra_params_.reset(extra_params.DeepCopy()); |
| + |
| + // Give the derived class an opportunity to perform some actions. |
| + DidAttach(); |
| // GuestViewBase::Attach is called prior to initialization (and initial |
| // navigation) of the guest in the content layer in order to permit mapping |
| @@ -181,14 +199,6 @@ void GuestViewBase::Attach(content::WebContents* embedder_web_contents, |
| weak_ptr_factory_.GetWeakPtr())); |
| } |
| -void GuestViewBase::Destroy() { |
| - WillDestroy(); |
| - if (!destruction_callback_.is_null()) |
| - destruction_callback_.Run(); |
| - delete guest_web_contents(); |
| -} |
| - |
| - |
| void GuestViewBase::SetOpener(GuestViewBase* guest) { |
| if (guest && guest->IsViewType(GetViewType())) { |
| opener_ = guest->AsWeakPtr(); |