Commit 88e1faf9 authored by mek@chromium.org's avatar mek@chromium.org

Blink side of exposing the service worker registration associated with geofencing API calls.

This still leaves the old codepaths for the geofencing API in place, those will be cleaned up in a followup CL.

BUG=383125

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

git-svn-id: svn://svn.chromium.org/blink/trunk@183931 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e666e07f
<!DOCTYPE html>
<title>Tests that all geofencing methods always reject.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
// Copied from http/tests/serviceworker/resources/worker-test-harness.js, can be
// removed once this makes it into testharness.js itself.
function promise_test(func, name, properties) {
properties = properties || {};
var test = async_test(name, properties);
Promise.resolve(test.step(func, test, test))
.then(function() { test.done(); })
.catch(test.step_func(function(value) {
throw value;
}));
}
promise_test(function(test) {
return navigator.geofencing.registerRegion(
new CircularGeofencingRegion({latitude: 37.421999,
longitude: -122.084015}))
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'registerRegion should fail');
promise_test(function(test) {
return navigator.geofencing.unregisterRegion("")
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'unregisterRegion should fail');
promise_test(function(test) {
return navigator.geofencing.getRegisteredRegions()
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'getRegisteredRegions should fail');
</script>
<!DOCTYPE html>
<title>Tests that all geofencing methods exposed on a service worker registration always reject.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/testharness-helpers.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script>
var sw_url = 'resources/emptyworker.js';
var sw_scope = '/service-worker-scope' + window.location.pathname;
promise_test(function(test) {
return assert_promise_rejects(
service_worker_unregister_and_register(test, sw_url, sw_scope + '/register')
.then(function(r) {
return r.geofencing.registerRegion(
new CircularGeofencingRegion({latitude: 37.421999,
longitude: -122.084015}));
}),
'AbortError',
'registerRegion should fail with an AbortError');
}, 'registerRegion should fail');
promise_test(function(test) {
return assert_promise_rejects(
service_worker_unregister_and_register(test, sw_url, sw_scope + '/unregister')
.then(function(r) {
return r.geofencing.unregisterRegion('');
}),
'AbortError',
'unregisterRegion should fail with an AbortError');
}, 'unregisterRegion should fail');
promise_test(function(test) {
return assert_promise_rejects(
service_worker_unregister_and_register(test, sw_url, sw_scope + '/getregions')
.then(function(r) {
return r.geofencing.getRegisteredRegions();
}),
'AbortError',
'getRegisteredRegions should fail with an AbortError');
}, 'getRegisteredRegions should fail');
</script>
......@@ -13,6 +13,7 @@
#include "modules/geofencing/CircularGeofencingRegion.h"
#include "modules/geofencing/GeofencingError.h"
#include "modules/geofencing/GeofencingRegion.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCircularGeofencingRegion.h"
#include "public/platform/WebGeofencingProvider.h"
......@@ -46,7 +47,8 @@ private:
} // namespace
Geofencing::Geofencing()
Geofencing::Geofencing(ServiceWorkerRegistration* registration)
: m_registration(registration)
{
}
......@@ -58,8 +60,13 @@ ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
// FIXME: somehow pass a reference to the current serviceworker to the provider.
provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->webRegion(), new CallbackPromiseAdapter<void, GeofencingError>(resolver));
WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, GeofencingError>(resolver);
// FIXME: remove this call once chromium is updated to implement the other registerRegion.
provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->webRegion(), callbacks);
WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr;
if (m_registration)
serviceWorkerRegistration = m_registration->webRegistration();
provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->webRegion(), serviceWorkerRegistration, callbacks);
return promise;
}
......@@ -71,8 +78,13 @@ ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
// FIXME: somehow pass a reference to the current serviceworker to the provider.
provider->unregisterRegion(regionId, new CallbackPromiseAdapter<void, GeofencingError>(resolver));
WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, GeofencingError>(resolver);
// FIXME: remove this call once chromium is updated to implement the other unregisterRegion.
provider->unregisterRegion(regionId, callbacks);
WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr;
if (m_registration)
serviceWorkerRegistration = m_registration->webRegistration();
provider->unregisterRegion(regionId, serviceWorkerRegistration, callbacks);
return promise;
}
......@@ -84,9 +96,19 @@ ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
// FIXME: somehow pass a reference to the current serviceworker to the provider.
provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, GeofencingError>(resolver));
WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<RegionArray, GeofencingError>(resolver);
// FIXME: remove this call once chromium is updated to implement the other getRegisteredRegions.
provider->getRegisteredRegions(callbacks);
WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr;
if (m_registration)
serviceWorkerRegistration = m_registration->webRegistration();
provider->getRegisteredRegions(serviceWorkerRegistration, callbacks);
return promise;
}
void Geofencing::trace(Visitor* visitor)
{
visitor->trace(m_registration);
}
} // namespace blink
......@@ -14,23 +14,26 @@ namespace blink {
class GeofencingRegion;
class ScriptPromise;
class ScriptState;
class ServiceWorkerRegistration;
class Geofencing final : public GarbageCollected<Geofencing>, public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static Geofencing* create()
static Geofencing* create(ServiceWorkerRegistration* registration)
{
return new Geofencing();
return new Geofencing(registration);
}
ScriptPromise registerRegion(ScriptState*, GeofencingRegion*);
ScriptPromise unregisterRegion(ScriptState*, const String& regionId);
ScriptPromise getRegisteredRegions(ScriptState*) const;
virtual void trace(Visitor*) { }
virtual void trace(Visitor*);
private:
Geofencing();
explicit Geofencing(ServiceWorkerRegistration*);
Member<ServiceWorkerRegistration> m_registration;
};
} // namespace blink
......
// 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/geofencing/NavigatorGeofencing.h"
#include "core/frame/Navigator.h"
#include "modules/geofencing/Geofencing.h"
namespace blink {
NavigatorGeofencing::NavigatorGeofencing()
{
}
NavigatorGeofencing::~NavigatorGeofencing()
{
}
const char* NavigatorGeofencing::supplementName()
{
return "NavigatorGeofencing";
}
NavigatorGeofencing& NavigatorGeofencing::from(Navigator& navigator)
{
NavigatorGeofencing* supplement = static_cast<NavigatorGeofencing*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
if (!supplement) {
supplement = new NavigatorGeofencing();
provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
}
return *supplement;
}
Geofencing* NavigatorGeofencing::geofencing(Navigator& navigator)
{
return NavigatorGeofencing::from(navigator).geofencing();
}
Geofencing* NavigatorGeofencing::geofencing()
{
if (!m_geofencing)
m_geofencing = Geofencing::create();
return m_geofencing.get();
}
void NavigatorGeofencing::trace(Visitor* visitor)
{
visitor->trace(m_geofencing);
WillBeHeapSupplement<Navigator>::trace(visitor);
}
} // namespace blink
// 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/geofencing/ServiceWorkerRegistrationGeofencing.h"
#include "modules/geofencing/Geofencing.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
namespace blink {
ServiceWorkerRegistrationGeofencing::ServiceWorkerRegistrationGeofencing(ServiceWorkerRegistration* registration)
: m_registration(registration)
{
}
ServiceWorkerRegistrationGeofencing::~ServiceWorkerRegistrationGeofencing()
{
}
const char* ServiceWorkerRegistrationGeofencing::supplementName()
{
return "ServiceWorkerRegistrationGeofencing";
}
ServiceWorkerRegistrationGeofencing& ServiceWorkerRegistrationGeofencing::from(ServiceWorkerRegistration& registration)
{
ServiceWorkerRegistrationGeofencing* supplement = static_cast<ServiceWorkerRegistrationGeofencing*>(HeapSupplement<ServiceWorkerRegistration>::from(registration, supplementName()));
if (!supplement) {
supplement = new ServiceWorkerRegistrationGeofencing(&registration);
provideTo(registration, supplementName(), supplement);
}
return *supplement;
}
Geofencing* ServiceWorkerRegistrationGeofencing::geofencing(ServiceWorkerRegistration& registration)
{
return ServiceWorkerRegistrationGeofencing::from(registration).geofencing();
}
Geofencing* ServiceWorkerRegistrationGeofencing::geofencing()
{
if (!m_geofencing)
m_geofencing = Geofencing::create(m_registration);
return m_geofencing.get();
}
void ServiceWorkerRegistrationGeofencing::trace(Visitor* visitor)
{
visitor->trace(m_registration);
visitor->trace(m_geofencing);
HeapSupplement<ServiceWorkerRegistration>::trace(visitor);
}
} // namespace blink
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NavigatorGeofencing_h
#define NavigatorGeofencing_h
#ifndef ServiceWorkerRegistrationGeofencing_h
#define ServiceWorkerRegistrationGeofencing_h
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......@@ -11,29 +11,28 @@
namespace blink {
class Geofencing;
class Navigator;
class NavigatorGeofencing final
: public NoBaseWillBeGarbageCollectedFinalized<NavigatorGeofencing>
, public WillBeHeapSupplement<Navigator> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NavigatorGeofencing);
class ServiceWorkerRegistration;
class ServiceWorkerRegistrationGeofencing final : public GarbageCollectedFinalized<ServiceWorkerRegistrationGeofencing>, public HeapSupplement<ServiceWorkerRegistration> {
USING_GARBAGE_COLLECTED_MIXIN(ServiceWorkerRegistrationGeofencing);
WTF_MAKE_NONCOPYABLE(ServiceWorkerRegistrationGeofencing);
public:
virtual ~NavigatorGeofencing();
static NavigatorGeofencing& from(Navigator&);
virtual ~ServiceWorkerRegistrationGeofencing();
static ServiceWorkerRegistrationGeofencing& from(ServiceWorkerRegistration&);
static Geofencing* geofencing(Navigator&);
static Geofencing* geofencing(ServiceWorkerRegistration&);
Geofencing* geofencing();
virtual void trace(Visitor*) override;
private:
NavigatorGeofencing();
explicit ServiceWorkerRegistrationGeofencing(ServiceWorkerRegistration*);
static const char* supplementName();
PersistentWillBeMember<Geofencing> m_geofencing;
Member<ServiceWorkerRegistration> m_registration;
Member<Geofencing> m_geofencing;
};
} // namespace blink
#endif // NavigatorGeofencing_h
#endif // ServiceWorkerRegistrationGeofencing_h
......@@ -4,6 +4,6 @@
[
RuntimeEnabled=Geofencing,
] partial interface Navigator {
] partial interface ServiceWorkerRegistration {
readonly attribute Geofencing geofencing;
};
......@@ -41,7 +41,7 @@ Geofencing* WorkerNavigatorGeofencing::geofencing(WorkerNavigator& navigator)
Geofencing* WorkerNavigatorGeofencing::geofencing()
{
if (!m_geofencing)
m_geofencing = Geofencing::create();
m_geofencing = Geofencing::create(nullptr);
return m_geofencing.get();
}
......
......@@ -13,6 +13,7 @@ namespace blink {
class Geofencing;
class WorkerNavigator;
// FIXME: Delete this class once ServiceWorkerRegistration is exposed in service workers.
class WorkerNavigatorGeofencing final : public NoBaseWillBeGarbageCollectedFinalized<WorkerNavigatorGeofencing>, public WillBeHeapSupplement<WorkerNavigator> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WorkerNavigatorGeofencing);
WTF_MAKE_NONCOPYABLE(WorkerNavigatorGeofencing);
......
......@@ -6,5 +6,6 @@
RuntimeEnabled=Geofencing,
Exposed=Worker,
] partial interface WorkerNavigator {
// FIXME: Delete this class once ServiceWorkerRegistration is exposed in service workers.
readonly attribute Geofencing geofencing;
};
......@@ -224,8 +224,8 @@
'filesystem/WindowFileSystem.idl',
'filesystem/WorkerGlobalScopeFileSystem.idl',
'gamepad/NavigatorGamepad.idl',
'geofencing/NavigatorGeofencing.idl',
'geofencing/ServiceWorkerGlobalScopeGeofencing.idl',
'geofencing/ServiceWorkerRegistrationGeofencing.idl',
'geofencing/WorkerNavigatorGeofencing.idl',
'geolocation/NavigatorGeolocation.idl',
'indexeddb/WindowIndexedDatabase.idl',
......@@ -511,9 +511,9 @@
'geofencing/GeofencingEvent.cpp',
'geofencing/GeofencingEvent.h',
'geofencing/GeofencingRegion.h',
'geofencing/NavigatorGeofencing.cpp',
'geofencing/NavigatorGeofencing.h',
'geofencing/ServiceWorkerGlobalScopeGeofencing.h',
'geofencing/ServiceWorkerRegistrationGeofencing.cpp',
'geofencing/ServiceWorkerRegistrationGeofencing.h',
'geofencing/WorkerNavigatorGeofencing.cpp',
'geofencing/WorkerNavigatorGeofencing.h',
'geolocation/Coordinates.cpp',
......
......@@ -161,6 +161,7 @@ void ServiceWorkerRegistration::trace(Visitor* visitor)
visitor->trace(m_waiting);
visitor->trace(m_active);
EventTargetWithInlineData::trace(visitor);
HeapSupplementable<ServiceWorkerRegistration>::trace(visitor);
}
bool ServiceWorkerRegistration::hasPendingActivity() const
......
......@@ -8,6 +8,7 @@
#include "core/dom/ActiveDOMObject.h"
#include "core/events/EventTarget.h"
#include "modules/serviceworkers/ServiceWorker.h"
#include "platform/Supplementable.h"
#include "public/platform/WebServiceWorkerRegistration.h"
#include "public/platform/WebServiceWorkerRegistrationProxy.h"
#include "wtf/OwnPtr.h"
......@@ -26,10 +27,11 @@ class ServiceWorkerRegistration final
: public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<ServiceWorkerRegistration>
, public ActiveDOMObject
, public EventTargetWithInlineData
, public WebServiceWorkerRegistrationProxy {
, public WebServiceWorkerRegistrationProxy
, public HeapSupplementable<ServiceWorkerRegistration> {
DEFINE_WRAPPERTYPEINFO();
DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<ServiceWorkerRegistration>);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ServiceWorkerRegistration);
USING_GARBAGE_COLLECTED_MIXIN(ServiceWorkerRegistration);
public:
// EventTarget overrides.
virtual const AtomicString& interfaceName() const override;
......@@ -53,6 +55,8 @@ public:
String scope() const;
WebServiceWorkerRegistration* webRegistration() { return m_outerRegistration.get(); }
ScriptPromise unregister(ScriptState*);
DEFINE_ATTRIBUTE_EVENT_LISTENER(updatefound);
......
......@@ -59,7 +59,7 @@ FileAPIBlobClose status=experimental
FileConstructor status=stable
FileSystem status=stable
FullscreenUnprefixed status=test
Geofencing status=test
Geofencing status=experimental
GeometryInterfaces status=test
// Temporary setting to allow easy rollback of change to hover media feature.
HoverMediaQueryKeywords status=stable
......
......@@ -13,6 +13,7 @@ namespace blink {
struct WebCircularGeofencingRegion;
struct WebGeofencingError;
struct WebGeofencingRegistration;
class WebServiceWorkerRegistration;
class WebString;
typedef WebCallbacks<void, WebGeofencingError> WebGeofencingCallbacks;
......@@ -24,15 +25,18 @@ public:
// Registers a region.
// Ownership of the WebGeofencingCallbacks is transferred to the client.
virtual void registerRegion(const WebString& regionId, const WebCircularGeofencingRegion&, WebGeofencingCallbacks*) = 0;
virtual void registerRegion(const WebString& regionId, const WebCircularGeofencingRegion&, WebGeofencingCallbacks*) { }
virtual void registerRegion(const WebString& regionId, const WebCircularGeofencingRegion&, WebServiceWorkerRegistration*, WebGeofencingCallbacks*) { }
// Unregisters a region.
// Ownership of the WebGeofencingCallbacks is transferred to the client.
virtual void unregisterRegion(const WebString& regionId, WebGeofencingCallbacks*) = 0;
virtual void unregisterRegion(const WebString& regionId, WebGeofencingCallbacks*) { }
virtual void unregisterRegion(const WebString& regionId, WebServiceWorkerRegistration*, WebGeofencingCallbacks*) { }
// Returns all the currently registered regions.
// Ownership of the WebGeofencingRegionsCallbacks is transferred to the client.
virtual void getRegisteredRegions(WebGeofencingRegionsCallbacks*) = 0;
virtual void getRegisteredRegions(WebGeofencingRegionsCallbacks*) { }
virtual void getRegisteredRegions(WebServiceWorkerRegistration*, WebGeofencingRegionsCallbacks*) { }
};
} // namespace blink
......
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