WebKit Bugzilla
Attachment 345768 Details for
Bug 188009
: navigator.userAgent may return outdated value after webView.customUserAgent is set
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188009-20180725110602.patch (text/plain), 16.24 KB, created by
Chris Dumez
on 2018-07-25 11:06:03 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2018-07-25 11:06:03 PDT
Size:
16.24 KB
patch
obsolete
>Subversion Revision: 234202 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 28fb29fc32c44ce683061b0eba8eaaf6365de627..200a96ba0dc52ea20e541b146454d4aae66dbba1 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,22 @@ >+2018-07-25 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent may return outdated value after webView.customUserAgent is set >+ https://bugs.webkit.org/show_bug.cgi?id=188009 >+ <rdar://problem/42566456> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Invalidate the navigator.userAgent cache whenever the user agent gets changed to avoid exposing >+ outdated values to JavaScript. >+ >+ * page/Navigator.cpp: >+ (WebCore::Navigator::userAgentChanged): >+ * page/Navigator.h: >+ * page/NavigatorID.idl: >+ * page/Page.cpp: >+ (WebCore::Page::userAgentChanged): >+ * page/Page.h: >+ > 2018-07-25 Chris Dumez <cdumez@apple.com> > > Turn assertion preventing removal of ActiveDOMObjects while we iterate over them into a RELEASE_ASSERT >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 4edb532c1472ac873b1f1189446623b686926925..59a6f76785901c84fc35b553a10a59d29bf2b7f0 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,16 @@ >+2018-07-25 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent may return outdated value after webView.customUserAgent is set >+ https://bugs.webkit.org/show_bug.cgi?id=188009 >+ <rdar://problem/42566456> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Let the page know when the user agent changes. >+ >+ * WebProcess/WebPage/WebPage.cpp: >+ (WebKit::WebPage::setUserAgent): >+ > 2018-07-25 Alex Christensen <achristensen@webkit.org> > > Use CompletionHandler for policy decisions >diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog >index c9d88350e6e5532d654723a56add9b0be22f23a1..95a0a78f9101661a5244b17d9ca3292cae3d7470 100644 >--- a/Source/WebKitLegacy/mac/ChangeLog >+++ b/Source/WebKitLegacy/mac/ChangeLog >@@ -1,3 +1,20 @@ >+2018-07-25 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent may return outdated value after webView.customUserAgent is set >+ https://bugs.webkit.org/show_bug.cgi?id=188009 >+ <rdar://problem/42566456> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Let the page know when the user agent changes. >+ >+ * WebView/WebView.mm: >+ (-[WebView _preferencesChanged:]): >+ (-[WebView setApplicationNameForUserAgent:]): >+ (-[WebView _invalidateUserAgentCache]): >+ (-[WebView setCustomUserAgent:]): >+ * WebView/WebViewInternal.h: >+ > 2018-07-24 Tim Horton <timothy_horton@apple.com> > > Enable Web Content Filtering on watchOS >diff --git a/Source/WebCore/page/Navigator.cpp b/Source/WebCore/page/Navigator.cpp >index 9a8d268c8817b35b40369dc2ac6e039408abf30f..78098006b72bc17a6d159fd2ad18dc7f773b659c 100644 >--- a/Source/WebCore/page/Navigator.cpp >+++ b/Source/WebCore/page/Navigator.cpp >@@ -84,6 +84,11 @@ const String& Navigator::userAgent() const > return m_userAgent; > } > >+void Navigator::userAgentChanged() >+{ >+ m_userAgent = String(); >+} >+ > bool Navigator::onLine() const > { > return platformStrategies()->loaderStrategy()->isOnLine(); >diff --git a/Source/WebCore/page/Navigator.h b/Source/WebCore/page/Navigator.h >index 1816e3a56d1d7c21102cea26b7eb6658123997ca..b86ed89daff4b698a9c13790c2d75341f3a06a6a 100644 >--- a/Source/WebCore/page/Navigator.h >+++ b/Source/WebCore/page/Navigator.h >@@ -40,6 +40,7 @@ public: > bool cookieEnabled() const; > bool javaEnabled() const; > const String& userAgent() const final; >+ void userAgentChanged(); > bool onLine() const final; > > #if PLATFORM(IOS) >diff --git a/Source/WebCore/page/NavigatorID.idl b/Source/WebCore/page/NavigatorID.idl >index f6b14faefc33bc5d0050208402c75eecc7a64383..57967ce5c183b66d318919c269cc3539c0d573e1 100644 >--- a/Source/WebCore/page/NavigatorID.idl >+++ b/Source/WebCore/page/NavigatorID.idl >@@ -35,7 +35,7 @@ > readonly attribute DOMString platform; > readonly attribute DOMString product; > [Exposed=Window] readonly attribute DOMString productSub; >- [CachedAttribute] readonly attribute DOMString userAgent; >+ readonly attribute DOMString userAgent; > [Exposed=Window] readonly attribute DOMString vendor; > [Exposed=Window] readonly attribute DOMString vendorSub; > }; >diff --git a/Source/WebCore/page/Page.cpp b/Source/WebCore/page/Page.cpp >index ee86ccd026099f2f7205ac8855ab903e09accb40..2c466d2326eaf0515fefe0d1aac18ef15a3abd6c 100644 >--- a/Source/WebCore/page/Page.cpp >+++ b/Source/WebCore/page/Page.cpp >@@ -1238,6 +1238,17 @@ const String& Page::userStyleSheet() const > return m_userStyleSheet; > } > >+void Page::userAgentChanged() >+{ >+ for (auto* frame = &m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) { >+ auto* window = frame->window(); >+ if (!window) >+ continue; >+ if (auto* navigator = window->optionalNavigator()) >+ navigator->userAgentChanged(); >+ } >+} >+ > void Page::invalidateStylesForAllLinks() > { > for (Frame* frame = &m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) { >diff --git a/Source/WebCore/page/Page.h b/Source/WebCore/page/Page.h >index e0696745089360f665ee29a75e0dafc8dc29d0ed..915e846113a81ab3b57edb4a305ca0c339797a8e 100644 >--- a/Source/WebCore/page/Page.h >+++ b/Source/WebCore/page/Page.h >@@ -439,6 +439,8 @@ public: > void userStyleSheetLocationChanged(); > const String& userStyleSheet() const; > >+ WEBCORE_EXPORT void userAgentChanged(); >+ > void dnsPrefetchingStateChanged(); > void storageBlockingStateChanged(); > >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >index 78749198da155d169c99dfb6f3e19dcaf3bc75cb..c232dd99b16c906a06037e4fb672d73d1fe88f88 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >@@ -2909,7 +2909,13 @@ String WebPage::userAgent(WebFrame* frame, const URL& webcoreURL) const > > void WebPage::setUserAgent(const String& userAgent) > { >+ if (m_userAgent == userAgent) >+ return; >+ > m_userAgent = userAgent; >+ >+ if (m_page) >+ m_page->userAgentChanged(); > } > > void WebPage::suspendActiveDOMObjectsAndAnimations() >diff --git a/Source/WebKitLegacy/mac/WebView/WebView.mm b/Source/WebKitLegacy/mac/WebView/WebView.mm >index 9edb0de7bd7b487279831e44f9786790306c824b..808c3c09dfadff3c1292c15b299b59a062aa0578 100644 >--- a/Source/WebKitLegacy/mac/WebView/WebView.mm >+++ b/Source/WebKitLegacy/mac/WebView/WebView.mm >@@ -2795,7 +2795,7 @@ - (void)_preferencesChanged:(WebPreferences *)preferences > { > ASSERT(preferences == [self preferences]); > if (!_private->userAgentOverridden) >- _private->userAgent = String(); >+ [self _invalidateUserAgentCache]; > > // Cache this value so we don't have to read NSUserDefaults on each page load > _private->useSiteSpecificSpoofing = [preferences _useSiteSpecificSpoofing]; >@@ -6580,7 +6580,17 @@ - (void)setApplicationNameForUserAgent:(NSString *)applicationName > [_private->applicationNameForUserAgent release]; > _private->applicationNameForUserAgent = name; > if (!_private->userAgentOverridden) >- _private->userAgent = String(); >+ [self _invalidateUserAgentCache]; >+} >+ >+- (void)_invalidateUserAgentCache >+{ >+ if (_private->userAgent.isNull()) >+ return; >+ >+ _private->userAgent = String(); >+ if (_private->page) >+ _private->page->userAgentChanged(); > } > > - (NSString *)applicationNameForUserAgent >@@ -6590,6 +6600,7 @@ - (NSString *)applicationNameForUserAgent > > - (void)setCustomUserAgent:(NSString *)userAgentString > { >+ [self _invalidateUserAgentCache]; > _private->userAgent = userAgentString; > _private->userAgentOverridden = userAgentString != nil; > } >diff --git a/Source/WebKitLegacy/mac/WebView/WebViewInternal.h b/Source/WebKitLegacy/mac/WebView/WebViewInternal.h >index c394a8f91d430941f6461ddd9be6686634c642ac..90fa38770859ef1e8bacffac42fcc10a05e5499a 100644 >--- a/Source/WebKitLegacy/mac/WebView/WebViewInternal.h >+++ b/Source/WebKitLegacy/mac/WebView/WebViewInternal.h >@@ -267,6 +267,7 @@ OBJC_CLASS NSTextAlternatives; > #endif > > - (void)_preferencesChanged:(WebPreferences *)preferences; >+- (void)_invalidateUserAgentCache; > > #if ENABLE(VIDEO) && defined(__cplusplus) > - (void)_enterVideoFullscreenForVideoElement:(WebCore::HTMLVideoElement*)videoElement mode:(WebCore::HTMLMediaElementEnums::VideoFullscreenMode)mode; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 881621798fd915639ac74c535b97359b5f515dbc..c4e240a1b3861d785352d586cd58b1f7bbd67b8f 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,17 @@ >+2018-07-25 Chris Dumez <cdumez@apple.com> >+ >+ navigator.userAgent may return outdated value after webView.customUserAgent is set >+ https://bugs.webkit.org/show_bug.cgi?id=188009 >+ <rdar://problem/42566456> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add API test coverage. >+ >+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/WebKitCocoa/CustomUserAgent.mm: Added. >+ (TEST): >+ > 2018-07-25 Charlie Turner <cturner@igalia.com> > > [Flatpak] Pass more environment variables to sandbox >diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index 29d942b1e79124ba009bf7fe2ae5ee349c2fdeb5..af7b554af24a67242dff8c877af92b55d57c599d 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -160,6 +160,7 @@ > 46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; }; > 4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */; }; > 466C3843210637DE006A88DE /* notify-resourceLoadObserver.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */; }; >+ 46A911592108E6780078D40D /* CustomUserAgent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A911582108E66B0078D40D /* CustomUserAgent.mm */; }; > 46AE5A3720F9066D00E0873E /* SimpleServiceWorkerRegistrations-3.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4656A75720F9054F0002E21F /* SimpleServiceWorkerRegistrations-3.sqlite3 */; }; > 46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */; }; > 46C519E61D3563FD00DAA51A /* LocalStorageNullEntries.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46C519E21D35629600DAA51A /* LocalStorageNullEntries.html */; }; >@@ -1401,6 +1402,7 @@ > 4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessDidTerminate.cpp; sourceTree = "<group>"; }; > 4656A75720F9054F0002E21F /* SimpleServiceWorkerRegistrations-3.sqlite3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SimpleServiceWorkerRegistrations-3.sqlite3"; sourceTree = "<group>"; }; > 466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "notify-resourceLoadObserver.html"; sourceTree = "<group>"; }; >+ 46A911582108E66B0078D40D /* CustomUserAgent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomUserAgent.mm; sourceTree = "<group>"; }; > 46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageNullEntries.mm; sourceTree = "<group>"; }; > 46C519E21D35629600DAA51A /* LocalStorageNullEntries.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LocalStorageNullEntries.html; sourceTree = "<group>"; }; > 46C519E31D35629600DAA51A /* LocalStorageNullEntries.localstorage */ = {isa = PBXFileReference; lastKnownFileType = file; path = LocalStorageNullEntries.localstorage; sourceTree = "<group>"; }; >@@ -2255,6 +2257,7 @@ > 9B1056411F9045C700D5583F /* CopyHTML.mm */, > 9999108A1F393C8B008AD455 /* Copying.mm */, > 9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */, >+ 46A911582108E66B0078D40D /* CustomUserAgent.mm */, > 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */, > 518EE51C20A78D3300E024F3 /* DecidePolicyForNavigationAction.mm */, > CEA7F57B20895F5B0078EF6E /* DidResignInputElementStrongPasswordAppearance.mm */, >@@ -3639,6 +3642,7 @@ > 7CCE7F291A411B1000447C4C /* CustomProtocolsInvalidScheme.mm in Sources */, > 7CCE7F2A1A411B1000447C4C /* CustomProtocolsSyncXHRTest.mm in Sources */, > 7CCE7F2B1A411B1000447C4C /* CustomProtocolsTest.mm in Sources */, >+ 46A911592108E6780078D40D /* CustomUserAgent.mm in Sources */, > 751B05D61F8EAC410028A09E /* DatabaseTrackerTest.mm in Sources */, > 2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */, > F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */, >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/CustomUserAgent.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CustomUserAgent.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..88612230b6353d25d163f722fe97601cf2639239 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CustomUserAgent.mm >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#import "PlatformUtilities.h" >+#import "TestNavigationDelegate.h" >+#import <WebKit/WebKit.h> >+#import <wtf/RetainPtr.h> >+ >+static bool done = false; >+ >+TEST(CustomUserAgent, UpdateCachedNavigatorUserAgent) >+{ >+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); >+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; >+ >+ [webView _test_waitForDidFinishNavigation]; >+ >+ // Query navigator.userAgent once so it gets cached. >+ [webView evaluateJavaScript:@"navigator.userAgent;" completionHandler:^(id _Nullable response, NSError * _Nullable error) { >+ ASSERT_TRUE(!error); >+ NSString *userAgent = (NSString *)response; >+ ASSERT_TRUE(!!userAgent); >+ // Override user agent with a custom one. >+ webView.get().customUserAgent = @"Custom UserAgent"; >+ done = true; >+ }]; >+ TestWebKitAPI::Util::run(&done); >+ done = false; >+ >+ // Query navigator.userAgent again to make sure its cache was invalidated and it returns the updated value. >+ [webView evaluateJavaScript:@"navigator.userAgent;" completionHandler:^(id _Nullable response, NSError * _Nullable error) { >+ ASSERT_TRUE(!error); >+ NSString *userAgent = (NSString *)response; >+ ASSERT_TRUE(!!userAgent); >+ EXPECT_WK_STREQ(@"Custom UserAgent", userAgent); >+ done = true; >+ }]; >+ TestWebKitAPI::Util::run(&done); >+ done = false; >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188009
:
345768
|
345772