[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.21-584-g1e41756

eric at webkit.org eric at webkit.org
Fri Feb 26 22:22:32 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit 34f5b7794183d718998694e069337b84bcd504e7
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Feb 17 12:00:15 2010 +0000

    2010-02-17  Marcus Bulach  <bulach at chromium.org>
    
            Reviewed by Jeremy Orlow.
    
            Implements GeolocationServices for Chromium.
            https://bugs.webkit.org/show_bug.cgi?id=32068
    
            This is part of implementing Geolocation framework for Chromium. Existing layout tests should pass.
    
            * WebCore.gypi:
            * page/Geolocation.h:
            * platform/GeolocationService.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54883 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index e4352fe..08cf15b 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,16 @@
+2010-02-17  Marcus Bulach  <bulach at chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        Implements GeolocationServices for Chromium.
+        https://bugs.webkit.org/show_bug.cgi?id=32068
+
+        This is part of implementing Geolocation framework for Chromium. Existing layout tests should pass.
+
+        * WebCore.gypi:
+        * page/Geolocation.h:
+        * platform/GeolocationService.h:
+
 2010-02-17  Steve Block  <steveblock at google.com>
 
         Reviewed by Ariya Hidayat.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 69e2066..a9f01cf 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -1925,6 +1925,7 @@
             'platform/chromium/FramelessScrollView.h',
             'platform/chromium/FramelessScrollViewClient.h',
             'platform/chromium/GeolocationServiceChromium.cpp',
+            'platform/chromium/GeolocationServiceChromium.h',
             'platform/chromium/KeyCodeConversion.h',
             'platform/chromium/KeyCodeConversionGtk.cpp',
             'platform/chromium/KeyboardCodesPosix.h',
diff --git a/WebCore/page/Geolocation.h b/WebCore/page/Geolocation.h
index dd8c0b8..173da87 100644
--- a/WebCore/page/Geolocation.h
+++ b/WebCore/page/Geolocation.h
@@ -78,10 +78,13 @@ public:
     
     void setShouldClearCache(bool shouldClearCache) { m_shouldClearCache = shouldClearCache; }
     bool shouldClearCache() const { return m_shouldClearCache; }
+    Frame* frame() const { return m_frame; }
 
 #if ENABLE(CLIENT_BASED_GEOLOCATION)
     void setPosition(GeolocationPosition*);
     void setError(GeolocationError*);
+#else
+    GeolocationService* getGeolocationService() const { return m_service.get(); }
 #endif
 
 private:
diff --git a/WebCore/platform/GeolocationService.cpp b/WebCore/platform/GeolocationService.cpp
index be9553b..7e1f755 100644
--- a/WebCore/platform/GeolocationService.cpp
+++ b/WebCore/platform/GeolocationService.cpp
@@ -25,12 +25,13 @@
 
 #include "config.h"
 #include "GeolocationService.h"
-#include "Geoposition.h"
+
 #include "GeolocationServiceMock.h"
+#include "Geoposition.h"
 #include "PositionError.h"
 
-#include <wtf/CurrentTime.h>
 #include <wtf/Assertions.h>
+#include <wtf/CurrentTime.h>
 
 namespace WebCore {
 
diff --git a/WebCore/platform/GeolocationService.h b/WebCore/platform/GeolocationService.h
index cebf313..4390496 100644
--- a/WebCore/platform/GeolocationService.h
+++ b/WebCore/platform/GeolocationService.h
@@ -20,7 +20,7 @@
  * 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. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef GeolocationService_h
@@ -46,10 +46,10 @@ class GeolocationService : public Noncopyable {
 public:
     static GeolocationService* create(GeolocationServiceClient*);
     virtual ~GeolocationService() { }
-    
+
     virtual bool startUpdating(PositionOptions*) { return false; }
     virtual void stopUpdating() { }
-    
+
     virtual void suspend() { }
     virtual void resume() { }
 
@@ -63,6 +63,7 @@ public:
 
 protected:
     GeolocationService(GeolocationServiceClient*);
+    GeolocationServiceClient* geolocationServiceClient() const { return m_geolocationServiceClient; }
 
 private:
     GeolocationServiceClient* m_geolocationServiceClient;
diff --git a/WebCore/platform/chromium/ChromiumBridge.h b/WebCore/platform/chromium/ChromiumBridge.h
index 8551491..5a085be 100644
--- a/WebCore/platform/chromium/ChromiumBridge.h
+++ b/WebCore/platform/chromium/ChromiumBridge.h
@@ -53,6 +53,8 @@ namespace WebCore {
     class Cursor;
     class Document;
     class Frame;
+    class GeolocationServiceBridge;
+    class GeolocationServiceChromium;
     class GraphicsContext;
     class Image;
     class IntRect;
@@ -117,6 +119,9 @@ namespace WebCore {
         // Forms --------------------------------------------------------------
         static void notifyFormStateChanged(const Document*);
 
+        // Geolocation --------------------------------------------------------
+        static GeolocationServiceBridge* createGeolocationServiceBridge(GeolocationServiceChromium*);
+
         // HTML5 DB -----------------------------------------------------------
 #if ENABLE(DATABASE)
         // Returns a handle to the DB file and ooptionally a handle to its containing directory
diff --git a/WebCore/platform/chromium/GeolocationServiceChromium.cpp b/WebCore/platform/chromium/GeolocationServiceChromium.cpp
index 65886b0..22b95bc 100644
--- a/WebCore/platform/chromium/GeolocationServiceChromium.cpp
+++ b/WebCore/platform/chromium/GeolocationServiceChromium.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Google Inc. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -29,27 +29,79 @@
  */
 
 #include "config.h"
-#include "GeolocationService.h"
+#include "GeolocationServiceChromium.h"
+
+#include "ChromiumBridge.h"
 
 namespace WebCore {
 
-class GeolocationServiceChromium : public GeolocationService {
-public:
-    GeolocationServiceChromium(GeolocationServiceClient* c)
-        : GeolocationService(c)
-    {
-    }
-    // FIXME: Implement. https://bugs.webkit.org/show_bug.cgi?id=32068
-};
+GeolocationServiceChromium::GeolocationServiceChromium(GeolocationServiceClient* c)
+        : GeolocationService(c),
+          m_geolocation(reinterpret_cast<Geolocation*>(c)),
+          m_lastPosition(Geoposition::create(Coordinates::create(0.0, 0.0, false, 0.0, 0.0, false, 0.0, false, 0.0, false, 0.0), 0)),
+          m_lastError(PositionError::create(PositionError::POSITION_UNAVAILABLE, "")),
+          m_geolocationServiceBridge(ChromiumBridge::createGeolocationServiceBridge(this))
+{
+}
+
+void GeolocationServiceChromium::setIsAllowed(bool allowed)
+{
+    m_geolocation->setIsAllowed(allowed);  
+}
+
+void GeolocationServiceChromium::setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp)
+{
+    m_lastPosition = Geoposition::create(Coordinates::create(latitude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed), timestamp);
+    positionChanged();
+}
+
+void GeolocationServiceChromium::setLastError(int errorCode, const String& message)
+{
+    m_lastError = PositionError::create(static_cast<PositionError::ErrorCode>(errorCode), message);
+    errorOccurred();
+}
+
+Frame* GeolocationServiceChromium::frame()
+{
+    return m_geolocation->frame();
+}
+
+bool GeolocationServiceChromium::startUpdating(PositionOptions* options)
+{
+    return m_geolocationServiceBridge->startUpdating(options);
+}
+
+void GeolocationServiceChromium::stopUpdating()
+{
+    return m_geolocationServiceBridge->stopUpdating();
+}
+
+void GeolocationServiceChromium::suspend()
+{
+    return m_geolocationServiceBridge->suspend();
+}
+
+void GeolocationServiceChromium::resume()
+{
+    return m_geolocationServiceBridge->resume();
+}
+
+Geoposition* GeolocationServiceChromium::lastPosition() const
+{
+    return m_lastPosition.get();
+}
+
+PositionError* GeolocationServiceChromium::lastError() const
+{
+    return m_lastError.get();
+}
 
-// This guard is the counterpart of the one in WebCore/platform/GeolocationService.cpp
-#if ENABLE(GEOLOCATION)
-static GeolocationService* createGeolocationService(GeolocationServiceClient* c)
+static GeolocationService* createGeolocationServiceChromium(GeolocationServiceClient* c)
 {
     return new GeolocationServiceChromium(c);
 }
 
-GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &createGeolocationService;
-#endif
+// Sets up the factory function for GeolocationService.
+GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &createGeolocationServiceChromium;
 
 } // namespace WebCore
diff --git a/WebCore/platform/chromium/GeolocationServiceChromium.h b/WebCore/platform/chromium/GeolocationServiceChromium.h
new file mode 100644
index 0000000..e32de8b
--- /dev/null
+++ b/WebCore/platform/chromium/GeolocationServiceChromium.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2010, 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 GeolocationServiceChromium_h
+#define GeolocationServiceChromium_h
+
+#include "Geolocation.h"
+#include "GeolocationService.h"
+#include "Geoposition.h"
+#include "PlatformString.h"
+#include "PositionError.h"
+
+namespace WebCore {
+
+// Provides an interface for GeolocationServiceChromium to call into the embedder.
+class GeolocationServiceBridge {
+public:
+    // Called by GeolocationServiceChromium.
+    virtual bool startUpdating(PositionOptions*) = 0;
+    virtual void stopUpdating() = 0;
+    virtual void suspend() = 0;
+    virtual void resume() = 0;
+
+    // Called by the embedder, to identify this bridge.
+    virtual int getBridgeId() const = 0;
+};
+
+// This class extends GeolocationService, and uses GeolocationServiceBridge to
+// call into the embedder, as well as provides a few extra methods so that the
+// embedder can notify permission, position, error, etc.
+class GeolocationServiceChromium : public GeolocationService {
+public:
+    explicit GeolocationServiceChromium(GeolocationServiceClient*);
+
+    GeolocationServiceBridge* geolocationServiceBridge() const { return m_geolocationServiceBridge.get(); }
+    void setIsAllowed(bool allowed);
+    void setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp);
+    void setLastError(int errorCode, const String& message);
+    Frame* frame();
+
+    // From GeolocationService.
+    virtual bool startUpdating(PositionOptions*);
+    virtual void stopUpdating();
+    virtual void suspend();
+    virtual void resume();
+    virtual Geoposition* lastPosition() const;
+    virtual PositionError* lastError() const;
+
+private:
+    Geolocation* m_geolocation;
+    OwnPtr<GeolocationServiceBridge> m_geolocationServiceBridge;    
+    RefPtr<Geoposition> m_lastPosition;
+    RefPtr<PositionError> m_lastError;
+};
+
+} // namespace WebCore
+
+#endif // GeolocationServiceChromium_h
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index 9550682..0c76dd3 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -68,6 +68,7 @@
                 'WEBKIT_IMPLEMENTATION',
             ],
             'sources': [
+                'public/GeolocationServiceBridgeChromium.h',
                 'public/gtk/WebInputEventFactory.h',
                 'public/linux/WebFontRendering.h',
                 'public/linux/WebRenderTheme.h',
@@ -232,6 +233,7 @@
                 'src/EventListenerWrapper.h',
                 'src/FrameLoaderClientImpl.cpp',
                 'src/FrameLoaderClientImpl.h',
+                'src/GeolocationServiceBridgeChromium.cpp',		
                 'src/gtk/WebFontInfo.cpp',
                 'src/gtk/WebFontInfo.h',
                 'src/gtk/WebInputEventFactory.cpp',
diff --git a/WebKit/chromium/public/GeolocationServiceBridgeChromium.h b/WebKit/chromium/public/GeolocationServiceBridgeChromium.h
new file mode 100644
index 0000000..adca956
--- /dev/null
+++ b/WebKit/chromium/public/GeolocationServiceBridgeChromium.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2010, 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 GeolocationServiceBridgeChromium_h
+#define GeolocationServiceBridgeChromium_h
+
+namespace WebCore {
+class GeolocationServiceBridge;
+class GeolocationServiceChromium;
+}
+
+namespace WebKit {
+
+class WebString;
+class WebURL;
+
+// Provides a WebKit API called by the embedder.
+class WebGeolocationServiceBridge {
+public:
+    virtual void setIsAllowed(bool allowed) = 0;
+    virtual void setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp) = 0;
+    virtual void setLastError(int errorCode, const WebString& message) = 0;
+};
+
+// Provides an embedder API called by WebKit.
+class WebGeolocationServiceInterface {
+public:
+    virtual void requestPermissionForFrame(int bridgeId, const WebURL& url) = 0;
+    virtual void startUpdating(int bridgeId, bool hasHighAccuracy) = 0;
+    virtual void stopUpdating(int bridgeId) = 0;
+    virtual void suspend(int bridgeId) = 0;
+    virtual void resume(int bridgeId) = 0;
+
+    // Attaches the GeolocationBridge to the embedder and returns its id, which
+    // should be used on subsequent calls for the methods above.
+    virtual int attachBridge(WebKit::WebGeolocationServiceBridge* geolocationServiceBridge) = 0;
+
+    // Dettaches the GeolocationService from the embedder.
+    virtual void dettachBridge(int bridgeId) = 0;
+};
+
+WebCore::GeolocationServiceBridge* createGeolocationServiceBridgeImpl(WebCore::GeolocationServiceChromium*);
+
+} // namespace WebKit
+
+#endif // GeolocationServiceBridgeChromium_h
diff --git a/WebKit/chromium/public/WebViewClient.h b/WebKit/chromium/public/WebViewClient.h
index 4d272bb..a2de115 100644
--- a/WebKit/chromium/public/WebViewClient.h
+++ b/WebKit/chromium/public/WebViewClient.h
@@ -46,6 +46,7 @@ class WebAccessibilityObject;
 class WebDragData;
 class WebFileChooserCompletion;
 class WebFrame;
+class WebGeolocationServiceInterface;
 class WebNode;
 class WebNotificationPresenter;
 class WebRange;
@@ -277,6 +278,11 @@ public:
     virtual void removeAutofillSuggestions(const WebString& name,
                                            const WebString& value) { }
 
+    // Geolocation ---------------------------------------------------------
+
+    // Access the embedder API for geolocation services.
+    virtual WebKit::WebGeolocationServiceInterface* getGeolocationService() { return 0; }
+
 protected:
     ~WebViewClient() { }
 };
diff --git a/WebKit/chromium/src/ChromeClientImpl.cpp b/WebKit/chromium/src/ChromeClientImpl.cpp
index ce2f00c..5d58934 100644
--- a/WebKit/chromium/src/ChromeClientImpl.cpp
+++ b/WebKit/chromium/src/ChromeClientImpl.cpp
@@ -43,6 +43,10 @@
 #include "FloatRect.h"
 #include "FrameLoadRequest.h"
 #include "FrameView.h"
+#include "Geolocation.h"
+#include "GeolocationService.h"
+#include "GeolocationServiceBridgeChromium.h"
+#include "GeolocationServiceChromium.h"
 #include "HitTestResult.h"
 #include "IntRect.h"
 #include "Node.h"
@@ -674,4 +678,10 @@ NotificationPresenter* ChromeClientImpl::notificationPresenter() const
 }
 #endif
 
+void ChromeClientImpl::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
+{
+    GeolocationServiceChromium* geolocationService = reinterpret_cast<GeolocationServiceChromium*>(geolocation->getGeolocationService());
+    m_webView->client()->getGeolocationService()->requestPermissionForFrame(geolocationService->geolocationServiceBridge()->getBridgeId(), frame->document()->url());
+}
+
 } // namespace WebKit
diff --git a/WebKit/chromium/src/ChromeClientImpl.h b/WebKit/chromium/src/ChromeClientImpl.h
index 9e8c2e3..ad57203 100644
--- a/WebKit/chromium/src/ChromeClientImpl.h
+++ b/WebKit/chromium/src/ChromeClientImpl.h
@@ -121,8 +121,7 @@ public:
 #if ENABLE(NOTIFICATIONS)
     virtual WebCore::NotificationPresenter* notificationPresenter() const;
 #endif
-    virtual void requestGeolocationPermissionForFrame(
-        WebCore::Frame*, WebCore::Geolocation*) { }
+    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*);
     virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
     virtual bool setCursor(WebCore::PlatformCursorHandle) { return false; }
     virtual void formStateDidChange(const WebCore::Node*);
diff --git a/WebKit/chromium/src/ChromiumBridge.cpp b/WebKit/chromium/src/ChromiumBridge.cpp
index 3d81b01..e04226e 100644
--- a/WebKit/chromium/src/ChromiumBridge.cpp
+++ b/WebKit/chromium/src/ChromiumBridge.cpp
@@ -74,6 +74,7 @@
 #include "BitmapImage.h"
 #include "Cookie.h"
 #include "FrameView.h"
+#include "GeolocationServiceBridgeChromium.h"
 #include "GraphicsContext.h"
 #include "KURL.h"
 #include "NotImplemented.h"
@@ -357,6 +358,13 @@ String ChromiumBridge::getFontFamilyForCharacters(const UChar* characters, size_
 }
 #endif
 
+// Geolocation ----------------------------------------------------------------
+
+GeolocationServiceBridge* ChromiumBridge::createGeolocationServiceBridge(GeolocationServiceChromium* geolocationServiceChromium)
+{
+    return createGeolocationServiceBridgeImpl(geolocationServiceChromium);
+}
+
 // HTML5 DB -------------------------------------------------------------------
 
 #if ENABLE(DATABASE)
diff --git a/WebKit/chromium/src/GeolocationServiceBridgeChromium.cpp b/WebKit/chromium/src/GeolocationServiceBridgeChromium.cpp
new file mode 100644
index 0000000..eadcdaf
--- /dev/null
+++ b/WebKit/chromium/src/GeolocationServiceBridgeChromium.cpp
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2010 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 "GeolocationServiceBridgeChromium.h"
+
+#include "Chrome.h"
+#include "ChromeClientImpl.h"
+#include "Frame.h"
+#include "Geolocation.h"
+#include "GeolocationServiceChromium.h"
+#include "Geoposition.h"
+#include "Page.h"
+#include "PositionError.h"
+#include "PositionOptions.h"
+#include "WebFrame.h"
+#include "WebFrameImpl.h"
+#include "WebViewClient.h"
+#include "WebViewImpl.h"
+
+#if ENABLE(GEOLOCATION)
+
+using WebCore::Coordinates;
+using WebCore::Frame;
+using WebCore::Geolocation;
+using WebCore::GeolocationServiceBridge;
+using WebCore::GeolocationServiceChromium;
+using WebCore::GeolocationServiceClient;
+using WebCore::Geoposition;
+using WebCore::PositionError;
+using WebCore::PositionOptions;
+using WebCore::String;
+
+namespace WebKit {
+
+class GeolocationServiceBridgeImpl : public GeolocationServiceBridge, public WebGeolocationServiceBridge {
+public:
+    explicit GeolocationServiceBridgeImpl(GeolocationServiceChromium*);
+    virtual ~GeolocationServiceBridgeImpl();
+
+    // GeolocationServiceBridge
+    virtual bool startUpdating(PositionOptions*);
+    virtual void stopUpdating();
+    virtual void suspend();
+    virtual void resume();
+    virtual int getBridgeId() const;
+
+    // WebGeolocationServiceBridge
+    virtual void setIsAllowed(bool allowed);
+    virtual void setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp);
+    virtual void setLastError(int errorCode, const WebString& message);
+
+private:
+    WebViewClient* getWebViewClient();
+
+    // GeolocationServiceChromium owns us, we only have a pointer back to it.
+    GeolocationServiceChromium* m_GeolocationServiceChromium;
+    int m_bridgeId;
+};
+
+GeolocationServiceBridge* createGeolocationServiceBridgeImpl(GeolocationServiceChromium* geolocationServiceChromium)
+{
+    return new GeolocationServiceBridgeImpl(geolocationServiceChromium);
+}
+
+GeolocationServiceBridgeImpl::GeolocationServiceBridgeImpl(GeolocationServiceChromium* geolocationServiceChromium)
+    : m_GeolocationServiceChromium(geolocationServiceChromium)
+{
+    // We need to attach ourselves here: Geolocation calls requestPermissionForFrame()
+    // directly, and we need to be attached so that the embedder can call
+    // our setIsAllowed().
+    m_bridgeId = getWebViewClient()->getGeolocationService()->attachBridge(this);
+    ASSERT(m_bridgeId);
+}
+
+GeolocationServiceBridgeImpl::~GeolocationServiceBridgeImpl()
+{
+    WebKit::WebViewClient* webViewClient = getWebViewClient();
+    // Geolocation has an OwnPtr to us, and it's destroyed after the frame has
+    // been potentially disconnected. In this case, it calls stopUpdating()
+    // has been called and we have already dettached ourselves.
+    if (!webViewClient) {
+        ASSERT(!m_bridgeId);
+    } else if (m_bridgeId)
+        webViewClient->getGeolocationService()->dettachBridge(m_bridgeId);
+}
+
+bool GeolocationServiceBridgeImpl::startUpdating(PositionOptions* positionOptions)
+{
+    if (!m_bridgeId)
+        m_bridgeId = getWebViewClient()->getGeolocationService()->attachBridge(this);
+    getWebViewClient()->getGeolocationService()->startUpdating(m_bridgeId, positionOptions->enableHighAccuracy());
+    //// FIXME: this will trigger a permission request regardless.
+    //// Is it correct? confirm with andreip.
+    // positionChanged();
+    return true;
+}
+
+void GeolocationServiceBridgeImpl::stopUpdating()
+{
+    WebGeolocationServiceInterface* geolocationService = getWebViewClient()->getGeolocationService();
+    geolocationService->stopUpdating(m_bridgeId);
+    geolocationService->dettachBridge(m_bridgeId);
+    m_bridgeId = 0;
+}
+
+void GeolocationServiceBridgeImpl::suspend()
+{
+    getWebViewClient()->getGeolocationService()->suspend(m_bridgeId);
+}
+
+void GeolocationServiceBridgeImpl::resume()
+{
+    getWebViewClient()->getGeolocationService()->resume(m_bridgeId);
+}
+
+int GeolocationServiceBridgeImpl::getBridgeId() const
+{
+    return m_bridgeId;
+}
+
+void GeolocationServiceBridgeImpl::setIsAllowed(bool allowed)
+{
+    m_GeolocationServiceChromium->setIsAllowed(allowed);
+}
+
+void GeolocationServiceBridgeImpl::setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp)
+{
+    m_GeolocationServiceChromium->setLastPosition(latitude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, timestamp);
+}
+
+void GeolocationServiceBridgeImpl::setLastError(int errorCode, const WebString& message)
+{
+    m_GeolocationServiceChromium->setLastError(errorCode, message);
+}
+
+WebViewClient* GeolocationServiceBridgeImpl::getWebViewClient()
+{
+    Frame* frame = m_GeolocationServiceChromium->frame();
+    if (!frame || !frame->page())
+        return 0;
+    WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClientImpl*>(frame->page()->chrome()->client());
+    WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client();
+    return webViewClient;
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(GEOLOCATION)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list