Ejemplo n.º 1
0
  /** Launch browser and open file url. If debug mode also connect to browser. */
  void connectToChromiumDebug(
      File executable,
      String browserName,
      ILaunch launch,
      DartLaunchConfigWrapper launchConfig,
      String url,
      IProgressMonitor monitor,
      Process runtimeProcess,
      LogTimer timer,
      boolean enableBreakpoints,
      int devToolsPortNumber,
      ListeningStream dartiumOutput,
      String processDescription)
      throws CoreException {
    monitor.worked(1);

    try {
      // avg: 383ms
      timer.startTask("get chromium tabs");

      ChromiumTabInfo chromiumTab =
          getChromiumTab(runtimeProcess, devToolsPortNumber, dartiumOutput);

      monitor.worked(2);

      timer.stopTask();

      // avg: 46ms
      timer.startTask("open WIP connection");

      if (chromiumTab == null) {
        throw new DebugException(
            new Status(
                IStatus.ERROR, DartDebugCorePlugin.PLUGIN_ID, "Unable to connect to Dartium"));
      }

      if (chromiumTab == null || chromiumTab.getWebSocketDebuggerUrl() == null) {
        throw new DebugException(
            new Status(
                IStatus.ERROR, DartDebugCorePlugin.PLUGIN_ID, "Unable to connect to Chromium"));
      }

      WebkitConnection connection = new WebkitConnection(chromiumTab.getWebSocketDebuggerUrl());

      final DartiumDebugTarget debugTarget =
          new DartiumDebugTarget(
              executable,
              browserName,
              connection,
              launch,
              runtimeProcess,
              getResourceServer(),
              enableBreakpoints);

      monitor.worked(1);

      launch.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8");
      launch.addDebugTarget(debugTarget);
      launch.addProcess(debugTarget.getProcess());
      debugTarget.getProcess().setAttribute(IProcess.ATTR_CMDLINE, processDescription);

      if (launchConfig.getShowLaunchOutput()) {
        dartiumOutput.setListener(
            new StreamListener() {
              @Override
              public void handleStreamData(String data) {
                debugTarget.writeToStdout(data);
              }
            });
      }

      debugTarget.openConnection(url);

      timer.stopTask();
    } catch (IOException e) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);

      IStatus status;

      // Clean up the error message on certain connection failures to Dartium.
      // http://code.google.com/p/dart/issues/detail?id=4435
      if (e.toString().indexOf("connection failed: unknown status code 500") != -1) {
        DartDebugCorePlugin.logError(e);

        status =
            new Status(
                IStatus.ERROR, DartDebugCorePlugin.PLUGIN_ID, "Unable to connect to Dartium");
      } else {
        status = new Status(IStatus.ERROR, DartDebugCorePlugin.PLUGIN_ID, e.toString(), e);
      }

      throw new CoreException(status);
    }

    if (firstLaunch) {
      firstLaunch = false;
    }

    monitor.worked(1);
  }
Ejemplo n.º 2
0
  protected void launchBrowser(
      ILaunch launch,
      DartLaunchConfigWrapper launchConfig,
      IFile file,
      String url,
      IProgressMonitor monitor,
      boolean enableDebugging)
      throws CoreException {

    // For now, we always start a debugging connection, even when we're not really debugging.
    boolean enableBreakpoints = enableDebugging;

    monitor.beginTask("Launching Dartium...", enableDebugging ? 7 : 2);

    File dartium = DartSdkManager.getManager().getSdk().getDartiumExecutable();

    if (dartium == null) {
      throw new CoreException(
          new Status(IStatus.ERROR, DartDebugCorePlugin.PLUGIN_ID, "Could not find Dartium"));
    }

    IPath browserLocation = new Path(dartium.getAbsolutePath());

    String browserName = dartium.getName();

    // avg: 0.434 sec (old: 0.597)
    LogTimer timer = new LogTimer("Dartium debug startup");

    // avg: 55ms
    timer.startTask(browserName + " startup");

    url = resolveLaunchUrl(file, url);

    // for now, check if browser is open, and connection is alive
    boolean restart =
        browserProcess == null
            || isProcessTerminated(browserProcess)
            || DartiumDebugTarget.getActiveTarget() == null
            || !DartiumDebugTarget.getActiveTarget().canTerminate();

    if (!restart) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);

      try {
        DartiumDebugTarget.getActiveTarget().navigateToUrl(url, enableBreakpoints);
      } catch (IOException e) {
        DartDebugCorePlugin.logError(e);
      }
    } else {
      terminateExistingBrowserProcess();

      StringBuilder processDescription = new StringBuilder();

      ListeningStream dartiumOutput =
          startNewBrowserProcess(
              launchConfig,
              url,
              monitor,
              enableDebugging,
              browserLocation,
              browserName,
              processDescription);

      sleep(100);

      monitor.worked(1);

      if (isProcessTerminated(browserProcess)) {
        DartDebugCorePlugin.logError("Dartium output: " + dartiumOutput.toString());

        throw new CoreException(
            new Status(
                IStatus.ERROR,
                DartDebugCorePlugin.PLUGIN_ID,
                "Could not launch browser - process terminated on startup"
                    + getProcessStreamMessage(dartiumOutput.toString())));
      }

      connectToChromiumDebug(
          dartium,
          browserName,
          launch,
          launchConfig,
          url,
          monitor,
          browserProcess,
          timer,
          enableBreakpoints,
          devToolsPortNumber,
          dartiumOutput,
          processDescription.toString());
    }

    DebugUIHelper.getHelper().activateApplication(dartium, "Chromium");

    timer.stopTask();
    timer.stopTimer();
    monitor.done();
  }