| Index: ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java b/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java
|
| index cc0198c972d7b25a1e00ea4f8bd81df37cd240e5..3782d309f73af821245ba51828e1f578701076b2 100644
|
| --- a/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java
|
| +++ b/ui/android/java/src/org/chromium/ui/gfx/NativeWindow.java
|
| @@ -4,38 +4,22 @@
|
|
|
| package org.chromium.ui.gfx;
|
|
|
| -import android.app.Activity;
|
| -import android.content.ActivityNotFoundException;
|
| import android.content.ContentResolver;
|
| +import android.content.Context;
|
| import android.content.Intent;
|
| -import android.content.res.Resources;
|
| -import android.os.Bundle;
|
| -import android.util.SparseArray;
|
| -import android.widget.Toast;
|
|
|
| import org.chromium.base.JNINamespace;
|
|
|
| -import java.util.HashMap;
|
| -
|
| /**
|
| - * The window that has access to the main activity and is able to create and receive intents,
|
| - * and show error messages.
|
| + * The window base class that has the minimum functionality.
|
| */
|
| @JNINamespace("ui")
|
| -public class NativeWindow {
|
| -
|
| - // 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";
|
| +public abstract class NativeWindow {
|
|
|
| // Native pointer to the c++ WindowAndroid object.
|
| private int mNativeWindowAndroid = 0;
|
| - private int mNextRequestCode = 0;
|
| - protected Activity mActivity;
|
| - private SparseArray<IntentCallback> mOutstandingIntents;
|
| - private HashMap<Integer, String> mIntentErrors;
|
| +
|
| + private Context mContext;
|
|
|
| /**
|
| * An interface that intent callback objects have to implement.
|
| @@ -53,159 +37,44 @@ public class NativeWindow {
|
| }
|
|
|
| /**
|
| - * Constructs a Window object, saves a reference to the main activity, and initializes the
|
| - * outstanding intent map. NativeWindowAndroid gets lazily loaded on getNativePointer().
|
| - * @param activity The main application activity.
|
| + * Constructs a Window object, saves a reference to the context.
|
| + * @param context
|
| */
|
| - public NativeWindow(Activity activity) {
|
| - mActivity = activity;
|
| - mOutstandingIntents = new SparseArray<IntentCallback>();
|
| - mIntentErrors = new HashMap<Integer, String>();
|
| + public NativeWindow(Context context) {
|
| mNativeWindowAndroid = 0;
|
| + mContext = context;
|
| }
|
|
|
| /**
|
| - * Destroys the c++ WindowAndroid object if one has been created.
|
| + * Stub overridden by extending class.
|
| */
|
| - public void destroy() {
|
| - if (mNativeWindowAndroid != 0) {
|
| - nativeDestroy(mNativeWindowAndroid);
|
| - mNativeWindowAndroid = 0;
|
| - }
|
| - }
|
| + abstract public void sendBroadcast(Intent intent);
|
|
|
| /**
|
| - * Shows an intent and returns the results to the callback object.
|
| - * @param intent The intent that needs to be showed.
|
| - * @param callback The object that will receive the results for the intent.
|
| - * @return Whether the intent was shown.
|
| + * Stub overridden by extending class.
|
| */
|
| - public boolean showIntent(Intent intent, IntentCallback callback) {
|
| - return showIntent(intent, callback, null);
|
| - }
|
| + abstract public boolean showIntent(Intent intent, IntentCallback callback, String error);
|
|
|
| /**
|
| - * Shows an intent and returns the results to the callback object.
|
| - * @param intent The intent that needs to be showed.
|
| - * @param callback The object that will receive the results for the intent.
|
| - * @param errorId The id of the error string to be show if activity is paused before intent
|
| - * results.
|
| - * @return Whether the intent was shown.
|
| + * Stub overridden by extending class.
|
| */
|
| - public boolean showIntent(Intent intent, IntentCallback callback, int errorId) {
|
| - String error = null;
|
| - try {
|
| - error = mActivity.getString(errorId);
|
| - } catch (Resources.NotFoundException e) { }
|
| - return showIntent(intent, callback, error);
|
| - }
|
| + abstract public void showError(String error);
|
|
|
| /**
|
| - * Shows an intent and returns the results to the callback object.
|
| - * @param intent The intent that needs to be showed.
|
| - * @param callback The object that will receive the results for the intent.
|
| - * @param error The error string to be show if activity is paused before intent results.
|
| - * @return Whether the intent was shown.
|
| + * @return context.
|
| */
|
| - public boolean showIntent(Intent intent, IntentCallback callback, String error) {
|
| - 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);
|
| - if (error != null) mIntentErrors.put(requestCode, error);
|
| -
|
| - return true;
|
| + public Context getContext() {
|
| + return mContext;
|
| }
|
|
|
| /**
|
| - * Saves the error messages that should be shown if any pending intents would return
|
| - * after the application has been put onPause.
|
| - * @param bundle The bundle to save the information in onPause
|
| - */
|
| - public void saveInstanceState(Bundle bundle) {
|
| - bundle.putSerializable(WINDOW_CALLBACK_ERRORS, mIntentErrors);
|
| - }
|
| -
|
| - /**
|
| - * Restores the error messages that should be shown if any pending intents would return
|
| - * after the application has been put onPause.
|
| - * @param bundle The bundle to restore the information from onResume
|
| - */
|
| - public void restoreInstanceState(Bundle bundle) {
|
| - if (bundle == null) return;
|
| -
|
| - Object errors = bundle.getSerializable(WINDOW_CALLBACK_ERRORS);
|
| - if (errors instanceof HashMap) {
|
| - @SuppressWarnings("unchecked")
|
| - HashMap<Integer, String> intentErrors = (HashMap<Integer, String>) errors;
|
| - mIntentErrors = intentErrors;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Displays an error message with a provided error message string.
|
| - * @param error The error message string to be displayed.
|
| - */
|
| - public void showError(String error) {
|
| - if (error != null) Toast.makeText(mActivity, error, Toast.LENGTH_SHORT).show();
|
| - }
|
| -
|
| - /**
|
| - * Displays an error message with a provided error message string id.
|
| - * @param errorId The string id of the error message string to be displayed.
|
| - */
|
| - public void showError(int errorId) {
|
| - String error = null;
|
| - try {
|
| - error = mActivity.getString(errorId);
|
| - } catch (Resources.NotFoundException e) { }
|
| - showError(error);
|
| - }
|
| -
|
| - /**
|
| - * Displays an error message for a nonexistent callback.
|
| - * @param error The error message string to be displayed.
|
| - */
|
| - protected void showCallbackNonExistentError(String error) {
|
| - showError(error);
|
| - }
|
| -
|
| - /**
|
| - * @return The main application activity.
|
| - */
|
| - public Activity getActivity() {
|
| - return mActivity;
|
| - }
|
| -
|
| - /**
|
| - * Responds to the intent result if the intent was created by the native window.
|
| - * @param requestCode Request code of the requested intent.
|
| - * @param resultCode Result code of the requested intent.
|
| - * @param data The data returned by the intent.
|
| - * @return Boolean value of whether the intent was started by the native window.
|
| + * Destroys the c++ WindowAndroid object if one has been created.
|
| */
|
| - 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;
|
| - }
|
| + public void destroy() {
|
| + if (mNativeWindowAndroid != 0) {
|
| + nativeDestroy(mNativeWindowAndroid);
|
| + mNativeWindowAndroid = 0;
|
| }
|
| - return false;
|
| }
|
|
|
| /**
|
|
|