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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 fullscreen_widget_had_focus_at_shutdown_(false), | 356 fullscreen_widget_had_focus_at_shutdown_(false), |
357 is_subframe_(false), | 357 is_subframe_(false), |
358 force_disable_overscroll_content_(false), | 358 force_disable_overscroll_content_(false), |
359 last_dialog_suppressed_(false), | 359 last_dialog_suppressed_(false), |
360 geolocation_service_context_(new GeolocationServiceContext()), | 360 geolocation_service_context_(new GeolocationServiceContext()), |
361 accessibility_mode_( | 361 accessibility_mode_( |
362 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), | 362 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
363 audio_stream_monitor_(this), | 363 audio_stream_monitor_(this), |
364 virtual_keyboard_requested_(false), | 364 virtual_keyboard_requested_(false), |
365 loading_weak_factory_(this) { | 365 loading_weak_factory_(this) { |
| 366 LOG(ERROR) << "WC[" << this << "]::WC"; |
366 frame_tree_.SetFrameRemoveListener( | 367 frame_tree_.SetFrameRemoveListener( |
367 base::Bind(&WebContentsImpl::OnFrameRemoved, | 368 base::Bind(&WebContentsImpl::OnFrameRemoved, |
368 base::Unretained(this))); | 369 base::Unretained(this))); |
369 #if defined(ENABLE_BROWSER_CDMS) | 370 #if defined(ENABLE_BROWSER_CDMS) |
370 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); | 371 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
371 #endif | 372 #endif |
372 } | 373 } |
373 | 374 |
374 WebContentsImpl::~WebContentsImpl() { | 375 WebContentsImpl::~WebContentsImpl() { |
375 is_being_destroyed_ = true; | 376 is_being_destroyed_ = true; |
(...skipping 25 matching lines...) Expand all Loading... |
401 NOTIFICATION_WEB_CONTENTS_DESTROYED, | 402 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
402 Source<WebContents>(this), | 403 Source<WebContents>(this), |
403 NotificationService::NoDetails()); | 404 NotificationService::NoDetails()); |
404 | 405 |
405 // Destroy all frame tree nodes except for the root; this notifies observers. | 406 // Destroy all frame tree nodes except for the root; this notifies observers. |
406 frame_tree_.ResetForMainFrameSwap(); | 407 frame_tree_.ResetForMainFrameSwap(); |
407 GetRenderManager()->ResetProxyHosts(); | 408 GetRenderManager()->ResetProxyHosts(); |
408 | 409 |
409 // Manually call the observer methods for the root frame tree node. | 410 // Manually call the observer methods for the root frame tree node. |
410 RenderFrameHostManager* root = GetRenderManager(); | 411 RenderFrameHostManager* root = GetRenderManager(); |
411 if (root->pending_frame_host()) { | |
412 FOR_EACH_OBSERVER(WebContentsObserver, | |
413 observers_, | |
414 RenderFrameDeleted(root->pending_frame_host())); | |
415 } | |
416 FOR_EACH_OBSERVER(WebContentsObserver, | |
417 observers_, | |
418 RenderFrameDeleted(root->current_frame_host())); | |
419 | |
420 if (root->pending_render_view_host()) { | 412 if (root->pending_render_view_host()) { |
421 FOR_EACH_OBSERVER(WebContentsObserver, | 413 FOR_EACH_OBSERVER(WebContentsObserver, |
422 observers_, | 414 observers_, |
423 RenderViewDeleted(root->pending_render_view_host())); | 415 RenderViewDeleted(root->pending_render_view_host())); |
424 } | 416 } |
425 | 417 |
426 FOR_EACH_OBSERVER(WebContentsObserver, | 418 FOR_EACH_OBSERVER(WebContentsObserver, |
427 observers_, | 419 observers_, |
428 RenderViewDeleted(root->current_host())); | 420 RenderViewDeleted(root->current_host())); |
429 | 421 |
430 FOR_EACH_OBSERVER(WebContentsObserver, | 422 FOR_EACH_OBSERVER(WebContentsObserver, |
431 observers_, | 423 observers_, |
432 WebContentsDestroyed()); | 424 WebContentsDestroyed()); |
433 | 425 |
434 FOR_EACH_OBSERVER(WebContentsObserver, | 426 FOR_EACH_OBSERVER(WebContentsObserver, |
435 observers_, | 427 observers_, |
436 ResetWebContents()); | 428 ResetWebContents()); |
437 | 429 |
438 SetDelegate(NULL); | 430 SetDelegate(NULL); |
439 | 431 |
440 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), | 432 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), |
441 destruction_observers_.end()); | 433 destruction_observers_.end()); |
| 434 LOG(ERROR) << "WC[" << this << "]::~WC"; |
442 } | 435 } |
443 | 436 |
444 WebContentsImpl* WebContentsImpl::CreateWithOpener( | 437 WebContentsImpl* WebContentsImpl::CreateWithOpener( |
445 const WebContents::CreateParams& params, | 438 const WebContents::CreateParams& params, |
446 WebContentsImpl* opener) { | 439 WebContentsImpl* opener) { |
447 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); | 440 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
448 WebContentsImpl* new_contents = new WebContentsImpl( | 441 WebContentsImpl* new_contents = new WebContentsImpl( |
449 params.browser_context, params.opener_suppressed ? NULL : opener); | 442 params.browser_context, params.opener_suppressed ? NULL : opener); |
450 | 443 |
451 if (params.guest_delegate) { | 444 if (params.guest_delegate) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 const IPC::Message& message) { | 491 const IPC::Message& message) { |
499 DCHECK(render_view_host || render_frame_host); | 492 DCHECK(render_view_host || render_frame_host); |
500 if (GetWebUI() && | 493 if (GetWebUI() && |
501 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { | 494 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
502 return true; | 495 return true; |
503 } | 496 } |
504 | 497 |
505 ObserverListBase<WebContentsObserver>::Iterator it(observers_); | 498 ObserverListBase<WebContentsObserver>::Iterator it(observers_); |
506 WebContentsObserver* observer; | 499 WebContentsObserver* observer; |
507 if (render_frame_host) { | 500 if (render_frame_host) { |
508 while ((observer = it.GetNext()) != NULL) | 501 if (!static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out())
{ |
509 if (observer->OnMessageReceived(message, render_frame_host)) | 502 while ((observer = it.GetNext()) != NULL) |
510 return true; | 503 if (observer->OnMessageReceived(message, render_frame_host)) |
| 504 return true; |
| 505 } |
511 } else { | 506 } else { |
512 while ((observer = it.GetNext()) != NULL) | 507 while ((observer = it.GetNext()) != NULL) |
513 if (observer->OnMessageReceived(message)) | 508 if (observer->OnMessageReceived(message)) |
514 return true; | 509 return true; |
515 } | 510 } |
516 | 511 |
517 // Message handlers should be aware of which | 512 // Message handlers should be aware of which |
518 // RenderViewHost/RenderFrameHost sent the message, which is temporarily | 513 // RenderViewHost/RenderFrameHost sent the message, which is temporarily |
519 // stored in render_(view|frame)_message_source_. | 514 // stored in render_(view|frame)_message_source_. |
520 if (render_frame_host) | 515 if (render_frame_host) |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 default: | 1188 default: |
1194 NOTREACHED(); | 1189 NOTREACHED(); |
1195 } | 1190 } |
1196 } | 1191 } |
1197 | 1192 |
1198 WebContents* WebContentsImpl::GetWebContents() { | 1193 WebContents* WebContentsImpl::GetWebContents() { |
1199 return this; | 1194 return this; |
1200 } | 1195 } |
1201 | 1196 |
1202 void WebContentsImpl::Init(const WebContents::CreateParams& params) { | 1197 void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
| 1198 LOG(ERROR) << "WC[" << this << "]::Init"; |
| 1199 |
1203 // This is set before initializing the render manager since | 1200 // This is set before initializing the render manager since |
1204 // RenderFrameHostManager::Init calls back into us via its delegate to ask if | 1201 // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
1205 // it should be hidden. | 1202 // it should be hidden. |
1206 should_normally_be_visible_ = !params.initially_hidden; | 1203 should_normally_be_visible_ = !params.initially_hidden; |
1207 | 1204 |
1208 // Either both routing ids can be given, or neither can be. | 1205 // Either both routing ids can be given, or neither can be. |
1209 DCHECK((params.routing_id == MSG_ROUTING_NONE && | 1206 DCHECK((params.routing_id == MSG_ROUTING_NONE && |
1210 params.main_frame_routing_id == MSG_ROUTING_NONE) || | 1207 params.main_frame_routing_id == MSG_ROUTING_NONE) || |
1211 (params.routing_id != MSG_ROUTING_NONE && | 1208 (params.routing_id != MSG_ROUTING_NONE && |
1212 params.main_frame_routing_id != MSG_ROUTING_NONE)); | 1209 params.main_frame_routing_id != MSG_ROUTING_NONE)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 date_time_chooser_.reset(new DateTimeChooserAndroid()); | 1256 date_time_chooser_.reset(new DateTimeChooserAndroid()); |
1260 #endif | 1257 #endif |
1261 | 1258 |
1262 // BrowserPluginGuest::Init needs to be called after this WebContents has | 1259 // BrowserPluginGuest::Init needs to be called after this WebContents has |
1263 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. | 1260 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
1264 if (browser_plugin_guest_) | 1261 if (browser_plugin_guest_) |
1265 browser_plugin_guest_->Init(); | 1262 browser_plugin_guest_->Init(); |
1266 | 1263 |
1267 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 1264 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
1268 g_created_callbacks.Get().at(i).Run(this); | 1265 g_created_callbacks.Get().at(i).Run(this); |
| 1266 |
| 1267 NotifySwappedFromRenderManager( |
| 1268 nullptr, GetRenderManager()->current_frame_host(), true); |
1269 } | 1269 } |
1270 | 1270 |
1271 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 1271 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
1272 RemoveDestructionObserver(web_contents); | 1272 RemoveDestructionObserver(web_contents); |
1273 | 1273 |
1274 // Clear the opener if it has been closed. | 1274 // Clear the opener if it has been closed. |
1275 if (web_contents == opener_) { | 1275 if (web_contents == opener_) { |
1276 opener_ = NULL; | 1276 opener_ = NULL; |
1277 return; | 1277 return; |
1278 } | 1278 } |
(...skipping 2313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3592 | 3592 |
3593 void WebContentsImpl::RemoveBrowserPluginEmbedder() { | 3593 void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
3594 if (browser_plugin_embedder_) | 3594 if (browser_plugin_embedder_) |
3595 browser_plugin_embedder_.reset(); | 3595 browser_plugin_embedder_.reset(); |
3596 } | 3596 } |
3597 | 3597 |
3598 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 3598 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
3599 // Don't send notifications if we are just creating a swapped-out RVH for | 3599 // Don't send notifications if we are just creating a swapped-out RVH for |
3600 // the opener chain. These won't be used for view-source or WebUI, so it's | 3600 // the opener chain. These won't be used for view-source or WebUI, so it's |
3601 // ok to return early. | 3601 // ok to return early. |
3602 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active()) | 3602 bool rvh_is_active = |
3603 return; | 3603 static_cast<RenderViewHostImpl*>(render_view_host)->is_active(); |
3604 | 3604 |
3605 if (delegate_) | 3605 if (rvh_is_active) { |
3606 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 3606 if (delegate_) |
| 3607 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
3607 | 3608 |
3608 NotificationService::current()->Notify( | 3609 NotificationService::current()->Notify( |
3609 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 3610 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
3610 Source<WebContents>(this), | 3611 Source<WebContents>(this), |
3611 Details<RenderViewHost>(render_view_host)); | 3612 Details<RenderViewHost>(render_view_host)); |
3612 | 3613 |
3613 // When we're creating views, we're still doing initial setup, so we always | 3614 // When we're creating views, we're still doing initial setup, so we always |
3614 // use the pending Web UI rather than any possibly existing committed one. | 3615 // use the pending Web UI rather than any possibly existing committed one. |
3615 if (GetRenderManager()->pending_web_ui()) | 3616 if (GetRenderManager()->pending_web_ui()) |
3616 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host); | 3617 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host); |
3617 | 3618 |
3618 NavigationEntry* entry = controller_.GetPendingEntry(); | 3619 NavigationEntry* entry = controller_.GetPendingEntry(); |
3619 if (entry && entry->IsViewSourceMode()) { | 3620 if (entry && entry->IsViewSourceMode()) { |
3620 // Put the renderer in view source mode. | 3621 // Put the renderer in view source mode. |
3621 render_view_host->Send( | 3622 render_view_host->Send( |
3622 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 3623 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
| 3624 } |
| 3625 |
| 3626 view_->RenderViewCreated(render_view_host); |
| 3627 |
| 3628 FOR_EACH_OBSERVER( |
| 3629 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
3623 } | 3630 } |
3624 | 3631 |
3625 view_->RenderViewCreated(render_view_host); | 3632 RenderFrameHostImpl* rfh = |
| 3633 static_cast<RenderFrameHostImpl*>(render_view_host->GetMainFrame()); |
| 3634 rfh->SetRenderFrameCreated(true); |
3626 | 3635 |
3627 FOR_EACH_OBSERVER( | 3636 if (rvh_is_active) |
3628 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 3637 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); |
3629 | |
3630 // We tell the observers now instead of when the main RenderFrameHostImpl is | |
3631 // constructed because otherwise it would be too early (i.e. IPCs sent to the | |
3632 // frame would be dropped because it's not created yet). | |
3633 RenderFrameHost* main_frame = render_view_host->GetMainFrame(); | |
3634 FOR_EACH_OBSERVER( | |
3635 WebContentsObserver, observers_, RenderFrameCreated(main_frame)); | |
3636 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame); | |
3637 | |
3638 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); | |
3639 } | 3638 } |
3640 | 3639 |
3641 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { | 3640 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
3642 if (rvh != GetRenderViewHost()) { | 3641 if (rvh != GetRenderViewHost()) { |
3643 // Don't notify the world, since this came from a renderer in the | 3642 // Don't notify the world, since this came from a renderer in the |
3644 // background. | 3643 // background. |
3645 return; | 3644 return; |
3646 } | 3645 } |
3647 | 3646 |
3648 notify_disconnection_ = true; | 3647 notify_disconnection_ = true; |
(...skipping 12 matching lines...) Expand all Loading... |
3661 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { | 3660 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
3662 view_->Focus(); | 3661 view_->Focus(); |
3663 } | 3662 } |
3664 | 3663 |
3665 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); | 3664 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
3666 } | 3665 } |
3667 | 3666 |
3668 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, | 3667 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
3669 base::TerminationStatus status, | 3668 base::TerminationStatus status, |
3670 int error_code) { | 3669 int error_code) { |
3671 // TODO(nasko): This isn't ideal; the termination process should be handled by | |
3672 // RenderFrameDeleted(). See http://crbug.com/455943. | |
3673 ClearPowerSaveBlockers(rvh->GetMainFrame()); | |
3674 | |
3675 if (rvh != GetRenderViewHost()) { | 3670 if (rvh != GetRenderViewHost()) { |
3676 // The pending page's RenderViewHost is gone. | 3671 // The pending page's RenderViewHost is gone. |
3677 return; | 3672 return; |
3678 } | 3673 } |
3679 | 3674 |
3680 // Ensure fullscreen mode is exited in the |delegate_| since a crashed | 3675 // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
3681 // renderer may not have made a clean exit. | 3676 // renderer may not have made a clean exit. |
3682 if (IsFullscreenForCurrentTab()) | 3677 if (IsFullscreenForCurrentTab()) |
3683 ExitFullscreenMode(); | 3678 ExitFullscreenMode(); |
3684 | 3679 |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4476 node->render_manager()->ResumeResponseDeferredAtStart(); | 4471 node->render_manager()->ResumeResponseDeferredAtStart(); |
4477 } | 4472 } |
4478 | 4473 |
4479 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4474 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4480 force_disable_overscroll_content_ = force_disable; | 4475 force_disable_overscroll_content_ = force_disable; |
4481 if (view_) | 4476 if (view_) |
4482 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4477 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4483 } | 4478 } |
4484 | 4479 |
4485 } // namespace content | 4480 } // namespace content |
OLD | NEW |