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