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/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1999 DidOpenRequestedURL(new_contents, | 1999 DidOpenRequestedURL(new_contents, |
2000 url, | 2000 url, |
2001 referrer, | 2001 referrer, |
2002 disposition, | 2002 disposition, |
2003 transition_type, | 2003 transition_type, |
2004 source_frame_id)); | 2004 source_frame_id)); |
2005 } | 2005 } |
2006 } | 2006 } |
2007 | 2007 |
2008 void TabContents::RunJavaScriptMessage( | 2008 void TabContents::RunJavaScriptMessage( |
2009 const RenderViewHost* rvh, | 2009 RenderViewHost* rvh, |
2010 const string16& message, | 2010 const string16& message, |
2011 const string16& default_prompt, | 2011 const string16& default_prompt, |
2012 const GURL& frame_url, | 2012 const GURL& frame_url, |
2013 ui::JavascriptMessageType javascript_message_type, | 2013 ui::JavascriptMessageType javascript_message_type, |
2014 IPC::Message* reply_msg, | 2014 IPC::Message* reply_msg, |
2015 bool* did_suppress_message) { | 2015 bool* did_suppress_message) { |
2016 // Suppress JavaScript dialogs when requested. Also suppress messages when | 2016 // Suppress JavaScript dialogs when requested. Also suppress messages when |
2017 // showing an interstitial as it's shown over the previous page and we don't | 2017 // showing an interstitial as it's shown over the previous page and we don't |
2018 // want the hidden page's dialogs to interfere with the interstitial. | 2018 // want the hidden page's dialogs to interfere with the interstitial. |
2019 bool suppress_this_message = | 2019 bool suppress_this_message = |
(...skipping 23 matching lines...) Expand all Loading... | |
2043 javascript_message_type, | 2043 javascript_message_type, |
2044 message, | 2044 message, |
2045 default_prompt, | 2045 default_prompt, |
2046 reply_msg, | 2046 reply_msg, |
2047 &suppress_this_message); | 2047 &suppress_this_message); |
2048 } | 2048 } |
2049 | 2049 |
2050 if (suppress_this_message) { | 2050 if (suppress_this_message) { |
2051 // If we are suppressing messages, just reply as if the user immediately | 2051 // If we are suppressing messages, just reply as if the user immediately |
2052 // pressed "Cancel". | 2052 // pressed "Cancel". |
2053 OnDialogClosed(reply_msg, false, string16()); | 2053 OnDialogClosed(rvh, reply_msg, false, string16()); |
2054 } | 2054 } |
2055 | 2055 |
2056 *did_suppress_message = suppress_this_message; | 2056 *did_suppress_message = suppress_this_message; |
2057 } | 2057 } |
2058 | 2058 |
2059 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, | 2059 void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh, |
2060 const string16& message, | 2060 const string16& message, |
2061 IPC::Message* reply_msg) { | 2061 IPC::Message* reply_msg) { |
2062 if (delegate_) | 2062 if (delegate_) |
2063 delegate_->WillRunBeforeUnloadConfirm(); | 2063 delegate_->WillRunBeforeUnloadConfirm(); |
2064 | 2064 |
2065 bool suppress_this_message = | 2065 bool suppress_this_message = |
2066 rvh->is_swapped_out() || | 2066 rvh->is_swapped_out() || |
2067 !delegate_ || | 2067 !delegate_ || |
2068 delegate_->ShouldSuppressDialogs(); | 2068 delegate_->ShouldSuppressDialogs(); |
2069 if (suppress_this_message) { | 2069 if (suppress_this_message) { |
2070 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16()); | 2070 rvh->JavaScriptDialogClosed(reply_msg, true, string16()); |
2071 return; | 2071 return; |
2072 } | 2072 } |
2073 | 2073 |
2074 is_showing_before_unload_dialog_ = true; | 2074 is_showing_before_unload_dialog_ = true; |
2075 dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); | 2075 dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
2076 dialog_creator_->RunBeforeUnloadDialog(this, | 2076 dialog_creator_->RunBeforeUnloadDialog(this, |
2077 message, | 2077 message, |
2078 reply_msg); | 2078 reply_msg); |
2079 } | 2079 } |
2080 | 2080 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2246 // linux. See crbug.com/83941. | 2246 // linux. See crbug.com/83941. |
2247 if (rwh_view) { | 2247 if (rwh_view) { |
2248 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) | 2248 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
2249 render_widget_host->WasResized(); | 2249 render_widget_host->WasResized(); |
2250 } | 2250 } |
2251 #endif | 2251 #endif |
2252 | 2252 |
2253 return true; | 2253 return true; |
2254 } | 2254 } |
2255 | 2255 |
2256 void TabContents::OnDialogClosed(IPC::Message* reply_msg, | 2256 void TabContents::OnDialogClosed(RenderViewHost* rvh, |
2257 IPC::Message* reply_msg, | |
2257 bool success, | 2258 bool success, |
2258 const string16& user_input) { | 2259 const string16& user_input) { |
2259 if (is_showing_before_unload_dialog_ && !success) { | 2260 if (is_showing_before_unload_dialog_ && !success) { |
2260 // If a beforeunload dialog is canceled, we need to stop the throbber from | 2261 // If a beforeunload dialog is canceled, we need to stop the throbber from |
2261 // spinning, since we forced it to start spinning in Navigate. | 2262 // spinning, since we forced it to start spinning in Navigate. |
2262 DidStopLoading(); | 2263 DidStopLoading(); |
2263 | 2264 |
2264 tab_close_start_time_ = base::TimeTicks(); | 2265 tab_close_start_time_ = base::TimeTicks(); |
2265 } | 2266 } |
2266 is_showing_before_unload_dialog_ = false; | 2267 is_showing_before_unload_dialog_ = false; |
2267 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input); | 2268 // TODO(creis): We shouldn't have this. The API should make it possible |
2269 // to send the reply to the right RVH implicitly. | |
jam
2012/01/26 00:29:21
I don't understand which API you mean? and how thi
| |
2270 if (!rvh) | |
2271 rvh = GetRenderViewHost(); | |
2272 rvh->JavaScriptDialogClosed(reply_msg, success, user_input); | |
Charlie Reis
2012/01/26 00:17:52
I recognize that we probably don't want to add Ren
| |
2268 } | 2273 } |
2269 | 2274 |
2270 gfx::NativeWindow TabContents::GetDialogRootWindow() const { | 2275 gfx::NativeWindow TabContents::GetDialogRootWindow() const { |
2271 return view_->GetTopLevelNativeWindow(); | 2276 return view_->GetTopLevelNativeWindow(); |
2272 } | 2277 } |
2273 | 2278 |
2274 void TabContents::OnDialogShown() { | 2279 void TabContents::OnDialogShown() { |
2275 Activate(); | 2280 Activate(); |
2276 } | 2281 } |
2277 | 2282 |
2278 void TabContents::SetEncoding(const std::string& encoding) { | 2283 void TabContents::SetEncoding(const std::string& encoding) { |
2279 encoding_ = content::GetContentClient()->browser()-> | 2284 encoding_ = content::GetContentClient()->browser()-> |
2280 GetCanonicalEncodingNameByAliasName(encoding); | 2285 GetCanonicalEncodingNameByAliasName(encoding); |
2281 } | 2286 } |
2282 | 2287 |
2283 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2288 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2284 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); | 2289 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
2285 // Can be NULL during tests. | 2290 // Can be NULL during tests. |
2286 if (rwh_view) | 2291 if (rwh_view) |
2287 rwh_view->SetSize(GetView()->GetContainerSize()); | 2292 rwh_view->SetSize(GetView()->GetContainerSize()); |
2288 } | 2293 } |
OLD | NEW |