WorkerNavigator is missing some attributes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2016 17:44:20 +0000 (17:44 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2016 17:44:20 +0000 (17:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158593
<rdar://problem/26731334>

Reviewed by Darin Adler.

Source/WebCore:

Add attributes that are missing on WorkerNavigator:
- appCodeName
- hardwareConcurrency
- language
- product
- productSub
- vendor
- vendorSub

Firefox and Chrome already expose those attributes.

Relevant specification:
https://html.spec.whatwg.org/multipage/workers.html#the-workernavigator-object

This patch also refactors the IDL to match the specification more
closely and promote sharing between Navigator and WorkerNavigator.

No new tests, updated existing test.

* CMakeLists.txt:
* DerivedSources.make:
Add new supplemental IDL files.

* page/Navigator.cpp:
* page/Navigator.h:
Moved language() / hardwareConcurrency() from Navigator to NavigatorBase
so that it can be used by NavigatorWorker as well.

* page/NavigatorBase.h:
* page/NavigatorBase.cpp:
(WebCore::NavigatorBase::language):
The implementation still calls defaultLanguage() but I updated it to be
thread safe on all platforms.

(WebCore::NavigatorBase::hardwareConcurrency):
Use std::call_once() for thread safety.

* page/Navigator.idl:
* page/NavigatorConcurrentHardware.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
* page/NavigatorID.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
* page/NavigatorLanguage.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
* page/NavigatorOnLine.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
* page/WorkerNavigator.idl:
Move several attributes to their own supplemental interfaces to match
the specification and promote sharing with WorkerNavigator.

* platform/Language.cpp:
(WebCore::userPreferredLanguages):
* platform/Language.h:
Made thread-safe on all platforms.

Source/WTF:

* wtf/PlatformUserPreferredLanguages.h:
* wtf/PlatformUserPreferredLanguagesWin.cpp:
(WTF::platformLanguage):
(WTF::platformUserPreferredLanguages):

Make platformUserPreferredLanguages() thread safe on Windows. The
Mac and Unix implementations are already thread-safe.

LayoutTests:

Improved test coverage for WorkerNavigator.

* fast/workers/resources/worker-navigator.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201970 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/workers/resources/worker-navigator.js
LayoutTests/fast/workers/worker-navigator-expected.txt
Source/WTF/ChangeLog
Source/WTF/wtf/PlatformUserPreferredLanguages.h
Source/WTF/wtf/PlatformUserPreferredLanguagesWin.cpp
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/page/Navigator.cpp
Source/WebCore/page/Navigator.h
Source/WebCore/page/Navigator.idl
Source/WebCore/page/NavigatorBase.cpp
Source/WebCore/page/NavigatorBase.h
Source/WebCore/page/NavigatorConcurrentHardware.idl [new file with mode: 0644]
Source/WebCore/page/NavigatorID.idl [new file with mode: 0644]
Source/WebCore/page/NavigatorLanguage.idl [new file with mode: 0644]
Source/WebCore/page/NavigatorOnLine.idl [new file with mode: 0644]
Source/WebCore/page/WorkerNavigator.idl
Source/WebCore/platform/Language.cpp
Source/WebCore/platform/Language.h

index 28e3486..c40c681 100644 (file)
@@ -1,3 +1,15 @@
+2016-06-11  Chris Dumez  <cdumez@apple.com>
+
+        WorkerNavigator is missing some attributes
+        https://bugs.webkit.org/show_bug.cgi?id=158593
+        <rdar://problem/26731334>
+
+        Reviewed by Darin Adler.
+
+        Improved test coverage for WorkerNavigator.
+
+        * fast/workers/resources/worker-navigator.js:
+
 2016-06-10  Antti Koivisto  <antti@apple.com>
 
         Vary:Cookie validation doesn't work in private browsing
index d1972ba..87026e3 100644 (file)
@@ -11,11 +11,28 @@ if (window.testRunner) {
 var worker = createWorker();
 worker.postMessage("eval typeof navigator");
 worker.postMessage("eval navigator");
-worker.postMessage("eval navigator.appName");
+
+// NavigatorConcurrentHardware
+worker.postMessage("eval navigator.hardwareConcurrency >= 1 && navigator.hardwareConcurrency <= 8");
+
+// NavigatorID
+worker.postMessage("eval navigator.appCodeName === 'Mozilla'");
+worker.postMessage("eval navigator.appName === 'Netscape'");
 worker.postMessage("eval navigator.appVersion.indexOf('WebKit') != 0");
-worker.postMessage("eval typeof navigator.platform");
+worker.postMessage("eval typeof navigator.platform == 'string'");
+worker.postMessage("eval navigator.product === 'Gecko'");
+worker.postMessage("eval navigator.productSub === '20030107'");
 worker.postMessage("eval navigator.userAgent.indexOf('WebKit') != 0");
-worker.postMessage("eval typeof navigator.onLine");
+worker.postMessage("eval navigator.vendor === 'Apple Computer, Inc.'");
+worker.postMessage("eval navigator.vendorSub === ''");
+
+// NavigatorLanguage
+worker.postMessage("eval typeof navigator.language == 'string'");
+
+// NavigatorOnLine
+worker.postMessage("eval typeof navigator.onLine == 'boolean'");
+
+
 worker.postMessage("eval foo//bar");
 
 worker.onmessage = function(evt) {
index a80b250..db0d1fd 100644 (file)
@@ -2,10 +2,17 @@ Test Navigator properties.
 
 typeof navigator: object
 navigator: [object WorkerNavigator]
-navigator.appName: Netscape
+navigator.hardwareConcurrency >= 1 && navigator.hardwareConcurrency <= 8: true
+navigator.appCodeName === 'Mozilla': true
+navigator.appName === 'Netscape': true
 navigator.appVersion.indexOf('WebKit') != 0: true
-typeof navigator.platform: string
+typeof navigator.platform == 'string': true
+navigator.product === 'Gecko': true
+navigator.productSub === '20030107': true
 navigator.userAgent.indexOf('WebKit') != 0: true
-typeof navigator.onLine: boolean
+navigator.vendor === 'Apple Computer, Inc.': true
+navigator.vendorSub === '': true
+typeof navigator.language == 'string': true
+typeof navigator.onLine == 'boolean': true
 DONE
 
index aaf6f82..f9b6fb4 100644 (file)
@@ -1,3 +1,19 @@
+2016-06-11  Chris Dumez  <cdumez@apple.com>
+
+        WorkerNavigator is missing some attributes
+        https://bugs.webkit.org/show_bug.cgi?id=158593
+        <rdar://problem/26731334>
+
+        Reviewed by Darin Adler.
+
+        * wtf/PlatformUserPreferredLanguages.h:
+        * wtf/PlatformUserPreferredLanguagesWin.cpp:
+        (WTF::platformLanguage):
+        (WTF::platformUserPreferredLanguages):
+
+        Make platformUserPreferredLanguages() thread safe on Windows. The
+        Mac and Unix implementations are already thread-safe.
+
 2016-06-10  Alex Christensen  <achristensen@webkit.org>
 
         Introduce WTF::UniqueRef
index 63f695d..93580fc 100644 (file)
@@ -33,6 +33,7 @@ namespace WTF {
 
 WTF_EXPORT_PRIVATE void setPlatformUserPreferredLanguagesChangedCallback(void (*)());
 
+// This is thread-safe.
 WTF_EXPORT_PRIVATE Vector<String> platformUserPreferredLanguages();
 
 } // namespace WTF
index 0f38640..79ad23c 100644 (file)
 #include "config.h"
 #include "PlatformUserPreferredLanguages.h"
 
+#include <mutex>
 #include <windows.h>
+#include <wtf/Lock.h>
 #include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
 namespace WTF {
 
+static StaticLock platformLanguageMutex;
+
 void setPlatformUserPreferredLanguagesChangedCallback(void (*)()) { }
 
 static String localeInfo(LCTYPE localeType, const String& fallback)
@@ -54,9 +58,11 @@ static String localeInfo(LCTYPE localeType, const String& fallback)
 
 static String platformLanguage()
 {
+    std::lock_guard<StaticLock> lock(platformLanguageMutex);
+
     static String computedDefaultLanguage;
     if (!computedDefaultLanguage.isEmpty())
-        return computedDefaultLanguage;
+        return computedDefaultLanguage.isolatedCopy();
 
     String languageName = localeInfo(LOCALE_SISO639LANGNAME, "en");
     String countryName = localeInfo(LOCALE_SISO3166CTRYNAME, String());
@@ -71,9 +77,7 @@ static String platformLanguage()
 
 Vector<String> platformUserPreferredLanguages()
 {
-    Vector<String> userPreferredLanguages;
-    userPreferredLanguages.append(platformLanguage());
-    return userPreferredLanguages;
+    return { platformLanguage() };
 }
 
 } // namespace WTF
index 5939413..a711ce4 100644 (file)
@@ -603,6 +603,10 @@ set(WebCore_NON_SVG_IDL_FILES
     page/History.idl
     page/Location.idl
     page/Navigator.idl
+    page/NavigatorConcurrentHardware.idl
+    page/NavigatorID.idl
+    page/NavigatorLanguage.idl
+    page/NavigatorOnLine.idl
     page/Performance.idl
     page/PerformanceEntry.idl
     page/PerformanceEntryList.idl
index f87ed36..e1ba30a 100644 (file)
@@ -1,3 +1,62 @@
+2016-06-11  Chris Dumez  <cdumez@apple.com>
+
+        WorkerNavigator is missing some attributes
+        https://bugs.webkit.org/show_bug.cgi?id=158593
+        <rdar://problem/26731334>
+
+        Reviewed by Darin Adler.
+
+        Add attributes that are missing on WorkerNavigator:
+        - appCodeName
+        - hardwareConcurrency
+        - language
+        - product
+        - productSub
+        - vendor
+        - vendorSub
+
+        Firefox and Chrome already expose those attributes.
+
+        Relevant specification:
+        https://html.spec.whatwg.org/multipage/workers.html#the-workernavigator-object
+
+        This patch also refactors the IDL to match the specification more
+        closely and promote sharing between Navigator and WorkerNavigator.
+
+        No new tests, updated existing test.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        Add new supplemental IDL files.
+
+        * page/Navigator.cpp:
+        * page/Navigator.h:
+        Moved language() / hardwareConcurrency() from Navigator to NavigatorBase
+        so that it can be used by NavigatorWorker as well.
+
+        * page/NavigatorBase.h:
+        * page/NavigatorBase.cpp:
+        (WebCore::NavigatorBase::language):
+        The implementation still calls defaultLanguage() but I updated it to be
+        thread safe on all platforms.
+
+        (WebCore::NavigatorBase::hardwareConcurrency):
+        Use std::call_once() for thread safety.
+
+        * page/Navigator.idl:
+        * page/NavigatorConcurrentHardware.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
+        * page/NavigatorID.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
+        * page/NavigatorLanguage.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
+        * page/NavigatorOnLine.idl: Copied from Source/WebCore/page/WorkerNavigator.idl.
+        * page/WorkerNavigator.idl:
+        Move several attributes to their own supplemental interfaces to match
+        the specification and promote sharing with WorkerNavigator.
+
+        * platform/Language.cpp:
+        (WebCore::userPreferredLanguages):
+        * platform/Language.h:
+        Made thread-safe on all platforms.
+
 2016-06-11  Antti Koivisto  <antti@apple.com>
 
         Build fix.
index 3b4a433..e3a9061 100644 (file)
@@ -514,6 +514,10 @@ NON_SVG_BINDING_IDLS = \
     $(WebCore)/page/History.idl \
     $(WebCore)/page/Location.idl \
     $(WebCore)/page/Navigator.idl \
+    $(WebCore)/page/NavigatorConcurrentHardware.idl \
+    $(WebCore)/page/NavigatorID.idl \
+    $(WebCore)/page/NavigatorLanguage.idl \
+    $(WebCore)/page/NavigatorOnLine.idl \
     $(WebCore)/page/Performance.idl \
     $(WebCore)/page/PerformanceEntry.idl \
     $(WebCore)/page/PerformanceEntryList.idl \
index 25895bf..7f6532a 100644 (file)
@@ -38,7 +38,6 @@
 #include "SecurityOrigin.h"
 #include "Settings.h"
 #include <wtf/HashSet.h>
-#include <wtf/NumberOfCores.h>
 #include <wtf/StdLibExtras.h>
 
 using namespace WTF;
@@ -78,11 +77,6 @@ String Navigator::appVersion() const
     return appVersion;
 }
 
-String Navigator::language() const
-{
-    return defaultLanguage();
-}
-
 String Navigator::userAgent() const
 {
     if (!m_frame)
@@ -134,28 +128,6 @@ bool Navigator::javaEnabled() const
     return true;
 }
 
-#if defined(ENABLE_NAVIGATOR_HWCONCURRENCY)
-int Navigator::hardwareConcurrency() const
-{
-    // Enforce a maximum for the number of cores reported to mitigate
-    // fingerprinting for the minority of machines with large numbers of cores.
-    // If machines with more than 8 cores become commonplace, we should bump this number.
-    // see https://bugs.webkit.org/show_bug.cgi?id=132588 for the
-    // rationale behind this decision.
-#if PLATFORM(IOS)
-    const int maxCoresToReport = 2;
-#else
-    const int maxCoresToReport = 8;
-#endif
-    int hardwareConcurrency = numberOfProcessorCores();
-
-    if (hardwareConcurrency > maxCoresToReport)
-        return maxCoresToReport;
-
-    return hardwareConcurrency;
-}
-#endif
-
 #if PLATFORM(IOS)
 bool Navigator::standalone() const
 {
index 16abdd8..fbb12c4 100644 (file)
@@ -45,14 +45,10 @@ public:
     virtual ~Navigator();
 
     String appVersion() const;
-    String language() const;
     DOMPluginArray* plugins() const;
     DOMMimeTypeArray* mimeTypes() const;
     bool cookieEnabled() const;
     bool javaEnabled() const;
-#if defined(ENABLE_NAVIGATOR_HWCONCURRENCY)
-    int hardwareConcurrency() const;
-#endif
     virtual String userAgent() const;
 
 #if PLATFORM(IOS)
index bdce4f2..152c566 100644 (file)
 [
     GenerateIsReachable=ImplFrame,
 ] interface Navigator {
-    [Nondeterministic] readonly attribute DOMString appCodeName;
-    [Nondeterministic] readonly attribute DOMString appName;
-    [Nondeterministic] readonly attribute DOMString appVersion;
-    [Nondeterministic] readonly attribute DOMString language;
-    [Nondeterministic] readonly attribute DOMString userAgent;
-    [Nondeterministic] readonly attribute DOMString platform;
     readonly attribute DOMPluginArray plugins;
     readonly attribute DOMMimeTypeArray mimeTypes;
-    [Nondeterministic] readonly attribute DOMString product;
-    [Nondeterministic] readonly attribute DOMString productSub;
-    [Nondeterministic] readonly attribute DOMString vendor;
-    [Nondeterministic] readonly attribute DOMString vendorSub;
     [Nondeterministic] readonly attribute boolean cookieEnabled;
     [Nondeterministic] boolean javaEnabled();
 
-    readonly attribute boolean onLine;
-
-#if defined(ENABLE_NAVIGATOR_HWCONCURRENCY)
-    readonly attribute long hardwareConcurrency;
-#endif
-
     // FIXME: Convert this #if'def to an IDL conditional attribute.
 #if defined(WTF_PLATFORM_IOS) && WTF_PLATFORM_IOS
     readonly attribute boolean standalone;
@@ -49,3 +33,7 @@
     void getStorageUpdates(); // FIXME: Remove this method or rename to yieldForStorageUpdates.
 };
 
+Navigator implements NavigatorConcurrentHardware;
+Navigator implements NavigatorID;
+Navigator implements NavigatorLanguage;
+Navigator implements NavigatorOnLine;
index 0be2e1f..91cc9f5 100644 (file)
 #include "config.h"
 #include "NavigatorBase.h"
 
+#include "Language.h"
 #include "NetworkStateNotifier.h"
+#include <mutex>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/NumberOfCores.h>
 #include <wtf/text/WTFString.h>
 
 #if OS(LINUX)
 #if PLATFORM(IOS)
 #define WEBCORE_NAVIGATOR_PLATFORM deviceName()
 #elif OS(MAC_OS_X) && (CPU(PPC) || CPU(PPC64))
-#define WEBCORE_NAVIGATOR_PLATFORM "MacPPC"
+#define WEBCORE_NAVIGATOR_PLATFORM ASCIILiteral("MacPPC")
 #elif OS(MAC_OS_X) && (CPU(X86) || CPU(X86_64))
-#define WEBCORE_NAVIGATOR_PLATFORM "MacIntel"
+#define WEBCORE_NAVIGATOR_PLATFORM ASCIILiteral("MacIntel")
 #elif OS(WINDOWS)
-#define WEBCORE_NAVIGATOR_PLATFORM "Win32"
+#define WEBCORE_NAVIGATOR_PLATFORM ASCIILiteral("Win32")
 #else
-#define WEBCORE_NAVIGATOR_PLATFORM ""
+#define WEBCORE_NAVIGATOR_PLATFORM emptyString()
 #endif
 #endif // ifndef WEBCORE_NAVIGATOR_PLATFORM
 
 #ifndef WEBCORE_NAVIGATOR_PRODUCT
-#define WEBCORE_NAVIGATOR_PRODUCT "Gecko"
+#define WEBCORE_NAVIGATOR_PRODUCT ASCIILiteral("Gecko")
 #endif // ifndef WEBCORE_NAVIGATOR_PRODUCT
 
 #ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
-#define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
+#define WEBCORE_NAVIGATOR_PRODUCT_SUB ASCIILiteral("20030107")
 #endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
 
 #ifndef WEBCORE_NAVIGATOR_VENDOR
-#define WEBCORE_NAVIGATOR_VENDOR "Apple Computer, Inc."
+#define WEBCORE_NAVIGATOR_VENDOR ASCIILiteral("Apple Computer, Inc.")
 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR
 
 #ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
-#define WEBCORE_NAVIGATOR_VENDOR_SUB ""
+#define WEBCORE_NAVIGATOR_VENDOR_SUB emptyString()
 #endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
 
 namespace WebCore {
@@ -76,9 +79,9 @@ NavigatorBase::~NavigatorBase()
 {
 }
 
-String NavigatorBase::appName() const
+String NavigatorBase::appName()
 {
-    return "Netscape";
+    return ASCIILiteral("Netscape");
 }
 
 String NavigatorBase::appVersion() const
@@ -88,7 +91,7 @@ String NavigatorBase::appVersion() const
     return agent.substring(agent.find('/') + 1);
 }
 
-String NavigatorBase::platform() const
+String NavigatorBase::platform()
 {
 #if OS(LINUX)
     if (!String(WEBCORE_NAVIGATOR_PLATFORM).isEmpty())
@@ -101,34 +104,65 @@ String NavigatorBase::platform() const
 #endif
 }
 
-String NavigatorBase::appCodeName() const
+String NavigatorBase::appCodeName()
 {
-    return "Mozilla";
+    return ASCIILiteral("Mozilla");
 }
 
-String NavigatorBase::product() const
+String NavigatorBase::product()
 {
     return WEBCORE_NAVIGATOR_PRODUCT;
 }
 
-String NavigatorBase::productSub() const
+String NavigatorBase::productSub()
 {
     return WEBCORE_NAVIGATOR_PRODUCT_SUB;
 }
 
-String NavigatorBase::vendor() const
+String NavigatorBase::vendor()
 {
     return WEBCORE_NAVIGATOR_VENDOR;
 }
 
-String NavigatorBase::vendorSub() const
+String NavigatorBase::vendorSub()
 {
     return WEBCORE_NAVIGATOR_VENDOR_SUB;
 }
 
-bool NavigatorBase::onLine() const
+bool NavigatorBase::onLine()
 {
     return networkStateNotifier().onLine();
 }
 
+String NavigatorBase::language()
+{
+    return defaultLanguage();
+}
+
+#if ENABLE(NAVIGATOR_HWCONCURRENCY)
+
+int NavigatorBase::hardwareConcurrency()
+{
+    static int numberOfCores;
+
+    static std::once_flag once;
+    std::call_once(once, [] {
+        // Enforce a maximum for the number of cores reported to mitigate
+        // fingerprinting for the minority of machines with large numbers of cores.
+        // If machines with more than 8 cores become commonplace, we should bump this number.
+        // see https://bugs.webkit.org/show_bug.cgi?id=132588 for the
+        // rationale behind this decision.
+#if PLATFORM(IOS)
+        const int maxCoresToReport = 2;
+#else
+        const int maxCoresToReport = 8;
+#endif
+        numberOfCores = std::min(WTF::numberOfProcessorCores(), maxCoresToReport);
+    });
+
+    return numberOfCores;
+}
+
+#endif
+
 } // namespace WebCore
index 5283f56..92f4343 100644 (file)
 
 namespace WebCore {
 
-    class NavigatorBase {
-    public:
-        String appName() const;
-        String appVersion() const;
-        virtual String userAgent() const = 0;
-        String platform() const;
-
-        String appCodeName() const;
-        String product() const;
-        String productSub() const;
-        String vendor() const;
-        String vendorSub() const;
-
-        bool onLine() const;
-
-    protected:
-        virtual ~NavigatorBase();
-    };
+class NavigatorBase {
+public:
+    static String appName();
+    String appVersion() const;
+    virtual String userAgent() const = 0;
+    static String platform();
+
+    static String appCodeName();
+    static String product();
+    static String productSub();
+    static String vendor();
+    static String vendorSub();
+
+    static bool onLine();
+
+    static String language();
+
+#if ENABLE(NAVIGATOR_HWCONCURRENCY)
+    static int hardwareConcurrency();
+#endif
+
+protected:
+    virtual ~NavigatorBase();
+};
 
 } // namespace WebCore
 
diff --git a/Source/WebCore/page/NavigatorConcurrentHardware.idl b/Source/WebCore/page/NavigatorConcurrentHardware.idl
new file mode 100644 (file)
index 0000000..b19219a
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 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.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+ */
+
+[
+    NoInterfaceObject
+] interface NavigatorConcurrentHardware {
+    [Conditional=NAVIGATOR_HWCONCURRENCY] readonly attribute unsigned long long hardwareConcurrency;
+};
diff --git a/Source/WebCore/page/NavigatorID.idl b/Source/WebCore/page/NavigatorID.idl
new file mode 100644 (file)
index 0000000..6ca1257
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2016 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.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+ */
+
+[
+    NoInterfaceObject
+] interface NavigatorID {
+    [Nondeterministic] readonly attribute DOMString appCodeName;
+    [Nondeterministic] readonly attribute DOMString appName;
+    [Nondeterministic] readonly attribute DOMString appVersion;
+    [Nondeterministic] readonly attribute DOMString platform;
+    [Nondeterministic] readonly attribute DOMString product;
+    [Nondeterministic] readonly attribute DOMString productSub;
+    [Nondeterministic] readonly attribute DOMString userAgent;
+    [Nondeterministic] readonly attribute DOMString vendor;
+    [Nondeterministic] readonly attribute DOMString vendorSub;
+};
diff --git a/Source/WebCore/page/NavigatorLanguage.idl b/Source/WebCore/page/NavigatorLanguage.idl
new file mode 100644 (file)
index 0000000..66f590f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 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.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+ */
+
+[
+    NoInterfaceObject
+] interface NavigatorLanguage {
+    [Nondeterministic]  readonly attribute DOMString language;
+    // readonly attribute FrozenArray<DOMString> languages;
+};
diff --git a/Source/WebCore/page/NavigatorOnLine.idl b/Source/WebCore/page/NavigatorOnLine.idl
new file mode 100644 (file)
index 0000000..c927635
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 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.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+ */
+
+[
+    NoInterfaceObject
+] interface NavigatorOnLine {
+    readonly attribute boolean onLine;
+};
index 3109cac..f7e7c2a 100644 (file)
     Exposed=Worker,
     GenerateIsReachable=Impl,
 ] interface WorkerNavigator {
-    readonly attribute DOMString appName;
-    readonly attribute DOMString appVersion;
-    readonly attribute DOMString platform;
-    readonly attribute DOMString userAgent;
-
-    readonly attribute boolean onLine;
 };
 
+WorkerNavigator implements NavigatorConcurrentHardware;
+WorkerNavigator implements NavigatorID;
+WorkerNavigator implements NavigatorLanguage;
+WorkerNavigator implements NavigatorOnLine;
index e2f04fd..ec4b349 100644 (file)
@@ -38,6 +38,8 @@
 
 namespace WebCore {
 
+static StaticLock userPreferredLanguagesMutex;
+
 static void registerLanguageDidChangeCallbackIfNecessary()
 {
     static std::once_flag once;
@@ -100,11 +102,23 @@ void overrideUserPreferredLanguages(const Vector<String>& override)
     languageDidChange();
 }
 
+static Vector<String> isolatedCopy(const Vector<String>& strings)
+{
+    Vector<String> copy;
+    copy.reserveInitialCapacity(strings.size());
+    for (auto& language : strings)
+        copy.uncheckedAppend(language.isolatedCopy());
+    return copy;
+}
+
 Vector<String> userPreferredLanguages()
 {
-    Vector<String>& override = preferredLanguagesOverride();
-    if (!override.isEmpty())
-        return override;
+    {
+        std::lock_guard<StaticLock> lock(userPreferredLanguagesMutex);
+        Vector<String>& override = preferredLanguagesOverride();
+        if (!override.isEmpty())
+            return isolatedCopy(override);
+    }
     
     registerLanguageDidChangeCallbackIfNecessary();
     return platformUserPreferredLanguages();
index 7ae5407..112603a 100644 (file)
@@ -31,8 +31,8 @@
 
 namespace WebCore {
 
-WEBCORE_EXPORT String defaultLanguage();
-WEBCORE_EXPORT Vector<String> userPreferredLanguages();
+WEBCORE_EXPORT String defaultLanguage(); // Thread-safe.
+WEBCORE_EXPORT Vector<String> userPreferredLanguages(); // Thread-safe.
 Vector<String> userPreferredLanguagesOverride();
 WEBCORE_EXPORT void overrideUserPreferredLanguages(const Vector<String>&);
 size_t indexOfBestMatchingLanguageInList(const String& language, const Vector<String>& languageList, bool& exactMatch);