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" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/debugger/devtools_manager.h" | 17 #include "chrome/browser/debugger/devtools_manager.h" |
18 #include "chrome/browser/load_from_memory_cache_details.h" | 18 #include "chrome/browser/load_from_memory_cache_details.h" |
19 #include "chrome/browser/notifications/desktop_notification_service.h" | 19 #include "chrome/browser/notifications/desktop_notification_service.h" |
20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | |
23 #include "chrome/browser/ui/browser_dialogs.h" | 22 #include "chrome/browser/ui/browser_dialogs.h" |
24 #include "chrome/common/chrome_constants.h" | |
25 #include "content/browser/child_process_security_policy.h" | 23 #include "content/browser/child_process_security_policy.h" |
26 #include "content/browser/content_browser_client.h" | 24 #include "content/browser/content_browser_client.h" |
27 #include "content/browser/host_zoom_map.h" | 25 #include "content/browser/host_zoom_map.h" |
28 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 26 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
29 #include "content/browser/load_notification_details.h" | 27 #include "content/browser/load_notification_details.h" |
30 #include "content/browser/renderer_host/render_process_host.h" | 28 #include "content/browser/renderer_host/render_process_host.h" |
31 #include "content/browser/renderer_host/render_view_host.h" | 29 #include "content/browser/renderer_host/render_view_host.h" |
32 #include "content/browser/renderer_host/render_widget_host_view.h" | 30 #include "content/browser/renderer_host/render_widget_host_view.h" |
33 #include "content/browser/renderer_host/resource_request_details.h" | 31 #include "content/browser/renderer_host/resource_request_details.h" |
34 #include "content/browser/site_instance.h" | 32 #include "content/browser/site_instance.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 load_state_(net::LOAD_STATE_IDLE), | 181 load_state_(net::LOAD_STATE_IDLE), |
184 upload_size_(0), | 182 upload_size_(0), |
185 upload_position_(0), | 183 upload_position_(0), |
186 displayed_insecure_content_(false), | 184 displayed_insecure_content_(false), |
187 capturing_contents_(false), | 185 capturing_contents_(false), |
188 is_being_destroyed_(false), | 186 is_being_destroyed_(false), |
189 notify_disconnection_(false), | 187 notify_disconnection_(false), |
190 #if defined(OS_WIN) | 188 #if defined(OS_WIN) |
191 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 189 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
192 #endif | 190 #endif |
193 suppress_javascript_messages_(false), | |
194 is_showing_before_unload_dialog_(false), | 191 is_showing_before_unload_dialog_(false), |
195 opener_web_ui_type_(WebUI::kNoWebUI), | 192 opener_web_ui_type_(WebUI::kNoWebUI), |
196 closed_by_user_gesture_(false), | 193 closed_by_user_gesture_(false), |
197 minimum_zoom_percent_( | 194 minimum_zoom_percent_( |
198 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 195 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
199 maximum_zoom_percent_( | 196 maximum_zoom_percent_( |
200 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 197 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
201 temporary_zoom_settings_(false), | 198 temporary_zoom_settings_(false), |
202 content_restrictions_(0) { | 199 content_restrictions_(0) { |
203 | 200 |
(...skipping 12 matching lines...) Expand all Loading... |
216 // uses to get the routing_id. | 213 // uses to get the routing_id. |
217 AddObservers(); | 214 AddObservers(); |
218 } | 215 } |
219 | 216 |
220 TabContents::~TabContents() { | 217 TabContents::~TabContents() { |
221 is_being_destroyed_ = true; | 218 is_being_destroyed_ = true; |
222 | 219 |
223 // We don't want any notifications while we're running our destructor. | 220 // We don't want any notifications while we're running our destructor. |
224 registrar_.RemoveAll(); | 221 registrar_.RemoveAll(); |
225 | 222 |
| 223 // Clear out any JavaScript state. |
| 224 content::GetContentClient()->browser()->ResetJavaScriptState(this); |
| 225 |
226 NotifyDisconnected(); | 226 NotifyDisconnected(); |
227 browser::HideHungRendererDialog(this); | 227 browser::HideHungRendererDialog(this); |
228 | 228 |
229 // First cleanly close all child windows. | 229 // First cleanly close all child windows. |
230 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 230 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
231 // some of these to close. CloseWindows is async, so it might get called | 231 // some of these to close. CloseWindows is async, so it might get called |
232 // twice before it runs. | 232 // twice before it runs. |
233 CloseConstrainedWindows(); | 233 CloseConstrainedWindows(); |
234 | 234 |
235 // Notify any observer that have a reference on this tab contents. | 235 // Notify any observer that have a reference on this tab contents. |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1083 |
1084 // Notify observers about navigation. | 1084 // Notify observers about navigation. |
1085 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1085 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1086 DidNavigateMainFramePostCommit(details, params)); | 1086 DidNavigateMainFramePostCommit(details, params)); |
1087 } | 1087 } |
1088 | 1088 |
1089 void TabContents::DidNavigateAnyFramePostCommit( | 1089 void TabContents::DidNavigateAnyFramePostCommit( |
1090 RenderViewHost* render_view_host, | 1090 RenderViewHost* render_view_host, |
1091 const content::LoadCommittedDetails& details, | 1091 const content::LoadCommittedDetails& details, |
1092 const ViewHostMsg_FrameNavigate_Params& params) { | 1092 const ViewHostMsg_FrameNavigate_Params& params) { |
1093 // If we navigate, start showing messages again. This does nothing to prevent | 1093 // If we navigate, reset JavaScript state. This does nothing to prevent |
1094 // a malicious script from spamming messages, since the script could just | 1094 // a malicious script from spamming messages, since the script could just |
1095 // reload the page to stop blocking. | 1095 // reload the page to stop blocking. |
1096 suppress_javascript_messages_ = false; | 1096 content::GetContentClient()->browser()->ResetJavaScriptState(this); |
1097 | 1097 |
1098 // Notify observers about navigation. | 1098 // Notify observers about navigation. |
1099 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1099 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1100 DidNavigateAnyFramePostCommit(details, params)); | 1100 DidNavigateAnyFramePostCommit(details, params)); |
1101 } | 1101 } |
1102 | 1102 |
1103 void TabContents::CloseConstrainedWindows() { | 1103 void TabContents::CloseConstrainedWindows() { |
1104 // Clear out any constrained windows since we are leaving this page entirely. | 1104 // Clear out any constrained windows since we are leaving this page entirely. |
1105 // To ensure that we iterate over every element in child_windows_ we | 1105 // To ensure that we iterate over every element in child_windows_ we |
1106 // need to use a copy of child_windows_. Otherwise if | 1106 // need to use a copy of child_windows_. Otherwise if |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 } | 1564 } |
1565 | 1565 |
1566 void TabContents::RunJavaScriptMessage( | 1566 void TabContents::RunJavaScriptMessage( |
1567 const RenderViewHost* rvh, | 1567 const RenderViewHost* rvh, |
1568 const string16& message, | 1568 const string16& message, |
1569 const string16& default_prompt, | 1569 const string16& default_prompt, |
1570 const GURL& frame_url, | 1570 const GURL& frame_url, |
1571 const int flags, | 1571 const int flags, |
1572 IPC::Message* reply_msg, | 1572 IPC::Message* reply_msg, |
1573 bool* did_suppress_message) { | 1573 bool* did_suppress_message) { |
1574 // Suppress javascript messages when requested and when inside a constrained | 1574 // Suppress JavaScript dialogs when requested. Also suppress messages when |
1575 // popup window (because that activates them and breaks them out of the | 1575 // showing an interstitial. The interstitial is shown over the previous page, |
1576 // constrained window jail). | 1576 // we don't want the hidden page dialogs to interfere with the interstitial. |
1577 // Also suppress messages when showing an interstitial. The interstitial is | |
1578 // shown over the previous page, we don't want the hidden page dialogs to | |
1579 // interfere with the interstitial. | |
1580 bool suppress_this_message = | 1577 bool suppress_this_message = |
1581 rvh->is_swapped_out() || | 1578 rvh->is_swapped_out() || |
1582 suppress_javascript_messages_ || | |
1583 showing_interstitial_page() || | 1579 showing_interstitial_page() || |
1584 (delegate() && delegate()->ShouldSuppressDialogs()); | 1580 (delegate() && delegate()->ShouldSuppressDialogs()); |
1585 if (delegate()) | 1581 |
1586 suppress_this_message |= | 1582 if (!suppress_this_message) { |
1587 (delegate()->GetConstrainingContents(this) != this); | 1583 content::GetContentClient()->browser()->RunJavaScriptDialog( |
| 1584 this, |
| 1585 frame_url, |
| 1586 flags, |
| 1587 message, |
| 1588 default_prompt, |
| 1589 reply_msg, |
| 1590 &suppress_this_message, |
| 1591 profile()); |
| 1592 } |
| 1593 |
| 1594 if (suppress_this_message) { |
| 1595 // If we are suppressing messages, just reply as if the user immediately |
| 1596 // pressed "Cancel". |
| 1597 OnDialogClosed(reply_msg, false, string16()); |
| 1598 } |
1588 | 1599 |
1589 *did_suppress_message = suppress_this_message; | 1600 *did_suppress_message = suppress_this_message; |
1590 | |
1591 if (!suppress_this_message) { | |
1592 base::TimeDelta time_since_last_message( | |
1593 base::TimeTicks::Now() - last_javascript_message_dismissal_); | |
1594 bool show_suppress_checkbox = false; | |
1595 // Show a checkbox offering to suppress further messages if this message is | |
1596 // being displayed within kJavascriptMessageExpectedDelay of the last one. | |
1597 if (time_since_last_message < | |
1598 base::TimeDelta::FromMilliseconds( | |
1599 chrome::kJavascriptMessageExpectedDelay)) | |
1600 show_suppress_checkbox = true; | |
1601 | |
1602 RunJavascriptMessageBox(profile(), | |
1603 this, | |
1604 frame_url, | |
1605 flags, | |
1606 UTF16ToWideHack(message), | |
1607 UTF16ToWideHack(default_prompt), | |
1608 show_suppress_checkbox, | |
1609 reply_msg); | |
1610 } else { | |
1611 // If we are suppressing messages, just reply as is if the user immediately | |
1612 // pressed "Cancel". | |
1613 OnMessageBoxClosed(reply_msg, false, std::wstring()); | |
1614 } | |
1615 } | 1601 } |
1616 | 1602 |
1617 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, | 1603 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, |
1618 const string16& message, | 1604 const string16& message, |
1619 IPC::Message* reply_msg) { | 1605 IPC::Message* reply_msg) { |
1620 if (delegate()) | 1606 if (delegate()) |
1621 delegate()->WillRunBeforeUnloadConfirm(); | 1607 delegate()->WillRunBeforeUnloadConfirm(); |
1622 bool suppress_this_message = rvh->is_swapped_out() || | 1608 bool suppress_this_message = rvh->is_swapped_out() || |
1623 (delegate() && delegate()->ShouldSuppressDialogs()); | 1609 (delegate() && delegate()->ShouldSuppressDialogs()); |
1624 if (suppress_this_message) { | 1610 if (suppress_this_message) { |
1625 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16()); | 1611 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16()); |
1626 return; | 1612 return; |
1627 } | 1613 } |
1628 is_showing_before_unload_dialog_ = true; | 1614 is_showing_before_unload_dialog_ = true; |
1629 RunBeforeUnloadDialog(this, UTF16ToWideHack(message), reply_msg); | 1615 content::GetContentClient()->browser()->RunBeforeUnloadDialog( |
| 1616 this, |
| 1617 message, |
| 1618 reply_msg); |
1630 } | 1619 } |
1631 | 1620 |
1632 WebPreferences TabContents::GetWebkitPrefs() { | 1621 WebPreferences TabContents::GetWebkitPrefs() { |
1633 Profile* profile = render_view_host()->process()->profile(); | 1622 Profile* profile = render_view_host()->process()->profile(); |
1634 bool is_web_ui = false; | 1623 bool is_web_ui = false; |
1635 WebPreferences web_prefs = | 1624 WebPreferences web_prefs = |
1636 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui); | 1625 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui); |
1637 | 1626 |
1638 // Force accelerated compositing and 2d canvas off for chrome: and | 1627 // Force accelerated compositing and 2d canvas off for chrome: and |
1639 // chrome-extension: pages. | 1628 // chrome-extension: pages. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 const NotificationDetails& details) { | 1804 const NotificationDetails& details) { |
1816 switch (type.value) { | 1805 switch (type.value) { |
1817 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: | 1806 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: |
1818 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); | 1807 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); |
1819 break; | 1808 break; |
1820 default: | 1809 default: |
1821 NOTREACHED(); | 1810 NOTREACHED(); |
1822 } | 1811 } |
1823 } | 1812 } |
1824 | 1813 |
1825 gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { | 1814 // Overridden from JavaScriptDialogDelegate |
1826 return view_->GetTopLevelNativeWindow(); | |
1827 } | |
1828 | 1815 |
1829 void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, | 1816 void TabContents::OnDialogClosed(IPC::Message* reply_msg, |
1830 bool success, | 1817 bool success, |
1831 const std::wstring& user_input) { | 1818 const string16& user_input) { |
1832 last_javascript_message_dismissal_ = base::TimeTicks::Now(); | |
1833 if (is_showing_before_unload_dialog_ && !success) { | 1819 if (is_showing_before_unload_dialog_ && !success) { |
1834 // If a beforeunload dialog is canceled, we need to stop the throbber from | 1820 // If a beforeunload dialog is canceled, we need to stop the throbber from |
1835 // spinning, since we forced it to start spinning in Navigate. | 1821 // spinning, since we forced it to start spinning in Navigate. |
1836 DidStopLoading(); | 1822 DidStopLoading(); |
1837 | 1823 |
1838 tab_close_start_time_ = base::TimeTicks(); | 1824 tab_close_start_time_ = base::TimeTicks(); |
1839 } | 1825 } |
1840 is_showing_before_unload_dialog_ = false; | 1826 is_showing_before_unload_dialog_ = false; |
1841 render_view_host()->JavaScriptDialogClosed(reply_msg, | 1827 render_view_host()->JavaScriptDialogClosed(reply_msg, |
1842 success, | 1828 success, |
1843 WideToUTF16Hack(user_input)); | 1829 user_input); |
1844 } | 1830 } |
1845 | 1831 |
1846 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { | 1832 gfx::NativeWindow TabContents::GetDialogRootWindow() { |
1847 set_suppress_javascript_messages(suppress_message_boxes); | 1833 return view_->GetTopLevelNativeWindow(); |
1848 } | 1834 } |
1849 | 1835 |
1850 TabContents* TabContents::AsTabContents() { | 1836 TabContents* TabContents::AsTabContents() { |
1851 return this; | 1837 return this; |
1852 } | 1838 } |
1853 | 1839 |
1854 ExtensionHost* TabContents::AsExtensionHost() { | 1840 ExtensionHost* TabContents::AsExtensionHost() { |
1855 return NULL; | 1841 return NULL; |
1856 } | 1842 } |
1857 | 1843 |
1858 void TabContents::set_encoding(const std::string& encoding) { | 1844 void TabContents::set_encoding(const std::string& encoding) { |
1859 encoding_ = content::GetContentClient()->browser()-> | 1845 encoding_ = content::GetContentClient()->browser()-> |
1860 GetCanonicalEncodingNameByAliasName(encoding); | 1846 GetCanonicalEncodingNameByAliasName(encoding); |
1861 } | 1847 } |
1862 | 1848 |
1863 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1849 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
1864 render_manager_.SwapInRenderViewHost(rvh); | 1850 render_manager_.SwapInRenderViewHost(rvh); |
1865 } | 1851 } |
1866 | 1852 |
1867 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1853 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
1868 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1854 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
1869 rwh_view->SetSize(view()->GetContainerSize()); | 1855 rwh_view->SetSize(view()->GetContainerSize()); |
1870 } | 1856 } |
1871 | 1857 |
1872 void TabContents::OnOnlineStateChanged(bool online) { | 1858 void TabContents::OnOnlineStateChanged(bool online) { |
1873 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 1859 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
1874 render_view_host()->routing_id(), online)); | 1860 render_view_host()->routing_id(), online)); |
1875 } | 1861 } |
OLD | NEW |