| 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 430 |
| 431 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), | 431 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), |
| 432 destruction_observers_.end()); | 432 destruction_observers_.end()); |
| 433 } | 433 } |
| 434 | 434 |
| 435 WebContentsImpl* WebContentsImpl::CreateWithOpener( | 435 WebContentsImpl* WebContentsImpl::CreateWithOpener( |
| 436 const WebContents::CreateParams& params, | 436 const WebContents::CreateParams& params, |
| 437 WebContentsImpl* opener) { | 437 WebContentsImpl* opener) { |
| 438 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); | 438 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
| 439 WebContentsImpl* new_contents = new WebContentsImpl( | 439 WebContentsImpl* new_contents = new WebContentsImpl( |
| 440 params.browser_context, opener); | 440 params.browser_context, params.opener_suppressed ? NULL : opener); |
| 441 | 441 |
| 442 if (params.guest_instance_id) { | 442 if (params.guest_instance_id) { |
| 443 scoped_ptr<base::DictionaryValue> extra_params( | 443 scoped_ptr<base::DictionaryValue> extra_params; |
| 444 params.guest_extra_params->DeepCopy()); | 444 if (params.guest_extra_params) |
| 445 extra_params.reset(params.guest_extra_params->DeepCopy()); |
| 445 // This makes |new_contents| act as a guest. | 446 // This makes |new_contents| act as a guest. |
| 446 // For more info, see comment above class BrowserPluginGuest. | 447 // For more info, see comment above class BrowserPluginGuest. |
| 447 BrowserPluginGuest::Create(params.guest_instance_id, | 448 BrowserPluginGuest::Create(params.guest_instance_id, |
| 448 params.site_instance, | 449 params.site_instance, |
| 449 new_contents, | 450 new_contents, |
| 450 extra_params.Pass()); | 451 extra_params.Pass(), |
| 452 opener ? opener->GetBrowserPluginGuest() : NULL); |
| 451 // We are instantiating a WebContents for browser plugin. Set its subframe | 453 // We are instantiating a WebContents for browser plugin. Set its subframe |
| 452 // bit to true. | 454 // bit to true. |
| 453 new_contents->is_subframe_ = true; | 455 new_contents->is_subframe_ = true; |
| 454 } | 456 } |
| 455 new_contents->Init(params); | 457 new_contents->Init(params); |
| 456 return new_contents; | 458 return new_contents; |
| 457 } | 459 } |
| 458 | 460 |
| 459 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { | 461 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
| 460 return GetRenderManager(); | 462 return GetRenderManager(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 646 |
| 645 void WebContentsImpl::SendToAllFrames(IPC::Message* message) { | 647 void WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
| 646 ForEachFrame(base::Bind(&SendToAllFramesInternal, message)); | 648 ForEachFrame(base::Bind(&SendToAllFramesInternal, message)); |
| 647 delete message; | 649 delete message; |
| 648 } | 650 } |
| 649 | 651 |
| 650 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { | 652 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { |
| 651 return GetRenderManager()->current_host(); | 653 return GetRenderManager()->current_host(); |
| 652 } | 654 } |
| 653 | 655 |
| 654 WebContents* WebContentsImpl::GetEmbedderWebContents() const { | |
| 655 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | |
| 656 if (guest) | |
| 657 return guest->embedder_web_contents(); | |
| 658 return NULL; | |
| 659 } | |
| 660 | |
| 661 int WebContentsImpl::GetEmbeddedInstanceID() const { | |
| 662 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | |
| 663 if (guest) | |
| 664 return guest->instance_id(); | |
| 665 return 0; | |
| 666 } | |
| 667 | |
| 668 int WebContentsImpl::GetRoutingID() const { | 656 int WebContentsImpl::GetRoutingID() const { |
| 669 if (!GetRenderViewHost()) | 657 if (!GetRenderViewHost()) |
| 670 return MSG_ROUTING_NONE; | 658 return MSG_ROUTING_NONE; |
| 671 | 659 |
| 672 return GetRenderViewHost()->GetRoutingID(); | 660 return GetRenderViewHost()->GetRoutingID(); |
| 673 } | 661 } |
| 674 | 662 |
| 675 int WebContentsImpl::GetFullscreenWidgetRoutingID() const { | 663 int WebContentsImpl::GetFullscreenWidgetRoutingID() const { |
| 676 return fullscreen_widget_routing_id_; | 664 return fullscreen_widget_routing_id_; |
| 677 } | 665 } |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 Send(new ViewMsg_Close(route_id)); | 1384 Send(new ViewMsg_Close(route_id)); |
| 1397 } | 1385 } |
| 1398 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id); | 1386 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id); |
| 1399 GetRenderViewHost()->GetProcess()->ResumeRequestsForView( | 1387 GetRenderViewHost()->GetProcess()->ResumeRequestsForView( |
| 1400 main_frame_route_id); | 1388 main_frame_route_id); |
| 1401 return; | 1389 return; |
| 1402 } | 1390 } |
| 1403 | 1391 |
| 1404 // Create the new web contents. This will automatically create the new | 1392 // Create the new web contents. This will automatically create the new |
| 1405 // WebContentsView. In the future, we may want to create the view separately. | 1393 // WebContentsView. In the future, we may want to create the view separately. |
| 1406 WebContentsImpl* new_contents = | |
| 1407 new WebContentsImpl(GetBrowserContext(), | |
| 1408 params.opener_suppressed ? NULL : this); | |
| 1409 | |
| 1410 new_contents->GetController().SetSessionStorageNamespace( | |
| 1411 partition_id, | |
| 1412 session_storage_namespace); | |
| 1413 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1394 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
| 1414 create_params.routing_id = route_id; | 1395 create_params.routing_id = route_id; |
| 1415 create_params.main_frame_routing_id = main_frame_route_id; | 1396 create_params.main_frame_routing_id = main_frame_route_id; |
| 1397 create_params.opener = this; |
| 1398 create_params.opener_suppressed = params.opener_suppressed; |
| 1399 if (params.disposition == NEW_BACKGROUND_TAB) |
| 1400 create_params.initially_hidden = true; |
| 1401 |
| 1416 if (!is_guest) { | 1402 if (!is_guest) { |
| 1417 create_params.context = view_->GetNativeView(); | 1403 create_params.context = view_->GetNativeView(); |
| 1418 create_params.initial_size = GetContainerBounds().size(); | 1404 create_params.initial_size = GetContainerBounds().size(); |
| 1419 } else { | 1405 } else { |
| 1420 // This makes |new_contents| act as a guest. | 1406 create_params.guest_instance_id = |
| 1421 // For more info, see comment above class BrowserPluginGuest. | |
| 1422 int instance_id = | |
| 1423 GetBrowserContext()->GetGuestManager()->GetNextInstanceID(); | 1407 GetBrowserContext()->GetGuestManager()->GetNextInstanceID(); |
| 1424 WebContentsImpl* new_contents_impl = | |
| 1425 static_cast<WebContentsImpl*>(new_contents); | |
| 1426 BrowserPluginGuest::CreateWithOpener(instance_id, | |
| 1427 new_contents_impl->opener() != NULL, | |
| 1428 new_contents_impl, | |
| 1429 GetBrowserPluginGuest()); | |
| 1430 } | 1408 } |
| 1431 if (params.disposition == NEW_BACKGROUND_TAB) | 1409 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>( |
| 1432 create_params.initially_hidden = true; | 1410 WebContents::Create(create_params)); |
| 1433 new_contents->Init(create_params); | 1411 new_contents->GetController().SetSessionStorageNamespace( |
| 1412 partition_id, |
| 1413 session_storage_namespace); |
| 1434 new_contents->RenderViewCreated(new_contents->GetRenderViewHost()); | 1414 new_contents->RenderViewCreated(new_contents->GetRenderViewHost()); |
| 1435 | 1415 |
| 1436 // Save the window for later if we're not suppressing the opener (since it | 1416 // Save the window for later if we're not suppressing the opener (since it |
| 1437 // will be shown immediately). | 1417 // will be shown immediately). |
| 1438 if (!params.opener_suppressed) { | 1418 if (!params.opener_suppressed) { |
| 1439 if (!is_guest) { | 1419 if (!is_guest) { |
| 1440 WebContentsView* new_view = new_contents->view_.get(); | 1420 WebContentsView* new_view = new_contents->view_.get(); |
| 1441 | 1421 |
| 1442 // TODO(brettw): It seems bogus that we have to call this function on the | 1422 // TODO(brettw): It seems bogus that we have to call this function on the |
| 1443 // newly created object and give it one of its own member variables. | 1423 // newly created object and give it one of its own member variables. |
| (...skipping 2646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4090 | 4070 |
| 4091 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4071 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 4092 if (!delegate_) | 4072 if (!delegate_) |
| 4093 return; | 4073 return; |
| 4094 const gfx::Size new_size = GetPreferredSize(); | 4074 const gfx::Size new_size = GetPreferredSize(); |
| 4095 if (new_size != old_size) | 4075 if (new_size != old_size) |
| 4096 delegate_->UpdatePreferredSize(this, new_size); | 4076 delegate_->UpdatePreferredSize(this, new_size); |
| 4097 } | 4077 } |
| 4098 | 4078 |
| 4099 } // namespace content | 4079 } // namespace content |
| OLD | NEW |