diff options
Diffstat (limited to 'webkit/port')
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.cpp | 67 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.h | 23 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptInstance.cpp | 83 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptInstance.h | 63 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.cpp | 55 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_npobject.cpp | 10 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.h | 4 |
7 files changed, 196 insertions, 109 deletions
diff --git a/webkit/port/bindings/v8/ScriptController.cpp b/webkit/port/bindings/v8/ScriptController.cpp index c286b8c..2d45354 100644 --- a/webkit/port/bindings/v8/ScriptController.cpp +++ b/webkit/port/bindings/v8/ScriptController.cpp @@ -363,16 +363,16 @@ bool ScriptController::isEnabled() const return m_proxy->isEnabled(); } -JSInstanceHandle ScriptController::createScriptInstanceForWidget(Widget* widget) +PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widget) { ASSERT(widget != 0); if (widget->isFrameView()) - return JSInstanceHolder::EmptyInstance(); + return 0; NPObject* npObject = ChromiumBridge::pluginScriptableObject(widget); if (!npObject) - return JSInstanceHolder::EmptyInstance(); + return 0; // Frame Memory Management for NPObjects // ------------------------------------- @@ -404,8 +404,7 @@ JSInstanceHandle ScriptController::createScriptInstanceForWidget(Widget* widget) // Track the plugin object. We've been given a reference to the object. m_pluginObjects.set(widget, npObject); - JSInstance instance = wrapper; - return instance; + return V8ScriptInstance::create(wrapper); } void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle) @@ -496,62 +495,4 @@ void ScriptController::updateDocument() m_proxy->updateDocument(); } - -JSInstanceHolder::JSInstanceHolder() -{ -} - -JSInstanceHolder::JSInstanceHolder(JSInstanceHandle instance) -{ - *this = instance; -} - -JSInstanceHolder::~JSInstanceHolder() -{ - Clear(); -} - -bool JSInstanceHolder::IsEmpty() -{ - return m_instance.IsEmpty(); -} - -JSInstance JSInstanceHolder::Get() -{ - return v8::Local<v8::Object>::New(m_instance); -} - -void JSInstanceHolder::Clear() -{ - if (m_instance.IsEmpty()) - return; - v8::HandleScope scope; - v8::Persistent<v8::Object> handle(m_instance); -#ifndef NDEBUG - V8Proxy::UnregisterGlobalHandle(this, handle); -#endif - handle.Dispose(); - m_instance.Clear(); -} - -JSInstance JSInstanceHolder::EmptyInstance() -{ - return v8::Local<v8::Object>(); -} - -JSInstanceHolder& JSInstanceHolder::operator=(JSInstanceHandle instance) -{ - Clear(); - if (instance.IsEmpty()) - return *this; - - v8::Persistent<v8::Object> handle = - v8::Persistent<v8::Object>::New(instance); - m_instance = handle; -#ifndef NDEBUG - V8Proxy::RegisterGlobalHandle(JSINSTANCE, this, handle); -#endif - return *this; -} - } // namespace WebCpre diff --git a/webkit/port/bindings/v8/ScriptController.h b/webkit/port/bindings/v8/ScriptController.h index c7daeb8..00c6e0c 100644 --- a/webkit/port/bindings/v8/ScriptController.h +++ b/webkit/port/bindings/v8/ScriptController.h @@ -35,6 +35,7 @@ #include "HashMap.h" #include "MessagePort.h" +#include "ScriptInstance.h" #include "ScriptValue.h" #include "SecurityOrigin.h" @@ -164,7 +165,7 @@ public: NPRuntimeFunctions* functions(); - JSInstanceHandle createScriptInstanceForWidget(Widget*); + PassScriptInstance createScriptInstanceForWidget(Widget*); void clearPluginObjects(); void disconnectFrame(); @@ -281,26 +282,6 @@ private: #endif }; -// JSInstance is an abstraction for a wrapped C class. JSC and V8 -// have very different implementations. -class JSInstanceHolder { -public: - JSInstanceHolder(); - JSInstanceHolder(JSInstanceHandle); - ~JSInstanceHolder(); - // Returns true if the holder is empty. - bool IsEmpty(); - // Get the contained JSInstance. - JSInstance Get(); - // Clear the contained JSInstance. - void Clear(); - JSInstanceHolder& operator=(JSInstanceHandle); - static JSInstance EmptyInstance(); - -private: - JSPersistentInstance m_instance; -}; - } // namespace WebCore #endif // ScriptController_h diff --git a/webkit/port/bindings/v8/ScriptInstance.cpp b/webkit/port/bindings/v8/ScriptInstance.cpp new file mode 100644 index 0000000..4c9f64b --- /dev/null +++ b/webkit/port/bindings/v8/ScriptInstance.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2008, 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 "ScriptInstance.h" + +#include "v8_proxy.h" +#include <wtf/Assertions.h> + +namespace WebCore { + +V8ScriptInstance::V8ScriptInstance() +{ +} + +V8ScriptInstance::V8ScriptInstance(v8::Handle<v8::Object> instance) +{ + set(instance); +} + +V8ScriptInstance::~V8ScriptInstance() +{ + clear(); +} + +v8::Persistent<v8::Object> V8ScriptInstance::instance() +{ + return m_instance; +} + +void V8ScriptInstance::clear() +{ + if (m_instance.IsEmpty()) + return; +#ifndef NDEBUG + V8Proxy::UnregisterGlobalHandle(this, m_instance); +#endif + m_instance.Dispose(); + m_instance.Clear(); +} + +void V8ScriptInstance::set(v8::Handle<v8::Object> instance) +{ + clear(); + if (instance.IsEmpty()) + return; + + m_instance = v8::Persistent<v8::Object>::New(instance); +#ifndef NDEBUG + V8Proxy::RegisterGlobalHandle(SCRIPTINSTANCE, this, m_instance); +#endif + +} + + +} // namespace WebCore diff --git a/webkit/port/bindings/v8/ScriptInstance.h b/webkit/port/bindings/v8/ScriptInstance.h new file mode 100644 index 0000000..b45c87b --- /dev/null +++ b/webkit/port/bindings/v8/ScriptInstance.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008, 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. + */ + +#ifndef ScriptInstance_h +#define ScriptInstance_h + +#include "v8.h" +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class V8ScriptInstance : public RefCounted<V8ScriptInstance> { +public: + static PassRefPtr<V8ScriptInstance> create(v8::Handle<v8::Object> instance) + { + return adoptRef(new V8ScriptInstance(instance)); + } + V8ScriptInstance(); + V8ScriptInstance(v8::Handle<v8::Object>); + ~V8ScriptInstance(); + v8::Persistent<v8::Object> instance(); + +private: + void clear(); + void set(v8::Handle<v8::Object>); + mutable v8::Persistent<v8::Object> m_instance; +}; + +typedef RefPtr<V8ScriptInstance> ScriptInstance; +typedef PassRefPtr<V8ScriptInstance> PassScriptInstance; + +} // namespace WebCore + +#endif // ScriptInstance_h diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp index 15028a5..c5cdc34 100644 --- a/webkit/port/bindings/v8/v8_custom.cpp +++ b/webkit/port/bindings/v8/v8_custom.cpp @@ -101,6 +101,7 @@ #include "RenderWidget.h" #include "ScheduledAction.h" #include "ScriptCallContext.h" +#include "ScriptController.h" #include "SecurityOrigin.h" #include "Settings.h" #include "StyleSheetList.h" @@ -1794,10 +1795,15 @@ NAMED_PROPERTY_GETTER(HTMLPlugInElement) { INC_STATS("DOM.HTMLPlugInElement.NamedPropertyGetter"); HTMLPlugInElement* imp = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(info.Holder()); - v8::Local<v8::Object> instance = - v8::Local<v8::Object>::New(imp->getInstance()); - if (instance.IsEmpty()) return v8::Handle<v8::Object>(); - return NPObjectGetNamedProperty(instance, name); + ScriptInstance script_instance = imp->getInstance(); + if (script_instance) { + v8::Local<v8::Object> instance = + v8::Local<v8::Object>::New(script_instance->instance()); + if (!instance.IsEmpty()) { + return NPObjectGetNamedProperty(instance, name); + } + } + return v8::Handle<v8::Object>(); } @@ -1805,13 +1811,15 @@ NAMED_PROPERTY_SETTER(HTMLPlugInElement) { INC_STATS("DOM.HTMLPlugInElement.NamedPropertySetter"); HTMLPlugInElement* imp = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(info.Holder()); - v8::Local<v8::Object> instance = - v8::Local<v8::Object>::New(imp->getInstance()); - if (instance.IsEmpty()) { - return v8::Handle<v8::Value>(); // do not block the call + ScriptInstance script_instance = imp->getInstance(); + if (script_instance) { + v8::Local<v8::Object> instance = + v8::Local<v8::Object>::New(script_instance->instance()); + if (!instance.IsEmpty()) { + return NPObjectSetNamedProperty(instance, name, value); + } } - - return NPObjectSetNamedProperty(instance, name, value); + return v8::Handle<v8::Value>(); // do not block the call } @@ -1825,10 +1833,15 @@ INDEXED_PROPERTY_GETTER(HTMLPlugInElement) { INC_STATS("DOM.HTMLPlugInElement.IndexedPropertyGetter"); HTMLPlugInElement* imp = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(info.Holder()); - v8::Local<v8::Object> instance = - v8::Local<v8::Object>::New(imp->getInstance()); - if (instance.IsEmpty()) return v8::Handle<v8::Object>(); - return NPObjectGetIndexedProperty(instance, index); + ScriptInstance script_instance = imp->getInstance(); + if (script_instance) { + v8::Local<v8::Object> instance = + v8::Local<v8::Object>::New(script_instance->instance()); + if (!instance.IsEmpty()) { + return NPObjectGetIndexedProperty(instance, index); + } + } + return v8::Handle<v8::Object>(); } @@ -1836,13 +1849,15 @@ INDEXED_PROPERTY_SETTER(HTMLPlugInElement) { INC_STATS("DOM.HTMLPlugInElement.IndexedPropertySetter"); HTMLPlugInElement* imp = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(info.Holder()); - v8::Local<v8::Object> instance = - v8::Local<v8::Object>::New(imp->getInstance()); - if (instance.IsEmpty()) { - return v8::Handle<v8::Value>(); // do not block the call + ScriptInstance script_instance = imp->getInstance(); + if (script_instance) { + v8::Local<v8::Object> instance = + v8::Local<v8::Object>::New(script_instance->instance()); + if (!instance.IsEmpty()) { + return NPObjectSetIndexedProperty(instance, index, value); + } } - - return NPObjectSetIndexedProperty(instance, index, value); + return v8::Handle<v8::Value>(); // do not block the call } NAMED_PROPERTY_GETTER(StyleSheetList) { diff --git a/webkit/port/bindings/v8/v8_npobject.cpp b/webkit/port/bindings/v8/v8_npobject.cpp index 060f982..f26f510 100644 --- a/webkit/port/bindings/v8/v8_npobject.cpp +++ b/webkit/port/bindings/v8/v8_npobject.cpp @@ -61,9 +61,13 @@ static v8::Handle<v8::Value> NPObjectInvokeImpl( // The holder object is a subtype of HTMLPlugInElement. HTMLPlugInElement* imp = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(args.Holder()); - v8::Handle<v8::Object> instance = imp->getInstance(); - npobject = V8Proxy::ToNativeObject<NPObject>( - V8ClassIndex::NPOBJECT, instance); + ScriptInstance script_instance = imp->getInstance(); + if (script_instance) { + npobject = V8Proxy::ToNativeObject<NPObject>( + V8ClassIndex::NPOBJECT, script_instance->instance()); + } else { + npobject = NULL; + } } else { // The holder object is not a subtype of HTMLPlugInElement, it diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h index 724222f..c63dbf4 100644 --- a/webkit/port/bindings/v8/v8_proxy.h +++ b/webkit/port/bindings/v8/v8_proxy.h @@ -86,8 +86,8 @@ void log_info(Frame* frame, const String& msg, const String& url); V(SCHEDULED_ACTION) \ V(EVENT_LISTENER) \ V(NODE_FILTER) \ - V(SCRIPTVALUE) \ - V(JSINSTANCE) + V(SCRIPTINSTANCE) \ + V(SCRIPTVALUE) // Host information of persistent handles. |