Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/WindowAndroid.java |
| diff --git a/ui/android/java/src/org/chromium/ui/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/WindowAndroid.java |
| index 7c8141bffe448094c0ba1600d1c7b228f7c58e7e..bc05608ff11db1288186e52dc4b06e8a823a8d11 100644 |
| --- a/ui/android/java/src/org/chromium/ui/WindowAndroid.java |
| +++ b/ui/android/java/src/org/chromium/ui/WindowAndroid.java |
| @@ -4,20 +4,14 @@ |
| package org.chromium.ui; |
| -import android.app.Activity; |
| -import android.content.ActivityNotFoundException; |
| import android.content.ContentResolver; |
| import android.content.Context; |
| import android.content.Intent; |
| -import android.graphics.Bitmap; |
| -import android.graphics.Rect; |
| import android.os.Bundle; |
| import android.util.Log; |
| import android.util.SparseArray; |
| -import android.view.View; |
| import android.widget.Toast; |
| -import java.io.ByteArrayOutputStream; |
| import java.util.HashMap; |
| import org.chromium.base.CalledByNative; |
| @@ -28,33 +22,26 @@ import org.chromium.base.JNINamespace; |
| */ |
| @JNINamespace("ui") |
| public class WindowAndroid { |
| - |
| private static final String TAG = "WindowAndroid"; |
| // Native pointer to the c++ WindowAndroid object. |
| private int mNativeWindowAndroid = 0; |
| - // Constants used for intent request code bounding. |
| - private static final int REQUEST_CODE_PREFIX = 1000; |
| - private static final int REQUEST_CODE_RANGE_SIZE = 100; |
| // A string used as a key to store intent errors in a bundle |
| static final String WINDOW_CALLBACK_ERRORS = "window_callback_errors"; |
| - private int mNextRequestCode = 0; |
| - protected Activity mActivity; |
| protected Context mApplicationContext; |
| protected SparseArray<IntentCallback> mOutstandingIntents; |
| protected HashMap<Integer, String> mIntentErrors; |
| /** |
| - * @param activity |
| + * @param context, the application context.. |
| */ |
| - public WindowAndroid(Activity activity) { |
| - mActivity = activity; |
| - mApplicationContext = mActivity.getApplicationContext(); |
| + public WindowAndroid(Context context) { |
| + assert context == context.getApplicationContext(); |
|
joth
2013/11/09 02:22:11
Can this just be removed?
michaelbai
2013/11/09 06:05:54
I think this make the people use the right class,
|
| + mApplicationContext = context; |
| mOutstandingIntents = new SparseArray<IntentCallback>(); |
| mIntentErrors = new HashMap<Integer, String>(); |
| - |
| } |
| /** |
| @@ -66,19 +53,8 @@ public class WindowAndroid { |
| * @return Whether the intent was shown. |
| */ |
| public boolean showIntent(Intent intent, IntentCallback callback, int errorId) { |
| - int requestCode = REQUEST_CODE_PREFIX + mNextRequestCode; |
| - mNextRequestCode = (mNextRequestCode + 1) % REQUEST_CODE_RANGE_SIZE; |
| - |
| - try { |
| - mActivity.startActivityForResult(intent, requestCode); |
| - } catch (ActivityNotFoundException e) { |
| - return false; |
| - } |
| - |
| - mOutstandingIntents.put(requestCode, callback); |
| - mIntentErrors.put(requestCode, mActivity.getString(errorId)); |
| - |
| - return true; |
| + Log.d(TAG, "Can't show intent as context is not an Activity: " + intent); |
| + return false; |
| } |
| /** |
| @@ -87,7 +63,7 @@ public class WindowAndroid { |
| */ |
| public void showError(String error) { |
| if (error != null) { |
| - Toast.makeText(mActivity, error, Toast.LENGTH_SHORT).show(); |
| + Toast.makeText(mApplicationContext, error, Toast.LENGTH_SHORT).show(); |
| } |
| } |
| @@ -96,7 +72,7 @@ public class WindowAndroid { |
| * @param resId The error message string's resource id. |
| */ |
| public void showError(int resId) { |
| - showError(mActivity.getString(resId)); |
| + showError(mApplicationContext.getString(resId)); |
| } |
| /** |
| @@ -111,17 +87,18 @@ public class WindowAndroid { |
| * Broadcasts the given intent to all interested BroadcastReceivers. |
| */ |
| public void sendBroadcast(Intent intent) { |
| - mActivity.sendBroadcast(intent); |
| + mApplicationContext.sendBroadcast(intent); |
| } |
| /** |
| * TODO(nileshagrawal): Stop returning Activity Context crbug.com/233440. |
| - * @return Activity context. |
| + * @return Activity context, it could be null. Note, in most cases, you probably |
| + * just need Application Context returned by getApplicationContext(). |
| * @see #getApplicationContext() |
| */ |
| @Deprecated |
| public Context getContext() { |
| - return mActivity; |
| + return null; |
| } |
| /** |
| @@ -164,20 +141,6 @@ public class WindowAndroid { |
| * @return Boolean value of whether the intent was started by the native window. |
| */ |
| public boolean onActivityResult(int requestCode, int resultCode, Intent data) { |
| - IntentCallback callback = mOutstandingIntents.get(requestCode); |
| - mOutstandingIntents.delete(requestCode); |
| - String errorMessage = mIntentErrors.remove(requestCode); |
| - |
| - if (callback != null) { |
| - callback.onIntentCompleted(this, resultCode, |
| - mActivity.getContentResolver(), data); |
| - return true; |
| - } else { |
| - if (errorMessage != null) { |
| - showCallbackNonExistentError(errorMessage); |
| - return true; |
| - } |
| - } |
| return false; |
| } |
| @@ -224,31 +187,7 @@ public class WindowAndroid { |
| */ |
| @CalledByNative |
| public byte[] grabSnapshot(int windowX, int windowY, int width, int height) { |
| - try { |
| - // Take a screenshot of the root activity view. This generally includes UI |
| - // controls such as the URL bar and OS windows such as the status bar. |
| - View rootView = mActivity.findViewById(android.R.id.content).getRootView(); |
| - Bitmap bitmap = UiUtils.generateScaledScreenshot(rootView, 0, Bitmap.Config.ARGB_8888); |
| - if (bitmap == null) return null; |
| - |
| - // Clip the result into the requested region. |
| - if (windowX > 0 || windowY > 0 || width != bitmap.getWidth() || |
| - height != bitmap.getHeight()) { |
| - Rect clip = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); |
| - clip.intersect(windowX, windowY, windowX + width, windowY + height); |
| - bitmap = Bitmap.createBitmap( |
| - bitmap, clip.left, clip.top, clip.width(), clip.height()); |
| - } |
| - |
| - // Compress the result into a PNG. |
| - ByteArrayOutputStream result = new ByteArrayOutputStream(); |
| - if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, result)) return null; |
| - bitmap.recycle(); |
| - return result.toByteArray(); |
| - } catch (OutOfMemoryError e) { |
| - Log.e(TAG, "Out of memory while grabbing window snapshot.", e); |
| - return null; |
| - } |
| + return null; |
| } |
| private native int nativeInit(); |