Chromium Code Reviews| Index: Source/modules/geofencing/Geofencing.cpp |
| diff --git a/Source/modules/geofencing/Geofencing.cpp b/Source/modules/geofencing/Geofencing.cpp |
| index 59d8b975755550e0b2f48b7a08e7fda81d16acc8..7c35d754eae0dbbb032f1392aa76e7e2a6dc6f7f 100644 |
| --- a/Source/modules/geofencing/Geofencing.cpp |
| +++ b/Source/modules/geofencing/Geofencing.cpp |
| @@ -5,12 +5,44 @@ |
| #include "config.h" |
| #include "modules/geofencing/Geofencing.h" |
| +#include "bindings/core/v8/CallbackPromiseAdapter.h" |
| #include "bindings/core/v8/ScriptPromise.h" |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| #include "core/dom/DOMException.h" |
| #include "core/dom/ExceptionCode.h" |
| +#include "modules/geofencing/GeofencingError.h" |
| +#include "modules/geofencing/GeofencingRegion.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebGeofencingProvider.h" |
| namespace blink { |
| +namespace { |
| + |
| +class RegionArray { |
| +public: |
| + typedef blink::WebVector<blink::WebGeofencingRegion> WebType; |
| + static HeapVector<Member<GeofencingRegion> > take(ScriptPromiseResolver* resolver, WebType* regionsRaw) |
| + { |
| + OwnPtr<WebType> webRegions = adoptPtr(regionsRaw); |
|
abarth-chromium
2014/08/23 05:43:34
We try to push the adoptPtr as close to the API as
Marijn Kruisselbrink
2014/08/25 22:25:25
This and the other comment about dispose seem more
|
| + HeapVector<Member<GeofencingRegion> > regions; |
| + for (size_t i = 0; i < webRegions->size(); ++i) { |
| + regions.append(GeofencingRegion::createFromWebRegion((*webRegions)[i])); |
|
abarth-chromium
2014/08/23 05:43:34
s/createFromWebRegion/create/
C++ can dispatch th
Marijn Kruisselbrink
2014/08/25 22:25:25
Done.
|
| + } |
| + return regions; |
| + } |
| + |
| + static void dispose(WebType* regionsRaw) |
| + { |
| + delete regionsRaw; |
| + } |
|
abarth-chromium
2014/08/23 05:43:34
We shouldn't have this. As soon as we get the reg
Marijn Kruisselbrink
2014/08/25 22:25:25
Same reply as to your comment on my ::take impleme
|
| + |
| +private: |
| + RegionArray(); |
| +}; |
| + |
| +} // namespace |
| + |
| Geofencing::Geofencing() |
| { |
| ScriptWrappable::init(this); |
| @@ -18,17 +50,41 @@ Geofencing::Geofencing() |
| ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingRegion* region) |
| { |
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
| + if (!provider) |
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + |
| + 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->webRegion(), new CallbackPromiseAdapter<void, GeofencingError>(resolver)); |
| + return promise; |
| } |
| ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const String& regionId) |
| { |
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
| + if (!provider) |
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + |
| + 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)); |
| + return promise; |
| } |
| ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const |
| { |
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
| + if (!provider) |
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + |
| + 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)); |
| + return promise; |
| } |
| } // namespace blink |