Commit 3883c060 authored by jkarlin@chromium.org's avatar jkarlin@chromium.org

Adds WebWorker support to NetInfo v3.

Design doc: https://docs.google.com/a/chromium.org/document/d/1LTk9uVMGi4kurzcF5ellsAJReTF31fFJMHrQwSVtBjc/

BUG=368358

Review URL: https://codereview.chromium.org/299883004

git-svn-id: svn://svn.chromium.org/blink/trunk@175281 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent bf657f65
addEventListener('message', function(e) {
self.postMessage(navigator.connection.type);
}, false);
navigator.connection.addEventListener('typechange', function() {
self.postMessage(navigator.connection.type);
}, false);
Tests that web-workers have access to NetInfo.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/netinfo_common.js"></script>
</head>
<body>
<script>
description('Tests that web-workers have access to NetInfo.');
shouldBe('typeof window.internals.observeGC', '"function"',
'this test requires window.internals');
var worker = new Worker("resources/web-worker.js");
var msg_count = 0;
worker.addEventListener('message', function(e) {
if (msg_count == 0) {
if (e.data != connection.type) {
testFailed("Worker type disagrees with main frame.");
}
internals.setNetworkConnectionInfo(newConnectionType);
} else if (msg_count == 1) {
if (e.data != newConnectionType)
testFailed("Worker switched to wrong connection type.");
internals.setNetworkConnectionInfo(initialType);
} else if (msg_count == 2) {
if (e.data != initialType)
testFailed("Worker did not revert back to initial type.");
finishJSTest();
}
msg_count += 1;
});
worker.postMessage('kickoff');
</script>
</body>
</html>
......@@ -39,6 +39,7 @@ Starting worker: resources/global-context-constructors-listing.js
[Worker] Int8Array
[Worker] MessageChannel
[Worker] MessageEvent
[Worker] NetworkInformation
[Worker] Number
[Worker] Object
[Worker] Promise
......
......@@ -38,6 +38,7 @@ Starting worker: resources/global-context-constructors-listing.js
[Worker] Int8Array
[Worker] MessageChannel
[Worker] MessageEvent
[Worker] NetworkInformation
[Worker] Number
[Worker] Object
[Worker] Promise
......
......@@ -219,6 +219,7 @@
'mediastream/WindowMediaStream.idl',
'navigatorcontentutils/NavigatorContentUtils.idl',
'netinfo/NavigatorNetworkInformation.idl',
'netinfo/WorkerNavigatorNetworkInformation.idl',
'performance/SharedWorkerPerformance.idl',
'performance/WorkerGlobalScopePerformance.idl',
'push_messaging/NavigatorPushManager.idl',
......@@ -586,6 +587,8 @@
'netinfo/NavigatorNetworkInformation.h',
'netinfo/NetworkInformation.cpp',
'netinfo/NetworkInformation.h',
'netinfo/WorkerNavigatorNetworkInformation.cpp',
'netinfo/WorkerNavigatorNetworkInformation.h',
'notifications/Notification.cpp',
'notifications/Notification.h',
'notifications/NotificationClient.h',
......
......@@ -13,6 +13,7 @@ enum ConnectionType {
[
RuntimeEnabled=NetworkInformation,
Exposed=Window&Worker,
WillBeGarbageCollected,
ActiveDOMObject
] interface NetworkInformation : EventTarget {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/netinfo/WorkerNavigatorNetworkInformation.h"
#include "core/workers/WorkerNavigator.h"
#include "modules/netinfo/NetworkInformation.h"
namespace WebCore {
WorkerNavigatorNetworkInformation::WorkerNavigatorNetworkInformation(WorkerNavigator& navigator, ExecutionContext* context)
{
}
WorkerNavigatorNetworkInformation::~WorkerNavigatorNetworkInformation()
{
}
WorkerNavigatorNetworkInformation& WorkerNavigatorNetworkInformation::from(WorkerNavigator& navigator, ExecutionContext* context)
{
WorkerNavigatorNetworkInformation* supplement = toWorkerNavigatorNetworkInformation(navigator, context);
if (!supplement) {
supplement = new WorkerNavigatorNetworkInformation(navigator, context);
provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
}
return *supplement;
}
WorkerNavigatorNetworkInformation* WorkerNavigatorNetworkInformation::toWorkerNavigatorNetworkInformation(WorkerNavigator& navigator, ExecutionContext* context)
{
return static_cast<WorkerNavigatorNetworkInformation*>(WillBeHeapSupplement<WorkerNavigator>::from(navigator, supplementName()));
}
const char* WorkerNavigatorNetworkInformation::supplementName()
{
return "WorkerNavigatorNetworkInformation";
}
NetworkInformation* WorkerNavigatorNetworkInformation::connection(ExecutionContext* context, WorkerNavigator& navigator)
{
return WorkerNavigatorNetworkInformation::from(navigator, context).connection(context);
}
void WorkerNavigatorNetworkInformation::trace(Visitor* visitor)
{
visitor->trace(m_connection);
WillBeHeapSupplement<WorkerNavigator>::trace(visitor);
}
NetworkInformation* WorkerNavigatorNetworkInformation::connection(ExecutionContext* context)
{
ASSERT(context);
if (!m_connection)
m_connection = NetworkInformation::create(context);
return m_connection.get();
}
} // namespace WebCore
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WorkerNavigatorNetworkInformation_h
#define WorkerNavigatorNetworkInformation_h
#include "platform/Supplementable.h"
namespace WebCore {
class ExecutionContext;
class NetworkInformation;
class WorkerNavigator;
class WorkerNavigatorNetworkInformation FINAL
: public NoBaseWillBeGarbageCollectedFinalized<WorkerNavigatorNetworkInformation>
, public WillBeHeapSupplement<WorkerNavigator> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WorkerNavigatorNetworkInformation);
public:
virtual ~WorkerNavigatorNetworkInformation();
static WorkerNavigatorNetworkInformation& from(WorkerNavigator&, ExecutionContext*);
static WorkerNavigatorNetworkInformation* toWorkerNavigatorNetworkInformation(WorkerNavigator&, ExecutionContext*);
static const char* supplementName();
static NetworkInformation* connection(ExecutionContext*, WorkerNavigator&);
virtual void trace(Visitor*) OVERRIDE;
private:
WorkerNavigatorNetworkInformation(WorkerNavigator&, ExecutionContext*);
NetworkInformation* connection(ExecutionContext*);
RefPtrWillBeMember<NetworkInformation> m_connection;
};
} // namespace WebCore
#endif // WorkerNavigatorNetworkInformation_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
RuntimeEnabled=NetworkInformation,
Exposed=Worker
] partial interface WorkerNavigator {
[CallWith=ExecutionContext] readonly attribute NetworkInformation connection;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment