Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / geolocation / Geolocation.cpp
index 187a12a..330a663 100644 (file)
@@ -42,18 +42,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 PassRefPtrWillBeRawPtr<Geoposition> createGeoposition(GeolocationPosition* position)
 {
     if (!position)
         return 0;
 
-    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());
+    RefPtrWillBeRawPtr<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()));
 }
 
-static PassRefPtr<PositionError> createPositionError(GeolocationError* error)
+static PassRefPtrWillBeRawPtr<PositionError> createPositionError(GeolocationError* error)
 {
     PositionError::ErrorCode code = PositionError::POSITION_UNAVAILABLE;
     switch (error->code()) {
@@ -68,7 +77,9 @@ 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)
+DEFINE_GC_INFO(Geolocation::GeoNotifier);
+
+Geolocation::GeoNotifier::GeoNotifier(Geolocation* geolocation, PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PassRefPtrWillBeRawPtr<PositionOptions> options)
     : m_geolocation(geolocation)
     , m_successCallback(successCallback)
     , m_errorCallback(errorCallback)
@@ -83,7 +94,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(PassRefPtrWillBeRawPtr<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
@@ -141,7 +159,7 @@ void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*)
 
     // Protect this GeoNotifier object, since it
     // could be deleted by a call to clearWatch in a callback.
-    RefPtr<GeoNotifier> protect(this);
+    RefPtrWillBeRawPtr<GeoNotifier> protect(this);
 
     // Test for fatal error first. This is required for the case where the Frame is
     // disconnected and requests are cancelled.
@@ -161,16 +179,22 @@ void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*)
     }
 
     if (m_errorCallback) {
-        RefPtr<PositionError> error = PositionError::create(PositionError::TIMEOUT, "Timeout expired");
+        RefPtrWillBeRawPtr<PositionError> error = PositionError::create(PositionError::TIMEOUT, "Timeout expired");
         m_errorCallback->handleEvent(error.get());
     }
     m_geolocation->requestTimedOut(this);
 }
 
-bool Geolocation::Watchers::add(int id, PassRefPtr<GeoNotifier> prpNotifier)
+void Geolocation::Watchers::trace(Visitor* visitor)
+{
+    visitor->trace(m_idToNotifierMap);
+    visitor->trace(m_notifierToIdMap);
+}
+
+bool Geolocation::Watchers::add(int id, PassRefPtrWillBeRawPtr<GeoNotifier> prpNotifier)
 {
     ASSERT(id > 0);
-    RefPtr<GeoNotifier> notifier = prpNotifier;
+    RefPtrWillBeRawPtr<GeoNotifier> notifier = prpNotifier;
 
     if (!m_idToNotifierMap.add(id, notifier.get()).isNewEntry)
         return false;
@@ -227,9 +251,11 @@ void Geolocation::Watchers::getNotifiersVector(GeoNotifierVector& copy) const
     copyValuesToVector(m_idToNotifierMap, copy);
 }
 
-PassRefPtr<Geolocation> Geolocation::create(ExecutionContext* context)
+DEFINE_GC_INFO(Geolocation);
+
+PassRefPtrWillBeRawPtr<Geolocation> Geolocation::create(ExecutionContext* context)
 {
-    RefPtr<Geolocation> geolocation = adoptRef(new Geolocation(context));
+    RefPtrWillBeRawPtr<Geolocation> geolocation = adoptRefWillBeNoop(new Geolocation(context));
     geolocation->suspendIfNeeded();
     return geolocation.release();
 }
@@ -246,6 +272,15 @@ Geolocation::~Geolocation()
     ASSERT(m_allowGeolocation != InProgress);
 }
 
+void Geolocation::trace(Visitor* visitor)
+{
+    visitor->trace(m_oneShots);
+    visitor->trace(m_watchers);
+    visitor->trace(m_pendingForPermissionNotifiers);
+    visitor->trace(m_lastPosition);
+    visitor->trace(m_requestsAwaitingCachedPosition);
+}
+
 Document* Geolocation::document() const
 {
     return toDocument(executionContext());
@@ -284,23 +319,23 @@ Geoposition* Geolocation::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, PassRefPtrWillBeRawPtr<PositionOptions> options)
 {
     if (!frame())
         return;
 
-    RefPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
+    RefPtrWillBeRawPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
     startRequest(notifier.get());
 
     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, PassRefPtrWillBeRawPtr<PositionOptions> options)
 {
     if (!frame())
         return 0;
 
-    RefPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
+    RefPtrWillBeRawPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
     startRequest(notifier.get());
 
     int watchID;
@@ -428,7 +463,7 @@ void Geolocation::clearWatch(int watchID)
 void Geolocation::setIsAllowed(bool allowed)
 {
     // Protect the Geolocation object from garbage collection during a callback.
-    RefPtr<Geolocation> protect(this);
+    RefPtrWillBeRawPtr<Geolocation> protect(this);
 
     // This may be due to either a new position from the service, or a cached
     // position.
@@ -442,7 +477,7 @@ void Geolocation::setIsAllowed(bool allowed)
     }
 
     if (!isAllowed()) {
-        RefPtr<PositionError> error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage);
+        RefPtrWillBeRawPtr<PositionError> error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage);
         error->setIsFatal(true);
         handleError(error.get());
         m_requestsAwaitingCachedPosition.clear();
@@ -460,12 +495,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)
@@ -635,7 +667,7 @@ void Geolocation::positionChanged()
 
 void Geolocation::setError(GeolocationError* error)
 {
-    RefPtr<PositionError> positionError = createPositionError(error);
+    RefPtrWillBeRawPtr<PositionError> positionError = createPositionError(error);
     handleError(positionError.get());
 }