summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-08-07 08:52:42 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-08-07 08:52:42 -0700
commit3b019d46a57ef711ce94c60fe542baa7c22c4995 (patch)
tree9d8be827a89b44880d4f3566e280678097e89534
parente9b13fd506940552be878cad0aa936e1b8091b47 (diff)
parent8a1e59b214bfd5b55c4d1332154e0e992571bf27 (diff)
downloadexternal_webkit-3b019d46a57ef711ce94c60fe542baa7c22c4995.zip
external_webkit-3b019d46a57ef711ce94c60fe542baa7c22c4995.tar.gz
external_webkit-3b019d46a57ef711ce94c60fe542baa7c22c4995.tar.bz2
Merge change 20415
* changes: Revert "Correctly sets default values for Geolocation PositionOptions."
-rw-r--r--WebCore/bindings/js/JSGeolocationCustom.cpp173
-rw-r--r--WebCore/page/Geolocation.cpp6
-rw-r--r--WebCore/page/PositionOptions.h29
3 files changed, 83 insertions, 125 deletions
diff --git a/WebCore/bindings/js/JSGeolocationCustom.cpp b/WebCore/bindings/js/JSGeolocationCustom.cpp
index 5ecd227..493166c 100644
--- a/WebCore/bindings/js/JSGeolocationCustom.cpp
+++ b/WebCore/bindings/js/JSGeolocationCustom.cpp
@@ -39,140 +39,109 @@ using namespace JSC;
namespace WebCore {
-const long PositionOptions::infinity = -1;
-
-static PassRefPtr<PositionCallback> createPositionCallback(ExecState* exec, JSValue value)
+static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValue value)
{
- JSObject* object = value.getObject();
- if (!object) {
- setDOMException(exec, TYPE_MISMATCH_ERR);
+ if (!value.isObject())
return 0;
- }
- Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame();
- ASSERT(frame);
- return JSCustomPositionCallback::create(object, frame);
-}
+ JSObject* object = asObject(value);
-static PassRefPtr<PositionErrorCallback> createPositionErrorCallback(ExecState* exec, JSValue value)
-{
- // No value is OK.
- if (value.isUndefinedOrNull()) {
+ JSValue enableHighAccuracyValue = object->get(exec, Identifier(exec, "enableHighAccuracy"));
+ if (exec->hadException())
+ return 0;
+ bool enableHighAccuracy = enableHighAccuracyValue.toBoolean(exec);
+ if (exec->hadException())
return 0;
- }
- JSObject* object = value.getObject();
- if (!object) {
- setDOMException(exec, TYPE_MISMATCH_ERR);
+ JSValue timeoutValue = object->get(exec, Identifier(exec, "timeout"));
+ if (exec->hadException())
+ return 0;
+ unsigned timeout = timeoutValue.toUInt32(exec);
+ if (exec->hadException())
return 0;
- }
- Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame();
- ASSERT(frame);
- return JSCustomPositionErrorCallback::create(object, frame);
-}
+ JSValue maximumAgeValue = object->get(exec, Identifier(exec, "maximumAge"));
+ if (exec->hadException())
+ return 0;
+ unsigned maximumAge = maximumAgeValue.toUInt32(exec);
+ if (exec->hadException())
+ return 0;
-// If value represents a non-negative number, the value is truncated to a long
-// and assigned to result, and the function returns true. Otherwise, result is
-// not set, and the function returns false.
-static bool getNonNegativeLong(ExecState* exec, const JSValue& value, long* result)
-{
- if (!value.isNumber() || (value.toNumber(exec) < 0)) {
- return false;
- }
- *result = value.toNumber(exec);
- return true;
+ return PositionOptions::create(enableHighAccuracy, timeout, maximumAge);
}
-static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValue value)
+JSValue JSGeolocation::getCurrentPosition(ExecState* exec, const ArgList& args)
{
- // Create default options.
- RefPtr<PositionOptions> options = PositionOptions::create();
-
- if (value.isUndefinedOrNull()) {
- // Use default options.
- return options;
- }
-
- JSObject* object = value.getObject();
+ // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
+ RefPtr<PositionCallback> positionCallback;
+ JSObject* object = args.at(0).getObject();
+ if (exec->hadException())
+ return jsUndefined();
if (!object) {
setDOMException(exec, TYPE_MISMATCH_ERR);
- return 0;
+ return jsUndefined();
}
- JSValue enableHighAccuracyValue = object->get(exec, Identifier(exec, "enableHighAccuracy"));
- if (!enableHighAccuracyValue.isUndefinedOrNull()) {
- if (!enableHighAccuracyValue.isBoolean()) {
+ if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame())
+ positionCallback = JSCustomPositionCallback::create(object, frame);
+
+ RefPtr<PositionErrorCallback> positionErrorCallback;
+ if (!args.at(1).isUndefinedOrNull()) {
+ JSObject* object = args.at(1).getObject();
+ if (!object) {
setDOMException(exec, TYPE_MISMATCH_ERR);
- return 0;
+ return jsUndefined();
}
- options->setEnableHighAccuracy(enableHighAccuracyValue.toBoolean(exec));
- }
- JSValue timeoutValue = object->get(exec, Identifier(exec, "timeout"));
- if (!timeoutValue.isUndefinedOrNull()) {
- long timeout;
- if (getNonNegativeLong(exec, timeoutValue, &timeout))
- options->setTimeout(timeout);
- else {
- setDOMException(exec, TYPE_MISMATCH_ERR);
- return 0;
- }
+ if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame())
+ positionErrorCallback = JSCustomPositionErrorCallback::create(object, frame);
}
-
- JSValue maximumAgeValue = object->get(exec, Identifier(exec, "maximumAge"));
- if (!maximumAgeValue.isUndefinedOrNull()) {
- long maximumAge;
- if (getNonNegativeLong(exec, maximumAgeValue, &maximumAge))
- options->setTimeout(maximumAge);
- else {
- setDOMException(exec, TYPE_MISMATCH_ERR);
- return 0;
- }
+
+ RefPtr<PositionOptions> positionOptions;
+ if (!args.at(2).isUndefinedOrNull()) {
+ positionOptions = createPositionOptions(exec, args.at(2));
+ if (exec->hadException())
+ return jsUndefined();
}
- return options;
-}
-
-JSValue JSGeolocation::getCurrentPosition(ExecState* exec, const ArgList& args)
-{
- // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
-
- RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, args.at(0));
- if (exec->hadException())
- return jsUndefined();
- ASSERT(positionCallback);
-
- RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, args.at(1));
- if (exec->hadException())
- return jsUndefined();
-
- RefPtr<PositionOptions> positionOptions = createPositionOptions(exec, args.at(2));
- if (exec->hadException())
- return jsUndefined();
- ASSERT(positionOptions);
-
m_impl->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
+
return jsUndefined();
}
JSValue JSGeolocation::watchPosition(ExecState* exec, const ArgList& args)
{
// Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
-
- RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, args.at(0));
- if (exec->hadException())
- return jsUndefined();
- ASSERT(positionCallback);
-
- RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, args.at(1));
+ RefPtr<PositionCallback> positionCallback;
+ JSObject* object = args.at(0).getObject();
if (exec->hadException())
return jsUndefined();
-
- RefPtr<PositionOptions> positionOptions = createPositionOptions(exec, args.at(2));
- if (exec->hadException())
+ if (!object) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
return jsUndefined();
- ASSERT(positionOptions);
+ }
+
+ if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame())
+ positionCallback = JSCustomPositionCallback::create(object, frame);
+
+ RefPtr<PositionErrorCallback> positionErrorCallback;
+ if (!args.at(1).isUndefinedOrNull()) {
+ JSObject* object = args.at(1).getObject();
+ if (!object) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame())
+ positionErrorCallback = JSCustomPositionErrorCallback::create(object, frame);
+ }
+
+ RefPtr<PositionOptions> positionOptions;
+ if (!args.at(2).isUndefinedOrNull()) {
+ positionOptions = createPositionOptions(exec, args.at(2));
+ if (exec->hadException())
+ return jsUndefined();
+ }
int watchID = m_impl->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
return jsNumber(exec, watchID);
diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp
index 8bfa093..7010339 100644
--- a/WebCore/page/Geolocation.cpp
+++ b/WebCore/page/Geolocation.cpp
@@ -40,15 +40,11 @@ Geolocation::GeoNotifier::GeoNotifier(PassRefPtr<PositionCallback> successCallba
, m_options(options)
, m_timer(this, &Geolocation::GeoNotifier::timerFired)
{
- ASSERT(m_successCallback);
- // If no options were supplied from JS, we should have created a default set
- // of options in JSGeolocationCustom.cpp.
- ASSERT(m_options);
}
void Geolocation::GeoNotifier::startTimer()
{
- if (m_errorCallback && m_options->timeout() != PositionOptions::infinity)
+ if (m_errorCallback && m_options)
m_timer.startOneShot(m_options->timeout() / 1000.0);
}
diff --git a/WebCore/page/PositionOptions.h b/WebCore/page/PositionOptions.h
index a513f61..10845d3 100644
--- a/WebCore/page/PositionOptions.h
+++ b/WebCore/page/PositionOptions.h
@@ -33,33 +33,26 @@ namespace WebCore {
class PositionOptions : public RefCounted<PositionOptions> {
public:
- static const long infinity;
- static PassRefPtr<PositionOptions> create() { return adoptRef(new PositionOptions()); }
+ static PassRefPtr<PositionOptions> create(bool highAccuracy, unsigned timeout, unsigned maximumAge) { return adoptRef(new PositionOptions(highAccuracy, timeout, maximumAge)); }
bool enableHighAccuracy() const { return m_highAccuracy; }
void setEnableHighAccuracy(bool enable) { m_highAccuracy = enable; }
- long timeout() const { return m_timeout; }
- void setTimeout(long t) {
- ASSERT(t == infinity || t >= 0);
- m_timeout = t;
- }
- long maximumAge() const { return m_maximumAge; }
- void setMaximumAge(long a) {
- ASSERT(a == infinity || a >= 0);
- m_maximumAge = a;
- }
+ unsigned timeout() const { return m_timeout; }
+ void setTimeout(unsigned t) { m_timeout = t; }
+ unsigned maximumAge() const { return m_maximumAge; }
+ void setMaximumAge(unsigned a) { m_maximumAge = a; }
private:
- PositionOptions()
- : m_highAccuracy(false)
- , m_timeout(infinity)
- , m_maximumAge(0)
+ PositionOptions(bool highAccuracy, unsigned timeout, unsigned maximumAge)
+ : m_highAccuracy(highAccuracy)
+ , m_timeout(timeout)
+ , m_maximumAge(maximumAge)
{
}
bool m_highAccuracy;
- long m_timeout;
- long m_maximumAge;
+ unsigned m_timeout;
+ unsigned m_maximumAge;
};
} // namespace WebCore