| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, The Android Open Source Project | 2 * Copyright 2009, The Android Open Source Project |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * * Redistributions of source code must retain the above copyright | 7 * * Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * * Redistributions in binary form must reproduce the above copyright | 9 * * Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "bindings/modules/v8/V8PositionErrorCallback.h" | 30 #include "bindings/modules/v8/V8PositionErrorCallback.h" |
| 31 #include "bindings/v8/V8Binding.h" | 31 #include "bindings/v8/V8Binding.h" |
| 32 #include "bindings/v8/V8Callback.h" | 32 #include "bindings/v8/V8Callback.h" |
| 33 #include "modules/geolocation/Geolocation.h" | 33 #include "modules/geolocation/Geolocation.h" |
| 34 | 34 |
| 35 using namespace std; | 35 using namespace std; |
| 36 using namespace WTF; | 36 using namespace WTF; |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v
8::Value> value, v8::Isolate* isolate, bool& succeeded, ExceptionState& exceptio
nState) | 40 static PositionOptions* createPositionOptions(v8::Local<v8::Value> value, v8::Is
olate* isolate, bool& succeeded, ExceptionState& exceptionState) |
| 41 { | 41 { |
| 42 succeeded = true; | 42 succeeded = true; |
| 43 | 43 |
| 44 // Create default options. | 44 // Create default options. |
| 45 RefPtrWillBeRawPtr<PositionOptions> options = PositionOptions::create(); | 45 PositionOptions* options = PositionOptions::create(); |
| 46 | 46 |
| 47 // Argument is optional (hence undefined is allowed), and null is allowed. | 47 // Argument is optional (hence undefined is allowed), and null is allowed. |
| 48 if (isUndefinedOrNull(value)) { | 48 if (isUndefinedOrNull(value)) { |
| 49 // Use default options. | 49 // Use default options. |
| 50 return options.release(); | 50 return options; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Given the above test, this will always yield an object. | 53 // Given the above test, this will always yield an object. |
| 54 v8::Local<v8::Object> object = value->ToObject(); | 54 v8::Local<v8::Object> object = value->ToObject(); |
| 55 | 55 |
| 56 // For all three properties, we apply the following ... | 56 // For all three properties, we apply the following ... |
| 57 // - If the getter or the property's valueOf method throws an exception, we | 57 // - If the getter or the property's valueOf method throws an exception, we |
| 58 // quit so as not to risk overwriting the exception. | 58 // quit so as not to risk overwriting the exception. |
| 59 // - If the value is absent or undefined, we don't override the default. | 59 // - If the value is absent or undefined, we don't override the default. |
| 60 v8::Local<v8::Value> enableHighAccuracyValue = object->Get(v8AtomicString(is
olate, "enableHighAccuracy")); | 60 v8::Local<v8::Value> enableHighAccuracyValue = object->Get(v8AtomicString(is
olate, "enableHighAccuracy")); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (maximumAgeNumber.IsEmpty()) { | 98 if (maximumAgeNumber.IsEmpty()) { |
| 99 succeeded = false; | 99 succeeded = false; |
| 100 return nullptr; | 100 return nullptr; |
| 101 } | 101 } |
| 102 if (maximumAgeNumber->Value() <= 0) | 102 if (maximumAgeNumber->Value() <= 0) |
| 103 options->setMaximumAge(0); | 103 options->setMaximumAge(0); |
| 104 else | 104 else |
| 105 options->setMaximumAge(toUInt32(maximumAgeValue, Clamp, exceptionSta
te)); | 105 options->setMaximumAge(toUInt32(maximumAgeValue, Clamp, exceptionSta
te)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 return options.release(); | 108 return options; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) | 111 void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 112 { | 112 { |
| 113 bool succeeded = false; | 113 bool succeeded = false; |
| 114 | 114 |
| 115 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getCurrentP
osition", "Geolocation", info.Holder(), info.GetIsolate()); | 115 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getCurrentP
osition", "Geolocation", info.Holder(), info.GetIsolate()); |
| 116 | 116 |
| 117 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); | 117 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); |
| 118 if (!succeeded) | 118 if (!succeeded) |
| 119 return; | 119 return; |
| 120 ASSERT(positionCallback); | 120 ASSERT(positionCallback); |
| 121 | 121 |
| 122 // Argument is optional (hence undefined is allowed), and null is allowed. | 122 // Argument is optional (hence undefined is allowed), and null is allowed. |
| 123 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); | 123 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); |
| 124 if (!succeeded) | 124 if (!succeeded) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(
info[2], info.GetIsolate(), succeeded, exceptionState); | 127 PositionOptions* positionOptions = createPositionOptions(info[2], info.GetIs
olate(), succeeded, exceptionState); |
| 128 if (!succeeded) | 128 if (!succeeded) |
| 129 return; | 129 return; |
| 130 ASSERT(positionOptions); | 130 ASSERT(positionOptions); |
| 131 | 131 |
| 132 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); | 132 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); |
| 133 geolocation->getCurrentPosition(positionCallback.release(), positionErrorCal
lback.release(), positionOptions.release()); | 133 geolocation->getCurrentPosition(positionCallback.release(), positionErrorCal
lback.release(), positionOptions); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void V8Geolocation::watchPositionMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) | 136 void V8Geolocation::watchPositionMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) |
| 137 { | 137 { |
| 138 bool succeeded = false; | 138 bool succeeded = false; |
| 139 | 139 |
| 140 ExceptionState exceptionState(ExceptionState::ExecutionContext, "watchCurren
tPosition", "Geolocation", info.Holder(), info.GetIsolate()); | 140 ExceptionState exceptionState(ExceptionState::ExecutionContext, "watchCurren
tPosition", "Geolocation", info.Holder(), info.GetIsolate()); |
| 141 | 141 |
| 142 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); | 142 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); |
| 143 if (!succeeded) | 143 if (!succeeded) |
| 144 return; | 144 return; |
| 145 ASSERT(positionCallback); | 145 ASSERT(positionCallback); |
| 146 | 146 |
| 147 // Argument is optional (hence undefined is allowed), and null is allowed. | 147 // Argument is optional (hence undefined is allowed), and null is allowed. |
| 148 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); | 148 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); |
| 149 if (!succeeded) | 149 if (!succeeded) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(
info[2], info.GetIsolate(), succeeded, exceptionState); | 152 PositionOptions* positionOptions = createPositionOptions(info[2], info.GetIs
olate(), succeeded, exceptionState); |
| 153 if (!succeeded) | 153 if (!succeeded) |
| 154 return; | 154 return; |
| 155 ASSERT(positionOptions); | 155 ASSERT(positionOptions); |
| 156 | 156 |
| 157 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); | 157 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); |
| 158 int watchId = geolocation->watchPosition(positionCallback.release(), positio
nErrorCallback.release(), positionOptions.release()); | 158 int watchId = geolocation->watchPosition(positionCallback.release(), positio
nErrorCallback.release(), positionOptions); |
| 159 v8SetReturnValue(info, watchId); | 159 v8SetReturnValue(info, watchId); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace WebCore | 162 } // namespace WebCore |
| OLD | NEW |