コード例 #1
0
 private static Intent getIntentForAction(final Context context, final String action) {
   final Intent intent = new Intent(action, /* uri */ null, context, GeckoService.class);
   final GeckoProfile profile = GeckoThread.getActiveProfile();
   if (profile != null) {
     setIntentProfile(intent, profile.getName(), profile.getDir().getAbsolutePath());
   }
   return intent;
 }
コード例 #2
0
  private int handleIntent(final Intent intent, final int startId) {
    if (DEBUG) {
      Log.d(LOGTAG, "Handling " + intent.getAction());
    }

    final String profileName = intent.getStringExtra(INTENT_PROFILE_NAME);
    final String profileDir = intent.getStringExtra(INTENT_PROFILE_DIR);

    if (profileName == null || profileDir == null) {
      throw new IllegalArgumentException("Intent must specify profile.");
    }

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

      final GeckoProfile profile = GeckoThread.getActiveProfile();
      if (profile != null) {
        Log.w(
            LOGTAG,
            "Current profile is "
                + profile.getName()
                + " ["
                + profile.getDir().getAbsolutePath()
                + ']');
      }
      stopSelf(startId);
      return Service.START_NOT_STICKY;
    }

    GeckoThread.launch();

    switch (intent.getAction()) {
      case INTENT_ACTION_UPDATE_ADDONS:
        // Run the add-on update service. Because the service is automatically invoked
        // when loading Gecko, we don't have to do anything else here.
        break;

      case INTENT_ACTION_CREATE_SERVICES:
        final String category = intent.getStringExtra(INTENT_SERVICE_CATEGORY);

        if (category == null) {
          break;
        }
        GeckoThread.createServices(category);
        break;

      default:
        Log.w(LOGTAG, "Unknown request: " + intent);
    }

    stopSelf(startId);
    return Service.START_NOT_STICKY;
  }
コード例 #3
0
 private static void fillIntentWithProfileInfo(final Context context, final Intent intent) {
   // There is a race here, but GeckoProfile returns the default profile
   // when Gecko is not explicitly running for a different profile.  In a
   // multi-profile world, this will need to be updated (possibly to
   // broadcast settings for all profiles).  See Bug 882182.
   GeckoProfile profile = GeckoProfile.get(context);
   if (profile != null) {
     intent
         .putExtra("profileName", profile.getName())
         .putExtra("profilePath", profile.getDir().getAbsolutePath());
   }
 }
コード例 #4
0
ファイル: GeckoView.java プロジェクト: nikaiw/gecko-dev
  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();
    }
  }