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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 : m_registration(registration) | 46 : m_registration(registration) |
47 { | 47 { |
48 } | 48 } |
49 | 49 |
50 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg
ion* region) | 50 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg
ion* region) |
51 { | 51 { |
52 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 52 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
53 if (!provider) | 53 if (!provider) |
54 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 54 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
55 | 55 |
56 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 56 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
57 ScriptPromise promise = resolver->promise(); | 57 ScriptPromise promise = resolver->promise(); |
58 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); | 58 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); |
59 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; | 59 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; |
60 if (m_registration) | 60 if (m_registration) |
61 serviceWorkerRegistration = m_registration->webRegistration(); | 61 serviceWorkerRegistration = m_registration->webRegistration(); |
62 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w
ebRegion(), serviceWorkerRegistration, callbacks); | 62 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w
ebRegion(), serviceWorkerRegistration, callbacks); |
63 return promise; | 63 return promise; |
64 } | 64 } |
65 | 65 |
66 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin
g& regionId) | 66 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin
g& regionId) |
67 { | 67 { |
68 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 68 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
69 if (!provider) | 69 if (!provider) |
70 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 70 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
71 | 71 |
72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 72 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
73 ScriptPromise promise = resolver->promise(); | 73 ScriptPromise promise = resolver->promise(); |
74 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); | 74 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc
ingError>(resolver); |
75 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; | 75 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; |
76 if (m_registration) | 76 if (m_registration) |
77 serviceWorkerRegistration = m_registration->webRegistration(); | 77 serviceWorkerRegistration = m_registration->webRegistration(); |
78 provider->unregisterRegion(regionId, serviceWorkerRegistration, callbacks); | 78 provider->unregisterRegion(regionId, serviceWorkerRegistration, callbacks); |
79 return promise; | 79 return promise; |
80 } | 80 } |
81 | 81 |
82 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const | 82 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const |
83 { | 83 { |
84 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); | 84 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); |
85 if (!provider) | 85 if (!provider) |
86 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 86 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
87 | 87 |
88 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 88 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
89 ScriptPromise promise = resolver->promise(); | 89 ScriptPromise promise = resolver->promise(); |
90 WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<Region
Array, GeofencingError>(resolver); | 90 WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<Region
Array, GeofencingError>(resolver); |
91 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; | 91 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr; |
92 if (m_registration) | 92 if (m_registration) |
93 serviceWorkerRegistration = m_registration->webRegistration(); | 93 serviceWorkerRegistration = m_registration->webRegistration(); |
94 provider->getRegisteredRegions(serviceWorkerRegistration, callbacks); | 94 provider->getRegisteredRegions(serviceWorkerRegistration, callbacks); |
95 return promise; | 95 return promise; |
96 } | 96 } |
97 | 97 |
98 DEFINE_TRACE(Geofencing) | 98 DEFINE_TRACE(Geofencing) |
99 { | 99 { |
100 visitor->trace(m_registration); | 100 visitor->trace(m_registration); |
101 } | 101 } |
102 | 102 |
103 } // namespace blink | 103 } // namespace blink |
OLD | NEW |