OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 421 |
422 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), | 422 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), |
423 destruction_observers_.end()); | 423 destruction_observers_.end()); |
424 } | 424 } |
425 | 425 |
426 WebContentsImpl* WebContentsImpl::CreateWithOpener( | 426 WebContentsImpl* WebContentsImpl::CreateWithOpener( |
427 const WebContents::CreateParams& params, | 427 const WebContents::CreateParams& params, |
428 WebContentsImpl* opener) { | 428 WebContentsImpl* opener) { |
429 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); | 429 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
430 WebContentsImpl* new_contents = new WebContentsImpl( | 430 WebContentsImpl* new_contents = new WebContentsImpl( |
431 params.browser_context, opener); | 431 params.browser_context, params.opener_suppressed ? NULL : opener); |
432 | 432 |
433 if (params.guest_instance_id) { | 433 if (params.guest_instance_id) { |
434 scoped_ptr<base::DictionaryValue> extra_params( | 434 scoped_ptr<base::DictionaryValue> extra_params; |
435 params.guest_extra_params->DeepCopy()); | 435 if (params.guest_extra_params) |
| 436 extra_params.reset(params.guest_extra_params->DeepCopy()); |
436 // This makes |new_contents| act as a guest. | 437 // This makes |new_contents| act as a guest. |
437 // For more info, see comment above class BrowserPluginGuest. | 438 // For more info, see comment above class BrowserPluginGuest. |
438 BrowserPluginGuest::Create(params.guest_instance_id, | 439 BrowserPluginGuest::Create(params.guest_instance_id, |
439 params.site_instance, | 440 params.site_instance, |
440 new_contents, | 441 new_contents, |
441 extra_params.Pass()); | 442 extra_params.Pass(), |
| 443 opener ? opener->GetBrowserPluginGuest() : NULL); |
442 // We are instantiating a WebContents for browser plugin. Set its subframe | 444 // We are instantiating a WebContents for browser plugin. Set its subframe |
443 // bit to true. | 445 // bit to true. |
444 new_contents->is_subframe_ = true; | 446 new_contents->is_subframe_ = true; |
445 } | 447 } |
446 new_contents->Init(params); | 448 new_contents->Init(params); |
447 return new_contents; | 449 return new_contents; |
448 } | 450 } |
449 | 451 |
450 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { | 452 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
451 return GetRenderManager(); | 453 return GetRenderManager(); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 639 |
638 void WebContentsImpl::SendToAllFrames(IPC::Message* message) { | 640 void WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
639 ForEachFrame(base::Bind(&SendToAllFramesInternal, message)); | 641 ForEachFrame(base::Bind(&SendToAllFramesInternal, message)); |
640 delete message; | 642 delete message; |
641 } | 643 } |
642 | 644 |
643 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { | 645 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { |
644 return GetRenderManager()->current_host(); | 646 return GetRenderManager()->current_host(); |
645 } | 647 } |
646 | 648 |
647 WebContents* WebContentsImpl::GetEmbedderWebContents() const { | |
648 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | |
649 if (guest) | |
650 return guest->embedder_web_contents(); | |
651 return NULL; | |
652 } | |
653 | |
654 int WebContentsImpl::GetEmbeddedInstanceID() const { | |
655 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | |
656 if (guest) | |
657 return guest->instance_id(); | |
658 return 0; | |
659 } | |
660 | |
661 int WebContentsImpl::GetRoutingID() const { | 649 int WebContentsImpl::GetRoutingID() const { |
662 if (!GetRenderViewHost()) | 650 if (!GetRenderViewHost()) |
663 return MSG_ROUTING_NONE; | 651 return MSG_ROUTING_NONE; |
664 | 652 |
665 return GetRenderViewHost()->GetRoutingID(); | 653 return GetRenderViewHost()->GetRoutingID(); |
666 } | 654 } |
667 | 655 |
668 int WebContentsImpl::GetFullscreenWidgetRoutingID() const { | 656 int WebContentsImpl::GetFullscreenWidgetRoutingID() const { |
669 return fullscreen_widget_routing_id_; | 657 return fullscreen_widget_routing_id_; |
670 } | 658 } |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 Send(new ViewMsg_Close(route_id)); | 1382 Send(new ViewMsg_Close(route_id)); |
1395 } | 1383 } |
1396 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id); | 1384 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id); |
1397 GetRenderViewHost()->GetProcess()->ResumeRequestsForView( | 1385 GetRenderViewHost()->GetProcess()->ResumeRequestsForView( |
1398 main_frame_route_id); | 1386 main_frame_route_id); |
1399 return; | 1387 return; |
1400 } | 1388 } |
1401 | 1389 |
1402 // Create the new web contents. This will automatically create the new | 1390 // Create the new web contents. This will automatically create the new |
1403 // WebContentsView. In the future, we may want to create the view separately. | 1391 // WebContentsView. In the future, we may want to create the view separately. |
1404 WebContentsImpl* new_contents = | |
1405 new WebContentsImpl(GetBrowserContext(), | |
1406 params.opener_suppressed ? NULL : this); | |
1407 | |
1408 new_contents->GetController().SetSessionStorageNamespace( | |
1409 partition_id, | |
1410 session_storage_namespace); | |
1411 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1392 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
1412 create_params.routing_id = route_id; | 1393 create_params.routing_id = route_id; |
1413 create_params.main_frame_routing_id = main_frame_route_id; | 1394 create_params.main_frame_routing_id = main_frame_route_id; |
| 1395 create_params.opener = this; |
| 1396 create_params.opener_suppressed = params.opener_suppressed; |
| 1397 if (params.disposition == NEW_BACKGROUND_TAB) |
| 1398 create_params.initially_hidden = true; |
| 1399 |
1414 if (!is_guest) { | 1400 if (!is_guest) { |
1415 create_params.context = view_->GetNativeView(); | 1401 create_params.context = view_->GetNativeView(); |
1416 create_params.initial_size = GetContainerBounds().size(); | 1402 create_params.initial_size = GetContainerBounds().size(); |
1417 } else { | 1403 } else { |
1418 // This makes |new_contents| act as a guest. | 1404 create_params.guest_instance_id = |
1419 // For more info, see comment above class BrowserPluginGuest. | |
1420 int instance_id = | |
1421 GetBrowserContext()->GetGuestManager()->GetNextInstanceID(); | 1405 GetBrowserContext()->GetGuestManager()->GetNextInstanceID(); |
1422 WebContentsImpl* new_contents_impl = | |
1423 static_cast<WebContentsImpl*>(new_contents); | |
1424 BrowserPluginGuest::CreateWithOpener(instance_id, | |
1425 new_contents_impl->opener() != NULL, | |
1426 new_contents_impl, | |
1427 GetBrowserPluginGuest()); | |
1428 } | 1406 } |
1429 if (params.disposition == NEW_BACKGROUND_TAB) | 1407 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>( |
1430 create_params.initially_hidden = true; | 1408 WebContents::Create(create_params)); |
1431 new_contents->Init(create_params); | 1409 new_contents->GetController().SetSessionStorageNamespace( |
| 1410 partition_id, |
| 1411 session_storage_namespace); |
1432 | 1412 |
1433 // Save the window for later if we're not suppressing the opener (since it | 1413 // Save the window for later if we're not suppressing the opener (since it |
1434 // will be shown immediately). | 1414 // will be shown immediately). |
1435 if (!params.opener_suppressed) { | 1415 if (!params.opener_suppressed) { |
1436 if (!is_guest) { | 1416 if (!is_guest) { |
1437 WebContentsView* new_view = new_contents->view_.get(); | 1417 WebContentsView* new_view = new_contents->view_.get(); |
1438 | 1418 |
1439 // TODO(brettw): It seems bogus that we have to call this function on the | 1419 // TODO(brettw): It seems bogus that we have to call this function on the |
1440 // newly created object and give it one of its own member variables. | 1420 // newly created object and give it one of its own member variables. |
1441 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 1421 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
(...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3965 | 3945 |
3966 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3946 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3967 if (!delegate_) | 3947 if (!delegate_) |
3968 return; | 3948 return; |
3969 const gfx::Size new_size = GetPreferredSize(); | 3949 const gfx::Size new_size = GetPreferredSize(); |
3970 if (new_size != old_size) | 3950 if (new_size != old_size) |
3971 delegate_->UpdatePreferredSize(this, new_size); | 3951 delegate_->UpdatePreferredSize(this, new_size); |
3972 } | 3952 } |
3973 | 3953 |
3974 } // namespace content | 3954 } // namespace content |
OLD | NEW |