Add APIs for customizing the user agent
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / Cocoa / WKWebViewConfiguration.mm
index d534f70..06ed882 100644 (file)
@@ -56,6 +56,12 @@ public:
         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 @@ private:
     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 @@ private:
 #endif
 
     configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
+    configuration.applicationNameForUserAgent = self.applicationNameForUserAgent;
+
 #if PLATFORM(IOS)
     configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
     configuration->_allowsAlternateFullscreen = self->_allowsAlternateFullscreen;
@@ -157,6 +167,25 @@ private:
     _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]); });