Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: Source/modules/geofencing/Geofencing.cpp

Issue 623813002: Blink side of exposing the service worker registration associated with geofencing API calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: hopefully correctly fix compile Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/geofencing/Geofencing.h ('k') | Source/modules/geofencing/NavigatorGeofencing.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // 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;
67 if (m_registration)
68 serviceWorkerRegistration = m_registration->webRegistration();
69 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w ebRegion(), serviceWorkerRegistration, callbacks);
63 return promise; 70 return promise;
64 } 71 }
65 72
66 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) 73 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId)
67 { 74 {
68 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); 75 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
69 if (!provider) 76 if (!provider)
70 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); 77 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
71 78
72 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 79 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
73 ScriptPromise promise = resolver->promise(); 80 ScriptPromise promise = resolver->promise();
74 // FIXME: somehow pass a reference to the current serviceworker to the provi der. 81 WebGeofencingCallbacks* callbacks = new CallbackPromiseAdapter<void, Geofenc ingError>(resolver);
75 provider->unregisterRegion(regionId, new CallbackPromiseAdapter<void, Geofen cingError>(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;
85 if (m_registration)
86 serviceWorkerRegistration = m_registration->webRegistration();
87 provider->unregisterRegion(regionId, serviceWorkerRegistration, callbacks);
76 return promise; 88 return promise;
77 } 89 }
78 90
79 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const 91 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const
80 { 92 {
81 WebGeofencingProvider* provider = Platform::current()->geofencingProvider(); 93 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
82 if (!provider) 94 if (!provider)
83 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); 95 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
84 96
85 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 97 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
86 ScriptPromise promise = resolver->promise(); 98 ScriptPromise promise = resolver->promise();
87 // FIXME: somehow pass a reference to the current serviceworker to the provi der. 99 WebGeofencingRegionsCallbacks* callbacks = new CallbackPromiseAdapter<Region Array, GeofencingError>(resolver);
88 provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, Geofe ncingError>(resolver)); 100 // FIXME: remove this call once chromium is updated to implement the other g etRegisteredRegions.
101 provider->getRegisteredRegions(callbacks);
102 WebServiceWorkerRegistration* serviceWorkerRegistration = nullptr;
103 if (m_registration)
104 serviceWorkerRegistration = m_registration->webRegistration();
105 provider->getRegisteredRegions(serviceWorkerRegistration, callbacks);
89 return promise; 106 return promise;
90 } 107 }
91 108
109 void Geofencing::trace(Visitor* visitor)
110 {
111 visitor->trace(m_registration);
112 }
113
92 } // namespace blink 114 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/geofencing/Geofencing.h ('k') | Source/modules/geofencing/NavigatorGeofencing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698