OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 crashed_error_code_(0), | 178 crashed_error_code_(0), |
179 waiting_for_response_(false), | 179 waiting_for_response_(false), |
180 max_page_id_(-1), | 180 max_page_id_(-1), |
181 load_state_(net::LOAD_STATE_IDLE, string16()), | 181 load_state_(net::LOAD_STATE_IDLE, string16()), |
182 upload_size_(0), | 182 upload_size_(0), |
183 upload_position_(0), | 183 upload_position_(0), |
184 displayed_insecure_content_(false), | 184 displayed_insecure_content_(false), |
185 capturing_contents_(false), | 185 capturing_contents_(false), |
186 is_being_destroyed_(false), | 186 is_being_destroyed_(false), |
187 notify_disconnection_(false), | 187 notify_disconnection_(false), |
| 188 dialog_creator_(NULL), |
188 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
189 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 190 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
190 #endif | 191 #endif |
191 is_showing_before_unload_dialog_(false), | 192 is_showing_before_unload_dialog_(false), |
192 opener_web_ui_type_(WebUI::kNoWebUI), | 193 opener_web_ui_type_(WebUI::kNoWebUI), |
193 closed_by_user_gesture_(false), | 194 closed_by_user_gesture_(false), |
194 minimum_zoom_percent_( | 195 minimum_zoom_percent_( |
195 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 196 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
196 maximum_zoom_percent_( | 197 maximum_zoom_percent_( |
197 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 198 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
198 temporary_zoom_settings_(false), | 199 temporary_zoom_settings_(false), |
199 content_restrictions_(0) { | 200 content_restrictions_(0) { |
200 | 201 |
201 render_manager_.Init(browser_context, site_instance, routing_id); | 202 render_manager_.Init(browser_context, site_instance, routing_id); |
202 | 203 |
203 // We have the initial size of the view be based on the size of the passed in | 204 // We have the initial size of the view be based on the size of the passed in |
204 // tab contents (normally a tab from the same window). | 205 // tab contents (normally a tab from the same window). |
205 view_->CreateView(base_tab_contents ? | 206 view_->CreateView(base_tab_contents ? |
206 base_tab_contents->view()->GetContainerSize() : gfx::Size()); | 207 base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
207 } | 208 } |
208 | 209 |
209 TabContents::~TabContents() { | 210 TabContents::~TabContents() { |
210 is_being_destroyed_ = true; | 211 is_being_destroyed_ = true; |
211 | 212 |
212 // Clear out any JavaScript state. | 213 // Clear out any JavaScript state. |
213 if (delegate_) | 214 if (dialog_creator_) |
214 delegate_->GetJavaScriptDialogCreator()->ResetJavaScriptState(this); | 215 dialog_creator_->ResetJavaScriptState(this); |
215 | 216 |
216 NotifyDisconnected(); | 217 NotifyDisconnected(); |
217 | 218 |
218 // First cleanly close all child windows. | 219 // First cleanly close all child windows. |
219 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 220 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
220 // some of these to close. CloseWindows is async, so it might get called | 221 // some of these to close. CloseWindows is async, so it might get called |
221 // twice before it runs. | 222 // twice before it runs. |
222 CloseConstrainedWindows(); | 223 CloseConstrainedWindows(); |
223 | 224 |
224 // Notify any observer that have a reference on this tab contents. | 225 // Notify any observer that have a reference on this tab contents. |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 DidNavigateMainFramePostCommit(details, params)); | 1217 DidNavigateMainFramePostCommit(details, params)); |
1217 } | 1218 } |
1218 | 1219 |
1219 void TabContents::DidNavigateAnyFramePostCommit( | 1220 void TabContents::DidNavigateAnyFramePostCommit( |
1220 RenderViewHost* render_view_host, | 1221 RenderViewHost* render_view_host, |
1221 const content::LoadCommittedDetails& details, | 1222 const content::LoadCommittedDetails& details, |
1222 const ViewHostMsg_FrameNavigate_Params& params) { | 1223 const ViewHostMsg_FrameNavigate_Params& params) { |
1223 // If we navigate, reset JavaScript state. This does nothing to prevent | 1224 // If we navigate, reset JavaScript state. This does nothing to prevent |
1224 // a malicious script from spamming messages, since the script could just | 1225 // a malicious script from spamming messages, since the script could just |
1225 // reload the page to stop blocking. | 1226 // reload the page to stop blocking. |
1226 if (delegate_) | 1227 if (dialog_creator_) { |
1227 delegate_->GetJavaScriptDialogCreator()->ResetJavaScriptState(this); | 1228 dialog_creator_->ResetJavaScriptState(this); |
| 1229 dialog_creator_ = NULL; |
| 1230 } |
1228 | 1231 |
1229 // Notify observers about navigation. | 1232 // Notify observers about navigation. |
1230 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1233 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1231 DidNavigateAnyFramePostCommit(details, params)); | 1234 DidNavigateAnyFramePostCommit(details, params)); |
1232 } | 1235 } |
1233 | 1236 |
1234 void TabContents::CloseConstrainedWindows() { | 1237 void TabContents::CloseConstrainedWindows() { |
1235 // Clear out any constrained windows since we are leaving this page entirely. | 1238 // Clear out any constrained windows since we are leaving this page entirely. |
1236 // To ensure that we iterate over every element in child_windows_ we | 1239 // To ensure that we iterate over every element in child_windows_ we |
1237 // need to use a copy of child_windows_. Otherwise if | 1240 // need to use a copy of child_windows_. Otherwise if |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 | 1687 |
1685 if (!frame_url.has_host()) { | 1688 if (!frame_url.has_host()) { |
1686 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE; | 1689 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE; |
1687 } else { | 1690 } else { |
1688 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL; | 1691 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL; |
1689 title = net::FormatUrl( | 1692 title = net::FormatUrl( |
1690 frame_url.GetOrigin(), | 1693 frame_url.GetOrigin(), |
1691 content::GetContentClient()->browser()->GetAcceptLangs(this)); | 1694 content::GetContentClient()->browser()->GetAcceptLangs(this)); |
1692 } | 1695 } |
1693 | 1696 |
1694 delegate_->GetJavaScriptDialogCreator()->RunJavaScriptDialog( | 1697 dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
1695 this, | 1698 dialog_creator_->RunJavaScriptDialog(this, |
1696 title_type, | 1699 title_type, |
1697 title, | 1700 title, |
1698 flags, | 1701 flags, |
1699 message, | 1702 message, |
1700 default_prompt, | 1703 default_prompt, |
1701 reply_msg, | 1704 reply_msg, |
1702 &suppress_this_message); | 1705 &suppress_this_message); |
1703 } | 1706 } |
1704 | 1707 |
1705 if (suppress_this_message) { | 1708 if (suppress_this_message) { |
1706 // If we are suppressing messages, just reply as if the user immediately | 1709 // If we are suppressing messages, just reply as if the user immediately |
1707 // pressed "Cancel". | 1710 // pressed "Cancel". |
1708 OnDialogClosed(reply_msg, false, string16()); | 1711 OnDialogClosed(reply_msg, false, string16()); |
1709 } | 1712 } |
1710 | 1713 |
1711 *did_suppress_message = suppress_this_message; | 1714 *did_suppress_message = suppress_this_message; |
1712 } | 1715 } |
1713 | 1716 |
1714 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, | 1717 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, |
1715 const string16& message, | 1718 const string16& message, |
1716 IPC::Message* reply_msg) { | 1719 IPC::Message* reply_msg) { |
1717 if (delegate()) | 1720 if (delegate()) |
1718 delegate()->WillRunBeforeUnloadConfirm(); | 1721 delegate()->WillRunBeforeUnloadConfirm(); |
1719 | 1722 |
1720 bool suppress_this_message = | 1723 bool suppress_this_message = |
1721 rvh->is_swapped_out() || | 1724 rvh->is_swapped_out() || |
1722 !delegate_ || | 1725 !delegate_ || |
1723 delegate_->ShouldSuppressDialogs(); | 1726 delegate_->ShouldSuppressDialogs(); |
1724 if (suppress_this_message) { | 1727 if (suppress_this_message) { |
1725 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16()); | 1728 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16()); |
1726 return; | 1729 return; |
1727 } | 1730 } |
1728 | 1731 |
1729 is_showing_before_unload_dialog_ = true; | 1732 is_showing_before_unload_dialog_ = true; |
1730 delegate_->GetJavaScriptDialogCreator()->RunBeforeUnloadDialog( | 1733 dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
1731 this, | 1734 dialog_creator_->RunBeforeUnloadDialog(this, |
1732 message, | 1735 message, |
1733 reply_msg); | 1736 reply_msg); |
1734 } | 1737 } |
1735 | 1738 |
1736 WebPreferences TabContents::GetWebkitPrefs() { | 1739 WebPreferences TabContents::GetWebkitPrefs() { |
1737 WebPreferences web_prefs = | 1740 WebPreferences web_prefs = |
1738 content::GetContentClient()->browser()->GetWebkitPrefs( | 1741 content::GetContentClient()->browser()->GetWebkitPrefs( |
1739 render_view_host()->process()->browser_context(), false); | 1742 render_view_host()->process()->browser_context(), false); |
1740 | 1743 |
1741 // Force accelerated compositing and 2d canvas off for chrome:, about: and | 1744 // Force accelerated compositing and 2d canvas off for chrome:, about: and |
1742 // chrome-devtools: pages (unless it's specifically allowed). | 1745 // chrome-devtools: pages (unless it's specifically allowed). |
1743 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || | 1746 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1935 } | 1938 } |
1936 | 1939 |
1937 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1940 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
1938 render_manager_.SwapInRenderViewHost(rvh); | 1941 render_manager_.SwapInRenderViewHost(rvh); |
1939 } | 1942 } |
1940 | 1943 |
1941 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1944 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
1942 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1945 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
1943 rwh_view->SetSize(view()->GetContainerSize()); | 1946 rwh_view->SetSize(view()->GetContainerSize()); |
1944 } | 1947 } |
OLD | NEW |