Commit 53e74f18 authored by mek@chromium.org's avatar mek@chromium.org

Pass through geofencing API calls to the content layer.

BUG=383125

Review URL: https://codereview.chromium.org/464073002

git-svn-id: svn://svn.chromium.org/blink/trunk@181755 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7e4cb4ce
......@@ -14,7 +14,7 @@ function shouldReject(promise)
function() { testPassed("Promise rejected as expected."); });
}
shouldReject(navigator.geofencing.registerRegion(new CircularRegion({latitude: 37.421999, longitude: -122.084015})));
shouldReject(navigator.geofencing.registerRegion(new CircularGeofencingRegion({latitude: 37.421999, longitude: -122.084015})));
shouldReject(navigator.geofencing.unregisterRegion(""));
shouldReject(navigator.geofencing.getRegisteredRegions());
</script>
......
......@@ -17,7 +17,7 @@ Starting worker: resources/global-context-constructors-listing.js
[Worker] ArrayBuffer
[Worker] Blob
[Worker] Boolean
[Worker] CircularRegion
[Worker] CircularGeofencingRegion
[Worker] DataView
[Worker] Date
[Worker] DedicatedWorkerGlobalScope
......
......@@ -66,7 +66,7 @@ CanvasRenderingContext2D
ChannelMergerNode
ChannelSplitterNode
CharacterData
CircularRegion
CircularGeofencingRegion
ClientRect
ClientRectList
CloseEvent
......
......@@ -8,7 +8,7 @@ Starting worker: resources/global-context-constructors-listing.js
[Worker] ArrayBuffer
[Worker] Blob
[Worker] Boolean
[Worker] CircularRegion
[Worker] CircularGeofencingRegion
[Worker] DataView
[Worker] Date
[Worker] Error
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/geofencing/CircularGeofencingRegion.h"
#include "bindings/core/v8/Dictionary.h"
#include "public/platform/WebString.h"
namespace blink {
CircularGeofencingRegion* CircularGeofencingRegion::create(const Dictionary& dictionary)
{
String id;
DictionaryHelper::get(dictionary, "id", id);
WebCircularGeofencingRegion region;
DictionaryHelper::get(dictionary, "latitude", region.latitude);
DictionaryHelper::get(dictionary, "longitude", region.longitude);
DictionaryHelper::get(dictionary, "radius", region.radius);
return new CircularGeofencingRegion(id, region);
}
CircularGeofencingRegion* CircularGeofencingRegion::create(const WebString& id, const WebCircularGeofencingRegion& region)
{
return new CircularGeofencingRegion(id, region);
}
CircularGeofencingRegion::CircularGeofencingRegion(const String& id, const WebCircularGeofencingRegion& region)
: GeofencingRegion(id)
, m_webRegion(region)
{
}
WebCircularGeofencingRegion CircularGeofencingRegion::webRegion() const
{
return m_webRegion;
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CircularGeofencingRegion_h
#define CircularGeofencingRegion_h
#include "modules/geofencing/GeofencingRegion.h"
#include "public/platform/WebCircularGeofencingRegion.h"
namespace blink {
class Dictionary;
class CircularGeofencingRegion FINAL : public GeofencingRegion {
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(CircularGeofencingRegion);
public:
static CircularGeofencingRegion* create(const Dictionary& init);
static CircularGeofencingRegion* create(const WebString& id, const WebCircularGeofencingRegion&);
virtual ~CircularGeofencingRegion() { }
double latitude() const { return m_webRegion.latitude; }
double longitude() const { return m_webRegion.longitude; }
double radius() const { return m_webRegion.radius; }
WebCircularGeofencingRegion webRegion() const;
virtual void trace(Visitor* visitor) OVERRIDE { GeofencingRegion::trace(visitor); }
virtual bool isCircularGeofencingRegion() const OVERRIDE { return true; }
private:
explicit CircularGeofencingRegion(const String& id, const WebCircularGeofencingRegion&);
WebCircularGeofencingRegion m_webRegion;
};
DEFINE_TYPE_CASTS(CircularGeofencingRegion, GeofencingRegion, region, region->isCircularGeofencingRegion(), region.isCircularGeofencingRegion());
} // namespace blink
#endif // CircularGeofencingRegion_h
......@@ -7,7 +7,7 @@
Exposed=(Window,Worker),
GarbageCollected,
Constructor(Dictionary init)
] interface CircularRegion : GeofencingRegion {
] interface CircularGeofencingRegion : GeofencingRegion {
const double MIN_RADIUS = 1.0;
const double MAX_RADIUS = 100.0;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/geofencing/CircularRegion.h"
#include "bindings/core/v8/Dictionary.h"
namespace blink {
CircularRegionInit::CircularRegionInit(const Dictionary& init)
: latitude(0)
, longitude(0)
, radius(0)
{
DictionaryHelper::get(init, "id", id);
DictionaryHelper::get(init, "latitude", latitude);
DictionaryHelper::get(init, "longitude", longitude);
DictionaryHelper::get(init, "radius", radius);
}
CircularRegion* CircularRegion::create(const Dictionary& init)
{
return new CircularRegion(CircularRegionInit(init));
}
CircularRegion::CircularRegion(const CircularRegionInit& init)
: GeofencingRegion(init.id)
, m_latitude(init.latitude)
, m_longitude(init.longitude)
, m_radius(init.radius)
{
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CircularRegion_h
#define CircularRegion_h
#include "modules/geofencing/GeofencingRegion.h"
namespace blink {
class Dictionary;
struct CircularRegionInit {
CircularRegionInit() : latitude(0), longitude(0), radius(0) { }
explicit CircularRegionInit(const Dictionary& init);
String id;
double latitude;
double longitude;
double radius;
};
class CircularRegion FINAL : public GeofencingRegion {
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(CircularRegion);
public:
static CircularRegion* create(const Dictionary& init);
virtual ~CircularRegion() { }
double latitude() const { return m_latitude; }
double longitude() const { return m_longitude; }
double radius() const { return m_radius; }
virtual void trace(Visitor* visitor) OVERRIDE { GeofencingRegion::trace(visitor); }
private:
explicit CircularRegion(const CircularRegionInit&);
double m_latitude;
double m_longitude;
double m_radius;
};
} // namespace blink
#endif // CircularRegion_h
......@@ -5,29 +5,88 @@
#include "config.h"
#include "modules/geofencing/Geofencing.h"
#include "bindings/core/v8/CallbackPromiseAdapter.h"
#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
#include "modules/geofencing/CircularGeofencingRegion.h"
#include "modules/geofencing/GeofencingError.h"
#include "modules/geofencing/GeofencingRegion.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCircularGeofencingRegion.h"
#include "public/platform/WebGeofencingProvider.h"
#include "public/platform/WebGeofencingRegistration.h"
namespace blink {
namespace {
// For CallbackPromiseAdapter to convert a WebVector of regions to a HeapVector.
class RegionArray {
public:
typedef blink::WebVector<blink::WebGeofencingRegistration> WebType;
static HeapVector<Member<GeofencingRegion> > take(ScriptPromiseResolver* resolver, WebType* regionsRaw)
{
OwnPtr<WebType> webRegions = adoptPtr(regionsRaw);
HeapVector<Member<GeofencingRegion> > regions;
for (size_t i = 0; i < webRegions->size(); ++i)
regions.append(CircularGeofencingRegion::create((*webRegions)[i].id, (*webRegions)[i].region));
return regions;
}
static void dispose(WebType* regionsRaw)
{
delete regionsRaw;
}
private:
RegionArray();
};
} // namespace
Geofencing::Geofencing()
{
}
ScriptPromise Geofencing::registerRegion(ScriptState* scriptState, GeofencingRegion* region)
{
WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
if (!provider)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
// FIXME: somehow pass a reference to the current serviceworker to the provider.
provider->registerRegion(region->id(), toCircularGeofencingRegion(region)->webRegion(), new CallbackPromiseAdapter<void, GeofencingError>(resolver));
return promise;
}
ScriptPromise Geofencing::unregisterRegion(ScriptState* scriptState, const String& regionId)
{
WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
if (!provider)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
// FIXME: somehow pass a reference to the current serviceworker to the provider.
provider->unregisterRegion(regionId, new CallbackPromiseAdapter<void, GeofencingError>(resolver));
return promise;
}
ScriptPromise Geofencing::getRegisteredRegions(ScriptState* scriptState) const
{
WebGeofencingProvider* provider = Platform::current()->geofencingProvider();
if (!provider)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
// FIXME: somehow pass a reference to the current serviceworker to the provider.
provider->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, GeofencingError>(resolver));
return promise;
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/geofencing/GeofencingError.h"
#include "core/dom/ExceptionCode.h"
#include "wtf/OwnPtr.h"
namespace blink {
PassRefPtrWillBeRawPtr<DOMException> GeofencingError::take(ScriptPromiseResolver*, WebType* webErrorRaw)
{
OwnPtr<WebType> webError = adoptPtr(webErrorRaw);
switch (webError->errorType) {
case WebType::ErrorTypeAbort:
return DOMException::create(AbortError, webError->message);
case WebType::ErrorTypeUnknown:
return DOMException::create(UnknownError, webError->message);
}
ASSERT_NOT_REACHED();
return DOMException::create(UnknownError);
}
void GeofencingError::dispose(WebType* webErrorRaw)
{
delete webErrorRaw;
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GeofencingError_h
#define GeofencingError_h
#include "core/dom/DOMException.h"
#include "platform/heap/Handle.h"
#include "public/platform/WebGeofencingError.h"
namespace blink {
class ScriptPromiseResolver;
class GeofencingError {
WTF_MAKE_NONCOPYABLE(GeofencingError);
public:
// For CallbackPromiseAdapter.
typedef blink::WebGeofencingError WebType;
static PassRefPtrWillBeRawPtr<DOMException> take(ScriptPromiseResolver*, WebType* webErrorRaw);
static void dispose(WebType* webErrorRaw);
private:
GeofencingError() WTF_DELETED_FUNCTION;
};
} // namespace blink
#endif // GeofencingError_h
......@@ -21,8 +21,11 @@ public:
virtual void trace(Visitor*) { }
// For SpecialWrapFor
virtual bool isCircularGeofencingRegion() const { return false; }
protected:
GeofencingRegion(const String& id) : m_id(id) { }
explicit GeofencingRegion(const String& id) : m_id(id) { }
private:
String m_id;
......
......@@ -4,6 +4,7 @@
[
RuntimeEnabled=Geofencing,
SpecialWrapFor=CircularGeofencingRegion,
NoInterfaceObject,
GarbageCollected,
] interface GeofencingRegion {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/geofencing/WorkerNavigatorGeofencing.h"
#include "core/workers/WorkerNavigator.h"
#include "modules/geofencing/Geofencing.h"
namespace blink {
WorkerNavigatorGeofencing::WorkerNavigatorGeofencing()
{
}
WorkerNavigatorGeofencing::~WorkerNavigatorGeofencing()
{
}
const char* WorkerNavigatorGeofencing::supplementName()
{
return "WorkerNavigatorGeofencing";
}
WorkerNavigatorGeofencing& WorkerNavigatorGeofencing::from(WorkerNavigator& navigator)
{
WorkerNavigatorGeofencing* supplement = static_cast<WorkerNavigatorGeofencing*>(WillBeHeapSupplement<WorkerNavigator>::from(navigator, supplementName()));
if (!supplement) {
supplement = new WorkerNavigatorGeofencing();
provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
}
return *supplement;
}
Geofencing* WorkerNavigatorGeofencing::geofencing(WorkerNavigator& navigator)
{
return WorkerNavigatorGeofencing::from(navigator).geofencing();
}
Geofencing* WorkerNavigatorGeofencing::geofencing()
{
if (!m_geofencing)
m_geofencing = Geofencing::create();
return m_geofencing.get();
}
void WorkerNavigatorGeofencing::trace(Visitor* visitor)
{
visitor->trace(m_geofencing);
WillBeHeapSupplement<WorkerNavigator>::trace(visitor);
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WorkerNavigatorGeofencing_h
#define WorkerNavigatorGeofencing_h
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
namespace blink {
class Geofencing;
class WorkerNavigator;
class WorkerNavigatorGeofencing FINAL : public NoBaseWillBeGarbageCollectedFinalized<WorkerNavigatorGeofencing>, public WillBeHeapSupplement<WorkerNavigator> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WorkerNavigatorGeofencing);
WTF_MAKE_NONCOPYABLE(WorkerNavigatorGeofencing);
public:
virtual ~WorkerNavigatorGeofencing();
static WorkerNavigatorGeofencing& from(WorkerNavigator&);
static Geofencing* geofencing(WorkerNavigator&);
Geofencing* geofencing();
virtual void trace(Visitor*) OVERRIDE;
private:
WorkerNavigatorGeofencing();
static const char* supplementName();
PersistentWillBeMember<Geofencing> m_geofencing;
};
} // namespace blink
#endif // WorkerNavigatorGeofencing_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
RuntimeEnabled=Geofencing,
Exposed=Worker,
] partial interface WorkerNavigator {
readonly attribute Geofencing geofencing;
};
......@@ -59,7 +59,7 @@
'gamepad/GamepadList.idl',
'gamepad/WebKitGamepad.idl',
'gamepad/WebKitGamepadList.idl',
'geofencing/CircularRegion.idl',
'geofencing/CircularGeofencingRegion.idl',
'geofencing/Geofencing.idl',
'geofencing/GeofencingRegion.idl',
'geolocation/Coordinates.idl',
......@@ -223,6 +223,7 @@
'filesystem/WorkerGlobalScopeFileSystem.idl',
'gamepad/NavigatorGamepad.idl',
'geofencing/NavigatorGeofencing.idl',
'geofencing/WorkerNavigatorGeofencing.idl',
'geolocation/NavigatorGeolocation.idl',
'indexeddb/WindowIndexedDatabase.idl',
'indexeddb/WorkerGlobalScopeIndexedDatabase.idl',
......@@ -460,13 +461,17 @@
'gamepad/WebKitGamepad.h',
'gamepad/WebKitGamepadList.cpp',
'gamepad/WebKitGamepadList.h',
'geofencing/CircularRegion.cpp',
'geofencing/CircularRegion.h',
'geofencing/CircularGeofencingRegion.cpp',
'geofencing/CircularGeofencingRegion.h',
'geofencing/Geofencing.cpp',
'geofencing/Geofencing.h',
'geofencing/GeofencingError.cpp',
'geofencing/GeofencingError.h',
'geofencing/GeofencingRegion.h',
'geofencing/NavigatorGeofencing.cpp',
'geofencing/NavigatorGeofencing.h',
'geofencing/WorkerNavigatorGeofencing.cpp',
'geofencing/WorkerNavigatorGeofencing.h',
'geolocation/Coordinates.cpp',
'geolocation/Geolocation.cpp',
'geolocation/GeolocationController.cpp',
......
......@@ -74,6 +74,7 @@ class WebFallbackThemeEngine;
class WebFileSystem;
class WebFileUtilities;
class WebFlingAnimator;
class WebGeofencingProvider;
class WebGestureCurveTarget;
class WebGestureCurve;
class WebGraphicsContext3DProvider;
......@@ -631,6 +632,10 @@ public:
virtual WebNotificationPresenter* notificationPresenter() { return 0; }
// Geofencing ---------------------------------------------------------
virtual WebGeofencingProvider* geofencingProvider() { return 0; }
protected:
virtual ~Platform() { }
};
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebCircularGeofencingRegion_h
#define WebCircularGeofencingRegion_h
#include "WebCommon.h"
#include "WebString.h"
namespace blink {
struct WebCircularGeofencingRegion {
double latitude;
double longitude;
double radius;
WebCircularGeofencingRegion()
: latitude(0)
, longitude(0)
, radius(0)
{
}
};
} // namespace blink
#endif // WebCircularGeofencingRegion_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebGeofencingError_h
#define WebGeofencingError_h
#include "WebString.h"
namespace blink {
struct WebGeofencingError {
enum ErrorType {
ErrorTypeAbort = 0,
ErrorTypeUnknown,
ErrorTypeLast = ErrorTypeUnknown
};
WebGeofencingError(ErrorType errorType, const WebString& message)
: errorType(errorType)
, message(message)
{
}
ErrorType errorType;
WebString message;
};
} // namespace blink
#endif // WebGeofencingError_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebGeofencingProvider_h
#define WebGeofencingProvider_h
#include "public/platform/WebCallbacks.h"
#include "public/platform/WebVector.h"
namespace blink {
struct WebCircularGeofencingRegion;
struct WebGeofencingError;
struct WebGeofencingRegistration;
class WebString;
typedef WebCallbacks<void, WebGeofencingError> WebGeofencingCallbacks;
typedef WebCallbacks<WebVector<WebGeofencingRegistration>, WebGeofencingError> WebGeofencingRegionsCallbacks;
class WebGeofencingProvider {
public:
virtual ~WebGeofencingProvider() { }
// Registers a region.
// Ownership of the WebGeofencingCallbacks is transferred to the client.
virtual void registerRegion(const WebString& regionId, const WebCircularGeofencingRegion&, WebGeofencingCallbacks*) = 0;
// Unregisters a region.
// Ownership of the WebGeofencingCallbacks is transferred to the client.
virtual void unregisterRegion(const WebString& regionId, WebGeofencingCallbacks*) = 0;
// Returns all the currently registered regions.
// Ownership of the WebGeofencingRegionsCallbacks is transferred to the client.
virtual void getRegisteredRegions(WebGeofencingRegionsCallbacks*) = 0;
};
} // namespace blink
#endif // WebGeofencingProvider_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebGeofencingRegistration_h
#define WebGeofencingRegistration_h
#include "WebCircularGeofencingRegion.h"
#include "WebString.h"
namespace blink {
struct WebGeofencingRegistration {
WebString id;
WebCircularGeofencingRegion region;
WebGeofencingRegistration() { }
};
} // namespace blink
#endif // WebGeofencingRegistration_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment