Program: 23198
Project: 23198
Buggy source:
@Override public void handleMessage(Message msg){
  if (DebugFlags.WEB_VIEW) {
    Log.v(LOGTAG,msg.what < REMEMBER_PASSWORD || msg.what > SHOW_RECT_MSG_ID ? Integer.toString(msg.what) : HandlerDebugString[msg.what - REMEMBER_PASSWORD]);
  }
  if (mWebViewCore == null) {
    return;
  }
switch (msg.what) {
case REMEMBER_PASSWORD:
{
      mDatabase.setUsernamePassword(msg.getData().getString("String_Node_Str"),msg.getData().getString("String_Node_Str"),msg.getData().getString("String_Node_Str"));
      ((Message)msg.obj).sendToTarget();
      break;
    }
case NEVER_REMEMBER_PASSWORD:
{
    mDatabase.setUsernamePassword(msg.getData().getString("String_Node_Str"),null,null);
    ((Message)msg.obj).sendToTarget();
    break;
  }
case SWITCH_TO_SHORTPRESS:
{
  if (mPreventDrag == PREVENT_DRAG_MAYBE_YES) {
    mPreventDrag=PREVENT_DRAG_NO;
  }
  if (mTouchMode == TOUCH_INIT_MODE) {
    mTouchMode=TOUCH_SHORTPRESS_START_MODE;
    updateSelection();
  }
 else   if (mTouchMode == TOUCH_DOUBLE_TAP_MODE) {
    mTouchMode=TOUCH_DONE_MODE;
  }
  break;
}
case SWITCH_TO_LONGPRESS:
{
if (mPreventDrag == PREVENT_DRAG_NO) {
  mTouchMode=TOUCH_DONE_MODE;
  performLongClick();
  rebuildWebTextView();
}
break;
}
case RELEASE_SINGLE_TAP:
{
if (mPreventDrag == PREVENT_DRAG_NO) {
mTouchMode=TOUCH_DONE_MODE;
doShortPress();
}
break;
}
case SCROLL_BY_MSG_ID:
setContentScrollBy(msg.arg1,msg.arg2,(Boolean)msg.obj);
break;
case SYNC_SCROLL_TO_MSG_ID:
if (mUserScroll) {
mUserScroll=false;
break;
}
case SCROLL_TO_MSG_ID:
if (setContentScrollTo(msg.arg1,msg.arg2)) {
mUserScroll=false;
mWebViewCore.sendMessage(EventHub.SYNC_SCROLL,msg.arg1,msg.arg2);
}
break;
case SPAWN_SCROLL_TO_MSG_ID:
spawnContentScrollTo(msg.arg1,msg.arg2);
break;
case NEW_PICTURE_MSG_ID:
{
WebSettings settings=mWebViewCore.getSettings();
final int viewWidth=getViewWidth();
final WebViewCore.DrawData draw=(WebViewCore.DrawData)msg.obj;
final Point viewSize=draw.mViewPoint;
boolean useWideViewport=settings.getUseWideViewPort();
WebViewCore.RestoreState restoreState=draw.mRestoreState;
if (restoreState != null) {
mInZoomOverview=false;
if (restoreState.mMinScale == 0) {
if (restoreState.mMobileSite) {
if (draw.mMinPrefWidth > Math.max(0,draw.mViewPoint.x)) {
mMinZoomScale=(float)viewWidth / draw.mMinPrefWidth;
mMinZoomScaleFixed=false;
mInZoomOverview=useWideViewport && settings.getLoadWithOverviewMode();
}
 else {
mMinZoomScale=restoreState.mDefaultScale;
mMinZoomScaleFixed=true;
}
}
 else {
mMinZoomScale=DEFAULT_MIN_ZOOM_SCALE;
mMinZoomScaleFixed=false;
}
}
 else {
mMinZoomScale=restoreState.mMinScale;
mMinZoomScaleFixed=true;
}
if (restoreState.mMaxScale == 0) {
mMaxZoomScale=DEFAULT_MAX_ZOOM_SCALE;
}
 else {
mMaxZoomScale=restoreState.mMaxScale;
}
if (mInitialScaleInPercent > 0) {
setNewZoomScale(mInitialScaleInPercent / 100.0f,mInitialScaleInPercent != mTextWrapScale * 100,false);
}
 else if (restoreState.mViewScale > 0) {
mTextWrapScale=restoreState.mTextWrapScale;
setNewZoomScale(restoreState.mViewScale,false,false);
}
 else {
mInZoomOverview=useWideViewport && settings.getLoadWithOverviewMode();
float scale;
if (mInZoomOverview) {
scale=(float)viewWidth / WebViewCore.DEFAULT_VIEWPORT_WIDTH;
}
 else {
scale=restoreState.mTextWrapScale;
}
setNewZoomScale(scale,Math.abs(scale - mTextWrapScale) >= 0.01f,false);
}
setContentScrollTo(restoreState.mScrollX,restoreState.mScrollY);
clearTextEntry();
}
final boolean updateLayout=viewSize.x == mLastWidthSent && viewSize.y == mLastHeightSent;
recordNewContentSize(draw.mWidthHeight.x,draw.mWidthHeight.y + (mFindIsUp ? mFindHeight : 0),updateLayout);
if (DebugFlags.WEB_VIEW) {
Rect b=draw.mInvalRegion.getBounds();
Log.v(LOGTAG,"String_Node_Str" + b.left + "String_Node_Str"+ b.top+ "String_Node_Str"+ b.right+ "String_Node_Str"+ b.bottom+ "String_Node_Str");
}
invalidateContentRect(draw.mInvalRegion.getBounds());
if (mPictureListener != null) {
mPictureListener.onNewPicture(WebView.this,capturePicture());
}
if (useWideViewport) {
mZoomOverviewWidth=Math.max((int)(viewWidth / mDefaultScale),Math.max(draw.mMinPrefWidth,draw.mViewPoint.x));
}
if (!mMinZoomScaleFixed) {
mMinZoomScale=(float)viewWidth / mZoomOverviewWidth;
}
if (!mDrawHistory && mInZoomOverview) {
if (Math.abs((viewWidth * mInvActualScale) - mZoomOverviewWidth) > 1) {
setNewZoomScale((float)viewWidth / mZoomOverviewWidth,Math.abs(mActualScale - mTextWrapScale) < 0.01f,false);
}
}
break;
}
case WEBCORE_INITIALIZED_MSG_ID:
nativeCreate(msg.arg1);
break;
case UPDATE_TEXTFIELD_TEXT_MSG_ID:
if (inEditingMode() && mWebTextView.isSameTextField(msg.arg1)) {
if (msg.getData().getBoolean("String_Node_Str")) {
Spannable text=(Spannable)mWebTextView.getText();
int start=Selection.getSelectionStart(text);
int end=Selection.getSelectionEnd(text);
mWebTextView.setInPassword(true);
Spannable pword=(Spannable)mWebTextView.getText();
Selection.setSelection(pword,start,end);
}
 else if (msg.arg2 == mTextGeneration) {
mWebTextView.setTextAndKeepSelection((String)msg.obj);
}
}
break;
case UPDATE_TEXT_SELECTION_MSG_ID:
if (inEditingMode() && mWebTextView.isSameTextField(msg.arg1) && msg.arg2 == mTextGeneration) {
WebViewCore.TextSelectionData tData=(WebViewCore.TextSelectionData)msg.obj;
mWebTextView.setSelectionFromWebKit(tData.mStart,tData.mEnd);
}
break;
case MOVE_OUT_OF_PLUGIN:
if (nativePluginEatsNavKey()) {
navHandledKey(msg.arg1,1,false,0,true);
}
break;
case UPDATE_TEXT_ENTRY_MSG_ID:
if (inEditingMode() && nativeCursorIsTextInput()) {
mWebTextView.bringIntoView();
rebuildWebTextView();
}
break;
case CLEAR_TEXT_ENTRY:
clearTextEntry();
break;
case INVAL_RECT_MSG_ID:
{
Rect r=(Rect)msg.obj;
if (r == null) {
invalidate();
}
 else {
viewInvalidate(r.left,r.top,r.right,r.bottom);
}
break;
}
case REQUEST_FORM_DATA:
AutoCompleteAdapter adapter=(AutoCompleteAdapter)msg.obj;
if (mWebTextView.isSameTextField(msg.arg1)) {
mWebTextView.setAdapterCustom(adapter);
}
break;
case UPDATE_CLIPBOARD:
String str=(String)msg.obj;
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG,"String_Node_Str" + str);
}
try {
IClipboard clip=IClipboard.Stub.asInterface(ServiceManager.getService("String_Node_Str"));
clip.setClipboardText(str);
}
 catch (android.os.RemoteException e) {
Log.e(LOGTAG,"String_Node_Str",e);
}
break;
case RESUME_WEBCORE_UPDATE:
WebViewCore.resumeUpdate(mWebViewCore);
break;
case LONG_PRESS_CENTER:
mGotCenterDown=false;
mTrackballDown=false;
if (getParent() != null) {
performLongClick();
}
break;
case WEBCORE_NEED_TOUCH_EVENTS:
mForwardTouchEvents=(msg.arg1 != 0);
break;
case PREVENT_TOUCH_ID:
if (msg.arg1 == MotionEvent.ACTION_DOWN) {
if (mPreventDrag == PREVENT_DRAG_MAYBE_YES) {
mPreventDrag=msg.arg2 == 1 ? PREVENT_DRAG_YES : PREVENT_DRAG_NO;
if (mPreventDrag == PREVENT_DRAG_YES) {
mTouchMode=TOUCH_DONE_MODE;
}
}
}
break;
case REQUEST_KEYBOARD:
if (msg.arg1 == 0) {
hideSoftKeyboard();
}
 else {
displaySoftKeyboard(false);
}
break;
case SHOW_RECT_MSG_ID:
WebViewCore.ShowRectData data=(WebViewCore.ShowRectData)msg.obj;
int x=mScrollX;
int left=contentToViewDimension(data.mLeft);
int width=contentToViewDimension(data.mWidth);
int maxWidth=contentToViewDimension(data.mContentWidth);
int viewWidth=getViewWidth();
if (width < viewWidth) {
x+=left + width / 2 - mScrollX - viewWidth / 2;
}
 else {
x+=(int)(left + data.mXPercentInDoc * width - mScrollX - data.mXPercentInView * viewWidth);
}
x=Math.max(0,(Math.min(maxWidth,x + viewWidth)) - viewWidth);
int y=mScrollY;
int top=contentToViewDimension(data.mTop);
int height=contentToViewDimension(data.mHeight);
int maxHeight=contentToViewDimension(data.mContentHeight);
int viewHeight=getViewHeight();
if (height < viewHeight) {
y+=top + height / 2 - mScrollY - viewHeight / 2;
}
 else {
y+=(int)(top + data.mYPercentInDoc * height - mScrollY - data.mYPercentInView * viewHeight);
}
y=Math.max(0,(Math.min(maxHeight,y + viewHeight) - viewHeight));
scrollTo(x,y);
break;
default :
super.handleMessage(msg);
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
  if (DebugFlags.WEB_VIEW) {
    Log.v(LOGTAG,msg.what < REMEMBER_PASSWORD || msg.what > SHOW_RECT_MSG_ID ? Integer.toString(msg.what) : HandlerDebugString[msg.what - REMEMBER_PASSWORD]);
  }
  if (mWebViewCore == null) {
    return;
  }
switch (msg.what) {
case REMEMBER_PASSWORD:
{
      mDatabase.setUsernamePassword(msg.getData().getString("String_Node_Str"),msg.getData().getString("String_Node_Str"),msg.getData().getString("String_Node_Str"));
      ((Message)msg.obj).sendToTarget();
      break;
    }
case NEVER_REMEMBER_PASSWORD:
{
    mDatabase.setUsernamePassword(msg.getData().getString("String_Node_Str"),null,null);
    ((Message)msg.obj).sendToTarget();
    break;
  }
case SWITCH_TO_SHORTPRESS:
{
  if (mPreventDrag == PREVENT_DRAG_MAYBE_YES) {
    mPreventDrag=PREVENT_DRAG_NO;
  }
  if (mTouchMode == TOUCH_INIT_MODE) {
    mTouchMode=TOUCH_SHORTPRESS_START_MODE;
    updateSelection();
  }
 else   if (mTouchMode == TOUCH_DOUBLE_TAP_MODE) {
    mTouchMode=TOUCH_DONE_MODE;
  }
  break;
}
case SWITCH_TO_LONGPRESS:
{
if (mPreventDrag == PREVENT_DRAG_NO) {
  mTouchMode=TOUCH_DONE_MODE;
  performLongClick();
  rebuildWebTextView();
}
break;
}
case RELEASE_SINGLE_TAP:
{
if (mPreventDrag == PREVENT_DRAG_NO) {
mTouchMode=TOUCH_DONE_MODE;
doShortPress();
}
break;
}
case SCROLL_BY_MSG_ID:
setContentScrollBy(msg.arg1,msg.arg2,(Boolean)msg.obj);
break;
case SYNC_SCROLL_TO_MSG_ID:
if (mUserScroll) {
mUserScroll=false;
break;
}
case SCROLL_TO_MSG_ID:
if (setContentScrollTo(msg.arg1,msg.arg2)) {
mUserScroll=false;
mWebViewCore.sendMessage(EventHub.SYNC_SCROLL,msg.arg1,msg.arg2);
}
break;
case SPAWN_SCROLL_TO_MSG_ID:
spawnContentScrollTo(msg.arg1,msg.arg2);
break;
case UPDATE_ZOOM_RANGE:
{
WebViewCore.RestoreState restoreState=(WebViewCore.RestoreState)msg.obj;
updateZoomRange(restoreState,getViewWidth(),restoreState.mScrollX,false);
break;
}
case NEW_PICTURE_MSG_ID:
{
WebSettings settings=mWebViewCore.getSettings();
final int viewWidth=getViewWidth();
final WebViewCore.DrawData draw=(WebViewCore.DrawData)msg.obj;
final Point viewSize=draw.mViewPoint;
boolean useWideViewport=settings.getUseWideViewPort();
WebViewCore.RestoreState restoreState=draw.mRestoreState;
if (restoreState != null) {
mInZoomOverview=false;
updateZoomRange(restoreState,viewSize.x,draw.mMinPrefWidth,true);
if (mInitialScaleInPercent > 0) {
setNewZoomScale(mInitialScaleInPercent / 100.0f,mInitialScaleInPercent != mTextWrapScale * 100,false);
}
 else if (restoreState.mViewScale > 0) {
mTextWrapScale=restoreState.mTextWrapScale;
setNewZoomScale(restoreState.mViewScale,false,false);
}
 else {
mInZoomOverview=useWideViewport && settings.getLoadWithOverviewMode();
float scale;
if (mInZoomOverview) {
scale=(float)viewWidth / WebViewCore.DEFAULT_VIEWPORT_WIDTH;
}
 else {
scale=restoreState.mTextWrapScale;
}
setNewZoomScale(scale,Math.abs(scale - mTextWrapScale) >= 0.01f,false);
}
setContentScrollTo(restoreState.mScrollX,restoreState.mScrollY);
clearTextEntry();
}
final boolean updateLayout=viewSize.x == mLastWidthSent && viewSize.y == mLastHeightSent;
recordNewContentSize(draw.mWidthHeight.x,draw.mWidthHeight.y + (mFindIsUp ? mFindHeight : 0),updateLayout);
if (DebugFlags.WEB_VIEW) {
Rect b=draw.mInvalRegion.getBounds();
Log.v(LOGTAG,"String_Node_Str" + b.left + "String_Node_Str"+ b.top+ "String_Node_Str"+ b.right+ "String_Node_Str"+ b.bottom+ "String_Node_Str");
}
invalidateContentRect(draw.mInvalRegion.getBounds());
if (mPictureListener != null) {
mPictureListener.onNewPicture(WebView.this,capturePicture());
}
if (useWideViewport) {
mZoomOverviewWidth=Math.max((int)(viewWidth / mDefaultScale),Math.max(draw.mMinPrefWidth,draw.mViewPoint.x));
}
if (!mMinZoomScaleFixed) {
mMinZoomScale=(float)viewWidth / mZoomOverviewWidth;
}
if (!mDrawHistory && mInZoomOverview) {
if (Math.abs((viewWidth * mInvActualScale) - mZoomOverviewWidth) > 1) {
setNewZoomScale((float)viewWidth / mZoomOverviewWidth,Math.abs(mActualScale - mTextWrapScale) < 0.01f,false);
}
}
break;
}
case WEBCORE_INITIALIZED_MSG_ID:
nativeCreate(msg.arg1);
break;
case UPDATE_TEXTFIELD_TEXT_MSG_ID:
if (inEditingMode() && mWebTextView.isSameTextField(msg.arg1)) {
if (msg.getData().getBoolean("String_Node_Str")) {
Spannable text=(Spannable)mWebTextView.getText();
int start=Selection.getSelectionStart(text);
int end=Selection.getSelectionEnd(text);
mWebTextView.setInPassword(true);
Spannable pword=(Spannable)mWebTextView.getText();
Selection.setSelection(pword,start,end);
}
 else if (msg.arg2 == mTextGeneration) {
mWebTextView.setTextAndKeepSelection((String)msg.obj);
}
}
break;
case UPDATE_TEXT_SELECTION_MSG_ID:
if (inEditingMode() && mWebTextView.isSameTextField(msg.arg1) && msg.arg2 == mTextGeneration) {
WebViewCore.TextSelectionData tData=(WebViewCore.TextSelectionData)msg.obj;
mWebTextView.setSelectionFromWebKit(tData.mStart,tData.mEnd);
}
break;
case MOVE_OUT_OF_PLUGIN:
if (nativePluginEatsNavKey()) {
navHandledKey(msg.arg1,1,false,0,true);
}
break;
case UPDATE_TEXT_ENTRY_MSG_ID:
if (inEditingMode() && nativeCursorIsTextInput()) {
mWebTextView.bringIntoView();
rebuildWebTextView();
}
break;
case CLEAR_TEXT_ENTRY:
clearTextEntry();
break;
case INVAL_RECT_MSG_ID:
{
Rect r=(Rect)msg.obj;
if (r == null) {
invalidate();
}
 else {
viewInvalidate(r.left,r.top,r.right,r.bottom);
}
break;
}
case REQUEST_FORM_DATA:
AutoCompleteAdapter adapter=(AutoCompleteAdapter)msg.obj;
if (mWebTextView.isSameTextField(msg.arg1)) {
mWebTextView.setAdapterCustom(adapter);
}
break;
case UPDATE_CLIPBOARD:
String str=(String)msg.obj;
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG,"String_Node_Str" + str);
}
try {
IClipboard clip=IClipboard.Stub.asInterface(ServiceManager.getService("String_Node_Str"));
clip.setClipboardText(str);
}
 catch (android.os.RemoteException e) {
Log.e(LOGTAG,"String_Node_Str",e);
}
break;
case RESUME_WEBCORE_UPDATE:
WebViewCore.resumeUpdate(mWebViewCore);
break;
case LONG_PRESS_CENTER:
mGotCenterDown=false;
mTrackballDown=false;
if (getParent() != null) {
performLongClick();
}
break;
case WEBCORE_NEED_TOUCH_EVENTS:
mForwardTouchEvents=(msg.arg1 != 0);
break;
case PREVENT_TOUCH_ID:
if (msg.arg1 == MotionEvent.ACTION_DOWN) {
if (mPreventDrag == PREVENT_DRAG_MAYBE_YES) {
mPreventDrag=msg.arg2 == 1 ? PREVENT_DRAG_YES : PREVENT_DRAG_NO;
if (mPreventDrag == PREVENT_DRAG_YES) {
mTouchMode=TOUCH_DONE_MODE;
}
}
}
break;
case REQUEST_KEYBOARD:
if (msg.arg1 == 0) {
hideSoftKeyboard();
}
 else {
displaySoftKeyboard(false);
}
break;
case SHOW_RECT_MSG_ID:
WebViewCore.ShowRectData data=(WebViewCore.ShowRectData)msg.obj;
int x=mScrollX;
int left=contentToViewDimension(data.mLeft);
int width=contentToViewDimension(data.mWidth);
int maxWidth=contentToViewDimension(data.mContentWidth);
int viewWidth=getViewWidth();
if (width < viewWidth) {
x+=left + width / 2 - mScrollX - viewWidth / 2;
}
 else {
x+=(int)(left + data.mXPercentInDoc * width - mScrollX - data.mXPercentInView * viewWidth);
}
x=Math.max(0,(Math.min(maxWidth,x + viewWidth)) - viewWidth);
int y=mScrollY;
int top=contentToViewDimension(data.mTop);
int height=contentToViewDimension(data.mHeight);
int maxHeight=contentToViewDimension(data.mContentHeight);
int viewHeight=getViewHeight();
if (height < viewHeight) {
y+=top + height / 2 - mScrollY - viewHeight / 2;
}
 else {
y+=(int)(top + data.mYPercentInDoc * height - mScrollY - data.mYPercentInView * viewHeight);
}
y=Math.max(0,(Math.min(maxHeight,y + viewHeight) - viewHeight));
scrollTo(x,y);
break;
default :
super.handleMessage(msg);
break;
}
}