| 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 3050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3061 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); | 3061 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
| 3062 dialog_manager_->RunJavaScriptDialog( | 3062 dialog_manager_->RunJavaScriptDialog( |
| 3063 this, | 3063 this, |
| 3064 frame_url.GetOrigin(), | 3064 frame_url.GetOrigin(), |
| 3065 accept_lang, | 3065 accept_lang, |
| 3066 javascript_message_type, | 3066 javascript_message_type, |
| 3067 message, | 3067 message, |
| 3068 default_prompt, | 3068 default_prompt, |
| 3069 base::Bind(&WebContentsImpl::OnDialogClosed, | 3069 base::Bind(&WebContentsImpl::OnDialogClosed, |
| 3070 base::Unretained(this), | 3070 base::Unretained(this), |
| 3071 rfh->GetProcess()->GetID(), | 3071 rfh, |
| 3072 rfh->GetRoutingID(), | |
| 3073 reply_msg, | 3072 reply_msg, |
| 3074 false), | 3073 false), |
| 3075 &suppress_this_message); | 3074 &suppress_this_message); |
| 3076 } | 3075 } |
| 3077 | 3076 |
| 3078 if (suppress_this_message) { | 3077 if (suppress_this_message) { |
| 3079 // If we are suppressing messages, just reply as if the user immediately | 3078 // If we are suppressing messages, just reply as if the user immediately |
| 3080 // pressed "Cancel", passing true to |dialog_was_suppressed|. | 3079 // pressed "Cancel", passing true to |dialog_was_suppressed|. |
| 3081 OnDialogClosed(rfh->GetProcess()->GetID(), rfh->GetRoutingID(), reply_msg, | 3080 OnDialogClosed(rfh, reply_msg, true, false, base::string16()); |
| 3082 true, false, base::string16()); | |
| 3083 } | 3081 } |
| 3084 | 3082 |
| 3085 // OnDialogClosed (two lines up) may have caused deletion of this object (see | 3083 // OnDialogClosed (two lines up) may have caused deletion of this object (see |
| 3086 // http://crbug.com/288961 ). The only safe thing to do here is return. | 3084 // http://crbug.com/288961 ). The only safe thing to do here is return. |
| 3087 } | 3085 } |
| 3088 | 3086 |
| 3089 void WebContentsImpl::RunBeforeUnloadConfirm( | 3087 void WebContentsImpl::RunBeforeUnloadConfirm( |
| 3090 RenderFrameHost* rfh, | 3088 RenderFrameHost* rfh, |
| 3091 const base::string16& message, | 3089 const base::string16& message, |
| 3092 bool is_reload, | 3090 bool is_reload, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3105 if (suppress_this_message) { | 3103 if (suppress_this_message) { |
| 3106 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); | 3104 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); |
| 3107 return; | 3105 return; |
| 3108 } | 3106 } |
| 3109 | 3107 |
| 3110 is_showing_before_unload_dialog_ = true; | 3108 is_showing_before_unload_dialog_ = true; |
| 3111 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); | 3109 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
| 3112 dialog_manager_->RunBeforeUnloadDialog( | 3110 dialog_manager_->RunBeforeUnloadDialog( |
| 3113 this, message, is_reload, | 3111 this, message, is_reload, |
| 3114 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), | 3112 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 3115 rfh->GetProcess()->GetID(), rfh->GetRoutingID(), reply_msg, | 3113 rfh, reply_msg, false)); |
| 3116 false)); | |
| 3117 } | 3114 } |
| 3118 | 3115 |
| 3119 WebContents* WebContentsImpl::GetAsWebContents() { | 3116 WebContents* WebContentsImpl::GetAsWebContents() { |
| 3120 return this; | 3117 return this; |
| 3121 } | 3118 } |
| 3122 | 3119 |
| 3123 bool WebContentsImpl::IsNeverVisible() { | 3120 bool WebContentsImpl::IsNeverVisible() { |
| 3124 if (!delegate_) | 3121 if (!delegate_) |
| 3125 return false; | 3122 return false; |
| 3126 return delegate_->IsNeverVisible(this); | 3123 return delegate_->IsNeverVisible(this); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3780 return web_contents_android->GetJavaObject(); | 3777 return web_contents_android->GetJavaObject(); |
| 3781 } | 3778 } |
| 3782 | 3779 |
| 3783 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { | 3780 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
| 3784 return CreateRenderViewForRenderManager(GetRenderViewHost(), | 3781 return CreateRenderViewForRenderManager(GetRenderViewHost(), |
| 3785 MSG_ROUTING_NONE, | 3782 MSG_ROUTING_NONE, |
| 3786 NULL); | 3783 NULL); |
| 3787 } | 3784 } |
| 3788 #endif | 3785 #endif |
| 3789 | 3786 |
| 3790 void WebContentsImpl::OnDialogClosed(int render_process_id, | 3787 void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh, |
| 3791 int render_frame_id, | |
| 3792 IPC::Message* reply_msg, | 3788 IPC::Message* reply_msg, |
| 3793 bool dialog_was_suppressed, | 3789 bool dialog_was_suppressed, |
| 3794 bool success, | 3790 bool success, |
| 3795 const base::string16& user_input) { | 3791 const base::string16& user_input) { |
| 3796 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, | |
| 3797 render_frame_id); | |
| 3798 last_dialog_suppressed_ = dialog_was_suppressed; | 3792 last_dialog_suppressed_ = dialog_was_suppressed; |
| 3799 | 3793 |
| 3800 if (is_showing_before_unload_dialog_ && !success) { | 3794 if (is_showing_before_unload_dialog_ && !success) { |
| 3801 // If a beforeunload dialog is canceled, we need to stop the throbber from | 3795 // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 3802 // spinning, since we forced it to start spinning in Navigate. | 3796 // spinning, since we forced it to start spinning in Navigate. |
| 3803 if (rfh) | 3797 DidStopLoading(rfh); |
| 3804 DidStopLoading(rfh); | |
| 3805 controller_.DiscardNonCommittedEntries(); | 3798 controller_.DiscardNonCommittedEntries(); |
| 3806 | 3799 |
| 3807 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3800 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3808 BeforeUnloadDialogCancelled()); | 3801 BeforeUnloadDialogCancelled()); |
| 3809 } | 3802 } |
| 3810 | 3803 |
| 3811 is_showing_before_unload_dialog_ = false; | 3804 is_showing_before_unload_dialog_ = false; |
| 3812 if (rfh) { | 3805 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed( |
| 3813 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, | 3806 reply_msg, success, user_input, dialog_was_suppressed); |
| 3814 dialog_was_suppressed); | |
| 3815 } | |
| 3816 } | 3807 } |
| 3817 | 3808 |
| 3818 void WebContentsImpl::SetEncoding(const std::string& encoding) { | 3809 void WebContentsImpl::SetEncoding(const std::string& encoding) { |
| 3819 encoding_ = GetContentClient()->browser()-> | 3810 encoding_ = GetContentClient()->browser()-> |
| 3820 GetCanonicalEncodingNameByAliasName(encoding); | 3811 GetCanonicalEncodingNameByAliasName(encoding); |
| 3821 } | 3812 } |
| 3822 | 3813 |
| 3823 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 3814 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 3824 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); | 3815 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); |
| 3825 // Can be NULL during tests. | 3816 // Can be NULL during tests. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3890 | 3881 |
| 3891 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3882 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 3892 if (!delegate_) | 3883 if (!delegate_) |
| 3893 return; | 3884 return; |
| 3894 const gfx::Size new_size = GetPreferredSize(); | 3885 const gfx::Size new_size = GetPreferredSize(); |
| 3895 if (new_size != old_size) | 3886 if (new_size != old_size) |
| 3896 delegate_->UpdatePreferredSize(this, new_size); | 3887 delegate_->UpdatePreferredSize(this, new_size); |
| 3897 } | 3888 } |
| 3898 | 3889 |
| 3899 } // namespace content | 3890 } // namespace content |
| OLD | NEW |