Commit e44c2b26 authored by Jim Chen's avatar Jim Chen
Browse files

Bug 1442255 - 4. Use extras bundle to initialize Gecko in Fennec; r=esawin

Use extras bundle (e.g. from an Intent) to initialize Gecko in GeckoApp
and GeckoService.

MozReview-Commit-ID: AmLZ8Uir8f4

--HG--
extra : rebase_source : 89b93e482eb4cd90760fd22f7702b6c1fa71ec10
parent 66578430
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -969,11 +969,6 @@ public abstract class GeckoApp extends GeckoActivity

        earlyStartJavaSampler(intent);

        // GeckoLoader wants to dig some environment variables out of the
        // incoming intent, so pass it in here. GeckoLoader will do its
        // business later and dispose of the reference.
        GeckoLoader.setLastIntent(intent);

        // Workaround for <http://code.google.com/p/android/issues/detail?id=20915>.
        try {
            Class.forName("android.os.AsyncTask");
@@ -1012,12 +1007,12 @@ public abstract class GeckoApp extends GeckoActivity

        } else {
            final String action = intent.getAction();
            final String args = GeckoApplication.addDefaultGeckoArgs(
                    intent.getStringExtra("args"));
            final String[] args = GeckoApplication.getDefaultGeckoArgs();
            final int flags = ACTION_DEBUG.equals(action) ? GeckoThread.FLAG_DEBUGGING : 0;

            sAlreadyLoaded = true;
            GeckoThread.initMainProcess(/* profile */ null, args, flags);
            GeckoThread.initMainProcess(/* profile */ null, args,
                                        intent.getExtras(), flags);

            // Speculatively pre-fetch the profile in the background.
            ThreadUtils.postToBackgroundThread(new Runnable() {
+4 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import android.os.Environment;
import android.os.Process;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.text.TextUtils;
import android.util.Base64;
@@ -102,7 +103,7 @@ public class GeckoApplication extends Application
        return sSessionUUID;
    }

    public static String addDefaultGeckoArgs(String args) {
    public static @Nullable String[] getDefaultGeckoArgs() {
        if (!AppConstants.MOZILLA_OFFICIAL) {
            // In un-official builds, we want to load Javascript resources fresh
            // with each build.  In official builds, the startup cache is purged by
@@ -110,9 +111,9 @@ public class GeckoApplication extends Application
            // buildid, so we purge here instead.
            Log.w(LOG_TAG, "STARTUP PERFORMANCE WARNING: un-official build: purging the " +
                           "startup (JavaScript) caches.");
            args = (args != null) ? (args + " -purgecaches") : "-purgecaches";
            return new String[] { "-purgecaches" };
        }
        return args;
        return null;
    }

    public static String getDefaultUAString() {
+7 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.app.Service;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Handler;
import android.os.Looper;
@@ -115,6 +116,11 @@ public class GeckoService extends Service {

    private static Intent getIntentForAction(final Context context, final String action) {
        final Intent intent = new Intent(action, /* uri */ null, context, GeckoService.class);
        final Bundle extras = GeckoThread.getActiveExtras();
        if (extras != null && extras.size() > 0) {
            intent.replaceExtras(extras);
        }

        final GeckoProfile profile = GeckoThread.getActiveProfile();
        if (profile != null) {
            setIntentProfile(intent, profile.getName(), profile.getDir().getAbsolutePath());
@@ -162,7 +168,7 @@ public class GeckoService extends Service {

        if (!GeckoThread.initMainProcessWithProfile(
                profileName, profileDir != null ? new File(profileDir) : null,
                GeckoApplication.addDefaultGeckoArgs(null))) {
                GeckoApplication.getDefaultGeckoArgs(), intent.getExtras())) {
            Log.w(LOGTAG, "Ignoring due to profile mismatch: " +
                          profileName + " [" + profileDir + ']');

+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

@@ -324,6 +325,10 @@ public class GeckoThread extends Thread {
            args.add(profile.getName());
        }

        if (mArgs != null) {
            args.addAll(Arrays.asList(mArgs));
        }

        final String extraArgs = mExtras.getString(EXTRA_ARGS, null);
        if (extraArgs != null) {
            final StringTokenizer st = new StringTokenizer(extraArgs);
+13 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ package org.mozilla.gecko.mozglue;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.ArrayList;
@@ -41,6 +42,18 @@ public class SafeIntent {
        }
    }

    public @Nullable Bundle getExtras() {
        try {
            return intent.getExtras();
        } catch (OutOfMemoryError e) {
            Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
            return null;
        } catch (RuntimeException e) {
            Log.w(LOGTAG, "Couldn't get intent extras.", e);
            return null;
        }
    }

    public boolean getBooleanExtra(final String name, final boolean defaultValue) {
        try {
            return intent.getBooleanExtra(name, defaultValue);