[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Thu Apr 8 00:07:17 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit bc2e427e636b838c91d1bf2c9bf8ed4f51de27a3
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Dec 1 16:46:38 2009 +0000

    2009-12-01  Steve Block  <steveblock at 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.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51540 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 549257b..c0456f2 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,38 @@
+2009-12-01  Steve Block  <steveblock at 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 at chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/WebCore/WebCore.gyp/WebCore.gyp b/WebCore/WebCore.gyp/WebCore.gyp
index f178857..fe93978 100644
--- a/WebCore/WebCore.gyp/WebCore.gyp
+++ b/WebCore/WebCore.gyp/WebCore.gyp
@@ -228,13 +228,6 @@
         # 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',
 
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 8d98bac..1acccdf 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -189,6 +189,7 @@
             'page/AbstractView.idl',
             'page/BarInfo.idl',
             'page/Console.idl',
+            'page/Coordinates.idl',
             'page/DOMSelection.idl',
             'page/DOMWindow.idl',
             'page/Geolocation.idl',
@@ -651,12 +652,17 @@
             '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',
@@ -680,6 +686,7 @@
             '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',
diff --git a/WebCore/bindings/v8/DOMObjectsInclude.h b/WebCore/bindings/v8/DOMObjectsInclude.h
index e5e6fe4..7855809 100644
--- a/WebCore/bindings/v8/DOMObjectsInclude.h
+++ b/WebCore/bindings/v8/DOMObjectsInclude.h
@@ -185,6 +185,12 @@
 #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"
diff --git a/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp b/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
index cffc2fb..b32d7d4 100644
--- a/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
+++ b/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
@@ -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"
@@ -102,6 +103,8 @@
 #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"
@@ -198,6 +201,7 @@
 #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"
diff --git a/WebCore/bindings/v8/V8Index.cpp b/WebCore/bindings/v8/V8Index.cpp
index f312b27..2b9a922 100644
--- a/WebCore/bindings/v8/V8Index.cpp
+++ b/WebCore/bindings/v8/V8Index.cpp
@@ -438,6 +438,12 @@
 #include "V8InspectorFrontendHost.h"
 #endif
 
+// Geolocation
+#include "V8Coordinates.h"
+#include "V8Geolocation.h"
+#include "V8Geoposition.h"
+#include "V8PositionError.h"
+
 namespace WebCore {
 
 FunctionTemplateFactory V8ClassIndex::GetFactory(V8WrapperType type)
diff --git a/WebCore/bindings/v8/V8Index.h b/WebCore/bindings/v8/V8Index.h
index 6f879b9..1c87d25 100644
--- a/WebCore/bindings/v8/V8Index.h
+++ b/WebCore/bindings/v8/V8Index.h
@@ -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
index 0000000..1c07f29
--- /dev/null
+++ b/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp
@@ -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
diff --git a/WebCore/bindings/v8/custom/V8CustomBinding.h b/WebCore/bindings/v8/custom/V8CustomBinding.h
index 769a0b2..4aa1152 100644
--- a/WebCore/bindings/v8/custom/V8CustomBinding.h
+++ b/WebCore/bindings/v8/custom/V8CustomBinding.h
@@ -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
index 0000000..5e9a8f2
--- /dev/null
+++ b/WebCore/bindings/v8/custom/V8CustomPositionCallback.cpp
@@ -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
index 0000000..d2290ee
--- /dev/null
+++ b/WebCore/bindings/v8/custom/V8CustomPositionCallback.h
@@ -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
index 0000000..117f374
--- /dev/null
+++ b/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.cpp
@@ -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
index 0000000..aaf56a7
--- /dev/null
+++ b/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.h
@@ -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
index 0000000..011beff
--- /dev/null
+++ b/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp
@@ -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

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list