From dcb9f821994a3c585bc51d6f1a6a356a6034de5b Mon Sep 17 00:00:00 2001 From: Andrei Popescu Date: Wed, 13 Jan 2010 18:43:00 +0000 Subject: [PATCH] Prepare NPV8Object.h/cpp for upstreaming: - remove #include bindings/npruntime.h from NPV8Object.cpp since that's also included in the NPV8Object.h - add ARRAYSIZE_UNSAFE macro - remove some TODOS This will be checked in after the corresponding webkit bug gets landed. See https://bugs.webkit.org/show_bug.cgi?id=33608 --- WebCore/bindings/v8/NPV8Object.cpp | 23 +---------- WebCore/bindings/v8/NPV8Object.h | 7 +++- WebCore/platform/android/PlatformBridge.h | 49 ++++++++++++++++++++++++ WebKit/android/WebCoreSupport/PlatformBridge.cpp | 5 +++ 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/WebCore/bindings/v8/NPV8Object.cpp b/WebCore/bindings/v8/NPV8Object.cpp index 69cd303a3..e222ecd4f 100644 --- a/WebCore/bindings/v8/NPV8Object.cpp +++ b/WebCore/bindings/v8/NPV8Object.cpp @@ -28,10 +28,7 @@ #include "NPV8Object.h" -#if PLATFORM(CHROMIUM) -// TODO(andreip): upstream -#include "ChromiumBridge.h" -#endif +#include "PlatformBridge.h" #include "DOMWindow.h" #include "Frame.h" #include "OwnArrayPtr.h" @@ -42,11 +39,6 @@ #include "V8Helpers.h" #include "V8NPUtils.h" #include "V8Proxy.h" -#if PLATFORM(CHROMIUM) -#include "bindings/npruntime.h" -#else -#include "bridge/npruntime.h" -#endif #include "npruntime_impl.h" #include "npruntime_priv.h" @@ -242,13 +234,7 @@ bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments, bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* result) { -#if PLATFORM(CHROMIUM) - bool popupsAllowed = WebCore::ChromiumBridge::popupsAllowed(npp); -#else - // TODO(andreip): Some of the binding code is specific to Chromium - // and we don't want it to Android. What is the preferred way to handle this? - bool popupsAllowed = false; -#endif + bool popupsAllowed = WebCore::PlatformBridge::popupsAllowed(npp); return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); } @@ -461,12 +447,7 @@ bool _NPN_Enumerate(NPP npp, NPObject* npObject, NPIdentifier** identifier, uint v8::Handle enumeratorObj = script->Run(); v8::Handle enumerator = v8::Handle::Cast(enumeratorObj); v8::Handle argv[] = { obj }; -#if PLATFORM(ANDROID) -// TODO(benm): implement an arry size function on android - v8::Local propsObj = enumerator->Call(v8::Handle::Cast(enumeratorObj), 1, argv); -#else v8::Local propsObj = enumerator->Call(v8::Handle::Cast(enumeratorObj), ARRAYSIZE_UNSAFE(argv), argv); -#endif if (propsObj.IsEmpty()) return false; diff --git a/WebCore/bindings/v8/NPV8Object.h b/WebCore/bindings/v8/NPV8Object.h index 1b65a1f81..62b3ba431 100644 --- a/WebCore/bindings/v8/NPV8Object.h +++ b/WebCore/bindings/v8/NPV8Object.h @@ -31,10 +31,13 @@ #define NPV8Object_h #if PLATFORM(CHROMIUM) -// TODO(andreip): diff and consolidate +// FIXME: Chromium uses a different npruntime.h, which is in +// the Chromium source repository under third_party/npapi/bindings. +// The Google-specific changes in that file should probably be +// moved into bridge/npruntime.h, guarded by an #if PlATFORM(CHROMIUM). #include "bindings/npruntime.h" #else -#include "bridge/npruntime.h" // use WebCore version +#include "bridge/npruntime.h" // Use WebCore version for Android and other ports. #endif #include diff --git a/WebCore/platform/android/PlatformBridge.h b/WebCore/platform/android/PlatformBridge.h index 8b0849095..cf9f561ad 100644 --- a/WebCore/platform/android/PlatformBridge.h +++ b/WebCore/platform/android/PlatformBridge.h @@ -27,10 +27,56 @@ #define PlatformBridge_h #include "KURL.h" +#include "npapi.h" #include "PlatformString.h" #include +// V8 bindings use the ARRAYSIZE_UNSAFE macro. This macro was copied +// from http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h +// +// ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, +// but can be used on anonymous types or types defined inside +// functions. It's less safe than arraysize as it accepts some +// (although not all) pointers. Therefore, you should use arraysize +// whenever possible. +// +// The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type +// size_t. +// +// ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error +// +// "warning: division by zero in ..." +// +// when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer. +// You should only use ARRAYSIZE_UNSAFE on statically allocated arrays. +// +// The following comments are on the implementation details, and can +// be ignored by the users. +// +// ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in +// the array) and sizeof(*(arr)) (the # of bytes in one array +// element). If the former is divisible by the latter, perhaps arr is +// indeed an array, in which case the division result is the # of +// elements in the array. Otherwise, arr cannot possibly be an array, +// and we generate a compiler error to prevent the code from +// compiling. +// +// Since the size of bool is implementation-defined, we need to cast +// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final +// result has type size_t. +// +// This macro is not perfect as it wrongfully accepts certain +// pointers, namely where the pointer size is divisible by the pointee +// size. Since all our code has to go through a 32-bit compiler, +// where a pointer is 4 bytes, this means all pointers to a type whose +// size is 3 or greater than 4 will be (righteously) rejected. + +#define ARRAYSIZE_UNSAFE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + static_cast(!(sizeof(a) % sizeof(*(a))))) + + class NPObject; namespace WebCore { @@ -59,6 +105,9 @@ public: static bool cookiesEnabled(); // Plugin static NPObject* pluginScriptableObject(Widget*); + // Popups + static bool popupsAllowed(NPP); + // These ids need to be in sync with the constants in BrowserFrame.java enum rawResId { NoDomain = 1, diff --git a/WebKit/android/WebCoreSupport/PlatformBridge.cpp b/WebKit/android/WebCoreSupport/PlatformBridge.cpp index 995999bc6..9f620e7af 100644 --- a/WebKit/android/WebCoreSupport/PlatformBridge.cpp +++ b/WebKit/android/WebCoreSupport/PlatformBridge.cpp @@ -114,6 +114,11 @@ bool PlatformBridge::isWebViewPaused() return WebViewCore::isPaused(); } +bool PlatformBridge::popupsAllowed(NPP) +{ + return false; +} + } // namespace WebCore -- 2.11.0