public WebkitDebugTarget connect( ILaunch launch, ILaunchConfiguration configuration, IResourceResolver resourceResolver, IBrowserTabChooser browserTabChooser, String host, int port, IProgressMonitor monitor) throws CoreException { try { SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); LogTimer timer = new LogTimer("Chrome debug connect"); try { timer.startTask("connect"); try { launchConfig.markAsLaunched(); return connectToChromiumDebug( "Chrome Remote Connection", launch, launchConfig, null /*url*/, monitor, null /*runtimeProcess*/, timer, true /*enableBreakpoints*/, host, port, 0L /*maxStartupDelay*/, null /*browserOutput*/, null /*processDescription*/, resourceResolver, browserTabChooser, true /*remote*/); } finally { timer.stopTask(); } } finally { timer.stopTimer(); } } catch (CoreException e) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); throw e; } }
public void launchBrowser( ILaunch launch, ILaunchConfiguration configuration, IResourceResolver resourceResolver, IBrowserTabChooser browserTabChooser, String url, IProgressMonitor monitor, boolean enableDebugging, List<String> extraCommandLineArgs) throws CoreException { try { if (launchSemaphore.tryAcquire()) { try { SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); launchConfig.markAsLaunched(); monitor.beginTask("Launching Chrome...", enableDebugging ? 7 : 2); // avg: 0.434 sec (old: 0.597) LogTimer timer = new LogTimer("Chrome debug startup"); // avg: 55ms timer.startTask("Chrome startup"); // for now, check if browser is open, and connection is alive boolean restart = browserProcess == null || isProcessTerminated(browserProcess) || WebkitDebugTarget.getActiveTarget() == null || !WebkitDebugTarget.getActiveTarget().canTerminate(); // we only re-cycle the debug connection if we're launching the same launch configuration if (!restart) { if (!WebkitDebugTarget.getActiveTarget() .getLaunch() .getLaunchConfiguration() .equals(launch.getLaunchConfiguration())) { restart = true; } } if (!restart) { if (enableDebugging != WebkitDebugTarget.getActiveTarget().getEnableBreakpoints()) { restart = true; } } CoreLaunchUtils.removeTerminatedLaunches(); File browserExecutable = getBrowserExecutable(); if (!restart && url != null && resourceResolver != null) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); try { WebkitDebugTarget.getActiveTarget() .navigateToUrl( launch.getLaunchConfiguration(), url, true /*enableBreakpoints*/, resourceResolver); } catch (IOException e) { SDBGDebugCorePlugin.logError(e); } } else { terminateExistingBrowserProcess(); StringBuilder processDescription = new StringBuilder(); int[] devToolsPortNumberHolder = new int[1]; ListeningStream browserOutput = startNewBrowserProcess( launchConfig, url, monitor, enableDebugging, processDescription, extraCommandLineArgs, devToolsPortNumberHolder); sleep(100); monitor.worked(1); if (isProcessTerminated(browserProcess)) { SDBGDebugCorePlugin.logError("Browser output: " + browserOutput.toString()); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Could not launch browser - process terminated on startup" + getProcessStreamMessage(browserOutput.toString()))); } if (enableDebugging) { connectToChromiumDebug( browserExecutable.getName(), launch, launchConfig, url, monitor, browserProcess, timer, true /*enableBreakpoints*/, null, devToolsPortNumberHolder[0], 20 * 1000L /*maxStartupDelay*/, browserOutput, processDescription.toString(), resourceResolver, browserTabChooser, false /*remote*/); } else { registerProcess( launch, launchConfig, DebugPlugin.newProcess( launch, browserProcess, browserExecutable.getName() + " - run only, debugging DISABLED (" + new Date() + ")"), processDescription.toString()); } } DebugUIHelper.getHelper().activateApplication(browserExecutable, "Chrome"); timer.stopTask(); timer.stopTimer(); monitor.done(); } finally { launchSemaphore.release(); } } } catch (CoreException e) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); throw e; } }
public WebkitDebugTarget connect( ILaunch launch, ILaunchConfiguration configuration, IResourceResolver resourceResolver, IDeviceChooser deviceChooser, IBrowserTabChooser browserTabChooser, IProgressMonitor monitor) throws CoreException { try { SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); LogTimer timer = new LogTimer("Chrome debug connect"); try { timer.startTask("connect"); try { launchConfig.markAsLaunched(); List<? extends IDeviceInfo> devices = adbManager.getDevices(); if (devices.isEmpty()) { throw new DebugException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "No USB-attached Android devices found.\n\nPlease make sure you have enabled USB debugging on your device and you have attached it to the PC via USB.")); } IDeviceInfo device = deviceChooser.chooseDevice(devices); if (device != null) { int port = NetUtils.findUnusedPort(DEVTOOLS_PORT_NUMBER); MobileBrowserUtils.addChromiumForward(adbManager, device.getId(), port); try { final String url = launchConfig.getUrl(); boolean launchTab = launchConfig.isLaunchTabWithUrl() && url != null && url.length() > 0; if (launchTab) { MobileBrowserUtils.launchChromeBrowser(adbManager, device.getId()); IBrowserTabInfo tab = getChromiumTab( null /*runtimeProcess*/, new IBrowserTabChooser() { @Override public IBrowserTabInfo chooseTab(List<? extends IBrowserTabInfo> tabs) throws CoreException { for (IBrowserTabInfo tab : tabs) { if (tab.getUrl() != null && tab.getUrl().toLowerCase().contains(url.toLowerCase())) { return tab; } } return null; } }, "127.0.0.1", port, 10 * 1000L /*maxStartupDelay*/, null /*output*/); if (tab == null) { MobileBrowserUtils.launchChromeBrowser( adbManager, device.getId(), launchConfig.getUrl()); } } return connectToChromiumDebug( "Mobile Chrome Remote Connection", launch, launchConfig, null /*url*/, monitor, null /*runtimeProcess*/, timer, true /*enableBreakpoints*/, "127.0.0.1", port, launchTab ? 10 * 1000L : 0L /*maxStartupDelay*/, null /*browserOutput*/, null /*processDescription*/, resourceResolver, browserTabChooser, true /*remote*/); } catch (IOException e) { adbManager.removeAllForwards(); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Unable to connect to debugger in Chrome: " + e.getMessage(), e)); } catch (CoreException e) { adbManager.removeAllForwards(); throw e; } } else { throw new DebugException( new Status( IStatus.INFO, SDBGDebugCorePlugin.PLUGIN_ID, "No Android device was chosen. Connection cancelled.")); } } finally { timer.stopTask(); } } finally { timer.stopTimer(); } } catch (CoreException e) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); throw e; } }