summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Popescu <andreip@google.com>2010-01-13 18:43:00 +0000
committerAndrei Popescu <andreip@google.com>2010-01-25 11:52:07 +0000
commitdcb9f821994a3c585bc51d6f1a6a356a6034de5b (patch)
treef5399e101de0bee8dacf8c808d70b10aae9c3982
parentb621c75b275a6b7ac0fd99772749aaadb3548815 (diff)
downloadexternal_webkit-dcb9f821994a3c585bc51d6f1a6a356a6034de5b.zip
external_webkit-dcb9f821994a3c585bc51d6f1a6a356a6034de5b.tar.gz
external_webkit-dcb9f821994a3c585bc51d6f1a6a356a6034de5b.tar.bz2
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
-rw-r--r--WebCore/bindings/v8/NPV8Object.cpp23
-rw-r--r--WebCore/bindings/v8/NPV8Object.h7
-rw-r--r--WebCore/platform/android/PlatformBridge.h49
-rw-r--r--WebKit/android/WebCoreSupport/PlatformBridge.cpp5
4 files changed, 61 insertions, 23 deletions
diff --git a/WebCore/bindings/v8/NPV8Object.cpp b/WebCore/bindings/v8/NPV8Object.cpp
index 69cd303..e222ecd 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<v8::Value> enumeratorObj = script->Run();
v8::Handle<v8::Function> enumerator = v8::Handle<v8::Function>::Cast(enumeratorObj);
v8::Handle<v8::Value> argv[] = { obj };
-#if PLATFORM(ANDROID)
-// TODO(benm): implement an arry size function on android
- v8::Local<v8::Value> propsObj = enumerator->Call(v8::Handle<v8::Object>::Cast(enumeratorObj), 1, argv);
-#else
v8::Local<v8::Value> propsObj = enumerator->Call(v8::Handle<v8::Object>::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 1b65a1f..62b3ba4 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 <v8.h>
diff --git a/WebCore/platform/android/PlatformBridge.h b/WebCore/platform/android/PlatformBridge.h
index 8b08490..cf9f561 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 <wtf/Vector.h>
+// 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<size_t>(!(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 995999b..9f620e7 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