summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-11 12:11:56 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-11 12:11:56 -0700
commite67bd8de533debe80a307056f0f62065d6fd5041 (patch)
tree54f2ebb40b0005ec0d6bd3976cc1e8fb47cae5ff
parentba96c5ad9d140287cc378faec6bd9384836a00e6 (diff)
downloadexternal_webkit-e67bd8de533debe80a307056f0f62065d6fd5041.zip
external_webkit-e67bd8de533debe80a307056f0f62065d6fd5041.tar.gz
external_webkit-e67bd8de533debe80a307056f0f62065d6fd5041.tar.bz2
auto import from //branches/cupcake/...@137873
-rw-r--r--WebCore/bridge/jni/jni_instance.h11
-rw-r--r--WebCore/rendering/bidi.cpp20
-rw-r--r--WebKit/android/jni/WebCoreFrameBridge.cpp56
-rw-r--r--WebKit/android/jni/WebViewCore.cpp23
-rw-r--r--WebKit/android/jni/WebViewCore.h3
5 files changed, 82 insertions, 31 deletions
diff --git a/WebCore/bridge/jni/jni_instance.h b/WebCore/bridge/jni/jni_instance.h
index c2e0d9d..551b8e7 100644
--- a/WebCore/bridge/jni/jni_instance.h
+++ b/WebCore/bridge/jni/jni_instance.h
@@ -33,6 +33,12 @@
#include <JavaVM/jni.h>
+#if PLATFORM(ANDROID)
+namespace android {
+class WeakJavaInstance;
+}
+#endif
+
namespace JSC {
namespace Bindings {
@@ -46,6 +52,9 @@ friend class JavaArray;
friend class JavaField;
friend class JavaInstance;
friend class JavaMethod;
+#if PLATFORM(ANDROID)
+friend class android::WeakJavaInstance;
+#endif
protected:
JObjectWrapper(jobject instance);
@@ -92,7 +101,9 @@ protected:
virtual void virtualBegin();
virtual void virtualEnd();
+#if !PLATFORM(ANDROID) // Submit patch to webkit.org
private:
+#endif
JavaInstance(jobject instance, PassRefPtr<RootObject>);
RefPtr<JObjectWrapper> _instance;
diff --git a/WebCore/rendering/bidi.cpp b/WebCore/rendering/bidi.cpp
index 2f05e7f..212bf3c 100644
--- a/WebCore/rendering/bidi.cpp
+++ b/WebCore/rendering/bidi.cpp
@@ -859,19 +859,23 @@ void RenderBlock::layoutInlineChildren(bool relayoutChildren, int& repaintTop, i
#ifdef ANDROID_LAYOUT
if (doTextWrap && !hasTextToWrap && o->isText()) {
Node* node = o->element();
- // as it is very common for sites to use a serial of <a> as
- // tabs, we don't force text to wrap if all the text are
- // short and within an <a> tag, or only separated by short
- // word like "|" or ";".
+ // as it is very common for sites to use a serial of <a> or
+ // <li> as tabs, we don't force text to wrap if all the text
+ // are short and within an <a> or <li> tag, and only separated
+ // by short word like "|" or ";".
if (node && node->isTextNode() &&
!static_cast<Text*>(node)->containsOnlyWhitespace()) {
int length = static_cast<Text*>(node)->length();
- if (length > 20 || (length >3 &&
- !node->parent()->hasTagName(HTMLNames::aTag)))
- hasTextToWrap = true;
+ // FIXME, need a magic number to decide it is too long to
+ // be a tab. Pick 25 for now as it covers around 160px
+ // (half of 320px) with the default font.
+ if (length > 25 || (length > 3 &&
+ (!node->parent()->hasTagName(HTMLNames::aTag) &&
+ !node->parent()->hasTagName(HTMLNames::liTag))))
+ hasTextToWrap = true;
}
}
-#endif
+#endif
}
o = bidiNext(this, o, 0, false, &endOfInline);
}
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp
index 5ec70c6..ccca088 100644
--- a/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -100,6 +100,9 @@
#include <runtime/JSLock.h>
#endif
+using namespace JSC;
+using namespace JSC::Bindings;
+
namespace android {
// ----------------------------------------------------------------------------
@@ -924,6 +927,57 @@ static jobject StringByEvaluatingJavaScriptFromString(JNIEnv *env, jobject obj,
return env->NewString((unsigned short*)result.characters(), len);
}
+// 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 {
+public:
+ static PassRefPtr<WeakJavaInstance> create(jobject obj,
+ PassRefPtr<RootObject> root) {
+ return adoptRef(new WeakJavaInstance(obj, root));
+ }
+
+protected:
+ WeakJavaInstance(jobject instance, PassRefPtr<RootObject> rootObject)
+ : JavaInstance(instance, rootObject)
+ {
+ JNIEnv* env = getJNIEnv();
+ // JavaInstance creates a global ref to instance in its constructor.
+ env->DeleteGlobalRef(_instance->_instance);
+ // Set the object to our WeakReference wrapper.
+ _instance->_instance = adoptGlobalRef(env, instance);
+ }
+
+ virtual void virtualBegin() {
+ _weakRef = _instance->_instance;
+ JNIEnv* env = 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 strong() and weak().
+ // So, create a new local reference to the real object here and delete
+ // it in weak().
+ _realObject = env->NewLocalRef(getRealObject(env, _weakRef).get());
+ // Point to the real object
+ _instance->_instance = _realObject;
+ // Call the base class method
+ INHERITED::virtualBegin();
+ }
+
+ virtual void virtualEnd() {
+ // Get rid of the local reference to the real object
+ getJNIEnv()->DeleteLocalRef(_realObject);
+ // Point back to the WeakReference.
+ _instance->_instance = _weakRef;
+ // Call the base class method
+ INHERITED::virtualEnd();
+ }
+
+private:
+ typedef JavaInstance INHERITED;
+ jobject _realObject;
+ jobject _weakRef;
+};
+
static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePointer,
jobject javascriptObj, jstring interfaceName)
{
@@ -945,7 +999,7 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi
JSC::Bindings::setJavaVM(vm);
// Add the binding to JS environment
JSC::ExecState* exec = window->globalExec();
- JSC::JSObject *addedObject = JSC::Bindings::JavaInstance::create(javascriptObj,
+ JSC::JSObject *addedObject = WeakJavaInstance::create(javascriptObj,
root)->createRuntimeObject(exec);
const jchar* s = env->GetStringChars(interfaceName, NULL);
if (s) {
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 0da3974..a84a67f 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -385,21 +385,15 @@ void WebViewCore::recordPictureSet(PictureSet* content)
// and check to see if any already split pieces need to be redrawn.
if (content->build())
rebuildPictureSet(content);
- m_frameCacheOutOfDate = true;
-}
-
-void WebViewCore::checkNavCache()
-{
- CacheBuilder& builder = FrameLoaderClientAndroid::get(m_mainFrame)
- ->getCacheBuilder();
+ CacheBuilder& builder = FrameLoaderClientAndroid::get(m_mainFrame)->getCacheBuilder();
WebCore::Node* oldFocusNode = builder.currentFocus();
+ m_frameCacheOutOfDate = true;
WebCore::IntRect oldBounds = oldFocusNode ?
oldFocusNode->getRect() : WebCore::IntRect(0,0,0,0);
DBG_NAV_LOGD("m_lastFocused=%p oldFocusNode=%p"
" m_lastFocusedBounds={%d,%d,%d,%d} oldBounds={%d,%d,%d,%d}",
m_lastFocused, oldFocusNode,
- m_lastFocusedBounds.x(), m_lastFocusedBounds.y(),
- m_lastFocusedBounds.width(), m_lastFocusedBounds.height(),
+ m_lastFocusedBounds.x(), m_lastFocusedBounds.y(), m_lastFocusedBounds.width(), m_lastFocusedBounds.height(),
oldBounds.x(), oldBounds.y(), oldBounds.width(), oldBounds.height());
unsigned latestVersion = 0;
// as domTreeVersion only increment, we can just check the sum to see whether
@@ -2420,15 +2414,6 @@ static void RegisterURLSchemeAsLocal(JNIEnv* env, jobject obj, jstring scheme) {
WebCore::FrameLoader::registerURLSchemeAsLocal(to_string(env, scheme));
}
-static void CheckNavCache(JNIEnv *env, jobject obj)
-{
-#ifdef ANDROID_INSTRUMENT
- TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter);
-#endif
- WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
- viewImpl->checkNavCache();
-}
-
static void ClearContent(JNIEnv *env, jobject obj)
{
#ifdef ANDROID_INSTRUMENT
@@ -2464,8 +2449,6 @@ static bool DrawContent(JNIEnv *env, jobject obj, jobject canv, jint color)
* JNI registration.
*/
static JNINativeMethod gJavaWebViewCoreMethods[] = {
- { "nativeCheckNavCache", "()V",
- (void*) CheckNavCache },
{ "nativeClearContent", "()V",
(void*) ClearContent },
{ "nativeCopyContentToPicture", "(Landroid/graphics/Picture;)V",
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index 3743206..d9549de 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -182,8 +182,7 @@ namespace android {
// Create a single picture to represent the drawn DOM (used by navcache)
void recordPicture(SkPicture* picture);
- // Rebuild the nav cache if the dom changed
- void checkNavCache();
+
// Create a set of pictures to represent the drawn DOM, driven by
// the invalidated region and the time required to draw (used to draw)
void recordPictureSet(PictureSet* master);