| Index: webkit/chaos/ChaosGeolocation.cpp
|
| ===================================================================
|
| --- webkit/chaos/ChaosGeolocation.cpp (revision 0)
|
| +++ webkit/chaos/ChaosGeolocation.cpp (revision 0)
|
| @@ -0,0 +1,165 @@
|
| +#include "config.h"
|
| +
|
| +#include "ChaosCoordinates.h"
|
| +#include "ChaosGeolocation.h"
|
| +#include "ChaosGeoposition.h"
|
| +#include "ChromeClient.h"
|
| +#include "DOMWindow.h"
|
| +#include "Frame.h"
|
| +#include "GeolocationPowerbox.h"
|
| +#include "Page.h"
|
| +#include "V8Proxy.h"
|
| +
|
| +#undef LOG
|
| +#include "base/logging.h"
|
| +//#include "views/controls/button/radio_button.h"
|
| +//#include "views/view.h"
|
| +//#include "views/window/dialog_delegate.h"
|
| +
|
| +#include "webkit/glue/webview_delegate.h"
|
| +
|
| +#include <math.h>
|
| +
|
| +namespace WebCore {
|
| +
|
| +class ChaosGeolocationExact : public ChaosGeolocationImpl {
|
| + public:
|
| + ChaosGeolocationExact() {
|
| + }
|
| + ChaosCoordinates *coords() const {
|
| + return new ChaosCoordinates(1.234, 2.345, .00001);
|
| + }
|
| + std::string describe() const {
|
| + return "exact geolocation";
|
| + }
|
| +};
|
| +
|
| +class ChaosGeolocationCity : public ChaosGeolocationImpl {
|
| + ChaosGeolocationImpl *source_;
|
| + static const double ACCURACY = .1;
|
| +
|
| + static double round(double x) {
|
| + return x - fmod(x, ACCURACY);
|
| + }
|
| + public:
|
| + ChaosGeolocationCity(ChaosGeolocationImpl *source) : source_(source) {
|
| + }
|
| + ChaosCoordinates *coords() const {
|
| + ChaosCoordinates *sc = source_->coords();
|
| + ChaosCoordinates *mc = new ChaosCoordinates(round(sc->latitude()),
|
| + round(sc->longitude()),
|
| + ACCURACY);
|
| + delete sc;
|
| + return mc;
|
| + }
|
| + std::string describe() const {
|
| + return "city-level geoloication using " + source_->describe();
|
| + }
|
| +};
|
| +
|
| +class ChooseGeolocationProvider : public ChooseGeolocationProviderCallback {
|
| + public:
|
| + ChooseGeolocationProvider(ChaosGeolocation *choosing_for)
|
| + : choosing_for_(choosing_for) {
|
| + // V8Proxy* proxy = V8Proxy::retrieve();
|
| + Frame *frame = V8Proxy::retrieveFrameForCurrentContext();
|
| + KURL url = frame->document()->url();
|
| + frame->page()->chrome()->client()->chooseGeolocationProvider(this, url);
|
| + }
|
| + void OnProviderChosen(GeolocationPowerbox::ProviderId provider_id) {
|
| + ChaosGeolocationImpl *impl = NULL;
|
| +
|
| + /*
|
| + String urlString = url_.string();
|
| + LOG(WARNING) << "Choice " << provider_id << " for domain "
|
| + << url_.string().ascii().data();
|
| + */
|
| +
|
| + switch(provider_id) {
|
| + case GeolocationPowerbox::EXACT:
|
| + impl = new ChaosGeolocationExact();
|
| + break;
|
| + case GeolocationPowerbox::CITY:
|
| + impl = new ChaosGeolocationCity(new ChaosGeolocationExact());
|
| + break;
|
| + }
|
| + ASSERT(impl);
|
| + choosing_for_->OnProviderChosen(impl);
|
| + // I believe this gets deleted by the caller now...
|
| + }
|
| +
|
| + private:
|
| + ChaosGeolocation *choosing_for_;
|
| +};
|
| +
|
| +static GeolocationPowerbox powerbox;
|
| +GeolocationBrowserPowerbox GeolocationBrowserPowerbox::powerbox;
|
| +
|
| +ChooseGeolocationProvider *GeolocationPowerbox::choose(
|
| + ChaosGeolocation *geolocation) {
|
| + ChaosGeolocationImpl *choice;
|
| +
|
| + ChooseGeolocationProvider *chooser
|
| + = new ChooseGeolocationProvider(geolocation);
|
| +
|
| + return chooser;
|
| +}
|
| +
|
| +ChaosGeolocation::ChaosGeolocation() : impl_(0) {
|
| +}
|
| +
|
| +void ChaosGeolocation::OnProviderChosen(ChaosGeolocationImpl *impl) {
|
| + // FIXME(benl): refcount this
|
| + impl_ = impl;
|
| + LOG(WARNING) << "Wired up " << impl_->describe();
|
| +}
|
| +
|
| +ChaosGeoposition *ChaosGeolocation::lastPosition() {
|
| + return NULL;
|
| +}
|
| +
|
| +void ChaosGeolocation::getCurrentPosition(PassRefPtr<ChaosPositionCallback> cb) {
|
| + oneShots_.add(GeoNotifier::create(this, cb));
|
| +}
|
| +
|
| +int ChaosGeolocation::watchPosition(PassRefPtr<ChaosPositionCallback> cb) {
|
| + static int nextWatchId = 1; // Do not start at zero, can't use it
|
| + // in a map since it is reserved to
|
| + // mean "empty".
|
| +
|
| + LOG(WARNING) << "pid = " << getpid();
|
| + LOG(WARNING) << "wp2";
|
| + watchers_.set(nextWatchId, GeoNotifier::create(this, cb));
|
| + LOG(WARNING) << "wp3";
|
| +
|
| + powerbox.choose(this);
|
| +
|
| + return nextWatchId++;
|
| +}
|
| +
|
| +void ChaosGeolocation::clearWatch(long watchId) {
|
| + watchers_.remove(watchId);
|
| +}
|
| +
|
| +ChaosGeolocation::GeoNotifier::GeoNotifier(ChaosGeolocation *parent,
|
| + PassRefPtr<ChaosPositionCallback> successCallback)
|
| + : successCallback_(successCallback),
|
| + timer_(this, &ChaosGeolocation::GeoNotifier::timerFired),
|
| + parent_(parent) {
|
| + startTimer();
|
| +}
|
| +
|
| +void ChaosGeolocation::GeoNotifier::startTimer() {
|
| + timer_.startRepeating(1);
|
| +}
|
| +
|
| +void ChaosGeolocation::GeoNotifier::timerFired(Timer<GeoNotifier> *timer) {
|
| + if (!parent_->impl_)
|
| + return;
|
| +
|
| + DLOG(WARNING) << "tock!";
|
| + ChaosGeoposition *pos = new ChaosGeoposition(parent_->impl_->coords());
|
| + successCallback_->handleEvent(pos);
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|
| Property changes on: webkit/chaos/ChaosGeolocation.cpp
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|