Ejemplo n.º 1
0
  private void initialize(Context context) {

    Log.i("Ludei", "***************************");
    Log.i("Ludei", "Initializing Ludei WebView+");
    Log.i("Ludei", "**************************");

    if (!staticInitialization) {
      PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
      ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES);
      ResourceProvider.registerResources();
      staticInitialization = true;
    }

    this.ctx = context;
    if (mProxyWebView == null) {
      mProxyWebView = new LudeiWebView(context, null, 0, this);
    }
    mBridge =
        new LudeiContentsClientBridge(
            mProxyWebView, new LudeiDefaultWebChromeClient(this.ctx, this));
    mDelegate = new LudeiContentViewDelegate(this, mBridge);

    // Initializing the command line must occur before loading the library.
    if (!CommandLine.isInitialized()) {
      CommandLine.initFromFile(COMMAND_LINE_FILE);
      String[] commandLineParams = null; // getCommandLineParamsFromIntent(getIntent());

      if (commandLineParams != null) {
        CommandLine.getInstance().appendSwitchesAndArguments(commandLineParams);
      }
      CommandLine.getInstance().appendSwitch("allow-file-access-from-files");
      if (!LudeiContentView.REMOTE_DEBUGGING) {
        CommandLine.getInstance().appendSwitch("disable-remote-debugging");
      }
      CommandLine.getInstance().appendSwitch("ignore-gpu-blacklist");
    }
    waitForDebuggerIfNeeded();

    DeviceUtils.addDeviceSpecificUserAgentSwitch(context);
    try {
      org.chromium.base.library_loader.LibraryLoader.ensureInitialized();
    } catch (ProcessInitException e) {
      Log.e(TAG, "ContentView initialization failed.", e);
      // Since the library failed to initialize nothing in the application
      // can work, so kill the whole application not just the activity
      System.exit(-1);
      return;
    }

    mSettings = LudeiWebSettingsProxy.Create(context, (new LudeiWebSettings(context, true, false)));
    shellManager = new ShellManager(context, null, this, mDelegate);

    WindowAndroid mWindowAndroid = new ActivityWindowAndroid((Activity) ctx);
    // mWindowAndroid.restoreInstanceState(savedInstanceState);
    shellManager.setWindow(
        mWindowAndroid,
        new Runnable() {
          @Override
          public void run() {
            LudeiContentView.this.onReadyToRender();
          }
        });

    if (CommandLine.getInstance().hasSwitch(ContentSwitches.DUMP_RENDER_TREE)) {
      try {
        BrowserStartupController.get(context).startBrowserProcessesSync(true);
      } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to load native library.", e);
        System.exit(-1);
      }
    } else {
      try {
        BrowserStartupController.get(context)
            .startBrowserProcessesAsync(
                new BrowserStartupController.StartupCallback() {
                  @Override
                  public void onSuccess(boolean alreadyStarted) {
                    // finishInitialization(savedInstanceState);
                    finishInitialization(null);
                  }

                  @Override
                  public void onFailure() {
                    initializationFailed();
                  }
                });
      } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        System.exit(-1);
      }
    }
  }