summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-18 21:11:53 +0000
committerlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-18 21:11:53 +0000
commitc4a36185a5f3189391b301bf9e0a2619c9e70084 (patch)
tree0dbf9c3856896170fe75972637669cbfec4f46fc /webkit
parent85887cd014f665af5c473bcb2032c603b78a17b8 (diff)
downloadchromium_src-c4a36185a5f3189391b301bf9e0a2619c9e70084.zip
chromium_src-c4a36185a5f3189391b301bf9e0a2619c9e70084.tar.gz
chromium_src-c4a36185a5f3189391b301bf9e0a2619c9e70084.tar.bz2
ScriptController.* needs to be reformatted into WebKit style.
TEST=Scripting in the browser. This should be pretty well covered by other testing. BUG=http://crbug.com/12063 Review URL: http://codereview.chromium.org/115417 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webframe_impl.cc2
-rw-r--r--webkit/port/bindings/v8/ScriptController.cpp231
-rw-r--r--webkit/port/bindings/v8/ScriptController.h337
3 files changed, 214 insertions, 356 deletions
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 6976573..11675ce 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -793,7 +793,7 @@ void WebFrameImpl::BindToWindowObject(const std::wstring& name,
String key = webkit_glue::StdWStringToString(name);
#if USE(V8)
- frame_->script()->BindToWindowObject(frame_, key, object);
+ frame_->script()->bindToWindowObject(frame_, key, object);
#endif
#if USE(JSC)
diff --git a/webkit/port/bindings/v8/ScriptController.cpp b/webkit/port/bindings/v8/ScriptController.cpp
index 1865cd5..c719cc1 100644
--- a/webkit/port/bindings/v8/ScriptController.cpp
+++ b/webkit/port/bindings/v8/ScriptController.cpp
@@ -1,31 +1,32 @@
-// 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.
+/*
+ * Copyright (C) 2008, 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 "ScriptController.h"
@@ -46,38 +47,15 @@
#include "ScriptState.h"
#include "Widget.h"
-#include "v8_proxy.h"
-#include "v8_binding.h"
+#include "V8Binding.h"
#include "V8NPObject.h"
-
-NPRuntimeFunctions npruntime_functions = {
- NPN_GetStringIdentifier,
- NPN_GetStringIdentifiers,
- NPN_GetIntIdentifier,
- NPN_IdentifierIsString,
- NPN_UTF8FromIdentifier,
- NPN_IntFromIdentifier,
- NPN_CreateObject,
- NPN_RetainObject,
- NPN_ReleaseObject,
- NPN_Invoke,
- NPN_InvokeDefault,
- NPN_Evaluate,
- NPN_GetProperty,
- NPN_SetProperty,
- NPN_RemoveProperty,
- NPN_HasProperty,
- NPN_HasMethod,
- NPN_ReleaseVariantValue,
- NPN_SetException
-};
-
+#include "V8Proxy.h"
namespace WebCore {
-void ScriptController::setFlags(const char* str, int length)
+void ScriptController::setFlags(const char* string, int length)
{
- v8::V8::SetFlagsFromString(str, length);
+ v8::V8::SetFlagsFromString(string, length);
}
Frame* ScriptController::retrieveFrameForEnteredContext()
@@ -95,14 +73,14 @@ bool ScriptController::isSafeScript(Frame* target)
return V8Proxy::CanAccessFrame(target, true);
}
-void ScriptController::gcProtectJSWrapper(void* dom_object)
+void ScriptController::gcProtectJSWrapper(void* domObject)
{
- V8Proxy::GCProtect(dom_object);
+ V8Proxy::GCProtect(domObject);
}
-void ScriptController::gcUnprotectJSWrapper(void* dom_object)
+void ScriptController::gcUnprotectJSWrapper(void* domObject)
{
- V8Proxy::GCUnprotect(dom_object);
+ V8Proxy::GCUnprotect(domObject);
}
ScriptController::ScriptController(Frame* frame)
@@ -152,7 +130,7 @@ void ScriptController::updatePlatformScriptObjects()
notImplemented();
}
-// Disconnect the proxy from its owner frame;
+// Disconnect the proxy from its owner frame.
void ScriptController::disconnectFrame()
{
m_proxy->disconnectFrame();
@@ -160,16 +138,16 @@ void ScriptController::disconnectFrame()
bool ScriptController::processingUserGesture() const
{
- Frame* active_frame = V8Proxy::retrieveFrameForEnteredContext();
- // No script is running, must be run by users.
- if (!active_frame)
+ Frame* activeFrame = V8Proxy::retrieveFrameForEnteredContext();
+ // No script is running, so it must be run by users.
+ if (!activeFrame)
return true;
- V8Proxy* active_proxy = active_frame->script()->proxy();
+ V8Proxy* activeProxy = activeFrame->script()->proxy();
- v8::HandleScope handle_scope;
- v8::Handle<v8::Context> context = V8Proxy::GetContext(active_frame);
- // TODO(fqian): find all cases context can be empty:
+ v8::HandleScope handleScope;
+ v8::Handle<v8::Context> context = V8Proxy::GetContext(activeFrame);
+ // FIXME: find all cases context can be empty:
// 1) JS is disabled;
// 2) page is NULL;
if (context.IsEmpty())
@@ -178,84 +156,68 @@ bool ScriptController::processingUserGesture() const
v8::Context::Scope scope(context);
v8::Handle<v8::Object> global = context->Global();
- v8::Handle<v8::Value> jsevent = global->Get(v8::String::NewSymbol("event"));
- Event* event = V8Proxy::ToNativeEvent(jsevent);
+ v8::Handle<v8::Value> jsEvent = global->Get(v8::String::NewSymbol("event"));
+ Event* event = V8Proxy::ToNativeEvent(jsEvent);
// Based on code from kjs_bindings.cpp.
// Note: This is more liberal than Firefox's implementation.
if (event) {
const AtomicString& type = event->type();
- bool event_ok =
- // mouse events
- type == eventNames().clickEvent ||
- type == eventNames().mousedownEvent ||
- type == eventNames().mouseupEvent ||
- type == eventNames().dblclickEvent ||
- // keyboard events
- type == eventNames().keydownEvent ||
- type == eventNames().keypressEvent ||
- type == eventNames().keyupEvent ||
- // other accepted events
- type == eventNames().selectEvent ||
- type == eventNames().changeEvent ||
- type == eventNames().focusEvent ||
- type == eventNames().blurEvent ||
- type == eventNames().submitEvent;
-
- if (event_ok)
- return true;
- } else if (active_proxy->inlineCode() && !active_proxy->timerCallback())
- // This is the <a href="javascript:window.open('...')> case -> we let it
- // through
+ bool eventOk =
+ // mouse events
+ type == eventNames().clickEvent || type == eventNames().mousedownEvent || type == eventNames().mouseupEvent || type == eventNames().dblclickEvent
+ // keyboard events
+ || type == eventNames().keydownEvent || type == eventNames().keypressEvent || type == eventNames().keyupEvent
+ // other accepted events
+ || type == eventNames().selectEvent || type == eventNames().changeEvent || type == eventNames().focusEvent || type == eventNames().blurEvent || type == eventNames().submitEvent;
+
+ if (eventOk)
+ return true;
+ } else if (activeProxy->inlineCode() && !activeProxy->timerCallback()) {
+ // This is the <a href="javascript:window.open('...')> case -> we let it through.
return true;
+ }
- // This is the <script>window.open(...)</script> case or a timer callback ->
- // block it
+ // This is the <script>window.open(...)</script> case or a timer callback -> block it.
return false;
}
-void ScriptController::evaluateInNewContext(
- const Vector<ScriptSourceCode>& sources) {
- m_proxy->evaluateInNewContext(sources);
+void ScriptController::evaluateInNewContext(const Vector<ScriptSourceCode>& sources)
+{
+ m_proxy->evaluateInNewContext(sources);
}
// Evaluate a script file in the environment of this proxy.
ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode)
{
- v8::HandleScope hs;
+ v8::HandleScope handleScope;
v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame());
if (context.IsEmpty())
return ScriptValue();
v8::Context::Scope scope(context);
- v8::Local<v8::Value> obj = m_proxy->evaluate(sourceCode, NULL);
+ v8::Local<v8::Value> object = m_proxy->evaluate(sourceCode, 0);
- if (obj.IsEmpty() || obj->IsUndefined())
+ if (object.IsEmpty() || object->IsUndefined())
return ScriptValue();
- return ScriptValue(obj);
+ return ScriptValue(object);
}
-void ScriptController::disposeJSResult(v8::Persistent<v8::Value> result)
+void ScriptController::setEventHandlerLineNumber(int lineNumber)
{
- result.Dispose();
- result.Clear();
+ m_proxy->setEventHandlerLineno(lineNumber);
}
-void ScriptController::setEventHandlerLineNumber(int lineno)
+void ScriptController::finishedWithEvent(Event* event)
{
- m_proxy->setEventHandlerLineno(lineno);
+ m_proxy->finishedWithEvent(event);
}
-void ScriptController::finishedWithEvent(Event* evt)
+// Create a V8 object with an interceptor of NPObjectPropertyGetter.
+void ScriptController::bindToWindowObject(Frame* frame, const String& key, NPObject* object)
{
- m_proxy->finishedWithEvent(evt);
-}
-
-// Create a V8 object with an interceptor of NPObjectPropertyGetter
-void ScriptController::BindToWindowObject(Frame* frame, const String& key, NPObject* object)
-{
- v8::HandleScope handle_scope;
+ v8::HandleScope handleScope;
v8::Handle<v8::Context> context = V8Proxy::GetContext(frame);
if (context.IsEmpty())
@@ -263,31 +225,25 @@ void ScriptController::BindToWindowObject(Frame* frame, const String& key, NPObj
v8::Context::Scope scope(context);
- v8::Handle<v8::Object> value = CreateV8ObjectForNPObject(object, NULL);
+ v8::Handle<v8::Object> value = CreateV8ObjectForNPObject(object, 0);
- // Attach to the global object
+ // Attach to the global object.
v8::Handle<v8::Object> global = context->Global();
global->Set(v8String(key), value);
}
void ScriptController::collectGarbage()
{
- v8::HandleScope hs;
+ v8::HandleScope handleScope;
v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame());
if (context.IsEmpty())
return;
v8::Context::Scope scope(context);
- m_proxy->evaluate(ScriptSourceCode("if (window.gc) void(gc());"), NULL);
+ m_proxy->evaluate(ScriptSourceCode("if (window.gc) void(gc());"), 0);
}
-NPRuntimeFunctions* ScriptController::functions()
-{
- return &npruntime_functions;
-}
-
-
bool ScriptController::haveInterpreter() const
{
return m_proxy->ContextInitialized();
@@ -300,7 +256,7 @@ bool ScriptController::isEnabled() const
PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widget)
{
- ASSERT(widget != 0);
+ ASSERT(widget);
if (widget->isFrameView())
return 0;
@@ -314,29 +270,28 @@ PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widge
// NPObjects are treated differently than other objects wrapped by JS.
// NPObjects can be created either by the browser (e.g. the main
// window object) or by the plugin (the main plugin object
- // for a HTMLEmbedElement). Further,
- // unlike most DOM Objects, the frame is especially careful to ensure
- // NPObjects terminate at frame teardown because if a plugin leaks a
- // reference, it could leak its objects (or the browser's objects).
+ // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame
+ // is especially careful to ensure NPObjects terminate at frame teardown because
+ // if a plugin leaks a reference, it could leak its objects (or the browser's objects).
//
// The Frame maintains a list of plugin objects (m_pluginObjects)
// which it can use to quickly find the wrapped embed object.
//
// Inside the NPRuntime, we've added a few methods for registering
- // wrapped NPObjects. The purpose of the registration is because
+ // wrapped NPObjects. The purpose of the registration is because
// javascript garbage collection is non-deterministic, yet we need to
- // be able to tear down the plugin objects immediately. When an object
- // is registered, javascript can use it. When the object is destroyed,
+ // be able to tear down the plugin objects immediately. When an object
+ // is registered, javascript can use it. When the object is destroyed,
// or when the object's "owning" object is destroyed, the object will
// be un-registered, and the javascript engine must not use it.
//
// Inside the javascript engine, the engine can keep a reference to the
- // NPObject as part of its wrapper. However, before accessing the object
+ // NPObject as part of its wrapper. However, before accessing the object
// it must consult the NPN_Registry.
- v8::Local<v8::Object> wrapper = CreateV8ObjectForNPObject(npObject, NULL);
+ v8::Local<v8::Object> wrapper = CreateV8ObjectForNPObject(npObject, 0);
- // Track the plugin object. We've been given a reference to the object.
+ // Track the plugin object. We've been given a reference to the object.
m_pluginObjects.set(widget, npObject);
return V8ScriptInstance::create(wrapper);
@@ -381,10 +336,10 @@ NPObject* ScriptController::windowScriptNPObject()
// JavaScript is enabled, so there is a JavaScript window object.
// Return an NPObject bound to the window object.
m_windowScriptNPObject = createScriptObject(m_frame);
- _NPN_RegisterObject(m_windowScriptNPObject, NULL);
+ _NPN_RegisterObject(m_windowScriptNPObject, 0);
} else {
// JavaScript is not enabled, so we cannot bind the NPObject to the
- // JavaScript window object. Instead, we create an NPObject of a
+ // JavaScript window object. Instead, we create an NPObject of a
// different class, one which is not bound to a JavaScript object.
m_windowScriptNPObject = createNoScriptObject();
}
@@ -393,7 +348,7 @@ NPObject* ScriptController::windowScriptNPObject()
NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement* plugin)
{
- // Can't create NPObjects when JavaScript is disabled
+ // Can't create NPObjects when JavaScript is disabled.
if (!isEnabled())
return createNoScriptObject();
@@ -430,4 +385,4 @@ void ScriptController::updateDocument()
m_proxy->updateDocument();
}
-} // namespace WebCpre
+} // namespace WebCore
diff --git a/webkit/port/bindings/v8/ScriptController.h b/webkit/port/bindings/v8/ScriptController.h
index 6f052d2..e84731d 100644
--- a/webkit/port/bindings/v8/ScriptController.h
+++ b/webkit/port/bindings/v8/ScriptController.h
@@ -1,266 +1,169 @@
-// Copyright 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.
-
-// An interface to abstract implementation differences
-// for various Javascript engines.
+/*
+ * Copyright (C) 2008, 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.
+ */
#ifndef ScriptController_h
#define ScriptController_h
-#include "HashMap.h"
-#include "MessagePort.h"
#include "ScriptInstance.h"
#include "ScriptValue.h"
-#include "SecurityOrigin.h"
-#include "bindings/npruntime.h"
+#include "V8Proxy.h"
+
+#include <v8.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
-#include "v8.h"
-#include "v8_proxy.h"
-
-// JavaScript implementations which expose NPObject will need to implement
-// these methods.
-typedef void (*NPN_ReleaseVariantValueProcPtr) (NPVariant *variant);
-
-typedef NPIdentifier(*NPN_GetStringIdentifierProcPtr) (const NPUTF8 *name);
-typedef void (*NPN_GetStringIdentifiersProcPtr) (const NPUTF8 **names,
- int32_t nameCount,
- NPIdentifier *identifiers);
-typedef NPIdentifier(*NPN_GetIntIdentifierProcPtr) (int32_t intid);
-typedef int32_t (*NPN_IntFromIdentifierProcPtr) (NPIdentifier identifier);
-typedef bool (*NPN_IdentifierIsStringProcPtr) (NPIdentifier identifier);
-typedef NPUTF8 * (*NPN_UTF8FromIdentifierProcPtr) (NPIdentifier identifier);
-
-typedef NPObject* (*NPN_CreateObjectProcPtr) (NPP,
- NPClass *aClass);
-typedef NPObject* (*NPN_RetainObjectProcPtr) (NPObject *obj);
-typedef void (*NPN_ReleaseObjectProcPtr) (NPObject *obj);
-typedef bool (*NPN_InvokeProcPtr) (NPP npp,
- NPObject *obj,
- NPIdentifier methodName,
- const NPVariant *args,
- unsigned argCount,
- NPVariant *result);
-typedef bool (*NPN_InvokeDefaultProcPtr) (NPP npp,
- NPObject *obj,
- const NPVariant *args,
- unsigned argCount,
- NPVariant *result);
-typedef bool (*NPN_EvaluateProcPtr) (NPP npp,
- NPObject *obj,
- NPString *script,
- NPVariant *result);
-typedef bool (*NPN_GetPropertyProcPtr) (NPP npp,
- NPObject *obj,
- NPIdentifier propertyName,
- NPVariant *result);
-typedef bool (*NPN_SetPropertyProcPtr) (NPP npp,
- NPObject *obj,
- NPIdentifier propertyName,
- const NPVariant *value);
-typedef bool (*NPN_HasPropertyProcPtr) (NPP,
- NPObject *npobj,
- NPIdentifier propertyName);
-typedef bool (*NPN_HasMethodProcPtr) (NPP npp,
- NPObject *npobj,
- NPIdentifier methodName);
-typedef bool (*NPN_RemovePropertyProcPtr) (NPP npp,
- NPObject *obj,
- NPIdentifier propertyName);
-typedef void (*NPN_SetExceptionProcPtr) (NPObject *obj,
- const NPUTF8 *message);
-
-typedef struct _NPRuntimeFunctions {
- NPN_GetStringIdentifierProcPtr getStringIdentifier;
- NPN_GetStringIdentifiersProcPtr getStringIdentifiers;
- NPN_GetIntIdentifierProcPtr getIntIdentifier;
- NPN_IdentifierIsStringProcPtr identifierIsString;
- NPN_UTF8FromIdentifierProcPtr utf8FromIdentifier;
- NPN_IntFromIdentifierProcPtr intFromIdentifier;
- NPN_CreateObjectProcPtr createObject;
- NPN_RetainObjectProcPtr retainObject;
- NPN_ReleaseObjectProcPtr releaseObject;
- NPN_InvokeProcPtr invoke;
- NPN_InvokeDefaultProcPtr invokeDefault;
- NPN_EvaluateProcPtr evaluate;
- NPN_GetPropertyProcPtr getProperty;
- NPN_SetPropertyProcPtr setProperty;
- NPN_RemovePropertyProcPtr removeProperty;
- NPN_HasPropertyProcPtr hasProperty;
- NPN_HasMethodProcPtr hasMethod;
- NPN_ReleaseVariantValueProcPtr releaseVariantValue;
- NPN_SetExceptionProcPtr setException;
-} NPRuntimeFunctions;
-
namespace WebCore {
-class Document;
-class EventListener;
-class Event;
-class Frame;
-class HTMLPlugInElement;
-class Node;
-class ScriptSourceCode;
-class ScriptState;
-class String;
-class Widget;
-
-typedef v8::Local<v8::Object> JSInstance;
-typedef v8::Local<v8::Object> JSInstanceHandle;
-typedef v8::Persistent<v8::Object> JSPersistentInstance;
-typedef v8::Local<v8::Value> JSException;
-typedef v8::Persistent<v8::Value> JSResult;
-
-class ScriptController {
-public:
- ScriptController(Frame*);
- ~ScriptController();
-
- // TODO(eseidel): V8Proxy should either be folded into ScriptController
- // or this accessor should be made JSProxy*
- V8Proxy* proxy() { return m_proxy.get(); }
+ class Event;
+ class Frame;
+ class HTMLPlugInElement;
+ class ScriptSourceCode;
+ class ScriptState;
+ class String;
+ class Widget;
- // 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&);
+ class ScriptController {
+ public:
+ ScriptController(Frame*);
+ ~ScriptController();
- // Executes JavaScript in a new context associated with the web frame. The
- // script gets its own global scope and its own prototypes for intrinsic
- // JavaScript objects (String, Array, and so-on). It shares the wrappers for
- // all DOM nodes and DOM constructors.
- void evaluateInNewContext(const Vector<ScriptSourceCode>& sources);
+ // FIXME: V8Proxy should either be folded into ScriptController
+ // or this accessor should be made JSProxy*
+ V8Proxy* proxy() { return m_proxy.get(); }
- // JSC has a WindowShell object, but for V8, the ScriptController
- // is the WindowShell.
- bool haveWindowShell() const { return true; }
+ // 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&);
- // Masquerade 'this' as the windowShell.
- // This is a bit of a hack, but provides reasonable compatibility
- // with what JSC does as well.
- ScriptController* windowShell() { return this; }
+ // Executes JavaScript in a new context associated with the web frame. The
+ // script gets its own global scope and its own prototypes for intrinsic
+ // JavaScript objects (String, Array, and so-on). It shares the wrappers for
+ // all DOM nodes and DOM constructors.
+ void evaluateInNewContext(const Vector<ScriptSourceCode>&);
- ScriptState* state() const { return m_scriptState.get(); }
+ // JSC has a WindowShell object, but for V8, the ScriptController
+ // is the WindowShell.
+ bool haveWindowShell() const { return true; }
- void disposeJSResult(JSResult result);
- void collectGarbage();
+ // Masquerade 'this' as the windowShell.
+ // This is a bit of a hack, but provides reasonable compatibility
+ // with what JSC does as well.
+ ScriptController* windowShell() { return this; }
- // Creates a property of the global object of a frame.
- void BindToWindowObject(Frame*, const String& key, NPObject*);
+ ScriptState* state() const { return m_scriptState.get(); }
- NPRuntimeFunctions* functions();
+ void collectGarbage();
- PassScriptInstance createScriptInstanceForWidget(Widget*);
+ // Creates a property of the global object of a frame.
+ void bindToWindowObject(Frame*, const String& key, NPObject*);
- void disconnectFrame();
+ PassScriptInstance createScriptInstanceForWidget(Widget*);
- // Check if the javascript engine has been initialized.
- bool haveInterpreter() const;
+ void disconnectFrame();
- bool isEnabled() const;
+ // Check if the javascript engine has been initialized.
+ bool haveInterpreter() const;
- // TODO(eseidel): void* is a compile hack
- void attachDebugger(void*);
+ bool isEnabled() const;
- // Create a NPObject wrapper for a JSObject
- // NPObject *WrapScriptObject(NPP pluginId, JSObject* objectToWrap,
- // JSRootObject* originRootObject,
- // JSRootObject* rootObject);
+ // FIXME: void* is a compile hack.
+ void attachDebugger(void*);
- // --- Static methods assume we are running VM in single thread, ---
- // --- and there is only one VM instance. ---
+ // --- Static methods assume we are running VM in single thread, ---
+ // --- and there is only one VM instance. ---
- // Returns the frame for the entered context. See comments in
- // V8Proxy::retrieveFrameForEnteredContext() for more information.
- static Frame* retrieveFrameForEnteredContext();
+ // Returns the frame for the entered context. See comments in
+ // V8Proxy::retrieveFrameForEnteredContext() for more information.
+ static Frame* retrieveFrameForEnteredContext();
- // Returns the frame for the current context. See comments in
- // V8Proxy::retrieveFrameForEnteredContext() for more information.
- static Frame* retrieveFrameForCurrentContext();
+ // Returns the frame for the current context. See comments in
+ // V8Proxy::retrieveFrameForEnteredContext() for more information.
+ static Frame* retrieveFrameForCurrentContext();
- // Check whether it is safe to access a frame in another domain.
- static bool isSafeScript(Frame* target);
+ // Check whether it is safe to access a frame in another domain.
+ static bool isSafeScript(Frame*);
- // Pass command-line flags to the JS engine
- static void setFlags(const char* str, int length);
+ // Pass command-line flags to the JS engine.
+ static void setFlags(const char* string, int length);
- // Protect and unprotect the JS wrapper from garbage collected.
- static void gcProtectJSWrapper(void* object);
- static void gcUnprotectJSWrapper(void* object);
+ // Protect and unprotect the JS wrapper from garbage collected.
+ static void gcProtectJSWrapper(void*);
+ static void gcUnprotectJSWrapper(void*);
- void finishedWithEvent(Event*);
- void setEventHandlerLineNumber(int lineno);
+ void finishedWithEvent(Event*);
+ void setEventHandlerLineNumber(int lineNumber);
- void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; }
- bool processingUserGesture() const;
+ void setProcessingTimerCallback(bool processingTimerCallback) { m_processingTimerCallback = processingTimerCallback; }
+ bool processingUserGesture() const;
- void setPaused(bool b) { m_paused = b; }
- bool isPaused() const { return m_paused; }
+ void setPaused(bool paused) { m_paused = paused; }
+ bool isPaused() const { return m_paused; }
- const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script
+ const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script.
- void clearWindowShell();
- void updateDocument();
+ void clearWindowShell();
+ void updateDocument();
- void updateSecurityOrigin();
- void clearScriptObjects();
- void updatePlatformScriptObjects();
- void cleanupScriptObjectsForPlugin(void*);
+ void updateSecurityOrigin();
+ void clearScriptObjects();
+ void updatePlatformScriptObjects();
+ void cleanupScriptObjectsForPlugin(void*);
#if ENABLE(NETSCAPE_PLUGIN_API)
- NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*);
- NPObject* windowScriptNPObject();
+ NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*);
+ NPObject* windowScriptNPObject();
#endif
-private:
- Frame* m_frame;
- const String* m_sourceURL;
+ private:
+ Frame* m_frame;
+ const String* m_sourceURL;
- bool m_processingTimerCallback;
- bool m_paused;
+ bool m_processingTimerCallback;
+ bool m_paused;
- OwnPtr<ScriptState> m_scriptState;
- OwnPtr<V8Proxy> m_proxy;
- typedef HashMap<void*, NPObject*> PluginObjectMap;
+ OwnPtr<ScriptState> m_scriptState;
+ OwnPtr<V8Proxy> m_proxy;
+ typedef HashMap<void*, NPObject*> PluginObjectMap;
- // A mapping between Widgets and their corresponding script object.
- // This list is used so that when the plugin dies, we can immediately
- // invalidate all sub-objects which are associated with that plugin.
- // The frame keeps a NPObject reference for each item on the list.
- PluginObjectMap m_pluginObjects;
+ // A mapping between Widgets and their corresponding script object.
+ // This list is used so that when the plugin dies, we can immediately
+ // invalidate all sub-objects which are associated with that plugin.
+ // The frame keeps a NPObject reference for each item on the list.
+ PluginObjectMap m_pluginObjects;
#if ENABLE(NETSCAPE_PLUGIN_API)
- NPObject* m_windowScriptNPObject;
+ NPObject* m_windowScriptNPObject;
#endif
-};
+ };
-} // namespace WebCore
+} // namespace WebCore
-#endif // ScriptController_h
+#endif // ScriptController_h