summaryrefslogtreecommitdiffstats
path: root/core/java/android/webkit
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:51:23 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:51:23 -0800
commitb798689749c64baba81f02e10cf2157c747d6b46 (patch)
treeda394a395ddb1a6cf69193314846b03fe47a397e /core/java/android/webkit
parentf013e1afd1e68af5e3b868c26a653bbfb39538f8 (diff)
downloadframeworks_base-b798689749c64baba81f02e10cf2157c747d6b46.zip
frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.tar.gz
frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.tar.bz2
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'core/java/android/webkit')
-rw-r--r--core/java/android/webkit/CookieManager.java85
-rw-r--r--core/java/android/webkit/TextDialog.java59
-rw-r--r--core/java/android/webkit/WebView.java81
-rw-r--r--core/java/android/webkit/WebViewCore.java79
4 files changed, 128 insertions, 176 deletions
diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java
index 00b17d2..5a37f04 100644
--- a/core/java/android/webkit/CookieManager.java
+++ b/core/java/android/webkit/CookieManager.java
@@ -172,7 +172,7 @@ public final class CookieManager {
if (urlPath.startsWith(path)) {
int len = path.length();
int urlLen = urlPath.length();
- if (urlLen > len) {
+ if (path.charAt(len-1) != PATH_DELIM && urlLen > len) {
// make sure /wee doesn't match /we
return urlPath.charAt(len) == PATH_DELIM;
}
@@ -440,29 +440,43 @@ public final class CookieManager {
/**
* Remove all session cookies, which are cookies without expiration date
*/
- public synchronized void removeSessionCookie() {
- Collection<ArrayList<Cookie>> cookieList = mCookieMap.values();
- Iterator<ArrayList<Cookie>> listIter = cookieList.iterator();
- while (listIter.hasNext()) {
- ArrayList<Cookie> list = listIter.next();
- Iterator<Cookie> iter = list.iterator();
- while (iter.hasNext()) {
- Cookie cookie = iter.next();
- if (cookie.expires == -1) {
- iter.remove();
+ public void removeSessionCookie() {
+ final Runnable clearCache = new Runnable() {
+ public void run() {
+ synchronized(CookieManager.this) {
+ Collection<ArrayList<Cookie>> cookieList = mCookieMap.values();
+ Iterator<ArrayList<Cookie>> listIter = cookieList.iterator();
+ while (listIter.hasNext()) {
+ ArrayList<Cookie> list = listIter.next();
+ Iterator<Cookie> iter = list.iterator();
+ while (iter.hasNext()) {
+ Cookie cookie = iter.next();
+ if (cookie.expires == -1) {
+ iter.remove();
+ }
+ }
+ }
+ CookieSyncManager.getInstance().clearSessionCookies();
}
}
- }
- CookieSyncManager.getInstance().clearSessionCookies();
+ };
+ new Thread(clearCache).start();
}
/**
* Remove all cookies
*/
- public synchronized void removeAllCookie() {
- mCookieMap = new LinkedHashMap<String, ArrayList<Cookie>>(
- MAX_DOMAIN_COUNT, 0.75f, true);
- CookieSyncManager.getInstance().clearAllCookies();
+ public void removeAllCookie() {
+ final Runnable clearCache = new Runnable() {
+ public void run() {
+ synchronized(CookieManager.this) {
+ mCookieMap = new LinkedHashMap<String, ArrayList<Cookie>>(
+ MAX_DOMAIN_COUNT, 0.75f, true);
+ CookieSyncManager.getInstance().clearAllCookies();
+ }
+ }
+ };
+ new Thread(clearCache).start();
}
/**
@@ -475,23 +489,30 @@ public final class CookieManager {
/**
* Remove all expired cookies
*/
- public synchronized void removeExpiredCookie() {
- long now = System.currentTimeMillis();
- Collection<ArrayList<Cookie>> cookieList = mCookieMap.values();
- Iterator<ArrayList<Cookie>> listIter = cookieList.iterator();
- while (listIter.hasNext()) {
- ArrayList<Cookie> list = listIter.next();
- Iterator<Cookie> iter = list.iterator();
- while (iter.hasNext()) {
- Cookie cookie = iter.next();
- // expires == -1 means no expires defined. Otherwise negative
- // means far future
- if (cookie.expires > 0 && cookie.expires < now) {
- iter.remove();
+ public void removeExpiredCookie() {
+ final Runnable clearCache = new Runnable() {
+ public void run() {
+ synchronized(CookieManager.this) {
+ long now = System.currentTimeMillis();
+ Collection<ArrayList<Cookie>> cookieList = mCookieMap.values();
+ Iterator<ArrayList<Cookie>> listIter = cookieList.iterator();
+ while (listIter.hasNext()) {
+ ArrayList<Cookie> list = listIter.next();
+ Iterator<Cookie> iter = list.iterator();
+ while (iter.hasNext()) {
+ Cookie cookie = iter.next();
+ // expires == -1 means no expires defined. Otherwise
+ // negative means far future
+ if (cookie.expires > 0 && cookie.expires < now) {
+ iter.remove();
+ }
+ }
+ }
+ CookieSyncManager.getInstance().clearExpiredCookies(now);
}
}
- }
- CookieSyncManager.getInstance().clearExpiredCookies(now);
+ };
+ new Thread(clearCache).start();
}
/**
diff --git a/core/java/android/webkit/TextDialog.java b/core/java/android/webkit/TextDialog.java
index 4e9370c..30b519a 100644
--- a/core/java/android/webkit/TextDialog.java
+++ b/core/java/android/webkit/TextDialog.java
@@ -37,6 +37,7 @@ import android.text.method.MetaKeyKeyListener;
import android.text.method.MovementMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.method.TextKeyListener;
+import android.view.inputmethod.EditorInfo;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -265,13 +266,20 @@ import android.widget.AutoCompleteTextView;
if (mGotEnterDown && !down) {
return true;
}
- // WebView check the trackballtime in onKeyDown to avoid calling native
- // from both trackball and key handling. As this is called from
- // TextDialog, we always want WebView to check with native. Reset
- // trackballtime to ensure it.
- mWebView.resetTrackballTime();
- return down ? mWebView.onKeyDown(keyCode, event) :
- mWebView.onKeyUp(keyCode, event);
+ // if it is a navigation key, pass it to WebView
+ if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT
+ || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
+ || keyCode == KeyEvent.KEYCODE_DPAD_UP
+ || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
+ // WebView check the trackballtime in onKeyDown to avoid calling
+ // native from both trackball and key handling. As this is called
+ // from TextDialog, we always want WebView to check with native.
+ // Reset trackballtime to ensure it.
+ mWebView.resetTrackballTime();
+ return down ? mWebView.onKeyDown(keyCode, event) : mWebView
+ .onKeyUp(keyCode, event);
+ }
+ return false;
}
/**
@@ -315,31 +323,30 @@ import android.widget.AutoCompleteTextView;
updateCachedTextfield();
return;
}
- // In this case, replace before with all but the last character of the
- // new text.
- if (count > 1) {
- String replace = s.subSequence(start, start + count - 1).toString();
+ // Find the last character being replaced. If it can be represented by
+ // events, we will pass them to native (after replacing the beginning
+ // of the changed text), so we can see javascript events.
+ // Otherwise, replace the text being changed (including the last
+ // character) in the textfield.
+ TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
+ KeyCharacterMap kmap =
+ KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+ KeyEvent[] events = kmap.getEvents(mCharacter);
+ boolean cannotUseKeyEvents = null == events;
+ int charactersFromKeyEvents = cannotUseKeyEvents ? 0 : 1;
+ if (count > 1 || cannotUseKeyEvents) {
+ String replace = s.subSequence(start,
+ start + count - charactersFromKeyEvents).toString();
mWebView.replaceTextfieldText(start, start + before, replace,
- start + count - 1, start + count - 1);
+ start + count - charactersFromKeyEvents,
+ start + count - charactersFromKeyEvents);
} else {
// This corrects the selection which may have been affected by the
// trackball or auto-correct.
mWebView.setSelection(start, start + before);
}
- // Whether the text to be added is only one character, or we already
- // added all but the last character, we now figure out the DOM events
- // for the last character, and pass them down.
- TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
- // We only care about the events that translate directly into
- // characters. Should we be using KeyCharacterMap.BUILT_IN_KEYBOARD?
- // The comment makes it sound like it may not be directly related to
- // the keys. However, KeyCharacterMap.ALPHA says it has "maybe some
- // numbers." Not sure if that will have the numbers we may need.
- KeyCharacterMap kmap =
- KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
- KeyEvent[] events = kmap.getEvents(mCharacter);
updateCachedTextfield();
- if (null == events) {
+ if (cannotUseKeyEvents) {
return;
}
int length = events.length;
@@ -433,6 +440,8 @@ import android.widget.AutoCompleteTextView;
method = null;
}
setTransformationMethod(method);
+ setInputType(inPassword ? EditorInfo.TYPE_TEXT_VARIATION_PASSWORD :
+ EditorInfo.TYPE_CLASS_TEXT);
}
/* package */ void setMaxLength(int maxLength) {
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 7467b83..bd910b5 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2841,11 +2841,6 @@ public class WebView extends AbsoluteLayout
// a center key. Does not affect long press with the trackball/touch.
private boolean mGotEnterDown = false;
- // Enable copy/paste with trackball here.
- // This should be left disabled until the framework can guarantee
- // delivering matching key-up and key-down events for the shift key
- private static final boolean ENABLE_COPY_PASTE = true;
-
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (LOGV_ENABLED) {
@@ -2876,7 +2871,7 @@ public class WebView extends AbsoluteLayout
return false;
}
- if (ENABLE_COPY_PASTE && mShiftIsPressed == false
+ if (mShiftIsPressed == false && nativeFocusNodeWantsKeyEvents() == false
&& (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
|| keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)) {
mExtendSelection = false;
@@ -2911,10 +2906,6 @@ public class WebView extends AbsoluteLayout
mPrivateHandler.sendMessageDelayed(mPrivateHandler
.obtainMessage(LONG_PRESS_ENTER), LONG_PRESS_TIMEOUT);
nativeRecordButtons(true, true);
- // FIXME, currently in webcore keydown it doesn't do anything.
- // In keyup, it calls both keydown and keyup, we should fix it.
- mWebViewCore.sendMessage(EventHub.KEY_DOWN, keyCode,
- EventHub.KEYEVENT_UNHANDLED_TYPE, event);
return true;
}
// Bubble up the key event as WebView doesn't handle it
@@ -2949,15 +2940,10 @@ public class WebView extends AbsoluteLayout
}
}
- if (nativeFocusNodeWantsKeyEvents()) {
- mWebViewCore.sendMessage(EventHub.KEY_DOWN, keyCode,
- EventHub.KEYEVENT_FOCUS_NODE_TYPE, event);
- // return true as DOM handles the key
- return true;
- } else if (false) { // reserved to check the meta tag
+ // TODO: should we pass all the keys to DOM or check the meta tag
+ if (nativeFocusNodeWantsKeyEvents() || true) {
// pass the key to DOM
- mWebViewCore.sendMessage(EventHub.KEY_DOWN, keyCode,
- EventHub.KEYEVENT_UNHANDLED_TYPE, event);
+ mWebViewCore.sendMessage(EventHub.KEY_DOWN, event);
// return true as DOM handles the key
return true;
}
@@ -3008,8 +2994,8 @@ public class WebView extends AbsoluteLayout
return false;
}
- if (ENABLE_COPY_PASTE && (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
- || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)) {
+ if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
+ || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
if (commitCopy()) {
return true;
}
@@ -3050,25 +3036,18 @@ public class WebView extends AbsoluteLayout
Rect visibleRect = sendOurVisibleRect();
// Note that sendOurVisibleRect calls viewToContent, so the
// coordinates should be in content coordinates.
- boolean nodeOnScreen = false;
- boolean isTextField = false;
- boolean isTextArea = false;
- FocusNode node = null;
if (nativeUpdateFocusNode()) {
- node = mFocusNode;
- isTextField = node.mIsTextField;
- isTextArea = node.mIsTextArea;
- nodeOnScreen = Rect.intersects(node.mBounds, visibleRect);
- }
- if (nodeOnScreen && !isTextField && !isTextArea) {
- nativeSetFollowedLink(true);
- mWebViewCore.sendMessage(EventHub.SET_FINAL_FOCUS,
- EventHub.BLOCK_FOCUS_CHANGE_UNTIL_KEY_UP, 0,
- new WebViewCore.FocusData(mFocusData));
- playSoundEffect(SoundEffectConstants.CLICK);
- if (!mCallbackProxy.uiOverrideUrlLoading(node.mText)) {
- mWebViewCore.sendMessage(EventHub.KEY_UP, keyCode,
- EventHub.KEYEVENT_UNHANDLED_TYPE, event);
+ if (Rect.intersects(mFocusNode.mBounds, visibleRect)) {
+ nativeSetFollowedLink(true);
+ mWebViewCore.sendMessage(EventHub.SET_FINAL_FOCUS,
+ EventHub.BLOCK_FOCUS_CHANGE_UNTIL_KEY_UP, 0,
+ new WebViewCore.FocusData(mFocusData));
+ playSoundEffect(SoundEffectConstants.CLICK);
+ if (!mCallbackProxy.uiOverrideUrlLoading(mFocusNode.mText)) {
+ // use CLICK instead of KEY_DOWN/KEY_UP so that we can
+ // trigger mouse click events
+ mWebViewCore.sendMessage(EventHub.CLICK);
+ }
}
return true;
}
@@ -3076,15 +3055,10 @@ public class WebView extends AbsoluteLayout
return false;
}
- if (nativeFocusNodeWantsKeyEvents()) {
- mWebViewCore.sendMessage(EventHub.KEY_UP, keyCode,
- EventHub.KEYEVENT_FOCUS_NODE_TYPE, event);
- // return true as DOM handles the key
- return true;
- } else if (false) { // reserved to check the meta tag
+ // TODO: should we pass all the keys to DOM or check the meta tag
+ if (nativeFocusNodeWantsKeyEvents() || true) {
// pass the key to DOM
- mWebViewCore.sendMessage(EventHub.KEY_UP, keyCode,
- EventHub.KEYEVENT_UNHANDLED_TYPE, event);
+ mWebViewCore.sendMessage(EventHub.KEY_UP, event);
// return true as DOM handles the key
return true;
}
@@ -3637,12 +3611,7 @@ public class WebView extends AbsoluteLayout
private long mTrackballUpTime = 0;
private long mLastFocusTime = 0;
private Rect mLastFocusBounds;
-
- // Used to determine that the trackball is down AND that it has not
- // been moved while down, whereas mTrackballDown is true until we
- // receive an ACTION_UP
- private boolean mTrackTrackball = false;
-
+
// Set by default; BrowserActivity clears to interpret trackball data
// directly for movement. Currently, the framework only passes
// arrow key events, not trackball events, from one child to the next
@@ -3666,7 +3635,6 @@ public class WebView extends AbsoluteLayout
}
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mPrivateHandler.removeMessages(SWITCH_TO_ENTER);
- mTrackTrackball = true;
mTrackballDown = true;
if (mNativeClass != 0) {
nativeRecordButtons(true, true);
@@ -3681,12 +3649,10 @@ public class WebView extends AbsoluteLayout
+ " mLastFocusTime=" + mLastFocusTime);
}
return false; // let common code in onKeyDown at it
- } else if (mTrackTrackball) {
- // LONG_PRESS_ENTER is set in common onKeyDown
- mPrivateHandler.removeMessages(LONG_PRESS_ENTER);
- mTrackTrackball = false;
}
if (ev.getAction() == MotionEvent.ACTION_UP) {
+ // LONG_PRESS_ENTER is set in common onKeyDown
+ mPrivateHandler.removeMessages(LONG_PRESS_ENTER);
mTrackballDown = false;
mTrackballUpTime = time;
if (mShiftIsPressed) {
@@ -4511,7 +4477,6 @@ public class WebView extends AbsoluteLayout
// as this is shared by keydown and trackballdown, reset all
// the states
mGotEnterDown = false;
- mTrackTrackball = false;
mTrackballDown = false;
// LONG_PRESS_ENTER is sent as a delayed message. If we
// switch to windows overview, the WebView will be
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 9e413f9..323b44d 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -25,7 +25,6 @@ import android.graphics.Picture;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
-import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -300,14 +299,10 @@ final class WebViewCore {
*/
private native void nativeSplitContent();
- // these must be kept lock-step with the KeyState enum in WebViewCore.h
- static private final int KEY_ACTION_DOWN = 0;
- static private final int KEY_ACTION_UP = 1;
+ private native boolean nativeKey(int keyCode, int unichar,
+ int repeatCount, boolean isShift, boolean isAlt, boolean isDown);
- private native boolean nativeSendKeyToFocusNode(int keyCode, int unichar,
- int repeatCount, boolean isShift, boolean isAlt, int keyAction);
-
- private native boolean nativeKeyUp(int keycode, int keyvalue);
+ private native boolean nativeClick();
private native void nativeSendListBoxChoices(boolean[] choices, int size);
@@ -527,6 +522,7 @@ final class WebViewCore {
static final int PASS_TO_JS = 115;
static final int SET_GLOBAL_BOUNDS = 116;
static final int UPDATE_CACHE_AND_TEXT_ENTRY = 117;
+ static final int CLICK = 118;
static final int DOC_HAS_IMAGES = 120;
static final int SET_SNAP_ANCHOR = 121;
static final int DELETE_SELECTION = 122;
@@ -573,19 +569,6 @@ final class WebViewCore {
static final int NO_FOCUS_CHANGE_BLOCK = 0;
static final int BLOCK_FOCUS_CHANGE_UNTIL_KEY_UP = 1;
- /* The KEY_DOWN and KEY_UP messages pass the keyCode in arg1, and a
- "type" in arg2. These are the types, and they describe what the
- circumstances were that prompted the UI thread to send the keyevent
- to webkit.
-
- FOCUS_NODE - the currently focused node says it wants key events
- (e.g. plugins)
- UNHANDLED - the UI side did not handle the key, so we give webkit
- a shot at it.
- */
- static final int KEYEVENT_FOCUS_NODE_TYPE = 0;
- static final int KEYEVENT_UNHANDLED_TYPE = 1;
-
// Private handler for WebCore messages.
private Handler mHandler;
// Message queue for containing messages before the WebCore thread is
@@ -680,11 +663,15 @@ final class WebViewCore {
break;
case KEY_DOWN:
- keyDown(msg.arg1, msg.arg2, (KeyEvent) msg.obj);
+ key((KeyEvent) msg.obj, true);
break;
case KEY_UP:
- keyUp(msg.arg1, msg.arg2, (KeyEvent) msg.obj);
+ key((KeyEvent) msg.obj, false);
+ break;
+
+ case CLICK:
+ nativeClick();
break;
case VIEW_SIZE_CHANGED:
@@ -1130,49 +1117,19 @@ final class WebViewCore {
mBrowserFrame.loadUrl(url);
}
- private void keyDown(int code, int target, KeyEvent event) {
+ private void key(KeyEvent evt, boolean isDown) {
if (LOGV_ENABLED) {
- Log.v(LOGTAG, "CORE keyDown at " + System.currentTimeMillis()
- + ", " + event);
+ Log.v(LOGTAG, "CORE key at " + System.currentTimeMillis() + ", "
+ + evt);
}
- switch (target) {
- case EventHub.KEYEVENT_UNHANDLED_TYPE:
- break;
- case EventHub.KEYEVENT_FOCUS_NODE_TYPE:
- if (nativeSendKeyToFocusNode(code, event.getUnicodeChar(),
- event.getRepeatCount(),
- event.isShiftPressed(),
- event.isAltPressed(),
- KEY_ACTION_DOWN)) {
- return;
- }
- break;
+ if (!nativeKey(evt.getKeyCode(), evt.getUnicodeChar(),
+ evt.getRepeatCount(), evt.isShiftPressed(), evt.isAltPressed(),
+ isDown)) {
+ // bubble up the event handling
+ mCallbackProxy.onUnhandledKeyEvent(evt);
}
- // If we get here, no one handled it, so call our proxy
- mCallbackProxy.onUnhandledKeyEvent(event);
}
- private void keyUp(int code, int target, KeyEvent event) {
- if (LOGV_ENABLED) {
- Log.v(LOGTAG, "CORE keyUp at " + System.currentTimeMillis()
- + ", " + event);
- }
- switch (target) {
- case EventHub.KEYEVENT_UNHANDLED_TYPE:
- if (!nativeKeyUp(code, event.getUnicodeChar())) {
- mCallbackProxy.onUnhandledKeyEvent(event);
- }
- break;
- case EventHub.KEYEVENT_FOCUS_NODE_TYPE:
- nativeSendKeyToFocusNode(code, event.getUnicodeChar(),
- event.getRepeatCount(),
- event.isShiftPressed(),
- event.isAltPressed(),
- KEY_ACTION_UP);
- break;
- }
- }
-
// These values are used to avoid requesting a layout based on old values
private int mCurrentViewWidth = 0;
private int mCurrentViewHeight = 0;