diff options
Diffstat (limited to 'WebCore/bindings/v8')
-rw-r--r-- | WebCore/bindings/v8/NPV8Object.cpp | 10 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptController.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptController.h | 4 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptFunctionCall.cpp | 72 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptFunctionCall.h | 27 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8DOMWindowShell.cpp | 17 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8Proxy.cpp | 17 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8Proxy.h | 6 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8ClipboardCustom.cpp | 2 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp | 10 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp | 8 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DOMTokenListCustom.cpp | 56 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp | 146 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp | 6 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DirectoryEntryCustom.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp | 2 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp | 3 |
17 files changed, 291 insertions, 103 deletions
diff --git a/WebCore/bindings/v8/NPV8Object.cpp b/WebCore/bindings/v8/NPV8Object.cpp index fb97d59..e4be0d8 100644 --- a/WebCore/bindings/v8/NPV8Object.cpp +++ b/WebCore/bindings/v8/NPV8Object.cpp @@ -34,6 +34,7 @@ #include "OwnArrayPtr.h" #include "PlatformString.h" #include "ScriptController.h" +#include "UserGestureIndicator.h" #include "V8GCController.h" #include "V8Helpers.h" #include "V8NPUtils.h" @@ -278,8 +279,17 @@ bool _NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npObject, NPStri if (!popupsAllowed) filename = "npscript"; + // Set popupsAllowed flag to the current execution frame, so WebKit can get + // right gesture status for popups initiated from plugins. + Frame* frame = proxy->frame(); + ASSERT(frame); + bool oldAllowPopups = frame->script()->allowPopupsFromPlugin(); + frame->script()->setAllowPopupsFromPlugin(popupsAllowed); + String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length); v8::Local<v8::Value> v8result = proxy->evaluate(ScriptSourceCode(script, KURL(ParsedURLString, filename)), 0); + // Restore the old flag. + frame->script()->setAllowPopupsFromPlugin(oldAllowPopups); if (v8result.IsEmpty()) return false; diff --git a/WebCore/bindings/v8/ScriptController.cpp b/WebCore/bindings/v8/ScriptController.cpp index 5023254..8018a18 100644 --- a/WebCore/bindings/v8/ScriptController.cpp +++ b/WebCore/bindings/v8/ScriptController.cpp @@ -121,6 +121,7 @@ ScriptController::ScriptController(Frame* frame) , m_inExecuteScript(false) , m_processingTimerCallback(false) , m_paused(false) + , m_allowPopupsFromPlugin(false) , m_proxy(new V8Proxy(frame)) #if ENABLE(NETSCAPE_PLUGIN_API) , m_windowScriptNPObject(0) @@ -203,7 +204,8 @@ bool ScriptController::processingUserGesture() // This is the <a href="javascript:window.open('...')> case -> we let it through. return true; } - + if (activeFrame->script()->allowPopupsFromPlugin()) + return true; // This is the <script>window.open(...)</script> case or a timer callback -> block it. // Based on JSC version, use returned value of UserGestureIndicator::processingUserGesture for all other situations. return UserGestureIndicator::processingUserGesture(); diff --git a/WebCore/bindings/v8/ScriptController.h b/WebCore/bindings/v8/ScriptController.h index 3bc42ef..8ac9064 100644 --- a/WebCore/bindings/v8/ScriptController.h +++ b/WebCore/bindings/v8/ScriptController.h @@ -193,6 +193,9 @@ public: void evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*); static void getAllWorlds(Vector<DOMWrapperWorld*>& worlds); + void setAllowPopupsFromPlugin(bool allowPopupsFromPlugin) { m_allowPopupsFromPlugin = allowPopupsFromPlugin; } + bool allowPopupsFromPlugin() const { return m_allowPopupsFromPlugin; } + private: Frame* m_frame; const String* m_sourceURL; @@ -201,6 +204,7 @@ private: bool m_processingTimerCallback; bool m_paused; + bool m_allowPopupsFromPlugin; OwnPtr<V8Proxy> m_proxy; typedef HashMap<Widget*, NPObject*> PluginObjectMap; diff --git a/WebCore/bindings/v8/ScriptFunctionCall.cpp b/WebCore/bindings/v8/ScriptFunctionCall.cpp index e6b22ee..29dbb02 100644 --- a/WebCore/bindings/v8/ScriptFunctionCall.cpp +++ b/WebCore/bindings/v8/ScriptFunctionCall.cpp @@ -45,14 +45,7 @@ namespace WebCore { -ScriptFunctionCall::ScriptFunctionCall(const ScriptObject& thisObject, const String& name) - : m_scriptState(thisObject.scriptState()) - , m_thisObject(thisObject) - , m_name(name) -{ -} - -void ScriptFunctionCall::appendArgument(const ScriptObject& argument) +void ScriptCallArgumentHandler::appendArgument(const ScriptObject& argument) { if (argument.scriptState() != m_scriptState) { ASSERT_NOT_REACHED(); @@ -61,64 +54,71 @@ void ScriptFunctionCall::appendArgument(const ScriptObject& argument) m_arguments.append(argument); } -void ScriptFunctionCall::appendArgument(const ScriptString& argument) +void ScriptCallArgumentHandler::appendArgument(const ScriptString& argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8String(argument)); } -void ScriptFunctionCall::appendArgument(const ScriptValue& argument) +void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument) { m_arguments.append(argument); } -void ScriptFunctionCall::appendArgument(const String& argument) +void ScriptCallArgumentHandler::appendArgument(const String& argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8String(argument)); } -void ScriptFunctionCall::appendArgument(const char* argument) +void ScriptCallArgumentHandler::appendArgument(const char* argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8String(argument)); } -void ScriptFunctionCall::appendArgument(long argument) +void ScriptCallArgumentHandler::appendArgument(long argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8::Number::New(argument)); } -void ScriptFunctionCall::appendArgument(long long argument) +void ScriptCallArgumentHandler::appendArgument(long long argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8::Number::New(argument)); } -void ScriptFunctionCall::appendArgument(unsigned int argument) +void ScriptCallArgumentHandler::appendArgument(unsigned int argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8::Number::New(argument)); } -void ScriptFunctionCall::appendArgument(unsigned long argument) +void ScriptCallArgumentHandler::appendArgument(unsigned long argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8::Number::New(argument)); } -void ScriptFunctionCall::appendArgument(int argument) +void ScriptCallArgumentHandler::appendArgument(int argument) { ScriptScope scope(m_scriptState); m_arguments.append(v8::Number::New(argument)); } -void ScriptFunctionCall::appendArgument(bool argument) +void ScriptCallArgumentHandler::appendArgument(bool argument) { m_arguments.append(v8Boolean(argument)); } +ScriptFunctionCall::ScriptFunctionCall(const ScriptObject& thisObject, const String& name) + : ScriptCallArgumentHandler(thisObject.scriptState()) + , m_thisObject(thisObject) + , m_name(name) +{ +} + ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions) { ScriptScope scope(m_scriptState, reportExceptions); @@ -179,4 +179,40 @@ ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExcept return ScriptObject(m_scriptState, result); } +ScriptCallback::ScriptCallback(ScriptState* state, ScriptValue function) + : ScriptCallArgumentHandler(state) + , m_function(function) +{ +} + +ScriptValue ScriptCallback::call() +{ + bool hadException = false; + return call(hadException); +} + +ScriptValue ScriptCallback::call(bool& hadException) +{ + ASSERT(v8::Context::InContext()); + ASSERT(m_function.v8Value()->IsFunction()); + + v8::TryCatch exceptionCatcher; + v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global(); + v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(m_function.v8Value()); + + OwnArrayPtr<v8::Handle<v8::Value> > args(new v8::Handle<v8::Value>[m_arguments.size()]); + for (size_t i = 0; i < m_arguments.size(); ++i) + args[i] = m_arguments[i].v8Value(); + + v8::Handle<v8::Value> result = V8Proxy::callFunctionWithoutFrame(function, object, m_arguments.size(), args.get()); + + if (exceptionCatcher.HasCaught()) { + hadException = true; + m_scriptState->setException(exceptionCatcher.Exception()); + return ScriptValue(); + } + + return ScriptValue(result); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptFunctionCall.h b/WebCore/bindings/v8/ScriptFunctionCall.h index 4cbbf7e..04dddc8 100644 --- a/WebCore/bindings/v8/ScriptFunctionCall.h +++ b/WebCore/bindings/v8/ScriptFunctionCall.h @@ -41,10 +41,9 @@ namespace WebCore { class ScriptState; class ScriptString; - class ScriptFunctionCall { + class ScriptCallArgumentHandler { public: - ScriptFunctionCall(const ScriptObject& thisObject, const String& name); - virtual ~ScriptFunctionCall() {}; + ScriptCallArgumentHandler(ScriptState* scriptState) : m_scriptState(scriptState) { } void appendArgument(const ScriptObject&); void appendArgument(const ScriptString&); @@ -57,15 +56,33 @@ namespace WebCore { void appendArgument(unsigned long); void appendArgument(int); void appendArgument(bool); + + protected: + ScriptState* m_scriptState; + Vector<ScriptValue> m_arguments; + }; + + class ScriptFunctionCall : public ScriptCallArgumentHandler { + public: + ScriptFunctionCall(const ScriptObject& thisObject, const String& name); ScriptValue call(bool& hadException, bool reportExceptions = true); ScriptValue call(); ScriptObject construct(bool& hadException, bool reportExceptions = true); protected: - ScriptState* m_scriptState; ScriptObject m_thisObject; String m_name; - Vector<ScriptValue> m_arguments; + }; + + class ScriptCallback : public ScriptCallArgumentHandler { + public: + ScriptCallback(ScriptState*, ScriptValue); + + ScriptValue call(); + ScriptValue call(bool& hadException); + + private: + ScriptValue m_function; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/V8DOMWindowShell.cpp b/WebCore/bindings/v8/V8DOMWindowShell.cpp index f0f473d..bea1eb8 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -352,11 +352,18 @@ v8::Persistent<v8::Context> V8DOMWindowShell::createNewContext(v8::Handle<v8::Ob if (extensions[i].group && extensions[i].group != extensionGroup) continue; - // Note: we check the loader URL here instead of the document URL - // because we might be currently loading an URL into a blank page. - // See http://code.google.com/p/chromium/issues/detail?id=10924 - if (extensions[i].scheme.length() > 0 && (extensions[i].scheme != m_frame->loader()->activeDocumentLoader()->url().protocol())) - continue; + if (extensions[i].useCallback) { + // Ensure our date extension is always allowed. + if (extensions[i].extension != DateExtension::get() + && !m_frame->loader()->client()->allowScriptExtension(extensions[i].extension->name(), extensionGroup)) + continue; + } else { + // Note: we check the loader URL here instead of the document URL + // because we might be currently loading an URL into a blank page. + // See http://code.google.com/p/chromium/issues/detail?id=10924 + if (extensions[i].scheme.length() > 0 && (extensions[i].scheme != m_frame->loader()->activeDocumentLoader()->url().protocol())) + continue; + } extensionNames[index++] = extensions[i].extension->name(); } diff --git a/WebCore/bindings/v8/V8Proxy.cpp b/WebCore/bindings/v8/V8Proxy.cpp index 27e09e6..be2be07 100644 --- a/WebCore/bindings/v8/V8Proxy.cpp +++ b/WebCore/bindings/v8/V8Proxy.cpp @@ -687,11 +687,7 @@ void V8Proxy::didLeaveScriptContext() // If we've just left a script context and indexed database has been // instantiated, we must let its transaction coordinator know so it can terminate // any not-yet-started transactions. - if (IDBPendingTransactionMonitor::hasPendingTransactions()) { - ASSERT(page->group().hasIDBFactory()); - page->group().idbFactory()->abortPendingTransactions(IDBPendingTransactionMonitor::pendingTransactions()); - IDBPendingTransactionMonitor::clearPendingTransactions(); - } + IDBPendingTransactionMonitor::abortPendingTransactions(); #endif // ENABLE(INDEXED_DATABASE) // If we've just left a top level script context and local storage has been // instantiated, we must ensure that any storage locks have been freed. @@ -876,14 +872,21 @@ bool V8Proxy::registeredExtensionWithV8(v8::Extension* extension) void V8Proxy::registerExtension(v8::Extension* extension, const String& schemeRestriction) { registerExtensionWithV8(extension); - V8ExtensionInfo info = {schemeRestriction, 0, extension}; + V8ExtensionInfo info = {schemeRestriction, 0, extension, false}; m_extensions.append(info); } void V8Proxy::registerExtension(v8::Extension* extension, int extensionGroup) { registerExtensionWithV8(extension); - V8ExtensionInfo info = {String(), extensionGroup, extension}; + V8ExtensionInfo info = {String(), extensionGroup, extension, false}; + m_extensions.append(info); +} + +void V8Proxy::registerExtension(v8::Extension* extension) +{ + registerExtensionWithV8(extension); + V8ExtensionInfo info = {String(), 0, extension, true}; m_extensions.append(info); } diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h index 4d2404f..169883b 100644 --- a/WebCore/bindings/v8/V8Proxy.h +++ b/WebCore/bindings/v8/V8Proxy.h @@ -128,6 +128,7 @@ namespace WebCore { String scheme; int group; v8::Extension* extension; + bool useCallback; // FIXME: remove }; typedef WTF::Vector<V8ExtensionInfo> V8Extensions; @@ -337,6 +338,11 @@ namespace WebCore { static void registerExtension(v8::Extension*, const String& schemeRestriction); static void registerExtension(v8::Extension*, int extensionGroup); + // Same as above, but new version. + // FIXME: remove the other 2 versions in phase 3 of multipart checkin: + // https://bugs.webkit.org/show_bug.cgi?id=45721 + static void registerExtension(v8::Extension*); + static void registerExtensionWithV8(v8::Extension*); static bool registeredExtensionWithV8(v8::Extension*); diff --git a/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp b/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp index 69742f8..d85d7a0 100644 --- a/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp @@ -101,7 +101,7 @@ v8::Handle<v8::Value> V8Clipboard::setDragImageCallback(const v8::Arguments& arg INC_STATS("DOM.Clipboard.setDragImage()"); Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); - if (!clipboard->isForDragging()) + if (!clipboard->isForDragAndDrop()) return v8::Undefined(); if (args.Length() != 3) diff --git a/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp b/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp index 25e7e0d..11f309b 100644 --- a/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp @@ -66,6 +66,7 @@ void V8CustomVoidCallback::handleEvent() bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext) { v8::TryCatch exceptionCatcher; + exceptionCatcher.SetVerbose(true); v8::Local<v8::Function> callbackFunction; if (callback->IsFunction()) { @@ -84,14 +85,7 @@ bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8 v8::Handle<v8::Value> result = callbackFunction->Call(thisObject, argc, argv); callbackReturnValue = !result.IsEmpty() && result->BooleanValue(); - - if (exceptionCatcher.HasCaught()) { - v8::Local<v8::Message> message = exceptionCatcher.Message(); - scriptExecutionContext->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName())); - return true; - } - - return false; + return exceptionCatcher.HasCaught(); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp b/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp index c8a975b..71ff357 100644 --- a/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp @@ -34,6 +34,7 @@ #include "DOMStringMap.h" #include "V8Binding.h" #include "V8DOMWrapper.h" +#include "V8Element.h" namespace WebCore { @@ -101,8 +102,11 @@ v8::Handle<v8::Value> toV8(DOMStringMap* impl) v8::Handle<v8::Object> wrapper = V8DOMStringMap::wrap(impl); // Add a hidden reference from the element to the DOMStringMap. Element* element = impl->element(); - if (!wrapper.IsEmpty() && element) - V8DOMWrapper::setHiddenWindowReference(element->document()->frame(), wrapper); + if (!wrapper.IsEmpty() && element) { + v8::Handle<v8::Value> elementValue = toV8(element); + if (!elementValue.IsEmpty() && elementValue->IsObject()) + V8DOMWrapper::setHiddenReference(elementValue.As<v8::Object>(), wrapper); + } return wrapper; } diff --git a/WebCore/bindings/v8/custom/V8DOMTokenListCustom.cpp b/WebCore/bindings/v8/custom/V8DOMTokenListCustom.cpp new file mode 100644 index 0000000..171ff5c --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DOMTokenListCustom.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 "V8DOMTokenList.h" + +#include "DOMTokenList.h" +#include "V8Binding.h" +#include "V8DOMWrapper.h" +#include "V8Element.h" + +namespace WebCore { + +v8::Handle<v8::Value> toV8(DOMTokenList* impl) +{ + if (!impl) + return v8::Null(); + v8::Handle<v8::Object> wrapper = V8DOMTokenList::wrap(impl); + // Add a hidden reference from the element to the DOMTokenList. + Element* element = impl->element(); + if (!wrapper.IsEmpty() && element) { + v8::Handle<v8::Value> elementValue = toV8(element); + if (!elementValue.IsEmpty() && elementValue->IsObject()) + V8DOMWrapper::setHiddenReference(elementValue.As<v8::Object>(), wrapper); + } + return wrapper; +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp index 67f27c5..f7a03f9 100644 --- a/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp @@ -37,67 +37,122 @@ namespace WebCore { -v8::Handle<v8::Value> V8DeviceMotionEvent::xAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +namespace { + +v8::Handle<v8::Value> createAccelerationObject(const DeviceMotionData::Acceleration* acceleration) { - INC_STATS("DOM.DeviceMotionEvent.xAcceleration._get"); - v8::Handle<v8::Object> holder = info.Holder(); - DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); - if (!imp->deviceMotionData()->canProvideXAcceleration()) - return v8::Null(); - return v8::Number::New(imp->deviceMotionData()->xAcceleration()); + v8::Local<v8::Object> object = v8::Object::New(); + object->Set(v8::String::New("x"), acceleration->canProvideX() ? v8::Number::New(acceleration->x()) : v8::Null()); + object->Set(v8::String::New("y"), acceleration->canProvideY() ? v8::Number::New(acceleration->y()) : v8::Null()); + object->Set(v8::String::New("z"), acceleration->canProvideZ() ? v8::Number::New(acceleration->z()) : v8::Null()); + return object; } -v8::Handle<v8::Value> V8DeviceMotionEvent::yAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +v8::Handle<v8::Value> createRotationRateObject(const DeviceMotionData::RotationRate* rotationRate) { - INC_STATS("DOM.DeviceMotionEvent.yAcceleration._get"); - v8::Handle<v8::Object> holder = info.Holder(); - DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); - if (!imp->deviceMotionData()->canProvideYAcceleration()) - return v8::Null(); - return v8::Number::New(imp->deviceMotionData()->yAcceleration()); + v8::Local<v8::Object> object = v8::Object::New(); + object->Set(v8::String::New("alpha"), rotationRate->canProvideAlpha() ? v8::Number::New(rotationRate->alpha()) : v8::Null()); + object->Set(v8::String::New("beta"), rotationRate->canProvideBeta() ? v8::Number::New(rotationRate->beta()) : v8::Null()); + object->Set(v8::String::New("gamma"), rotationRate->canProvideGamma() ? v8::Number::New(rotationRate->gamma()) : v8::Null()); + return object; } -v8::Handle<v8::Value> V8DeviceMotionEvent::zAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +RefPtr<DeviceMotionData::Acceleration> readAccelerationArgument(v8::Local<v8::Value> value) { - INC_STATS("DOM.DeviceMotionEvent.zAcceleration._get"); - v8::Handle<v8::Object> holder = info.Holder(); - DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); - if (!imp->deviceMotionData()->canProvideZAcceleration()) - return v8::Null(); - return v8::Number::New(imp->deviceMotionData()->zAcceleration()); + if (isUndefinedOrNull(value)) + return 0; + + // Given the test above, this will always yield an object. + v8::Local<v8::Object> object = value->ToObject(); + + v8::Local<v8::Value> xValue = object->Get(v8::String::New("x")); + if (xValue.IsEmpty()) + return 0; + bool canProvideX = !isUndefinedOrNull(xValue); + double x = xValue->NumberValue(); + + v8::Local<v8::Value> yValue = object->Get(v8::String::New("y")); + if (yValue.IsEmpty()) + return 0; + bool canProvideY = !isUndefinedOrNull(yValue); + double y = yValue->NumberValue(); + + v8::Local<v8::Value> zValue = object->Get(v8::String::New("z")); + if (zValue.IsEmpty()) + return 0; + bool canProvideZ = !isUndefinedOrNull(zValue); + double z = zValue->NumberValue(); + + if (!canProvideX && !canProvideY && !canProvideZ) + return 0; + + return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y, canProvideZ, z); } -v8::Handle<v8::Value> V8DeviceMotionEvent::xRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +RefPtr<DeviceMotionData::RotationRate> readRotationRateArgument(v8::Local<v8::Value> value) { - INC_STATS("DOM.DeviceMotionEvent.xRotationRate._get"); + if (isUndefinedOrNull(value)) + return 0; + + // Given the test above, this will always yield an object. + v8::Local<v8::Object> object = value->ToObject(); + + v8::Local<v8::Value> alphaValue = object->Get(v8::String::New("alpha")); + if (alphaValue.IsEmpty()) + return 0; + bool canProvideAlpha = !isUndefinedOrNull(alphaValue); + double alpha = alphaValue->NumberValue(); + + v8::Local<v8::Value> betaValue = object->Get(v8::String::New("beta")); + if (betaValue.IsEmpty()) + return 0; + bool canProvideBeta = !isUndefinedOrNull(betaValue); + double beta = betaValue->NumberValue(); + + v8::Local<v8::Value> gammaValue = object->Get(v8::String::New("gamma")); + if (gammaValue.IsEmpty()) + return 0; + bool canProvideGamma = !isUndefinedOrNull(gammaValue); + double gamma = gammaValue->NumberValue(); + + if (!canProvideAlpha && !canProvideBeta && !canProvideGamma) + return 0; + + return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma); +} + +} // namespace + +v8::Handle<v8::Value> V8DeviceMotionEvent::accelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.acceleration._get"); v8::Handle<v8::Object> holder = info.Holder(); DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); - if (!imp->deviceMotionData()->canProvideXRotationRate()) + if (!imp->deviceMotionData()->acceleration()) return v8::Null(); - return v8::Number::New(imp->deviceMotionData()->xRotationRate()); + return createAccelerationObject(imp->deviceMotionData()->acceleration()); } -v8::Handle<v8::Value> V8DeviceMotionEvent::yRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +v8::Handle<v8::Value> V8DeviceMotionEvent::accelerationIncludingGravityAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - INC_STATS("DOM.DeviceMotionEvent.yRotationRate._get"); + INC_STATS("DOM.DeviceMotionEvent.accelerationIncludingGravity._get"); v8::Handle<v8::Object> holder = info.Holder(); DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); - if (!imp->deviceMotionData()->canProvideYRotationRate()) + if (!imp->deviceMotionData()->accelerationIncludingGravity()) return v8::Null(); - return v8::Number::New(imp->deviceMotionData()->yRotationRate()); + return createAccelerationObject(imp->deviceMotionData()->accelerationIncludingGravity()); } -v8::Handle<v8::Value> V8DeviceMotionEvent::zRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +v8::Handle<v8::Value> V8DeviceMotionEvent::rotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - INC_STATS("DOM.DeviceMotionEvent.zRotationRate._get"); + INC_STATS("DOM.DeviceMotionEvent.rotationRate._get"); v8::Handle<v8::Object> holder = info.Holder(); DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); - if (!imp->deviceMotionData()->canProvideZRotationRate()) + if (!imp->deviceMotionData()->rotationRate()) return v8::Null(); - return v8::Number::New(imp->deviceMotionData()->zRotationRate()); + return createRotationRateObject(imp->deviceMotionData()->rotationRate()); } - v8::Handle<v8::Value> V8DeviceMotionEvent::intervalAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.DeviceMotionEvent.interval._get"); @@ -114,23 +169,12 @@ v8::Handle<v8::Value> V8DeviceMotionEvent::initDeviceMotionEventCallback(const v STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, type, args[0]); bool bubbles = args[1]->BooleanValue(); bool cancelable = args[2]->BooleanValue(); - // If any of the parameters are null or undefined, mark them as not provided. - // Otherwise, use the standard JavaScript conversion. - bool xAccelerationProvided = !isUndefinedOrNull(args[3]); - double xAcceleration = static_cast<double>(args[3]->NumberValue()); - bool yAccelerationProvided = !isUndefinedOrNull(args[4]); - double yAcceleration = static_cast<double>(args[4]->NumberValue()); - bool zAccelerationProvided = !isUndefinedOrNull(args[5]); - double zAcceleration = static_cast<double>(args[5]->NumberValue()); - bool xRotationRateProvided = !isUndefinedOrNull(args[6]); - double xRotationRate = static_cast<double>(args[6]->NumberValue()); - bool yRotationRateProvided = !isUndefinedOrNull(args[7]); - double yRotationRate = static_cast<double>(args[7]->NumberValue()); - bool zRotationRateProvided = !isUndefinedOrNull(args[8]); - double zRotationRate = static_cast<double>(args[8]->NumberValue()); - bool intervalProvided = !isUndefinedOrNull(args[9]); - double interval = static_cast<double>(args[9]->NumberValue()); - RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(xAccelerationProvided, xAcceleration, yAccelerationProvided, yAcceleration, zAccelerationProvided, zAcceleration, xRotationRateProvided, xRotationRate, yRotationRateProvided, yRotationRate, zRotationRateProvided, zRotationRate, intervalProvided, interval); + RefPtr<DeviceMotionData::Acceleration> acceleration = readAccelerationArgument(args[3]); + RefPtr<DeviceMotionData::Acceleration> accelerationIncludingGravity = readAccelerationArgument(args[4]); + RefPtr<DeviceMotionData::RotationRate> rotationRate = readRotationRateArgument(args[5]); + bool intervalProvided = !isUndefinedOrNull(args[6]); + double interval = args[6]->NumberValue(); + RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval); imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get()); return v8::Handle<v8::Value>(); } diff --git a/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp b/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp index 72f759a..ce8eaf3 100644 --- a/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp @@ -76,11 +76,11 @@ v8::Handle<v8::Value> V8DeviceOrientationEvent::initDeviceOrientationEventCallba // If alpha, beta or gamma are null or undefined, mark them as not provided. // Otherwise, use the standard JavaScript conversion. bool alphaProvided = !isUndefinedOrNull(args[3]); - double alpha = static_cast<double>(args[3]->NumberValue()); + double alpha = args[3]->NumberValue(); bool betaProvided = !isUndefinedOrNull(args[4]); - double beta = static_cast<double>(args[4]->NumberValue()); + double beta = args[4]->NumberValue(); bool gammaProvided = !isUndefinedOrNull(args[5]); - double gamma = static_cast<double>(args[5]->NumberValue()); + double gamma = args[5]->NumberValue(); RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma); imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get()); return v8::Handle<v8::Value>(); diff --git a/WebCore/bindings/v8/custom/V8DirectoryEntryCustom.cpp b/WebCore/bindings/v8/custom/V8DirectoryEntryCustom.cpp index 286b154..fc8cf98 100644 --- a/WebCore/bindings/v8/custom/V8DirectoryEntryCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DirectoryEntryCustom.cpp @@ -71,7 +71,7 @@ v8::Handle<v8::Value> V8DirectoryEntry::getDirectoryCallback(const v8::Arguments } } else { EXCEPTION_BLOCK(Flags*, tmp_flags, V8Flags::HasInstance(args[1]) ? V8Flags::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0); - flags = adoptRef(tmp_flags); + flags = tmp_flags; } RefPtr<EntryCallback> successCallback; if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) { @@ -114,7 +114,7 @@ v8::Handle<v8::Value> V8DirectoryEntry::getFileCallback(const v8::Arguments& arg } } else { EXCEPTION_BLOCK(Flags*, tmp_flags, V8Flags::HasInstance(args[1]) ? V8Flags::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0); - flags = adoptRef(tmp_flags); + flags = tmp_flags; } RefPtr<EntryCallback> successCallback; if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) { diff --git a/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp b/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp index 25b9010..94fa86e 100644 --- a/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp @@ -47,6 +47,8 @@ v8::Handle<v8::Value> V8InspectorFrontendHost::platformCallback(const v8::Argume return v8String("mac"); #elif defined(OS_LINUX) return v8String("linux"); +#elif defined(OS_FREEBSD) + return v8String("freebsd"); #elif defined(OS_WIN) return v8String("windows"); #else diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp index cfeb503..2355d2a 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp @@ -32,6 +32,7 @@ #include "V8XMLHttpRequest.h" #include "Frame.h" +#include "InspectorController.h" #include "V8Binding.h" #include "V8Blob.h" #include "V8DOMFormData.h" @@ -113,6 +114,8 @@ v8::Handle<v8::Value> V8XMLHttpRequest::sendCallback(const v8::Arguments& args) INC_STATS("DOM.XMLHttpRequest.send()"); XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); + InspectorController::instrumentWillSendXMLHttpRequest(xmlHttpRequest->scriptExecutionContext(), xmlHttpRequest->url()); + ExceptionCode ec = 0; if (args.Length() < 1) xmlHttpRequest->send(ec); |