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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) | 507 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
508 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse, | 508 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse, |
509 OnDomOperationResponse) | 509 OnDomOperationResponse) |
510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, | 510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
511 OnDocumentLoadedInFrame) | 511 OnDocumentLoadedInFrame) |
512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) | 512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
513 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) | 513 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) |
514 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) | 514 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) |
515 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, | 515 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, |
516 OnSetSelectedColorInColorChooser) | 516 OnSetSelectedColorInColorChooser) |
| 517 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification, |
| 518 OnMediaPlayingNotification) |
| 519 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification, |
| 520 OnMediaPausedNotification) |
517 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache, | 521 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache, |
518 OnDidLoadResourceFromMemoryCache) | 522 OnDidLoadResourceFromMemoryCache) |
519 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent, | 523 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent, |
520 OnDidDisplayInsecureContent) | 524 OnDidDisplayInsecureContent) |
521 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent, | 525 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent, |
522 OnDidRunInsecureContent) | 526 OnDidRunInsecureContent) |
523 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) | 527 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
524 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) | 528 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
525 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) | 529 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
526 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, | 530 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, |
527 OnRegisterProtocolHandler) | 531 OnRegisterProtocolHandler) |
528 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) | 532 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) |
529 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 533 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
530 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 534 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
531 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 535 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
532 OnRequestPpapiBrokerPermission) | 536 OnRequestPpapiBrokerPermission) |
533 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID, | 537 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID, |
534 OnBrowserPluginMessage(message)) | 538 OnBrowserPluginMessage(message)) |
535 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, | 539 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, |
536 OnBrowserPluginMessage(message)) | 540 OnBrowserPluginMessage(message)) |
537 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage) | 541 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage) |
538 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 542 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
539 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification, | |
540 OnMediaPlayingNotification) | |
541 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification, | |
542 OnMediaPausedNotification) | |
543 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, | 543 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
544 OnFirstVisuallyNonEmptyPaint) | 544 OnFirstVisuallyNonEmptyPaint) |
545 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, | 545 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, |
546 OnShowValidationMessage) | 546 OnShowValidationMessage) |
547 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, | 547 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, |
548 OnHideValidationMessage) | 548 OnHideValidationMessage) |
549 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, | 549 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, |
550 OnMoveValidationMessage) | 550 OnMoveValidationMessage) |
551 #if defined(OS_ANDROID) | 551 #if defined(OS_ANDROID) |
552 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply, | 552 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply, |
(...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2821 #if defined(OS_ANDROID) | 2821 #if defined(OS_ANDROID) |
2822 static_cast<PowerSaveBlockerImpl*>(blocker.get()) | 2822 static_cast<PowerSaveBlockerImpl*>(blocker.get()) |
2823 ->InitDisplaySleepBlocker(GetView()->GetNativeView()); | 2823 ->InitDisplaySleepBlocker(GetView()->GetNativeView()); |
2824 #endif | 2824 #endif |
2825 } else if (has_audio) { | 2825 } else if (has_audio) { |
2826 blocker = PowerSaveBlocker::Create( | 2826 blocker = PowerSaveBlocker::Create( |
2827 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio"); | 2827 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio"); |
2828 } | 2828 } |
2829 | 2829 |
2830 if (blocker) { | 2830 if (blocker) { |
2831 power_save_blockers_[render_view_message_source_][player_cookie] = | 2831 power_save_blockers_[render_frame_message_source_][player_cookie] = |
2832 blocker.release(); | 2832 blocker.release(); |
2833 } | 2833 } |
2834 #endif // !defined(OS_CHROMEOS) | 2834 #endif // !defined(OS_CHROMEOS) |
2835 } | 2835 } |
2836 | 2836 |
2837 void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) { | 2837 void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) { |
2838 // Chrome OS does its own detection of audio and video. | 2838 // Chrome OS does its own detection of audio and video. |
2839 #if !defined(OS_CHROMEOS) | 2839 #if !defined(OS_CHROMEOS) |
2840 delete power_save_blockers_[render_view_message_source_][player_cookie]; | 2840 delete power_save_blockers_[render_frame_message_source_][player_cookie]; |
2841 power_save_blockers_[render_view_message_source_].erase(player_cookie); | 2841 power_save_blockers_[render_frame_message_source_].erase(player_cookie); |
2842 #endif // !defined(OS_CHROMEOS) | 2842 #endif // !defined(OS_CHROMEOS) |
2843 } | 2843 } |
2844 | 2844 |
2845 void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) { | 2845 void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) { |
2846 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2846 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2847 DidFirstVisuallyNonEmptyPaint(page_id)); | 2847 DidFirstVisuallyNonEmptyPaint(page_id)); |
2848 } | 2848 } |
2849 | 2849 |
2850 void WebContentsImpl::DidChangeVisibleSSLState() { | 2850 void WebContentsImpl::DidChangeVisibleSSLState() { |
2851 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2851 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3040 | 3040 |
3041 void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { | 3041 void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
3042 // Note this is only for subframes, the notification for the main frame | 3042 // Note this is only for subframes, the notification for the main frame |
3043 // happens in RenderViewCreated. | 3043 // happens in RenderViewCreated. |
3044 FOR_EACH_OBSERVER(WebContentsObserver, | 3044 FOR_EACH_OBSERVER(WebContentsObserver, |
3045 observers_, | 3045 observers_, |
3046 RenderFrameCreated(render_frame_host)); | 3046 RenderFrameCreated(render_frame_host)); |
3047 } | 3047 } |
3048 | 3048 |
3049 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { | 3049 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
| 3050 ClearPowerSaveBlockers(render_frame_host); |
3050 FOR_EACH_OBSERVER(WebContentsObserver, | 3051 FOR_EACH_OBSERVER(WebContentsObserver, |
3051 observers_, | 3052 observers_, |
3052 RenderFrameDeleted(render_frame_host)); | 3053 RenderFrameDeleted(render_frame_host)); |
3053 } | 3054 } |
3054 | 3055 |
3055 void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) { | 3056 void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) { |
3056 if (delegate_) | 3057 if (delegate_) |
3057 delegate_->WorkerCrashed(this); | 3058 delegate_->WorkerCrashed(this); |
3058 } | 3059 } |
3059 | 3060 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3252 | 3253 |
3253 // Ensure fullscreen mode is exited in the |delegate_| since a crashed | 3254 // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
3254 // renderer may not have made a clean exit. | 3255 // renderer may not have made a clean exit. |
3255 if (IsFullscreenForCurrentTab()) | 3256 if (IsFullscreenForCurrentTab()) |
3256 ToggleFullscreenMode(false); | 3257 ToggleFullscreenMode(false); |
3257 | 3258 |
3258 // Cancel any visible dialogs so they are not left dangling over the sad tab. | 3259 // Cancel any visible dialogs so they are not left dangling over the sad tab. |
3259 if (dialog_manager_) | 3260 if (dialog_manager_) |
3260 dialog_manager_->CancelActiveAndPendingDialogs(this); | 3261 dialog_manager_->CancelActiveAndPendingDialogs(this); |
3261 | 3262 |
3262 ClearPowerSaveBlockers(rvh); | |
3263 SetIsLoading(rvh, false, true, NULL); | 3263 SetIsLoading(rvh, false, true, NULL); |
3264 NotifyDisconnected(); | 3264 NotifyDisconnected(); |
3265 SetIsCrashed(status, error_code); | 3265 SetIsCrashed(status, error_code); |
3266 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_); | 3266 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_); |
3267 | 3267 |
3268 FOR_EACH_OBSERVER(WebContentsObserver, | 3268 FOR_EACH_OBSERVER(WebContentsObserver, |
3269 observers_, | 3269 observers_, |
3270 RenderProcessGone(GetCrashedStatus())); | 3270 RenderProcessGone(GetCrashedStatus())); |
3271 } | 3271 } |
3272 | 3272 |
3273 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { | 3273 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
3274 ClearPowerSaveBlockers(rvh); | |
3275 GetRenderManager()->RenderViewDeleted(rvh); | 3274 GetRenderManager()->RenderViewDeleted(rvh); |
3276 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); | 3275 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); |
3277 } | 3276 } |
3278 | 3277 |
3279 void WebContentsImpl::UpdateState(RenderViewHost* rvh, | 3278 void WebContentsImpl::UpdateState(RenderViewHost* rvh, |
3280 int32 page_id, | 3279 int32 page_id, |
3281 const PageState& page_state) { | 3280 const PageState& page_state) { |
3282 // Ensure that this state update comes from either the active RVH or one of | 3281 // Ensure that this state update comes from either the active RVH or one of |
3283 // the swapped out RVHs. We don't expect to hear from any other RVHs. | 3282 // the swapped out RVHs. We don't expect to hear from any other RVHs. |
3284 // TODO(nasko): This should go through RenderFrameHost. | 3283 // TODO(nasko): This should go through RenderFrameHost. |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3887 } | 3886 } |
3888 | 3887 |
3889 BrowserPluginGuestManager* | 3888 BrowserPluginGuestManager* |
3890 WebContentsImpl::GetBrowserPluginGuestManager() const { | 3889 WebContentsImpl::GetBrowserPluginGuestManager() const { |
3891 return static_cast<BrowserPluginGuestManager*>( | 3890 return static_cast<BrowserPluginGuestManager*>( |
3892 GetBrowserContext()->GetUserData( | 3891 GetBrowserContext()->GetUserData( |
3893 browser_plugin::kBrowserPluginGuestManagerKeyName)); | 3892 browser_plugin::kBrowserPluginGuestManagerKeyName)); |
3894 } | 3893 } |
3895 | 3894 |
3896 void WebContentsImpl::ClearPowerSaveBlockers( | 3895 void WebContentsImpl::ClearPowerSaveBlockers( |
3897 RenderViewHost* render_view_host) { | 3896 RenderFrameHost* render_frame_host) { |
3898 STLDeleteValues(&power_save_blockers_[render_view_host]); | 3897 STLDeleteValues(&power_save_blockers_[render_frame_host]); |
3899 power_save_blockers_.erase(render_view_host); | 3898 power_save_blockers_.erase(render_frame_host); |
3900 } | 3899 } |
3901 | 3900 |
3902 void WebContentsImpl::ClearAllPowerSaveBlockers() { | 3901 void WebContentsImpl::ClearAllPowerSaveBlockers() { |
3903 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin()); | 3902 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin()); |
3904 i != power_save_blockers_.end(); ++i) | 3903 i != power_save_blockers_.end(); ++i) |
3905 STLDeleteValues(&power_save_blockers_[i->first]); | 3904 STLDeleteValues(&power_save_blockers_[i->first]); |
3906 power_save_blockers_.clear(); | 3905 power_save_blockers_.clear(); |
3907 } | 3906 } |
3908 | 3907 |
3909 gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { | 3908 gfx::Size WebContentsImpl::GetSizeForNewRenderView() const { |
(...skipping 14 matching lines...) Expand all Loading... |
3924 | 3923 |
3925 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3924 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3926 if (!delegate_) | 3925 if (!delegate_) |
3927 return; | 3926 return; |
3928 const gfx::Size new_size = GetPreferredSize(); | 3927 const gfx::Size new_size = GetPreferredSize(); |
3929 if (new_size != old_size) | 3928 if (new_size != old_size) |
3930 delegate_->UpdatePreferredSize(this, new_size); | 3929 delegate_->UpdatePreferredSize(this, new_size); |
3931 } | 3930 } |
3932 | 3931 |
3933 } // namespace content | 3932 } // namespace content |
OLD | NEW |