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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg
ion* region) | 55 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg
ion* region) |
56 { | 56 { |
57 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 57 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
58 if (!provider) | 58 if (!provider) |
59 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 59 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
60 | 60 |
61 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 61 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
62 ScriptPromise promise = resolver->promise(); | 62 ScriptPromise promise = resolver->promise(); |
63 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); | 63 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); |
64 // FIXME: remove this call once chromium is updated to implement the other r
egisterRegion. | |
65 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w
ebRegion(), callbacks); | |
66 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; | 64 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; |
67 if (m_registration) | 65 if (m_registration) |
68 serviceWorkerRegistration = m_registration->webRegistration(); | 66 serviceWorkerRegistration = m_registration->webRegistration(); |
69 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w
ebRegion(), serviceWorkerRegistration, callbacks); | 67 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w
ebRegion(), serviceWorkerRegistration, callbacks); |
70 return promise; | 68 return promise; |
71 } | 69 } |
72 | 70 |
73 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin
g& regionId) | 71 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin
g& regionId) |
74 { | 72 { |
75 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 73 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
76 if (!provider) | 74 if (!provider) |
77 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 75 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
78 | 76 |
79 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 77 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
80 ScriptPromise promise = resolver->promise(); | 78 ScriptPromise promise = resolver->promise(); |
81 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); | 79 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); |
82 // FIXME: remove this call once chromium is updated to implement the other u
nregisterRegion. | |
83 provider->unregisterRegion(regionId, callbacks); | |
84 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; | 80 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; |
85 if (m_registration) | 81 if (m_registration) |
86 serviceWorkerRegistration = m_registration->webRegistration(); | 82 serviceWorkerRegistration = m_registration->webRegistration(); |
87 provider->unregisterRegion(regionId, serviceWorkerRegistration, callbacks); | 83 provider->unregisterRegion(regionId, serviceWorkerRegistration, callbacks); |
88 return promise; | 84 return promise; |
89 } | 85 } |
90 | 86 |
91 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const | 87 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const |
92 { | 88 { |
93 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 89 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
94 if (!provider) | 90 if (!provider) |
95 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 91 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
96 | 92 |
97 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 93 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
98 ScriptPromise promise = resolver->promise(); | 94 ScriptPromise promise = resolver->promise(); |
99 WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<Region
Array, GeofencingError>(resolver); | 95 WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<Region
Array, GeofencingError>(resolver); |
100 // FIXME: remove this call once chromium is updated to implement the other g
etRegisteredRegions. | |
101 provider->getRegisteredRegions(callbacks); | |
102 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; | 96 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; |
103 if (m_registration) | 97 if (m_registration) |
104 serviceWorkerRegistration = m_registration->webRegistration(); | 98 serviceWorkerRegistration = m_registration->webRegistration(); |
105 provider->getRegisteredRegions(serviceWorkerRegistration, callbacks); | 99 provider->getRegisteredRegions(serviceWorkerRegistration, callbacks); |
106 return promise; | 100 return promise; |
107 } | 101 } |
108 | 102 |
109 void Geofencing::trace(Visitor* visitor) | 103 void Geofencing::trace(Visitor* visitor) |
110 { | 104 { |
111 visitor->trace(m_registration); | 105 visitor->trace(m_registration); |
112 } | 106 } |
113 | 107 |
114 } // namespace blink | 108 } // namespace blink |
OLD | NEW |