diff options
author | Feng Qian <fqian@google.com> | 2009-04-24 16:01:03 -0700 |
---|---|---|
committer | Feng Qian <fqian@google.com> | 2009-04-24 16:01:03 -0700 |
commit | 109a58c31072b14f5b2c0493ed6c5a1855f82fd7 (patch) | |
tree | 134f7efdba4ea4d9b6dfb660bbcb47b4d54f9ad7 | |
parent | ac888b0a574d343996d06d2b084eaebab7846d81 (diff) | |
download | external_webkit-109a58c31072b14f5b2c0493ed6c5a1855f82fd7.zip external_webkit-109a58c31072b14f5b2c0493ed6c5a1855f82fd7.tar.gz external_webkit-109a58c31072b14f5b2c0493ed6c5a1855f82fd7.tar.bz2 |
Make WebCore built with V8.
Picked up several new files from Chrome port.
46 files changed, 2521 insertions, 357 deletions
diff --git a/JavaScriptCore/wtf/Platform.h b/JavaScriptCore/wtf/Platform.h index 9ab0af8..23e6c8b 100644 --- a/JavaScriptCore/wtf/Platform.h +++ b/JavaScriptCore/wtf/Platform.h @@ -189,6 +189,9 @@ // Prevents Webkit from drawing the caret in textfields and textareas // This prevents unnecessary invals. #define ENABLE_TEXT_CARET 1 +#if WTF_USE_V8 +#define ENABLE_JAVASCRIPT_DEBUGGER 0 +#endif #endif // ANDROID /* CPU */ diff --git a/V8Binding/V8Binding.derived.mk b/V8Binding/V8Binding.derived.mk index aa65ffa..2515887 100644 --- a/V8Binding/V8Binding.derived.mk +++ b/V8Binding/V8Binding.derived.mk @@ -15,14 +15,17 @@ ## limitations under the License. ## -LOCAL_CFLAGS += -DWTF_USE_V8 +LOCAL_CFLAGS += -DWTF_USE_V8=1 v8binding_dir := $(LOCAL_PATH) BINDING_C_INCLUDES := \ $(BASE_PATH)/v8/include \ $(WEBCORE_PATH)/bindings/v8 \ + $(WEBCORE_PATH)/bindings/v8/custom \ + $(WEBCORE_PATH)/bridge/jni \ $(LOCAL_PATH)/v8 \ + $(LOCAL_PATH)/npapi \ $(JAVASCRIPTCORE_PATH)/wtf \ $(JAVASCRIPTCORE_PATH) @@ -48,14 +51,10 @@ WEBCORE_SRC_FILES := \ bindings/v8/custom/V8ClipboardCustom.cpp \ bindings/v8/custom/V8CustomBinding.cpp \ bindings/v8/custom/V8CustomEventListener.cpp \ - bindings/v8/custom/V8CustomSQLStatementCallback.cpp \ - bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp \ - bindings/v8/custom/V8CustomSQLTransactionCallback.cpp \ - bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp \ bindings/v8/custom/V8CustomVoidCallback.cpp \ bindings/v8/custom/V8DOMParserConstructor.cpp \ bindings/v8/custom/V8DOMStringListCustom.cpp \ - bindings/v8/custom/V8DatabaseCustom.cpp \ + bindings/v8/custom/V8DOMWindowCustom.cpp \ bindings/v8/custom/V8DocumentCustom.cpp \ bindings/v8/custom/V8ElementCustom.cpp \ bindings/v8/custom/V8EventCustom.cpp \ @@ -70,7 +69,6 @@ WEBCORE_SRC_FILES := \ bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp \ bindings/v8/custom/V8HTMLPlugInElementCustom.cpp \ bindings/v8/custom/V8HTMLSelectElementCustom.cpp \ - bindings/v8/custom/V8InspectorControllerCustom.cpp \ bindings/v8/custom/V8LocationCustom.cpp \ bindings/v8/custom/V8MessageChannelConstructor.cpp \ bindings/v8/custom/V8NamedNodeMapCustom.cpp \ @@ -80,8 +78,17 @@ WEBCORE_SRC_FILES := \ bindings/v8/custom/V8NodeFilterCustom.cpp \ bindings/v8/custom/V8NodeIteratorCustom.cpp \ bindings/v8/custom/V8NodeListCustom.cpp \ - bindings/v8/custom/V8SQLResultSetRowListCustom.cpp \ + +ifeq ($(ENABLE_STORAGE), true) +WEBCORE_SRC_FILES := $(WEBCORE_SRC_FILES) \ + bindings/v8/custom/V8DatabaseCustom.cpp \ bindings/v8/custom/V8SQLTransactionCustom.cpp + bindings/v8/custom/V8CustomSQLStatementCallback.cpp \ + bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp \ + bindings/v8/custom/V8CustomSQLTransactionCallback.cpp \ + bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp \ + bindings/v8/custom/V8SQLResultSetRowListCustom.cpp +endif ifeq ($(ENABLE_SVG), true) WEBCORE_SRC_FILES := $(WEBCORE_SRC_FILES) \ @@ -98,10 +105,8 @@ WEBCORE_SRC_FILES := $(WEBCORE_SRC_FILES) \ bindings/v8/custom/V8XMLHttpRequestCustom.cpp \ bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp \ bindings/v8/custom/V8XMLSerializerConstructor.cpp \ - bindings/v8/custom/V8XPathEvaluatorConstructor.cpp \ - bindings/v8/custom/V8XSLTProcessorCustom.cpp \ - \ - bridge/jni/jni_utility.cpp + \ + bridge/jni/jni_utility.cpp LOCAL_SRC_FILES := \ v8/JSDOMBinding.cpp \ @@ -158,6 +163,7 @@ GEN := \ $(intermediates)/css/V8StyleSheetList.h \ $(intermediates)/css/V8WebKitCSSKeyframeRule.h \ $(intermediates)/css/V8WebKitCSSKeyframesRule.h \ + $(intermediates)/css/V8WebKitCSSMatrix.h \ $(intermediates)/css/V8WebKitCSSTransformValue.h $(GEN): PRIVATE_CUSTOM_TOOL = SOURCE_ROOT=$(WEBCORE_PATH) perl -I$(v8binding_dir)/scripts -I$(WEBCORE_PATH)/bindings/scripts $(v8binding_dir)/scripts/generate-bindings.pl --defines "$(FEATURE_DEFINES) LANGUAGE_JAVASCRIPT" --generator V8 --include css --include dom --include html --outputdir $(dir $@) $< $(GEN): $(intermediates)/css/V8%.h : $(WEBCORE_PATH)/css/%.idl $(js_binding_scripts) @@ -349,6 +355,27 @@ LOCAL_GENERATED_SOURCES += $(GEN) $(GEN:%.h=%.cpp) # above rules. Specifying this explicitly makes -j2 work. $(patsubst %.h,%.cpp,$(GEN)): $(intermediates)/plugins/%.cpp : $(intermediates)/plugins/%.h +ifeq ($(ENABLE_STORAGE),true) +# Storage support +GEN := \ + $(intermediates)/storage/V8Database.h \ + $(intermediates)/storage/V8SQLError.h \ + $(intermediates)/storage/V8SQLResultSet.h \ + $(intermediates)/storage/V8SQLResultSetRowList.h \ + $(intermediates)/storage/V8SQLTransaction.h \ + $(intermediates)/storage/V8Storage.h \ + $(intermediates)/storage/V8StorageEvent.h + +$(GEN): PRIVATE_CUSTOM_TOOL = SOURCE_ROOT=$(WEBCORE_PATH) perl -I$(v8binding_dir)/scripts -I$(WEBCORE_PATH)/bindings/scripts $(v8binding_dir)/scripts/generate-bindings.pl --defines "$(FEATURE_DEFINES) LANGUAGE_JAVASCRIPT" --generator V8 --include dom --include html --outputdir $(dir $@) $< +$(GEN): $(intermediates)/storage/V8%.h : $(WEBCORE_PATH)/storage/%.idl $(js_binding_scripts) + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) $(GEN:%.h=%.cpp) + +# We also need the .cpp files, which are generated as side effects of the +# above rules. Specifying this explicitly makes -j2 work. +$(patsubst %.h,%.cpp,$(GEN)): $(intermediates)/storage/%.cpp : $(intermediates)/storage/%.h +endif + #new section for xml/DOMParser.idl GEN := \ $(intermediates)/xml/V8DOMParser.h \ @@ -356,8 +383,11 @@ GEN := \ $(intermediates)/xml/V8XMLHttpRequestException.h \ $(intermediates)/xml/V8XMLHttpRequestProgressEvent.h \ $(intermediates)/xml/V8XMLHttpRequestUpload.h \ - $(intermediates)/xml/V8XMLSerializer.h \ - $(intermediates)/xml/V8XPathEvaluator.h \ + $(intermediates)/xml/V8XMLSerializer.h + + +# $(intermediates)/xml/V8XPathEvaluator.h \ + $(intermediates)/xml/V8XPathException.h \ $(intermediates)/xml/V8XPathExpression.h \ $(intermediates)/xml/V8XPathNSResolver.h \ $(intermediates)/xml/V8XPathResult.h \ diff --git a/V8Binding/npapi/README b/V8Binding/npapi/README new file mode 100644 index 0000000..0522ba2 --- /dev/null +++ b/V8Binding/npapi/README @@ -0,0 +1,3 @@ +Copy from WebCore/bridge. + +We only need npapi.h and npruntime.h. Chrome's version is also tied to Chromme codebase. diff --git a/V8Binding/npapi/npapi.h b/V8Binding/npapi/npapi.h new file mode 100644 index 0000000..43b701b --- /dev/null +++ b/V8Binding/npapi/npapi.h @@ -0,0 +1,853 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + + /* + * Netscape client plug-in API spec + */ + + +#ifndef _NPAPI_H_ +#define _NPAPI_H_ + +#ifdef INCLUDE_JAVA +#include "jri.h" /* Java Runtime Interface */ +#else +#define jref void * +#define JRIEnv void +#endif + +#ifdef _WIN32 +# ifndef XP_WIN +# define XP_WIN 1 +# endif /* XP_WIN */ +#endif /* _WIN32 */ + +#ifdef __MWERKS__ +# define _declspec __declspec +# ifdef macintosh +# ifndef XP_MAC +# define XP_MAC 1 +# endif /* XP_MAC */ +# endif /* macintosh */ +# ifdef __INTEL__ +# undef NULL +# ifndef XP_WIN +# define XP_WIN 1 +# endif /* __INTEL__ */ +# endif /* XP_PC */ +#endif /* __MWERKS__ */ + +#if defined(__APPLE_CC__) && !defined(__MACOS_CLASSIC__) && !defined(XP_UNIX) +# define XP_MACOSX +#endif + +#ifdef XP_MAC + #include <Quickdraw.h> + #include <Events.h> +#endif + +#if defined(XP_MACOSX) && defined(__LP64__) +#define NP_NO_QUICKDRAW +#define NP_NO_CARBON +#endif + +#ifdef XP_MACOSX + #include <ApplicationServices/ApplicationServices.h> + #include <OpenGL/OpenGL.h> +#ifndef NP_NO_CARBON + #include <Carbon/Carbon.h> +#endif +#endif + +#ifdef XP_UNIX + #include <X11/Xlib.h> + #include <X11/Xutil.h> + #include <stdio.h> +#endif + +#ifdef XP_WIN + #include <windows.h> +#endif + +/*----------------------------------------------------------------------*/ +/* Plugin Version Constants */ +/*----------------------------------------------------------------------*/ + +#define NP_VERSION_MAJOR 0 +#define NP_VERSION_MINOR 24 + +/*----------------------------------------------------------------------*/ +/* Definition of Basic Types */ +/*----------------------------------------------------------------------*/ + +#ifndef _UINT16 +#define _UINT16 +typedef unsigned short uint16; +#endif + +#ifndef _UINT32 +#define _UINT32 +#ifdef __LP64__ +typedef unsigned int uint32; +#else /* __LP64__ */ +typedef unsigned long uint32; +#endif /* __LP64__ */ +#endif + +#ifndef _INT16 +#define _INT16 +typedef short int16; +#endif + +#ifndef _INT32 +#define _INT32 +#ifdef __LP64__ +typedef int int32; +#else /* __LP64__ */ +typedef long int32; +#endif /* __LP64__ */ +#endif + +#ifndef FALSE +#define FALSE (0) +#endif +#ifndef TRUE +#define TRUE (1) +#endif +#ifndef NULL +#define NULL (0L) +#endif + +typedef unsigned char NPBool; +typedef int16 NPError; +typedef int16 NPReason; +typedef char* NPMIMEType; + + + +/*----------------------------------------------------------------------*/ +/* Structures and definitions */ +/*----------------------------------------------------------------------*/ + +#if !defined(__LP64__) +#if defined(XP_MAC) || defined(XP_MACOSX) +#pragma options align=mac68k +#endif +#endif /* __LP64__ */ + +/* + * NPP is a plug-in's opaque instance handle + */ +typedef struct _NPP +{ + void* pdata; /* plug-in private data */ + void* ndata; /* netscape private data */ +} NPP_t; + +typedef NPP_t* NPP; + + +typedef struct _NPStream +{ + void* pdata; /* plug-in private data */ + void* ndata; /* netscape private data */ + const char* url; + uint32 end; + uint32 lastmodified; + void* notifyData; + const char* headers; /* Response headers from host. + * Exists only for >= NPVERS_HAS_RESPONSE_HEADERS. + * Used for HTTP only; NULL for non-HTTP. + * Available from NPP_NewStream onwards. + * Plugin should copy this data before storing it. + * Includes HTTP status line and all headers, + * preferably verbatim as received from server, + * headers formatted as in HTTP ("Header: Value"), + * and newlines (\n, NOT \r\n) separating lines. + * Terminated by \n\0 (NOT \n\n\0). */ +} NPStream; + + +typedef struct _NPByteRange +{ + int32 offset; /* negative offset means from the end */ + uint32 length; + struct _NPByteRange* next; +} NPByteRange; + + +typedef struct _NPSavedData +{ + int32 len; + void* buf; +} NPSavedData; + + +typedef struct _NPRect +{ + uint16 top; + uint16 left; + uint16 bottom; + uint16 right; +} NPRect; + + +#ifdef XP_UNIX +/* + * Unix specific structures and definitions + */ + +/* + * Callback Structures. + * + * These are used to pass additional platform specific information. + */ +enum { + NP_SETWINDOW = 1, + NP_PRINT +}; + +typedef struct +{ + int32 type; +} NPAnyCallbackStruct; + +typedef struct +{ + int32 type; + Display* display; + Visual* visual; + Colormap colormap; + unsigned int depth; +} NPSetWindowCallbackStruct; + +typedef struct +{ + int32 type; + FILE* fp; +} NPPrintCallbackStruct; + +#endif /* XP_UNIX */ + +/* + * The following masks are applied on certain platforms to NPNV and + * NPPV selectors that pass around pointers to COM interfaces. Newer + * compilers on some platforms may generate vtables that are not + * compatible with older compilers. To prevent older plugins from + * not understanding a new browser's ABI, these masks change the + * values of those selectors on those platforms. To remain backwards + * compatible with differenet versions of the browser, plugins can + * use these masks to dynamically determine and use the correct C++ + * ABI that the browser is expecting. This does not apply to Windows + * as Microsoft's COM ABI will likely not change. + */ + +#define NP_ABI_GCC3_MASK 0x10000000 +/* + * gcc 3.x generated vtables on UNIX and OSX are incompatible with + * previous compilers. + */ +#if (defined (XP_UNIX) && defined(__GNUC__) && (__GNUC__ >= 3)) +#define _NP_ABI_MIXIN_FOR_GCC3 NP_ABI_GCC3_MASK +#else +#define _NP_ABI_MIXIN_FOR_GCC3 0 +#endif + +#define NP_ABI_MACHO_MASK 0x01000000 +/* + * On OSX, the Mach-O executable format is significantly + * different than CFM. In addition to having a different + * C++ ABI, it also has has different C calling convention. + * You must use glue code when calling between CFM and + * Mach-O C functions. + */ +#if (defined(TARGET_RT_MAC_MACHO)) +#define _NP_ABI_MIXIN_FOR_MACHO NP_ABI_MACHO_MASK +#else +#define _NP_ABI_MIXIN_FOR_MACHO 0 +#endif + + +#define NP_ABI_MASK (_NP_ABI_MIXIN_FOR_GCC3 | _NP_ABI_MIXIN_FOR_MACHO) + +/* + * List of variable names for which NPP_GetValue shall be implemented + */ +typedef enum { + NPPVpluginNameString = 1, + NPPVpluginDescriptionString, + NPPVpluginWindowBool, + NPPVpluginTransparentBool, + + NPPVjavaClass, /* Not implemented in WebKit */ + NPPVpluginWindowSize, /* Not implemented in WebKit */ + NPPVpluginTimerInterval, /* Not implemented in WebKit */ + + NPPVpluginScriptableInstance = (10 | NP_ABI_MASK), /* Not implemented in WebKit */ + NPPVpluginScriptableIID = 11, /* Not implemented in WebKit */ + + /* 12 and over are available on Mozilla builds starting with 0.9.9 */ + NPPVjavascriptPushCallerBool = 12, /* Not implemented in WebKit */ + NPPVpluginKeepLibraryInMemory = 13, /* Not implemented in WebKit */ + NPPVpluginNeedsXEmbed = 14, /* Not implemented in WebKit */ + + /* Get the NPObject for scripting the plugin. */ + NPPVpluginScriptableNPObject = 15, + + /* Get the plugin value (as \0-terminated UTF-8 string data) for + * form submission if the plugin is part of a form. Use + * NPN_MemAlloc() to allocate memory for the string data. + */ + NPPVformValue = 16, /* Not implemented in WebKit */ + + NPPVpluginUrlRequestsDisplayedBool = 17, /* Not implemented in WebKit */ + + /* Checks if the plugin is interested in receiving the http body of + * failed http requests (http status != 200). + */ + NPPVpluginWantsAllNetworkStreams = 18, + + NPPVpluginPrivateModeBool = 19, + + /* Checks to see if the plug-in would like the browser to load the "src" attribute. */ + NPPVpluginCancelSrcStream = 20, + +#ifdef XP_MACOSX + /* Used for negotiating drawing models */ + NPPVpluginDrawingModel = 1000, + /* Used for negotiating event models */ + NPPVpluginEventModel = 1001, + /* In the NPDrawingModelCoreAnimation drawing model, the browser asks the plug-in for a Core Animation layer. */ + NPPVpluginCoreAnimationLayer = 1003 +#endif + +#ifdef ANDROID + NPPFakeValueToForce32Bits = 0x7FFFFFFF +#endif +} NPPVariable; + +/* + * List of variable names for which NPN_GetValue is implemented by Mozilla + */ +typedef enum { + NPNVxDisplay = 1, + NPNVxtAppContext, + NPNVnetscapeWindow, + NPNVjavascriptEnabledBool, + NPNVasdEnabledBool, + NPNVisOfflineBool, + + /* 10 and over are available on Mozilla builds starting with 0.9.4 */ + NPNVserviceManager = (10 | NP_ABI_MASK), /* Not implemented in WebKit */ + NPNVDOMElement = (11 | NP_ABI_MASK), /* Not implemented in WebKit */ + NPNVDOMWindow = (12 | NP_ABI_MASK), /* Not implemented in WebKit */ + NPNVToolkit = (13 | NP_ABI_MASK), /* Not implemented in WebKit */ + NPNVSupportsXEmbedBool = 14, /* Not implemented in WebKit */ + + /* Get the NPObject wrapper for the browser window. */ + NPNVWindowNPObject = 15, + + /* Get the NPObject wrapper for the plugins DOM element. */ + NPNVPluginElementNPObject = 16, + + NPNVSupportsWindowless = 17, + + NPNVprivateModeBool = 18 + +#ifdef XP_MACOSX + , NPNVpluginDrawingModel = 1000 /* The NPDrawingModel specified by the plugin */ + +#ifndef NP_NO_QUICKDRAW + , NPNVsupportsQuickDrawBool = 2000 /* TRUE if the browser supports the QuickDraw drawing model */ +#endif + , NPNVsupportsCoreGraphicsBool = 2001 /* TRUE if the browser supports the CoreGraphics drawing model */ + , NPNVsupportsOpenGLBool = 2002 /* TRUE if the browser supports the OpenGL drawing model (CGL on Mac) */ + , NPNVsupportsCoreAnimationBool = 2003 /* TRUE if the browser supports the CoreAnimation drawing model */ + +#ifndef NP_NO_CARBON + , NPNVsupportsCarbonBool = 3000 /* TRUE if the browser supports the Carbon event model */ +#endif + , NPNVsupportsCocoaBool = 3001 /* TRUE if the browser supports the Cocoa event model */ + +#endif /* XP_MACOSX */ + +#ifdef ANDROID + , NPNFakeValueToForce32Bits = 0x7FFFFFFF +#endif +} NPNVariable; + +typedef enum { + NPNURLVCookie = 501, + NPNURLVProxy +} NPNURLVariable; + +/* + * The type of a NPWindow - it specifies the type of the data structure + * returned in the window field. + */ +typedef enum { + NPWindowTypeWindow = 1, + NPWindowTypeDrawable +} NPWindowType; + +#ifdef XP_MACOSX + +/* + * The drawing model for a Mac OS X plugin. These are the possible values for the NPNVpluginDrawingModel variable. + */ + +typedef enum { +#ifndef NP_NO_QUICKDRAW + NPDrawingModelQuickDraw = 0, +#endif + NPDrawingModelCoreGraphics = 1, + NPDrawingModelOpenGL = 2, + NPDrawingModelCoreAnimation = 3 +} NPDrawingModel; + +/* + * The event model for a Mac OS X plugin. These are the possible values for the NPNVpluginEventModel variable. + */ + +typedef enum { +#ifndef NP_NO_CARBON + NPEventModelCarbon = 0, +#endif + NPEventModelCocoa = 1, +} NPEventModel; + +typedef enum { + NPCocoaEventDrawRect = 1, + NPCocoaEventMouseDown, + NPCocoaEventMouseUp, + NPCocoaEventMouseMoved, + NPCocoaEventMouseEntered, + NPCocoaEventMouseExited, + NPCocoaEventMouseDragged, + NPCocoaEventKeyDown, + NPCocoaEventKeyUp, + NPCocoaEventFlagsChanged, + NPCocoaEventFocusChanged, + NPCocoaEventWindowFocusChanged, + NPCocoaEventScrollWheel, + NPCocoaEventTextInput +} NPCocoaEventType; + +typedef struct _NPNSString NPNSString; +typedef struct _NPNSWindow NPNSWindow; +typedef struct _NPNSMenu NPNSMenu; + +typedef struct _NPCocoaEvent { + NPCocoaEventType type; + uint32 version; + + union { + struct { + uint32 modifierFlags; + double pluginX; + double pluginY; + int32 buttonNumber; + int32 clickCount; + double deltaX; + double deltaY; + double deltaZ; + } mouse; + struct { + uint32 modifierFlags; + NPNSString *characters; + NPNSString *charactersIgnoringModifiers; + NPBool isARepeat; + uint16 keyCode; + } key; + struct { + double x; + double y; + double width; + double height; + } draw; + struct { + NPBool hasFocus; + } focus; + struct { + NPNSString *text; + } text; + } data; +} NPCocoaEvent; + +#endif + +typedef struct _NPWindow +{ + void* window; /* Platform specific window handle */ + int32 x; /* Position of top left corner relative */ + int32 y; /* to a netscape page. */ + uint32 width; /* Maximum window size */ + uint32 height; + NPRect clipRect; /* Clipping rectangle in port coordinates */ + /* Used by MAC only. */ +#ifdef XP_UNIX + void * ws_info; /* Platform-dependent additonal data */ +#endif /* XP_UNIX */ + NPWindowType type; /* Is this a window or a drawable? */ +} NPWindow; + + +typedef struct _NPFullPrint +{ + NPBool pluginPrinted; /* Set TRUE if plugin handled fullscreen */ + /* printing */ + NPBool printOne; /* TRUE if plugin should print one copy */ + /* to default printer */ + void* platformPrint; /* Platform-specific printing info */ +} NPFullPrint; + +typedef struct _NPEmbedPrint +{ + NPWindow window; + void* platformPrint; /* Platform-specific printing info */ +} NPEmbedPrint; + +typedef struct _NPPrint +{ + uint16 mode; /* NP_FULL or NP_EMBED */ + union + { + NPFullPrint fullPrint; /* if mode is NP_FULL */ + NPEmbedPrint embedPrint; /* if mode is NP_EMBED */ + } print; +} NPPrint; + +#ifdef XP_MACOSX +typedef NPNSMenu NPMenu; +#else +typedef void * NPMenu; +#endif + +#if defined(XP_MAC) || defined(XP_MACOSX) + +#ifndef NP_NO_CARBON +typedef EventRecord NPEvent; +#endif + +#elif defined(XP_WIN) +typedef struct _NPEvent +{ + uint16 event; + uint32 wParam; + uint32 lParam; +} NPEvent; +#elif defined (XP_UNIX) +typedef XEvent NPEvent; +#else +typedef void* NPEvent; +#endif /* XP_MAC */ + +#if defined(XP_MAC) +typedef RgnHandle NPRegion; +#elif defined(XP_MACOSX) +/* + * NPRegion's type depends on the drawing model specified by the plugin (see NPNVpluginDrawingModel). + * NPQDRegion represents a QuickDraw RgnHandle and is used with the QuickDraw drawing model. + * NPCGRegion repesents a graphical region when using any other drawing model. + */ +typedef void *NPRegion; +#ifndef NP_NO_QUICKDRAW +typedef RgnHandle NPQDRegion; +#endif +typedef CGPathRef NPCGRegion; +#elif defined(XP_WIN) +typedef HRGN NPRegion; +#elif defined(XP_UNIX) +typedef Region NPRegion; +#else +typedef void *NPRegion; +#endif /* XP_MAC */ + +#ifdef XP_MACOSX + +/* + * NP_CGContext is the type of the NPWindow's 'window' when the plugin specifies NPDrawingModelCoreGraphics + * as its drawing model. + */ + +typedef struct NP_CGContext +{ + CGContextRef context; +#ifdef NP_NO_CARBON + NPNSWindow *window; +#else + void *window; // Can be either an NSWindow or a WindowRef depending on the event model +#endif +} NP_CGContext; + +/* + * NP_GLContext is the type of the NPWindow's 'window' when the plugin specifies NPDrawingModelOpenGL as its + * drawing model. + */ + +typedef struct NP_GLContext +{ + CGLContextObj context; +#ifdef NP_NO_CARBON + NPNSWindow *window; +#else + void *window; // Can be either an NSWindow or a WindowRef depending on the event model +#endif +} NP_GLContext; + +#endif /* XP_MACOSX */ + +#if defined(XP_MAC) || defined(XP_MACOSX) + +/* + * Mac-specific structures and definitions. + */ + +#ifndef NP_NO_QUICKDRAW + +/* + * NP_Port is the type of the NPWindow's 'window' when the plugin specifies NPDrawingModelQuickDraw as its + * drawing model, or the plugin does not specify a drawing model. + * + * It is not recommended that new plugins use NPDrawingModelQuickDraw or NP_Port, as QuickDraw has been + * deprecated in Mac OS X 10.5. CoreGraphics is the preferred drawing API. + * + * NP_Port is not available in 64-bit. + */ + +typedef struct NP_Port +{ + CGrafPtr port; /* Grafport */ + int32 portx; /* position inside the topmost window */ + int32 porty; +} NP_Port; + +#endif /* NP_NO_QUICKDRAW */ + +/* + * Non-standard event types that can be passed to HandleEvent + */ +#define getFocusEvent (osEvt + 16) +#define loseFocusEvent (osEvt + 17) +#define adjustCursorEvent (osEvt + 18) + +#endif /* XP_MAC */ + + +/* + * Values for mode passed to NPP_New: + */ +#define NP_EMBED 1 +#define NP_FULL 2 + +/* + * Values for stream type passed to NPP_NewStream: + */ +#define NP_NORMAL 1 +#define NP_SEEK 2 +#define NP_ASFILE 3 +#define NP_ASFILEONLY 4 + +#define NP_MAXREADY (((unsigned)(~0)<<1)>>1) + +#if !defined(__LP64__) +#if defined(XP_MAC) || defined(XP_MACOSX) +#pragma options align=reset +#endif +#endif /* __LP64__ */ + + +/*----------------------------------------------------------------------*/ +/* Error and Reason Code definitions */ +/*----------------------------------------------------------------------*/ + +/* + * Values of type NPError: + */ +#define NPERR_BASE 0 +#define NPERR_NO_ERROR (NPERR_BASE + 0) +#define NPERR_GENERIC_ERROR (NPERR_BASE + 1) +#define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2) +#define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3) +#define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4) +#define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5) +#define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6) +#define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7) +#define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8) +#define NPERR_INVALID_PARAM (NPERR_BASE + 9) +#define NPERR_INVALID_URL (NPERR_BASE + 10) +#define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11) +#define NPERR_NO_DATA (NPERR_BASE + 12) +#define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13) + +/* + * Values of type NPReason: + */ +#define NPRES_BASE 0 +#define NPRES_DONE (NPRES_BASE + 0) +#define NPRES_NETWORK_ERR (NPRES_BASE + 1) +#define NPRES_USER_BREAK (NPRES_BASE + 2) + +/* + * Don't use these obsolete error codes any more. + */ +#define NP_NOERR NP_NOERR_is_obsolete_use_NPERR_NO_ERROR +#define NP_EINVAL NP_EINVAL_is_obsolete_use_NPERR_GENERIC_ERROR +#define NP_EABORT NP_EABORT_is_obsolete_use_NPRES_USER_BREAK + +/* + * Version feature information + */ +#define NPVERS_HAS_STREAMOUTPUT 8 +#define NPVERS_HAS_NOTIFICATION 9 +#define NPVERS_HAS_LIVECONNECT 9 +#define NPVERS_WIN16_HAS_LIVECONNECT 9 +#define NPVERS_68K_HAS_LIVECONNECT 11 +#define NPVERS_HAS_WINDOWLESS 11 +#define NPVERS_HAS_XPCONNECT_SCRIPTING 13 /* Not implemented in WebKit */ +#define NPVERS_HAS_NPRUNTIME_SCRIPTING 14 +#define NPVERS_HAS_FORM_VALUES 15 /* Not implemented in WebKit; see bug 13061 */ +#define NPVERS_HAS_POPUPS_ENABLED_STATE 16 /* Not implemented in WebKit */ +#define NPVERS_HAS_RESPONSE_HEADERS 17 +#define NPVERS_HAS_NPOBJECT_ENUM 18 +#define NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL 19 +#define NPVERS_HAS_ALL_NETWORK_STREAMS 20 +#define NPVERS_HAS_URL_AND_AUTH_INFO 21 +#define NPVERS_HAS_PRIVATE_MODE 22 +#define NPVERS_MACOSX_HAS_EVENT_MODELS 23 +#define NPVERS_HAS_CANCEL_SRC_STREAM 24 + +/*----------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------*/ + +#if defined(_WINDOWS) && !defined(WIN32) +#define NP_LOADDS _loadds +#else +#define NP_LOADDS +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * NPP_* functions are provided by the plugin and called by the navigator. + */ + +#ifdef XP_UNIX +char* NPP_GetMIMEDescription(void); +#endif /* XP_UNIX */ + +NPError NPP_Initialize(void); +void NPP_Shutdown(void); +NPError NP_LOADDS NPP_New(NPMIMEType pluginType, NPP instance, + uint16 mode, int16 argc, char* argn[], + char* argv[], NPSavedData* saved); +NPError NP_LOADDS NPP_Destroy(NPP instance, NPSavedData** save); +NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow* window); +NPError NP_LOADDS NPP_NewStream(NPP instance, NPMIMEType type, + NPStream* stream, NPBool seekable, + uint16* stype); +NPError NP_LOADDS NPP_DestroyStream(NPP instance, NPStream* stream, + NPReason reason); +int32 NP_LOADDS NPP_WriteReady(NPP instance, NPStream* stream); +int32 NP_LOADDS NPP_Write(NPP instance, NPStream* stream, int32 offset, + int32 len, void* buffer); +void NP_LOADDS NPP_StreamAsFile(NPP instance, NPStream* stream, + const char* fname); +void NP_LOADDS NPP_Print(NPP instance, NPPrint* platformPrint); +int16 NPP_HandleEvent(NPP instance, void* event); +void NP_LOADDS NPP_URLNotify(NPP instance, const char* url, + NPReason reason, void* notifyData); +jref NP_LOADDS NPP_GetJavaClass(void); +NPError NPP_GetValue(NPP instance, NPPVariable variable, + void *value); +NPError NPP_SetValue(NPP instance, NPNVariable variable, + void *value); + +/* + * NPN_* functions are provided by the navigator and called by the plugin. + */ + +void NPN_Version(int* plugin_major, int* plugin_minor, + int* netscape_major, int* netscape_minor); +NPError NPN_GetURLNotify(NPP instance, const char* url, + const char* target, void* notifyData); +NPError NPN_GetURL(NPP instance, const char* url, + const char* target); +NPError NPN_PostURLNotify(NPP instance, const char* url, + const char* target, uint32 len, + const char* buf, NPBool file, + void* notifyData); +NPError NPN_PostURL(NPP instance, const char* url, + const char* target, uint32 len, + const char* buf, NPBool file); +NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList); +NPError NPN_NewStream(NPP instance, NPMIMEType type, + const char* target, NPStream** stream); +int32 NPN_Write(NPP instance, NPStream* stream, int32 len, + void* buffer); +NPError NPN_DestroyStream(NPP instance, NPStream* stream, + NPReason reason); +void NPN_Status(NPP instance, const char* message); +const char* NPN_UserAgent(NPP instance); +void* NPN_MemAlloc(uint32 size); +void NPN_MemFree(void* ptr); +uint32 NPN_MemFlush(uint32 size); +void NPN_ReloadPlugins(NPBool reloadPages); +JRIEnv* NPN_GetJavaEnv(void); +jref NPN_GetJavaPeer(NPP instance); +NPError NPN_GetValue(NPP instance, NPNVariable variable, + void *value); +NPError NPN_SetValue(NPP instance, NPPVariable variable, + void *value); +void NPN_InvalidateRect(NPP instance, NPRect *invalidRect); +void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion); +void NPN_ForceRedraw(NPP instance); +void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled); +void NPN_PopPopupsEnabledState(NPP instance); +void NPN_PluginThreadAsyncCall(NPP instance, void (*func) (void *), void *userData); +uint32 NPN_ScheduleTimer(NPP instance, uint32 interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32 timerID)); +void NPN_UnscheduleTimer(NPP instance, uint32 timerID); +NPError NPN_PopUpContextMenu(NPP instance, NPMenu* menu); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* _NPAPI_H_ */ diff --git a/V8Binding/npapi/npruntime.h b/V8Binding/npapi/npruntime.h new file mode 100644 index 0000000..8a285be --- /dev/null +++ b/V8Binding/npapi/npruntime.h @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2004, Apple Computer, Inc. and The Mozilla Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla + * Foundation ("Mozilla") nor the names of their contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR 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 APPLE, MOZILLA OR + * THEIR 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. + * + * Revision 1 (March 4, 2004): + * Initial proposal. + * + * Revision 2 (March 10, 2004): + * All calls into script were made asynchronous. Results are + * provided via the NPScriptResultFunctionPtr callback. + * + * Revision 3 (March 10, 2004): + * Corrected comments to not refer to class retain/release FunctionPtrs. + * + * Revision 4 (March 11, 2004): + * Added additional convenience NPN_SetExceptionWithUTF8(). + * Changed NPHasPropertyFunctionPtr and NPHasMethodFunctionPtr to take NPClass + * pointers instead of NPObject pointers. + * Added NPIsValidIdentifier(). + * + * Revision 5 (March 17, 2004): + * Added context parameter to result callbacks from ScriptObject functions. + * + * Revision 6 (March 29, 2004): + * Renamed functions implemented by user agent to NPN_*. Removed _ from + * type names. + * Renamed "JavaScript" types to "Script". + * + * Revision 7 (April 21, 2004): + * NPIdentifier becomes a void*, was int32_t + * Remove NP_IsValidIdentifier, renamed NP_IdentifierFromUTF8 to NP_GetIdentifier + * Added NPVariant and modified functions to use this new type. + * + * Revision 8 (July 9, 2004): + * Updated to joint Apple-Mozilla license. + * + * Revision 9 (August 12, 2004): + * Changed NPVariantType enum values to form PVariantType_XXX + * Added NPP arguments to NPObject functions. + * Replaced NPVariant functions with macros. + */ +#ifndef _NP_RUNTIME_H_ +#define _NP_RUNTIME_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> +#include "npapi.h" + +/* + This API is used to facilitate binding code written in C to script + objects. The API in this header does not assume the presence of a + user agent. That is, it can be used to bind C code to scripting + environments outside of the context of a user agent. + + However, the normal use of the this API is in the context of a + scripting environment running in a browser or other user agent. + In particular it is used to support the extended Netscape + script-ability API for plugins (NP-SAP). NP-SAP is an extension + of the Netscape plugin API. As such we have adopted the use of + the "NP" prefix for this API. + + The following NP{N|P}Variables were added to the Netscape plugin + API (in npapi.h): + + NPNVWindowNPObject + NPNVPluginElementNPObject + NPPVpluginScriptableNPObject + + These variables are exposed through NPN_GetValue() and + NPP_GetValue() (respectively) and are used to establish the + initial binding between the user agent and native code. The DOM + objects in the user agent can be examined and manipulated using + the NPN_ functions that operate on NPObjects described in this + header. + + To the extent possible the assumptions about the scripting + language used by the scripting environment have been minimized. +*/ + + +/* + Objects (non-primitive data) passed between 'C' and script is + always wrapped in an NPObject. The 'interface' of an NPObject is + described by an NPClass. +*/ +typedef struct NPObject NPObject; +typedef struct NPClass NPClass; + +typedef char NPUTF8; +typedef struct _NPString { + const NPUTF8 *UTF8Characters; + uint32_t UTF8Length; +} NPString; + +typedef enum { + NPVariantType_Void, + NPVariantType_Null, + NPVariantType_Bool, + NPVariantType_Int32, + NPVariantType_Double, + NPVariantType_String, + NPVariantType_Object +} NPVariantType; + +typedef struct _NPVariant { + NPVariantType type; + union { + bool boolValue; + int32_t intValue; + double doubleValue; + NPString stringValue; + NPObject *objectValue; + } value; +} NPVariant; + +/* + NPN_ReleaseVariantValue is called on all 'out' parameters references. + Specifically it is called on variants that are resultant out parameters + in NPGetPropertyFunctionPtr and NPInvokeFunctionPtr. Resultant variants + from these two functions should be initialized using the + NPN_InitializeVariantXXX() functions. + + After calling NPReleaseVariantValue, the type of the variant will + be set to NPVariantUndefinedType. +*/ +void NPN_ReleaseVariantValue (NPVariant *variant); + +#define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void) +#define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null) +#define NPVARIANT_IS_BOOLEAN(_v) ((_v).type == NPVariantType_Bool) +#define NPVARIANT_IS_INT32(_v) ((_v).type == NPVariantType_Int32) +#define NPVARIANT_IS_DOUBLE(_v) ((_v).type == NPVariantType_Double) +#define NPVARIANT_IS_STRING(_v) ((_v).type == NPVariantType_String) +#define NPVARIANT_IS_OBJECT(_v) ((_v).type == NPVariantType_Object) + +#define NPVARIANT_TO_BOOLEAN(_v) ((_v).value.boolValue) +#define NPVARIANT_TO_INT32(_v) ((_v).value.intValue) +#define NPVARIANT_TO_DOUBLE(_v) ((_v).value.doubleValue) +#define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue) +#define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue) + +#define NP_BEGIN_MACRO do { +#define NP_END_MACRO } while (0) + +#define VOID_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Void; (_v).value.objectValue = NULL; NP_END_MACRO +#define NULL_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Null; (_v).value.objectValue = NULL; NP_END_MACRO +#define BOOLEAN_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Bool; (_v).value.boolValue = !!(_val); NP_END_MACRO +#define INT32_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Int32; (_v).value.intValue = _val; NP_END_MACRO +#define DOUBLE_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Double; (_v).value.doubleValue = _val; NP_END_MACRO +#define STRINGZ_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str = { _val, strlen(_val) }; (_v).value.stringValue = str; NP_END_MACRO +#define STRINGN_TO_NPVARIANT(_val, _len, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str = { _val, _len }; (_v).value.stringValue = str; NP_END_MACRO +#define OBJECT_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Object; (_v).value.objectValue = _val; NP_END_MACRO + +/* + Type mappings (JavaScript types have been used for illustration + purposes): + + JavaScript to C (NPVariant with type:) + undefined NPVariantType_Void + null NPVariantType_Null + Boolean NPVariantType_Bool + Number NPVariantType_Double or NPVariantType_Int32 + String NPVariantType_String + Object NPVariantType_Object + + C (NPVariant with type:) to JavaScript + NPVariantType_Void undefined + NPVariantType_Null null + NPVariantType_Bool Boolean + NPVariantType_Int32 Number + NPVariantType_Double Number + NPVariantType_String String + NPVariantType_Object Object +*/ + +typedef void *NPIdentifier; + +/* + NPObjects have methods and properties. Methods and properties are + identified with NPIdentifiers. These identifiers may be reflected + in script. NPIdentifiers can be either strings or integers, IOW, + methods and properties can be identified by either strings or + integers (i.e. foo["bar"] vs foo[1]). NPIdentifiers can be + compared using ==. In case of any errors, the requested + NPIdentifier(s) will be NULL. +*/ +NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name); +void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers); +NPIdentifier NPN_GetIntIdentifier(int32_t intid); +bool NPN_IdentifierIsString(NPIdentifier identifier); + +/* + The NPUTF8 returned from NPN_UTF8FromIdentifier SHOULD be freed. +*/ +NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier); + +/* + Get the integer represented by identifier. If identifier is not an + integer identifier, the behaviour is undefined. +*/ +int32_t NPN_IntFromIdentifier(NPIdentifier identifier); + +/* + NPObject behavior is implemented using the following set of + callback functions. + + The NPVariant *result argument of these functions (where + applicable) should be released using NPN_ReleaseVariantValue(). +*/ +typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass); +typedef void (*NPDeallocateFunctionPtr)(NPObject *obj); +typedef void (*NPInvalidateFunctionPtr)(NPObject *obj); +typedef bool (*NPHasMethodFunctionPtr)(NPObject *obj, NPIdentifier name); +typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); +typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result); +typedef bool (*NPHasPropertyFunctionPtr)(NPObject *obj, NPIdentifier name); +typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result); +typedef bool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value); +typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, NPIdentifier name); +typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value, uint32_t *count); +typedef bool (*NPConstructFunctionPtr)(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result); + +/* + NPObjects returned by create have a reference count of one. It is the caller's responsibility + to release the returned object. + + NPInvokeFunctionPtr function may return false to indicate a the method could not be invoked. + + NPGetPropertyFunctionPtr and NPSetPropertyFunctionPtr may return false to indicate a property doesn't + exist. + + NPInvalidateFunctionPtr is called by the scripting environment when the native code is + shutdown. Any attempt to message a NPObject instance after the invalidate + callback has been called will result in undefined behavior, even if the + native code is still retaining those NPObject instances. + (The runtime will typically return immediately, with 0 or NULL, from an attempt to + dispatch to a NPObject, but this behavior should not be depended upon.) + + The NPEnumerationFunctionPtr function may pass an array of + NPIdentifiers back to the caller. The callee allocs the memory of + the array using NPN_MemAlloc(), and it's the caller's responsibility + to release it using NPN_MemFree(). +*/ +struct NPClass +{ + uint32_t structVersion; + NPAllocateFunctionPtr allocate; + NPDeallocateFunctionPtr deallocate; + NPInvalidateFunctionPtr invalidate; + NPHasMethodFunctionPtr hasMethod; + NPInvokeFunctionPtr invoke; + NPInvokeDefaultFunctionPtr invokeDefault; + NPHasPropertyFunctionPtr hasProperty; + NPGetPropertyFunctionPtr getProperty; + NPSetPropertyFunctionPtr setProperty; + NPRemovePropertyFunctionPtr removeProperty; + NPEnumerationFunctionPtr enumerate; + NPConstructFunctionPtr construct; +}; + +#define NP_CLASS_STRUCT_VERSION 3 +#define NP_CLASS_STRUCT_VERSION_ENUM 2 +#define NP_CLASS_STRUCT_VERSION_CTOR 3 + +#define NP_CLASS_STRUCT_VERSION_HAS_ENUM(npclass) \ + ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM) +#define NP_CLASS_STRUCT_VERSION_HAS_CTOR(npclass) \ + ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_CTOR) + +struct NPObject { + NPClass *_class; + uint32_t referenceCount; + // Additional space may be allocated here by types of NPObjects +}; + +/* + If the class has an allocate function, NPN_CreateObject invokes that function, + otherwise a NPObject is allocated and returned. If a class has an allocate + function it is the responsibility of that implementation to set the initial retain + count to 1. +*/ +NPObject *NPN_CreateObject(NPP npp, NPClass *aClass); + +/* + Increment the NPObject's reference count. +*/ +NPObject *NPN_RetainObject (NPObject *obj); + +/* + Decremented the NPObject's reference count. If the reference + count goes to zero, the class's destroy function is invoke if + specified, otherwise the object is freed directly. +*/ +void NPN_ReleaseObject (NPObject *obj); + +/* + Functions to access script objects represented by NPObject. + + Calls to script objects are synchronous. If a function returns a + value, it will be supplied via the result NPVariant + argument. Successful calls will return true, false will be + returned in case of an error. + + Calls made from plugin code to script must be made from the thread + on which the plugin was initialized. +*/ +bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result); +bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result); +bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, NPVariant *result); +bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result); +bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value); +bool NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName); +bool NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName); +bool NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName); +bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count); +bool NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result); + +/* + NPN_SetException may be called to trigger a script exception upon return + from entry points into NPObjects. +*/ +void NPN_SetException (NPObject *obj, const NPUTF8 *message); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/V8Binding/scripts/CodeGeneratorV8.pm b/V8Binding/scripts/CodeGeneratorV8.pm index 5bb69cb..95935b6 100644 --- a/V8Binding/scripts/CodeGeneratorV8.pm +++ b/V8Binding/scripts/CodeGeneratorV8.pm @@ -1708,12 +1708,14 @@ my %typeCanFailConversion = ( "Event" => 0, "EventListener" => 0, "EventTarget" => 0, + "Geoposition" => 0, "HTMLElement" => 0, "HTMLOptionElement" => 0, "Node" => 0, "NodeFilter" => 0, "MessagePort" => 0, "NSResolver" => 0, + "PositionError" => 0, "Range" => 0, "SQLResultSet" => 0, "SVGAngle" => 0, @@ -1726,6 +1728,7 @@ my %typeCanFailConversion = ( "SVGPoint" => 0, "SVGRect" => 0, "SVGTransform" => 0, + "TouchList" => 0, "VoidCallback" => 1, "WebKitCSSMatrix" => 0, "WebKitPoint" => 0, diff --git a/V8Binding/v8/DOMObjectsInclude.h b/V8Binding/v8/DOMObjectsInclude.h index 5e067b4..b7b941e 100644 --- a/V8Binding/v8/DOMObjectsInclude.h +++ b/V8Binding/v8/DOMObjectsInclude.h @@ -94,8 +94,6 @@ #include "SQLResultSetRowList.h" #include "StyleSheet.h" #include "StyleSheetList.h" -#include "SVGColor.h" -#include "SVGPaint.h" #include "TextEvent.h" #include "TextMetrics.h" #include "TimeRanges.h" @@ -121,6 +119,7 @@ #include "XMLHttpRequestProgressEvent.h" #include "XMLHttpRequestUpload.h" #include "XMLSerializer.h" +#include "XPathEvaluator.h" #include "XPathException.h" #include "XPathExpression.h" #include "XPathNSResolver.h" @@ -129,6 +128,7 @@ #if ENABLE(SVG) #include "SVGAngle.h" #include "SVGAnimatedPoints.h" +#include "SVGColor.h" #include "SVGElement.h" #include "SVGElementInstance.h" #include "SVGElementInstanceList.h" @@ -136,6 +136,7 @@ #include "SVGLength.h" #include "SVGLengthList.h" #include "SVGNumberList.h" +#include "SVGPaint.h" #include "SVGPathSeg.h" #include "SVGPathSegArc.h" #include "SVGPathSegClosePath.h" @@ -167,9 +168,17 @@ #include "WorkerNavigator.h" #endif // WORKERS -#if ENABLE(XPATH) -#include "XPathEvaluator.h" -#endif // XPATH +#if PLATFORM(ANDROID) +#include "Coordinates.h" +#include "Geolocation.h" +#include "Geoposition.h" +#include "PositionError.h" +#include "PositionErrorCallback.h" +#include "Touch.h" +#include "TouchList.h" +#include "TouchEvent.h" +#include "VoidCallback.h" +#endif namespace WebCore { diff --git a/V8Binding/v8/NPV8Object.cpp b/V8Binding/v8/NPV8Object.cpp index 411439f..defe6bf 100644 --- a/V8Binding/v8/NPV8Object.cpp +++ b/V8Binding/v8/NPV8Object.cpp @@ -32,9 +32,10 @@ #define min min #include <v8.h> #include "NPV8Object.h" +#if PLATFORM(CHROMIUM) #include "ChromiumBridge.h" +#endif #include "Frame.h" -#include "bindings/npruntime.h" #include "npruntime_priv.h" #include "PlatformString.h" #include "ScriptController.h" @@ -241,12 +242,9 @@ bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, return true; } -bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *npscript, NPVariant *result) -{ - bool popupsAllowed = WebCore::ChromiumBridge::popupsAllowed(npp); - return NPN_EvaluateHelper(npp, popupsAllowed, npobj, npscript, result); -} - +#if PLATFORM(ANDROID) +static +#endif bool NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npobj, NPString* npscript, NPVariant *result) { VOID_TO_NPVARIANT(*result); @@ -282,6 +280,17 @@ bool NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npobj, NPString* return true; } +bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *npscript, NPVariant *result) +{ +#if PLATFORM(CHROMIUM) + bool popupsAllowed = WebCore::ChromiumBridge::popupsAllowed(npp); +#else + // TODO(fqian): create an Android bridge + bool popupsAllowed = false; +#endif + return NPN_EvaluateHelper(npp, popupsAllowed, npobj, npscript, result); +} + bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result) { if (!npobj) @@ -456,7 +465,7 @@ bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t v8::Handle<v8::Value> enumeratorObj = script->Run(); v8::Handle<v8::Function> enumerator = v8::Handle<v8::Function>::Cast(enumeratorObj); v8::Handle<v8::Value> argv[] = { obj }; - v8::Local<v8::Value> propsObj = enumerator->Call(v8::Handle<v8::Object>::Cast(enumeratorObj), ARRAYSIZE_UNSAFE(argv), argv); + v8::Local<v8::Value> propsObj = enumerator->Call(v8::Handle<v8::Object>::Cast(enumeratorObj), 1, argv); if (propsObj.IsEmpty()) return false; diff --git a/V8Binding/v8/NPV8Object.h b/V8Binding/v8/NPV8Object.h index bfe7bb7..1b9713e 100644 --- a/V8Binding/v8/NPV8Object.h +++ b/V8Binding/v8/NPV8Object.h @@ -5,7 +5,12 @@ #ifndef np_v8object_h #define np_v8object_h +#if PLATFORM(CHROMIUM) #include "bindings/npruntime.h" +#else +#include "bridge/npruntime.h" // use WebCore version +#endif + #include <v8.h> namespace WebCore { diff --git a/V8Binding/v8/ScriptController.cpp b/V8Binding/v8/ScriptController.cpp index 84ad8b4..83dc52c 100644 --- a/V8Binding/v8/ScriptController.cpp +++ b/V8Binding/v8/ScriptController.cpp @@ -30,7 +30,10 @@ #include "config.h" #include "ScriptController.h" +#if PLATFORM(CHROMIUM) #include "ChromiumBridge.h" +#endif + #include "CString.h" #include "Document.h" #include "DOMWindow.h" @@ -312,10 +315,13 @@ PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widge if (widget->isFrameView()) return 0; +#if PLATFORM(CHROMIUM) NPObject* npObject = ChromiumBridge::pluginScriptableObject(widget); +#else + NPObject* npObject = 0; // TODO(fqian): fix this +#endif if (!npObject) return 0; - // Frame Memory Management for NPObjects // ------------------------------------- // NPObjects are treated differently than other objects wrapped by JS. diff --git a/V8Binding/v8/ScriptController.h b/V8Binding/v8/ScriptController.h index e1e9e25..d26dbcc 100644 --- a/V8Binding/v8/ScriptController.h +++ b/V8Binding/v8/ScriptController.h @@ -39,7 +39,11 @@ #include "ScriptValue.h" #include "SecurityOrigin.h" +#if PLATFORM(CHROMIUM) #include "bindings/npruntime.h" +#else +#include "bridge/npruntime.h" // use WebCore version +#endif #include <wtf/HashMap.h> #include <wtf/Vector.h> diff --git a/V8Binding/v8/V8NPObject.h b/V8Binding/v8/V8NPObject.h index c236c60..04cbff1 100644 --- a/V8Binding/v8/V8NPObject.h +++ b/V8Binding/v8/V8NPObject.h @@ -6,7 +6,11 @@ #define v8_npobject_h #include <v8.h> +#if PLATFORM(CHROMIUM) #include "third_party/npapi/bindings/npruntime.h" +#else +#include "bridge/npruntime.h" // use WebCore version +#endif // These functions can be replaced by normal JS operation. // Getters diff --git a/V8Binding/v8/V8NPUtils.h b/V8Binding/v8/V8NPUtils.h index 08409f2..2e07e66 100644 --- a/V8Binding/v8/V8NPUtils.h +++ b/V8Binding/v8/V8NPUtils.h @@ -6,7 +6,11 @@ #define v8_np_utils_h #include <v8.h> +#if PLATFORM(CHROMIUM) #include "third_party/npapi/bindings/npruntime.h" +#else +#include "bridge/npruntime.h" // use WebCore version +#endif namespace WebCore { class Frame; diff --git a/V8Binding/v8/npruntime.cpp b/V8Binding/v8/npruntime.cpp index 1ecb68c..d1138ab 100644 --- a/V8Binding/v8/npruntime.cpp +++ b/V8Binding/v8/npruntime.cpp @@ -26,17 +26,17 @@ #include "config.h" -#include <map> -#include <set> -#include <string> #include <v8.h> -#include "bindings/npruntime.h" #include "NPV8Object.h" #include "npruntime_priv.h" #include "V8NPObject.h" #include <wtf/Assertions.h> +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> + +#include <utility> using namespace v8; @@ -49,29 +49,78 @@ using namespace v8; // Need a platform abstraction which we can use. // static Lock StringIdentifierMapLock; -namespace { // We use StringKey here as the key-type to avoid a string copy to // construct the map key and for faster comparisons than strcmp. struct StringKey { + StringKey() : string(NULL), length(0) {} StringKey(const char* str) : string(str), length(strlen(str)) {} const char* string; - const size_t length; + size_t length; + + StringKey& operator=(const StringKey& other) { + this->string = other.string; + this->length = other.length; + return *this; + } + }; -inline bool operator<(const StringKey& x, const StringKey& y) { +inline bool operator==(const StringKey& x, const StringKey& y) { // Shorter strings are less than longer strings, memcmp breaks ties. - if (x.length < y.length) - return true; - else if (x.length > y.length) + if (x.length != y.length) { return false; - else - return memcmp(x.string, y.string, y.length) < 0; + } else { + ASSERT(x.string != NULL && y.string != NULL); + return memcmp(x.string, y.string, y.length) == 0; + } } -} // namespace +struct StringKeyHash { + static unsigned hash(StringKey key) { + // sdbm hash function + unsigned hash = 0; + for (size_t i = 0; i < key.length; i++) { + char c = key.string[i]; + + hash += c; + hash += (hash << 10); + hash ^= (hash>> 6); + } + + // + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + if (hash == 0) { + hash = 27; + } + return hash; + } + + static bool equal(StringKey x, StringKey y) { + return x == y; + } + + static const bool safeToCompareToEmptyOrDeleted = false; +}; + +namespace WTF { + template<> struct HashTraits<StringKey> : GenericHashTraits<StringKey> { + static const bool emptyValueIsZero = true; + static const bool needsDestruction = false; + static void constructDeletedValue(StringKey& slot) { + slot.string = NULL; + slot.length = 0; + } -typedef std::map<const StringKey, PrivateIdentifier*> StringIdentifierMap; + static bool isDeletedValue(const StringKey& slot) { + return slot.string == NULL; + } + }; +} + +typedef WTF::HashMap<StringKey, PrivateIdentifier*, StringKeyHash> StringIdentifierMap; static StringIdentifierMap* getStringIdentifierMap() { static StringIdentifierMap* stringIdentifierMap = 0; @@ -83,7 +132,7 @@ static StringIdentifierMap* getStringIdentifierMap() { // FIXME: Consider removing locks if we're singlethreaded already. // static Lock IntIdentifierMapLock; -typedef std::map<int, PrivateIdentifier*> IntIdentifierMap; +typedef WTF::HashMap<int, PrivateIdentifier*> IntIdentifierMap; static IntIdentifierMap* getIntIdentifierMap() { static IntIdentifierMap* intIdentifierMap = 0; @@ -99,7 +148,6 @@ NPIdentifier NPN_GetStringIdentifier(const NPUTF8* name) { if (name) { // AutoLock safeLock(StringIdentifierMapLock); - StringKey key(name); StringIdentifierMap* identMap = getStringIdentifierMap(); StringIdentifierMap::iterator iter = identMap->find(key); @@ -116,7 +164,7 @@ NPIdentifier NPN_GetStringIdentifier(const NPUTF8* name) { identifier->isString = true; identifier->value.string = reinterpret_cast<NPUTF8*>(nameStorage); key.string = nameStorage; - (*identMap)[key] = identifier; + identMap->set(key, identifier); return (NPIdentifier)identifier; } @@ -146,7 +194,7 @@ NPIdentifier NPN_GetIntIdentifier(int32_t intid) { malloc(sizeof(PrivateIdentifier))); identifier->isString = false; identifier->value.number = intid; - (*identMap)[intid] = identifier; + identMap->set(intid, identifier); return (NPIdentifier)identifier; } @@ -276,9 +324,9 @@ void _NPN_InitializeVariantWithStringCopy(NPVariant* variant, // Frame teardown to deactivate all objects associated // with a particular plugin. -typedef std::set<NPObject*> NPObjectSet; -typedef std::map<NPObject*, NPObject*> NPObjectMap; -typedef std::map<NPObject*, NPObjectSet*> NPRootObjectMap; +typedef WTF::HashSet<NPObject*> NPObjectSet; +typedef WTF::HashMap<NPObject*, NPObject*> NPObjectMap; +typedef WTF::HashMap<NPObject*, NPObjectSet*> NPRootObjectMap; // A map of live NPObjects with pointers to their Roots. NPObjectMap g_live_objects; @@ -298,7 +346,7 @@ void _NPN_RegisterObject(NPObject* obj, NPObject* owner) { if (!owner) { // Registering a new owner object. ASSERT(g_root_objects.find(obj) == g_root_objects.end()); - g_root_objects[obj] = new NPObjectSet(); + g_root_objects.set(obj, new NPObjectSet()); } else { // Always associate this object with it's top-most parent. // Since we always flatten, we only have to look up one level. @@ -312,11 +360,11 @@ void _NPN_RegisterObject(NPObject* obj, NPObject* owner) { } ASSERT(g_root_objects.find(obj) == g_root_objects.end()); if (g_root_objects.find(owner) != g_root_objects.end()) - (g_root_objects[owner])->insert(obj); + g_root_objects.get(owner)->add(obj); } ASSERT(g_live_objects.find(obj) == g_live_objects.end()); - g_live_objects[obj] = owner; + g_live_objects.set(obj, owner); } void _NPN_UnregisterObject(NPObject* obj) { @@ -330,7 +378,7 @@ void _NPN_UnregisterObject(NPObject* obj) { if (owner == NULL) { // Unregistering a owner object; also unregister it's descendants. ASSERT(g_root_objects.find(obj) != g_root_objects.end()); - NPObjectSet* set = g_root_objects[obj]; + NPObjectSet* set = g_root_objects.get(obj); while (set->size() > 0) { #ifndef NDEBUG size_t size = set->size(); @@ -340,8 +388,8 @@ void _NPN_UnregisterObject(NPObject* obj) { ASSERT(g_root_objects.find(sub_object) == g_root_objects.end()); // First, unregister the object. - set->erase(sub_object); - g_live_objects.erase(sub_object); + set->remove(sub_object); + g_live_objects.remove(sub_object); // Remove the JS references to the object. ForgetV8ObjectForNPObject(sub_object); @@ -349,18 +397,18 @@ void _NPN_UnregisterObject(NPObject* obj) { ASSERT(set->size() < size); } delete set; - g_root_objects.erase(obj); + g_root_objects.remove(obj); } else { NPRootObjectMap::iterator owner_entry = g_root_objects.find(owner); if (owner_entry != g_root_objects.end()) { NPObjectSet* list = owner_entry->second; ASSERT(list->find(obj) != list->end()); - list->erase(obj); + list->remove(obj); } } ForgetV8ObjectForNPObject(obj); - g_live_objects.erase(obj); + g_live_objects.remove(obj); } bool _NPN_IsAlive(NPObject* obj) { diff --git a/V8Binding/v8/npruntime_impl.h b/V8Binding/v8/npruntime_impl.h index 9a9b612..31db922 100644 --- a/V8Binding/v8/npruntime_impl.h +++ b/V8Binding/v8/npruntime_impl.h @@ -31,13 +31,39 @@ #ifndef npruntime_impl_h #define npruntime_impl_h +#if PLATFORM(CHROMIUM) #include "bindings/npruntime.h" +#else +#include "npruntime.h" // use V8Binding/npapi version +#endif // This file exists to support WebCore, which expects to be able to call upon // portions of the NPRuntime implementation. // A simple mapping for now. FIXME We should probably just adopt the // underscore prefix as our naming convention too. + +#define _NPN_ReleaseVariantValue NPN_ReleaseVariantValue +#define _NPN_GetStringIdentifier NPN_GetStringIdentifier +#define _NPN_GetStringIdentifiers NPN_GetStringIdentifiers +#define _NPN_GetIntIdentifier NPN_GetIntIdentifier +#define _NPN_IdentifierIsString NPN_IdentifierIsString +#define _NPN_UTF8FromIdentifier NPN_UTF8FromIdentifier +#define _NPN_IntFromIdentifier NPN_IntFromIdentifier +#define _NPN_CreateObject NPN_CreateObject +#define _NPN_RetainObject NPN_RetainObject #define _NPN_ReleaseObject NPN_ReleaseObject +#define _NPN_DeallocateObject NPN_DeallocateObject +#define _NPN_Invoke NPN_Invoke +#define _NPN_InvokeDefault NPN_InvokeDefault +#define _NPN_Evaluate NPN_Evaluate +#define _NPN_GetProperty NPN_GetProperty +#define _NPN_SetProperty NPN_SetProperty +#define _NPN_RemoveProperty NPN_RemoveProperty +#define _NPN_HasProperty NPN_HasProperty +#define _NPN_HasMethod NPN_HasMethod +#define _NPN_SetException NPN_SetException +#define _NPN_Enumerate NPN_Enumerate +#define _NPN_Construct NPN_Construct #endif diff --git a/V8Binding/v8/npruntime_priv.h b/V8Binding/v8/npruntime_priv.h index 0aa952c..8b1ddec 100644 --- a/V8Binding/v8/npruntime_priv.h +++ b/V8Binding/v8/npruntime_priv.h @@ -26,8 +26,11 @@ #ifndef NP_RUNTIME_PRIV_H_ #define NP_RUNTIME_PRIV_H_ - +#if PLATFORM(CHROMIUM) #include "third_party/npapi/bindings/npruntime.h" +#else +#include "bridge/npruntime.h" +#endif #ifdef __cplusplus extern "C" { diff --git a/V8Binding/v8/v8_custom.cpp b/V8Binding/v8/v8_custom.cpp index 4b2e545..855e192 100644 --- a/V8Binding/v8/v8_custom.cpp +++ b/V8Binding/v8/v8_custom.cpp @@ -42,8 +42,11 @@ #include "V8HTMLImageElement.h" #include "V8HTMLOptionElement.h" #include "V8Node.h" + +#if ENABLE(XPATH) #include "V8XPathNSResolver.h" #include "V8XPathResult.h" +#endif #include "Base64.h" #include "CanvasGradient.h" @@ -692,149 +695,8 @@ static bool AllowSettingFrameSrcToJavascriptUrl(HTMLFrameElementBase* frame, } -// Element --------------------------------------------------------------------- - -CALLBACK_FUNC_DECL(ElementSetAttribute) { - INC_STATS("DOM.Element.setAttribute()"); - Element* imp = V8Proxy::DOMWrapperToNode<Element>(args.Holder()); - ExceptionCode ec = 0; - String name = ToWebCoreString(args[0]); - String value = ToWebCoreString(args[1]); - - if (!AllowSettingSrcToJavascriptURL(imp, name, value)) { - return v8::Undefined(); - } - - imp->setAttribute(name, value, ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(ElementSetAttributeNode) { - INC_STATS("DOM.Element.setAttributeNode()"); - if (!V8Attr::HasInstance(args[0])) { - V8Proxy::SetDOMException(TYPE_MISMATCH_ERR); - return v8::Handle<v8::Value>(); - } - - Attr* newAttr = V8Proxy::DOMWrapperToNode<Attr>(args[0]); - Element* imp = V8Proxy::DOMWrapperToNode<Element>(args.Holder()); - ExceptionCode ec = 0; - - if (!AllowSettingSrcToJavascriptURL(imp, newAttr->name(), newAttr->value())) { - return v8::Undefined(); - } - - RefPtr<Attr> result = imp->setAttributeNode(newAttr, ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - return V8Proxy::NodeToV8Object(result.get()); -} - -CALLBACK_FUNC_DECL(ElementSetAttributeNS) { - INC_STATS("DOM.Element.setAttributeNS()"); - Element* imp = V8Proxy::DOMWrapperToNode<Element>(args.Holder()); - ExceptionCode ec = 0; - String namespaceURI = valueToStringWithNullCheck(args[0]); - String qualifiedName = ToWebCoreString(args[1]); - String value = ToWebCoreString(args[2]); - - if (!AllowSettingSrcToJavascriptURL(imp, qualifiedName, value)) { - return v8::Undefined(); - } - - imp->setAttributeNS(namespaceURI, qualifiedName, value, ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(ElementSetAttributeNodeNS) { - INC_STATS("DOM.Element.setAttributeNodeNS()"); - if (!V8Attr::HasInstance(args[0])) { - V8Proxy::SetDOMException(TYPE_MISMATCH_ERR); - return v8::Handle<v8::Value>(); - } - - Attr* newAttr = V8Proxy::DOMWrapperToNode<Attr>(args[0]); - Element* imp = V8Proxy::DOMWrapperToNode<Element>(args.Holder()); - ExceptionCode ec = 0; - - if (!AllowSettingSrcToJavascriptURL(imp, newAttr->name(), newAttr->value())) { - return v8::Undefined(); - } - - RefPtr<Attr> result = imp->setAttributeNodeNS(newAttr, ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - return V8Proxy::NodeToV8Object(result.get()); -} - - - -// Attr ------------------------------------------------------------------------ - -ACCESSOR_SETTER(AttrValue) { - Attr* imp = - V8Proxy::DOMWrapperToNode<Attr>(info.Holder()); - String v = valueToStringWithNullCheck(value); - Element* ownerElement = imp->ownerElement(); - - if (ownerElement && - !AllowSettingSrcToJavascriptURL(ownerElement, imp->name(), v)) - return; - - ExceptionCode ec = 0; - imp->setValue(v, ec); - V8Proxy::SetDOMException(ec); -} - - -// HTMLFrameElement ------------------------------------------------------------ - -ACCESSOR_SETTER(HTMLFrameElementSrc) { - HTMLFrameElement* imp = - V8Proxy::DOMWrapperToNode<HTMLFrameElement>(info.Holder()); - String v = valueToStringWithNullCheck(value); - - if (!AllowSettingFrameSrcToJavascriptUrl(imp, v)) return; - - imp->setSrc(v); -} - -ACCESSOR_SETTER(HTMLFrameElementLocation) { - HTMLFrameElement* imp = - V8Proxy::DOMWrapperToNode<HTMLFrameElement>(info.Holder()); - String v = valueToStringWithNullCheck(value); - - if (!AllowSettingFrameSrcToJavascriptUrl(imp, v)) return; - - imp->setLocation(v); -} - - // HTMLIFrameElement ----------------------------------------------------------- -ACCESSOR_SETTER(HTMLIFrameElementSrc) { - HTMLIFrameElement* imp = - V8Proxy::DOMWrapperToNode<HTMLIFrameElement>(info.Holder()); - String v = valueToStringWithNullCheck(value); - - if (!AllowSettingFrameSrcToJavascriptUrl(imp, v)) return; - - imp->setSrc(v); -} - - // TODO(mbelshe): This should move into V8DOMWindowCustom.cpp // Can't move it right now because it depends on V8ScheduledAction, // which is private to this file (v8_custom.cpp). @@ -1080,48 +942,6 @@ ACCESSOR_GETTER(DOMWindowEventHandler) { } -ACCESSOR_SETTER(ElementEventHandler) { - Node* node = V8Proxy::DOMWrapperToNode<Node>(info.Holder()); - - // Name starts with 'on', remove them. - String key = ToWebCoreString(name); - ASSERT(key.startsWith("on")); - String event_type = key.substring(2); - - // Set handler if the value is a function. Otherwise, clear the - // event handler. - if (value->IsFunction()) { - V8Proxy* proxy = V8Proxy::retrieve(node->document()->frame()); - // the document might be created using createDocument, - // which does not have a frame, use the active frame - if (!proxy) - proxy = V8Proxy::retrieve(V8Proxy::retrieveActiveFrame()); - if (!proxy) - return; - - RefPtr<EventListener> listener = - proxy->FindOrCreateV8EventListener(value, true); - if (listener) { - node->setInlineEventListenerForType(event_type, listener); - } - } else { - node->removeInlineEventListenerForType(event_type); - } -} - - -ACCESSOR_GETTER(ElementEventHandler) { - Node* node = V8Proxy::DOMWrapperToNode<Node>(info.Holder()); - - // Name starts with 'on', remove them. - String key = ToWebCoreString(name); - ASSERT(key.startsWith("on")); - String event_type = key.substring(2); - - EventListener* listener = node->inlineEventListenerForType(event_type); - return V8Proxy::EventListenerToV8Object(listener); -} - // --------------- Security Checks ------------------------- NAMED_ACCESS_CHECK(DOMWindow) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); diff --git a/V8Binding/v8/v8_helpers.h b/V8Binding/v8/v8_helpers.h index eebdd1e..b7f15aa 100644 --- a/V8Binding/v8/v8_helpers.h +++ b/V8Binding/v8/v8_helpers.h @@ -5,7 +5,12 @@ #ifndef V8_HELPERS_H__ #define V8_HELPERS_H__ +#if PLATFORM(CHROMIUM) #include "third_party/npapi/bindings/npruntime.h" +#else +#include "bridge/npruntime.h" // use WebCore version +#endif + #include <v8.h> namespace WebCore { diff --git a/V8Binding/v8/v8_index.cpp b/V8Binding/v8/v8_index.cpp index 60757b6..1078847 100644 --- a/V8Binding/v8/v8_index.cpp +++ b/V8Binding/v8/v8_index.cpp @@ -62,7 +62,6 @@ #include "V8CSSStyleSheet.h" #include "V8CSSVariablesDeclaration.h" #include "V8CSSVariablesRule.h" -#include "V8Database.h" #include "V8Document.h" #include "V8DocumentFragment.h" #include "V8DocumentType.h" @@ -135,7 +134,6 @@ #include "V8HTMLTitleElement.h" #include "V8HTMLUListElement.h" #include "V8ImageData.h" -#include "V8InspectorController.h" #include "V8MediaList.h" #include "V8MessageChannel.h" #include "V8MessageEvent.h" @@ -180,28 +178,39 @@ #include "V8Range.h" #include "V8RangeException.h" #include "V8Rect.h" -#include "V8SQLError.h" -#include "V8SQLResultSet.h" -#include "V8SQLResultSetRowList.h" -#include "V8SQLTransaction.h" #include "V8NodeIterator.h" #include "V8TextMetrics.h" #include "V8TreeWalker.h" #include "V8StyleSheetList.h" #include "V8DOMImplementation.h" + +#if ENABLE(XPATH) #include "V8XPathResult.h" #include "V8XPathException.h" #include "V8XPathExpression.h" #include "V8XPathNSResolver.h" +#include "V8XPathEvaluator.h" +#endif +#if ENABLE(XSLT) +#include "V8XSLTProcessor.h" +#endif + #include "V8XMLHttpRequest.h" #include "V8XMLHttpRequestException.h" #include "V8XMLHttpRequestProgressEvent.h" #include "V8XMLHttpRequestUpload.h" #include "V8XMLSerializer.h" -#include "V8XPathEvaluator.h" -#include "V8XSLTProcessor.h" #include "V8RGBColor.h" +#if PLATFORM(CHROMIUM) +#include "V8InspectorController.h" +#include "V8Database.h" +#include "V8SQLError.h" +#include "V8SQLResultSet.h" +#include "V8SQLResultSetRowList.h" +#include "V8SQLTransaction.h" +#endif + #if ENABLE(SVG_ANIMATION) #include "V8SVGAnimateColorElement.h" #include "V8SVGAnimateElement.h" @@ -368,6 +377,18 @@ #include "V8WorkerNavigator.h" #endif +#if PLATFORM(ANDROID) +#include "V8Coordinates.h" +#include "V8Geolocation.h" +#include "V8Geoposition.h" +#include "V8PositionError.h" +#include "V8PositionErrorCallback.h" +#include "V8Touch.h" +#include "V8TouchList.h" +#include "V8TouchEvent.h" +#include "V8VoidCallback.h" +#endif + namespace WebCore { FunctionTemplateFactory V8ClassIndex::GetFactory(V8WrapperType type) { diff --git a/V8Binding/v8/v8_index.h b/V8Binding/v8/v8_index.h index f567e5d..ae32ba2 100644 --- a/V8Binding/v8/v8_index.h +++ b/V8Binding/v8/v8_index.h @@ -284,7 +284,6 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(HTMLOPTIONSCOLLECTION, HTMLOptionsCollection) \ V(IMAGEDATA, ImageData) \ V(CANVASPIXELARRAY, CanvasPixelArray) \ - V(INSPECTORCONTROLLER, InspectorController) \ V(KEYBOARDEVENT, KeyboardEvent) \ V(LOCATION, Location) \ V(MEDIALIST, MediaList) @@ -328,15 +327,16 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(XMLHTTPREQUESTEXCEPTION, XMLHttpRequestException) \ V(XMLHTTPREQUESTPROGRESSEVENT, XMLHttpRequestProgressEvent) \ V(XMLSERIALIZER, XMLSerializer) \ + ACTIVE_DOM_OBJECT_TYPES(V) \ + VIDEO_NONNODE_TYPES(V) \ + WORKER_NONNODE_WRAPPER_TYPES(V) + +#define DOM_OBJECT_XPATH_TYPES(V) \ V(XPATHEVALUATOR, XPathEvaluator) \ V(XPATHEXCEPTION, XPathException) \ V(XPATHEXPRESSION, XPathExpression) \ V(XPATHNSRESOLVER, XPathNSResolver) \ - V(XPATHRESULT, XPathResult) \ - V(XSLTPROCESSOR, XSLTProcessor) \ - ACTIVE_DOM_OBJECT_TYPES(V) \ - VIDEO_NONNODE_TYPES(V) \ - WORKER_NONNODE_WRAPPER_TYPES(V) + V(XPATHRESULT, XPathResult) #define DOM_OBJECT_DATABASE_TYPES(V) \ V(DATABASE, Database) \ @@ -345,10 +345,32 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(SQLRESULTSETROWLIST, SQLResultSetRowList) \ V(SQLTRANSACTION, SQLTransaction) +#if PLATFORM(CHROMIUM) #define DOM_OBJECT_TYPES(V) \ DOM_OBJECT_TYPES_1(V) \ DOM_OBJECT_TYPES_2(V) \ - DOM_OBJECT_DATABASE_TYPES(V) + DOM_OBJECT_DATABASE_TYPES(V) \ + DOM_OBJECT_XPATH_TYPES(V) \ + V(XSLTPROCESSOR, XSLTProcessor) \ + V(INSPECTORCONTROLLER, InspectorController) +#endif + +#if PLATFORM(ANDROID) +#define DOM_OBJECT_TYPES(V) \ + DOM_OBJECT_TYPES_1(V) \ + DOM_OBJECT_TYPES_2(V) \ + V(COORDINATES, Coordinates) \ + V(GEOLOCATION, Geolocation) \ + V(GEOPOSITION, Geoposition) \ + V(POSITIONERROR, PositionError) \ + V(POSITIONERRORCALLBACK, PositionErrorCallback) \ + V(TOUCHLIST, TouchList) \ + V(TOUCHEVENT, TouchEvent) \ + V(TOUCH, Touch) \ + V(VOIDCALLBACK, VoidCallback) +#endif + +// Other platform must define DOM_OBJECT_TYPES #if ENABLE(SVG) // SVG_OBJECT_TYPES are svg non-node, non-pod types. diff --git a/V8Binding/v8/v8_proxy.cpp b/V8Binding/v8/v8_proxy.cpp index deb47fd..204b2bc 100644 --- a/V8Binding/v8/v8_proxy.cpp +++ b/V8Binding/v8/v8_proxy.cpp @@ -33,7 +33,10 @@ #include <utility> #include <v8.h> + +#ifdef ENABLE_DEBUGGER_SUPPORT #include <v8-debug.h> +#endif #include "v8_proxy.h" #include "v8_index.h" @@ -42,12 +45,17 @@ #include "V8Collection.h" #include "V8DOMWindow.h" +#if PLATFORM(CHROMIUM) #include "ChromiumBridge.h" +#endif + #include "DOMObjectsInclude.h" #include "ScriptController.h" #include "V8DOMMap.h" +#include "CString.h" + namespace WebCore { V8EventListenerList::V8EventListenerList(const char* name) @@ -402,6 +410,17 @@ void V8Proxy::GCUnprotect(void* dom_object) } +typedef std::pair<uintptr_t, Node*> GrouperPair; +typedef Vector<GrouperPair> GrouperList; + +#if PLATFORM(ANDROID) +// Sort GrouperPair by the group id. Node* is only involved to sort within +// a group id, so it will be fine. +static bool ComparePair(const GrouperPair& p1, const GrouperPair& p2) { + return p1.first < p2.first; +} +#endif + // Create object groups for DOM tree nodes. static void GCPrologue() { @@ -473,9 +492,6 @@ ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE) } // Create object groups. - typedef std::pair<uintptr_t, Node*> GrouperPair; - typedef Vector<GrouperPair> GrouperList; - DOMNodeMap node_map = getDOMNodeMap().impl(); GrouperList grouper; grouper.reserveCapacity(node_map.size()); @@ -512,10 +528,14 @@ ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE) grouper.append(GrouperPair(group_id, node)); } +#if PLATFORM(ANDROID) + std::stable_sort<GrouperPair>(grouper.begin(), grouper.end(), ComparePair); +#else // Group by sorting by the group id. This will use the std::pair operator<, // which will really sort by both the group id and the Node*. However the // Node* is only involved to sort within a group id, so it will be fine. std::sort(grouper.begin(), grouper.end()); +#endif // TODO(deanm): Should probably work in iterators here, but indexes were // easier for my simple mind. @@ -1066,8 +1086,9 @@ bool V8Proxy::HandleOutOfMemory() // Destroy the global object. proxy->DestroyGlobal(); +#if PLATFORM(CHROMIUM) ChromiumBridge::notifyJSOutOfMemory(frame); - +#endif // Disable JS. Settings* settings = frame->settings(); ASSERT(settings); @@ -1122,15 +1143,19 @@ v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* n) // Compile the script. v8::Local<v8::String> code = v8ExternalString(source.source()); +#if PLATFORM(CHROMIUM) ChromiumBridge::traceEventBegin("v8.compile", n, ""); +#endif // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at // 1, whereas v8 starts at 0. v8::Handle<v8::Script> script = CompileScript(code, source.url(), source.startLine() - 1); +#if PLATFORM(CHROMIUM) ChromiumBridge::traceEventEnd("v8.compile", n, ""); - ChromiumBridge::traceEventBegin("v8.run", n, ""); +#endif + v8::Local<v8::Value> result; { // Isolate exceptions that occur when executing the code. These @@ -1144,7 +1169,9 @@ v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* n) // this based on whether the script source has a URL. result = RunScript(script, source.url().string().isNull()); } +#if PLATFORM(CHROMIUM) ChromiumBridge::traceEventEnd("v8.run", n, ""); +#endif return result; } @@ -1662,12 +1689,16 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( V8Custom::kXMLHttpRequestInternalFieldCount); break; } +#if ENABLE(XPATH) case V8ClassIndex::XPATHEVALUATOR: desc->SetCallHandler(USE_CALLBACK(XPathEvaluatorConstructor)); break; +#endif +#if ENABLE(XSLT) case V8ClassIndex::XSLTPROCESSOR: desc->SetCallHandler(USE_CALLBACK(XSLTProcessorConstructor)); break; +#endif default: break; } @@ -1788,13 +1819,20 @@ bool V8Proxy::isEnabled() // not be made at this layer. instead, we should bridge out to the // embedder to allow them to override policy here. +#if PLATFORM(CHROMIUM) if (origin->protocol() == ChromiumBridge::uiResourceProtocol()) return true; // Embedder's scripts are ok to run +#endif // If the scheme is ftp: or file:, an empty file name indicates a directory // listing, which requires JavaScript to function properly. const char* kDirProtocols[] = { "ftp", "file" }; +#if PLATFORM(ANDROID) + // TODO(fqian): port arraysize function to Android. + for (size_t i = 0; i < 2; ++i) { +#else for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { +#endif if (origin->protocol() == kDirProtocols[i]) { const KURL& url = document->url(); return url.pathAfterLastSlash() == url.pathEnd(); @@ -3300,6 +3338,9 @@ void V8Proxy::CreateUtilityContext() { int V8Proxy::GetSourceLineNumber() { +#if PLATFORM(ANDROID) + return 0; +#else v8::HandleScope scope; v8::Handle<v8::Context> utility_context = V8Proxy::GetUtilityContext(); if (utility_context.IsEmpty()) { @@ -3317,10 +3358,14 @@ int V8Proxy::GetSourceLineNumber() { return 0; } return result->Int32Value(); +#endif } String V8Proxy::GetSourceName() { +#if PLATFORM(ANDROID) + return String(); +#else v8::HandleScope scope; v8::Handle<v8::Context> utility_context = GetUtilityContext(); if (utility_context.IsEmpty()) { @@ -3334,13 +3379,14 @@ String V8Proxy::GetSourceName() { return String(); } return ToWebCoreString(v8::Debug::Call(frame_source_name)); +#endif } void V8Proxy::RegisterExtension(v8::Extension* extension, const String& schemeRestriction) { v8::RegisterExtension(extension); V8ExtensionInfo info = {schemeRestriction, extension}; - m_extensions.push_back(info); + m_extensions.append(info); } } // namespace WebCore diff --git a/V8Binding/v8/v8_proxy.h b/V8Binding/v8/v8_proxy.h index d1a7a9f..45f9f39 100644 --- a/V8Binding/v8/v8_proxy.h +++ b/V8Binding/v8/v8_proxy.h @@ -9,7 +9,6 @@ #include "v8_index.h" #include "v8_custom.h" #include "v8_utility.h" -#include "ChromiumBridge.h" #include "Node.h" #include "NodeFilter.h" #include "PlatformString.h" // for WebCore::String @@ -20,10 +19,8 @@ #include <wtf/PassRefPtr.h> // so generated bindings don't have to #include <wtf/Vector.h> -#include <iterator> -#include <list> - -#ifdef ENABLE_DOM_STATS_COUNTERS +#if defined(ENABLE_DOM_STATS_COUNTERS) && PLATFORM(CHROMIUM) +#include "ChromiumBridge.h" #define INC_STATS(name) ChromiumBridge::incrementStatsCounter(name) #else #define INC_STATS(name) @@ -185,7 +182,7 @@ struct V8ExtensionInfo { String scheme; v8::Extension* extension; }; -typedef std::list<V8ExtensionInfo> V8ExtensionList; +typedef WTF::Vector<V8ExtensionInfo> V8ExtensionList; class V8Proxy { public: diff --git a/WebCore/Android.derived.mk b/WebCore/Android.derived.mk index 297fff6..9c56ec4 100644 --- a/WebCore/Android.derived.mk +++ b/WebCore/Android.derived.mk @@ -174,6 +174,16 @@ $(GEN): $(make_css_file_arrays) $(style_sheets) $(transform-generated-source) LOCAL_GENERATED_SOURCES += $(GEN) $(GEN:%.h=%.cpp) +# XML attribute names + +GEN:= $(intermediates)/XMLNames.cpp +$(GEN): PRIVATE_PATH := $(LOCAL_PATH) +$(GEN): PRIVATE_CUSTOM_TOOL = perl -I $(PRIVATE_PATH)/bindings/scripts $< --attrs $(xml_attrs) --output $(dir $@) +$(GEN): xml_attrs := $(LOCAL_PATH)/xml/xmlattrs.in +$(GEN): $(LOCAL_PATH)/dom/make_names.pl $(xml_attrs) + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + # character set name table #gen_inputs := \ diff --git a/WebCore/Android.mk b/WebCore/Android.mk index 347b29b..356aa1d 100644 --- a/WebCore/Android.mk +++ b/WebCore/Android.mk @@ -648,8 +648,8 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ plugins/npapi.cpp \ \ plugins/android/PluginDataAndroid.cpp \ - plugins/android/PluginPackageAndroid.cpp \ - plugins/android/PluginViewAndroid.cpp \ + plugins/android/PluginPackageAndroid.cpp \ + plugins/android/PluginViewAndroid.cpp \ \ rendering/AutoTableLayout.cpp \ rendering/CounterNode.cpp \ @@ -697,7 +697,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ rendering/RenderPartObject.cpp \ rendering/RenderPath.cpp \ rendering/RenderReplaced.cpp \ - rendering/RenderReplica.cpp \ + rendering/RenderReplica.cpp ifeq ($(ENABLE_SVG), true) LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ diff --git a/WebCore/JavaScriptCore.derived.mk b/WebCore/JavaScriptCore.derived.mk index 970c6bf..fa8e627 100644 --- a/WebCore/JavaScriptCore.derived.mk +++ b/WebCore/JavaScriptCore.derived.mk @@ -15,9 +15,10 @@ ## limitations under the License. ## -LOCAL_CFLAGS += -DWTF_USE_JSC - BINDING_C_INCLUDES := \ + $(BASE_PATH)/WebCore/bridge \ + $(BASE_PATH)/WebCore/bridge/c \ + $(BASE_PATH)/WebCore/bridge/jni \ $(BASE_PATH)/WebCore/bindings/js \ $(BASE_PATH)/JavaScriptCore \ $(BASE_PATH)/JavaScriptCore/API \ @@ -32,11 +33,7 @@ BINDING_C_INCLUDES := \ $(BASE_PATH)/JavaScriptCore/profiler \ $(BASE_PATH)/JavaScriptCore/runtime \ $(BASE_PATH)/JavaScriptCore/wrec \ - $(BASE_PATH)/JavaScriptCore/wtf \ - $(BASE_PATH)/JavaScriptCore/wtf/unicode \ - $(BASE_PATH)/JavaScriptCore/wtf/unicode/icu \ $(BASE_PATH)/JavaScriptCore/ForwardingHeaders \ - $(base_intermediates)/JavaScriptCore \ $(base_intermediates)/JavaScriptCore/parser \ $(base_intermediates)/JavaScriptCore/runtime \ $(base_intermediates)/WebCore/bindings/js @@ -669,16 +666,6 @@ $(GEN): $(LOCAL_PATH)/dom/make_names.pl $(svg_tags) $(svg_attrs) LOCAL_GENERATED_SOURCES += $(GEN) endif -# XML attribute names - -GEN:= $(intermediates)/XMLNames.cpp -$(GEN): PRIVATE_PATH := $(LOCAL_PATH) -$(GEN): PRIVATE_CUSTOM_TOOL = perl -I $(PRIVATE_PATH)/bindings/scripts $< --attrs $(xml_attrs) --output $(dir $@) -$(GEN): xml_attrs := $(LOCAL_PATH)/xml/xmlattrs.in -$(GEN): $(LOCAL_PATH)/dom/make_names.pl $(xml_attrs) - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - # XLink attribute names ifeq ($(ENABLE_SVG), true) diff --git a/WebCore/bindings/v8/V8DOMMap.cpp b/WebCore/bindings/v8/V8DOMMap.cpp index 830320e..82d9e69 100644 --- a/WebCore/bindings/v8/V8DOMMap.cpp +++ b/WebCore/bindings/v8/V8DOMMap.cpp @@ -279,8 +279,10 @@ private: InternalDOMWrapperMap<Node> m_staticDomNodeMap; InternalDOMWrapperMap<void> m_staticDomObjectMap; InternalDOMWrapperMap<void> m_staticActiveDomObjectMap; +#if ENABLE(SVG) InternalDOMWrapperMap<SVGElementInstance> m_staticDomSvgElementInstanceMap; InternalDOMWrapperMap<void> m_staticDomSvgObjectWithContextMap; +#endif }; DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<NonMainThreadSpecificDOMData>, threadSpecificDOMData, ()); diff --git a/WebCore/bindings/v8/custom/V8CustomBinding.cpp b/WebCore/bindings/v8/custom/V8CustomBinding.cpp index 841382b..03361ea 100644 --- a/WebCore/bindings/v8/custom/V8CustomBinding.cpp +++ b/WebCore/bindings/v8/custom/V8CustomBinding.cpp @@ -30,6 +30,7 @@ #include "config.h" #include "V8CustomBinding.h" +#include "V8Proxy.h" #include "Element.h" #include "Document.h" diff --git a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp new file mode 100644 index 0000000..d031a50 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp @@ -0,0 +1,698 @@ +/* + * Copyright (C) 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 "DOMWindow.h" + +#include "V8Binding.h" +#include "V8CustomBinding.h" +#include "V8CustomEventListener.h" +#include "V8Proxy.h" + +#include "DOMTimer.h" +#include "Frame.h" +#include "FrameLoadRequest.h" +#include "FrameView.h" +#include "Page.h" +#include "PlatformScreen.h" +#include "ScriptSourceCode.h" +#include "Settings.h" +#include "WindowFeatures.h" + + +// Horizontal and vertical offset, from the parent content area, around newly +// opened popups that don't specify a location. +static const int popupTilePixels = 10; + +namespace WebCore { + +ACCESSOR_SETTER(DOMWindowLocation) +{ + v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, info.This()); + if (holder.IsEmpty()) + return; + + DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder); + WindowSetLocation(imp, toWebCoreString(value)); +} + + +ACCESSOR_SETTER(DOMWindowOpener) +{ + DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + + if (!V8Proxy::CanAccessFrame(imp->frame(), true)) + return; + + // Opener can be shadowed if it is in the same domain. + // Have a special handling of null value to behave + // like Firefox. See bug http://b/1224887 & http://b/791706. + if (value->IsNull()) { + // imp->frame() cannot be null, + // otherwise, SameOrigin check would have failed. + ASSERT(imp->frame()); + imp->frame()->loader()->setOpener(0); + } + + // Delete the accessor from this object. + info.Holder()->Delete(name); + + // Put property on the front (this) object. + info.This()->Set(name, value); +} + +CALLBACK_FUNC_DECL(DOMWindowAddEventListener) +{ + INC_STATS("DOM.DOMWindow.addEventListener()"); + DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + + if (!V8Proxy::CanAccessFrame(imp->frame(), true)) + return v8::Undefined(); + + if (!imp->frame()) + return v8::Undefined(); // DOMWindow could be disconnected from the frame + + Document* doc = imp->frame()->document(); + if (!doc) + return v8::Undefined(); + + // TODO: Check if there is not enough arguments + V8Proxy* proxy = V8Proxy::retrieve(imp->frame()); + if (!proxy) + return v8::Undefined(); + + RefPtr<EventListener> listener = proxy->FindOrCreateV8EventListener(args[1], false); + + if (listener) { + String eventType = toWebCoreString(args[0]); + bool useCapture = args[2]->BooleanValue(); + doc->addWindowEventListener(eventType, listener, useCapture); + } + + return v8::Undefined(); +} + + +CALLBACK_FUNC_DECL(DOMWindowRemoveEventListener) +{ + INC_STATS("DOM.DOMWindow.removeEventListener()"); + DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + + if (!V8Proxy::CanAccessFrame(imp->frame(), true)) + return v8::Undefined(); + + if (!imp->frame()) + return v8::Undefined(); + + Document* doc = imp->frame()->document(); + if (!doc) + return v8::Undefined(); + + V8Proxy* proxy = V8Proxy::retrieve(imp->frame()); + if (!proxy) + return v8::Undefined(); + + RefPtr<EventListener> listener = proxy->FindV8EventListener(args[1], false); + + if (listener) { + String eventType = toWebCoreString(args[0]); + bool useCapture = args[2]->BooleanValue(); + doc->removeWindowEventListener(eventType, listener.get(), useCapture); + } + + return v8::Undefined(); +} + +CALLBACK_FUNC_DECL(DOMWindowPostMessage) +{ + INC_STATS("DOM.DOMWindow.postMessage()"); + DOMWindow* window = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + + DOMWindow* source = V8Proxy::retrieveActiveFrame()->domWindow(); + ASSERT(source->frame()); + + String uri = source->frame()->loader()->url().string(); + + v8::TryCatch tryCatch; + + String message = toWebCoreString(args[0]); + MessagePort* port = 0; + String domain; + + // This function has variable arguments and can either be: + // postMessage(message, port, domain); + // or + // postMessage(message, domain); + if (args.Length() > 2) { + if (V8Proxy::IsWrapperOfType(args[1], V8ClassIndex::MESSAGEPORT)) + port = V8Proxy::ToNativeObject<MessagePort>(V8ClassIndex::MESSAGEPORT, args[1]); + domain = valueToStringWithNullOrUndefinedCheck(args[2]); + } else + domain = valueToStringWithNullOrUndefinedCheck(args[1]); + + if (tryCatch.HasCaught()) + return v8::Undefined(); + + ExceptionCode ec = 0; + window->postMessage(message, port, domain, source, ec); + if (ec) + V8Proxy::SetDOMException(ec); + + return v8::Undefined(); +} + + +static bool canShowModalDialogNow(const Frame* frame) +{ + // A frame can out live its page. See bug 1219613. + if (!frame || !frame->page()) + return false; + return frame->page()->chrome()->canRunModalNow(); +} + +static bool allowPopUp() +{ + Frame* frame = V8Proxy::retrieveActiveFrame(); + + ASSERT(frame); + if (frame->script()->processingUserGesture()) + return true; + Settings* settings = frame->settings(); + return settings && settings->JavaScriptCanOpenWindowsAutomatically(); +} + +static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg) +{ + HashMap<String, String> map; + + Vector<String> features; + featuresArg.split(';', features); + Vector<String>::const_iterator end = features.end(); + for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) { + String featureString = *it; + int pos = featureString.find('='); + int colonPos = featureString.find(':'); + if (pos >= 0 && colonPos >= 0) + continue; // ignore any strings that have both = and : + if (pos < 0) + pos = colonPos; + if (pos < 0) { + // null string for value means key without value + map.set(featureString.stripWhiteSpace().lower(), String()); + } else { + String key = featureString.left(pos).stripWhiteSpace().lower(); + String val = featureString.substring(pos + 1).stripWhiteSpace().lower(); + int spacePos = val.find(' '); + if (spacePos != -1) + val = val.left(spacePos); + map.set(key, val); + } + } + + return map; +} + + +static Frame* createWindow(Frame* openerFrame, + const String& url, + const String& frameName, + const WindowFeatures& windowFeatures, + v8::Local<v8::Value> dialogArgs) +{ + Frame* activeFrame = V8Proxy::retrieveActiveFrame(); + + ResourceRequest request; + if (activeFrame) + request.setHTTPReferrer(activeFrame->loader()->outgoingReferrer()); + FrameLoadRequest frameRequest(request, frameName); + + // FIXME: It's much better for client API if a new window starts with a URL, + // here where we know what URL we are going to open. Unfortunately, this + // code passes the empty string for the URL, but there's a reason for that. + // Before loading we have to set up the opener, openedByDOM, + // and dialogArguments values. Also, to decide whether to use the URL + // we currently do an allowsAccessFrom call using the window we create, + // which can't be done before creating it. We'd have to resolve all those + // issues to pass the URL instead of "". + + bool created; + // We pass in the opener frame here so it can be used for looking up the + // frame name, in case the active frame is different from the opener frame, + // and the name references a frame relative to the opener frame, for example + // "_self" or "_parent". + Frame* newFrame = activeFrame->loader()->createWindow(openerFrame->loader(), frameRequest, windowFeatures, created); + if (!newFrame) + return 0; + + newFrame->loader()->setOpener(openerFrame); + newFrame->loader()->setOpenedByDOM(); + + // Set dialog arguments on the global object of the new frame. + if (!dialogArgs.IsEmpty()) { + v8::Local<v8::Context> context = V8Proxy::GetContext(newFrame); + if (!context.IsEmpty()) { + v8::Context::Scope scope(context); + context->Global()->Set(v8::String::New("dialogArguments"), dialogArgs); + } + } + + if (!parseURL(url).startsWith("javascript:", false) + || ScriptController::isSafeScript(newFrame)) { + KURL completedUrl = + url.isEmpty() ? KURL("") : activeFrame->document()->completeURL(url); + bool userGesture = activeFrame->script()->processingUserGesture(); + + if (created) + newFrame->loader()->changeLocation(completedUrl, activeFrame->loader()->outgoingReferrer(), false, false, userGesture); + else if (!url.isEmpty()) + newFrame->loader()->scheduleLocationChange(completedUrl.string(), activeFrame->loader()->outgoingReferrer(), false, userGesture); + } + + return newFrame; +} + + + +CALLBACK_FUNC_DECL(DOMWindowShowModalDialog) +{ + INC_STATS("DOM.DOMWindow.showModalDialog()"); + DOMWindow* window = V8Proxy::ToNativeObject<DOMWindow>( + V8ClassIndex::DOMWINDOW, args.Holder()); + Frame* frame = window->frame(); + + if (!frame || !V8Proxy::CanAccessFrame(frame, true)) + return v8::Undefined(); + + if (!canShowModalDialogNow(frame) || !allowPopUp()) + return v8::Undefined(); + + String url = valueToStringWithNullOrUndefinedCheck(args[0]); + v8::Local<v8::Value> dialogArgs = args[1]; + String featureArgs = valueToStringWithNullOrUndefinedCheck(args[2]); + + const HashMap<String, String> features = parseModalDialogFeatures(featureArgs); + + const bool trusted = false; + + FloatRect screenRect = screenAvailableRect(frame->view()); + + WindowFeatures windowFeatures; + // default here came from frame size of dialog in MacIE. + windowFeatures.width = WindowFeatures::floatFeature(features, "dialogwidth", 100, screenRect.width(), 620); + windowFeatures.widthSet = true; + // default here came from frame size of dialog in MacIE. + windowFeatures.height = WindowFeatures::floatFeature(features, "dialogheight", 100, screenRect.height(), 450); + windowFeatures.heightSet = true; + + windowFeatures.x = WindowFeatures::floatFeature(features, "dialogleft", screenRect.x(), screenRect.right() - windowFeatures.width, -1); + windowFeatures.xSet = windowFeatures.x > 0; + windowFeatures.y = WindowFeatures::floatFeature(features, "dialogtop", screenRect.y(), screenRect.bottom() - windowFeatures.height, -1); + windowFeatures.ySet = windowFeatures.y > 0; + + if (WindowFeatures::boolFeature(features, "center", true)) { + if (!windowFeatures.xSet) { + windowFeatures.x = screenRect.x() + (screenRect.width() - windowFeatures.width) / 2; + windowFeatures.xSet = true; + } + if (!windowFeatures.ySet) { + windowFeatures.y = screenRect.y() + (screenRect.height() - windowFeatures.height) / 2; + windowFeatures.ySet = true; + } + } + + windowFeatures.dialog = true; + windowFeatures.resizable = WindowFeatures::boolFeature(features, "resizable"); + windowFeatures.scrollbarsVisible = WindowFeatures::boolFeature(features, "scroll", true); + windowFeatures.statusBarVisible = WindowFeatures::boolFeature(features, "status", !trusted); + windowFeatures.menuBarVisible = false; + windowFeatures.toolBarVisible = false; + windowFeatures.locationBarVisible = false; + windowFeatures.fullscreen = false; + + Frame* dialogFrame = createWindow(frame, url, "", windowFeatures, dialogArgs); + if (!dialogFrame) + return v8::Undefined(); + + // Hold on to the context of the dialog window long enough to retrieve the + // value of the return value property. + v8::Local<v8::Context> context = V8Proxy::GetContext(dialogFrame); + + // Run the dialog. + dialogFrame->page()->chrome()->runModal(); + + // Extract the return value property from the dialog window. + v8::Local<v8::Value> returnValue; + if (!context.IsEmpty()) { + v8::Context::Scope scope(context); + returnValue = context->Global()->Get(v8::String::New("returnValue")); + } + + if (!returnValue.IsEmpty()) + return returnValue; + + return v8::Undefined(); +} + + +CALLBACK_FUNC_DECL(DOMWindowOpen) +{ + INC_STATS("DOM.DOMWindow.open()"); + DOMWindow* parent = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + Frame* frame = parent->frame(); + + if (!V8Proxy::CanAccessFrame(frame, true)) + return v8::Undefined(); + + Frame* activeFrame = V8Proxy::retrieveActiveFrame(); + if (!activeFrame) + return v8::Undefined(); + + Page* page = frame->page(); + if (!page) + return v8::Undefined(); + + String urlString = valueToStringWithNullOrUndefinedCheck(args[0]); + AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_blank" : AtomicString(toWebCoreString(args[1])); + + // Because FrameTree::find() returns true for empty strings, we must check + // for empty framenames. Otherwise, illegitimate window.open() calls with + // no name will pass right through the popup blocker. + if (!allowPopUp() && + (frameName.isEmpty() || !frame->tree()->find(frameName))) { + return v8::Undefined(); + } + + // Get the target frame for the special cases of _top and _parent. In those + // cases, we can schedule a location change right now and return early. + bool topOrParent = false; + if (frameName == "_top") { + frame = frame->tree()->top(); + topOrParent = true; + } else if (frameName == "_parent") { + if (Frame* parent = frame->tree()->parent()) + frame = parent; + topOrParent = true; + } + if (topOrParent) { + if (!activeFrame->loader()->shouldAllowNavigation(frame)) + return v8::Undefined(); + + String completedUrl; + if (!urlString.isEmpty()) + completedUrl = activeFrame->document()->completeURL(urlString); + + if (!completedUrl.isEmpty() && + (!parseURL(urlString).startsWith("javascript:", false) + || ScriptController::isSafeScript(frame))) { + bool userGesture = activeFrame->script()->processingUserGesture(); + frame->loader()->scheduleLocationChange(completedUrl, activeFrame->loader()->outgoingReferrer(), false, userGesture); + } + return V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, frame->domWindow()); + } + + // In the case of a named frame or a new window, we'll use the + // createWindow() helper. + + // Parse the values, and then work with a copy of the parsed values + // so we can restore the values we may not want to overwrite after + // we do the multiple monitor fixes. + WindowFeatures rawFeatures(valueToStringWithNullOrUndefinedCheck(args[2])); + WindowFeatures windowFeatures(rawFeatures); + FloatRect screenRect = screenAvailableRect(page->mainFrame()->view()); + + // Set default size and location near parent window if none were specified. + // These may be further modified by adjustWindowRect, below. + if (!windowFeatures.xSet) { + windowFeatures.x = parent->screenX() - screenRect.x() + popupTilePixels; + windowFeatures.xSet = true; + } + if (!windowFeatures.ySet) { + windowFeatures.y = parent->screenY() - screenRect.y() + popupTilePixels; + windowFeatures.ySet = true; + } + if (!windowFeatures.widthSet) { + windowFeatures.width = parent->innerWidth(); + windowFeatures.widthSet = true; + } + if (!windowFeatures.heightSet) { + windowFeatures.height = parent->innerHeight(); + windowFeatures.heightSet = true; + } + + FloatRect windowRect(windowFeatures.x, windowFeatures.y, windowFeatures.width, windowFeatures.height); + + // The new window's location is relative to its current screen, so shift + // it in case it's on a secondary monitor. See http://b/viewIssue?id=967905. + windowRect.move(screenRect.x(), screenRect.y()); + WebCore::DOMWindow::adjustWindowRect(screenRect, windowRect, windowRect); + + windowFeatures.x = windowRect.x(); + windowFeatures.y = windowRect.y(); + windowFeatures.height = windowRect.height(); + windowFeatures.width = windowRect.width(); + + // If either of the origin coordinates weren't set in the original + // string, make sure they aren't set now. + if (!rawFeatures.xSet) { + windowFeatures.x = 0; + windowFeatures.xSet = false; + } + if (!rawFeatures.ySet) { + windowFeatures.y = 0; + windowFeatures.ySet = false; + } + + frame = createWindow(frame, urlString, frameName, windowFeatures, v8::Local<v8::Value>()); + + if (!frame) + return v8::Undefined(); + + return V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, frame->domWindow()); +} + + +INDEXED_PROPERTY_GETTER(DOMWindow) +{ + INC_STATS("DOM.DOMWindow.IndexedPropertyGetter"); + v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, info.This()); + if (holder.IsEmpty()) + return notHandledByInterceptor(); + + DOMWindow* window = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder); + if (!window) + return notHandledByInterceptor(); + + Frame* frame = window->frame(); + if (!frame) + return notHandledByInterceptor(); + + Frame* child = frame->tree()->child(index); + if (child) + return V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, child->domWindow()); + + return notHandledByInterceptor(); +} + + +NAMED_PROPERTY_GETTER(DOMWindow) +{ + INC_STATS("DOM.DOMWindow.NamedPropertyGetter"); + // The key must be a string. + if (!name->IsString()) + return notHandledByInterceptor(); + + v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, info.This()); + if (holder.IsEmpty()) + return notHandledByInterceptor(); + + DOMWindow* window = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder); + if (!window) + return notHandledByInterceptor(); + + String propName = toWebCoreString(name); + + Frame* frame = window->frame(); + // window is detached from a frame. + if (!frame) + return notHandledByInterceptor(); + + // Search sub-frames. + Frame* child = frame->tree()->child(propName); + if (child) + return V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, child->domWindow()); + + // Search IDL functions defined in the prototype + v8::Handle<v8::Value> result = holder->GetRealNamedPropertyInPrototypeChain(name); + if (!result.IsEmpty()) + return result; + + // Lazy initialization map keeps global properties that can be lazily + // initialized. The value is the code to instantiate the property. + // It must return the value of property after initialization. + static HashMap<String, String> lazyInitMap; + if (lazyInitMap.isEmpty()) { + // "new Image()" does not appear to be well-defined in a spec, but Safari, + // Opera, and Firefox all consider it to always create an HTML image + // element, regardless of the current doctype. + lazyInitMap.set("Image", + "function Image() { \ + return document.createElementNS( \ + 'http://www.w3.org/1999/xhtml', 'img'); \ + }; \ + Image"); + lazyInitMap.set("Option", + "function Option(text, value, defaultSelected, selected) { \ + var option = document.createElement('option'); \ + if (text == null) return option; \ + option.text = text; \ + if (value == null) return option; \ + option.value = value; \ + if (defaultSelected == null) return option; \ + option.defaultSelected = defaultSelected; \ + if (selected == null) return option; \ + option.selected = selected; \ + return option; \ + }; \ + Option"); + } + + String code = lazyInitMap.get(propName); + if (!code.isEmpty()) { + v8::Local<v8::Context> context = V8Proxy::GetContext(window->frame()); + // Bail out if we cannot get the context for the frame. + if (context.IsEmpty()) + return notHandledByInterceptor(); + + // switch to the target object's environment. + v8::Context::Scope scope(context); + + // Set the property name to undefined to make sure that the + // property exists. This is necessary because this getter + // might be called when evaluating 'var RangeException = value' + // to figure out if we have a property named 'RangeException' before + // we set RangeException to the new value. In that case, we will + // evaluate 'var RangeException = {}' and enter an infinite loop. + // Setting the property name to undefined on the global object + // ensures that we do not have to ask this getter to figure out + // that we have the property. + // + // TODO(ager): We probably should implement the Has method + // for the interceptor instead of using the default Has method + // that calls Get. + context->Global()->Set(v8String(propName), v8::Undefined()); + V8Proxy* proxy = V8Proxy::retrieve(window->frame()); + ASSERT(proxy); + + return proxy->evaluate(WebCore::ScriptSourceCode(code), 0); + } + + // Search named items in the document. + Document* doc = frame->document(); + if (doc) { + RefPtr<HTMLCollection> items = doc->windowNamedItems(propName); + if (items->length() >= 1) { + if (items->length() == 1) + return V8Proxy::NodeToV8Object(items->firstItem()); + else + return V8Proxy::ToV8Object(V8ClassIndex::HTMLCOLLECTION, items.get()); + } + } + + return notHandledByInterceptor(); +} + + +void V8Custom::WindowSetLocation(DOMWindow* window, const String& v) +{ + if (!window->frame()) + return; + + Frame* activeFrame = ScriptController::retrieveActiveFrame(); + if (!activeFrame) + return; + + if (!activeFrame->loader()->shouldAllowNavigation(window->frame())) + return; + + if (!parseURL(v).startsWith("javascript:", false) + || ScriptController::isSafeScript(window->frame())) { + String completedUrl = activeFrame->loader()->completeURL(v).string(); + + // FIXME: The JSC bindings pass !anyPageIsProcessingUserGesture() for + // the lockHistory parameter. We should probably do something similar. + + window->frame()->loader()->scheduleLocationChange(completedUrl, + activeFrame->loader()->outgoingReferrer(), false, false, + activeFrame->script()->processingUserGesture()); + } +} + + +CALLBACK_FUNC_DECL(DOMWindowSetTimeout) +{ + INC_STATS("DOM.DOMWindow.setTimeout()"); + return WindowSetTimeoutImpl(args, true); +} + + +CALLBACK_FUNC_DECL(DOMWindowSetInterval) +{ + INC_STATS("DOM.DOMWindow.setInterval()"); + return WindowSetTimeoutImpl(args, false); +} + + +void V8Custom::ClearTimeoutImpl(const v8::Arguments& args) +{ + v8::Handle<v8::Value> holder = args.Holder(); + DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder); + if (!V8Proxy::CanAccessFrame(imp->frame(), true)) + return; + ScriptExecutionContext* context = static_cast<ScriptExecutionContext*>(imp->frame()->document()); + int handle = toInt32(args[0]); + DOMTimer::removeById(context, handle); +} + + +CALLBACK_FUNC_DECL(DOMWindowClearTimeout) +{ + INC_STATS("DOM.DOMWindow.clearTimeout"); + ClearTimeoutImpl(args); + return v8::Undefined(); +} + +CALLBACK_FUNC_DECL(DOMWindowClearInterval) +{ + INC_STATS("DOM.DOMWindow.clearInterval"); + ClearTimeoutImpl(args); + return v8::Undefined(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DocumentCustom.cpp b/WebCore/bindings/v8/custom/V8DocumentCustom.cpp index 7f868f1..3eadce7 100644 --- a/WebCore/bindings/v8/custom/V8DocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DocumentCustom.cpp @@ -41,8 +41,11 @@ #include "V8CustomBinding.h" #include "V8Node.h" #include "V8Proxy.h" + +#if ENABLE(XPATH) #include "V8XPathNSResolver.h" #include "V8XPathResult.h" +#endif #include <wtf/RefPtr.h> @@ -51,7 +54,7 @@ namespace WebCore { CALLBACK_FUNC_DECL(DocumentEvaluate) { INC_STATS("DOM.Document.evaluate()"); - +#if ENABLE(XPATH) Document* document = V8Proxy::DOMWrapperToNode<Document>(args.Holder()); ExceptionCode ec = 0; String expression = toWebCoreString(args[0]); @@ -81,6 +84,9 @@ CALLBACK_FUNC_DECL(DocumentEvaluate) return throwError(ec); return V8Proxy::ToV8Object(V8ClassIndex::XPATHRESULT, result.get()); +#else + return throwError(NOT_SUPPORTED_ERR); +#endif } CALLBACK_FUNC_DECL(DocumentGetCSSCanvasContext) diff --git a/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp index bc04f7e..1d408b2 100644 --- a/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Google Inc. All rights reserved. + * Copyright (C) 2007, 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 @@ -58,19 +58,6 @@ NAMED_PROPERTY_DELETER(HTMLDocument) return v8::True(); } -NAMED_PROPERTY_SETTER(HTMLDocument) -{ - INC_STATS("DOM.HTMLDocument.NamedPropertySetter"); - // Only handle document.all. We insert the value into the shadow - // internal field from which the getter will retrieve it. - String key = toWebCoreString(name); - if (key == "all") { - ASSERT(info.Holder()->InternalFieldCount() == kHTMLDocumentInternalFieldCount); - info.Holder()->SetInternalField(kHTMLDocumentShadowIndex, value); - } - return notHandledByInterceptor(); -} - NAMED_PROPERTY_GETTER(HTMLDocument) { INC_STATS("DOM.HTMLDocument.NamedPropertyGetter"); @@ -87,13 +74,13 @@ NAMED_PROPERTY_GETTER(HTMLDocument) return value; } - HTMLDocument* imp = V8Proxy::DOMWrapperToNode<HTMLDocument>(info.Holder()); + HTMLDocument* htmlDocument = V8Proxy::DOMWrapperToNode<HTMLDocument>(info.Holder()); // Fast case for named elements that are not there. - if (!imp->hasNamedItem(key.impl()) && !imp->hasExtraNamedItem(key.impl())) + if (!htmlDocument->hasNamedItem(key.impl()) && !htmlDocument->hasExtraNamedItem(key.impl())) return v8::Handle<v8::Value>(); - RefPtr<HTMLCollection> items = imp->documentNamedItems(key); + RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key); if (!items->length()) return notHandledByInterceptor(); @@ -109,4 +96,96 @@ NAMED_PROPERTY_GETTER(HTMLDocument) return V8Proxy::ToV8Object(V8ClassIndex::HTMLCOLLECTION, items.get()); } +// HTMLDocument ---------------------------------------------------------------- + +// Concatenates "args" to a string. If args is empty, returns empty string. +// Firefox/Safari/IE support non-standard arguments to document.write, ex: +// document.write("a", "b", "c") --> document.write("abc") +// document.write() --> document.write("") +static String writeHelperGetString(const v8::Arguments& args) +{ + String str = ""; + for (int i = 0; i < args.Length(); ++i) + str += toWebCoreString(args[i]); + return str; +} + +CALLBACK_FUNC_DECL(HTMLDocumentWrite) +{ + INC_STATS("DOM.HTMLDocument.write()"); + HTMLDocument* htmlDocument = V8Proxy::DOMWrapperToNode<HTMLDocument>(args.Holder()); + Frame* frame = V8Proxy::retrieveActiveFrame(); + ASSERT(frame); + htmlDocument->write(writeHelperGetString(args), frame->document()); + return v8::Undefined(); +} + +CALLBACK_FUNC_DECL(HTMLDocumentWriteln) +{ + INC_STATS("DOM.HTMLDocument.writeln()"); + HTMLDocument* htmlDocument = V8Proxy::DOMWrapperToNode<HTMLDocument>(args.Holder()); + Frame* frame = V8Proxy::retrieveActiveFrame(); + ASSERT(frame); + htmlDocument->writeln(writeHelperGetString(args), frame->document()); + return v8::Undefined(); +} + +CALLBACK_FUNC_DECL(HTMLDocumentOpen) +{ + INC_STATS("DOM.HTMLDocument.open()"); + HTMLDocument* htmlDocument = V8Proxy::DOMWrapperToNode<HTMLDocument>(args.Holder()); + + if (args.Length() > 2) { + if (Frame* frame = htmlDocument->frame()) { + // Fetch the global object for the frame. + v8::Local<v8::Context> context = V8Proxy::GetContext(frame); + // Bail out if we cannot get the context. + if (context.IsEmpty()) + return v8::Undefined(); + v8::Local<v8::Object> global = context->Global(); + // Get the open property of the global object. + v8::Local<v8::Value> function = global->Get(v8::String::New("open")); + // If the open property is not a function throw a type error. + if (!function->IsFunction()) { + throwError("open is not a function"); + return v8::Undefined(); + } + // Wrap up the arguments and call the function. + v8::Local<v8::Value>* params = new v8::Local<v8::Value>[args.Length()]; + for (int i = 0; i < args.Length(); i++) + params[i] = args[i]; + + V8Proxy* proxy = V8Proxy::retrieve(frame); + ASSERT(proxy); + + v8::Local<v8::Value> result = proxy->CallFunction(v8::Local<v8::Function>::Cast(function), global, args.Length(), params); + delete[] params; + return result; + } + } + + Frame* frame = V8Proxy::retrieveActiveFrame(); + htmlDocument->open(frame->document()); + // Return the document. + return args.Holder(); +} + +ACCESSOR_GETTER(HTMLDocumentAll) +{ + INC_STATS("DOM.HTMLDocument.all._get"); + v8::HandleScope scope; + v8::Handle<v8::Object> holder = info.Holder(); + HTMLDocument* htmlDocument = V8Proxy::DOMWrapperToNode<HTMLDocument>(holder); + RefPtr<HTMLCollection> collection = WTF::getPtr(htmlDocument->all()); + return V8Proxy::ToV8Object(V8ClassIndex::HTMLCOLLECTION, WTF::getPtr(collection)); +} + +ACCESSOR_SETTER(HTMLDocumentAll) +{ + INC_STATS("DOM.HTMLDocument.all._set"); + v8::Handle<v8::Object> holder = info.Holder(); + ASSERT(info.Holder()->InternalFieldCount() == kHTMLDocumentInternalFieldCount); + info.Holder()->SetInternalField(kHTMLDocumentShadowIndex, value); +} + } // namespace WebCore diff --git a/WebCore/bridge/jni/jni_utility.cpp b/WebCore/bridge/jni/jni_utility.cpp index 5dc4722..a1f4a2d 100644 --- a/WebCore/bridge/jni/jni_utility.cpp +++ b/WebCore/bridge/jni/jni_utility.cpp @@ -28,11 +28,14 @@ #if ENABLE(MAC_JAVA_BRIDGE) +#if USE(JSC) #include "jni_runtime.h" #include "runtime_array.h" #include "runtime_object.h" #include <runtime/JSArray.h> #include <runtime/JSLock.h> +#endif + #include <dlfcn.h> namespace JSC { @@ -347,6 +350,7 @@ jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *sig return result; } +#if USE(JSC) static jobject convertArrayInstanceToJavaArray(ExecState* exec, JSArray* jsArray, const char* javaClassName) { JNIEnv *env = getJNIEnv(); @@ -576,6 +580,7 @@ jvalue convertValueToJValue(ExecState* exec, JSValuePtr value, JNIType _JNIType, } return result; } +#endif // USE(JSC) } // end of namespace Bindings diff --git a/WebCore/bridge/jni/jni_utility.h b/WebCore/bridge/jni/jni_utility.h index e76570c..4330b1e 100644 --- a/WebCore/bridge/jni/jni_utility.h +++ b/WebCore/bridge/jni/jni_utility.h @@ -28,7 +28,9 @@ #if ENABLE(MAC_JAVA_BRIDGE) +#if USE(JSC) #include <runtime/JSValue.h> +#endif #include <JavaVM/jni.h> // The order of these items can not be modified as they are tightly @@ -53,8 +55,10 @@ typedef enum { namespace JSC { +#if USE(JSC) class ExecState; class JSObject; +#endif namespace Bindings { @@ -72,7 +76,9 @@ JNIType JNITypeFromClassName(const char *name); JNIType JNITypeFromPrimitiveType(char type); const char *signatureFromPrimitiveType(JNIType type); +#if USE(JSC) jvalue convertValueToJValue(ExecState*, JSValuePtr, JNIType, const char* javaClassName); +#endif jvalue getJNIField(jobject obj, JNIType type, const char *name, const char *signature); @@ -279,9 +285,10 @@ T callJNIStaticMethod(jclass cls, const char* methodName, const char* methodSign return result; } - -bool dispatchJNICall(ExecState*, const void* targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue* args, jvalue& result, const char* callingURL, JSValuePtr& exceptionDescription); +#if USE(JSC) +bool dispatchJNICall(ExecState*, const void* targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue* args, jvalue& result, const char* callingURL, JSValuePtr& exceptionDescription); +#endif } // namespace Bindings } // namespace JSC diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp index 2e2dd9a..e280c81 100644 --- a/WebCore/dom/Document.cpp +++ b/WebCore/dom/Document.cpp @@ -114,7 +114,9 @@ #include "XMLHttpRequest.h" #include "XMLNames.h" #include "XMLTokenizer.h" +#if USE(JSC) #include "JSDOMBinding.h" +#endif #include "ScriptController.h" #include <wtf/CurrentTime.h> #include <wtf/HashFunctions.h> @@ -455,7 +457,10 @@ Document::~Document() removeAllEventListeners(); + +#if USE(JSC) forgetAllDOMNodesForDocument(this); +#endif if (m_docChanged && changedDocuments) changedDocuments->remove(this); diff --git a/WebCore/dom/EventListener.h b/WebCore/dom/EventListener.h index b7daa6d..1836fe6 100644 --- a/WebCore/dom/EventListener.h +++ b/WebCore/dom/EventListener.h @@ -48,8 +48,9 @@ namespace WebCore { virtual bool virtualIsInline() const { return false; } }; +#if USE(JSC) inline void markIfNotNull(EventListener* listener) { if (listener) listener->mark(); } - +#endif } #endif diff --git a/WebCore/inspector/InspectorController.h b/WebCore/inspector/InspectorController.h index 96b5e6f..de0c7e9 100644 --- a/WebCore/inspector/InspectorController.h +++ b/WebCore/inspector/InspectorController.h @@ -33,7 +33,6 @@ #include "PlatformString.h" #include "StringHash.h" #include "Timer.h" -#include <JavaScriptCore/JSContextRef.h> #include <wtf/HashMap.h> #include <wtf/HashSet.h> #include <wtf/RefCounted.h> @@ -43,11 +42,13 @@ #include "JavaScriptDebugListener.h" #endif - +#if USE(JSC) +#include <JavaScriptCore/JSContextRef.h> namespace JSC { class Profile; class UString; } +#endif namespace WebCore { @@ -176,10 +177,12 @@ public: void clearConsoleMessages(); void toggleRecordButton(bool); +#if USE(JSC) void addProfile(PassRefPtr<JSC::Profile>, unsigned lineNumber, const JSC::UString& sourceURL); void addProfileMessageToConsole(PassRefPtr<JSC::Profile> prpProfile, unsigned lineNumber, const JSC::UString& sourceURL); void addScriptProfile(JSC::Profile* profile); const ProfilesArray& profiles() const { return m_profiles; } +#endif void attachWindow(); void detachWindow(); @@ -192,8 +195,10 @@ public: void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags); void handleMousePressOnNode(Node*); +#if USE(JSC) JSContextRef scriptContext() const { return m_scriptContext; }; void setScriptContext(JSContextRef context) { m_scriptContext = context; }; +#endif void inspectedWindowScriptObjectCleared(Frame*); void windowScriptObjectAvailable(); @@ -214,8 +219,13 @@ public: void didReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived); void didFinishLoading(DocumentLoader*, unsigned long identifier); void didFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&); +#if USE(JSC) void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const JSC::UString& sourceString); void scriptImported(unsigned long identifier, const JSC::UString& sourceString); +#elif USE(V8) + void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const String& sourceString); + void scriptImported(unsigned long identifier, const String& sourceString); +#endif #if ENABLE(DATABASE) void didOpenDatabase(Database*, const String& domain, const String& name, const String& version); @@ -266,15 +276,19 @@ private: InspectorController(Page*, InspectorClient*); void focusNode(); +#if USE(JSC) void addConsoleMessage(JSC::ExecState*, ConsoleMessage*); +#endif void addResource(InspectorResource*); void removeResource(InspectorResource*); +#if USE(JSC) JSObjectRef addScriptResource(InspectorResource*); + JSObjectRef addAndUpdateScriptResource(InspectorResource*); +#endif void removeScriptResource(InspectorResource*); - JSObjectRef addAndUpdateScriptResource(InspectorResource*); void updateScriptResourceRequest(InspectorResource*); void updateScriptResourceResponse(InspectorResource*); void updateScriptResourceType(InspectorResource*); @@ -285,16 +299,20 @@ private: void pruneResources(ResourcesMap*, DocumentLoader* loaderToKeep = 0); void removeAllResources(ResourcesMap* map) { pruneResources(map); } +#if USE(JSC) JSValueRef callSimpleFunction(JSContextRef, JSObjectRef thisObject, const char* functionName) const; JSValueRef callFunction(JSContextRef, JSObjectRef thisObject, const char* functionName, size_t argumentCount, const JSValueRef arguments[], JSValueRef& exception) const; bool handleException(JSContextRef, JSValueRef exception, unsigned lineNumber) const; +#endif void showWindow(); #if ENABLE(JAVASCRIPT_DEBUGGER) +#if USE(JSC) virtual void didParseSource(JSC::ExecState*, const JSC::SourceCode&); virtual void failedToParseSource(JSC::ExecState*, const JSC::SourceCode&, int errorLine, const JSC::UString& errorMessage); +#endif virtual void didPause(); #endif @@ -307,7 +325,9 @@ private: HashSet<String> m_knownResources; FrameResourcesMap m_frameResources; Vector<ConsoleMessage*> m_consoleMessages; +#if USE(JSC) ProfilesArray m_profiles; +#endif HashMap<String, double> m_times; HashMap<String, unsigned> m_counts; #if ENABLE(DATABASE) @@ -316,9 +336,11 @@ private: #if ENABLE(DOM_STORAGE) DOMStorageResourcesSet m_domStorageResources; #endif +#if USE(JSC) JSObjectRef m_scriptObject; JSObjectRef m_controllerScriptObject; JSContextRef m_scriptContext; +#endif bool m_windowVisible; #if ENABLE(JAVASCRIPT_DEBUGGER) bool m_debuggerEnabled; diff --git a/WebCore/loader/icon/IconDatabase.cpp b/WebCore/loader/icon/IconDatabase.cpp index 0521381..9d5bd20 100644 --- a/WebCore/loader/icon/IconDatabase.cpp +++ b/WebCore/loader/icon/IconDatabase.cpp @@ -106,7 +106,11 @@ static IconDatabaseClient* defaultClient() IconDatabase* iconDatabase() { if (!sharedIconDatabase) { +#if USE(JSC) JSC::initializeThreading(); +#elif USE(V8) + // TODO(fqian): Do something for V8 +#endif sharedIconDatabase = new IconDatabase; } return sharedIconDatabase; diff --git a/WebCore/page/DOMWindow.idl b/WebCore/page/DOMWindow.idl index 6bb08a8..fd0cd55 100644 --- a/WebCore/page/DOMWindow.idl +++ b/WebCore/page/DOMWindow.idl @@ -395,9 +395,11 @@ module window { #if defined(V8_BINDING) // With JSC, these are added in JSDOMWindowBase.cpp. attribute XMLHttpRequestConstructor XMLHttpRequest; - attribute XSLTProcessorConstructor XSLTProcessor; attribute MessageChannelConstructor MessageChannel; attribute WebKitPointConstructor WebKitPoint; +#if ENABLE_XSLT + attribute XSLTProcessorConstructor XSLTProcessor; +#endif #if ENABLE_WORKERS attribute WorkerConstructor Worker; #endif diff --git a/WebCore/page/Frame.cpp b/WebCore/page/Frame.cpp index f0cd1ec..0d1a27f 100644 --- a/WebCore/page/Frame.cpp +++ b/WebCore/page/Frame.cpp @@ -1575,7 +1575,9 @@ void Frame::pageDestroyed() if (page() && page()->focusController()->focusedFrame() == this) page()->focusController()->setFocusedFrame(0); +#if USE(JSC) script()->clearWindowShell(); +#endif // This will stop any JS timers if (script()->haveWindowShell()) diff --git a/WebCore/page/Geolocation.idl b/WebCore/page/Geolocation.idl index e125118..8a9fef9 100644 --- a/WebCore/page/Geolocation.idl +++ b/WebCore/page/Geolocation.idl @@ -28,10 +28,11 @@ module core { interface Geolocation { readonly attribute Geoposition lastPosition; +#if !defined(V8_BINDING) [Custom] void getCurrentPosition(in PositionCallback successCallback, in PositionErrorCallback errorCallback, in PositionOptions options); [Custom] long watchPosition(in PositionCallback successCallback, in PositionErrorCallback errorCallback, in PositionOptions options); - +#endif void clearWatch(in long watchId); }; diff --git a/WebCore/page/android/InspectorControllerAndroid.cpp b/WebCore/page/android/InspectorControllerAndroid.cpp index 8763df1..c480e94 100644 --- a/WebCore/page/android/InspectorControllerAndroid.cpp +++ b/WebCore/page/android/InspectorControllerAndroid.cpp @@ -30,8 +30,9 @@ #include "Frame.h" #include "Node.h" +#if USE(JSC) #include "Profile.h" - +#endif // This stub file was created to avoid building and linking in all the // Inspector codebase. If you would like to enable the Inspector, do the // following steps: @@ -89,9 +90,17 @@ void InspectorController::didOpenDatabase(Database*, String const&, String const bool InspectorController::enabled() const { return false; } void InspectorController::inspect(Node*) {} bool InspectorController::windowVisible() { return false; } +#if USE(JSC) void InspectorController::addProfile(PassRefPtr<JSC::Profile>, unsigned int, const JSC::UString&) {} -void InspectorController::inspectedPageDestroyed() {} void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, const JSC::UString& sourceString) {} +void InspectorController::failedToParseSource(JSC::ExecState* exec, const JSC::SourceCode& source, int errorLine, const JSC::UString& errorMessage) {} +void InspectorController::didParseSource(JSC::ExecState* exec, const JSC::SourceCode& source) {} +void InspectorController::scriptImported(unsigned long identifier, const JSC::UString& sourceString) {} +#elif USE(V8) +void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, const String& sourceString) {} +void InspectorController::scriptImported(unsigned long identifier, const String& sourceString) {} +#endif +void InspectorController::inspectedPageDestroyed() {} void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame) {} void InspectorController::startGroup(MessageSource source, ScriptCallStack* callFrame) {} @@ -102,10 +111,10 @@ void InspectorController::count(const String& title, unsigned lineNumber, const void InspectorController::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) {} void InspectorController::handleMousePressOnNode(Node*) {} -void InspectorController::failedToParseSource(JSC::ExecState* exec, const JSC::SourceCode& source, int errorLine, const JSC::UString& errorMessage) {} -void InspectorController::didParseSource(JSC::ExecState* exec, const JSC::SourceCode& source) {} + +#if ENABLE(JAVASCRIPT_DEBUGGER) void InspectorController::didPause() {} +#endif -void InspectorController::scriptImported(unsigned long identifier, const JSC::UString& sourceString) {} void InspectorController::startUserInitiatedProfiling(Timer<InspectorController>*) {} } // namespace WebCore diff --git a/WebCore/platform/android/TemporaryLinkStubs.cpp b/WebCore/platform/android/TemporaryLinkStubs.cpp index 5d71dd0..458171d 100644 --- a/WebCore/platform/android/TemporaryLinkStubs.cpp +++ b/WebCore/platform/android/TemporaryLinkStubs.cpp @@ -61,12 +61,15 @@ #include "IconDatabase.h" #include "IconLoader.h" #include "IntPoint.h" + +#if USE(JSC) #include "JavaScriptCallFrame.h" #include "JavaScriptDebugServer.h" #include "API/JSClassRef.h" -#include "JavaScriptCallFrame.h" #include "JavaScriptProfile.h" #include "jni_utility.h" +#endif + #include "KURL.h" #include "Language.h" #include "loader.h" @@ -745,6 +748,7 @@ PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String&) } +#if USE(JSC) namespace JSC { namespace Bindings { bool dispatchJNICall(ExecState*, const void* targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue* args, jvalue& result, const char* callingURL, JSValuePtr& exceptionDescription) @@ -754,6 +758,7 @@ bool dispatchJNICall(ExecState*, const void* targetAppletView, jobject obj, bool } } } // namespace Bindings +#endif char* dirname(const char*) { @@ -839,6 +844,7 @@ void AXObjectCache::remove(RenderObject*) notImplemented(); } +#if USE(JSC) using namespace JSC; @@ -962,3 +968,5 @@ void JavaScriptDebugServer::willExecuteProgram(const DebuggerCallFrame&, int, in { notImplemented(); } +#endif + diff --git a/WebCore/plugins/PluginView.cpp b/WebCore/plugins/PluginView.cpp index 60287f6..57317a1 100644 --- a/WebCore/plugins/PluginView.cpp +++ b/WebCore/plugins/PluginView.cpp @@ -38,7 +38,6 @@ #include "Image.h" #include "HTMLNames.h" #include "HTMLPlugInElement.h" -#include "JSDOMWindow.h" #include "KeyboardEvent.h" #include "MIMETypeRegistry.h" #include "MouseEvent.h" @@ -50,7 +49,6 @@ #include "PluginMessageThrottlerWin.h" #endif #include "PluginPackage.h" -#include "JSDOMBinding.h" #include "ScriptController.h" #include "ScriptValue.h" #include "PluginDatabase.h" @@ -59,20 +57,28 @@ #include "PluginPackage.h" #include "RenderBox.h" #include "RenderObject.h" -#include "c_instance.h" #include "npruntime_impl.h" -#include "runtime_root.h" #include "Settings.h" + +#if USE(JSC) +#include "JSDOMWindow.h" +#include "JSDOMBinding.h" +#include "c_instance.h" +#include "runtime_root.h" #include "runtime.h" #include <runtime/JSLock.h> #include <runtime/JSValue.h> +#endif + #include <wtf/ASCIICType.h> +#if USE(JSC) using JSC::ExecState; using JSC::JSLock; using JSC::JSObject; using JSC::JSValuePtr; using JSC::UString; +#endif using std::min; @@ -169,7 +175,9 @@ bool PluginView::start() NPError npErr; { PluginView::setCurrentPluginView(this); +#if USE(JSC) JSC::JSLock::DropAllLocks dropAllLocks(false); +#endif setCallingPlugin(true); npErr = m_plugin->pluginFuncs()->newp((NPMIMEType)m_mimeType.data(), m_instance, m_mode, m_paramCount, m_paramNames, m_paramValues, NULL); setCallingPlugin(false); @@ -212,6 +220,7 @@ static char* createUTF8String(const String& str) return result; } +#if USE(JSC) static bool getString(ScriptController* proxy, JSValuePtr result, String& string) { if (!proxy || !result || result.isUndefined()) @@ -225,6 +234,7 @@ static bool getString(ScriptController* proxy, JSValuePtr result, String& string string = ustring; return true; } +#endif void PluginView::performRequest(PluginRequest* request) { @@ -251,7 +261,9 @@ void PluginView::performRequest(PluginRequest* request) // FIXME: <rdar://problem/4807469> This should be sent when the document has finished loading if (request->sendNotification()) { PluginView::setCurrentPluginView(this); +#if USE(JSC) JSC::JSLock::DropAllLocks dropAllLocks(false); +#endif setCallingPlugin(true); m_plugin->pluginFuncs()->urlnotify(m_instance, requestURL.string().utf8().data(), NPRES_DONE, request->notifyData()); setCallingPlugin(false); @@ -264,7 +276,8 @@ void PluginView::performRequest(PluginRequest* request) // Targeted JavaScript requests are only allowed on the frame that contains the JavaScript plugin // and this has been made sure in ::load. ASSERT(targetFrameName.isEmpty() || m_parentFrame->tree()->find(targetFrameName) == m_parentFrame); - + +#if USE(JSC) // Executing a script can cause the plugin view to be destroyed, so we keep a reference to the parent frame. RefPtr<Frame> parentFrame = m_parentFrame; JSValuePtr result = m_parentFrame->loader()->executeScript(jsString, request->shouldAllowPopups()).jsValue(); @@ -280,6 +293,7 @@ void PluginView::performRequest(PluginRequest* request) m_streams.add(stream); stream->sendJavaScriptStream(requestURL, cstr); } +#endif } void PluginView::requestTimerFired(Timer<PluginView>* timer) @@ -484,6 +498,8 @@ void PluginView::setJavaScriptPaused(bool paused) m_requestTimer.startOneShot(0); } + +#if USE(JSC) PassRefPtr<JSC::Bindings::Instance> PluginView::bindingInstance() { #if ENABLE(NETSCAPE_PLUGIN_API) @@ -513,8 +529,9 @@ PassRefPtr<JSC::Bindings::Instance> PluginView::bindingInstance() return instance.release(); #else return 0; -#endif +#endif // NETSCAPE_PLUGIN_API } +#endif // JSC void PluginView::disconnectStream(PluginStream* stream) { diff --git a/WebCore/plugins/PluginView.h b/WebCore/plugins/PluginView.h index e895165..3821df6 100644 --- a/WebCore/plugins/PluginView.h +++ b/WebCore/plugins/PluginView.h @@ -58,11 +58,13 @@ typedef struct PluginWidgetAndroid* PlatformPluginWidget; typedef PlatformWidget PlatformPluginWidget; #endif +#if USE(JSC) namespace JSC { namespace Bindings { class Instance; } } +#endif namespace WebCore { class Element; @@ -124,7 +126,9 @@ namespace WebCore { void setNPWindowRect(const IntRect&); static PluginView* currentPluginView(); +#if USE(JSC) PassRefPtr<JSC::Bindings::Instance> bindingInstance(); +#endif PluginStatus status() const { return m_status; } diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp index 09117ae..084765b 100644 --- a/WebCore/plugins/android/PluginViewAndroid.cpp +++ b/WebCore/plugins/android/PluginViewAndroid.cpp @@ -50,19 +50,20 @@ #include "PlatformKeyboardEvent.h" #include "PluginMainThreadScheduler.h" #include "PluginPackage.h" -// #include "kjs_binding.h" -// #include "kjs_proxy.h" #include "android_graphics.h" #include "SkCanvas.h" #include "npruntime_impl.h" -#include "runtime_root.h" +// #include "runtime_root.h" #include "utils/SystemClock.h" #include "ScriptController.h" #include "Settings.h" + +#if USE(JSC) #include <runtime/JSLock.h> -// #include <kjs/value.h> +#endif + #include <wtf/ASCIICType.h> -#include "runtime.h" +// #include "runtime.h" #include "WebViewCore.h" #include "PluginDebug.h" @@ -131,12 +132,6 @@ static bool anp_getInterface(NPNVariable var, void* value, NPError* error) { /////////////////////////////////////////////////////////////////////////////// -using JSC::ExecState; -using JSC::Interpreter; -using JSC::JSLock; -using JSC::JSObject; -using JSC::UString; - using std::min; using namespace WTF; @@ -330,7 +325,9 @@ void PluginView::setNPWindowRect(const IntRect& rect) m_npWindow.clipRect.bottom = height; if (m_plugin->pluginFuncs()->setwindow) { +#if USE(JSC) JSC::JSLock::DropAllLocks dropAllLocks(false); +#endif setCallingPlugin(true); m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); setCallingPlugin(false); @@ -355,8 +352,9 @@ void PluginView::stop() ASSERT(m_streams.isEmpty()); m_isStarted = false; - +#if USE(JSC) JSC::JSLock::DropAllLocks dropAllLocks(false); +#endif PluginMainThreadScheduler::scheduler().unregisterPlugin(m_instance); diff --git a/WebKit/android/TimeCounter.cpp b/WebKit/android/TimeCounter.cpp index 96fb180..f78d46f 100644 --- a/WebKit/android/TimeCounter.cpp +++ b/WebKit/android/TimeCounter.cpp @@ -31,17 +31,18 @@ #include "CString.h" #include "Cache.h" #include "KURL.h" -#include "GCController.h" -#include "JSDOMWindow.h" #include "Node.h" -#include "Nodes.h" #include "SystemTime.h" #include "StyleBase.h" + +#if USE(JSC) +#include "JSDOMWindow.h" #include <runtime/JSGlobalObject.h> #include <runtime/JSLock.h> +#endif + #include <utils/Log.h> -using namespace JSC; using namespace WebCore; using namespace WTF; @@ -112,11 +113,13 @@ void TimeCounter::report(const KURL& url, int live, int dead, size_t arenaSize) } LOGD("Current cache has %d bytes live and %d bytes dead", live, dead); LOGD("Current render arena takes %d bytes", arenaSize); +#if USE(JSC) JSLock lock(false); Heap::Statistics jsHeapStatistics = JSDOMWindow::commonJSGlobalData()->heap.statistics(); LOGD("Current JavaScript heap size is %d and has %d bytes free", jsHeapStatistics.size, jsHeapStatistics.free); LOGD("Current JavaScript nodes use %d bytes", JSC::Node::reportJavaScriptNodesSize()); +#endif LOGD("Current CSS styles use %d bytes", StyleBase::reportStyleSize()); LOGD("Current DOM nodes use %d bytes", WebCore::Node::reportDOMNodesSize()); } diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 91103fb..5322f5d 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -46,7 +46,6 @@ #include "FrameLoaderClientAndroid.h" #include "FrameTree.h" #include "FrameView.h" -#include "GCController.h" #include "GraphicsContext.h" #include "HistoryItem.h" #include "HTMLElement.h" @@ -56,9 +55,14 @@ #include "IconDatabase.h" #include "Image.h" #include "InspectorClientAndroid.h" + +#if USE(JSC) +#include "GCController.h" #include "JSDOMWindow.h" #include <runtime/InitializeThreading.h> #include <runtime/JSLock.h> +#endif // USE(JSC) + #include "KURL.h" #include "Page.h" #include "PageCache.h" @@ -82,11 +86,17 @@ #include "WebViewCore.h" #include "wds/DebugServer.h" +#if USE(JSC) #include <runtime_root.h> #include <runtime_object.h> +#endif // USE(JSC) + #include <jni_utility.h> #include "jni.h" + +#if USE(JSC) #include "jni_instance.h" +#endif // USE(JSC) #include <JNIHelp.h> #include <SkGraphics.h> @@ -97,12 +107,8 @@ #ifdef ANDROID_INSTRUMENT #include "TimeCounter.h" -#include <runtime/JSLock.h> #endif -using namespace JSC; -using namespace JSC::Bindings; - namespace android { // ---------------------------------------------------------------------------- @@ -681,7 +687,9 @@ static void CallPolicyFunction(JNIEnv* env, jobject obj, jint func, jint decisio static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAssetManager, jobject historyList) { +#if USE(JSC) JSC::initializeThreading(); +#endif #ifdef ANDROID_INSTRUMENT TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter); #endif @@ -927,21 +935,22 @@ static jobject StringByEvaluatingJavaScriptFromString(JNIEnv *env, jobject obj, return env->NewString((unsigned short*)result.characters(), len); } +#if USE(JSC) // Wrap the JavaInstance used when binding custom javascript interfaces. Use a // weak reference so that the gc can collect the WebView. Override virtualBegin // and virtualEnd and swap the weak reference for the real object. -class WeakJavaInstance : public JavaInstance { +class WeakJavaInstance : public JSC::Bindings::JavaInstance { public: static PassRefPtr<WeakJavaInstance> create(jobject obj, - PassRefPtr<RootObject> root) { + PassRefPtr<JSC::Bindings::RootObject> root) { return adoptRef(new WeakJavaInstance(obj, root)); } protected: - WeakJavaInstance(jobject instance, PassRefPtr<RootObject> rootObject) - : JavaInstance(instance, rootObject) + WeakJavaInstance(jobject instance, PassRefPtr<JSC::Bindings::RootObject> rootObject) + : JSC::Bindings::JavaInstance(instance, rootObject) { - JNIEnv* env = getJNIEnv(); + JNIEnv* env = JSC::Bindings::getJNIEnv(); // JavaInstance creates a global ref to instance in its constructor. env->DeleteGlobalRef(_instance->_instance); // Set the object to our WeakReference wrapper. @@ -950,7 +959,7 @@ protected: virtual void virtualBegin() { _weakRef = _instance->_instance; - JNIEnv* env = getJNIEnv(); + JNIEnv* env = JSC::Bindings::getJNIEnv(); // This is odd. getRealObject returns an AutoJObject which is used to // cleanly create and delete a local reference. But, here we need to // maintain the local reference across calls to virtualBegin() and @@ -967,16 +976,17 @@ protected: // Call the base class method first to pop the local frame. INHERITED::virtualEnd(); // Get rid of the local reference to the real object. - getJNIEnv()->DeleteLocalRef(_realObject); + JSC::Bindings::getJNIEnv()->DeleteLocalRef(_realObject); // Point back to the WeakReference. _instance->_instance = _weakRef; } private: - typedef JavaInstance INHERITED; + typedef JSC::Bindings::JavaInstance INHERITED; jobject _realObject; jobject _weakRef; }; +#endif // USE(JSC) static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePointer, jobject javascriptObj, jstring interfaceName) @@ -991,6 +1001,7 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi env->GetJavaVM(&vm); LOGV("::WebCore:: addJSInterface: %p", pFrame); +#if USE(JSC) // Copied from qwebframe.cpp JSC::JSLock lock(false); WebCore::JSDOMWindow *window = WebCore::toJSDOMWindow(pFrame); @@ -1011,6 +1022,7 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi checkException(env); } } +#endif // USE(JSC) } static void SetCacheDisabled(JNIEnv *env, jobject obj, jboolean disabled) @@ -1033,22 +1045,25 @@ static void ClearCache(JNIEnv *env, jobject obj) { #ifdef ANDROID_INSTRUMENT TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter); - +#if USE(JSC) JSC::JSLock lock(false); JSC::Heap::Statistics jsHeapStatistics = WebCore::JSDOMWindow::commonJSGlobalData()->heap.statistics(); LOGD("About to gc and JavaScript heap size is %d and has %d bytes free", jsHeapStatistics.size, jsHeapStatistics.free); +#endif // USE(JSC) LOGD("About to clear cache and current cache has %d bytes live and %d bytes dead", cache()->getLiveSize(), cache()->getDeadSize()); -#endif +#endif // ANDROID_INSTRUMENT if (!WebCore::cache()->disabled()) { // Disabling the cache will remove all resources from the cache. They may // still live on if they are referenced by some Web page though. WebCore::cache()->setDisabled(true); WebCore::cache()->setDisabled(false); } +#if USE(JSC) // force JavaScript to GC when clear cache WebCore::gcController().garbageCollectSoon(); +#endif // USE(JSC) // clear image cache SkImageRef_GlobalPool::SetRAMUsed(0); } |