This source file includes following definitions.
- createPositionOptions
- getCurrentPositionMethodCustom
- watchPositionMethodCustom
#include "config.h"
#include "V8Geolocation.h"
#include "V8PositionCallback.h"
#include "V8PositionErrorCallback.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8Callback.h"
#include "modules/geolocation/Geolocation.h"
using namespace std;
using namespace WTF;
namespace WebCore {
static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> value, v8::Isolate* isolate, bool& succeeded)
{
succeeded = true;
RefPtrWillBeRawPtr<PositionOptions> options = PositionOptions::create();
if (isUndefinedOrNull(value)) {
return options.release();
}
v8::Local<v8::Object> object = value->ToObject();
v8::Local<v8::Value> enableHighAccuracyValue = object->Get(v8AtomicString(isolate, "enableHighAccuracy"));
if (enableHighAccuracyValue.IsEmpty()) {
succeeded = false;
return nullptr;
}
if (!enableHighAccuracyValue->IsUndefined()) {
v8::Local<v8::Boolean> enableHighAccuracyBoolean = enableHighAccuracyValue->ToBoolean();
if (enableHighAccuracyBoolean.IsEmpty()) {
succeeded = false;
return nullptr;
}
options->setEnableHighAccuracy(enableHighAccuracyBoolean->Value());
}
v8::Local<v8::Value> timeoutValue = object->Get(v8AtomicString(isolate, "timeout"));
if (timeoutValue.IsEmpty()) {
succeeded = false;
return nullptr;
}
if (!timeoutValue->IsUndefined()) {
v8::Local<v8::Number> timeoutNumber = timeoutValue->ToNumber();
if (timeoutNumber.IsEmpty()) {
succeeded = false;
return nullptr;
}
double timeoutDouble = timeoutNumber->Value();
if (!(std::isinf(timeoutDouble) && timeoutDouble > 0)) {
v8::Local<v8::Int32> timeoutInt32 = timeoutValue->ToInt32();
if (timeoutInt32.IsEmpty()) {
succeeded = false;
return nullptr;
}
options->setTimeout(max(0, timeoutInt32->Value()));
}
}
v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "maximumAge"));
if (maximumAgeValue.IsEmpty()) {
succeeded = false;
return nullptr;
}
if (!maximumAgeValue->IsUndefined()) {
v8::Local<v8::Number> maximumAgeNumber = maximumAgeValue->ToNumber();
if (maximumAgeNumber.IsEmpty()) {
succeeded = false;
return nullptr;
}
double maximumAgeDouble = maximumAgeNumber->Value();
if (std::isinf(maximumAgeDouble) && maximumAgeDouble > 0) {
options->clearMaximumAge();
} else {
v8::Local<v8::Int32> maximumAgeInt32 = maximumAgeValue->ToInt32();
if (maximumAgeInt32.IsEmpty()) {
succeeded = false;
return nullptr;
}
options->setMaximumAge(max(0, maximumAgeInt32->Value()));
}
}
return options.release();
}
void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
bool succeeded = false;
ExceptionState exceptionState(ExceptionState::ExecutionContext, "getCurrentPosition", "Geolocation", info.Holder(), info.GetIsolate());
OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8PositionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState);
if (!succeeded)
return;
ASSERT(positionCallback);
OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptionState, CallbackAllowUndefined | CallbackAllowNull);
if (!succeeded)
return;
RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(info[2], info.GetIsolate(), succeeded);
if (!succeeded)
return;
ASSERT(positionOptions);
Geolocation* geolocation = V8Geolocation::toNative(info.Holder());
geolocation->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
}
void V8Geolocation::watchPositionMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
bool succeeded = false;
ExceptionState exceptionState(ExceptionState::ExecutionContext, "watchCurrentPosition", "Geolocation", info.Holder(), info.GetIsolate());
OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8PositionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState);
if (!succeeded)
return;
ASSERT(positionCallback);
OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptionState, CallbackAllowUndefined | CallbackAllowNull);
if (!succeeded)
return;
RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(info[2], info.GetIsolate(), succeeded);
if (!succeeded)
return;
ASSERT(positionOptions);
Geolocation* geolocation = V8Geolocation::toNative(info.Holder());
int watchId = geolocation->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
v8SetReturnValue(info, watchId);
}
}