| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 last_active_time_(base::TimeTicks::Now()), | 331 last_active_time_(base::TimeTicks::Now()), |
| 332 closed_by_user_gesture_(false), | 332 closed_by_user_gesture_(false), |
| 333 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), | 333 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
| 334 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), | 334 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
| 335 temporary_zoom_settings_(false), | 335 temporary_zoom_settings_(false), |
| 336 totalPinchGestureAmount_(0), | 336 totalPinchGestureAmount_(0), |
| 337 currentPinchZoomStepDelta_(0), | 337 currentPinchZoomStepDelta_(0), |
| 338 color_chooser_identifier_(0), | 338 color_chooser_identifier_(0), |
| 339 render_view_message_source_(NULL), | 339 render_view_message_source_(NULL), |
| 340 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), | 340 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
| 341 is_subframe_(false) { | 341 is_subframe_(false), |
| 342 last_dialog_suppressed_(false) { |
| 342 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 343 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 343 g_created_callbacks.Get().at(i).Run(this); | 344 g_created_callbacks.Get().at(i).Run(this); |
| 344 frame_tree_.SetFrameRemoveListener( | 345 frame_tree_.SetFrameRemoveListener( |
| 345 base::Bind(&WebContentsImpl::OnFrameRemoved, | 346 base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 346 base::Unretained(this))); | 347 base::Unretained(this))); |
| 347 } | 348 } |
| 348 | 349 |
| 349 WebContentsImpl::~WebContentsImpl() { | 350 WebContentsImpl::~WebContentsImpl() { |
| 350 is_being_destroyed_ = true; | 351 is_being_destroyed_ = true; |
| 351 | 352 |
| (...skipping 2508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2860 | 2861 |
| 2861 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, | 2862 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 2862 const ContextMenuParams& params) { | 2863 const ContextMenuParams& params) { |
| 2863 // Allow WebContentsDelegates to handle the context menu operation first. | 2864 // Allow WebContentsDelegates to handle the context menu operation first. |
| 2864 if (delegate_ && delegate_->HandleContextMenu(params)) | 2865 if (delegate_ && delegate_->HandleContextMenu(params)) |
| 2865 return; | 2866 return; |
| 2866 | 2867 |
| 2867 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params); | 2868 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params); |
| 2868 } | 2869 } |
| 2869 | 2870 |
| 2871 void WebContentsImpl::RunJavaScriptMessage( |
| 2872 RenderFrameHost* rfh, |
| 2873 const base::string16& message, |
| 2874 const base::string16& default_prompt, |
| 2875 const GURL& frame_url, |
| 2876 JavaScriptMessageType javascript_message_type, |
| 2877 IPC::Message* reply_msg) { |
| 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<RenderViewHostImpl*>(rfh->GetRenderViewHost())-> |
| 2883 IsSwappedOut() || |
| 2884 ShowingInterstitialPage() || |
| 2885 !delegate_ || |
| 2886 delegate_->ShouldSuppressDialogs() || |
| 2887 !delegate_->GetJavaScriptDialogManager(); |
| 2888 |
| 2889 if (!suppress_this_message) { |
| 2890 std::string accept_lang = GetContentClient()->browser()-> |
| 2891 GetAcceptLangs(GetBrowserContext()); |
| 2892 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
| 2893 dialog_manager_->RunJavaScriptDialog( |
| 2894 this, |
| 2895 frame_url.GetOrigin(), |
| 2896 accept_lang, |
| 2897 javascript_message_type, |
| 2898 message, |
| 2899 default_prompt, |
| 2900 base::Bind(&WebContentsImpl::OnDialogClosed, |
| 2901 base::Unretained(this), |
| 2902 rfh, |
| 2903 reply_msg, |
| 2904 false), |
| 2905 &suppress_this_message); |
| 2906 } |
| 2907 |
| 2908 if (suppress_this_message) { |
| 2909 // If we are suppressing messages, just reply as if the user immediately |
| 2910 // pressed "Cancel", passing true to |dialog_was_suppressed|. |
| 2911 OnDialogClosed(rfh, reply_msg, true, 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 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); |
| 2936 return; |
| 2937 } |
| 2938 |
| 2939 is_showing_before_unload_dialog_ = true; |
| 2940 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
| 2941 dialog_manager_->RunBeforeUnloadDialog( |
| 2942 this, message, is_reload, |
| 2943 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 2944 rfh, reply_msg, false)); |
| 2945 } |
| 2946 |
| 2870 WebContents* WebContentsImpl::GetAsWebContents() { | 2947 WebContents* WebContentsImpl::GetAsWebContents() { |
| 2871 return this; | 2948 return this; |
| 2872 } | 2949 } |
| 2873 | 2950 |
| 2874 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { | 2951 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 2875 return render_view_host_delegate_view_; | 2952 return render_view_host_delegate_view_; |
| 2876 } | 2953 } |
| 2877 | 2954 |
| 2878 RendererPreferences WebContentsImpl::GetRendererPrefs( | 2955 RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 2879 BrowserContext* browser_context) const { | 2956 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; | 3321 new_params.source_routing_id = MSG_ROUTING_NONE; |
| 3245 } | 3322 } |
| 3246 } | 3323 } |
| 3247 | 3324 |
| 3248 // In most cases, we receive this from a swapped out RenderViewHost. | 3325 // 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, | 3326 // 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. | 3327 // in which case we might as well deliver the message anyway. |
| 3251 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); | 3328 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); |
| 3252 } | 3329 } |
| 3253 | 3330 |
| 3254 void WebContentsImpl::RunJavaScriptMessage( | |
| 3255 RenderViewHost* rvh, | |
| 3256 const base::string16& message, | |
| 3257 const base::string16& default_prompt, | |
| 3258 const GURL& frame_url, | |
| 3259 JavaScriptMessageType javascript_message_type, | |
| 3260 IPC::Message* reply_msg, | |
| 3261 bool* did_suppress_message) { | |
| 3262 // 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 | |
| 3264 // want the hidden page's dialogs to interfere with the interstitial. | |
| 3265 bool suppress_this_message = | |
| 3266 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() || | |
| 3267 ShowingInterstitialPage() || | |
| 3268 !delegate_ || | |
| 3269 delegate_->ShouldSuppressDialogs() || | |
| 3270 !delegate_->GetJavaScriptDialogManager(); | |
| 3271 | |
| 3272 if (!suppress_this_message) { | |
| 3273 std::string accept_lang = GetContentClient()->browser()-> | |
| 3274 GetAcceptLangs(GetBrowserContext()); | |
| 3275 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); | |
| 3276 dialog_manager_->RunJavaScriptDialog( | |
| 3277 this, | |
| 3278 frame_url.GetOrigin(), | |
| 3279 accept_lang, | |
| 3280 javascript_message_type, | |
| 3281 message, | |
| 3282 default_prompt, | |
| 3283 base::Bind(&WebContentsImpl::OnDialogClosed, | |
| 3284 base::Unretained(this), | |
| 3285 rvh, | |
| 3286 reply_msg), | |
| 3287 &suppress_this_message); | |
| 3288 } | |
| 3289 | |
| 3290 *did_suppress_message = suppress_this_message; | |
| 3291 | |
| 3292 if (suppress_this_message) { | |
| 3293 // If we are suppressing messages, just reply as if the user immediately | |
| 3294 // pressed "Cancel". | |
| 3295 OnDialogClosed(rvh, reply_msg, false, base::string16()); | |
| 3296 } | |
| 3297 | |
| 3298 // 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. | |
| 3300 } | |
| 3301 | |
| 3302 void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh, | |
| 3303 const base::string16& message, | |
| 3304 bool is_reload, | |
| 3305 IPC::Message* reply_msg) { | |
| 3306 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); | |
| 3307 if (delegate_) | |
| 3308 delegate_->WillRunBeforeUnloadConfirm(); | |
| 3309 | |
| 3310 bool suppress_this_message = | |
| 3311 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT || | |
| 3312 !delegate_ || | |
| 3313 delegate_->ShouldSuppressDialogs() || | |
| 3314 !delegate_->GetJavaScriptDialogManager(); | |
| 3315 if (suppress_this_message) { | |
| 3316 // The reply must be sent to the RVH that sent the request. | |
| 3317 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); | |
| 3318 return; | |
| 3319 } | |
| 3320 | |
| 3321 is_showing_before_unload_dialog_ = true; | |
| 3322 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); | |
| 3323 dialog_manager_->RunBeforeUnloadDialog( | |
| 3324 this, message, is_reload, | |
| 3325 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh, | |
| 3326 reply_msg)); | |
| 3327 } | |
| 3328 | |
| 3329 bool WebContentsImpl::AddMessageToConsole(int32 level, | 3331 bool WebContentsImpl::AddMessageToConsole(int32 level, |
| 3330 const base::string16& message, | 3332 const base::string16& message, |
| 3331 int32 line_no, | 3333 int32 line_no, |
| 3332 const base::string16& source_id) { | 3334 const base::string16& source_id) { |
| 3333 if (!delegate_) | 3335 if (!delegate_) |
| 3334 return false; | 3336 return false; |
| 3335 return delegate_->AddMessageToConsole(this, level, message, line_no, | 3337 return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 3336 source_id); | 3338 source_id); |
| 3337 } | 3339 } |
| 3338 | 3340 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3593 return web_contents_android->GetJavaObject(); | 3595 return web_contents_android->GetJavaObject(); |
| 3594 } | 3596 } |
| 3595 | 3597 |
| 3596 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { | 3598 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
| 3597 return CreateRenderViewForRenderManager(GetRenderViewHost(), | 3599 return CreateRenderViewForRenderManager(GetRenderViewHost(), |
| 3598 MSG_ROUTING_NONE, | 3600 MSG_ROUTING_NONE, |
| 3599 NULL); | 3601 NULL); |
| 3600 } | 3602 } |
| 3601 #endif | 3603 #endif |
| 3602 | 3604 |
| 3603 void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh, | 3605 void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh, |
| 3604 IPC::Message* reply_msg, | 3606 IPC::Message* reply_msg, |
| 3607 bool dialog_was_suppressed, |
| 3605 bool success, | 3608 bool success, |
| 3606 const base::string16& user_input) { | 3609 const base::string16& user_input) { |
| 3610 last_dialog_suppressed_ = dialog_was_suppressed; |
| 3611 |
| 3607 if (is_showing_before_unload_dialog_ && !success) { | 3612 if (is_showing_before_unload_dialog_ && !success) { |
| 3608 // If a beforeunload dialog is canceled, we need to stop the throbber from | 3613 // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 3609 // spinning, since we forced it to start spinning in Navigate. | 3614 // spinning, since we forced it to start spinning in Navigate. |
| 3610 DidStopLoading(rvh->GetMainFrame()); | 3615 DidStopLoading(rfh); |
| 3611 controller_.DiscardNonCommittedEntries(); | 3616 controller_.DiscardNonCommittedEntries(); |
| 3612 | 3617 |
| 3613 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3618 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3614 BeforeUnloadDialogCancelled()); | 3619 BeforeUnloadDialogCancelled()); |
| 3615 } | 3620 } |
| 3621 |
| 3616 is_showing_before_unload_dialog_ = false; | 3622 is_showing_before_unload_dialog_ = false; |
| 3617 static_cast<RenderViewHostImpl*>( | 3623 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed( |
| 3618 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input); | 3624 reply_msg, success, user_input, dialog_was_suppressed); |
| 3619 } | 3625 } |
| 3620 | 3626 |
| 3621 void WebContentsImpl::SetEncoding(const std::string& encoding) { | 3627 void WebContentsImpl::SetEncoding(const std::string& encoding) { |
| 3622 encoding_ = GetContentClient()->browser()-> | 3628 encoding_ = GetContentClient()->browser()-> |
| 3623 GetCanonicalEncodingNameByAliasName(encoding); | 3629 GetCanonicalEncodingNameByAliasName(encoding); |
| 3624 } | 3630 } |
| 3625 | 3631 |
| 3626 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 3632 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 3627 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); | 3633 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); |
| 3628 // Can be NULL during tests. | 3634 // Can be NULL during tests. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3693 | 3699 |
| 3694 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3700 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 3695 if (!delegate_) | 3701 if (!delegate_) |
| 3696 return; | 3702 return; |
| 3697 const gfx::Size new_size = GetPreferredSize(); | 3703 const gfx::Size new_size = GetPreferredSize(); |
| 3698 if (new_size != old_size) | 3704 if (new_size != old_size) |
| 3699 delegate_->UpdatePreferredSize(this, new_size); | 3705 delegate_->UpdatePreferredSize(this, new_size); |
| 3700 } | 3706 } |
| 3701 | 3707 |
| 3702 } // namespace content | 3708 } // namespace content |
| OLD | NEW |