Commit d51c935c authored by dominicc@chromium.org's avatar dominicc@chromium.org

Rename navigator.serviceWorker.current to controller.

Spec: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-service-worker-controller

BUG=363967

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

git-svn-id: svn://svn.chromium.org/blink/trunk@175237 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c29ed4da
......@@ -51,7 +51,7 @@ PASS window.cached_navigator_battery.ondischargingtimechange is null
PASS window.cached_navigator_battery.onlevelchange is null
PASS window.cached_navigator_connection.ontypechange is null
PASS window.cached_navigator_connection.type is window.navigator.connection.type
PASS window.cached_navigator_serviceWorker.current is null
PASS window.cached_navigator_serviceWorker.controller is null
PASS window.cached_performance.onwebkitresourcetimingbufferfull is null
PASS window.cached_performance_navigation.redirectCount is 0
PASS window.cached_performance_navigation.type is 0
......
......@@ -51,7 +51,7 @@ PASS window.cached_navigator_battery.ondischargingtimechange is null
PASS window.cached_navigator_battery.onlevelchange is null
PASS window.cached_navigator_connection.ontypechange is null
PASS window.cached_navigator_connection.type is window.navigator.connection.type
PASS window.cached_navigator_serviceWorker.current is null
PASS window.cached_navigator_serviceWorker.controller is null
PASS window.cached_performance.onwebkitresourcetimingbufferfull is null
PASS window.cached_performance_navigation.redirectCount is 0
PASS window.cached_performance_navigation.type is 0
......
......@@ -51,7 +51,7 @@ PASS window.cached_navigator_battery.ondischargingtimechange is null
PASS window.cached_navigator_battery.onlevelchange is null
PASS window.cached_navigator_connection.ontypechange is null
PASS window.cached_navigator_connection.type is window.navigator.connection.type
PASS window.cached_navigator_serviceWorker.current is null
PASS window.cached_navigator_serviceWorker.controller is null
PASS window.cached_performance.onwebkitresourcetimingbufferfull is null
PASS window.cached_performance_navigation.redirectCount is 0
PASS window.cached_performance_navigation.type is 0
......
......@@ -59,7 +59,7 @@ PASS oldChildWindow.navigator.onLine is newChildWindow.navigator.onLine
PASS oldChildWindow.navigator.platform is newChildWindow.navigator.platform
PASS oldChildWindow.navigator.product is newChildWindow.navigator.product
PASS oldChildWindow.navigator.productSub is newChildWindow.navigator.productSub
PASS oldChildWindow.navigator.serviceWorker.current is newChildWindow.navigator.serviceWorker.current
PASS oldChildWindow.navigator.serviceWorker.controller is newChildWindow.navigator.serviceWorker.controller
PASS oldChildWindow.navigator.userAgent is newChildWindow.navigator.userAgent
PASS oldChildWindow.navigator.vendor is newChildWindow.navigator.vendor
PASS oldChildWindow.navigator.vendorSub is newChildWindow.navigator.vendorSub
......
......@@ -59,7 +59,7 @@ PASS childWindow.navigator.onLine is window.navigator.onLine
PASS childWindow.navigator.platform is window.navigator.platform
PASS childWindow.navigator.product is window.navigator.product
PASS childWindow.navigator.productSub is window.navigator.productSub
FAIL childWindow.navigator.serviceWorker.current should be null. Threw exception TypeError: Cannot read property 'current' of null
FAIL childWindow.navigator.serviceWorker.controller should be null. Threw exception TypeError: Cannot read property 'controller' of null
PASS childWindow.navigator.userAgent is ''
PASS childWindow.navigator.vendor is window.navigator.vendor
PASS childWindow.navigator.vendorSub is ''
......
......@@ -58,7 +58,7 @@ PASS childWindow.navigator.onLine is window.navigator.onLine
PASS childWindow.navigator.platform is window.navigator.platform
PASS childWindow.navigator.product is window.navigator.product
PASS childWindow.navigator.productSub is window.navigator.productSub
PASS childWindow.navigator.serviceWorker.current is null
PASS childWindow.navigator.serviceWorker.controller is null
PASS childWindow.navigator.userAgent is ''
PASS childWindow.navigator.vendor is window.navigator.vendor
PASS childWindow.navigator.vendorSub is ''
......
FAIL controller is set for a controlled document assert_unreached: Unregister should not fail: NotSupportedError Reached unreachable code
<!DOCTYPE html>
<title>Service Worker: Current on load</title>
<title>Service Worker: Controller on load</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
var t = async_test('current is set for a controlled document');
var t = async_test('controller is set for a controlled document');
t.step(function() {
var url = 'resources/worker-no-op.js';
var scope = 'resources/blank.html';
......@@ -21,11 +21,11 @@ t.step(function() {
function onActive() {
with_iframe(scope, t.step_func(function(frame) {
var w = frame.contentWindow;
var current = w.navigator.serviceWorker.current;
assert_true(current instanceof w.ServiceWorker,
'current should be a ServiceWorker object');
assert_equals(current.scope, normalizeURL(scope));
assert_equals(current.url, normalizeURL(url));
var controller = w.navigator.serviceWorker.controller;
assert_true(controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object');
assert_equals(controller.scope, normalizeURL(scope));
assert_equals(controller.url, normalizeURL(url));
service_worker_unregister_and_done(t, scope);
}));
}
......
FAIL controller is set upon reload after registration assert_unreached: Unregister should not fail: NotSupportedError Reached unreachable code
<!DOCTYPE html>
<title>Service Worker: Current on reload</title>
<title>Service Worker: Controller on reload</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
var t = async_test('current is set upon reload after registration');
var t = async_test('controller is set upon reload after registration');
t.step(function() {
var reloaded = false;
var scope = 'resources/blank.html';
......@@ -22,8 +22,8 @@ t.step(function() {
var w = frame.contentWindow;
function onActive(event) {
assert_equals(w.navigator.serviceWorker.current, null,
'current should be null until the document is reloaded');
assert_equals(w.navigator.serviceWorker.controller, null,
'controller should be null until the document is reloaded');
reloaded = true;
w.location.reload();
}
......@@ -36,8 +36,8 @@ t.step(function() {
}
if (reloaded) {
assert_true(w.navigator.serviceWorker.current instanceof w.ServiceWorker,
'current should be a ServiceWorker object upon reload');
assert_true(w.navigator.serviceWorker.controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object upon reload');
service_worker_unregister_and_done(t, scope);
return;
}
......
FAIL current is set for a controlled document assert_unreached: Unregister should not fail: NotSupportedError Reached unreachable code
FAIL current is set upon reload after registration assert_unreached: Unregister should not fail: NotSupportedError Reached unreachable code
......@@ -22,7 +22,7 @@ t.step(function() {
with_iframe(scope, t.step_func(function(frame) {
var w = frame.contentWindow;
w.onmessage = t.step_func(onMessage);
w.navigator.serviceWorker.current.postMessage('ping');
w.navigator.serviceWorker.controller.postMessage('ping');
}));
}
......
......@@ -21,7 +21,7 @@ t.step(function() {
with_iframe(scope, t.step_func(function(frame) {
var w = frame.contentWindow;
w.onmessage = t.step_func(onMessage);
w.navigator.serviceWorker.current.postMessage('ping');
w.navigator.serviceWorker.controller.postMessage('ping');
}));
}
......
......@@ -141,12 +141,17 @@ ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
}
void ServiceWorkerContainer::setCurrentServiceWorker(blink::WebServiceWorker* serviceWorker)
{
setController(serviceWorker);
}
void ServiceWorkerContainer::setController(blink::WebServiceWorker* serviceWorker)
{
if (!executionContext()) {
delete serviceWorker;
return;
}
m_current = ServiceWorker::create(executionContext(), adoptPtr(serviceWorker));
m_controller = ServiceWorker::create(executionContext(), adoptPtr(serviceWorker));
}
void ServiceWorkerContainer::dispatchMessageEvent(const blink::WebString& message, const blink::WebMessagePortChannelArray& webChannels)
......
......@@ -67,17 +67,20 @@ public:
ScriptPromise registerServiceWorker(ExecutionContext*, const String& pattern, const Dictionary&);
ScriptPromise unregisterServiceWorker(ExecutionContext*, const String& scope = String());
PassRefPtr<ServiceWorker> current() { return m_current; }
PassRefPtr<ServiceWorker> controller() { return m_controller; }
// WebServiceWorkerProviderClient overrides.
virtual void setCurrentServiceWorker(blink::WebServiceWorker*) OVERRIDE;
virtual void setController(blink::WebServiceWorker*) OVERRIDE;
virtual void dispatchMessageEvent(const blink::WebString& message, const blink::WebMessagePortChannelArray&) OVERRIDE;
// FIXME: Delete this when the embedder switches to setController.
virtual void setCurrentServiceWorker(blink::WebServiceWorker*) OVERRIDE;
private:
explicit ServiceWorkerContainer(ExecutionContext*);
blink::WebServiceWorkerProvider* m_provider;
RefPtr<ServiceWorker> m_current;
RefPtr<ServiceWorker> m_controller;
};
} // namespace WebCore
......
......@@ -34,5 +34,5 @@
[CallWith=ExecutionContext, ImplementedAs=registerServiceWorker] Promise register(DOMString url, optional Dictionary options);
[CallWith=ExecutionContext, ImplementedAs=unregisterServiceWorker] Promise unregister(optional DOMString scope);
readonly attribute ServiceWorker current;
readonly attribute ServiceWorker controller;
};
......@@ -44,6 +44,9 @@ public:
virtual ~WebServiceWorkerProviderClient() { }
// The callee will take ownership of the given WebServiceWorker object.
virtual void setController(WebServiceWorker*) = 0;
// FIXME: Remove when the embedder switches to setController.
virtual void setCurrentServiceWorker(WebServiceWorker*) = 0;
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray&) = 0;
......
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