| 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/defaults.h" | 18 #include "chrome/browser/defaults.h" |
| 19 #include "chrome/browser/load_from_memory_cache_details.h" | 19 #include "chrome/browser/load_from_memory_cache_details.h" |
| 20 #include "chrome/browser/notifications/desktop_notification_service.h" | 20 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/renderer_host/web_cache_manager.h" | 24 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 25 #include "chrome/browser/renderer_preferences_util.h" | |
| 26 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 25 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 27 #include "chrome/browser/ui/browser_dialogs.h" | 26 #include "chrome/browser/ui/browser_dialogs.h" |
| 28 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
| 31 #include "content/browser/child_process_security_policy.h" | 30 #include "content/browser/child_process_security_policy.h" |
| 32 #include "content/browser/content_browser_client.h" | 31 #include "content/browser/content_browser_client.h" |
| 33 #include "content/browser/host_zoom_map.h" | 32 #include "content/browser/host_zoom_map.h" |
| 34 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 33 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| 35 #include "content/browser/load_notification_details.h" | 34 #include "content/browser/load_notification_details.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // it, but if so, the existing frame relationships will be maintained. | 109 // it, but if so, the existing frame relationships will be maintained. |
| 111 | 110 |
| 112 namespace { | 111 namespace { |
| 113 | 112 |
| 114 // Amount of time we wait between when a key event is received and the renderer | 113 // Amount of time we wait between when a key event is received and the renderer |
| 115 // is queried for its state and pushed to the NavigationEntry. | 114 // is queried for its state and pushed to the NavigationEntry. |
| 116 const int kQueryStateDelay = 5000; | 115 const int kQueryStateDelay = 5000; |
| 117 | 116 |
| 118 const int kSyncWaitDelay = 40; | 117 const int kSyncWaitDelay = 40; |
| 119 | 118 |
| 120 // The list of prefs we want to observe. | |
| 121 const char* kPrefsToObserve[] = { | |
| 122 prefs::kAlternateErrorPagesEnabled, | |
| 123 prefs::kDefaultZoomLevel, | |
| 124 prefs::kWebKitJavaEnabled, | |
| 125 prefs::kWebKitJavascriptEnabled, | |
| 126 prefs::kWebKitLoadsImagesAutomatically, | |
| 127 prefs::kWebKitPluginsEnabled, | |
| 128 prefs::kWebKitUsesUniversalDetector, | |
| 129 prefs::kWebKitStandardFontFamily, | |
| 130 prefs::kWebKitSerifFontFamily, | |
| 131 prefs::kWebKitSansSerifFontFamily, | |
| 132 prefs::kWebKitFixedFontFamily, | |
| 133 prefs::kWebKitDefaultFontSize, | |
| 134 prefs::kWebKitDefaultFixedFontSize, | |
| 135 prefs::kWebKitMinimumFontSize, | |
| 136 prefs::kWebKitMinimumLogicalFontSize, | |
| 137 prefs::kWebkitTabsToLinks, | |
| 138 prefs::kWebKitAllowRunningInsecureContent, | |
| 139 prefs::kWebKitAllowDisplayingInsecureContent, | |
| 140 prefs::kDefaultCharset, | |
| 141 prefs::kEnableReferrers | |
| 142 }; | |
| 143 | |
| 144 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); | |
| 145 | |
| 146 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 147 | 120 |
| 148 BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { | 121 BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { |
| 149 // Note: erase is required to properly paint some widgets borders. This can | 122 // Note: erase is required to properly paint some widgets borders. This can |
| 150 // be seen with textfields. | 123 // be seen with textfields. |
| 151 InvalidateRect(hwnd, NULL, TRUE); | 124 InvalidateRect(hwnd, NULL, TRUE); |
| 152 return TRUE; | 125 return TRUE; |
| 153 } | 126 } |
| 154 #endif | 127 #endif |
| 155 | 128 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 suppress_javascript_messages_(false), | 197 suppress_javascript_messages_(false), |
| 225 is_showing_before_unload_dialog_(false), | 198 is_showing_before_unload_dialog_(false), |
| 226 opener_web_ui_type_(WebUI::kNoWebUI), | 199 opener_web_ui_type_(WebUI::kNoWebUI), |
| 227 closed_by_user_gesture_(false), | 200 closed_by_user_gesture_(false), |
| 228 minimum_zoom_percent_( | 201 minimum_zoom_percent_( |
| 229 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 202 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
| 230 maximum_zoom_percent_( | 203 maximum_zoom_percent_( |
| 231 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 204 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
| 232 temporary_zoom_settings_(false), | 205 temporary_zoom_settings_(false), |
| 233 content_restrictions_(0) { | 206 content_restrictions_(0) { |
| 234 renderer_preferences_util::UpdateFromSystemSettings( | |
| 235 &renderer_preferences_, profile); | |
| 236 | 207 |
| 237 render_manager_.Init(profile, site_instance, routing_id); | 208 render_manager_.Init(profile, site_instance, routing_id); |
| 238 | 209 |
| 239 // We have the initial size of the view be based on the size of the passed in | 210 // We have the initial size of the view be based on the size of the passed in |
| 240 // tab contents (normally a tab from the same window). | 211 // tab contents (normally a tab from the same window). |
| 241 view_->CreateView(base_tab_contents ? | 212 view_->CreateView(base_tab_contents ? |
| 242 base_tab_contents->view()->GetContainerSize() : gfx::Size()); | 213 base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
| 243 | 214 |
| 244 // Register for notifications about all interested prefs change. | |
| 245 PrefService* prefs = profile->GetPrefs(); | |
| 246 pref_change_registrar_.Init(prefs); | |
| 247 if (prefs) { | |
| 248 for (int i = 0; i < kPrefsToObserveLength; ++i) | |
| 249 pref_change_registrar_.Add(kPrefsToObserve[i], this); | |
| 250 } | |
| 251 | |
| 252 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 215 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
| 253 NotificationService::AllSources()); | 216 NotificationService::AllSources()); |
| 254 #if defined(OS_LINUX) | |
| 255 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
| 256 NotificationService::AllSources()); | |
| 257 #endif | |
| 258 | |
| 259 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED, | |
| 260 NotificationService::AllSources()); | |
| 261 | |
| 262 // Listen for Google URL changes. | |
| 263 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED, | |
| 264 NotificationService::AllSources()); | |
| 265 | 217 |
| 266 // Can only add observers after render_manager_.Init() is called, since that's | 218 // Can only add observers after render_manager_.Init() is called, since that's |
| 267 // what sets up the render_view_host which TabContentObserver's constructor | 219 // what sets up the render_view_host which TabContentObserver's constructor |
| 268 // uses to get the routing_id. | 220 // uses to get the routing_id. |
| 269 AddObservers(); | 221 AddObservers(); |
| 270 } | 222 } |
| 271 | 223 |
| 272 TabContents::~TabContents() { | 224 TabContents::~TabContents() { |
| 273 is_being_destroyed_ = true; | 225 is_being_destroyed_ = true; |
| 274 | 226 |
| 275 // We don't want any notifications while we're running our destructor. | 227 // We don't want any notifications while we're running our destructor. |
| 276 registrar_.RemoveAll(); | 228 registrar_.RemoveAll(); |
| 277 pref_change_registrar_.RemoveAll(); | |
| 278 | 229 |
| 279 NotifyDisconnected(); | 230 NotifyDisconnected(); |
| 280 browser::HideHungRendererDialog(this); | 231 browser::HideHungRendererDialog(this); |
| 281 | 232 |
| 282 // First cleanly close all child windows. | 233 // First cleanly close all child windows. |
| 283 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 234 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
| 284 // some of these to close. CloseWindows is async, so it might get called | 235 // some of these to close. CloseWindows is async, so it might get called |
| 285 // twice before it runs. | 236 // twice before it runs. |
| 286 CloseConstrainedWindows(); | 237 CloseConstrainedWindows(); |
| 287 | 238 |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 for (ConstrainedWindowList::iterator it = child_windows_copy.begin(); | 1139 for (ConstrainedWindowList::iterator it = child_windows_copy.begin(); |
| 1189 it != child_windows_copy.end(); ++it) { | 1140 it != child_windows_copy.end(); ++it) { |
| 1190 ConstrainedWindow* window = *it; | 1141 ConstrainedWindow* window = *it; |
| 1191 if (window) { | 1142 if (window) { |
| 1192 window->CloseConstrainedWindow(); | 1143 window->CloseConstrainedWindow(); |
| 1193 BlockTabContent(false); | 1144 BlockTabContent(false); |
| 1194 } | 1145 } |
| 1195 } | 1146 } |
| 1196 } | 1147 } |
| 1197 | 1148 |
| 1198 void TabContents::UpdateAlternateErrorPageURL() { | |
| 1199 GURL url = GetAlternateErrorPageURL(); | |
| 1200 render_view_host()->Send(new ViewMsg_SetAltErrorPageURL( | |
| 1201 render_view_host()->routing_id(), url)); | |
| 1202 } | |
| 1203 | |
| 1204 void TabContents::UpdateWebPreferences() { | |
| 1205 render_view_host()->Send(new ViewMsg_UpdateWebPreferences( | |
| 1206 render_view_host()->routing_id(), GetWebkitPrefs())); | |
| 1207 } | |
| 1208 | |
| 1209 void TabContents::UpdateZoomLevel() { | |
| 1210 render_view_host()->Send(new ViewMsg_SetZoomLevel( | |
| 1211 render_view_host()->routing_id(), GetZoomLevel())); | |
| 1212 } | |
| 1213 | |
| 1214 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, | 1149 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
| 1215 RenderViewHost* rvh) { | 1150 RenderViewHost* rvh) { |
| 1216 // If we are creating a RVH for a restored controller, then we might | 1151 // If we are creating a RVH for a restored controller, then we might |
| 1217 // have more page IDs than the SiteInstance's current max page ID. We must | 1152 // have more page IDs than the SiteInstance's current max page ID. We must |
| 1218 // make sure that the max page ID is larger than any restored page ID. | 1153 // make sure that the max page ID is larger than any restored page ID. |
| 1219 // Note that it is ok for conflicting page IDs to exist in another tab | 1154 // Note that it is ok for conflicting page IDs to exist in another tab |
| 1220 // (i.e., NavigationController), but if any page ID is larger than the max, | 1155 // (i.e., NavigationController), but if any page ID is larger than the max, |
| 1221 // the back/forward list will get confused. | 1156 // the back/forward list will get confused. |
| 1222 int max_restored_page_id = controller_.max_restored_page_id(); | 1157 int max_restored_page_id = controller_.max_restored_page_id(); |
| 1223 if (max_restored_page_id > 0) { | 1158 if (max_restored_page_id > 0) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 if (render_manager_.pending_web_ui()) | 1283 if (render_manager_.pending_web_ui()) |
| 1349 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 1284 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
| 1350 | 1285 |
| 1351 if (entry->IsViewSourceMode()) { | 1286 if (entry->IsViewSourceMode()) { |
| 1352 // Put the renderer in view source mode. | 1287 // Put the renderer in view source mode. |
| 1353 render_view_host->Send( | 1288 render_view_host->Send( |
| 1354 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); | 1289 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
| 1355 } | 1290 } |
| 1356 | 1291 |
| 1357 view()->RenderViewCreated(render_view_host); | 1292 view()->RenderViewCreated(render_view_host); |
| 1293 |
| 1294 FOR_EACH_OBSERVER( |
| 1295 TabContentsObserver, observers_, RenderViewCreated(render_view_host)); |
| 1358 } | 1296 } |
| 1359 | 1297 |
| 1360 void TabContents::RenderViewReady(RenderViewHost* rvh) { | 1298 void TabContents::RenderViewReady(RenderViewHost* rvh) { |
| 1361 if (rvh != render_view_host()) { | 1299 if (rvh != render_view_host()) { |
| 1362 // Don't notify the world, since this came from a renderer in the | 1300 // Don't notify the world, since this came from a renderer in the |
| 1363 // background. | 1301 // background. |
| 1364 return; | 1302 return; |
| 1365 } | 1303 } |
| 1366 | 1304 |
| 1367 NotifyConnected(); | 1305 NotifyConnected(); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 (delegate() && delegate()->ShouldSuppressDialogs()); | 1636 (delegate() && delegate()->ShouldSuppressDialogs()); |
| 1699 if (suppress_this_message) { | 1637 if (suppress_this_message) { |
| 1700 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, | 1638 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, |
| 1701 std::wstring()); | 1639 std::wstring()); |
| 1702 return; | 1640 return; |
| 1703 } | 1641 } |
| 1704 is_showing_before_unload_dialog_ = true; | 1642 is_showing_before_unload_dialog_ = true; |
| 1705 RunBeforeUnloadDialog(this, message, reply_msg); | 1643 RunBeforeUnloadDialog(this, message, reply_msg); |
| 1706 } | 1644 } |
| 1707 | 1645 |
| 1708 GURL TabContents::GetAlternateErrorPageURL() const { | |
| 1709 return content::GetContentClient()->browser()->GetAlternateErrorPageURL(this); | |
| 1710 } | |
| 1711 | |
| 1712 WebPreferences TabContents::GetWebkitPrefs() { | 1646 WebPreferences TabContents::GetWebkitPrefs() { |
| 1713 Profile* profile = render_view_host()->process()->profile(); | 1647 Profile* profile = render_view_host()->process()->profile(); |
| 1714 bool is_web_ui = false; | 1648 bool is_web_ui = false; |
| 1715 WebPreferences web_prefs = | 1649 WebPreferences web_prefs = |
| 1716 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui); | 1650 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui); |
| 1717 | 1651 |
| 1718 // Force accelerated compositing and 2d canvas off for chrome: and | 1652 // Force accelerated compositing and 2d canvas off for chrome: and |
| 1719 // chrome-extension: pages. | 1653 // chrome-extension: pages. |
| 1720 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || | 1654 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || |
| 1721 GetURL().SchemeIs(chrome::kChromeUIScheme)) { | 1655 GetURL().SchemeIs(chrome::kChromeUIScheme)) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1880 | 1814 |
| 1881 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(), | 1815 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(), |
| 1882 render_view_host); | 1816 render_view_host); |
| 1883 return true; | 1817 return true; |
| 1884 } | 1818 } |
| 1885 | 1819 |
| 1886 void TabContents::Observe(NotificationType type, | 1820 void TabContents::Observe(NotificationType type, |
| 1887 const NotificationSource& source, | 1821 const NotificationSource& source, |
| 1888 const NotificationDetails& details) { | 1822 const NotificationDetails& details) { |
| 1889 switch (type.value) { | 1823 switch (type.value) { |
| 1890 case NotificationType::PREF_CHANGED: { | |
| 1891 std::string* pref_name_in = Details<std::string>(details).ptr(); | |
| 1892 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); | |
| 1893 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { | |
| 1894 UpdateAlternateErrorPageURL(); | |
| 1895 } else if ((*pref_name_in == prefs::kDefaultCharset) || | |
| 1896 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { | |
| 1897 UpdateWebPreferences(); | |
| 1898 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | |
| 1899 UpdateZoomLevel(); | |
| 1900 } else if (*pref_name_in == prefs::kEnableReferrers) { | |
| 1901 renderer_preferences_util::UpdateFromSystemSettings( | |
| 1902 &renderer_preferences_, profile()); | |
| 1903 render_view_host()->SyncRendererPrefs(); | |
| 1904 } else { | |
| 1905 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; | |
| 1906 } | |
| 1907 break; | |
| 1908 } | |
| 1909 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: | 1824 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: |
| 1910 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); | 1825 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); |
| 1911 break; | 1826 break; |
| 1912 | |
| 1913 #if defined(OS_LINUX) | |
| 1914 case NotificationType::BROWSER_THEME_CHANGED: { | |
| 1915 renderer_preferences_util::UpdateFromSystemSettings( | |
| 1916 &renderer_preferences_, profile()); | |
| 1917 render_view_host()->SyncRendererPrefs(); | |
| 1918 break; | |
| 1919 } | |
| 1920 #endif | |
| 1921 | |
| 1922 case NotificationType::USER_STYLE_SHEET_UPDATED: | |
| 1923 UpdateWebPreferences(); | |
| 1924 break; | |
| 1925 | |
| 1926 case NotificationType::GOOGLE_URL_UPDATED: | |
| 1927 UpdateAlternateErrorPageURL(); | |
| 1928 break; | |
| 1929 | |
| 1930 default: | 1827 default: |
| 1931 NOTREACHED(); | 1828 NOTREACHED(); |
| 1932 } | 1829 } |
| 1933 } | 1830 } |
| 1934 | 1831 |
| 1935 gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { | 1832 gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { |
| 1936 return view_->GetTopLevelNativeWindow(); | 1833 return view_->GetTopLevelNativeWindow(); |
| 1937 } | 1834 } |
| 1938 | 1835 |
| 1939 void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, | 1836 void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 | 1871 |
| 1975 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1872 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 1976 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1873 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 1977 rwh_view->SetSize(view()->GetContainerSize()); | 1874 rwh_view->SetSize(view()->GetContainerSize()); |
| 1978 } | 1875 } |
| 1979 | 1876 |
| 1980 void TabContents::OnOnlineStateChanged(bool online) { | 1877 void TabContents::OnOnlineStateChanged(bool online) { |
| 1981 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 1878 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 1982 render_view_host()->routing_id(), online)); | 1879 render_view_host()->routing_id(), online)); |
| 1983 } | 1880 } |
| OLD | NEW |