2009-12-01 Steve Block <steveblock@google.com>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Dec 2009 16:46:38 +0000 (16:46 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Dec 2009 16:46:38 +0000 (16:46 +0000)
        Reviewed by Dimitri Glazkov.

        Adds V8 bindings for Geolocation.
        https://bugs.webkit.org/show_bug.cgi?id=30206

        Also adds Geolocation files to Chrome build files.

        * WebCore.gyp/WebCore.gyp: Modified. Corrects list of Geolocation IDL files.
        * WebCore.gypi: Modified. Adds Geolocation files.
        * bindings/v8/DOMObjectsInclude.h: Modified. Adds Geolocation includes.
        * bindings/v8/DerivedSourcesAllInOne.cpp: Modified. Adds Geolocation files.
        * bindings/v8/V8Index.cpp: Modified. Includes Geolocation generated headers.
        * bindings/v8/V8Index.h: Modified. Adds Geolocation types to DOM_OBJECT_TYPES.
        * bindings/v8/custom/V8CoordinatesCustom.cpp: Added. Handles optional properties.
        * bindings/v8/custom/V8CustomBinding.h: Modified. Declares callbacks and getters.
        * bindings/v8/custom/V8CustomPositionCallback.cpp: Added.
        (WebCore::V8CustomPositionCallback::V8CustomPositionCallback): Added. Constructor.
        (WebCore::V8CustomPositionCallback::~V8CustomPositionCallback): Added. Destructor.
        (WebCore::V8CustomPositionCallback::handleEvent): Added. Invokes callback.
        * bindings/v8/custom/V8CustomPositionCallback.h: Added.
        (WebCore::V8CustomPositionCallback::create): Added. Factory method.
        * bindings/v8/custom/V8CustomPositionErrorCallback.cpp: Added.
        (WebCore::V8CustomPositionErrorCallback::V8CustomPositionErrorCallback): Added. Constructor.
        (WebCore::V8CustomPositionErrorCallback::~V8CustomPositionErrorCallback): Added. Destructor.
        (WebCore::V8CustomPositionErrorCallback::handleEvent): Added. Invokes callback.
        * bindings/v8/custom/V8CustomPositionErrorCallback.h: Added.
        (WebCore::V8CustomPositionErrorCallback::create): Added. Factory method.
        * bindings/v8/custom/V8GeolocationCustom.cpp: Added.
        (WebCore::throwTypeMismatchException): Added. Throws a type mismatch error.
        (WebCore::createPositionCallback): Added. Handles type checking for successCallback argument.
        (WebCore::createPositionErrorCallback): Added. Handles type checking for errorCallback argument.
        (WebCore::createPositionOptions): Added. Handles type checking for positionOptions argument.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51540 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
WebCore/ChangeLog
WebCore/WebCore.gyp/WebCore.gyp
WebCore/WebCore.gypi
WebCore/bindings/v8/DOMObjectsInclude.h
WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
WebCore/bindings/v8/V8Index.cpp
WebCore/bindings/v8/V8Index.h
WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp [new file with mode: 0644]
WebCore/bindings/v8/custom/V8CustomBinding.h
WebCore/bindings/v8/custom/V8CustomPositionCallback.cpp [new file with mode: 0644]
WebCore/bindings/v8/custom/V8CustomPositionCallback.h [new file with mode: 0644]
WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.cpp [new file with mode: 0644]
WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.h [new file with mode: 0644]
WebCore/bindings/v8/custom/V8GeolocationCustom.cpp [new file with mode: 0644]

index 549257bf673e3d2369fbe7458b200006909ebe3e..c0456f202aa8822072fe96ece46889aa87b5c3f2 100644 (file)
@@ -1,3 +1,38 @@
+2009-12-01  Steve Block  <steveblock@google.com>
+
+        Reviewed by Dimitri Glazkov.
+
+        Adds V8 bindings for Geolocation.
+        https://bugs.webkit.org/show_bug.cgi?id=30206
+
+        Also adds Geolocation files to Chrome build files.
+
+        * WebCore.gyp/WebCore.gyp: Modified. Corrects list of Geolocation IDL files.
+        * WebCore.gypi: Modified. Adds Geolocation files.
+        * bindings/v8/DOMObjectsInclude.h: Modified. Adds Geolocation includes.
+        * bindings/v8/DerivedSourcesAllInOne.cpp: Modified. Adds Geolocation files.
+        * bindings/v8/V8Index.cpp: Modified. Includes Geolocation generated headers.
+        * bindings/v8/V8Index.h: Modified. Adds Geolocation types to DOM_OBJECT_TYPES.
+        * bindings/v8/custom/V8CoordinatesCustom.cpp: Added. Handles optional properties.
+        * bindings/v8/custom/V8CustomBinding.h: Modified. Declares callbacks and getters.
+        * bindings/v8/custom/V8CustomPositionCallback.cpp: Added.
+        (WebCore::V8CustomPositionCallback::V8CustomPositionCallback): Added. Constructor.
+        (WebCore::V8CustomPositionCallback::~V8CustomPositionCallback): Added. Destructor.
+        (WebCore::V8CustomPositionCallback::handleEvent): Added. Invokes callback.
+        * bindings/v8/custom/V8CustomPositionCallback.h: Added.
+        (WebCore::V8CustomPositionCallback::create): Added. Factory method.
+        * bindings/v8/custom/V8CustomPositionErrorCallback.cpp: Added.
+        (WebCore::V8CustomPositionErrorCallback::V8CustomPositionErrorCallback): Added. Constructor.
+        (WebCore::V8CustomPositionErrorCallback::~V8CustomPositionErrorCallback): Added. Destructor.
+        (WebCore::V8CustomPositionErrorCallback::handleEvent): Added. Invokes callback.
+        * bindings/v8/custom/V8CustomPositionErrorCallback.h: Added.
+        (WebCore::V8CustomPositionErrorCallback::create): Added. Factory method.
+        * bindings/v8/custom/V8GeolocationCustom.cpp: Added.
+        (WebCore::throwTypeMismatchException): Added. Throws a type mismatch error.
+        (WebCore::createPositionCallback): Added. Handles type checking for successCallback argument.
+        (WebCore::createPositionErrorCallback): Added. Handles type checking for errorCallback argument.
+        (WebCore::createPositionOptions): Added. Handles type checking for positionOptions argument.
+
 2009-12-01  Yury Semikhatsky  <yurys@chromium.org>
 
         Reviewed by Adam Barth.
index f1788570e98a1b61d50a95f3c20dbad328fad9c3..fe93978cfb4af616353509c43b945177ae63622d 100644 (file)
         # JSC-only.
         '../inspector/JavaScriptCallFrame.idl',
 
-        # ENABLE_GEOLOCATION only.
-        '../page/Geolocation.idl',
-        '../page/Geoposition.idl',
-        '../page/PositionCallback.idl',
-        '../page/PositionError.idl',
-        '../page/PositionErrorCallback.idl',
-
         # Bindings with custom Objective-C implementations.
         '../page/AbstractView.idl',
 
index 8d98bac1030f31c6731f1a81f609dc3725476ebc..1acccdfb375a3e9646f9d9e3cf0a507bdc831e83 100644 (file)
             'page/AbstractView.idl',
             'page/BarInfo.idl',
             'page/Console.idl',
+            'page/Coordinates.idl',
             'page/DOMSelection.idl',
             'page/DOMWindow.idl',
             'page/Geolocation.idl',
             'bindings/v8/custom/V8WebGLRenderingContextCustom.cpp',
             'bindings/v8/custom/V8ClientRectListCustom.cpp',
             'bindings/v8/custom/V8ClipboardCustom.cpp',
+            'bindings/v8/custom/V8CoordinatesCustom.cpp',
             'bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp',
             'bindings/v8/custom/V8ConsoleCustom.cpp',
             'bindings/v8/custom/V8CustomBinding.cpp',
             'bindings/v8/custom/V8CustomBinding.h',
             'bindings/v8/custom/V8CustomEventListener.cpp',
             'bindings/v8/custom/V8CustomEventListener.h',
+            'bindings/v8/custom/V8CustomPositionCallback.cpp',
+            'bindings/v8/custom/V8CustomPositionCallback.h',
+            'bindings/v8/custom/V8CustomPositionErrorCallback.cpp',
+            'bindings/v8/custom/V8CustomPositionErrorCallback.h',
             'bindings/v8/custom/V8CustomSQLStatementCallback.cpp',
             'bindings/v8/custom/V8CustomSQLStatementCallback.h',
             'bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp',
             'bindings/v8/custom/V8ElementCustom.cpp',
             'bindings/v8/custom/V8EventCustom.cpp',
             'bindings/v8/custom/V8FileListCustom.cpp',
+            'bindings/v8/custom/V8GeolocationCustom.cpp',
             'bindings/v8/custom/V8HTMLAudioElementConstructor.cpp',
             'bindings/v8/custom/V8HTMLAudioElementConstructor.h',
             'bindings/v8/custom/V8HTMLAllCollectionCustom.cpp',
index e5e6fe47732ac4805303fc78f0f39170c9223916..785580969a4b0b6f55b936b602d7beecda05d88f 100644 (file)
 #include "StorageEvent.h"
 #endif // DOM_STORAGE
 
+// GEOLOCATION
+#include "Coordinates.h"
+#include "Geolocation.h"
+#include "Geoposition.h"
+#include "PositionError.h"
+
 #if ENABLE(SVG)
 #include "SVGAngle.h"
 #include "SVGAnimatedPoints.h"
index cffc2fbbe8f3cc2c48854634b4a245e84a48c7ed..b32d7d4f33751c1433d7a91a76ebbc02cc4b4262 100644 (file)
@@ -68,6 +68,7 @@
 #include "bindings/V8Comment.cpp"
 #include "bindings/V8CompositionEvent.cpp"
 #include "bindings/V8Console.cpp"
+#include "bindings/V8Coordinates.cpp"
 #include "bindings/V8Counter.cpp"
 #include "bindings/V8CSSCharsetRule.cpp"
 #include "bindings/V8CSSFontFaceRule.cpp"
 #include "bindings/V8EventException.cpp"
 #include "bindings/V8File.cpp"
 #include "bindings/V8FileList.cpp"
+#include "bindings/V8Geolocation.cpp"
+#include "bindings/V8Geoposition.cpp"
 #include "bindings/V8History.cpp"
 #include "bindings/V8HTMLAllCollection.cpp"
 #include "bindings/V8HTMLAnchorElement.cpp"
 #include "bindings/V8PageTransitionEvent.cpp"
 #include "bindings/V8Plugin.cpp"
 #include "bindings/V8PluginArray.cpp"
+#include "bindings/V8PositionError.cpp"
 #include "bindings/V8ProcessingInstruction.cpp"
 #include "bindings/V8ProgressEvent.cpp"
 #include "bindings/V8Range.cpp"
index f312b27eca9b5cbbc8c9781a4723b766acfa9688..2b9a9223c6be11126f6e764c579b90a996d285e9 100644 (file)
 #include "V8InspectorFrontendHost.h"
 #endif
 
+// Geolocation
+#include "V8Coordinates.h"
+#include "V8Geolocation.h"
+#include "V8Geoposition.h"
+#include "V8PositionError.h"
+
 namespace WebCore {
 
 FunctionTemplateFactory V8ClassIndex::GetFactory(V8WrapperType type)
index 6f879b963bde06c3cafa3aee7baae64ebe301a03..1c87d25a1ad2e209b488555b05f6931f1a9514fe 100644 (file)
@@ -494,6 +494,12 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)();
 #define DOM_OBJECT_INSPECTOR_TYPES(V)
 #endif
 
+#define DOM_OBJECT_GEOLOCATION_TYPES(V)                                 \
+    V(COORDINATES, Coordinates)                                         \
+    V(GEOLOCATION, Geolocation)                                         \
+    V(GEOPOSITION, Geoposition)                                         \
+    V(POSITIONERROR, PositionError)
+
 #define DOM_OBJECT_TYPES(V)                                             \
     DOM_OBJECT_TYPES_1(V)                                               \
     DOM_OBJECT_TYPES_2(V)                                               \
@@ -503,7 +509,8 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)();
     DOM_OBJECT_3D_CANVAS_TYPES(V)                                       \
     DOM_OBJECT_XPATH_TYPES(V)                                           \
     DOM_OBJECT_XSLT_TYPES(V)                                            \
-    DOM_OBJECT_INSPECTOR_TYPES(V)
+    DOM_OBJECT_INSPECTOR_TYPES(V)                                       \
+    DOM_OBJECT_GEOLOCATION_TYPES(V)
 
 #if ENABLE(SVG)
 // SVG_OBJECT_TYPES are svg non-node, non-pod types.
diff --git a/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp b/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp
new file mode 100644 (file)
index 0000000..1c07f29
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 "Coordinates.h"
+
+#include "V8Binding.h"
+#include "V8CustomBinding.h"
+#include "V8Proxy.h"
+
+namespace WebCore {
+
+ACCESSOR_GETTER(CoordinatesAltitude)
+{
+    INC_STATS("DOM.Coordinates.altitude._get");
+    v8::Handle<v8::Object> holder = info.Holder();
+    Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder);
+    if (!imp->canProvideAltitude())
+        return v8::Null();
+    return v8::Number::New(imp->altitude());
+}
+
+ACCESSOR_GETTER(CoordinatesAltitudeAccuracy)
+{
+    INC_STATS("DOM.Coordinates.altitudeAccuracy._get");
+    v8::Handle<v8::Object> holder = info.Holder();
+    Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder);
+    if (!imp->canProvideAltitudeAccuracy())
+        return v8::Null();
+    return v8::Number::New(imp->altitudeAccuracy());
+}
+
+ACCESSOR_GETTER(CoordinatesHeading)
+{
+    INC_STATS("DOM.Coordinates.heading._get");
+    v8::Handle<v8::Object> holder = info.Holder();
+    Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder);
+    if (!imp->canProvideHeading())
+        return v8::Null();
+    return v8::Number::New(imp->heading());
+}
+
+ACCESSOR_GETTER(CoordinatesSpeed)
+{
+    INC_STATS("DOM.Coordinates.speed._get");
+    v8::Handle<v8::Object> holder = info.Holder();
+    Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder);
+    if (!imp->canProvideSpeed())
+        return v8::Null();
+    return v8::Number::New(imp->speed());
+}
+
+} // namespace WebCore
index 769a0b2010f56412799ca82ea4d7794bf952be49..4aa11523c44162bf2b311aae08a0039348fb70ad 100644 (file)
@@ -686,6 +686,13 @@ namespace WebCore {
         DECLARE_ACCESSOR_RUNTIME_ENABLER(DOMWindowWebSocket);
 #endif
 
+        DECLARE_CALLBACK(GeolocationGetCurrentPosition);
+        DECLARE_CALLBACK(GeolocationWatchPosition);
+        DECLARE_PROPERTY_ACCESSOR_GETTER(CoordinatesAltitude);
+        DECLARE_PROPERTY_ACCESSOR_GETTER(CoordinatesAltitudeAccuracy);
+        DECLARE_PROPERTY_ACCESSOR_GETTER(CoordinatesHeading);
+        DECLARE_PROPERTY_ACCESSOR_GETTER(CoordinatesSpeed);
+
 #undef DECLARE_INDEXED_ACCESS_CHECK
 #undef DECLARE_NAMED_ACCESS_CHECK
 
diff --git a/WebCore/bindings/v8/custom/V8CustomPositionCallback.cpp b/WebCore/bindings/v8/custom/V8CustomPositionCallback.cpp
new file mode 100644 (file)
index 0000000..5e9a8f2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 "V8CustomPositionCallback.h"
+
+#include "Frame.h"
+#include "V8CustomVoidCallback.h"  // For invokeCallback
+
+namespace WebCore {
+
+V8CustomPositionCallback::V8CustomPositionCallback(v8::Local<v8::Object> callback, Frame* frame)
+    : m_callback(v8::Persistent<v8::Object>::New(callback))
+    , m_frame(frame)
+{
+}
+
+V8CustomPositionCallback::~V8CustomPositionCallback()
+{
+    m_callback.Dispose();
+}
+
+void V8CustomPositionCallback::handleEvent(Geoposition* position)
+{
+    v8::HandleScope handleScope;
+
+    v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get());
+    if (context.IsEmpty())
+        return;
+
+    v8::Context::Scope scope(context);
+
+    v8::Handle<v8::Value> argv[] = {
+        V8DOMWrapper::convertToV8Object(V8ClassIndex::GEOPOSITION, position)
+    };
+
+    // Protect the frame until the callback returns.
+    RefPtr<Frame> protector(m_frame);
+
+    bool callbackReturnValue = false;
+    invokeCallback(m_callback, 1, argv, callbackReturnValue);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/v8/custom/V8CustomPositionCallback.h b/WebCore/bindings/v8/custom/V8CustomPositionCallback.h
new file mode 100644 (file)
index 0000000..d2290ee
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 V8CustomPositionCallback_h
+#define V8CustomPositionCallback_h
+
+#include "PositionCallback.h"
+#include <v8.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Frame;
+class Geoposition;
+
+class V8CustomPositionCallback : public PositionCallback {
+public:
+    static PassRefPtr<V8CustomPositionCallback> create(v8::Local<v8::Value> value, Frame* frame)
+    {
+        ASSERT(value->IsObject());
+        return adoptRef(new V8CustomPositionCallback(value->ToObject(), frame));
+    }
+    virtual ~V8CustomPositionCallback();
+
+    virtual void handleEvent(Geoposition*);
+
+private:
+    V8CustomPositionCallback(v8::Local<v8::Object>, Frame*);
+
+    v8::Persistent<v8::Object> m_callback;
+    RefPtr<Frame> m_frame;
+};
+
+} // namespace WebCore
+
+#endif // V8CustomPositionCallback_h
diff --git a/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.cpp b/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.cpp
new file mode 100644 (file)
index 0000000..117f374
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 "V8CustomPositionErrorCallback.h"
+
+#include "Frame.h"
+#include "V8CustomVoidCallback.h"  // For invokeCallback
+
+namespace WebCore {
+
+V8CustomPositionErrorCallback::V8CustomPositionErrorCallback(v8::Local<v8::Object> callback, Frame* frame)
+    : m_callback(v8::Persistent<v8::Object>::New(callback))
+    , m_frame(frame)
+{
+}
+
+V8CustomPositionErrorCallback::~V8CustomPositionErrorCallback()
+{
+    m_callback.Dispose();
+}
+
+void V8CustomPositionErrorCallback::handleEvent(PositionError* error)
+{
+    v8::HandleScope handleScope;
+
+    v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get());
+    if (context.IsEmpty())
+        return;
+
+    v8::Context::Scope scope(context);
+
+    v8::Handle<v8::Value> argv[] = {
+        V8DOMWrapper::convertToV8Object(V8ClassIndex::POSITIONERROR, error)
+    };
+
+    // Protect the frame until the callback returns.
+    RefPtr<Frame> protector(m_frame);
+
+    bool callbackReturnValue = false;
+    invokeCallback(m_callback, 1, argv, callbackReturnValue);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.h b/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.h
new file mode 100644 (file)
index 0000000..aaf56a7
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 V8CustomPositionErrorCallback_h
+#define V8CustomPositionErrorCallback_h
+
+#include "PositionErrorCallback.h"
+#include <v8.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Frame;
+class PositionError;
+
+class V8CustomPositionErrorCallback : public PositionErrorCallback {
+public:
+    static PassRefPtr<V8CustomPositionErrorCallback> create(v8::Local<v8::Value> value, Frame* frame)
+    {
+        ASSERT(value->IsObject());
+        return adoptRef(new V8CustomPositionErrorCallback(value->ToObject(), frame));
+    }
+    virtual ~V8CustomPositionErrorCallback();
+
+    virtual void handleEvent(PositionError*);
+
+private:
+    V8CustomPositionErrorCallback(v8::Local<v8::Object>, Frame*);
+
+    v8::Persistent<v8::Object> m_callback;
+    RefPtr<Frame> m_frame;
+};
+
+} // namespace WebCore
+
+#endif // V8CustomPositionErrorCallback_h
diff --git a/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp b/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp
new file mode 100644 (file)
index 0000000..011beff
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 "Geolocation.h"
+
+#include "V8Binding.h"
+#include "V8CustomBinding.h"
+#include "V8CustomPositionCallback.h"
+#include "V8CustomPositionErrorCallback.h"
+#include "V8Proxy.h"
+
+using namespace std;
+using namespace WTF;
+
+namespace WebCore {
+
+static const char typeMismatchError[] = "TYPE_MISMATCH_ERR: DOM Exception 17";
+
+static void throwTypeMismatchException()
+{
+    V8Proxy::throwError(V8Proxy::GeneralError, typeMismatchError);
+}
+
+static PassRefPtr<PositionCallback> createPositionCallback(v8::Local<v8::Value> value, bool& succeeded)
+{
+    succeeded = true;
+
+    // The spec specifies 'FunctionOnly' for this object.
+    if (!value->IsFunction()) {
+        succeeded = false;
+        throwTypeMismatchException();
+        return 0;
+    }
+
+    Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
+    return V8CustomPositionCallback::create(value, frame);
+}
+
+static PassRefPtr<PositionErrorCallback> createPositionErrorCallback(v8::Local<v8::Value> value, bool& succeeded)
+{
+    succeeded = true;
+
+    // Argument is optional (hence undefined is allowed), and null is allowed.
+    if (isUndefinedOrNull(value))
+        return 0;
+
+    // The spec specifies 'FunctionOnly' for this object.
+    if (!value->IsFunction()) {
+        succeeded = false;
+        throwTypeMismatchException();
+        return 0;
+    }
+
+    Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
+    return V8CustomPositionErrorCallback::create(value, frame);
+}
+
+static PassRefPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> value, bool& succeeded)
+{
+    succeeded = true;
+
+    // Create default options.
+    RefPtr<PositionOptions> options = PositionOptions::create();
+
+    // Argument is optional (hence undefined is allowed), and null is allowed.
+    if (isUndefinedOrNull(value)) {
+        // Use default options.
+        return options.release();
+    }
+
+    // Given the above test, this will always yield an object.
+    v8::Local<v8::Object> object = value->ToObject();
+
+    // For all three properties, we apply the following ...
+    // - If the getter or the property's valueOf method throws an exception, we
+    //   quit so as not to risk overwriting the exception.
+    // - If the value is absent or undefined, we don't override the default.
+    v8::Local<v8::Value> enableHighAccuracyValue = object->Get(v8::String::New("enableHighAccuracy"));
+    if (enableHighAccuracyValue.IsEmpty()) {
+        succeeded = false;
+        return 0;
+    }
+    if (!enableHighAccuracyValue->IsUndefined()) {
+        v8::Local<v8::Boolean> enableHighAccuracyBoolean = enableHighAccuracyValue->ToBoolean();
+        if (enableHighAccuracyBoolean.IsEmpty()) {
+            succeeded = false;
+            return 0;
+        }
+        options->setEnableHighAccuracy(enableHighAccuracyBoolean->Value());
+    }
+
+    v8::Local<v8::Value> timeoutValue = object->Get(v8::String::New("timeout"));
+    if (timeoutValue.IsEmpty()) {
+        succeeded = false;
+        return 0;
+    }
+    if (!timeoutValue->IsUndefined()) {
+        v8::Local<v8::Number> timeoutNumber = timeoutValue->ToNumber();
+        if (timeoutNumber.IsEmpty()) {
+            succeeded = false;
+            return 0;
+        }
+        double timeoutDouble = timeoutNumber->Value();
+        // If the value is positive infinity, there's nothing to do.
+        if (!(isinf(timeoutDouble) && timeoutDouble > 0)) {
+            v8::Local<v8::Int32> timeoutInt32 = timeoutValue->ToInt32();
+            if (timeoutInt32.IsEmpty()) {
+                succeeded = false;
+                return 0;
+            }
+            // Wrap to int32 and force non-negative to match behavior of window.setTimeout.
+            options->setTimeout(max(0, timeoutInt32->Value()));
+        }
+    }
+
+    v8::Local<v8::Value> maximumAgeValue = object->Get(v8::String::New("maximumAge"));
+    if (maximumAgeValue.IsEmpty()) {
+        succeeded = false;
+        return 0;
+    }
+    if (!maximumAgeValue->IsUndefined()) {
+        v8::Local<v8::Number> maximumAgeNumber = maximumAgeValue->ToNumber();
+        if (maximumAgeNumber.IsEmpty()) {
+            succeeded = false;
+            return 0;
+        }
+        double maximumAgeDouble = maximumAgeNumber->Value();
+        if (isinf(maximumAgeDouble) && maximumAgeDouble > 0) {
+            // If the value is positive infinity, clear maximumAge.
+            options->clearMaximumAge();
+        } else {
+            v8::Local<v8::Int32> maximumAgeInt32 = maximumAgeValue->ToInt32();
+            if (maximumAgeInt32.IsEmpty()) {
+                succeeded = false;
+                return 0;
+            }
+            // Wrap to int32 and force non-negative to match behavior of window.setTimeout.
+            options->setMaximumAge(max(0, maximumAgeInt32->Value()));
+        }
+    }
+
+    return options.release();
+}
+
+CALLBACK_FUNC_DECL(GeolocationGetCurrentPosition)
+{
+    INC_STATS("DOM.Geolocation.getCurrentPosition()");
+
+    bool succeeded = false;
+
+    RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded);
+    if (!succeeded)
+        return v8::Undefined();
+    ASSERT(positionCallback);
+
+    RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded);
+    if (!succeeded)
+        return v8::Undefined();
+
+    RefPtr<PositionOptions> positionOptions = createPositionOptions(args[2], succeeded);
+    if (!succeeded)
+        return v8::Undefined();
+    ASSERT(positionOptions);
+
+    Geolocation* geolocation = V8DOMWrapper::convertToNativeObject<Geolocation>(V8ClassIndex::GEOLOCATION, args.Holder());
+    geolocation->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
+    return v8::Undefined();
+}
+
+CALLBACK_FUNC_DECL(GeolocationWatchPosition)
+{
+    INC_STATS("DOM.Geolocation.watchPosition()");
+
+    bool succeeded = false;
+
+    RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded);
+    if (!succeeded)
+        return v8::Undefined();
+    ASSERT(positionCallback);
+
+    RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded);
+    if (!succeeded)
+        return v8::Undefined();
+
+    RefPtr<PositionOptions> positionOptions = createPositionOptions(args[2], succeeded);
+    if (!succeeded)
+        return v8::Undefined();
+    ASSERT(positionOptions);
+
+    Geolocation* geolocation = V8DOMWrapper::convertToNativeObject<Geolocation>(V8ClassIndex::GEOLOCATION, args.Holder());
+    int watchId = geolocation->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
+    return v8::Number::New(watchId);
+}
+
+} // namespace WebCore