 Chromium Code Reviews
 Chromium Code Reviews Issue 464073002:
  Pass through geofencing API calls to the content layer.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 464073002:
  Pass through geofencing API calls to the content layer.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| Index: Source/modules/geofencing/Geofencing.cpp | 
| diff --git a/Source/modules/geofencing/Geofencing.cpp b/Source/modules/geofencing/Geofencing.cpp | 
| index 59d8b975755550e0b2f48b7a08e7fda81d16acc8..8cee0433f8d22a45bb84d3ee4c0da8445344cc34 100644 | 
| --- a/Source/modules/geofencing/Geofencing.cpp | 
| +++ b/Source/modules/geofencing/Geofencing.cpp | 
| @@ -5,12 +5,63 @@ | 
| #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 { | 
| + | 
| +// Copy of same class in ServiceWorkerContainer.cpp | 
| 
esprehn
2014/08/19 01:15:59
How can we fix this code duplication?
 
Marijn Kruisselbrink
2014/08/19 18:55:13
By adding more explicit support to WebCallbacks an
 
Marijn Kruisselbrink
2014/08/19 18:58:50
Actually it seems the WebCallbacks side of things
 
Marijn Kruisselbrink
2014/08/19 19:13:07
In my currently last patchset I got rid of this Un
 | 
| +class UndefinedValue { | 
| +public: | 
| + typedef blink::WebGeofencingError WebType; | 
| + static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* value) | 
| + { | 
| + ASSERT(!value); // Anything passed here will be leaked. | 
| + return V8UndefinedType(); | 
| + } | 
| + | 
| + static void dispose(WebType* value) | 
| + { | 
| + ASSERT(!value); // Anything passed here will be leaked. | 
| + } | 
| + | 
| +private: | 
| + UndefinedValue(); | 
| +}; | 
| + | 
| +class RegionArray { | 
| +public: | 
| + typedef blink::WebVector<blink::WebGeofencingRegion> WebType; | 
| + static HeapVector<Member<GeofencingRegion> > take(ScriptPromiseResolver* resolver, WebType* regionsRaw) | 
| + { | 
| + OwnPtr<WebType> webRegions = adoptPtr(regionsRaw); | 
| + HeapVector<Member<GeofencingRegion> > regions; | 
| + for (size_t i = 0; i < webRegions->size(); ++i) { | 
| + regions.append(GeofencingRegion::createFromWebRegion((*webRegions)[i])); | 
| + } | 
| + return regions; | 
| + } | 
| + | 
| + static void dispose(WebType* regionsRaw) | 
| + { | 
| + delete regionsRaw; | 
| + } | 
| + | 
| +private: | 
| + RegionArray(); | 
| +}; | 
| + | 
| +} // namespace | 
| + | 
| Geofencing::Geofencing() | 
| { | 
| ScriptWrappable::init(this); | 
| @@ -18,17 +69,44 @@ 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(); | 
| + // TODO(mek): somehow pass a reference to the current serviceworker to the provider. | 
| + provider->registerRegion(region->webRegion(), new CallbackPromiseAdapter<UndefinedValue, 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(); | 
| + // TODO(mek): somehow pass a reference to the current serviceworker to the provider. | 
| + provider->unregisterRegion(regionId, new CallbackPromiseAdapter<UndefinedValue, 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)); | 
| + } | 
| 
esprehn
2014/08/19 01:15:59
no braces
 
Marijn Kruisselbrink
2014/08/19 18:55:14
Done.
 | 
| + | 
| + RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); | 
| + ScriptPromise promise = resolver->promise(); | 
| + // TODO(mek): somehow pass a reference to the current serviceworker to the provider. | 
| + provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, GeofencingError>(resolver)); | 
| + return promise; | 
| } | 
| } // namespace blink |