| 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 "V8PositionErrorCallback.h" | 30 #include "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) | 40 static PassRefPtrWillBeRawPtr<PositionOptions> createPositionOptions(v8::Local<v
8::Value> value, v8::Isolate* isolate, bool& succeeded, ExceptionState& exceptio
nState) |
| 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 RefPtrWillBeRawPtr<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.release(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 78 } | 78 } |
| 79 if (!timeoutValue->IsUndefined()) { | 79 if (!timeoutValue->IsUndefined()) { |
| 80 v8::Local<v8::Number> timeoutNumber = timeoutValue->ToNumber(); | 80 v8::Local<v8::Number> timeoutNumber = timeoutValue->ToNumber(); |
| 81 if (timeoutNumber.IsEmpty()) { | 81 if (timeoutNumber.IsEmpty()) { |
| 82 succeeded = false; | 82 succeeded = false; |
| 83 return nullptr; | 83 return nullptr; |
| 84 } | 84 } |
| 85 double timeoutDouble = timeoutNumber->Value(); | 85 double timeoutDouble = timeoutNumber->Value(); |
| 86 // If the value is positive infinity, there's nothing to do. | 86 // If the value is positive infinity, there's nothing to do. |
| 87 if (!(std::isinf(timeoutDouble) && timeoutDouble > 0)) { | 87 if (!(std::isinf(timeoutDouble) && timeoutDouble > 0)) { |
| 88 v8::Local<v8::Int32> timeoutInt32 = timeoutValue->ToInt32(); | 88 if (timeoutDouble <= 0) { |
| 89 if (timeoutInt32.IsEmpty()) { | 89 options->setTimeout(0); |
| 90 succeeded = false; | 90 } else { |
| 91 return nullptr; | 91 options->setTimeout(toUInt32(timeoutValue, Clamp, exceptionState
)); |
| 92 } | 92 } |
| 93 // Wrap to int32 and force non-negative to match behavior of window.
setTimeout. | |
| 94 options->setTimeout(max(0, timeoutInt32->Value())); | |
| 95 } | 93 } |
| 96 } | 94 } |
| 97 | 95 |
| 98 v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "
maximumAge")); | 96 v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "
maximumAge")); |
| 99 if (maximumAgeValue.IsEmpty()) { | 97 if (maximumAgeValue.IsEmpty()) { |
| 100 succeeded = false; | 98 succeeded = false; |
| 101 return nullptr; | 99 return nullptr; |
| 102 } | 100 } |
| 103 if (!maximumAgeValue->IsUndefined()) { | 101 if (!maximumAgeValue->IsUndefined()) { |
| 104 v8::Local<v8::Number> maximumAgeNumber = maximumAgeValue->ToNumber(); | 102 v8::Local<v8::Number> maximumAgeNumber = maximumAgeValue->ToNumber(); |
| 105 if (maximumAgeNumber.IsEmpty()) { | 103 if (maximumAgeNumber.IsEmpty()) { |
| 106 succeeded = false; | 104 succeeded = false; |
| 107 return nullptr; | 105 return nullptr; |
| 108 } | 106 } |
| 109 double maximumAgeDouble = maximumAgeNumber->Value(); | 107 double maximumAgeDouble = maximumAgeNumber->Value(); |
| 110 if (std::isinf(maximumAgeDouble) && maximumAgeDouble > 0) { | 108 if (std::isinf(maximumAgeDouble) && maximumAgeDouble > 0) { |
| 111 // If the value is positive infinity, clear maximumAge. | 109 // If the value is positive infinity, clear maximumAge. |
| 112 options->clearMaximumAge(); | 110 options->clearMaximumAge(); |
| 113 } else { | 111 } else { |
| 114 v8::Local<v8::Int32> maximumAgeInt32 = maximumAgeValue->ToInt32(); | 112 if (maximumAgeDouble <= 0) { |
| 115 if (maximumAgeInt32.IsEmpty()) { | 113 options->setMaximumAge(0); |
| 116 succeeded = false; | 114 } else { |
| 117 return nullptr; | 115 options->setMaximumAge(toUInt32(maximumAgeValue, Clamp, exceptio
nState)); |
| 118 } | 116 } |
| 119 // Wrap to int32 and force non-negative to match behavior of window.
setTimeout. | |
| 120 options->setMaximumAge(max(0, maximumAgeInt32->Value())); | |
| 121 } | 117 } |
| 122 } | 118 } |
| 123 | 119 |
| 124 return options.release(); | 120 return options.release(); |
| 125 } | 121 } |
| 126 | 122 |
| 127 void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) | 123 void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 128 { | 124 { |
| 129 bool succeeded = false; | 125 bool succeeded = false; |
| 130 | 126 |
| 131 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getCurrentP
osition", "Geolocation", info.Holder(), info.GetIsolate()); | 127 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getCurrentP
osition", "Geolocation", info.Holder(), info.GetIsolate()); |
| 132 | 128 |
| 133 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); | 129 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); |
| 134 if (!succeeded) | 130 if (!succeeded) |
| 135 return; | 131 return; |
| 136 ASSERT(positionCallback); | 132 ASSERT(positionCallback); |
| 137 | 133 |
| 138 // Argument is optional (hence undefined is allowed), and null is allowed. | 134 // Argument is optional (hence undefined is allowed), and null is allowed. |
| 139 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); | 135 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); |
| 140 if (!succeeded) | 136 if (!succeeded) |
| 141 return; | 137 return; |
| 142 | 138 |
| 143 RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(
info[2], info.GetIsolate(), succeeded); | 139 RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(
info[2], info.GetIsolate(), succeeded, exceptionState); |
| 144 if (!succeeded) | 140 if (!succeeded) |
| 145 return; | 141 return; |
| 146 ASSERT(positionOptions); | 142 ASSERT(positionOptions); |
| 147 | 143 |
| 148 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); | 144 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); |
| 149 geolocation->getCurrentPosition(positionCallback.release(), positionErrorCal
lback.release(), positionOptions.release()); | 145 geolocation->getCurrentPosition(positionCallback.release(), positionErrorCal
lback.release(), positionOptions.release()); |
| 150 } | 146 } |
| 151 | 147 |
| 152 void V8Geolocation::watchPositionMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) | 148 void V8Geolocation::watchPositionMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) |
| 153 { | 149 { |
| 154 bool succeeded = false; | 150 bool succeeded = false; |
| 155 | 151 |
| 156 ExceptionState exceptionState(ExceptionState::ExecutionContext, "watchCurren
tPosition", "Geolocation", info.Holder(), info.GetIsolate()); | 152 ExceptionState exceptionState(ExceptionState::ExecutionContext, "watchCurren
tPosition", "Geolocation", info.Holder(), info.GetIsolate()); |
| 157 | 153 |
| 158 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); | 154 OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8Pos
itionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState); |
| 159 if (!succeeded) | 155 if (!succeeded) |
| 160 return; | 156 return; |
| 161 ASSERT(positionCallback); | 157 ASSERT(positionCallback); |
| 162 | 158 |
| 163 // Argument is optional (hence undefined is allowed), and null is allowed. | 159 // Argument is optional (hence undefined is allowed), and null is allowed. |
| 164 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); | 160 OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCall
back<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptio
nState, CallbackAllowUndefined | CallbackAllowNull); |
| 165 if (!succeeded) | 161 if (!succeeded) |
| 166 return; | 162 return; |
| 167 | 163 |
| 168 RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(
info[2], info.GetIsolate(), succeeded); | 164 RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(
info[2], info.GetIsolate(), succeeded, exceptionState); |
| 169 if (!succeeded) | 165 if (!succeeded) |
| 170 return; | 166 return; |
| 171 ASSERT(positionOptions); | 167 ASSERT(positionOptions); |
| 172 | 168 |
| 173 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); | 169 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); |
| 174 int watchId = geolocation->watchPosition(positionCallback.release(), positio
nErrorCallback.release(), positionOptions.release()); | 170 int watchId = geolocation->watchPosition(positionCallback.release(), positio
nErrorCallback.release(), positionOptions.release()); |
| 175 v8SetReturnValue(info, watchId); | 171 v8SetReturnValue(info, watchId); |
| 176 } | 172 } |
| 177 | 173 |
| 178 } // namespace WebCore | 174 } // namespace WebCore |
| OLD | NEW |