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

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: only support circular regions for now 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"
11 19
12 namespace blink { 20 namespace blink {
13 21
22 namespace {
23
24 // For CallbackPromiseAdapter to convert a WebVector of regions to a HeapVector.
25 class RegionArray {
26 public:
27 typedef blink::WebVector<blink::WebCircularGeofencingRegion> WebType;
28 static HeapVector<Member<GeofencingRegion> > take(ScriptPromiseResolver* res olver, WebType* regionsRaw)
29 {
30 OwnPtr<WebType> webRegions = adoptPtr(regionsRaw);
31 HeapVector<Member<GeofencingRegion> > regions;
32 for (size_t i = 0; i < webRegions->size(); ++i) {
jochen (gone - plz use gerrit) 2014/09/04 11:14:54 nit, no { }
Marijn Kruisselbrink 2014/09/04 17:44:19 Done.
33 regions.append(CircularGeofencingRegion::create((*webRegions)[i]));
34 }
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 ScriptWrappable::init(this); 51 ScriptWrappable::init(this);
17 } 52 }
18 53
19 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region) 54 ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingReg ion* region)
20 { 55 {
21 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 56 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
57 if (!provider)
58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
59
60 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
61 ScriptPromise promise = resolver->promise();
62 // FIXME: somehow pass a reference to the current serviceworker to the provi der.
63 provider->registerRegion(toCircularGeofencingRegion(region)->webRegion(), ne w CallbackPromiseAdapter<void, GeofencingError>(resolver));
64 return promise;
22 } 65 }
23 66
24 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId) 67 ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const Strin g& regionId)
25 { 68 {
26 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 69 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
70 if (!provider)
71 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
72
73 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
74 ScriptPromise promise = resolver->promise();
75 // FIXME: somehow pass a reference to the current serviceworker to the provi der.
76 provider->unregisterRegion(regionId, new CallbackPromiseAdapter<void, Geofen cingError>(resolver));
77 return promise;
27 } 78 }
28 79
29 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const 80 ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const
30 { 81 {
31 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 82 WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
83 if (!provider)
84 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
85
86 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
87 ScriptPromise promise = resolver->promise();
88 // FIXME: somehow pass a reference to the current serviceworker to the provi der.
89 provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, Geofe ncingError>(resolver));
90 return promise;
32 } 91 }
33 92
34 } // namespace blink 93 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698