diff options
21 files changed, 97 insertions, 44 deletions
diff --git a/android_webview/native/aw_settings.cc b/android_webview/native/aw_settings.cc index e9ba10e..2a0a50b 100644 --- a/android_webview/native/aw_settings.cc +++ b/android_webview/native/aw_settings.cc @@ -158,8 +158,7 @@ void AwSettings::UpdateWebkitPreferencesLocked(JNIEnv* env, jobject obj) { content::RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); if (!render_view_host) return; - render_view_host->UpdateWebkitPreferences( - render_view_host->GetWebkitPreferences()); + render_view_host->OnWebkitPreferencesChanged(); } void AwSettings::UpdateInitialPageScaleLocked(JNIEnv* env, jobject obj) { diff --git a/chrome/browser/android/voice_search_tab_helper.cc b/chrome/browser/android/voice_search_tab_helper.cc index c8f10db..0782f75 100644 --- a/chrome/browser/android/voice_search_tab_helper.cc +++ b/chrome/browser/android/voice_search_tab_helper.cc @@ -4,9 +4,11 @@ #include "chrome/browser/android/voice_search_tab_helper.h" +#include "base/command_line.h" #include "components/google/core/browser/google_util.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "content/public/common/content_switches.h" #include "content/public/common/web_preferences.h" #include "jni/VoiceSearchTabHelper_jni.h" @@ -20,19 +22,25 @@ bool RegisterVoiceSearchTabHelper(JNIEnv* env) { static void UpdateAutoplayStatus(JNIEnv* env, jobject obj, jobject j_web_contents) { + // In the case where media autoplay has been disabled by default (e.g. in + // performance media tests) do not update it based on navigation changes. + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch( + switches::kDisableGestureRequirementForMediaPlayback)) + return; + WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents); content::RenderViewHost* host = web_contents->GetRenderViewHost(); content::WebPreferences prefs = host->GetWebkitPreferences(); - // In the case where media autoplay has been enabled by default (e.g. in - // performance media tests) do not update it based on navigation changes. - // - // Note that GetWekitPreferences() is 'stateless'. It returns the default - // webkit preferences configuration from command line switches. - if (!prefs.user_gesture_required_for_media_playback) - return; - - prefs.user_gesture_required_for_media_playback = + bool gesture_required = !google_util::IsGoogleSearchUrl(web_contents->GetLastCommittedURL()); - host->UpdateWebkitPreferences(prefs); + + if (gesture_required != prefs.user_gesture_required_for_media_playback) { + // TODO(chrishtr): this is wrong. user_gesture_required_for_media_playback + // will be reset the next time a preference changes. + prefs.user_gesture_required_for_media_playback = + !google_util::IsGoogleSearchUrl(web_contents->GetLastCommittedURL()); + host->UpdateWebkitPreferences(prefs); + } } diff --git a/chrome/browser/prefs/chrome_pref_service_unittest.cc b/chrome/browser/prefs/chrome_pref_service_unittest.cc index 67a77a4..4b64946 100644 --- a/chrome/browser/prefs/chrome_pref_service_unittest.cc +++ b/chrome/browser/prefs/chrome_pref_service_unittest.cc @@ -117,7 +117,7 @@ class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { // to a WebPreferences object. TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) { WebPreferences webkit_prefs = - WebContentsTester::For(web_contents())->TestGetWebkitPrefs(); + WebContentsTester::For(web_contents())->TestComputeWebkitPrefs(); // These values have been overridden by the profile preferences. EXPECT_EQ("UTF-8", webkit_prefs.default_encoding); diff --git a/chrome/browser/printing/print_dialog_cloud.cc b/chrome/browser/printing/print_dialog_cloud.cc index 9269c7f..d0e67d2 100644 --- a/chrome/browser/printing/print_dialog_cloud.cc +++ b/chrome/browser/printing/print_dialog_cloud.cc @@ -361,6 +361,8 @@ void CloudPrintFlowHandler::Observe( // script permissions required for the web UI. RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); if (rvh) { + // TODO(chrishtr): this is wrong. allow_scripts_to_close_windows will + // be reset the next time a preference changes. WebPreferences webkit_prefs = rvh->GetWebkitPreferences(); webkit_prefs.allow_scripts_to_close_windows = true; rvh->UpdateWebkitPreferences(webkit_prefs); diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc index 0079bf9..bc9b08a 100644 --- a/chrome/browser/ui/prefs/prefs_tab_helper.cc +++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc @@ -49,23 +49,31 @@ namespace { // The list of prefs we want to observe. const char* kPrefsToObserve[] = { prefs::kDefaultCharset, + prefs::kDisable3DAPIs, + prefs::kEnableHyperlinkAuditing, prefs::kWebKitAllowDisplayingInsecureContent, prefs::kWebKitAllowRunningInsecureContent, prefs::kWebKitDefaultFixedFontSize, prefs::kWebKitDefaultFontSize, + prefs::kWebKitDomPasteEnabled, #if defined(OS_ANDROID) prefs::kWebKitFontScaleFactor, prefs::kWebKitForceEnableZoom, prefs::kWebKitPasswordEchoEnabled, #endif + prefs::kWebKitInspectorSettings, + prefs::kWebKitJavascriptCanOpenWindowsAutomatically, prefs::kWebKitJavascriptEnabled, prefs::kWebKitJavaEnabled, prefs::kWebKitLoadsImagesAutomatically, prefs::kWebKitMinimumFontSize, prefs::kWebKitMinimumLogicalFontSize, prefs::kWebKitPluginsEnabled, + prefs::kWebKitShrinksStandaloneImagesToFit, prefs::kWebkitTabsToLinks, - prefs::kWebKitUsesUniversalDetector + prefs::kWebKitTextAreasAreResizable, + prefs::kWebKitUsesUniversalDetector, + prefs::kWebKitWebSecurityEnabled, }; const int kPrefsToObserveLength = arraysize(kPrefsToObserve); @@ -112,6 +120,7 @@ ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_STANDARD) } } } +#endif // !defined(OS_ANDROID) // Registers |obs| to observe per-script font prefs under the path |map_name|. // On android, there's no exposed way to change these prefs, so we can save @@ -128,7 +137,6 @@ void RegisterFontFamilyMapObserver( registrar->Add(pref_name.c_str(), obs); } } -#endif // !defined(OS_ANDROID) #if defined(OS_WIN) // On Windows with antialising we want to use an alternate fixed font like @@ -326,12 +334,9 @@ PrefsTabHelper::PrefsTabHelper(WebContents* contents) &PrefsTabHelper::OnWebPrefChanged, base::Unretained(this)); for (int i = 0; i < kPrefsToObserveLength; ++i) { const char* pref_name = kPrefsToObserve[i]; - DCHECK(std::string(pref_name) == prefs::kDefaultCharset || - StartsWithASCII(pref_name, "webkit.webprefs.", true)); pref_change_registrar_.Add(pref_name, webkit_callback); } -#if !defined(OS_ANDROID) RegisterFontFamilyMapObserver(&pref_change_registrar_, prefs::kWebKitStandardFontFamilyMap, webkit_callback); @@ -353,7 +358,6 @@ PrefsTabHelper::PrefsTabHelper(WebContents* contents) RegisterFontFamilyMapObserver(&pref_change_registrar_, prefs::kWebKitPictographFontFamilyMap, webkit_callback); -#endif // !defined(OS_ANDROID) } renderer_preferences_util::UpdateFromSystemSettings( @@ -576,7 +580,7 @@ Profile* PrefsTabHelper::GetProfile() { return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); } -void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { +void PrefsTabHelper::OnFontFamilyPrefChanged(const std::string& pref_name) { // When a font family pref's value goes from non-empty to the empty string, we // must add it to the usual WebPreferences struct passed to the renderer. // @@ -604,6 +608,12 @@ void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { return; } } +} + +void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { +#if !defined(OS_ANDROID) + OnFontFamilyPrefChanged(pref_name); +#endif - UpdateWebPreferences(); + web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); } diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.h b/chrome/browser/ui/prefs/prefs_tab_helper.h index 055a2f1..f97410d 100644 --- a/chrome/browser/ui/prefs/prefs_tab_helper.h +++ b/chrome/browser/ui/prefs/prefs_tab_helper.h @@ -51,6 +51,8 @@ class PrefsTabHelper : public content::NotificationObserver, void UpdateRendererPreferences(); Profile* GetProfile(); + + void OnFontFamilyPrefChanged(const std::string& pref_name); void OnWebPrefChanged(const std::string& pref_name); content::WebContents* web_contents_; diff --git a/content/browser/android/content_settings.cc b/content/browser/android/content_settings.cc index 7ab181b..2d32143 100644 --- a/content/browser/android/content_settings.cc +++ b/content/browser/android/content_settings.cc @@ -39,7 +39,7 @@ bool ContentSettings::GetJavaScriptEnabled(JNIEnv* env, jobject obj) { RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); if (!render_view_host) return false; - return render_view_host->GetDelegate()->GetWebkitPrefs().javascript_enabled; + return render_view_host->GetWebkitPreferences().javascript_enabled; } void ContentSettings::WebContentsDestroyed() { diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index a3a86f8..4c754ff 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -215,7 +215,10 @@ void BrowserPluginGuest::Initialize( new BrowserPluginMsg_GuestContentWindowReady(instance_id_, guest_routing_id)); - WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); + // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will + // be reset again the next time preferences are updated. + WebPreferences prefs = + GetWebContents()->GetRenderViewHost()->GetWebkitPreferences(); prefs.navigate_on_drag_drop = false; GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); diff --git a/content/browser/frame_host/interstitial_page_impl.cc b/content/browser/frame_host/interstitial_page_impl.cc index 1a1ed43..f2cac9c 100644 --- a/content/browser/frame_host/interstitial_page_impl.cc +++ b/content/browser/frame_host/interstitial_page_impl.cc @@ -509,11 +509,11 @@ RendererPreferences InterstitialPageImpl::GetRendererPrefs( return renderer_preferences_; } -WebPreferences InterstitialPageImpl::GetWebkitPrefs() { +WebPreferences InterstitialPageImpl::ComputeWebkitPrefs() { if (!enabled()) return WebPreferences(); - return render_view_host_->GetWebkitPrefs(url_); + return render_view_host_->ComputeWebkitPrefs(url_); } void InterstitialPageImpl::RenderWidgetDeleted( diff --git a/content/browser/frame_host/interstitial_page_impl.h b/content/browser/frame_host/interstitial_page_impl.h index 7f2d4d7..1305eea 100644 --- a/content/browser/frame_host/interstitial_page_impl.h +++ b/content/browser/frame_host/interstitial_page_impl.h @@ -131,7 +131,7 @@ class CONTENT_EXPORT InterstitialPageImpl int error_code) OVERRIDE; virtual RendererPreferences GetRendererPrefs( BrowserContext* browser_context) const OVERRIDE; - virtual WebPreferences GetWebkitPrefs() OVERRIDE; + virtual WebPreferences ComputeWebkitPrefs() OVERRIDE; virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; virtual void CreateNewWindow( int render_process_id, diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 611d602..b8d98cd 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2145,7 +2145,7 @@ void RenderProcessHostImpl::OnGpuSwitching() { continue; RenderViewHost* rvh = RenderViewHost::From(widget); - rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); + rvh->OnWebkitPreferencesChanged(); } } diff --git a/content/browser/renderer_host/render_view_host_delegate.cc b/content/browser/renderer_host/render_view_host_delegate.cc index 9c0f17f..41a110e 100644 --- a/content/browser/renderer_host/render_view_host_delegate.cc +++ b/content/browser/renderer_host/render_view_host_delegate.cc @@ -22,7 +22,7 @@ WebContents* RenderViewHostDelegate::GetAsWebContents() { return NULL; } -WebPreferences RenderViewHostDelegate::GetWebkitPrefs() { +WebPreferences RenderViewHostDelegate::ComputeWebkitPrefs() { return WebPreferences(); } diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h index 4a44123..8c453a3 100644 --- a/content/browser/renderer_host/render_view_host_delegate.h +++ b/content/browser/renderer_host/render_view_host_delegate.h @@ -139,9 +139,9 @@ class CONTENT_EXPORT RenderViewHostDelegate { virtual RendererPreferences GetRendererPrefs( BrowserContext* browser_context) const = 0; - // Returns a WebPreferences object that will be used by the renderer + // Computes a WebPreferences object that will be used by the renderer // associated with the owning render view host. - virtual WebPreferences GetWebkitPrefs(); + virtual WebPreferences ComputeWebkitPrefs(); // Notification the user has made a gesture while focus was on the // page. This is used to avoid uninitiated user downloads (aka carpet diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index b03d28f..b4280c5 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -200,7 +200,8 @@ RenderViewHostImpl::RenderViewHostImpl( render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), virtual_keyboard_requested_(false), weak_factory_(this), - is_focused_element_editable_(false) { + is_focused_element_editable_(false), + updating_web_preferences_(false) { DCHECK(instance_.get()); CHECK(delegate_); // http://crbug.com/82827 @@ -292,7 +293,7 @@ bool RenderViewHostImpl::CreateRenderView( ViewMsg_New_Params params; params.renderer_preferences = delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext()); - params.web_preferences = delegate_->GetWebkitPrefs(); + params.web_preferences = GetWebkitPreferences(); params.view_id = GetRoutingID(); params.main_frame_routing_id = main_frame_routing_id_; params.surface_id = surface_id(); @@ -332,7 +333,7 @@ void RenderViewHostImpl::SyncRendererPrefs() { GetProcess()->GetBrowserContext()))); } -WebPreferences RenderViewHostImpl::GetWebkitPrefs(const GURL& url) { +WebPreferences RenderViewHostImpl::ComputeWebkitPrefs(const GURL& url) { TRACE_EVENT0("browser", "RenderViewHostImpl::GetWebkitPrefs"); WebPreferences prefs; @@ -1423,7 +1424,10 @@ void RenderViewHostImpl::ExitFullscreen() { } WebPreferences RenderViewHostImpl::GetWebkitPreferences() { - return delegate_->GetWebkitPrefs(); + if (!web_preferences_.get()) { + OnWebkitPreferencesChanged(); + } + return *web_preferences_; } void RenderViewHostImpl::DisownOpener() { @@ -1434,9 +1438,21 @@ void RenderViewHostImpl::DisownOpener() { } void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) { + web_preferences_.reset(new WebPreferences(prefs)); Send(new ViewMsg_UpdateWebPreferences(GetRoutingID(), prefs)); } +void RenderViewHostImpl::OnWebkitPreferencesChanged() { + // This is defensive code to avoid infinite loops due to code run inside + // UpdateWebkitPreferences() accidentally updating more preferences and thus + // calling back into this code. See crbug.com/398751 for one past example. + if (updating_web_preferences_) + return; + updating_web_preferences_ = true; + UpdateWebkitPreferences(delegate_->ComputeWebkitPrefs()); + updating_web_preferences_ = false; +} + void RenderViewHostImpl::GetAudioOutputControllers( const GetAudioOutputControllersCallback& callback) const { AudioRendererHost* audio_host = diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index b099a7b..4c674a5 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -204,6 +204,7 @@ class CONTENT_EXPORT RenderViewHostImpl virtual WebPreferences GetWebkitPreferences() OVERRIDE; virtual void UpdateWebkitPreferences( const WebPreferences& prefs) OVERRIDE; + virtual void OnWebkitPreferencesChanged() OVERRIDE; virtual void GetAudioOutputControllers( const GetAudioOutputControllersCallback& callback) const OVERRIDE; virtual void SelectWordAroundCaret() OVERRIDE; @@ -241,7 +242,7 @@ class CONTENT_EXPORT RenderViewHostImpl } // Returns the content specific prefs for this RenderViewHost. - WebPreferences GetWebkitPrefs(const GURL& url); + WebPreferences ComputeWebkitPrefs(const GURL& url); // Sends the given navigation message. Use this rather than sending it // yourself since this does the internal bookkeeping described below. This @@ -612,6 +613,13 @@ class CONTENT_EXPORT RenderViewHostImpl // True if the current focused element is editable. bool is_focused_element_editable_; + // This is updated every time UpdateWebkitPreferences is called. That method + // is in turn called when any of the settings change that the WebPreferences + // values depend on. + scoped_ptr<WebPreferences> web_preferences_; + + bool updating_web_preferences_; + DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl); }; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index aafea58..6039e32 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -3823,7 +3823,7 @@ bool WebContentsImpl::AddMessageToConsole(int32 level, source_id); } -WebPreferences WebContentsImpl::GetWebkitPrefs() { +WebPreferences WebContentsImpl::ComputeWebkitPrefs() { // We want to base the page config off of the actual URL, rather than the // virtual URL. // TODO(nasko): Investigate how to remove the GetActiveEntry usage here, @@ -3831,7 +3831,7 @@ WebPreferences WebContentsImpl::GetWebkitPrefs() { GURL url = controller_.GetActiveEntry() ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); - return GetRenderManager()->current_host()->GetWebkitPrefs(url); + return GetRenderManager()->current_host()->ComputeWebkitPrefs(url); } int WebContentsImpl::CreateSwappedOutRenderView( diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 8665cb6..05698e2 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -417,7 +417,7 @@ class CONTENT_EXPORT WebContentsImpl const base::string16& source_id) OVERRIDE; virtual RendererPreferences GetRendererPrefs( BrowserContext* browser_context) const OVERRIDE; - virtual WebPreferences GetWebkitPrefs() OVERRIDE; + virtual WebPreferences ComputeWebkitPrefs() OVERRIDE; virtual void OnUserGesture() OVERRIDE; virtual void OnIgnoredUIEvent() OVERRIDE; virtual void RendererUnresponsive(RenderViewHost* render_view_host, diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h index 840be8c..2c4c25f 100644 --- a/content/public/browser/render_view_host.h +++ b/content/public/browser/render_view_host.h @@ -194,9 +194,14 @@ class CONTENT_EXPORT RenderViewHost : virtual public RenderWidgetHost { // RenderViewHostDelegate. virtual void SyncRendererPrefs() = 0; - // Returns the current WebKit preferences. + // Returns the current WebKit preferences. Note: WebPreferences is cached, so + // this lookup will be fast virtual WebPreferences GetWebkitPreferences() = 0; + // If any state that affects the webkit preferences changed, this method must + // be called. This triggers recomputing preferences. + virtual void OnWebkitPreferencesChanged() = 0; + // Passes a list of Webkit preferences to the renderer. virtual void UpdateWebkitPreferences(const WebPreferences& prefs) = 0; diff --git a/content/public/test/web_contents_tester.h b/content/public/test/web_contents_tester.h index 73ccb7e..c3b52fc 100644 --- a/content/public/test/web_contents_tester.h +++ b/content/public/test/web_contents_tester.h @@ -86,8 +86,8 @@ class WebContentsTester { const Referrer& referrer, PageTransition transition) = 0; - // Promote GetWebkitPrefs to public. - virtual WebPreferences TestGetWebkitPrefs() = 0; + // Promote ComputeWebkitPrefs to public. + virtual WebPreferences TestComputeWebkitPrefs() = 0; }; } // namespace content diff --git a/content/test/test_web_contents.cc b/content/test/test_web_contents.cc index c337e2b..19d5418 100644 --- a/content/test/test_web_contents.cc +++ b/content/test/test_web_contents.cc @@ -91,8 +91,8 @@ void TestWebContents::TestDidNavigateWithReferrer( frame_tree_.root()->navigator()->DidNavigate(rfh, params); } -WebPreferences TestWebContents::TestGetWebkitPrefs() { - return GetWebkitPrefs(); +WebPreferences TestWebContents::TestComputeWebkitPrefs() { + return ComputeWebkitPrefs(); } bool TestWebContents::CreateRenderViewForRenderManager( diff --git a/content/test/test_web_contents.h b/content/test/test_web_contents.h index 5061bfb..8181b1c 100644 --- a/content/test/test_web_contents.h +++ b/content/test/test_web_contents.h @@ -42,7 +42,7 @@ class TestWebContents : public WebContentsImpl, public WebContentsTester { const GURL& url, const Referrer& referrer, PageTransition transition) OVERRIDE; - virtual WebPreferences TestGetWebkitPrefs() OVERRIDE; + virtual WebPreferences TestComputeWebkitPrefs() OVERRIDE; TestRenderViewHost* pending_test_rvh() const; |