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

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

Issue 464073002: Pass through geofencing API calls to the content layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix test expectations Created 6 years, 3 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
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/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/CircularGeofencingRegion.h"
14 #include "modules/geofencing/GeofencingError.h"
15 #include "modules/geofencing/GeofencingRegion.h"
16 #include "public/platform/Platform.h"
17 #include "public/platform/WebCircularGeofencingRegion.h"
18 #include "public/platform/WebGeofencingProvider.h"
19 #include "public/platform/WebGeofencingRegistration.h"
11 20
12 namespace blink { 21 namespace blink {
13 22
23 namespace {
24
25 // For CallbackPromiseAdapter to convert a WebVector of regions to a HeapVector.
26 class RegionArray {
27 public:
28 typedef blink::WebVector<blink::WebGeofencingRegistration> WebType;
29 static HeapVector<Member<GeofencingRegion> > take(ScriptPromiseResolver* res olver, WebType* regionsRaw)
30 {
31 OwnPtr<WebType> webRegions = adoptPtr(regionsRaw);
32 HeapVector<Member<GeofencingRegion> > regions;
33 for (size_t i = 0; i < webRegions->size(); ++i)
34 regions.append(CircularGeofencingRegion::create((*webRegions)[i].id, (*webRegions)[i].region));
35 return regions;
36 }
37
38 static void dispose(WebType* regionsRaw)
39 {
40 delete regionsRaw;
41 }
42
43 private:
44 RegionArray();
45 };
46
47 } // namespace
48
14 Geofencing::Geofencing() 49 Geofencing::Geofencing()
15 { 50 {
16 } 51 }
17 52
18 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region) 53 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region)
19 { 54 {
20 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 55 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
56 if (!provider)
57 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
58
59 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
60 ScriptPromise promise = resolver->promise();
61 // FIXME: somehow pass a reference to the current serviceworker to the provi der.
62 provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->w ebRegion(), new CallbackPromiseAdapter<void, GeofencingError>(resolver));
63 return promise;
21 } 64 }
22 65
23 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) 66 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId)
24 { 67 {
25 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 68 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
69 if (!provider)
70 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
71
72 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
73 ScriptPromise promise = resolver->promise();
74 // FIXME: somehow pass a reference to the current serviceworker to the provi der.
75 provider->unregisterRegion(regionId, new CallbackPromiseAdapter<void, Geofen cingError>(resolver));
76 return promise;
26 } 77 }
27 78
28 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const 79 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const
29 { 80 {
30 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 81 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
82 if (!provider)
83 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
84
85 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
86 ScriptPromise promise = resolver->promise();
87 // FIXME: somehow pass a reference to the current serviceworker to the provi der.
88 provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, Geofe ncingError>(resolver));
89 return promise;
31 } 90 }
32 91
33 } // namespace blink 92 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/geofencing/CircularRegion.idl ('k') | Source/modules/geofencing/GeofencingError.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698