OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/guest_view/guest_view_base.h" | 5 #include "extensions/browser/guest_view/guest_view_base.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 DidAttachToEmbedder(); | 303 DidAttachToEmbedder(); |
304 | 304 |
305 SendQueuedEvents(); | 305 SendQueuedEvents(); |
306 } | 306 } |
307 | 307 |
308 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, | 308 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, |
309 const gfx::Size& new_size) { | 309 const gfx::Size& new_size) { |
310 element_size_ = new_size; | 310 element_size_ = new_size; |
311 } | 311 } |
312 | 312 |
313 int GuestViewBase::GetGuestInstanceID() const { | |
314 return guest_instance_id_; | |
315 } | |
316 | |
317 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, | 313 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, |
318 const gfx::Size& new_size) { | 314 const gfx::Size& new_size) { |
319 if (!auto_size_enabled_) | 315 if (!auto_size_enabled_) |
320 return; | 316 return; |
321 guest_size_ = new_size; | 317 guest_size_ = new_size; |
322 GuestSizeChangedDueToAutoSize(old_size, new_size); | 318 GuestSizeChangedDueToAutoSize(old_size, new_size); |
323 } | 319 } |
324 | 320 |
| 321 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { |
| 322 attach_params_.reset(params.DeepCopy()); |
| 323 attach_params_->GetInteger(guestview::kParameterInstanceId, |
| 324 &view_instance_id_); |
| 325 } |
| 326 |
325 void GuestViewBase::SetOpener(GuestViewBase* guest) { | 327 void GuestViewBase::SetOpener(GuestViewBase* guest) { |
326 if (guest && guest->IsViewType(GetViewType())) { | 328 if (guest && guest->IsViewType(GetViewType())) { |
327 opener_ = guest->AsWeakPtr(); | 329 opener_ = guest->AsWeakPtr(); |
328 return; | 330 return; |
329 } | 331 } |
330 opener_ = base::WeakPtr<GuestViewBase>(); | 332 opener_ = base::WeakPtr<GuestViewBase>(); |
331 } | 333 } |
332 | 334 |
333 void GuestViewBase::RegisterDestructionCallback( | 335 void GuestViewBase::RegisterDestructionCallback( |
334 const DestructionCallback& callback) { | 336 const DestructionCallback& callback) { |
335 destruction_callback_ = callback; | 337 destruction_callback_ = callback; |
336 } | 338 } |
337 | 339 |
338 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, | 340 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents) { |
339 const base::DictionaryValue& extra_params) { | |
340 // After attachment, this GuestViewBase's lifetime is restricted to the | 341 // After attachment, this GuestViewBase's lifetime is restricted to the |
341 // lifetime of its embedder WebContents. Observing the RenderProcessHost | 342 // lifetime of its embedder WebContents. Observing the RenderProcessHost |
342 // of the embedder is no longer necessary. | 343 // of the embedder is no longer necessary. |
343 embedder_web_contents->GetRenderProcessHost()->RemoveObserver(this); | 344 embedder_web_contents->GetRenderProcessHost()->RemoveObserver(this); |
344 embedder_web_contents_ = embedder_web_contents; | 345 embedder_web_contents_ = embedder_web_contents; |
345 embedder_web_contents_observer_.reset( | 346 embedder_web_contents_observer_.reset( |
346 new EmbedderWebContentsObserver(this)); | 347 new EmbedderWebContentsObserver(this)); |
347 extra_params.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); | |
348 extra_params_.reset(extra_params.DeepCopy()); | |
349 | 348 |
350 WillAttachToEmbedder(); | 349 WillAttachToEmbedder(); |
351 } | 350 } |
352 | 351 |
353 void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) { | 352 void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) { |
354 if (!IsDragAndDropEnabled()) { | 353 if (!IsDragAndDropEnabled()) { |
355 const char script[] = "window.addEventListener('dragstart', function() { " | 354 const char script[] = "window.addEventListener('dragstart', function() { " |
356 " window.event.preventDefault(); " | 355 " window.event.preventDefault(); " |
357 "});"; | 356 "});"; |
358 render_view_host->GetMainFrame()->ExecuteJavaScript( | 357 render_view_host->GetMainFrame()->ExecuteJavaScript( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 guest_web_contents); | 439 guest_web_contents); |
441 callback.Run(guest_web_contents); | 440 callback.Run(guest_web_contents); |
442 } | 441 } |
443 | 442 |
444 // static | 443 // static |
445 void GuestViewBase::RegisterGuestViewTypes() { | 444 void GuestViewBase::RegisterGuestViewTypes() { |
446 ExtensionsAPIClient::Get()->RegisterGuestViewTypes(); | 445 ExtensionsAPIClient::Get()->RegisterGuestViewTypes(); |
447 } | 446 } |
448 | 447 |
449 } // namespace extensions | 448 } // namespace extensions |
OLD | NEW |