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/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
13 #include "modules/geofencing/CircularGeofencingRegion.h" | 13 #include "modules/geofencing/CircularGeofencingRegion.h" |
14 #include "modules/geofencing/GeofencingError.h" | 14 #include "modules/geofencing/GeofencingError.h" |
15 #include "modules/geofencing/GeofencingRegion.h" | 15 #include "modules/geofencing/GeofencingRegion.h" |
16 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | |
16 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
17 #include "public/platform/WebCircularGeofencingRegion.h" | 18 #include "public/platform/WebCircularGeofencingRegion.h" |
18 #include "public/platform/WebGeofencingProvider.h" | 19 #include "public/platform/WebGeofencingProvider.h" |
19 #include "public/platform/WebGeofencingRegistration.h" | 20 #include "public/platform/WebGeofencingRegistration.h" |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // For CallbackPromiseAdapter to convert a WebVector of regions to a HeapVector. | 26 // For CallbackPromiseAdapter to convert a WebVector of regions to a HeapVector. |
(...skipping 13 matching lines...) Expand all Loading... | |
39 { | 40 { |
40 delete regionsRaw; | 41 delete regionsRaw; |
41 } | 42 } |
42 | 43 |
43 private: | 44 private: |
44 RegionArray(); | 45 RegionArray(); |
45 }; | 46 }; |
46 | 47 |
47 } // namespace | 48 } // namespace |
48 | 49 |
49 Geofencing::Geofencing() | 50 Geofencing::Geofencing(ServiceWorkerRegistration* registration) |
51 : m_registration(registration) | |
50 { | 52 { |
51 } | 53 } |
52 | 54 |
53 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region) | 55 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region) |
54 { | 56 { |
55 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 57 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
56 if (!provider) | 58 if (!provider) |
57 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | 59 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); |
58 | 60 |
59 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 61 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
60 ScriptPromise promise = resolver->promise(); | 62 ScriptPromise promise = resolver->promise(); |
61 // FIXME: somehow pass a reference to the current serviceworker to the provi der. | 63 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc ingError>(resolver); |
62 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w ebRegion(), new CallbackPromiseAdapter<void, GeofencingError>(resolver)); | 64 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w ebRegion(), callbacks); |
65 WebServiceWorkerRegistration* serviceworker = nullptr; | |
Michael van Ouwerkerk
2014/10/09 10:56:27
Here and below, probably clearer to call the varia
Marijn Kruisselbrink
2014/10/09 18:10:54
Done.
| |
66 if (m_registration) | |
67 serviceworker = m_registration->webRegistration(); | |
68 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w ebRegion(), serviceworker, callbacks); | |
Michael van Ouwerkerk
2014/10/09 10:56:27
Why is registerRegion called twice?
Marijn Kruisselbrink
2014/10/09 18:10:54
Because I can't update blink and chromium in the s
| |
63 return promise; | 69 return promise; |
64 } | 70 } |
65 | 71 |
66 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) | 72 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) |
67 { | 73 { |
68 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 74 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
69 if (!provider) | 75 if (!provider) |
70 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | 76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); |
71 | 77 |
72 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 78 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
73 ScriptPromise promise = resolver->promise(); | 79 ScriptPromise promise = resolver->promise(); |
74 // FIXME: somehow pass a reference to the current serviceworker to the provi der. | 80 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc ingError>(resolver); |
75 provider->unregisterRegion(regionId, new CallbackPromiseAdapter<void, Geofen cingError>(resolver)); | 81 provider->unregisterRegion(regionId, callbacks); |
82 WebServiceWorkerRegistration* serviceworker = nullptr; | |
83 if (m_registration) | |
84 serviceworker = m_registration->webRegistration(); | |
85 provider->unregisterRegion(regionId, serviceworker, callbacks); | |
Michael van Ouwerkerk
2014/10/09 10:56:27
Why is unregisterRegion called twice?
Marijn Kruisselbrink
2014/10/09 18:10:54
Same as for registerRegion.
| |
76 return promise; | 86 return promise; |
77 } | 87 } |
78 | 88 |
79 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const | 89 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const |
80 { | 90 { |
81 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 91 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
82 if (!provider) | 92 if (!provider) |
83 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | 93 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); |
84 | 94 |
85 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 95 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
86 ScriptPromise promise = resolver->promise(); | 96 ScriptPromise promise = resolver->promise(); |
87 // FIXME: somehow pass a reference to the current serviceworker to the provi der. | 97 WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<Region Array, GeofencingError>(resolver); |
88 provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, Geofe ncingError>(resolver)); | 98 provider->getRegisteredRegions(callbacks); |
99 WebServiceWorkerRegistration* serviceworker = nullptr; | |
100 if (m_registration) | |
101 serviceworker = m_registration->webRegistration(); | |
102 provider->getRegisteredRegions(serviceworker, callbacks); | |
Michael van Ouwerkerk
2014/10/09 10:56:27
Why is getRegisteredRegions called twice?
Marijn Kruisselbrink
2014/10/09 18:10:54
Same as for registerRegion.
| |
89 return promise; | 103 return promise; |
90 } | 104 } |
91 | 105 |
106 void Geofencing::trace(Visitor* visitor) | |
107 { | |
108 visitor->trace(m_registration); | |
109 } | |
110 | |
92 } // namespace blink | 111 } // namespace blink |
OLD | NEW |