| Index: blimp/client/app/android/java/src/org/chromium/blimp/app/BlimpRendererActivity.java
|
| diff --git a/blimp/client/app/android/java/src/org/chromium/blimp/app/BlimpRendererActivity.java b/blimp/client/app/android/java/src/org/chromium/blimp/app/BlimpRendererActivity.java
|
| index d92f47630116bb465d4ad810852e573c1b503dc4..aec16b4ba3fac982f9229e3284aef12c4221a4a7 100644
|
| --- a/blimp/client/app/android/java/src/org/chromium/blimp/app/BlimpRendererActivity.java
|
| +++ b/blimp/client/app/android/java/src/org/chromium/blimp/app/BlimpRendererActivity.java
|
| @@ -4,77 +4,46 @@
|
|
|
| package org.chromium.blimp.app;
|
|
|
| -import android.annotation.SuppressLint;
|
| import android.app.Activity;
|
| +import android.content.Context;
|
| import android.content.Intent;
|
| import android.os.Bundle;
|
| -import android.os.Handler;
|
| import android.text.TextUtils;
|
| -import android.view.View;
|
| -import android.widget.TextView;
|
| +import android.view.ViewGroup;
|
| +import android.widget.RelativeLayout;
|
|
|
| -import org.chromium.base.CommandLine;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| import org.chromium.base.library_loader.ProcessInitException;
|
| -import org.chromium.blimp.app.auth.RetryingTokenSource;
|
| -import org.chromium.blimp.app.auth.TokenSource;
|
| -import org.chromium.blimp.app.auth.TokenSourceImpl;
|
| -import org.chromium.blimp.app.preferences.PreferencesUtil;
|
| -import org.chromium.blimp.app.session.BlimpClientSession;
|
| -import org.chromium.blimp.app.session.EngineInfo;
|
| -import org.chromium.blimp.app.session.TabControlFeature;
|
| import org.chromium.blimp.app.toolbar.Toolbar;
|
| -import org.chromium.blimp.app.toolbar.ToolbarMenu;
|
| -import org.chromium.blimp.core.BlimpClientSwitches;
|
| +import org.chromium.blimp_public.BlimpClientContext;
|
| +import org.chromium.blimp_public.BlimpClientContextDelegate;
|
| +import org.chromium.blimp_public.contents.BlimpContents;
|
| import org.chromium.ui.base.WindowAndroid;
|
| -import org.chromium.ui.widget.Toast;
|
|
|
| /**
|
| * The {@link Activity} for rendering the main Blimp client. This loads the Blimp rendering stack
|
| * and displays it.
|
| */
|
| public class BlimpRendererActivity
|
| - extends Activity implements BlimpLibraryLoader.Callback, TokenSource.Callback,
|
| - BlimpClientSession.ConnectionObserver,
|
| - ToolbarMenu.ToolbarMenuDelegate, Toolbar.ToolbarDelegate {
|
| - private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100;
|
| + extends Activity implements BlimpLibraryLoader.Callback, BlimpClientContextDelegate {
|
| private static final String TAG = "BlimpRendActivity";
|
|
|
| - // Refresh interval for the debug view in milliseconds.
|
| - private static final int DEBUG_VIEW_REFRESH_INTERVAL = 1000;
|
| - private static final int BYTES_PER_KILO = 1024;
|
| -
|
| - /** Provides user authentication tokens that can be used to query for engine assignments. This
|
| - * can potentially query GoogleAuthUtil for an OAuth2 authentication token with userinfo.email
|
| - * privileges for a chosen Android account. */
|
| - private TokenSource mTokenSource;
|
| -
|
| private BlimpContentsDisplay mBlimpContentsDisplay;
|
| private Toolbar mToolbar;
|
| - private BlimpClientSession mBlimpClientSession;
|
| - private TabControlFeature mTabControlFeature;
|
| private WindowAndroid mWindowAndroid;
|
| -
|
| - private Handler mHandler = new Handler();
|
| + private BlimpEnvironment mBlimpEnvironment;
|
|
|
| private boolean mFirstUrlLoadDone = false;
|
|
|
| // Flag to record the base value of the metrics when the debug view is turned on.
|
| - private boolean mStatsBaseRecorded = false;
|
| - private int mSentBase;
|
| - private int mReceivedBase;
|
| - private int mCommitsBase;
|
| - private int mSent;
|
| - private int mReceived;
|
| - private int mCommits;
|
| - private String mToken = null;
|
| + private BlimpContents mBlimpContents;
|
| + private BlimpClientContext mBlimpClientContext;
|
|
|
| @Override
|
| @SuppressFBWarnings("DM_EXIT") // FindBugs doesn't like System.exit().
|
| protected void onCreate(Bundle savedInstanceState) {
|
| super.onCreate(savedInstanceState);
|
| - buildAndTriggerTokenSourceIfNeeded();
|
| try {
|
| BlimpLibraryLoader.startAsync(this);
|
| } catch (ProcessInitException e) {
|
| @@ -86,56 +55,33 @@ public class BlimpRendererActivity
|
|
|
| @Override
|
| protected void onDestroy() {
|
| - if (mTabControlFeature != null) {
|
| - mTabControlFeature.destroy();
|
| - mTabControlFeature = null;
|
| - }
|
| -
|
| if (mBlimpContentsDisplay != null) {
|
| mBlimpContentsDisplay.destroyRenderer();
|
| mBlimpContentsDisplay = null;
|
| }
|
|
|
| - if (mToolbar != null) {
|
| - mToolbar.destroy();
|
| - mToolbar = null;
|
| + if (mBlimpContents != null) {
|
| + mBlimpContents.destroy();
|
| + mBlimpContents = null;
|
| }
|
|
|
| - if (mTokenSource != null) {
|
| - mTokenSource.destroy();
|
| - mTokenSource = null;
|
| - }
|
| + mBlimpClientContext = null;
|
|
|
| - // Destroy the BlimpClientSession last, as all other features may rely on it.
|
| - if (mBlimpClientSession != null) {
|
| - mBlimpClientSession.removeObserver(this);
|
| - mBlimpClientSession.destroy();
|
| - mBlimpClientSession = null;
|
| + if (mBlimpEnvironment != null) {
|
| + mBlimpEnvironment.destroy();
|
| + mBlimpEnvironment = null;
|
| }
|
|
|
| super.onDestroy();
|
| }
|
|
|
| @Override
|
| - protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
| - switch (requestCode) {
|
| - case ACCOUNT_CHOOSER_INTENT_REQUEST_CODE:
|
| - if (resultCode == RESULT_OK) {
|
| - mTokenSource.onAccountSelected(data);
|
| - mTokenSource.getToken();
|
| - } else {
|
| - onTokenUnavailable(false);
|
| - }
|
| - break;
|
| - default:
|
| - break;
|
| - }
|
| - }
|
| -
|
| - @Override
|
| public void onBackPressed() {
|
| // Check if the toolbar can handle the back navigation.
|
| - if (mToolbar != null && mToolbar.onBackPressed()) return;
|
| + if (mToolbar != null) {
|
| + mToolbar.onBackPressed();
|
| + return;
|
| + }
|
|
|
| // If not, use the default Activity behavior.
|
| super.onBackPressed();
|
| @@ -153,56 +99,25 @@ public class BlimpRendererActivity
|
| setContentView(R.layout.blimp_main);
|
|
|
| mWindowAndroid = new WindowAndroid(BlimpRendererActivity.this);
|
| - mBlimpClientSession =
|
| - new BlimpClientSession(PreferencesUtil.findAssignerUrl(this), mWindowAndroid);
|
| - mBlimpClientSession.addObserver(this);
|
|
|
| - mBlimpContentsDisplay = (BlimpContentsDisplay) findViewById(R.id.renderer);
|
| - mBlimpContentsDisplay.initializeRenderer(mBlimpClientSession);
|
| + mBlimpEnvironment = BlimpEnvironment.getInstance();
|
|
|
| - mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
| - mToolbar.initialize(mBlimpClientSession, this);
|
| + mBlimpClientContext = mBlimpEnvironment.getBlimpClientContext();
|
| + mBlimpContents = mBlimpClientContext.createBlimpContents(mWindowAndroid);
|
| + mBlimpContentsDisplay = (BlimpContentsDisplay) findViewById(R.id.contents_display);
|
| + mBlimpContentsDisplay.initializeRenderer(mBlimpEnvironment, mBlimpContents);
|
|
|
| - mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpContentsDisplay);
|
| + RelativeLayout.LayoutParams params =
|
| + new RelativeLayout.LayoutParams(mBlimpContentsDisplay.getLayoutParams());
|
| + params.addRule(RelativeLayout.BELOW, R.id.toolbar);
|
| + ((ViewGroup) findViewById(R.id.container)).addView(mBlimpContents.getView(), params);
|
|
|
| - handleUrlFromIntent(getIntent());
|
| + mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
| + mToolbar.initialize(mBlimpContents);
|
|
|
| - // If Blimp client has command line flag "engine-ip", client will use the command line token
|
| - // to connect. See GetAssignmentFromCommandLine() in
|
| - // blimp/client/session/assignment_source.cc
|
| - // In normal cases, where client uses the engine ip given by the Assigner,
|
| - // connection to the engine is triggered by the successful retrieval of a token as
|
| - // TokenSource.Callback.
|
| - if (CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGINE_IP)) {
|
| - mBlimpClientSession.connect(null);
|
| - } else {
|
| - if (mToken != null) {
|
| - mBlimpClientSession.connect(mToken);
|
| - mToken = null;
|
| - }
|
| - }
|
| - }
|
| + mBlimpClientContext.connect();
|
|
|
| - // ToolbarMenu.ToolbarMenuDelegate implementation.
|
| - @Override
|
| - public void showDebugView(boolean show) {
|
| - View debugView = findViewById(R.id.debug_stats);
|
| - debugView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
| - if (show) {
|
| - Runnable debugStatsRunnable = new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - if (mToolbar.getToolbarMenu().isDebugInfoEnabled()) {
|
| - int[] metrics = mBlimpClientSession.getDebugStats();
|
| - updateDebugStats(metrics);
|
| - mHandler.postDelayed(this, DEBUG_VIEW_REFRESH_INTERVAL);
|
| - }
|
| - }
|
| - };
|
| - debugStatsRunnable.run();
|
| - } else {
|
| - mStatsBaseRecorded = false;
|
| - }
|
| + handleUrlFromIntent(getIntent());
|
| }
|
|
|
| @Override
|
| @@ -244,98 +159,12 @@ public class BlimpRendererActivity
|
| mToolbar.loadUrl(url == null ? "http://www.google.com/" : url);
|
| }
|
|
|
| - // TokenSource.Callback implementation.
|
| @Override
|
| - public void onTokenReceived(String token) {
|
| - if (mBlimpClientSession != null) {
|
| - mBlimpClientSession.connect(token);
|
| - } else {
|
| - mToken = token;
|
| - }
|
| + public void restartBrowser() {
|
| + Intent intent = BrowserRestartActivity.createRestartIntent(this);
|
| + startActivity(intent);
|
| }
|
|
|
| @Override
|
| - public void onTokenUnavailable(boolean isTransient) {
|
| - // Ignore isTransient here because we're relying on the auto-retry TokenSource.
|
| - // TODO(dtrainor): Show a better error dialog/message.
|
| - Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG).show();
|
| - }
|
| -
|
| - @Override
|
| - public void onNeedsAccountToBeSelected(Intent suggestedIntent) {
|
| - startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_CODE);
|
| - }
|
| -
|
| - // BlimpClientSession.ConnectionObserver interface.
|
| - @Override
|
| - public void onAssignmentReceived(
|
| - int result, int suggestedMessageResourceId, EngineInfo engineInfo) {
|
| - Toast.makeText(this, suggestedMessageResourceId, Toast.LENGTH_LONG).show();
|
| - }
|
| -
|
| - @Override
|
| - public void onConnected() {
|
| - Toast.makeText(this, R.string.network_connected, Toast.LENGTH_SHORT).show();
|
| - }
|
| -
|
| - /**
|
| - * Displays debug metrics up to one decimal place.
|
| - */
|
| - @Override
|
| - @SuppressLint("DefaultLocale")
|
| - public void updateDebugStatsUI(int received, int sent, int commits) {
|
| - TextView tv = (TextView) findViewById(R.id.bytes_received_client);
|
| - tv.setText(String.format("%.1f", (float) received / BYTES_PER_KILO));
|
| - tv = (TextView) findViewById(R.id.bytes_sent_client);
|
| - tv.setText(String.format("%.1f", (float) sent / BYTES_PER_KILO));
|
| - tv = (TextView) findViewById(R.id.commit_count);
|
| - tv.setText(String.valueOf(commits));
|
| - }
|
| -
|
| - private void updateDebugStats(int[] metrics) {
|
| - assert metrics.length == 3;
|
| - mReceived = metrics[0];
|
| - mSent = metrics[1];
|
| - mCommits = metrics[2];
|
| - if (!mStatsBaseRecorded) {
|
| - mReceivedBase = mReceived;
|
| - mSentBase = mSent;
|
| - mCommitsBase = mCommits;
|
| - mStatsBaseRecorded = true;
|
| - }
|
| - updateDebugStatsUI(mReceived - mReceivedBase, mSent - mSentBase, mCommits - mCommitsBase);
|
| - }
|
| -
|
| - // Toolbar.ToolbarDelegate interface.
|
| - @Override
|
| - public void resetDebugStats() {
|
| - mReceivedBase = mReceived;
|
| - mSentBase = mSent;
|
| - mCommitsBase = mCommits;
|
| - }
|
| -
|
| - @Override
|
| - public void onDisconnected(String reason) {
|
| - Toast.makeText(this,
|
| - String.format(getResources().getString(R.string.network_disconnected), reason),
|
| - Toast.LENGTH_LONG)
|
| - .show();
|
| - }
|
| -
|
| - private void buildAndTriggerTokenSourceIfNeeded() {
|
| - // If Blimp client is given the engine ip by the command line, then there is no need to
|
| - // build a TokenSource, because token, engine ip, engine port, and transport protocol are
|
| - // all given by command line.
|
| - if (CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGINE_IP)) return;
|
| -
|
| - // Build a TokenSource that will internally retry accessing the underlying
|
| - // TokenSourceImpl. This will exponentially backoff while it tries to get the access
|
| - // token. See {@link RetryingTokenSource} for more information. The underlying
|
| - // TokenSourceImpl will attempt to query GoogleAuthUtil, but might fail if there is no
|
| - // account selected, in which case it will ask this Activity to show an account chooser
|
| - // and notify it of the selection result.
|
| - mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this));
|
| - mTokenSource.setCallback(this);
|
| - mTokenSource.getToken();
|
| - }
|
| + public void startUserSignInFlow(Context context) {}
|
| }
|
|
|