Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/geofencing/Geofencing.h" | 6 #include "modules/geofencing/Geofencing.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 9 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "modules/geofencing/GeofencingError.h" | |
| 14 #include "modules/geofencing/GeofencingRegion.h" | |
| 15 #include "public/platform/Platform.h" | |
| 16 #include "public/platform/WebGeofencingProvider.h" | |
| 11 | 17 |
| 12 namespace blink { | 18 namespace blink { |
| 13 | 19 |
| 20 namespace { | |
| 21 | |
| 22 // 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
| |
| 23 class UndefinedValue { | |
| 24 public: | |
| 25 typedef blink::WebGeofencingError WebType; | |
| 26 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* value) | |
| 27 { | |
| 28 ASSERT(!value); // Anything passed here will be leaked. | |
| 29 return V8UndefinedType(); | |
| 30 } | |
| 31 | |
| 32 static void dispose(WebType* value) | |
| 33 { | |
| 34 ASSERT(!value); // Anything passed here will be leaked. | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 UndefinedValue(); | |
| 39 }; | |
| 40 | |
| 41 class RegionArray { | |
| 42 public: | |
| 43 typedef blink::WebVector<blink::WebGeofencingRegion> WebType; | |
| 44 static HeapVector<Member<GeofencingRegion> > take(ScriptPromiseResolver* res olver, WebType* regionsRaw) | |
| 45 { | |
| 46 OwnPtr<WebType> webRegions = adoptPtr(regionsRaw); | |
| 47 HeapVector<Member<GeofencingRegion> > regions; | |
| 48 for (size_t i = 0; i < webRegions->size(); ++i) { | |
| 49 regions.append(GeofencingRegion::createFromWebRegion((*webRegions)[i ])); | |
| 50 } | |
| 51 return regions; | |
| 52 } | |
| 53 | |
| 54 static void dispose(WebType* regionsRaw) | |
| 55 { | |
| 56 delete regionsRaw; | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 RegionArray(); | |
| 61 }; | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 14 Geofencing::Geofencing() | 65 Geofencing::Geofencing() |
| 15 { | 66 { |
| 16 ScriptWrappable::init(this); | 67 ScriptWrappable::init(this); |
| 17 } | 68 } |
| 18 | 69 |
| 19 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region) | 70 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region) |
| 20 { | 71 { |
| 21 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); | 72 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
| 73 if (!provider) { | |
| 74 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
| 75 } | |
| 76 | |
| 77 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 78 ScriptPromise promise = resolver->promise(); | |
| 79 // TODO(mek): somehow pass a reference to the current serviceworker to the p rovider. | |
| 80 provider->registerRegion(region->webRegion(), new CallbackPromiseAdapter<Und efinedValue, GeofencingError>(resolver)); | |
| 81 return promise; | |
| 22 } | 82 } |
| 23 | 83 |
| 24 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) | 84 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) |
| 25 { | 85 { |
| 26 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); | 86 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
| 87 if (!provider) { | |
| 88 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
| 89 } | |
| 90 | |
| 91 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 92 ScriptPromise promise = resolver->promise(); | |
| 93 // TODO(mek): somehow pass a reference to the current serviceworker to the p rovider. | |
| 94 provider->unregisterRegion(regionId, new CallbackPromiseAdapter<UndefinedVal ue, GeofencingError>(resolver)); | |
| 95 return promise; | |
| 27 } | 96 } |
| 28 | 97 |
| 29 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const | 98 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const |
| 30 { | 99 { |
| 31 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); | 100 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
| 101 if (!provider) { | |
| 102 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
| 103 } | |
|
esprehn
2014/08/19 01:15:59
no braces
Marijn Kruisselbrink
2014/08/19 18:55:14
Done.
| |
| 104 | |
| 105 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 106 ScriptPromise promise = resolver->promise(); | |
| 107 // TODO(mek): somehow pass a reference to the current serviceworker to the p rovider. | |
| 108 provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, Geofe ncingError>(resolver)); | |
| 109 return promise; | |
| 32 } | 110 } |
| 33 | 111 |
| 34 } // namespace blink | 112 } // namespace blink |
| OLD | NEW |