Title: [176340] trunk/Source/WebKit2
- Revision
- 176340
- Author
- [email protected]
- Date
- 2014-11-19 14:07:22 -0800 (Wed, 19 Nov 2014)
Log Message
Add APIs for customizing the user agent
https://bugs.webkit.org/show_bug.cgi?id=138881
rdar://problem/17233981
Reviewed by Dan Bernstein.
* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
(-[WKWebView customUserAgent]):
(-[WKWebView setCustomUserAgent:]):
(-[WKWebView _customUserAgent]):
(-[WKWebView _setCustomUserAgent:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.h:
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(LazyInitialized::set):
(-[WKWebViewConfiguration copyWithZone:]):
(defaultApplicationNameForUserAgent):
(-[WKWebViewConfiguration applicationNameForUserAgent]):
(-[WKWebViewConfiguration setApplicationNameForUserAgent:]):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (176339 => 176340)
--- trunk/Source/WebKit2/ChangeLog 2014-11-19 22:05:03 UTC (rev 176339)
+++ trunk/Source/WebKit2/ChangeLog 2014-11-19 22:07:22 UTC (rev 176340)
@@ -1,3 +1,26 @@
+2014-11-19 Anders Carlsson <[email protected]>
+
+ Add APIs for customizing the user agent
+ https://bugs.webkit.org/show_bug.cgi?id=138881
+ rdar://problem/17233981
+
+ Reviewed by Dan Bernstein.
+
+ * UIProcess/API/Cocoa/WKWebView.h:
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView initWithFrame:configuration:]):
+ (-[WKWebView customUserAgent]):
+ (-[WKWebView setCustomUserAgent:]):
+ (-[WKWebView _customUserAgent]):
+ (-[WKWebView _setCustomUserAgent:]):
+ * UIProcess/API/Cocoa/WKWebViewConfiguration.h:
+ * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+ (LazyInitialized::set):
+ (-[WKWebViewConfiguration copyWithZone:]):
+ (defaultApplicationNameForUserAgent):
+ (-[WKWebViewConfiguration applicationNameForUserAgent]):
+ (-[WKWebViewConfiguration setApplicationNameForUserAgent:]):
+
2014-11-19 Simon Fraser <[email protected]>
[WK2 UI-side compositing] Initialize RemoteLayerTreeTransaction properties which are unset on Mac
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h (176339 => 176340)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h 2014-11-19 22:05:03 UTC (rev 176339)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h 2014-11-19 22:07:22 UTC (rev 176340)
@@ -209,6 +209,10 @@
*/
@property (nonatomic) BOOL allowsBackForwardNavigationGestures;
+/*! @abstract The custom user agent string or nil if no custom user agent string has been set.
+*/
+@property (nonatomic, copy) NSString *customUserAgent WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
#if TARGET_OS_IPHONE
/*! @abstract The scroll view associated with the web view.
*/
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (176339 => 176340)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2014-11-19 22:05:03 UTC (rev 176339)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2014-11-19 22:07:22 UTC (rev 176340)
@@ -300,7 +300,6 @@
_contentView = adoptNS([[WKContentView alloc] initWithFrame:bounds context:context configuration:WTF::move(webPageConfiguration) webView:self]);
_page = [_contentView page];
- _page->setApplicationNameForUserAgent([@"Mobile/" stringByAppendingString:[UIDevice currentDevice].buildVersion]);
_page->setDeviceOrientation(deviceOrientation());
[_contentView layer].anchorPoint = CGPointZero;
@@ -337,6 +336,9 @@
_page->setBackgroundExtendsBeyondPage(true);
+ if (NSString *applicationNameForUserAgent = configuration.applicationNameForUserAgent)
+ _page->setApplicationNameForUserAgent(applicationNameForUserAgent);
+
_navigationState = std::make_unique<WebKit::NavigationState>(self);
_page->setPolicyClient(_navigationState->createPolicyClient());
_page->setLoaderClient(_navigationState->createLoaderClient());
@@ -591,6 +593,16 @@
});
}
+- (NSString *)customUserAgent
+{
+ return _page->customUserAgent();
+}
+
+- (void)setCustomUserAgent:(NSString *)customUserAgent
+{
+ _page->setCustomUserAgent(customUserAgent);
+}
+
#pragma mark iOS-specific methods
#if PLATFORM(IOS)
@@ -1659,12 +1671,13 @@
- (NSString *)_customUserAgent
{
- return _page->customUserAgent();
+ return self.customUserAgent;
+
}
-- (void)_setCustomUserAgent:(NSString *)_customUserAgent
+- (void)_setCustomUserAgent:(NSString *)customUserAgent
{
- _page->setCustomUserAgent(_customUserAgent);
+ self.customUserAgent = customUserAgent;
}
- (pid_t)_webProcessIdentifier
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h (176339 => 176340)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h 2014-11-19 22:05:03 UTC (rev 176339)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h 2014-11-19 22:07:22 UTC (rev 176340)
@@ -77,6 +77,10 @@
*/
@property (nonatomic) BOOL suppressesIncrementalRendering;
+/*! @abstract The name of the application as used in the user agent string.
+*/
+@property (nonatomic, copy) NSString *applicationNameForUserAgent WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
#if TARGET_OS_IPHONE
/*! @abstract A Boolean value indicating whether HTML5 videos play inline
(YES) or use the native full-screen controller (NO).
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (176339 => 176340)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm 2014-11-19 22:05:03 UTC (rev 176339)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm 2014-11-19 22:07:22 UTC (rev 176340)
@@ -56,6 +56,12 @@
m_isInitialized = true;
}
+ void set(RetainPtr<T>&& t)
+ {
+ m_value = WTF::move(t);
+ m_isInitialized = true;
+ }
+
T* peek()
{
return m_value.get();
@@ -75,6 +81,8 @@
WebKit::WeakObjCPtr<WKWebView> _relatedWebView;
WebKit::WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures;
RetainPtr<NSString> _groupIdentifier;
+ LazyInitialized<NSString> _applicationNameForUserAgent;
+
#if PLATFORM(IOS)
LazyInitialized<WKWebViewContentProviderRegistry> _contentProviderRegistry;
BOOL _allowsAlternateFullscreen;
@@ -116,6 +124,8 @@
#endif
configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
+ configuration.applicationNameForUserAgent = self.applicationNameForUserAgent;
+
#if PLATFORM(IOS)
configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
configuration->_allowsAlternateFullscreen = self->_allowsAlternateFullscreen;
@@ -157,6 +167,25 @@
_userContentController.set(userContentController);
}
+static NSString *defaultApplicationNameForUserAgent()
+{
+#if PLATFORM(IOS)
+ return [@"Mobile/" stringByAppendingString:[UIDevice currentDevice].buildVersion];
+#else
+ return nil;
+#endif
+}
+
+- (NSString *)applicationNameForUserAgent
+{
+ return _applicationNameForUserAgent.get([] { return defaultApplicationNameForUserAgent(); });
+}
+
+- (void)setApplicationNameForUserAgent:(NSString *)applicationNameForUserAgent
+{
+ _applicationNameForUserAgent.set(adoptNS([applicationNameForUserAgent copy]));
+}
+
- (_WKVisitedLinkProvider *)_visitedLinkProvider
{
return _visitedLinkProvider.get([] { return adoptNS([[_WKVisitedLinkProvider alloc] init]); });
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes