diff options
Diffstat (limited to 'WebCore/bindings/v8')
-rw-r--r-- | WebCore/bindings/v8/NPV8Object.cpp | 58 | ||||
-rw-r--r-- | WebCore/bindings/v8/NPV8Object.h | 14 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptController.cpp | 11 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptController.h | 16 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8NPObject.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8NPObject.h | 4 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8NPUtils.cpp | 54 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8NPUtils.h | 20 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8AttrCustom.cpp | 58 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8EventCustom.cpp | 5 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp | 42 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8NamedNodesCollection.cpp | 2 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8NodeCustom.cpp | 63 | ||||
-rw-r--r-- | WebCore/bindings/v8/npruntime.cpp | 2 |
14 files changed, 142 insertions, 211 deletions
diff --git a/WebCore/bindings/v8/NPV8Object.cpp b/WebCore/bindings/v8/NPV8Object.cpp index 56f9810..d8076f3 100644 --- a/WebCore/bindings/v8/NPV8Object.cpp +++ b/WebCore/bindings/v8/NPV8Object.cpp @@ -52,13 +52,7 @@ #include <v8.h> #include <wtf/StringExtras.h> -using WebCore::npObjectInternalFieldCount; -using WebCore::toV8Context; -using WebCore::toV8Proxy; -using WebCore::V8DOMWrapper; -using WebCore::V8GCController; -using WebCore::V8Proxy; -using WebCore::WrapperTypeInfo; +using namespace WebCore; namespace WebCore { @@ -68,8 +62,6 @@ WrapperTypeInfo* npObjectTypeInfo() return &typeInfo; } -} - // FIXME: Comments on why use malloc and free. static NPObject* allocV8NPObject(NPP, NPClass*) { @@ -110,7 +102,7 @@ static v8::Local<v8::String> npIdentifierToV8Identifier(NPIdentifier name) NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object) { - return reinterpret_cast<NPObject*>(object->GetPointerFromInternalField(WebCore::v8DOMWrapperObjectIndex)); + return reinterpret_cast<NPObject*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); } static NPClass V8NPObjectClass = { NP_CLASS_STRUCT_VERSION, @@ -121,12 +113,12 @@ static NPClass V8NPObjectClass = { NP_CLASS_STRUCT_VERSION, // NPAPI's npruntime functions. NPClass* npScriptObjectClass = &V8NPObjectClass; -NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore::DOMWindow* root) +NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, DOMWindow* root) { // Check to see if this object is already wrapped. if (object->InternalFieldCount() == npObjectInternalFieldCount) { - WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(object->GetPointerFromInternalField(WebCore::v8DOMWrapperTypeIndex)); - if (typeInfo == WebCore::npObjectTypeInfo()) { + WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(object->GetPointerFromInternalField(v8DOMWrapperTypeIndex)); + if (typeInfo == npObjectTypeInfo()) { NPObject* returnValue = v8ObjectToNPObject(object); _NPN_RetainObject(returnValue); @@ -137,12 +129,14 @@ NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp, &V8NPObjectClass)); v8npObject->v8Object = v8::Persistent<v8::Object>::New(object); #ifndef NDEBUG - V8GCController::registerGlobalHandle(WebCore::NPOBJECT, v8npObject, v8npObject->v8Object); + V8GCController::registerGlobalHandle(NPOBJECT, v8npObject, v8npObject->v8Object); #endif v8npObject->rootObject = root; return reinterpret_cast<NPObject*>(v8npObject); } +} // namespace WebCore + bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) { if (!npObject) @@ -162,6 +156,14 @@ bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPV if (!identifier->isString) return false; + if (!strcmp(identifier->value.string, "eval")) { + if (argumentCount != 1) + return false; + if (arguments[0].type != NPVariantType_String) + return false; + return _NPN_Evaluate(npp, npObject, const_cast<NPString*>(&arguments[0].value.stringValue), result); + } + v8::HandleScope handleScope; // FIXME: should use the plugin's owner frame as the security context. v8::Handle<v8::Context> context = toV8Context(npp, npObject); @@ -169,14 +171,7 @@ bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPV return false; v8::Context::Scope scope(context); - - if (methodName == _NPN_GetStringIdentifier("eval")) { - if (argumentCount != 1) - return false; - if (arguments[0].type != NPVariantType_String) - return false; - return _NPN_Evaluate(npp, npObject, const_cast<NPString*>(&arguments[0].value.stringValue), result); - } + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Value> functionObject = v8NpObject->v8Object->Get(v8::String::New(identifier->value.string)); if (functionObject.IsEmpty() || functionObject->IsNull()) { @@ -229,6 +224,7 @@ bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments, return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; // Lookup the function object and call it. v8::Handle<v8::Object> functionObject(v8NpObject->v8Object); @@ -255,7 +251,7 @@ bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments, bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* result) { - bool popupsAllowed = WebCore::PlatformBridge::popupsAllowed(npp); + bool popupsAllowed = PlatformBridge::popupsAllowed(npp); return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); } @@ -277,13 +273,14 @@ bool _NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npObject, NPStri ASSERT(proxy); v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; - WebCore::String filename; + String filename; if (!popupsAllowed) filename = "npscript"; - WebCore::String script = WebCore::String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length); - v8::Local<v8::Value> v8result = proxy->evaluate(WebCore::ScriptSourceCode(script, WebCore::KURL(WebCore::ParsedURLString, filename)), 0); + String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length); + v8::Local<v8::Value> v8result = proxy->evaluate(ScriptSourceCode(script, KURL(ParsedURLString, filename)), 0); if (v8result.IsEmpty()) return false; @@ -306,6 +303,7 @@ bool _NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NP return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Object> obj(object->v8Object); v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(propertyName)); @@ -340,6 +338,7 @@ bool _NPN_SetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, co return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Object> obj(object->v8Object); obj->Set(npIdentifierToV8Identifier(propertyName), @@ -367,6 +366,7 @@ bool _NPN_RemoveProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) if (context.IsEmpty()) return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Object> obj(object->v8Object); // FIXME: Verify that setting to undefined is right. @@ -387,6 +387,7 @@ bool _NPN_HasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) if (context.IsEmpty()) return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Object> obj(object->v8Object); return obj->Has(npIdentifierToV8Identifier(propertyName)); @@ -410,6 +411,7 @@ bool _NPN_HasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName) if (context.IsEmpty()) return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Object> obj(object->v8Object); v8::Handle<v8::Value> prop = obj->Get(npIdentifierToV8Identifier(methodName)); @@ -439,6 +441,8 @@ void _NPN_SetException(NPObject* npObject, const NPUTF8 *message) return; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; + V8Proxy::throwError(V8Proxy::GeneralError, message); } @@ -455,6 +459,7 @@ bool _NPN_Enumerate(NPP npp, NPObject* npObject, NPIdentifier** identifier, uint if (context.IsEmpty()) return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; v8::Handle<v8::Object> obj(object->v8Object); @@ -509,6 +514,7 @@ bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uin if (context.IsEmpty()) return false; v8::Context::Scope scope(context); + ExceptionCatcher exceptionCatcher; // Lookup the constructor function. v8::Handle<v8::Object> ctorObj(object->v8Object); diff --git a/WebCore/bindings/v8/NPV8Object.h b/WebCore/bindings/v8/NPV8Object.h index b6fecce..2a81181 100644 --- a/WebCore/bindings/v8/NPV8Object.h +++ b/WebCore/bindings/v8/NPV8Object.h @@ -45,12 +45,12 @@ #include <v8.h> namespace WebCore { - class DOMWindow; - static const int npObjectInternalFieldCount = v8DefaultWrapperInternalFieldCount + 0; +class DOMWindow; - WrapperTypeInfo* npObjectTypeInfo(); -} +static const int npObjectInternalFieldCount = v8DefaultWrapperInternalFieldCount + 0; + +WrapperTypeInfo* npObjectTypeInfo(); extern NPClass* npScriptObjectClass; @@ -59,7 +59,7 @@ extern NPClass* npScriptObjectClass; struct V8NPObject { NPObject object; v8::Persistent<v8::Object> v8Object; - WebCore::DOMWindow* rootObject; + DOMWindow* rootObject; }; struct PrivateIdentifier { @@ -70,8 +70,10 @@ struct PrivateIdentifier { bool isString; }; -NPObject* npCreateV8ScriptObject(NPP, v8::Handle<v8::Object>, WebCore::DOMWindow*); +NPObject* npCreateV8ScriptObject(NPP, v8::Handle<v8::Object>, DOMWindow*); NPObject* v8ObjectToNPObject(v8::Handle<v8::Object>); +} // namespace WebCore + #endif // NPV8Object_h diff --git a/WebCore/bindings/v8/ScriptController.cpp b/WebCore/bindings/v8/ScriptController.cpp index 7748f75..41cb5a2 100644 --- a/WebCore/bindings/v8/ScriptController.cpp +++ b/WebCore/bindings/v8/ScriptController.cpp @@ -88,6 +88,11 @@ Frame* ScriptController::retrieveFrameForCurrentContext() return V8Proxy::retrieveFrameForCurrentContext(); } +bool ScriptController::canAccessFromCurrentOrigin(Frame *frame) +{ + return !v8::Context::InContext() || V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true); +} + bool ScriptController::isSafeScript(Frame* target) { return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, true); @@ -219,13 +224,13 @@ void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<Sc } // Evaluate a script file in the environment of this proxy. -ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) +ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode, ShouldAllowXSS shouldAllowXSS) { String sourceURL = sourceCode.url(); const String* savedSourceURL = m_sourceURL; m_sourceURL = &sourceURL; - if (!m_XSSAuditor->canEvaluate(sourceCode.source())) { + if (shouldAllowXSS == DoNotAllowXSS && !m_XSSAuditor->canEvaluate(sourceCode.source())) { // This script is not safe to be evaluated. return ScriptValue(); } @@ -444,7 +449,7 @@ NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement } -void ScriptController::clearWindowShell() +void ScriptController::clearWindowShell(bool) { // V8 binding expects ScriptController::clearWindowShell only be called // when a frame is loading a new page. V8Proxy::clearForNavigation diff --git a/WebCore/bindings/v8/ScriptController.h b/WebCore/bindings/v8/ScriptController.h index 1400134..ee39e9a 100644 --- a/WebCore/bindings/v8/ScriptController.h +++ b/WebCore/bindings/v8/ScriptController.h @@ -60,6 +60,12 @@ enum ReasonForCallingCanExecuteScripts { NotAboutToExecuteScript }; +// Whether to call the XSSAuditor to audit a script before passing it to the JavaScript engine. +enum ShouldAllowXSS { + AllowXSS, + DoNotAllowXSS +}; + class ScriptController { public: ScriptController(Frame*); @@ -69,8 +75,8 @@ public: // or this accessor should be made JSProxy* V8Proxy* proxy() { return m_proxy.get(); } - ScriptValue executeScript(const ScriptSourceCode&); - ScriptValue executeScript(const String& script, bool forceUserGesture = false); + ScriptValue executeScript(const ScriptSourceCode&, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); + ScriptValue executeScript(const String& script, bool forceUserGesture = false, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); // Returns true if argument is a JavaScript URL. bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, ShouldReplaceDocumentIfJavaScriptURL shouldReplaceDocumentIfJavaScriptURL = ReplaceDocumentIfJavaScriptURL); @@ -81,7 +87,7 @@ public: // Evaluate a script file in the environment of this proxy. // If succeeded, 'succ' is set to true and result is returned // as a string. - ScriptValue evaluate(const ScriptSourceCode&); + ScriptValue evaluate(const ScriptSourceCode&, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&); @@ -118,6 +124,8 @@ public: // Check if the javascript engine has been initialized. bool haveInterpreter() const; + static bool canAccessFromCurrentOrigin(Frame*); + bool canExecuteScripts(ReasonForCallingCanExecuteScripts); // FIXME: void* is a compile hack. @@ -158,7 +166,7 @@ public: const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script. - void clearWindowShell(); + void clearWindowShell(bool = false); void updateDocument(); void updateSecurityOrigin(); diff --git a/WebCore/bindings/v8/V8NPObject.cpp b/WebCore/bindings/v8/V8NPObject.cpp index 84450e5..f9cc94a 100644 --- a/WebCore/bindings/v8/V8NPObject.cpp +++ b/WebCore/bindings/v8/V8NPObject.cpp @@ -45,7 +45,7 @@ #include "npruntime_priv.h" #include <wtf/OwnArrayPtr.h> -using namespace WebCore; +namespace WebCore { enum InvokeFunctionType { InvokeMethod = 1, @@ -409,3 +409,5 @@ void forgetV8ObjectForNPObject(NPObject* object) _NPN_ReleaseObject(object); } } + +} // namespace WebCore diff --git a/WebCore/bindings/v8/V8NPObject.h b/WebCore/bindings/v8/V8NPObject.h index 5924b3c..a540ca9 100644 --- a/WebCore/bindings/v8/V8NPObject.h +++ b/WebCore/bindings/v8/V8NPObject.h @@ -39,6 +39,8 @@ #include <v8.h> +namespace WebCore { + // These functions can be replaced by normal JS operation. // Getters v8::Handle<v8::Value> npObjectNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo&); @@ -65,4 +67,6 @@ v8::Local<v8::Object> createV8ObjectForNPObject(NPObject*, NPObject* root); // cannot be referred to. void forgetV8ObjectForNPObject(NPObject*); +} // namespace WebCore + #endif // V8NPObject_h diff --git a/WebCore/bindings/v8/V8NPUtils.cpp b/WebCore/bindings/v8/V8NPUtils.cpp index 17855d7..8fa19d7 100644 --- a/WebCore/bindings/v8/V8NPUtils.cpp +++ b/WebCore/bindings/v8/V8NPUtils.cpp @@ -29,19 +29,18 @@ */ #include "config.h" - #include "V8NPUtils.h" #include "DOMWindow.h" #include "Frame.h" #include "PlatformString.h" -#undef LOG - +#include "npruntime_impl.h" +#include "npruntime_priv.h" #include "NPV8Object.h" #include "V8NPObject.h" #include "V8Proxy.h" -#include "npruntime_impl.h" -#include "npruntime_priv.h" + +namespace WebCore { void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NPVariant* result) { @@ -69,7 +68,7 @@ void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NP char* utf8_chars = strdup(*utf8); STRINGN_TO_NPVARIANT(utf8_chars, utf8.length(), *result); } else if (object->IsObject()) { - WebCore::DOMWindow* window = WebCore::V8Proxy::retrieveWindow(WebCore::V8Proxy::currentContext()); + DOMWindow* window = V8Proxy::retrieveWindow(V8Proxy::currentContext()); NPObject* npobject = npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(object), window); if (npobject) _NPN_RegisterObject(npobject, owner); @@ -77,7 +76,6 @@ void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NP } } - v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* npobject) { NPVariantType type = variant->type; @@ -128,3 +126,45 @@ NPIdentifier getStringIdentifier(v8::Handle<v8::String> str) v8::String::Utf8Value utf8(str); return _NPN_GetStringIdentifier(*utf8); } + +struct ExceptionHandlerInfo { + ExceptionHandlerInfo* previous; + ExceptionHandler handler; + void* data; +}; + +static ExceptionHandlerInfo* topHandler; + +void pushExceptionHandler(ExceptionHandler handler, void* data) +{ + ExceptionHandlerInfo* info = new ExceptionHandlerInfo; + info->previous = topHandler; + info->handler = handler; + info->data = data; + topHandler = info; +} + +void popExceptionHandler() +{ + ASSERT(topHandler); + ExceptionHandlerInfo* doomed = topHandler; + topHandler = topHandler->previous; + delete doomed; +} + +ExceptionCatcher::ExceptionCatcher() +{ + if (!topHandler) + m_tryCatch.SetVerbose(true); +} + +ExceptionCatcher::~ExceptionCatcher() +{ + if (!m_tryCatch.HasCaught()) + return; + + if (topHandler) + topHandler->handler(topHandler->data, *v8::String::Utf8Value(m_tryCatch.Exception())); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/V8NPUtils.h b/WebCore/bindings/v8/V8NPUtils.h index c978d2b..78414b4 100644 --- a/WebCore/bindings/v8/V8NPUtils.h +++ b/WebCore/bindings/v8/V8NPUtils.h @@ -38,6 +38,8 @@ #include <v8.h> +namespace WebCore { + // Convert a V8 Value of any type (string, bool, object, etc) to a NPVariant. void convertV8ObjectToNPVariant(v8::Local<v8::Value>, NPObject*, NPVariant*); @@ -48,4 +50,22 @@ v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant*, NPObject*); // Helper function to create an NPN String Identifier from a v8 string. NPIdentifier getStringIdentifier(v8::Handle<v8::String>); +// The ExceptionHandler will be notified of any exceptions thrown while +// operating on a NPObject. +typedef void (*ExceptionHandler)(void* data, const NPUTF8* message); +void pushExceptionHandler(ExceptionHandler, void* data); +void popExceptionHandler(); + +// Upon destruction, an ExceptionCatcher will pass a caught exception to the +// current ExceptionHandler. +class ExceptionCatcher { +public: + ExceptionCatcher(); + ~ExceptionCatcher(); +private: + v8::TryCatch m_tryCatch; +}; + +} // namespace WebCore + #endif // V8NPUtils_h diff --git a/WebCore/bindings/v8/custom/V8AttrCustom.cpp b/WebCore/bindings/v8/custom/V8AttrCustom.cpp deleted file mode 100644 index 0da4ae4..0000000 --- a/WebCore/bindings/v8/custom/V8AttrCustom.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2007-2009 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 "V8Attr.h" - -#include "Attr.h" -#include "Element.h" -#include "ExceptionCode.h" -#include "V8Binding.h" -#include "V8BindingState.h" -#include "V8Proxy.h" - -namespace WebCore { - -void V8Attr::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) -{ - Attr* imp = V8Attr::toNative(info.Holder()); - String attrValue = toWebCoreStringWithNullCheck(value); - Element* ownerElement = imp->ownerElement(); - - if (ownerElement && !V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), ownerElement, imp->name(), attrValue)) - return; - - ExceptionCode ec = 0; - imp->setValue(attrValue, ec); - if (ec) - throwError(ec); -} - -} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8EventCustom.cpp b/WebCore/bindings/v8/custom/V8EventCustom.cpp index 8a1a339..bce1561 100644 --- a/WebCore/bindings/v8/custom/V8EventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventCustom.cpp @@ -40,6 +40,7 @@ #include "V8Clipboard.h" #include "V8CompositionEvent.h" #include "V8CustomEvent.h" +#include "V8DeviceOrientationEvent.h" #include "V8ErrorEvent.h" #include "V8IDBErrorEvent.h" #include "V8IDBSuccessEvent.h" @@ -153,6 +154,10 @@ v8::Handle<v8::Value> toV8(Event* impl) #endif if (impl->isBeforeLoadEvent()) return toV8(static_cast<BeforeLoadEvent*>(impl)); +#if ENABLE(DEVICE_ORIENTATION) + if (impl->isDeviceOrientationEvent()) + return toV8(static_cast<DeviceOrientationEvent*>(impl)); +#endif if (impl->isCustomEvent()) return toV8(static_cast<CustomEvent*>(impl)); return V8Event::wrap(impl); diff --git a/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp b/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp index 4e1dd21..d9e1de0 100644 --- a/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp @@ -75,48 +75,6 @@ v8::Handle<v8::Value> V8NamedNodeMap::namedPropertyGetter(v8::Local<v8::String> return toV8(result.release()); } -v8::Handle<v8::Value> V8NamedNodeMap::setNamedItemNSCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.NamedNodeMap.setNamedItemNS"); - NamedNodeMap* imp = V8NamedNodeMap::toNative(args.Holder()); - Node* newNode = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; - - if (newNode && newNode->nodeType() == Node::ATTRIBUTE_NODE && imp->element()) { - if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), imp->element(), newNode->nodeName(), newNode->nodeValue())) - return v8::Handle<v8::Value>(); - } - - ExceptionCode ec = 0; - RefPtr<Node> result = imp->setNamedItemNS(newNode, ec); - if (UNLIKELY(ec)) { - throwError(ec); - return v8::Handle<v8::Value>(); - } - - return toV8(result.release()); -} - -v8::Handle<v8::Value> V8NamedNodeMap::setNamedItemCallback(const v8::Arguments & args) -{ - INC_STATS("DOM.NamedNodeMap.setNamedItem"); - NamedNodeMap* imp = V8NamedNodeMap::toNative(args.Holder()); - Node* newNode = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; - - if (newNode && newNode->nodeType() == Node::ATTRIBUTE_NODE && imp->element()) { - if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), imp->element(), newNode->nodeName(), newNode->nodeValue())) - return v8::Handle<v8::Value>(); - } - - ExceptionCode ec = 0; - RefPtr<Node> result = imp->setNamedItem(newNode, ec); - if (UNLIKELY(ec)) { - throwError(ec); - return v8::Handle<v8::Value>(); - } - - return toV8(result.release()); -} - v8::Handle<v8::Value> toV8(NamedNodeMap* impl) { if (!impl) diff --git a/WebCore/bindings/v8/custom/V8NamedNodesCollection.cpp b/WebCore/bindings/v8/custom/V8NamedNodesCollection.cpp index 0723498..905b23d 100644 --- a/WebCore/bindings/v8/custom/V8NamedNodesCollection.cpp +++ b/WebCore/bindings/v8/custom/V8NamedNodesCollection.cpp @@ -31,7 +31,7 @@ #include "V8NamedNodesCollection.h" #include "Element.h" -#include "NamedAttrMap.h" +#include "NamedNodeMap.h" namespace WebCore { diff --git a/WebCore/bindings/v8/custom/V8NodeCustom.cpp b/WebCore/bindings/v8/custom/V8NodeCustom.cpp index 0a7198a..1f0c79b 100644 --- a/WebCore/bindings/v8/custom/V8NodeCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NodeCustom.cpp @@ -57,57 +57,12 @@ namespace WebCore { -static inline bool isFrameSrc(Element *element, const String& name) -{ - return element && (element->hasTagName(HTMLNames::iframeTag) || element->hasTagName(HTMLNames::frameTag)) && equalIgnoringCase(name, "src"); -} - -void V8Node::textContentAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) -{ - Node* imp = V8Node::toNative(info.Holder()); - String nodeValue = toWebCoreStringWithNullCheck(value); - - if (imp->nodeType() == Node::ATTRIBUTE_NODE) { - Element * ownerElement = V8Attr::toNative(info.Holder())->ownerElement(); - if (ownerElement && !V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), ownerElement, imp->nodeName(), nodeValue)) - return; - } - - ExceptionCode ec = 0; - imp->setTextContent(nodeValue, ec); - if (ec) - throwError(ec); -} - -void V8Node::nodeValueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) -{ - Node* imp = V8Node::toNative(info.Holder()); - String nodeValue = toWebCoreStringWithNullCheck(value); - - if (imp->nodeType() == Node::ATTRIBUTE_NODE) { - Element * ownerElement = V8Attr::toNative(info.Holder())->ownerElement(); - if (ownerElement && !V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), ownerElement, imp->nodeName(), nodeValue)) - return; - } - - ExceptionCode ec = 0; - imp->setNodeValue(nodeValue, ec); - if (ec) - throwError(ec); -} - // This function is customized to take advantage of the optional 4th argument: shouldLazyAttach v8::Handle<v8::Value> V8Node::insertBeforeCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.insertBefore"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); - - if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { - V8Proxy::setDOMException(NOT_SUPPORTED_ERR); - return v8::Handle<v8::Value>(); - } - ExceptionCode ec = 0; Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; Node* refChild = V8Node::HasInstance(args[1]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; @@ -127,12 +82,6 @@ v8::Handle<v8::Value> V8Node::replaceChildCallback(const v8::Arguments& args) INC_STATS("DOM.Node.replaceChild"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); - - if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { - V8Proxy::setDOMException(NOT_SUPPORTED_ERR); - return v8::Handle<v8::Value>(); - } - ExceptionCode ec = 0; Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; Node* oldChild = V8Node::HasInstance(args[1]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; @@ -151,12 +100,6 @@ v8::Handle<v8::Value> V8Node::removeChildCallback(const v8::Arguments& args) INC_STATS("DOM.Node.removeChild"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); - - if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { - V8Proxy::setDOMException(NOT_SUPPORTED_ERR); - return v8::Handle<v8::Value>(); - } - ExceptionCode ec = 0; Node* oldChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool success = imp->removeChild(oldChild, ec); @@ -175,12 +118,6 @@ v8::Handle<v8::Value> V8Node::appendChildCallback(const v8::Arguments& args) INC_STATS("DOM.Node.appendChild"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); - - if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { - V8Proxy::setDOMException(NOT_SUPPORTED_ERR); - return v8::Handle<v8::Value>(); - } - ExceptionCode ec = 0; Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool success = imp->appendChild(newChild, ec, true ); diff --git a/WebCore/bindings/v8/npruntime.cpp b/WebCore/bindings/v8/npruntime.cpp index 35015b0..12500a7 100644 --- a/WebCore/bindings/v8/npruntime.cpp +++ b/WebCore/bindings/v8/npruntime.cpp @@ -35,6 +35,8 @@ #include <wtf/HashSet.h> #include <wtf/Assertions.h> +using namespace WebCore; + // FIXME: Consider removing locks if we're singlethreaded already. // The static initializer here should work okay, but we want to avoid // static initialization in general. |