| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.graphics.Picture; | 7 import android.graphics.Picture; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 import android.os.Message; | 10 import android.os.Message; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 final String mArgs; | 52 final String mArgs; |
| 53 | 53 |
| 54 LoginRequestInfo(String realm, String account, String args) { | 54 LoginRequestInfo(String realm, String account, String args) { |
| 55 mRealm = realm; | 55 mRealm = realm; |
| 56 mAccount = account; | 56 mAccount = account; |
| 57 mArgs = args; | 57 mArgs = args; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 private static class OnReceivedErrorInfo { | 61 private static class OnReceivedErrorInfo { |
| 62 final int mErrorCode; | 62 final AwContentsClient.AwWebResourceRequest mRequest; |
| 63 final String mDescription; | 63 final AwContentsClient.AwWebResourceError mError; |
| 64 final String mFailingUrl; | |
| 65 | 64 |
| 66 OnReceivedErrorInfo(int errorCode, String description, String failingUrl
) { | 65 OnReceivedErrorInfo(AwContentsClient.AwWebResourceRequest request, |
| 67 mErrorCode = errorCode; | 66 AwContentsClient.AwWebResourceError error) { |
| 68 mDescription = description; | 67 mRequest = request; |
| 69 mFailingUrl = failingUrl; | 68 mError = error; |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 private static final int MSG_ON_LOAD_RESOURCE = 1; | 72 private static final int MSG_ON_LOAD_RESOURCE = 1; |
| 74 private static final int MSG_ON_PAGE_STARTED = 2; | 73 private static final int MSG_ON_PAGE_STARTED = 2; |
| 75 private static final int MSG_ON_DOWNLOAD_START = 3; | 74 private static final int MSG_ON_DOWNLOAD_START = 3; |
| 76 private static final int MSG_ON_RECEIVED_LOGIN_REQUEST = 4; | 75 private static final int MSG_ON_RECEIVED_LOGIN_REQUEST = 4; |
| 77 private static final int MSG_ON_RECEIVED_ERROR = 5; | 76 private static final int MSG_ON_RECEIVED_ERROR = 5; |
| 78 private static final int MSG_ON_NEW_PICTURE = 6; | 77 private static final int MSG_ON_NEW_PICTURE = 6; |
| 79 private static final int MSG_ON_SCALE_CHANGED_SCALED = 7; | 78 private static final int MSG_ON_SCALE_CHANGED_SCALED = 7; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 info.mContentDisposition, info.mMimeType, info.mCont
entLength); | 112 info.mContentDisposition, info.mMimeType, info.mCont
entLength); |
| 114 break; | 113 break; |
| 115 } | 114 } |
| 116 case MSG_ON_RECEIVED_LOGIN_REQUEST: { | 115 case MSG_ON_RECEIVED_LOGIN_REQUEST: { |
| 117 LoginRequestInfo info = (LoginRequestInfo) msg.obj; | 116 LoginRequestInfo info = (LoginRequestInfo) msg.obj; |
| 118 mContentsClient.onReceivedLoginRequest(info.mRealm, info.mAc
count, info.mArgs); | 117 mContentsClient.onReceivedLoginRequest(info.mRealm, info.mAc
count, info.mArgs); |
| 119 break; | 118 break; |
| 120 } | 119 } |
| 121 case MSG_ON_RECEIVED_ERROR: { | 120 case MSG_ON_RECEIVED_ERROR: { |
| 122 OnReceivedErrorInfo info = (OnReceivedErrorInfo) msg.obj; | 121 OnReceivedErrorInfo info = (OnReceivedErrorInfo) msg.obj; |
| 123 mContentsClient.onReceivedError(info.mErrorCode, info.mDescr
iption, | 122 mContentsClient.onReceivedError(info.mRequest, info.mError); |
| 124 info.mFailingUrl); | |
| 125 break; | 123 break; |
| 126 } | 124 } |
| 127 case MSG_ON_NEW_PICTURE: { | 125 case MSG_ON_NEW_PICTURE: { |
| 128 Picture picture = null; | 126 Picture picture = null; |
| 129 try { | 127 try { |
| 130 if (msg.obj != null) picture = (Picture) ((Callable<?>)
msg.obj).call(); | 128 if (msg.obj != null) picture = (Picture) ((Callable<?>)
msg.obj).call(); |
| 131 } catch (Exception e) { | 129 } catch (Exception e) { |
| 132 throw new RuntimeException("Error getting picture", e); | 130 throw new RuntimeException("Error getting picture", e); |
| 133 } | 131 } |
| 134 mContentsClient.onNewPicture(picture); | 132 mContentsClient.onNewPicture(picture); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DownloadInfo info = new DownloadInfo(url, userAgent, contentDisposition,
mimeType, | 165 DownloadInfo info = new DownloadInfo(url, userAgent, contentDisposition,
mimeType, |
| 168 contentLength); | 166 contentLength); |
| 169 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DOWNLOAD_START, info)
); | 167 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DOWNLOAD_START, info)
); |
| 170 } | 168 } |
| 171 | 169 |
| 172 public void postOnReceivedLoginRequest(String realm, String account, String
args) { | 170 public void postOnReceivedLoginRequest(String realm, String account, String
args) { |
| 173 LoginRequestInfo info = new LoginRequestInfo(realm, account, args); | 171 LoginRequestInfo info = new LoginRequestInfo(realm, account, args); |
| 174 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_RECEIVED_LOGIN_REQUES
T, info)); | 172 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_RECEIVED_LOGIN_REQUES
T, info)); |
| 175 } | 173 } |
| 176 | 174 |
| 177 public void postOnReceivedError(int errorCode, String description, String fa
ilingUrl) { | 175 public void postOnReceivedError(AwContentsClient.AwWebResourceRequest reques
t, |
| 178 OnReceivedErrorInfo info = new OnReceivedErrorInfo(errorCode, descriptio
n, failingUrl); | 176 AwContentsClient.AwWebResourceError error) { |
| 177 OnReceivedErrorInfo info = new OnReceivedErrorInfo(request, error); |
| 179 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_RECEIVED_ERROR, info)
); | 178 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_RECEIVED_ERROR, info)
); |
| 180 } | 179 } |
| 181 | 180 |
| 182 public void postOnNewPicture(Callable<Picture> pictureProvider) { | 181 public void postOnNewPicture(Callable<Picture> pictureProvider) { |
| 183 if (mHasPendingOnNewPicture) return; | 182 if (mHasPendingOnNewPicture) return; |
| 184 mHasPendingOnNewPicture = true; | 183 mHasPendingOnNewPicture = true; |
| 185 long pictureTime = java.lang.Math.max(mLastPictureTime + ON_NEW_PICTURE_
MIN_PERIOD_MILLIS, | 184 long pictureTime = java.lang.Math.max(mLastPictureTime + ON_NEW_PICTURE_
MIN_PERIOD_MILLIS, |
| 186 SystemClock.uptimeMillis()); | 185 SystemClock.uptimeMillis()); |
| 187 mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pi
ctureProvider), | 186 mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pi
ctureProvider), |
| 188 pictureTime); | 187 pictureTime); |
| 189 } | 188 } |
| 190 | 189 |
| 191 public void postOnScaleChangedScaled(float oldScale, float newScale) { | 190 public void postOnScaleChangedScaled(float oldScale, float newScale) { |
| 192 // The float->int->float conversion here is to avoid unnecessary allocat
ions. The | 191 // The float->int->float conversion here is to avoid unnecessary allocat
ions. The |
| 193 // documentation states that intBitsToFloat(floatToIntBits(a)) == a for
all values of a | 192 // documentation states that intBitsToFloat(floatToIntBits(a)) == a for
all values of a |
| 194 // (except for NaNs which are collapsed to a single canonical NaN, but w
e don't care for | 193 // (except for NaNs which are collapsed to a single canonical NaN, but w
e don't care for |
| 195 // that case). | 194 // that case). |
| 196 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_SCALE_CHANGED_SCALED, | 195 mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_SCALE_CHANGED_SCALED, |
| 197 Float.floatToIntBits(oldScale), Float.floatToIntBits(newScal
e))); | 196 Float.floatToIntBits(oldScale), Float.floatToIntBits(newScal
e))); |
| 198 } | 197 } |
| 199 } | 198 } |
| OLD | NEW |