Commit bc2e427e authored by eric@webkit.org's avatar eric@webkit.org

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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51540 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0f5ad84b
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.
......@@ -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',
......
......@@ -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',
......
......@@ -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"
......
......@@ -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"
......
......@@ -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)
......
......@@ -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.
......
/*
* 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
......@@ -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
......
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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()));
}
}