예제 #1
0
  private static String initGeckoEnvironment() {
    final Context context = GeckoAppShell.getApplicationContext();
    GeckoLoader.loadMozGlue(context);
    setState(State.MOZGLUE_READY);

    final Locale locale = Locale.getDefault();
    final Resources res = context.getResources();
    if (locale.toString().equalsIgnoreCase("zh_hk")) {
      final Locale mappedLocale = Locale.TRADITIONAL_CHINESE;
      Locale.setDefault(mappedLocale);
      Configuration config = res.getConfiguration();
      config.locale = mappedLocale;
      res.updateConfiguration(config, null);
    }

    String[] pluginDirs = null;
    try {
      pluginDirs = GeckoAppShell.getPluginDirectories();
    } catch (Exception e) {
      Log.w(LOGTAG, "Caught exception getting plugin dirs.", e);
    }

    final String resourcePath = context.getPackageResourcePath();
    GeckoLoader.setupGeckoEnvironment(context, pluginDirs, context.getFilesDir().getPath());

    GeckoLoader.loadSQLiteLibs(context, resourcePath);
    GeckoLoader.loadNSSLibs(context, resourcePath);
    GeckoLoader.loadGeckoLibs(context, resourcePath);
    setState(State.LIBS_READY);

    return resourcePath;
  }
 @Override
 public void onCreate() {
   HardwareUtils.init(getApplicationContext());
   Clipboard.init(getApplicationContext());
   GeckoLoader.loadMozGlue(getApplicationContext());
   super.onCreate();
 }
예제 #3
0
  @RobocopTarget
  public static String decrypt(Context context, String profilePath, String aValue)
      throws Exception {
    String resourcePath = context.getPackageResourcePath();
    GeckoLoader.loadNSSLibs(context, resourcePath);

    return nativeDecrypt(profilePath, aValue);
  }
예제 #4
0
  @RobocopTarget
  public static String encrypt(Context context, String aValue) throws Exception {
    String resourcePath = context.getPackageResourcePath();
    GeckoLoader.loadNSSLibs(context, resourcePath);

    String path = GeckoProfile.get(context).getDir().toString();
    return nativeEncrypt(path, aValue);
  }
예제 #5
0
  private void init(Context context, String url, boolean doInit) {
    // TODO: Fennec currently takes care of its own initialization, so this
    // flag is a hack used in Fennec to prevent GeckoView initialization.
    // This should go away once Fennec also uses GeckoView for
    // initialization.
    if (!doInit) return;

    // If running outside of a GeckoActivity (eg, from a library project),
    // load the native code and disable content providers
    boolean isGeckoActivity = false;
    try {
      isGeckoActivity = context instanceof GeckoActivity;
    } catch (NoClassDefFoundError ex) {
    }

    if (!isGeckoActivity) {
      // Set the GeckoInterface if the context is an activity and the GeckoInterface
      // has not already been set
      if (context instanceof Activity && getGeckoInterface() == null) {
        setGeckoInterface(new BaseGeckoInterface(context));
      }

      Clipboard.init(context);
      HardwareUtils.init(context);

      // If you want to use GeckoNetworkManager, start it.

      GeckoLoader.loadMozGlue();
      BrowserDB.setEnableContentProviders(false);
    }

    if (url != null) {
      GeckoThread.setUri(url);
      GeckoThread.setAction(Intent.ACTION_VIEW);
      GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(url));
    }
    GeckoAppShell.setContextGetter(this);
    if (context instanceof Activity) {
      Tabs tabs = Tabs.getInstance();
      tabs.attachToContext(context);
    }

    EventDispatcher.getInstance()
        .registerGeckoThreadListener(
            this,
            "Gecko:Ready",
            "Content:StateChange",
            "Content:LoadError",
            "Content:PageShow",
            "DOMTitleChanged",
            "Link:Favicon",
            "Prompt:Show",
            "Prompt:ShowTop");

    ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
    initializeView(EventDispatcher.getInstance());

    if (GeckoThread.checkAndSetLaunchState(
        GeckoThread.LaunchState.Launching, GeckoThread.LaunchState.Launched)) {
      // This is the first launch, so finish initialization and go.
      GeckoProfile profile = GeckoProfile.get(context).forceCreate();
      BrowserDB.initialize(profile.getName());

      GeckoAppShell.setLayerView(this);
      GeckoThread.createAndStart();
    } else if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
      // If Gecko is already running, that means the Activity was
      // destroyed, so we need to re-attach Gecko to this GeckoView.
      connectToGecko();
    }
  }
예제 #6
0
  @Override
  public void run() {
    Looper.prepare();
    GeckoThread.msgQueue = Looper.myQueue();
    ThreadUtils.sGeckoThread = this;
    ThreadUtils.sGeckoHandler = new Handler();

    // Preparation for pumpMessageLoop()
    final MessageQueue.IdleHandler idleHandler =
        new MessageQueue.IdleHandler() {
          @Override
          public boolean queueIdle() {
            final Handler geckoHandler = ThreadUtils.sGeckoHandler;
            Message idleMsg = Message.obtain(geckoHandler);
            // Use |Message.obj == GeckoHandler| to identify our "queue is empty" message
            idleMsg.obj = geckoHandler;
            geckoHandler.sendMessageAtFrontOfQueue(idleMsg);
            // Keep this IdleHandler
            return true;
          }
        };
    Looper.myQueue().addIdleHandler(idleHandler);

    if (mDebugging) {
      try {
        Thread.sleep(5 * 1000 /* 5 seconds */);
      } catch (final InterruptedException e) {
      }
    }

    final String args = getGeckoArgs(initGeckoEnvironment());

    // This can only happen after the call to initGeckoEnvironment
    // above, because otherwise the JNI code hasn't been loaded yet.
    ThreadUtils.postToUiThread(
        new Runnable() {
          @Override
          public void run() {
            GeckoAppShell.registerJavaUiThread();
          }
        });

    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - runGecko");

    if (!AppConstants.MOZILLA_OFFICIAL) {
      Log.i(LOGTAG, "RunGecko - args = " + args);
    }

    // And go.
    GeckoLoader.nativeRun(args);

    // And... we're done.
    setState(State.EXITED);

    try {
      final JSONObject msg = new JSONObject();
      msg.put("type", "Gecko:Exited");
      EventDispatcher.getInstance().dispatchEvent(msg, null);
    } catch (final JSONException e) {
      Log.e(LOGTAG, "unable to dispatch event", e);
    }

    // Remove pumpMessageLoop() idle handler
    Looper.myQueue().removeIdleHandler(idleHandler);
  }