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 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2860 | 2860 |
2861 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, | 2861 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
2862 const ContextMenuParams& params) { | 2862 const ContextMenuParams& params) { |
2863 // Allow WebContentsDelegates to handle the context menu operation first. | 2863 // Allow WebContentsDelegates to handle the context menu operation first. |
2864 if (delegate_ && delegate_->HandleContextMenu(params)) | 2864 if (delegate_ && delegate_->HandleContextMenu(params)) |
2865 return; | 2865 return; |
2866 | 2866 |
2867 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params); | 2867 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params); |
2868 } | 2868 } |
2869 | 2869 |
| 2870 void WebContentsImpl::RunJavaScriptMessage( |
| 2871 RenderFrameHost* rfh, |
| 2872 const base::string16& message, |
| 2873 const base::string16& default_prompt, |
| 2874 const GURL& frame_url, |
| 2875 JavaScriptMessageType javascript_message_type, |
| 2876 IPC::Message* reply_msg, |
| 2877 bool* did_suppress_message) { |
| 2878 // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 2879 // showing an interstitial as it's shown over the previous page and we don't |
| 2880 // want the hidden page's dialogs to interfere with the interstitial. |
| 2881 bool suppress_this_message = |
| 2882 static_cast<RenderFrameHostImpl*>(rfh)->is_swapped_out() || |
| 2883 ShowingInterstitialPage() || |
| 2884 !delegate_ || |
| 2885 delegate_->ShouldSuppressDialogs() || |
| 2886 !delegate_->GetJavaScriptDialogManager(); |
| 2887 |
| 2888 if (!suppress_this_message) { |
| 2889 std::string accept_lang = GetContentClient()->browser()-> |
| 2890 GetAcceptLangs(GetBrowserContext()); |
| 2891 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
| 2892 dialog_manager_->RunJavaScriptDialog( |
| 2893 this, |
| 2894 frame_url.GetOrigin(), |
| 2895 accept_lang, |
| 2896 javascript_message_type, |
| 2897 message, |
| 2898 default_prompt, |
| 2899 base::Bind(&WebContentsImpl::OnDialogClosed, |
| 2900 base::Unretained(this), |
| 2901 rfh, |
| 2902 reply_msg), |
| 2903 &suppress_this_message); |
| 2904 } |
| 2905 |
| 2906 *did_suppress_message = suppress_this_message; |
| 2907 |
| 2908 if (suppress_this_message) { |
| 2909 // If we are suppressing messages, just reply as if the user immediately |
| 2910 // pressed "Cancel". |
| 2911 OnDialogClosed(rfh, reply_msg, false, base::string16()); |
| 2912 } |
| 2913 |
| 2914 // OnDialogClosed (two lines up) may have caused deletion of this object (see |
| 2915 // http://crbug.com/288961 ). The only safe thing to do here is return. |
| 2916 } |
| 2917 |
| 2918 void WebContentsImpl::RunBeforeUnloadConfirm( |
| 2919 RenderFrameHost* rfh, |
| 2920 const base::string16& message, |
| 2921 bool is_reload, |
| 2922 IPC::Message* reply_msg) { |
| 2923 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh); |
| 2924 RenderViewHostImpl* rvhi = |
| 2925 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost()); |
| 2926 if (delegate_) |
| 2927 delegate_->WillRunBeforeUnloadConfirm(); |
| 2928 |
| 2929 bool suppress_this_message = |
| 2930 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT || |
| 2931 !delegate_ || |
| 2932 delegate_->ShouldSuppressDialogs() || |
| 2933 !delegate_->GetJavaScriptDialogManager(); |
| 2934 if (suppress_this_message) { |
| 2935 // The reply must be sent to the RFH that sent the request. |
| 2936 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); |
| 2937 return; |
| 2938 } |
| 2939 |
| 2940 is_showing_before_unload_dialog_ = true; |
| 2941 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
| 2942 dialog_manager_->RunBeforeUnloadDialog( |
| 2943 this, message, is_reload, |
| 2944 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rfh, |
| 2945 reply_msg)); |
| 2946 } |
| 2947 |
2870 WebContents* WebContentsImpl::GetAsWebContents() { | 2948 WebContents* WebContentsImpl::GetAsWebContents() { |
2871 return this; | 2949 return this; |
2872 } | 2950 } |
2873 | 2951 |
2874 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { | 2952 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
2875 return render_view_host_delegate_view_; | 2953 return render_view_host_delegate_view_; |
2876 } | 2954 } |
2877 | 2955 |
2878 RendererPreferences WebContentsImpl::GetRendererPrefs( | 2956 RendererPreferences WebContentsImpl::GetRendererPrefs( |
2879 BrowserContext* browser_context) const { | 2957 BrowserContext* browser_context) const { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3244 new_params.source_routing_id = MSG_ROUTING_NONE; | 3322 new_params.source_routing_id = MSG_ROUTING_NONE; |
3245 } | 3323 } |
3246 } | 3324 } |
3247 | 3325 |
3248 // In most cases, we receive this from a swapped out RenderViewHost. | 3326 // In most cases, we receive this from a swapped out RenderViewHost. |
3249 // It is possible to receive it from one that has just been swapped in, | 3327 // It is possible to receive it from one that has just been swapped in, |
3250 // in which case we might as well deliver the message anyway. | 3328 // in which case we might as well deliver the message anyway. |
3251 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); | 3329 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); |
3252 } | 3330 } |
3253 | 3331 |
3254 void WebContentsImpl::RunJavaScriptMessage( | 3332 void WebContentsImpl::RunJavaScriptMessageOBSOLETE( |
3255 RenderViewHost* rvh, | 3333 RenderViewHost* rvh, |
3256 const base::string16& message, | 3334 const base::string16& message, |
3257 const base::string16& default_prompt, | 3335 const base::string16& default_prompt, |
3258 const GURL& frame_url, | 3336 const GURL& frame_url, |
3259 JavaScriptMessageType javascript_message_type, | 3337 JavaScriptMessageType javascript_message_type, |
3260 IPC::Message* reply_msg, | 3338 IPC::Message* reply_msg, |
3261 bool* did_suppress_message) { | 3339 bool* did_suppress_message) { |
3262 // Suppress JavaScript dialogs when requested. Also suppress messages when | 3340 // Suppress JavaScript dialogs when requested. Also suppress messages when |
3263 // showing an interstitial as it's shown over the previous page and we don't | 3341 // showing an interstitial as it's shown over the previous page and we don't |
3264 // want the hidden page's dialogs to interfere with the interstitial. | 3342 // want the hidden page's dialogs to interfere with the interstitial. |
3265 bool suppress_this_message = | 3343 bool suppress_this_message = |
3266 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() || | 3344 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() || |
3267 ShowingInterstitialPage() || | 3345 ShowingInterstitialPage() || |
3268 !delegate_ || | 3346 !delegate_ || |
3269 delegate_->ShouldSuppressDialogs() || | 3347 delegate_->ShouldSuppressDialogs() || |
3270 !delegate_->GetJavaScriptDialogManager(); | 3348 !delegate_->GetJavaScriptDialogManager(); |
3271 | 3349 |
3272 if (!suppress_this_message) { | 3350 if (!suppress_this_message) { |
3273 std::string accept_lang = GetContentClient()->browser()-> | 3351 std::string accept_lang = GetContentClient()->browser()-> |
3274 GetAcceptLangs(GetBrowserContext()); | 3352 GetAcceptLangs(GetBrowserContext()); |
3275 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); | 3353 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
3276 dialog_manager_->RunJavaScriptDialog( | 3354 dialog_manager_->RunJavaScriptDialog( |
3277 this, | 3355 this, |
3278 frame_url.GetOrigin(), | 3356 frame_url.GetOrigin(), |
3279 accept_lang, | 3357 accept_lang, |
3280 javascript_message_type, | 3358 javascript_message_type, |
3281 message, | 3359 message, |
3282 default_prompt, | 3360 default_prompt, |
3283 base::Bind(&WebContentsImpl::OnDialogClosed, | 3361 base::Bind(&WebContentsImpl::OnDialogClosedOBSOLETE, |
3284 base::Unretained(this), | 3362 base::Unretained(this), |
3285 rvh, | 3363 rvh, |
3286 reply_msg), | 3364 reply_msg), |
3287 &suppress_this_message); | 3365 &suppress_this_message); |
3288 } | 3366 } |
3289 | 3367 |
3290 *did_suppress_message = suppress_this_message; | 3368 *did_suppress_message = suppress_this_message; |
3291 | 3369 |
3292 if (suppress_this_message) { | 3370 if (suppress_this_message) { |
3293 // If we are suppressing messages, just reply as if the user immediately | 3371 // If we are suppressing messages, just reply as if the user immediately |
3294 // pressed "Cancel". | 3372 // pressed "Cancel". |
3295 OnDialogClosed(rvh, reply_msg, false, base::string16()); | 3373 OnDialogClosedOBSOLETE(rvh, reply_msg, false, base::string16()); |
3296 } | 3374 } |
3297 | 3375 |
3298 // OnDialogClosed (two lines up) may have caused deletion of this object (see | 3376 // OnDialogClosed (two lines up) may have caused deletion of this object (see |
3299 // http://crbug.com/288961 ). The only safe thing to do here is return. | 3377 // http://crbug.com/288961 ). The only safe thing to do here is return. |
3300 } | 3378 } |
3301 | 3379 |
3302 void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh, | 3380 void WebContentsImpl::RunBeforeUnloadConfirmOBSOLETE( |
3303 const base::string16& message, | 3381 RenderViewHost* rvh, |
3304 bool is_reload, | 3382 const base::string16& message, |
3305 IPC::Message* reply_msg) { | 3383 bool is_reload, |
| 3384 IPC::Message* reply_msg) { |
3306 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); | 3385 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
3307 if (delegate_) | 3386 if (delegate_) |
3308 delegate_->WillRunBeforeUnloadConfirm(); | 3387 delegate_->WillRunBeforeUnloadConfirm(); |
3309 | 3388 |
3310 bool suppress_this_message = | 3389 bool suppress_this_message = |
3311 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT || | 3390 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT || |
3312 !delegate_ || | 3391 !delegate_ || |
3313 delegate_->ShouldSuppressDialogs() || | 3392 delegate_->ShouldSuppressDialogs() || |
3314 !delegate_->GetJavaScriptDialogManager(); | 3393 !delegate_->GetJavaScriptDialogManager(); |
3315 if (suppress_this_message) { | 3394 if (suppress_this_message) { |
3316 // The reply must be sent to the RVH that sent the request. | 3395 // The reply must be sent to the RVH that sent the request. |
3317 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); | 3396 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); |
3318 return; | 3397 return; |
3319 } | 3398 } |
3320 | 3399 |
3321 is_showing_before_unload_dialog_ = true; | 3400 is_showing_before_unload_dialog_ = true; |
3322 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); | 3401 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
3323 dialog_manager_->RunBeforeUnloadDialog( | 3402 dialog_manager_->RunBeforeUnloadDialog( |
3324 this, message, is_reload, | 3403 this, message, is_reload, |
3325 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh, | 3404 base::Bind(&WebContentsImpl::OnDialogClosedOBSOLETE, |
| 3405 base::Unretained(this), |
| 3406 rvh, |
3326 reply_msg)); | 3407 reply_msg)); |
3327 } | 3408 } |
3328 | 3409 |
3329 bool WebContentsImpl::AddMessageToConsole(int32 level, | 3410 bool WebContentsImpl::AddMessageToConsole(int32 level, |
3330 const base::string16& message, | 3411 const base::string16& message, |
3331 int32 line_no, | 3412 int32 line_no, |
3332 const base::string16& source_id) { | 3413 const base::string16& source_id) { |
3333 if (!delegate_) | 3414 if (!delegate_) |
3334 return false; | 3415 return false; |
3335 return delegate_->AddMessageToConsole(this, level, message, line_no, | 3416 return delegate_->AddMessageToConsole(this, level, message, line_no, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3593 return web_contents_android->GetJavaObject(); | 3674 return web_contents_android->GetJavaObject(); |
3594 } | 3675 } |
3595 | 3676 |
3596 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { | 3677 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
3597 return CreateRenderViewForRenderManager(GetRenderViewHost(), | 3678 return CreateRenderViewForRenderManager(GetRenderViewHost(), |
3598 MSG_ROUTING_NONE, | 3679 MSG_ROUTING_NONE, |
3599 NULL); | 3680 NULL); |
3600 } | 3681 } |
3601 #endif | 3682 #endif |
3602 | 3683 |
3603 void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh, | 3684 void WebContentsImpl::OnDialogClosedOBSOLETE(RenderViewHost* rvh, |
3604 IPC::Message* reply_msg, | 3685 IPC::Message* reply_msg, |
3605 bool success, | 3686 bool success, |
3606 const base::string16& user_input) { | 3687 const base::string16& user_input) { |
3607 if (is_showing_before_unload_dialog_ && !success) { | 3688 if (is_showing_before_unload_dialog_ && !success) { |
3608 // If a beforeunload dialog is canceled, we need to stop the throbber from | 3689 // If a beforeunload dialog is canceled, we need to stop the throbber from |
3609 // spinning, since we forced it to start spinning in Navigate. | 3690 // spinning, since we forced it to start spinning in Navigate. |
3610 DidStopLoading(rvh->GetMainFrame()); | 3691 DidStopLoading(rvh->GetMainFrame()); |
3611 controller_.DiscardNonCommittedEntries(); | 3692 controller_.DiscardNonCommittedEntries(); |
3612 | 3693 |
3613 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3694 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3614 BeforeUnloadDialogCancelled()); | 3695 BeforeUnloadDialogCancelled()); |
3615 } | 3696 } |
3616 is_showing_before_unload_dialog_ = false; | 3697 is_showing_before_unload_dialog_ = false; |
3617 static_cast<RenderViewHostImpl*>( | 3698 static_cast<RenderViewHostImpl*>(rvh)-> |
3618 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input); | 3699 JavaScriptDialogClosed(reply_msg, success, user_input); |
| 3700 } |
| 3701 |
| 3702 void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh, |
| 3703 IPC::Message* reply_msg, |
| 3704 bool success, |
| 3705 const base::string16& user_input) { |
| 3706 if (is_showing_before_unload_dialog_ && !success) { |
| 3707 // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 3708 // spinning, since we forced it to start spinning in Navigate. |
| 3709 DidStopLoading(rfh); |
| 3710 controller_.DiscardNonCommittedEntries(); |
| 3711 |
| 3712 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3713 BeforeUnloadDialogCancelled()); |
| 3714 } |
| 3715 is_showing_before_unload_dialog_ = false; |
| 3716 static_cast<RenderFrameHostImpl*>(rfh)-> |
| 3717 JavaScriptDialogClosed(reply_msg, success, user_input); |
3619 } | 3718 } |
3620 | 3719 |
3621 void WebContentsImpl::SetEncoding(const std::string& encoding) { | 3720 void WebContentsImpl::SetEncoding(const std::string& encoding) { |
3622 encoding_ = GetContentClient()->browser()-> | 3721 encoding_ = GetContentClient()->browser()-> |
3623 GetCanonicalEncodingNameByAliasName(encoding); | 3722 GetCanonicalEncodingNameByAliasName(encoding); |
3624 } | 3723 } |
3625 | 3724 |
3626 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 3725 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
3627 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); | 3726 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); |
3628 // Can be NULL during tests. | 3727 // Can be NULL during tests. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3693 | 3792 |
3694 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3793 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3695 if (!delegate_) | 3794 if (!delegate_) |
3696 return; | 3795 return; |
3697 const gfx::Size new_size = GetPreferredSize(); | 3796 const gfx::Size new_size = GetPreferredSize(); |
3698 if (new_size != old_size) | 3797 if (new_size != old_size) |
3699 delegate_->UpdatePreferredSize(this, new_size); | 3798 delegate_->UpdatePreferredSize(this, new_size); |
3700 } | 3799 } |
3701 | 3800 |
3702 } // namespace content | 3801 } // namespace content |
OLD | NEW |