summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/modules/geolocation
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/modules/geolocation')
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.h13
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.idl1
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.cpp174
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.h61
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.idl13
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationClient.h12
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.cpp79
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.h32
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationError.h11
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.cpp102
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.h75
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/GeolocationPosition.h18
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.h19
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.idl1
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.cpp24
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.h16
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.idl3
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/PositionError.h8
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/PositionError.idl1
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/PositionOptions.h36
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.cpp187
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.h99
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.cpp100
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.h57
-rw-r--r--chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.idl37
25 files changed, 959 insertions, 220 deletions
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.h b/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.h
index 82d37e671a8..8f6ed80bdad 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.h
@@ -27,19 +27,18 @@
#define Coordinates_h
#include "bindings/v8/ScriptWrappable.h"
-#include "core/events/Event.h"
-#include "wtf/RefCounted.h"
+#include "modules/EventModules.h"
+#include "platform/heap/Handle.h"
namespace WebCore {
-class Coordinates : public RefCounted<Coordinates>, public ScriptWrappable {
+class Coordinates : public GarbageCollectedFinalized<Coordinates>, public ScriptWrappable {
public:
- static PassRefPtr<Coordinates> create(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed) { return adoptRef(new Coordinates(latitude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed)); }
-
- PassRefPtr<Coordinates> isolatedCopy() const
+ static Coordinates* create(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
{
- return Coordinates::create(m_latitude, m_longitude, m_canProvideAltitude, m_altitude, m_accuracy, m_canProvideAltitudeAccuracy, m_altitudeAccuracy, m_canProvideHeading, m_heading, m_canProvideSpeed, m_speed);
+ return new Coordinates(latitude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
}
+ void trace(Visitor*) { }
double latitude() const { return m_latitude; }
double longitude() const { return m_longitude; }
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.idl b/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.idl
index ed2b8bf6c37..9ff3e281787 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.idl
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Coordinates.idl
@@ -24,6 +24,7 @@
*/
[
+ GarbageCollected,
NoInterfaceObject
] interface Coordinates {
readonly attribute double latitude;
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.cpp b/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.cpp
index 187a12a5a27..fd6675f6b52 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.cpp
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.cpp
@@ -29,12 +29,11 @@
#include "modules/geolocation/Geolocation.h"
#include "core/dom/Document.h"
-#include "wtf/CurrentTime.h"
-
#include "modules/geolocation/Coordinates.h"
#include "modules/geolocation/GeolocationController.h"
#include "modules/geolocation/GeolocationError.h"
#include "modules/geolocation/GeolocationPosition.h"
+#include "wtf/CurrentTime.h"
namespace WebCore {
@@ -42,18 +41,27 @@ static const char permissionDeniedErrorMessage[] = "User denied Geolocation";
static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocation service";
static const char framelessDocumentErrorMessage[] = "Geolocation cannot be used in frameless documents";
-static PassRefPtr<Geoposition> createGeoposition(GeolocationPosition* position)
+static Geoposition* createGeoposition(GeolocationPosition* position)
{
if (!position)
- return 0;
+ return nullptr;
- RefPtr<Coordinates> coordinates = Coordinates::create(position->latitude(), position->longitude(), position->canProvideAltitude(), position->altitude(),
- position->accuracy(), position->canProvideAltitudeAccuracy(), position->altitudeAccuracy(),
- position->canProvideHeading(), position->heading(), position->canProvideSpeed(), position->speed());
- return Geoposition::create(coordinates.release(), convertSecondsToDOMTimeStamp(position->timestamp()));
+ Coordinates* coordinates = Coordinates::create(
+ position->latitude(),
+ position->longitude(),
+ position->canProvideAltitude(),
+ position->altitude(),
+ position->accuracy(),
+ position->canProvideAltitudeAccuracy(),
+ position->altitudeAccuracy(),
+ position->canProvideHeading(),
+ position->heading(),
+ position->canProvideSpeed(),
+ position->speed());
+ return Geoposition::create(coordinates, convertSecondsToDOMTimeStamp(position->timestamp()));
}
-static PassRefPtr<PositionError> createPositionError(GeolocationError* error)
+static PositionError* createPositionError(GeolocationError* error)
{
PositionError::ErrorCode code = PositionError::POSITION_UNAVAILABLE;
switch (error->code()) {
@@ -68,7 +76,7 @@ static PassRefPtr<PositionError> createPositionError(GeolocationError* error)
return PositionError::create(code, error->message());
}
-Geolocation::GeoNotifier::GeoNotifier(Geolocation* geolocation, PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
+Geolocation::GeoNotifier::GeoNotifier(Geolocation* geolocation, PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PositionOptions* options)
: m_geolocation(geolocation)
, m_successCallback(successCallback)
, m_errorCallback(errorCallback)
@@ -83,7 +91,14 @@ Geolocation::GeoNotifier::GeoNotifier(Geolocation* geolocation, PassOwnPtr<Posit
ASSERT(m_options);
}
-void Geolocation::GeoNotifier::setFatalError(PassRefPtr<PositionError> error)
+void Geolocation::GeoNotifier::trace(Visitor* visitor)
+{
+ visitor->trace(m_geolocation);
+ visitor->trace(m_options);
+ visitor->trace(m_fatalError);
+}
+
+void Geolocation::GeoNotifier::setFatalError(PositionError* error)
{
// If a fatal error has already been set, stick with it. This makes sure that
// when permission is denied, this is the error reported, as required by the
@@ -94,18 +109,13 @@ void Geolocation::GeoNotifier::setFatalError(PassRefPtr<PositionError> error)
m_fatalError = error;
// An existing timer may not have a zero timeout.
m_timer.stop();
- m_timer.startOneShot(0);
+ m_timer.startOneShot(0, FROM_HERE);
}
void Geolocation::GeoNotifier::setUseCachedPosition()
{
m_useCachedPosition = true;
- m_timer.startOneShot(0);
-}
-
-bool Geolocation::GeoNotifier::hasZeroTimeout() const
-{
- return m_options->hasTimeout() && m_options->timeout() == 0;
+ m_timer.startOneShot(0, FROM_HERE);
}
void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position)
@@ -124,10 +134,9 @@ void Geolocation::GeoNotifier::runErrorCallback(PositionError* error)
m_errorCallback->handleEvent(error);
}
-void Geolocation::GeoNotifier::startTimerIfNeeded()
+void Geolocation::GeoNotifier::startTimer()
{
- if (m_options->hasTimeout())
- m_timer.startOneShot(m_options->timeout() / 1000.0);
+ m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE);
}
void Geolocation::GeoNotifier::stopTimer()
@@ -139,11 +148,7 @@ void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*)
{
m_timer.stop();
- // Protect this GeoNotifier object, since it
- // could be deleted by a call to clearWatch in a callback.
- RefPtr<GeoNotifier> protect(this);
-
- // Test for fatal error first. This is required for the case where the Frame is
+ // Test for fatal error first. This is required for the case where the LocalFrame is
// disconnected and requests are cancelled.
if (m_fatalError) {
runErrorCallback(m_fatalError.get());
@@ -160,21 +165,23 @@ void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*)
return;
}
- if (m_errorCallback) {
- RefPtr<PositionError> error = PositionError::create(PositionError::TIMEOUT, "Timeout expired");
- m_errorCallback->handleEvent(error.get());
- }
+ if (m_errorCallback)
+ m_errorCallback->handleEvent(PositionError::create(PositionError::TIMEOUT, "Timeout expired"));
m_geolocation->requestTimedOut(this);
}
-bool Geolocation::Watchers::add(int id, PassRefPtr<GeoNotifier> prpNotifier)
+void Geolocation::Watchers::trace(Visitor* visitor)
{
- ASSERT(id > 0);
- RefPtr<GeoNotifier> notifier = prpNotifier;
+ visitor->trace(m_idToNotifierMap);
+ visitor->trace(m_notifierToIdMap);
+}
- if (!m_idToNotifierMap.add(id, notifier.get()).isNewEntry)
+bool Geolocation::Watchers::add(int id, GeoNotifier* notifier)
+{
+ ASSERT(id > 0);
+ if (!m_idToNotifierMap.add(id, notifier).isNewEntry)
return false;
- m_notifierToIdMap.set(notifier.release(), id);
+ m_notifierToIdMap.set(notifier, id);
return true;
}
@@ -227,11 +234,11 @@ void Geolocation::Watchers::getNotifiersVector(GeoNotifierVector& copy) const
copyValuesToVector(m_idToNotifierMap, copy);
}
-PassRefPtr<Geolocation> Geolocation::create(ExecutionContext* context)
+Geolocation* Geolocation::create(ExecutionContext* context)
{
- RefPtr<Geolocation> geolocation = adoptRef(new Geolocation(context));
+ Geolocation* geolocation = new Geolocation(context);
geolocation->suspendIfNeeded();
- return geolocation.release();
+ return geolocation;
}
Geolocation::Geolocation(ExecutionContext* context)
@@ -246,26 +253,30 @@ Geolocation::~Geolocation()
ASSERT(m_allowGeolocation != InProgress);
}
-Document* Geolocation::document() const
+void Geolocation::trace(Visitor* visitor)
{
- return toDocument(executionContext());
+ visitor->trace(m_oneShots);
+ visitor->trace(m_watchers);
+ visitor->trace(m_pendingForPermissionNotifiers);
+ visitor->trace(m_lastPosition);
+ visitor->trace(m_requestsAwaitingCachedPosition);
}
-Frame* Geolocation::frame() const
+Document* Geolocation::document() const
{
- return document() ? document()->frame() : 0;
+ return toDocument(executionContext());
}
-Page* Geolocation::page() const
+LocalFrame* Geolocation::frame() const
{
- return document() ? document()->page() : 0;
+ return document() ? document()->frame() : 0;
}
void Geolocation::stop()
{
- Page* page = this->page();
- if (page && m_allowGeolocation == InProgress)
- GeolocationController::from(page)->cancelPermissionRequest(this);
+ LocalFrame* frame = this->frame();
+ if (frame && m_allowGeolocation == InProgress)
+ GeolocationController::from(frame)->cancelPermissionRequest(this);
// The frame may be moving to a new page and we want to get the permissions from the new page's client.
m_allowGeolocation = Unknown;
cancelAllRequests();
@@ -275,33 +286,33 @@ void Geolocation::stop()
Geoposition* Geolocation::lastPosition()
{
- Page* page = this->page();
- if (!page)
+ LocalFrame* frame = this->frame();
+ if (!frame)
return 0;
- m_lastPosition = createGeoposition(GeolocationController::from(page)->lastPosition());
+ m_lastPosition = createGeoposition(GeolocationController::from(frame)->lastPosition());
return m_lastPosition.get();
}
-void Geolocation::getCurrentPosition(PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
+void Geolocation::getCurrentPosition(PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PositionOptions* options)
{
if (!frame())
return;
- RefPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
- startRequest(notifier.get());
+ GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
+ startRequest(notifier);
m_oneShots.add(notifier);
}
-int Geolocation::watchPosition(PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
+int Geolocation::watchPosition(PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PositionOptions* options)
{
if (!frame())
return 0;
- RefPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
- startRequest(notifier.get());
+ GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
+ startRequest(notifier);
int watchID;
// Keep asking for the next id until we're given one that we don't already have.
@@ -319,14 +330,14 @@ void Geolocation::startRequest(GeoNotifier *notifier)
notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage));
else if (haveSuitableCachedPosition(notifier->options()))
notifier->setUseCachedPosition();
- else if (notifier->hasZeroTimeout())
- notifier->startTimerIfNeeded();
+ else if (!notifier->options()->timeout())
+ notifier->startTimer();
else if (!isAllowed()) {
// if we don't yet have permission, request for permission before calling startUpdating()
m_pendingForPermissionNotifiers.add(notifier);
requestPermission();
} else if (startUpdating(notifier))
- notifier->startTimerIfNeeded();
+ notifier->startTimer();
else
notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
}
@@ -377,8 +388,8 @@ void Geolocation::makeCachedPositionCallbacks()
if (m_oneShots.contains(notifier))
m_oneShots.remove(notifier);
else if (m_watchers.contains(notifier)) {
- if (notifier->hasZeroTimeout() || startUpdating(notifier))
- notifier->startTimerIfNeeded();
+ if (!notifier->options()->timeout() || startUpdating(notifier))
+ notifier->startTimer();
else
notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
}
@@ -404,8 +415,6 @@ bool Geolocation::haveSuitableCachedPosition(PositionOptions* options)
Geoposition* cachedPosition = lastPosition();
if (!cachedPosition)
return false;
- if (!options->hasMaximumAge())
- return true;
if (!options->maximumAge())
return false;
DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime());
@@ -427,9 +436,6 @@ void Geolocation::clearWatch(int watchID)
void Geolocation::setIsAllowed(bool allowed)
{
- // Protect the Geolocation object from garbage collection during a callback.
- RefPtr<Geolocation> protect(this);
-
// This may be due to either a new position from the service, or a cached
// position.
m_allowGeolocation = allowed ? Yes : No;
@@ -442,9 +448,9 @@ void Geolocation::setIsAllowed(bool allowed)
}
if (!isAllowed()) {
- RefPtr<PositionError> error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage);
+ PositionError* error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage);
error->setIsFatal(true);
- handleError(error.get());
+ handleError(error);
m_requestsAwaitingCachedPosition.clear();
return;
}
@@ -460,12 +466,9 @@ void Geolocation::setIsAllowed(bool allowed)
void Geolocation::sendError(GeoNotifierVector& notifiers, PositionError* error)
{
- GeoNotifierVector::const_iterator end = notifiers.end();
- for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it) {
- RefPtr<GeoNotifier> notifier = *it;
-
- notifier->runErrorCallback(error);
- }
+ GeoNotifierVector::const_iterator end = notifiers.end();
+ for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it)
+ (*it)->runErrorCallback(error);
}
void Geolocation::sendPosition(GeoNotifierVector& notifiers, Geoposition* position)
@@ -585,14 +588,14 @@ void Geolocation::requestPermission()
if (m_allowGeolocation > Unknown)
return;
- Page* page = this->page();
- if (!page)
+ LocalFrame* frame = this->frame();
+ if (!frame)
return;
m_allowGeolocation = InProgress;
// Ask the embedder: it maintains the geolocation challenge policy itself.
- GeolocationController::from(page)->requestPermission(this);
+ GeolocationController::from(frame)->requestPermission(this);
}
void Geolocation::makeSuccessCallbacks()
@@ -635,27 +638,26 @@ void Geolocation::positionChanged()
void Geolocation::setError(GeolocationError* error)
{
- RefPtr<PositionError> positionError = createPositionError(error);
- handleError(positionError.get());
+ handleError(createPositionError(error));
}
bool Geolocation::startUpdating(GeoNotifier* notifier)
{
- Page* page = this->page();
- if (!page)
+ LocalFrame* frame = this->frame();
+ if (!frame)
return false;
- GeolocationController::from(page)->addObserver(this, notifier->options()->enableHighAccuracy());
+ GeolocationController::from(frame)->addObserver(this, notifier->options()->enableHighAccuracy());
return true;
}
void Geolocation::stopUpdating()
{
- Page* page = this->page();
- if (!page)
+ LocalFrame* frame = this->frame();
+ if (!frame)
return;
- GeolocationController::from(page)->removeObserver(this);
+ GeolocationController::from(frame)->removeObserver(this);
}
void Geolocation::handlePendingPermissionNotifiers()
@@ -670,7 +672,7 @@ void Geolocation::handlePendingPermissionNotifiers()
// start all pending notification requests as permission granted.
// The notifier is always ref'ed by m_oneShots or m_watchers.
if (startUpdating(notifier))
- notifier->startTimerIfNeeded();
+ notifier->startTimer();
else
notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
} else {
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.h b/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.h
index 4f8aed2daa7..a1779fbb383 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.h
@@ -35,34 +35,37 @@
#include "modules/geolocation/PositionErrorCallback.h"
#include "modules/geolocation/PositionOptions.h"
#include "platform/Timer.h"
+#include "platform/heap/Handle.h"
namespace WebCore {
class Document;
-class Frame;
+class LocalFrame;
class GeolocationController;
class GeolocationError;
class GeolocationPosition;
-class Page;
class ExecutionContext;
-class Geolocation : public ScriptWrappable, public RefCounted<Geolocation>, public ActiveDOMObject
-{
+class Geolocation FINAL
+ : public GarbageCollectedFinalized<Geolocation>
+ , public ScriptWrappable
+ , public ActiveDOMObject {
public:
- static PassRefPtr<Geolocation> create(ExecutionContext*);
- ~Geolocation();
+ static Geolocation* create(ExecutionContext*);
+ virtual ~Geolocation();
+ void trace(Visitor*);
virtual void stop() OVERRIDE;
Document* document() const;
- Frame* frame() const;
+ LocalFrame* frame() const;
// Creates a oneshot and attempts to obtain a position that meets the
// constraints of the options.
- void getCurrentPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>);
+ void getCurrentPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PositionOptions*);
// Creates a watcher that will be notified whenever a new position is
// available that meets the constraints of the options.
- int watchPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>);
+ int watchPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PositionOptions*);
// Removes all references to the watcher, it will not be updated again.
void clearWatch(int watchID);
@@ -86,21 +89,23 @@ private:
explicit Geolocation(ExecutionContext*);
- Page* page() const;
-
// Holds the success and error callbacks and the options that were provided
// when a oneshot or watcher were created. Also, if specified in the
// options, manages a timer to limit the time to wait for the system to
// obtain a position.
- class GeoNotifier : public RefCounted<GeoNotifier> {
+ class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> {
public:
- static PassRefPtr<GeoNotifier> create(Geolocation* geolocation, PassOwnPtr<PositionCallback> positionCallback, PassOwnPtr<PositionErrorCallback> positionErrorCallback, PassRefPtr<PositionOptions> options) { return adoptRef(new GeoNotifier(geolocation, positionCallback, positionErrorCallback, options)); }
+ static GeoNotifier* create(Geolocation* geolocation, PassOwnPtr<PositionCallback> positionCallback, PassOwnPtr<PositionErrorCallback> positionErrorCallback, PositionOptions* options)
+ {
+ return new GeoNotifier(geolocation, positionCallback, positionErrorCallback, options);
+ }
+ void trace(Visitor*);
PositionOptions* options() const { return m_options.get(); };
// Sets the given error as the fatal error if there isn't one yet.
// Starts the timer with an interval of 0.
- void setFatalError(PassRefPtr<PositionError>);
+ void setFatalError(PositionError*);
bool useCachedPosition() const { return m_useCachedPosition; }
@@ -111,9 +116,7 @@ private:
void runSuccessCallback(Geoposition*);
void runErrorCallback(PositionError*);
- // Starts the timer if a timeout was specified on the options.
- void startTimerIfNeeded();
-
+ void startTimer();
void stopTimer();
// Runs the error callback if there is a fatal error. Otherwise, if a
@@ -121,26 +124,26 @@ private:
// Otherwise, the notifier has expired, and its error callback is run.
void timerFired(Timer<GeoNotifier>*);
- bool hasZeroTimeout() const;
-
private:
- GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>);
+ GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PositionOptions*);
- RefPtr<Geolocation> m_geolocation;
+ Member<Geolocation> m_geolocation;
OwnPtr<PositionCallback> m_successCallback;
OwnPtr<PositionErrorCallback> m_errorCallback;
- RefPtr<PositionOptions> m_options;
+ Member<PositionOptions> m_options;
Timer<GeoNotifier> m_timer;
- RefPtr<PositionError> m_fatalError;
+ Member<PositionError> m_fatalError;
bool m_useCachedPosition;
};
- typedef Vector<RefPtr<GeoNotifier> > GeoNotifierVector;
- typedef HashSet<RefPtr<GeoNotifier> > GeoNotifierSet;
+ typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector;
+ typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet;
class Watchers {
+ DISALLOW_ALLOCATION();
public:
- bool add(int id, PassRefPtr<GeoNotifier>);
+ void trace(Visitor*);
+ bool add(int id, GeoNotifier*);
GeoNotifier* find(int id);
void remove(int id);
void remove(GeoNotifier*);
@@ -149,8 +152,8 @@ private:
bool isEmpty() const;
void getNotifiersVector(GeoNotifierVector&) const;
private:
- typedef HashMap<int, RefPtr<GeoNotifier> > IdToNotifierMap;
- typedef HashMap<RefPtr<GeoNotifier>, int> NotifierToIdMap;
+ typedef HeapHashMap<int, Member<GeoNotifier> > IdToNotifierMap;
+ typedef HeapHashMap<Member<GeoNotifier>, int> NotifierToIdMap;
IdToNotifierMap m_idToNotifierMap;
NotifierToIdMap m_notifierToIdMap;
};
@@ -226,7 +229,7 @@ private:
GeoNotifierSet m_oneShots;
Watchers m_watchers;
GeoNotifierSet m_pendingForPermissionNotifiers;
- RefPtr<Geoposition> m_lastPosition;
+ Member<Geoposition> m_lastPosition;
enum {
Unknown,
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.idl b/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.idl
index b8fde66b7bb..ca1b5a5e61d 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.idl
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Geolocation.idl
@@ -25,15 +25,18 @@
// http://www.w3.org/TR/geolocation-API/#geolocation_interface
[
- NoInterfaceObject
+ GarbageCollected,
+ NoInterfaceObject,
] interface Geolocation {
- [Custom, PerWorldBindings, ActivityLogging=ForIsolatedWorlds] void getCurrentPosition(PositionCallback successCallback,
+ // FIXME: should be: PositionOptions options: need PositionOptions.idl and dictionary http:/crbug.com/321462
+ [Custom, LogActivity] void getCurrentPosition(PositionCallback successCallback,
optional PositionErrorCallback errorCallback,
- optional PositionOptions options);
+ optional object options);
- [Custom, PerWorldBindings, ActivityLogging=ForIsolatedWorlds] long watchPosition(PositionCallback successCallback,
+ // FIXME: should be: PositionOptions options: need PositionOptions.idl and dictionary http:/crbug.com/321462
+ [Custom, LogActivity] long watchPosition(PositionCallback successCallback,
optional PositionErrorCallback errorCallback,
- optional PositionOptions options);
+ optional object options);
void clearWatch(long watchID);
};
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationClient.h b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationClient.h
index d8938710555..c4a90dac8ac 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationClient.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationClient.h
@@ -29,8 +29,9 @@
namespace WebCore {
class Geolocation;
+class GeolocationController;
class GeolocationPosition;
-class Page;
+class LocalFrame;
class GeolocationClient {
public:
@@ -38,23 +39,20 @@ public:
virtual void startUpdating() = 0;
virtual void stopUpdating() = 0;
- // FIXME: The V2 Geolocation specification proposes that this property is
- // renamed. See http://www.w3.org/2008/geolocation/track/issues/6
- // We should update WebKit to reflect this if and when the V2 specification
- // is published.
virtual void setEnableHighAccuracy(bool) = 0;
virtual GeolocationPosition* lastPosition() = 0;
virtual void requestPermission(Geolocation*) = 0;
virtual void cancelPermissionRequest(Geolocation*) = 0;
- void provideGeolocationTo(Page*, GeolocationClient*);
+ virtual void controllerForTestAdded(GeolocationController*) { }
+ virtual void controllerForTestRemoved(GeolocationController*) { }
protected:
virtual ~GeolocationClient() { }
};
-void provideGeolocationTo(Page*, GeolocationClient*);
+void provideGeolocationTo(LocalFrame&, GeolocationClient*);
} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.cpp b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.cpp
index 0c7f0e44480..213bb36efdb 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.cpp
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.cpp
@@ -24,20 +24,44 @@
*/
#include "config.h"
+
#include "modules/geolocation/GeolocationController.h"
-#include "core/inspector/InspectorInstrumentation.h"
+#include "core/inspector/InspectorController.h"
+#include "core/page/Page.h"
#include "modules/geolocation/GeolocationClient.h"
#include "modules/geolocation/GeolocationError.h"
+#include "modules/geolocation/GeolocationInspectorAgent.h"
#include "modules/geolocation/GeolocationPosition.h"
namespace WebCore {
-GeolocationController::GeolocationController(Page* page, GeolocationClient* client)
- : PageLifecycleObserver(page)
+GeolocationController::GeolocationController(LocalFrame& frame, GeolocationClient* client)
+ : PageLifecycleObserver(frame.page())
, m_client(client)
+ , m_hasClientForTest(false)
, m_isClientUpdating(false)
+ , m_inspectorAgent()
{
+ // FIXME: Once GeolocationInspectorAgent is per frame, there will be a 1:1 relationship between
+ // it and this class. Until then, there's one GeolocationInspectorAgent per page that the main
+ // frame is responsible for creating.
+ if (frame.isMainFrame()) {
+ OwnPtr<GeolocationInspectorAgent> geolocationAgent(GeolocationInspectorAgent::create());
+ m_inspectorAgent = geolocationAgent.get();
+ frame.page()->inspectorController().registerModuleAgent(geolocationAgent.release());
+ } else {
+ m_inspectorAgent = GeolocationController::from(frame.page()->deprecatedLocalMainFrame())->m_inspectorAgent;
+ }
+
+ m_inspectorAgent->AddController(this);
+
+ if (!frame.isMainFrame()) {
+ // internals.setGeolocationClientMock is per page.
+ GeolocationController* mainController = GeolocationController::from(frame.page()->deprecatedLocalMainFrame());
+ if (mainController->hasClientForTest())
+ setClientForTest(mainController->client());
+ }
}
void GeolocationController::startUpdatingIfNeeded()
@@ -59,14 +83,29 @@ void GeolocationController::stopUpdatingIfNeeded()
GeolocationController::~GeolocationController()
{
ASSERT(m_observers.isEmpty());
+ if (page())
+ m_inspectorAgent->RemoveController(this);
+ if (m_hasClientForTest)
+ m_client->controllerForTestRemoved(this);
+}
+
+// FIXME: Oilpan: Once GeolocationClient is on-heap m_client should be a strong
+// pointer and |willBeDestroyed| can potentially be removed from Supplement.
+void GeolocationController::willBeDestroyed()
+{
if (m_client)
m_client->geolocationDestroyed();
}
-PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, GeolocationClient* client)
+void GeolocationController::persistentHostHasBeenDestroyed()
+{
+ observeContext(0);
+}
+
+PassOwnPtrWillBeRawPtr<GeolocationController> GeolocationController::create(LocalFrame& frame, GeolocationClient* client)
{
- return adoptPtr(new GeolocationController(page, client));
+ return adoptPtrWillBeNoop(new GeolocationController(frame, client));
}
void GeolocationController::addObserver(Geolocation* observer, bool enableHighAccuracy)
@@ -116,13 +155,13 @@ void GeolocationController::cancelPermissionRequest(Geolocation* geolocation)
void GeolocationController::positionChanged(GeolocationPosition* position)
{
- position = InspectorInstrumentation::overrideGeolocationPosition(page(), position);
+ position = m_inspectorAgent->overrideGeolocationPosition(position);
if (!position) {
- errorOccurred(GeolocationError::create(GeolocationError::PositionUnavailable, "PositionUnavailable").get());
+ errorOccurred(GeolocationError::create(GeolocationError::PositionUnavailable, "PositionUnavailable"));
return;
}
m_lastPosition = position;
- Vector<RefPtr<Geolocation> > observersVector;
+ HeapVector<Member<Geolocation> > observersVector;
copyToVector(m_observers, observersVector);
for (size_t i = 0; i < observersVector.size(); ++i)
observersVector[i]->positionChanged();
@@ -130,7 +169,7 @@ void GeolocationController::positionChanged(GeolocationPosition* position)
void GeolocationController::errorOccurred(GeolocationError* error)
{
- Vector<RefPtr<Geolocation> > observersVector;
+ HeapVector<Member<Geolocation> > observersVector;
copyToVector(m_observers, observersVector);
for (size_t i = 0; i < observersVector.size(); ++i)
observersVector[i]->setError(error);
@@ -147,6 +186,16 @@ GeolocationPosition* GeolocationController::lastPosition()
return m_client->lastPosition();
}
+void GeolocationController::setClientForTest(GeolocationClient* client)
+{
+ if (m_hasClientForTest)
+ m_client->controllerForTestRemoved(this);
+ m_client = client;
+ m_hasClientForTest = true;
+
+ client->controllerForTestAdded(this);
+}
+
void GeolocationController::pageVisibilityChanged()
{
if (m_observers.isEmpty() || !m_client)
@@ -163,9 +212,17 @@ const char* GeolocationController::supplementName()
return "GeolocationController";
}
-void provideGeolocationTo(Page* page, GeolocationClient* client)
+void GeolocationController::trace(Visitor* visitor)
+{
+ visitor->trace(m_lastPosition);
+ visitor->trace(m_observers);
+ visitor->trace(m_highAccuracyObservers);
+ WillBeHeapSupplement<LocalFrame>::trace(visitor);
+}
+
+void provideGeolocationTo(LocalFrame& frame, GeolocationClient* client)
{
- Supplement<Page>::provideTo(page, GeolocationController::supplementName(), GeolocationController::create(page, client));
+ WillBeHeapSupplement<LocalFrame>::provideTo(frame, GeolocationController::supplementName(), GeolocationController::create(frame, client));
}
} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.h b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.h
index 50eaae892cb..17e5cb8f9f4 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationController.h
@@ -26,26 +26,27 @@
#ifndef GeolocationController_h
#define GeolocationController_h
-#include "core/page/Page.h"
+#include "core/frame/LocalFrame.h"
#include "core/page/PageLifecycleObserver.h"
#include "modules/geolocation/Geolocation.h"
+#include "platform/heap/Handle.h"
#include "wtf/HashSet.h"
#include "wtf/Noncopyable.h"
-#include "wtf/RefPtr.h"
namespace WebCore {
+class GeolocationInspectorAgent;
class GeolocationClient;
class GeolocationError;
class GeolocationPosition;
-class Page;
-class GeolocationController : public Supplement<Page>, public PageLifecycleObserver {
+class GeolocationController FINAL : public NoBaseWillBeGarbageCollectedFinalized<GeolocationController>, public WillBeHeapSupplement<LocalFrame>, public PageLifecycleObserver {
+ WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GeolocationController);
WTF_MAKE_NONCOPYABLE(GeolocationController);
public:
- ~GeolocationController();
+ virtual ~GeolocationController();
- static PassOwnPtr<GeolocationController> create(Page*, GeolocationClient*);
+ static PassOwnPtrWillBeRawPtr<GeolocationController> create(LocalFrame&, GeolocationClient*);
void addObserver(Geolocation*, bool enableHighAccuracy);
void removeObserver(Geolocation*);
@@ -58,26 +59,37 @@ public:
GeolocationPosition* lastPosition();
+ void setClientForTest(GeolocationClient*);
+ bool hasClientForTest() { return m_hasClientForTest; }
+ GeolocationClient* client() { return m_client; }
+
// Inherited from PageLifecycleObserver.
virtual void pageVisibilityChanged() OVERRIDE;
static const char* supplementName();
- static GeolocationController* from(Page* page) { return static_cast<GeolocationController*>(Supplement<Page>::from(page, supplementName())); }
+ static GeolocationController* from(LocalFrame* frame) { return static_cast<GeolocationController*>(WillBeHeapSupplement<LocalFrame>::from(frame, supplementName())); }
+
+ // Inherited from Supplement.
+ virtual void trace(Visitor*) OVERRIDE;
+ virtual void willBeDestroyed() OVERRIDE;
+ virtual void persistentHostHasBeenDestroyed() OVERRIDE;
private:
- GeolocationController(Page*, GeolocationClient*);
+ GeolocationController(LocalFrame&, GeolocationClient*);
void startUpdatingIfNeeded();
void stopUpdatingIfNeeded();
GeolocationClient* m_client;
+ bool m_hasClientForTest;
- RefPtr<GeolocationPosition> m_lastPosition;
- typedef HashSet<RefPtr<Geolocation> > ObserversSet;
+ PersistentWillBeMember<GeolocationPosition> m_lastPosition;
+ typedef PersistentHeapHashSetWillBeHeapHashSet<Member<Geolocation> > ObserversSet;
// All observers; both those requesting high accuracy and those not.
ObserversSet m_observers;
ObserversSet m_highAccuracyObservers;
bool m_isClientUpdating;
+ GeolocationInspectorAgent* m_inspectorAgent;
};
} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationError.h b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationError.h
index 23ecb71aa17..f2997f119db 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationError.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationError.h
@@ -26,21 +26,22 @@
#ifndef GeolocationError_h
#define GeolocationError_h
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefCounted.h"
-#include "wtf/RefPtr.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
-class GeolocationError : public RefCounted<GeolocationError> {
+class GeolocationError : public GarbageCollectedFinalized<GeolocationError> {
public:
enum ErrorCode {
PermissionDenied,
PositionUnavailable
};
- static PassRefPtr<GeolocationError> create(ErrorCode code, const String& message) { return adoptRef(new GeolocationError(code, message)); }
+ static GeolocationError* create(ErrorCode code, const String& message)
+ {
+ return new GeolocationError(code, message);
+ }
+ void trace(Visitor*) { }
ErrorCode code() const { return m_code; }
const String& message() const { return m_message; }
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.cpp b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.cpp
new file mode 100644
index 00000000000..049d821e010
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "modules/geolocation/GeolocationInspectorAgent.h"
+
+#include "modules/geolocation/GeolocationController.h"
+
+namespace WebCore {
+
+PassOwnPtr<GeolocationInspectorAgent> GeolocationInspectorAgent::create()
+{
+ return adoptPtr(new GeolocationInspectorAgent());
+}
+
+GeolocationInspectorAgent::~GeolocationInspectorAgent()
+{
+}
+
+GeolocationInspectorAgent::GeolocationInspectorAgent()
+ : InspectorBaseAgent<GeolocationInspectorAgent>("Geolocation")
+ , m_geolocationOverridden(false)
+{
+}
+
+void GeolocationInspectorAgent::setGeolocationOverride(ErrorString* error, const double* latitude, const double* longitude, const double* accuracy)
+{
+ GeolocationPosition* position = (*m_controllers.begin())->lastPosition();
+ if (!m_geolocationOverridden && position)
+ m_platformGeolocationPosition = position;
+
+ m_geolocationOverridden = true;
+ if (latitude && longitude && accuracy)
+ m_geolocationPosition = GeolocationPosition::create(currentTime(), *latitude, *longitude, *accuracy);
+ else
+ m_geolocationPosition.clear();
+
+ for (GeolocationControllers::iterator it = m_controllers.begin(); it != m_controllers.end(); ++it)
+ (*it)->positionChanged(0); // Kick location update.
+}
+
+void GeolocationInspectorAgent::clearGeolocationOverride(ErrorString*)
+{
+ if (!m_geolocationOverridden)
+ return;
+ m_geolocationOverridden = false;
+ m_geolocationPosition.clear();
+
+ if (GeolocationPosition* platformPosition = m_platformGeolocationPosition.get()) {
+ for (GeolocationControllers::iterator it = m_controllers.begin(); it != m_controllers.end(); ++it)
+ (*it)->positionChanged(platformPosition);
+ }
+}
+
+GeolocationPosition* GeolocationInspectorAgent::overrideGeolocationPosition(GeolocationPosition* position)
+{
+ if (m_geolocationOverridden) {
+ if (position)
+ m_platformGeolocationPosition = position;
+ return m_geolocationPosition.get();
+ }
+ return position;
+}
+
+void GeolocationInspectorAgent::AddController(GeolocationController* controller)
+{
+ m_controllers.add(controller);
+}
+
+void GeolocationInspectorAgent::RemoveController(GeolocationController* controller)
+{
+ m_controllers.remove(controller);
+}
+
+} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.h b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.h
new file mode 100644
index 00000000000..429ceae6167
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationInspectorAgent.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationInspectorAgent_h
+#define GeolocationInspectorAgent_h
+
+
+#include "core/inspector/InspectorBaseAgent.h"
+#include "modules/geolocation/GeolocationPosition.h"
+#include "wtf/HashSet.h"
+#include "wtf/text/WTFString.h"
+
+namespace WebCore {
+
+class GeolocationController;
+
+typedef String ErrorString;
+
+class GeolocationInspectorAgent FINAL : public InspectorBaseAgent<GeolocationInspectorAgent>, public InspectorBackendDispatcher::GeolocationCommandHandler {
+ WTF_MAKE_NONCOPYABLE(GeolocationInspectorAgent);
+public:
+ static PassOwnPtr<GeolocationInspectorAgent> create();
+ virtual ~GeolocationInspectorAgent();
+
+ // Protocol methods.
+ virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*) OVERRIDE;
+ virtual void clearGeolocationOverride(ErrorString*) OVERRIDE;
+
+ // Instrumentation method.
+ GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*);
+
+ void AddController(GeolocationController*);
+ void RemoveController(GeolocationController*);
+
+private:
+ GeolocationInspectorAgent();
+ typedef WillBeHeapHashSet<RawPtrWillBeMember<GeolocationController> > GeolocationControllers;
+ WillBePersistentHeapHashSet<RawPtrWillBeMember<GeolocationController> > m_controllers;
+ bool m_geolocationOverridden;
+ Persistent<GeolocationPosition> m_geolocationPosition;
+ Persistent<GeolocationPosition> m_platformGeolocationPosition;
+};
+
+
+} // namespace WebCore
+
+
+#endif // !defined(GeolocationInspectorAgent_h)
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationPosition.h b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationPosition.h
index 0b0b7da4e4d..11733df659d 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationPosition.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/GeolocationPosition.h
@@ -26,17 +26,21 @@
#ifndef GeolocationPosition_h
#define GeolocationPosition_h
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefCounted.h"
-#include "wtf/RefPtr.h"
+#include "platform/heap/Handle.h"
namespace WebCore {
-class GeolocationPosition : public RefCounted<GeolocationPosition> {
+class GeolocationPosition : public GarbageCollected<GeolocationPosition> {
public:
- static PassRefPtr<GeolocationPosition> create(double timestamp, double latitude, double longitude, double accuracy) { return adoptRef(new GeolocationPosition(timestamp, latitude, longitude, accuracy)); }
-
- static PassRefPtr<GeolocationPosition> create(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed) { return adoptRef(new GeolocationPosition(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed)); }
+ static GeolocationPosition* create(double timestamp, double latitude, double longitude, double accuracy)
+ {
+ return new GeolocationPosition(timestamp, latitude, longitude, accuracy);
+ }
+ static GeolocationPosition* create(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
+ {
+ return new GeolocationPosition(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
+ }
+ void trace(Visitor*) { }
double timestamp() const { return m_timestamp; }
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.h b/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.h
index 74a5f3dcd51..0a3bd266426 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.h
@@ -27,30 +27,29 @@
#define Geoposition_h
#include "bindings/v8/ScriptWrappable.h"
-#include "core/events/Event.h"
+#include "modules/EventModules.h"
#include "modules/geolocation/Coordinates.h"
-#include "wtf/RefCounted.h"
-#include "wtf/text/WTFString.h"
+#include "platform/heap/Handle.h"
namespace WebCore {
-class Geoposition : public RefCounted<Geoposition>, public ScriptWrappable {
+class Geoposition : public GarbageCollectedFinalized<Geoposition>, public ScriptWrappable {
public:
- static PassRefPtr<Geoposition> create(PassRefPtr<Coordinates> coordinates, DOMTimeStamp timestamp)
+ static Geoposition* create(Coordinates* coordinates, DOMTimeStamp timestamp)
{
- return adoptRef(new Geoposition(coordinates, timestamp));
+ return new Geoposition(coordinates, timestamp);
}
- PassRefPtr<Geoposition> isolatedCopy() const
+ void trace(Visitor* visitor)
{
- return Geoposition::create(m_coordinates->isolatedCopy(), m_timestamp);
+ visitor->trace(m_coordinates);
}
DOMTimeStamp timestamp() const { return m_timestamp; }
Coordinates* coords() const { return m_coordinates.get(); }
private:
- Geoposition(PassRefPtr<Coordinates> coordinates, DOMTimeStamp timestamp)
+ Geoposition(Coordinates* coordinates, DOMTimeStamp timestamp)
: m_coordinates(coordinates)
, m_timestamp(timestamp)
{
@@ -58,7 +57,7 @@ private:
ScriptWrappable::init(this);
}
- RefPtr<Coordinates> m_coordinates;
+ Member<Coordinates> m_coordinates;
DOMTimeStamp m_timestamp;
};
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.idl b/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.idl
index 1b5e3477064..7d5c597e29e 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.idl
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/Geoposition.idl
@@ -24,6 +24,7 @@
*/
[
+ GarbageCollected,
NoInterfaceObject
] interface Geoposition {
readonly attribute Coordinates coords;
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.cpp b/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.cpp
index 72429741aa9..b30bc7480e8 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.cpp
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.cpp
@@ -24,13 +24,13 @@
#include "modules/geolocation/NavigatorGeolocation.h"
#include "core/dom/Document.h"
-#include "core/frame/Frame.h"
+#include "core/frame/LocalFrame.h"
#include "core/frame/Navigator.h"
#include "modules/geolocation/Geolocation.h"
namespace WebCore {
-NavigatorGeolocation::NavigatorGeolocation(Frame* frame)
+NavigatorGeolocation::NavigatorGeolocation(LocalFrame* frame)
: DOMWindowProperty(frame)
{
}
@@ -44,19 +44,19 @@ const char* NavigatorGeolocation::supplementName()
return "NavigatorGeolocation";
}
-NavigatorGeolocation* NavigatorGeolocation::from(Navigator* navigator)
+NavigatorGeolocation& NavigatorGeolocation::from(Navigator& navigator)
{
- NavigatorGeolocation* supplement = static_cast<NavigatorGeolocation*>(Supplement<Navigator>::from(navigator, supplementName()));
+ NavigatorGeolocation* supplement = static_cast<NavigatorGeolocation*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
if (!supplement) {
- supplement = new NavigatorGeolocation(navigator->frame());
- provideTo(navigator, supplementName(), adoptPtr(supplement));
+ supplement = new NavigatorGeolocation(navigator.frame());
+ provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
}
- return supplement;
+ return *supplement;
}
-Geolocation* NavigatorGeolocation::geolocation(Navigator* navigator)
+Geolocation* NavigatorGeolocation::geolocation(Navigator& navigator)
{
- return NavigatorGeolocation::from(navigator)->geolocation();
+ return NavigatorGeolocation::from(navigator).geolocation();
}
Geolocation* NavigatorGeolocation::geolocation() const
@@ -66,4 +66,10 @@ Geolocation* NavigatorGeolocation::geolocation() const
return m_geolocation.get();
}
+void NavigatorGeolocation::trace(Visitor* visitor)
+{
+ visitor->trace(m_geolocation);
+ WillBeHeapSupplement<Navigator>::trace(visitor);
+}
+
} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.h b/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.h
index 37c37e55189..df8fd9a22f0 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.h
@@ -22,26 +22,30 @@
#include "core/frame/DOMWindowProperty.h"
#include "platform/Supplementable.h"
+#include "platform/heap/Handle.h"
namespace WebCore {
-class Frame;
+class LocalFrame;
class Geolocation;
class Navigator;
-class NavigatorGeolocation : public Supplement<Navigator>, public DOMWindowProperty {
+class NavigatorGeolocation FINAL : public NoBaseWillBeGarbageCollectedFinalized<NavigatorGeolocation>, public WillBeHeapSupplement<Navigator>, public DOMWindowProperty {
+ WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NavigatorGeolocation);
public:
virtual ~NavigatorGeolocation();
- static NavigatorGeolocation* from(Navigator*);
+ static NavigatorGeolocation& from(Navigator&);
- static Geolocation* geolocation(Navigator*);
+ static Geolocation* geolocation(Navigator&);
Geolocation* geolocation() const;
+ void trace(Visitor*);
+
private:
- NavigatorGeolocation(Frame*);
+ NavigatorGeolocation(LocalFrame*);
static const char* supplementName();
- mutable RefPtr<Geolocation> m_geolocation;
+ mutable PersistentWillBeMember<Geolocation> m_geolocation;
};
} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.idl b/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.idl
index 4de885ca811..9b96fd709da 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.idl
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/NavigatorGeolocation.idl
@@ -18,6 +18,5 @@
*/
partial interface Navigator {
- [RuntimeEnabled=Geolocation] readonly attribute Geolocation geolocation;
+ readonly attribute Geolocation geolocation;
};
-
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.h b/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.h
index d19b330d8d6..5be3f08b104 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.h
@@ -27,13 +27,12 @@
#define PositionError_h
#include "bindings/v8/ScriptWrappable.h"
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefCounted.h"
+#include "platform/heap/Handle.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
-class PositionError : public RefCounted<PositionError>, public ScriptWrappable {
+class PositionError : public GarbageCollectedFinalized<PositionError>, public ScriptWrappable {
public:
enum ErrorCode {
PERMISSION_DENIED = 1,
@@ -41,7 +40,8 @@ public:
TIMEOUT = 3
};
- static PassRefPtr<PositionError> create(ErrorCode code, const String& message) { return adoptRef(new PositionError(code, message)); }
+ static PositionError* create(ErrorCode code, const String& message) { return new PositionError(code, message); }
+ void trace(Visitor*) { }
ErrorCode code() const { return m_code; }
const String& message() const { return m_message; }
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.idl b/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.idl
index 2a673c0864c..b4a7f8363db 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.idl
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/PositionError.idl
@@ -24,6 +24,7 @@
*/
[
+ GarbageCollected,
NoInterfaceObject
] interface PositionError {
readonly attribute unsigned short code;
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/PositionOptions.h b/chromium/third_party/WebKit/Source/modules/geolocation/PositionOptions.h
index 1b1e48e661f..d3d9ffc8a9d 100644
--- a/chromium/third_party/WebKit/Source/modules/geolocation/PositionOptions.h
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/PositionOptions.h
@@ -26,56 +26,48 @@
#ifndef PositionOptions_h
#define PositionOptions_h
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefCounted.h"
+#include "platform/heap/Handle.h"
+#include <limits.h>
namespace WebCore {
-class PositionOptions : public RefCounted<PositionOptions> {
+class PositionOptions : public GarbageCollected<PositionOptions> {
public:
- static PassRefPtr<PositionOptions> create() { return adoptRef(new PositionOptions()); }
+ static PositionOptions* create() { return new PositionOptions(); }
+ void trace(Visitor*) { }
bool enableHighAccuracy() const { return m_highAccuracy; }
void setEnableHighAccuracy(bool enable) { m_highAccuracy = enable; }
- bool hasTimeout() const { return m_hasTimeout; }
- int timeout() const
+ unsigned timeout() const
{
- ASSERT(hasTimeout());
return m_timeout;
}
- void setTimeout(int timeout)
+ void setTimeout(unsigned timeout)
{
- ASSERT(timeout >= 0);
- m_hasTimeout = true;
m_timeout = timeout;
}
- bool hasMaximumAge() const { return m_hasMaximumAge; }
- int maximumAge() const
+ unsigned maximumAge() const
{
- ASSERT(hasMaximumAge());
return m_maximumAge;
}
- void clearMaximumAge() { m_hasMaximumAge = false; }
- void setMaximumAge(int age)
+ void setMaximumAge(unsigned age)
{
- ASSERT(age >= 0);
- m_hasMaximumAge = true;
m_maximumAge = age;
}
private:
PositionOptions()
: m_highAccuracy(false)
- , m_hasTimeout(false)
+ , m_maximumAge(0)
+ , m_timeout(std::numeric_limits<unsigned>::max())
+
{
setMaximumAge(0);
}
bool m_highAccuracy;
- bool m_hasTimeout;
- int m_timeout;
- bool m_hasMaximumAge;
- int m_maximumAge;
+ unsigned m_maximumAge;
+ unsigned m_timeout;
};
} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.cpp b/chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.cpp
new file mode 100644
index 00000000000..b82d2a94e82
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.cpp
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GeolocationClientMock.h"
+
+#include "modules/geolocation/GeolocationController.h"
+#include "modules/geolocation/GeolocationError.h"
+#include "modules/geolocation/GeolocationPosition.h"
+
+namespace WebCore {
+
+GeolocationClientMock::GeolocationClientMock()
+ : m_hasError(false)
+ , m_controllerTimer(this, &GeolocationClientMock::controllerTimerFired)
+ , m_permissionTimer(this, &GeolocationClientMock::permissionTimerFired)
+ , m_isActive(false)
+ , m_permissionState(PermissionStateUnset)
+{
+}
+
+GeolocationClientMock::~GeolocationClientMock()
+{
+ ASSERT(!m_isActive);
+}
+
+void GeolocationClientMock::setPosition(GeolocationPosition* position)
+{
+ m_lastPosition = position;
+ clearError();
+ asyncUpdateController();
+}
+
+void GeolocationClientMock::setPositionUnavailableError(const String& errorMessage)
+{
+ m_hasError = true;
+ m_errorMessage = errorMessage;
+ m_lastPosition = nullptr;
+ asyncUpdateController();
+}
+
+void GeolocationClientMock::setPermission(bool allowed)
+{
+ m_permissionState = allowed ? PermissionStateAllowed : PermissionStateDenied;
+ asyncUpdatePermission();
+}
+
+int GeolocationClientMock::numberOfPendingPermissionRequests() const
+{
+ return m_pendingPermissions.size();
+}
+
+void GeolocationClientMock::requestPermission(Geolocation* geolocation)
+{
+ m_pendingPermissions.add(geolocation);
+ if (m_permissionState != PermissionStateUnset)
+ asyncUpdatePermission();
+}
+
+void GeolocationClientMock::cancelPermissionRequest(Geolocation* geolocation)
+{
+ // Called from Geolocation::disconnectFrame() in response to LocalFrame destruction.
+ m_pendingPermissions.remove(geolocation);
+ if (m_pendingPermissions.isEmpty() && m_permissionTimer.isActive())
+ m_permissionTimer.stop();
+}
+
+void GeolocationClientMock::controllerForTestAdded(GeolocationController* controller)
+{
+ m_controllers.add(controller);
+}
+
+void GeolocationClientMock::controllerForTestRemoved(GeolocationController* controller)
+{
+ m_controllers.remove(controller);
+}
+
+void GeolocationClientMock::asyncUpdatePermission()
+{
+ ASSERT(m_permissionState != PermissionStateUnset);
+ if (!m_permissionTimer.isActive())
+ m_permissionTimer.startOneShot(0, FROM_HERE);
+}
+
+void GeolocationClientMock::permissionTimerFired(Timer<GeolocationClientMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_permissionTimer);
+ ASSERT(m_permissionState != PermissionStateUnset);
+ bool allowed = m_permissionState == PermissionStateAllowed;
+ GeolocationSet::iterator end = m_pendingPermissions.end();
+
+ // Once permission has been set (or denied) on a Geolocation object, there can be
+ // no further requests for permission to the mock. Consequently the callbacks
+ // which fire synchronously from Geolocation::setIsAllowed() cannot reentrantly modify
+ // m_pendingPermissions.
+ for (GeolocationSet::iterator it = m_pendingPermissions.begin(); it != end; ++it)
+ (*it)->setIsAllowed(allowed);
+ m_pendingPermissions.clear();
+}
+
+void GeolocationClientMock::geolocationDestroyed()
+{
+ ASSERT(!m_isActive);
+}
+
+void GeolocationClientMock::startUpdating()
+{
+ ASSERT(!m_isActive);
+ m_isActive = true;
+ asyncUpdateController();
+}
+
+void GeolocationClientMock::stopUpdating()
+{
+ ASSERT(m_isActive);
+ m_isActive = false;
+ m_controllerTimer.stop();
+}
+
+void GeolocationClientMock::setEnableHighAccuracy(bool)
+{
+ // FIXME: We need to add some tests regarding "high accuracy" mode.
+ // See https://bugs.webkit.org/show_bug.cgi?id=49438
+}
+
+GeolocationPosition* GeolocationClientMock::lastPosition()
+{
+ return m_lastPosition.get();
+}
+
+void GeolocationClientMock::asyncUpdateController()
+{
+ if (m_isActive && !m_controllerTimer.isActive())
+ m_controllerTimer.startOneShot(0, FROM_HERE);
+}
+
+void GeolocationClientMock::controllerTimerFired(Timer<GeolocationClientMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_controllerTimer);
+
+ // Make a copy of the set of controllers since it might be modified while iterating.
+ GeolocationControllers controllers = m_controllers;
+ if (m_lastPosition.get()) {
+ ASSERT(!m_hasError);
+ for (GeolocationControllers::iterator it = controllers.begin(); it != controllers.end(); ++it)
+ (*it)->positionChanged(m_lastPosition.get());
+ } else if (m_hasError) {
+ for (GeolocationControllers::iterator it = controllers.begin(); it != controllers.end(); ++it)
+ (*it)->errorOccurred(GeolocationError::create(GeolocationError::PositionUnavailable, m_errorMessage));
+ }
+}
+
+void GeolocationClientMock::clearError()
+{
+ m_hasError = false;
+ m_errorMessage = String();
+}
+
+} // WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.h b/chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.h
new file mode 100644
index 00000000000..b75f3cc05b4
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/testing/GeolocationClientMock.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationClientMock_h
+#define GeolocationClientMock_h
+
+#include "modules/geolocation/GeolocationClient.h"
+#include "platform/Timer.h"
+#include "platform/heap/Handle.h"
+#include "wtf/HashSet.h"
+#include "wtf/text/WTFString.h"
+
+namespace WebCore {
+
+class GeolocationController;
+class GeolocationPosition;
+
+// Provides a mock object for the geolocation client.
+class GeolocationClientMock : public GeolocationClient {
+public:
+ GeolocationClientMock();
+ virtual ~GeolocationClientMock();
+
+ void setPosition(GeolocationPosition*);
+ void setPositionUnavailableError(const String& errorMessage);
+ void setPermission(bool allowed);
+ int numberOfPendingPermissionRequests() const;
+
+ // GeolocationClient
+ virtual void geolocationDestroyed() OVERRIDE;
+ virtual void startUpdating() OVERRIDE;
+ virtual void stopUpdating() OVERRIDE;
+ virtual void setEnableHighAccuracy(bool) OVERRIDE;
+ virtual GeolocationPosition* lastPosition() OVERRIDE;
+ virtual void requestPermission(Geolocation*) OVERRIDE;
+ virtual void cancelPermissionRequest(Geolocation*) OVERRIDE;
+ void controllerForTestAdded(GeolocationController*) OVERRIDE;
+ void controllerForTestRemoved(GeolocationController*) OVERRIDE;
+
+private:
+ void asyncUpdateController();
+ void controllerTimerFired(Timer<GeolocationClientMock>*);
+
+ void asyncUpdatePermission();
+ void permissionTimerFired(Timer<GeolocationClientMock>*);
+
+ void clearError();
+
+ typedef WillBeHeapHashSet<RawPtrWillBeMember<GeolocationController> > GeolocationControllers;
+ WillBePersistentHeapHashSet<RawPtrWillBeMember<GeolocationController> > m_controllers;
+ Persistent<GeolocationPosition> m_lastPosition;
+ bool m_hasError;
+ String m_errorMessage;
+ Timer<GeolocationClientMock> m_controllerTimer;
+ Timer<GeolocationClientMock> m_permissionTimer;
+ bool m_isActive;
+
+ enum PermissionState {
+ PermissionStateUnset,
+ PermissionStateAllowed,
+ PermissionStateDenied
+ };
+
+ PermissionState m_permissionState;
+ typedef HeapHashSet<Member<Geolocation> > GeolocationSet;
+ PersistentHeapHashSet<Member<Geolocation> > m_pendingPermissions;
+};
+
+}
+
+#endif
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.cpp b/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.cpp
new file mode 100644
index 00000000000..a349b47576b
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InternalsGeolocation.h"
+
+#include "core/dom/Document.h"
+#include "core/page/Page.h"
+#include "core/testing/Internals.h"
+#include "modules/geolocation/GeolocationController.h"
+#include "modules/geolocation/GeolocationError.h"
+#include "modules/geolocation/GeolocationPosition.h"
+#include "modules/geolocation/testing/GeolocationClientMock.h"
+#include "wtf/CurrentTime.h"
+
+namespace WebCore {
+
+void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* document)
+{
+ ASSERT(document && document->frame());
+ GeolocationClientMock* client = new GeolocationClientMock();
+
+ for (Frame* childFrame = document->page()->mainFrame(); childFrame; childFrame = childFrame->tree().traverseNext()) {
+ if (childFrame->isLocalFrame())
+ GeolocationController::from(toLocalFrame(childFrame))->setClientForTest(client);
+ }
+}
+
+void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document, double latitude, double longitude, double accuracy)
+{
+ ASSERT(document && document->frame());
+ GeolocationClientMock* client = geolocationClient(document);
+ if (!client)
+ return;
+ client->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy));
+}
+
+void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Document* document, const String& message)
+{
+ ASSERT(document && document->frame());
+ GeolocationClientMock* client = geolocationClient(document);
+ if (!client)
+ return;
+ client->setPositionUnavailableError(message);
+}
+
+void InternalsGeolocation::setGeolocationPermission(Internals&, Document* document, bool allowed)
+{
+ ASSERT(document && document->frame());
+ GeolocationClientMock* client = geolocationClient(document);
+ if (!client)
+ return;
+ client->setPermission(allowed);
+}
+
+int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals&, Document* document)
+{
+ ASSERT(document && document->frame());
+ GeolocationClientMock* client = geolocationClient(document);
+ if (!client)
+ return -1;
+ return client->numberOfPendingPermissionRequests();
+}
+
+GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* document)
+{
+ GeolocationController* controller = GeolocationController::from(document->frame());
+ if (!controller->hasClientForTest())
+ return 0;
+ return static_cast<GeolocationClientMock*>(controller->client());
+}
+
+} // namespace WebCore
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.h b/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.h
new file mode 100644
index 00000000000..c76656758e2
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InternalsGeolocation_h
+#define InternalsGeolocation_h
+
+#include "platform/Timer.h"
+#include "wtf/text/WTFString.h"
+
+namespace WebCore {
+
+class Document;
+class GeolocationClientMock;
+class Internals;
+
+class InternalsGeolocation {
+public:
+ static void setGeolocationClientMock(Internals&, Document*);
+ static void setGeolocationPosition(Internals&, Document*, double latitude, double longitude, double accuracy);
+ static void setGeolocationPositionUnavailableError(Internals&, Document*, const String& message);
+ static void setGeolocationPermission(Internals&, Document*, bool allowed);
+ static int numberOfPendingGeolocationPermissionRequests(Internals&, Document*);
+
+private:
+ static GeolocationClientMock* geolocationClient(Document*);
+};
+
+} // namespace WebCore
+
+#endif // InternalsGeolocation_h
diff --git a/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.idl b/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.idl
new file mode 100644
index 00000000000..ac6b2d34c1e
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/geolocation/testing/InternalsGeolocation.idl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+partial interface Internals {
+ void setGeolocationClientMock(Document document);
+ void setGeolocationPosition(Document document, double latitude, double longitude, double accuracy);
+ void setGeolocationPositionUnavailableError(Document document, DOMString message);
+ void setGeolocationPermission(Document document, boolean allowed);
+ long numberOfPendingGeolocationPermissionRequests(Document document);
+};