| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 420 |
| 421 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), | 421 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), |
| 422 destruction_observers_.end()); | 422 destruction_observers_.end()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 WebContentsImpl* WebContentsImpl::CreateWithOpener( | 425 WebContentsImpl* WebContentsImpl::CreateWithOpener( |
| 426 const WebContents::CreateParams& params, | 426 const WebContents::CreateParams& params, |
| 427 WebContentsImpl* opener) { | 427 WebContentsImpl* opener) { |
| 428 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); | 428 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
| 429 WebContentsImpl* new_contents = new WebContentsImpl( | 429 WebContentsImpl* new_contents = new WebContentsImpl( |
| 430 params.browser_context, opener); | 430 params.browser_context, params.opener_suppressed ? NULL : opener); |
| 431 | 431 |
| 432 if (params.guest_instance_id) { | 432 if (params.guest_instance_id) { |
| 433 scoped_ptr<base::DictionaryValue> extra_params( | 433 scoped_ptr<base::DictionaryValue> extra_params; |
| 434 params.guest_extra_params->DeepCopy()); | 434 if (params.guest_extra_params) |
| 435 extra_params.reset(params.guest_extra_params->DeepCopy()); |
| 435 // This makes |new_contents| act as a guest. | 436 // This makes |new_contents| act as a guest. |
| 436 // For more info, see comment above class BrowserPluginGuest. | 437 // For more info, see comment above class BrowserPluginGuest. |
| 437 BrowserPluginGuest::Create(params.guest_instance_id, | 438 BrowserPluginGuest::Create(params.guest_instance_id, |
| 438 params.site_instance, | 439 params.site_instance, |
| 439 new_contents, | 440 new_contents, |
| 440 extra_params.Pass()); | 441 extra_params.Pass(), |
| 442 opener ? opener->GetBrowserPluginGuest() : NULL); |
| 441 // We are instantiating a WebContents for browser plugin. Set its subframe | 443 // We are instantiating a WebContents for browser plugin. Set its subframe |
| 442 // bit to true. | 444 // bit to true. |
| 443 new_contents->is_subframe_ = true; | 445 new_contents->is_subframe_ = true; |
| 444 } | 446 } |
| 445 new_contents->Init(params); | 447 new_contents->Init(params); |
| 446 return new_contents; | 448 return new_contents; |
| 447 } | 449 } |
| 448 | 450 |
| 449 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { | 451 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
| 450 return GetRenderManager(); | 452 return GetRenderManager(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 638 |
| 637 void WebContentsImpl::SendToAllFrames(IPC::Message* message) { | 639 void WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
| 638 ForEachFrame(base::Bind(&SendToAllFramesInternal, message)); | 640 ForEachFrame(base::Bind(&SendToAllFramesInternal, message)); |
| 639 delete message; | 641 delete message; |
| 640 } | 642 } |
| 641 | 643 |
| 642 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { | 644 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { |
| 643 return GetRenderManager()->current_host(); | 645 return GetRenderManager()->current_host(); |
| 644 } | 646 } |
| 645 | 647 |
| 646 WebContents* WebContentsImpl::GetEmbedderWebContents() const { | |
| 647 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | |
| 648 if (guest) | |
| 649 return guest->embedder_web_contents(); | |
| 650 return NULL; | |
| 651 } | |
| 652 | |
| 653 int WebContentsImpl::GetEmbeddedInstanceID() const { | 648 int WebContentsImpl::GetEmbeddedInstanceID() const { |
| 654 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | 649 BrowserPluginGuest* guest = GetBrowserPluginGuest(); |
| 655 if (guest) | 650 if (guest) |
| 656 return guest->instance_id(); | 651 return guest->instance_id(); |
| 657 return 0; | 652 return 0; |
| 658 } | 653 } |
| 659 | 654 |
| 660 int WebContentsImpl::GetRoutingID() const { | 655 int WebContentsImpl::GetRoutingID() const { |
| 661 if (!GetRenderViewHost()) | 656 if (!GetRenderViewHost()) |
| 662 return MSG_ROUTING_NONE; | 657 return MSG_ROUTING_NONE; |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 Send(new ViewMsg_Close(route_id)); | 1385 Send(new ViewMsg_Close(route_id)); |
| 1391 } | 1386 } |
| 1392 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id); | 1387 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id); |
| 1393 GetRenderViewHost()->GetProcess()->ResumeRequestsForView( | 1388 GetRenderViewHost()->GetProcess()->ResumeRequestsForView( |
| 1394 main_frame_route_id); | 1389 main_frame_route_id); |
| 1395 return; | 1390 return; |
| 1396 } | 1391 } |
| 1397 | 1392 |
| 1398 // Create the new web contents. This will automatically create the new | 1393 // Create the new web contents. This will automatically create the new |
| 1399 // WebContentsView. In the future, we may want to create the view separately. | 1394 // WebContentsView. In the future, we may want to create the view separately. |
| 1400 WebContentsImpl* new_contents = | |
| 1401 new WebContentsImpl(GetBrowserContext(), | |
| 1402 params.opener_suppressed ? NULL : this); | |
| 1403 | |
| 1404 new_contents->GetController().SetSessionStorageNamespace( | |
| 1405 partition_id, | |
| 1406 session_storage_namespace); | |
| 1407 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1395 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
| 1408 create_params.routing_id = route_id; | 1396 create_params.routing_id = route_id; |
| 1409 create_params.main_frame_routing_id = main_frame_route_id; | 1397 create_params.main_frame_routing_id = main_frame_route_id; |
| 1398 create_params.opener = this; |
| 1399 create_params.opener_suppressed = params.opener_suppressed; |
| 1400 if (params.disposition == NEW_BACKGROUND_TAB) |
| 1401 create_params.initially_hidden = true; |
| 1402 |
| 1410 if (!is_guest) { | 1403 if (!is_guest) { |
| 1411 create_params.context = view_->GetNativeView(); | 1404 create_params.context = view_->GetNativeView(); |
| 1412 create_params.initial_size = GetContainerBounds().size(); | 1405 create_params.initial_size = GetContainerBounds().size(); |
| 1413 } else { | 1406 } else { |
| 1414 // This makes |new_contents| act as a guest. | 1407 create_params.guest_instance_id = |
| 1415 // For more info, see comment above class BrowserPluginGuest. | |
| 1416 int instance_id = | |
| 1417 GetBrowserContext()->GetGuestManager()->GetNextInstanceID(); | 1408 GetBrowserContext()->GetGuestManager()->GetNextInstanceID(); |
| 1418 WebContentsImpl* new_contents_impl = | |
| 1419 static_cast<WebContentsImpl*>(new_contents); | |
| 1420 BrowserPluginGuest::CreateWithOpener(instance_id, | |
| 1421 new_contents_impl->opener() != NULL, | |
| 1422 new_contents_impl, | |
| 1423 GetBrowserPluginGuest()); | |
| 1424 } | 1409 } |
| 1425 if (params.disposition == NEW_BACKGROUND_TAB) | 1410 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>( |
| 1426 create_params.initially_hidden = true; | 1411 WebContents::Create(create_params)); |
| 1427 new_contents->Init(create_params); | 1412 new_contents->GetController().SetSessionStorageNamespace( |
| 1413 partition_id, |
| 1414 session_storage_namespace); |
| 1428 | 1415 |
| 1429 // 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 |
| 1430 // will be shown immediately). | 1417 // will be shown immediately). |
| 1431 if (!params.opener_suppressed) { | 1418 if (!params.opener_suppressed) { |
| 1432 if (!is_guest) { | 1419 if (!is_guest) { |
| 1433 WebContentsView* new_view = new_contents->view_.get(); | 1420 WebContentsView* new_view = new_contents->view_.get(); |
| 1434 | 1421 |
| 1435 // 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 |
| 1436 // 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. |
| 1437 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 1424 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
| (...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3961 | 3948 |
| 3962 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3949 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 3963 if (!delegate_) | 3950 if (!delegate_) |
| 3964 return; | 3951 return; |
| 3965 const gfx::Size new_size = GetPreferredSize(); | 3952 const gfx::Size new_size = GetPreferredSize(); |
| 3966 if (new_size != old_size) | 3953 if (new_size != old_size) |
| 3967 delegate_->UpdatePreferredSize(this, new_size); | 3954 delegate_->UpdatePreferredSize(this, new_size); |
| 3968 } | 3955 } |
| 3969 | 3956 |
| 3970 } // namespace content | 3957 } // namespace content |
| OLD | NEW |