Bug 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 17 - Network Information enabled, r=asuth

This commit is contained in:
Andrea Marchesini 2018-01-08 14:05:05 +01:00
parent 1b4b3007e5
commit bbefbae583
7 changed files with 8 additions and 17 deletions

View File

@ -50,6 +50,7 @@ PREF(StreamsEnabled, "dom.streams.enabled")
PREF(RequestContextEnabled, "dom.requestcontext.enabled") PREF(RequestContextEnabled, "dom.requestcontext.enabled")
PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled") PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled")
PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled") PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled")
PREF(NetworkInformationEnabled, "dom.netinfo.enabled")
#undef PREF #undef PREF
@ -72,6 +73,7 @@ PREF_WEBIDL(StreamsEnabled)
PREF_WEBIDL(RequestContextEnabled) PREF_WEBIDL(RequestContextEnabled)
PREF_WEBIDL(OffscreenCanvasEnabled) PREF_WEBIDL(OffscreenCanvasEnabled)
PREF_WEBIDL(WebkitBlinkDirectoryPickerEnabled) PREF_WEBIDL(WebkitBlinkDirectoryPickerEnabled)
PREF_WEBIDL(NetworkInformationEnabled)
#undef PREF_WEBIDL #undef PREF_WEBIDL

View File

@ -79,6 +79,10 @@ public:
// Returns true if the dom.webkitBlink.dirPicker.enabled pref is set. // Returns true if the dom.webkitBlink.dirPicker.enabled pref is set.
static bool WebkitBlinkDirectoryPickerEnabled(); static bool WebkitBlinkDirectoryPickerEnabled();
static bool WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj); static bool WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj);
// Returns true if the dom.netinfo.enabled pref is set.
static bool NetworkInformationEnabled();
static bool NetworkInformationEnabled(JSContext* aCx, JSObject* aObj);
}; };
} // dom namespace } // dom namespace

View File

@ -106,18 +106,6 @@ Connection::Update(ConnectionType aType, bool aIsWifi, uint32_t aDHCPGateway,
} }
} }
/* static */ bool
Connection::IsEnabled(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("dom.netinfo.enabled");
}
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
MOZ_ASSERT(workerPrivate);
return workerPrivate->NetworkInformationEnabled();
}
/* static */ Connection* /* static */ Connection*
Connection::CreateForWindow(nsPIDOMWindowInner* aWindow) Connection::CreateForWindow(nsPIDOMWindowInner* aWindow)
{ {

View File

@ -37,8 +37,6 @@ public:
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
static bool IsEnabled(JSContext* aCx, JSObject* aObj);
static Connection* static Connection*
CreateForWindow(nsPIDOMWindowInner* aWindow); CreateForWindow(nsPIDOMWindowInner* aWindow);

View File

@ -18,7 +18,7 @@ enum ConnectionType {
"unknown" "unknown"
}; };
[Func="mozilla::dom::network::Connection::IsEnabled", [Func="mozilla::dom::DOMPrefs::NetworkInformationEnabled",
Exposed=(Window,Worker)] Exposed=(Window,Worker)]
interface NetworkInformation : EventTarget { interface NetworkInformation : EventTarget {
readonly attribute ConnectionType type; readonly attribute ConnectionType type;

View File

@ -16,6 +16,6 @@ WorkerNavigator implements NavigatorStorage;
// http://wicg.github.io/netinfo/#extensions-to-the-navigator-interface // http://wicg.github.io/netinfo/#extensions-to-the-navigator-interface
[Exposed=(Worker)] [Exposed=(Worker)]
partial interface WorkerNavigator { partial interface WorkerNavigator {
[Func="mozilla::dom::network::Connection::IsEnabled", Throws] [Func="mozilla::dom::DOMPrefs::NetworkInformationEnabled", Throws]
readonly attribute NetworkInformation connection; readonly attribute NetworkInformation connection;
}; };

View File

@ -21,7 +21,6 @@
// * First argument is the name of the pref. // * First argument is the name of the pref.
// * The name of the function that updates the new value of a pref. // * The name of the function that updates the new value of a pref.
WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED)
WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED) WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)
WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED) WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED)
WORKER_SIMPLE_PREF("devtools.enabled", DevToolsEnabled, DEVTOOLS_ENABLED) WORKER_SIMPLE_PREF("devtools.enabled", DevToolsEnabled, DEVTOOLS_ENABLED)