Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/mobile/MobileLaunchConfigurationDelegate.java

Issue 321583008: Merge to trunk cl - fixes/features for mobile support in the editor (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/mobile/MobileLaunchConfigurationDelegate.java
===================================================================
--- dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/mobile/MobileLaunchConfigurationDelegate.java (revision 37106)
+++ dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/mobile/MobileLaunchConfigurationDelegate.java (working copy)
@@ -15,6 +15,7 @@
import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder;
import com.google.dart.tools.core.mobile.AndroidDebugBridge;
+import com.google.dart.tools.core.mobile.AndroidDevice;
import com.google.dart.tools.debug.core.DartDebugCorePlugin;
import com.google.dart.tools.debug.core.DartLaunchConfigWrapper;
import com.google.dart.tools.debug.core.DartLaunchConfigurationDelegate;
@@ -22,27 +23,76 @@
import com.google.dart.tools.debug.core.pubserve.PubCallback;
import com.google.dart.tools.debug.core.pubserve.PubResult;
import com.google.dart.tools.debug.core.pubserve.PubServeManager;
+import com.google.dart.tools.debug.core.pubserve.PubServeResourceResolver;
+import com.google.dart.tools.debug.core.util.BrowserManager;
+import com.google.dart.tools.debug.core.util.IRemoteConnectionDelegate;
+import com.google.dart.tools.debug.core.util.IResourceResolver;
import com.google.dart.tools.debug.core.util.ResourceServer;
import com.google.dart.tools.debug.core.util.ResourceServerManager;
+import com.google.dart.tools.debug.core.webkit.ChromiumTabInfo;
+import com.google.dart.tools.debug.core.webkit.DefaultChromiumTabChooser;
+import com.google.dart.tools.debug.core.webkit.IChromiumTabChooser;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IDebugTarget;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.List;
/**
* A LaunchConfigurationDelegate to launch in the browser on a connected device.
*/
-public class MobileLaunchConfigurationDelegate extends DartLaunchConfigurationDelegate {
+public class MobileLaunchConfigurationDelegate extends DartLaunchConfigurationDelegate implements
+ IRemoteConnectionDelegate {
+ /**
+ * A class to choose a tab from the given list of tabs.
+ */
+ public static class ChromeTabChooser implements IChromiumTabChooser {
+ public ChromeTabChooser() {
+
+ }
+
+ @Override
+ public ChromiumTabInfo chooseTab(final List<ChromiumTabInfo> tabs) {
+ if (tabs.size() == 0) {
+ return null;
+ }
+
+ int tabCount = 0;
+
+ for (ChromiumTabInfo tab : tabs) {
+ if (!tab.isChromeExtension()) {
+ tabCount++;
+ }
+ }
+
+ if (tabCount == 1) {
+ return tabs.get(0);
+ }
+
+ for (ChromiumTabInfo tab : tabs) {
+ if (!tab.isChromeExtension()) {
+ return tab;
+ }
+
+ }
+
+ return new DefaultChromiumTabChooser().chooseTab(tabs);
+ }
+ }
+
private PubCallback<String> pubConnectionCallback = new PubCallback<String>() {
@Override
public void handleResult(PubResult<String> result) {
@@ -55,7 +105,7 @@
try {
String launchUrl = result.getResult();
- launchOnMobile(launchUrl);
+ launchOnMobile(launchUrl, true, new NullProgressMonitor());
} catch (CoreException e) {
DartDebugCorePlugin.logError(e);
DebugUIHelper.getHelper().showError("Dartium Launch Error", e.getMessage());
@@ -65,8 +115,9 @@
};
private DartLaunchConfigWrapper wrapper;
- private static final String DEBUG_PORT = "9222";
+ private static final int REMOTE_DEBUG_PORT = 9224;
+
@Override
public void doLaunch(ILaunchConfiguration configuration, String mode, ILaunch launch,
IProgressMonitor monitor, InstrumentationBuilder instrumentation) throws CoreException {
@@ -76,6 +127,8 @@
String launchUrl = "";
+ boolean usePubServe = wrapper.getUsePubServe();
+
if (wrapper.getShouldLaunchFile()) {
IResource resource = wrapper.getApplicationResource();
@@ -90,7 +143,6 @@
instrumentation.data("Resource-Name", resource.getName());
try {
- boolean usePubServe = true; // TODO(keertip): get from launch config
if (usePubServe) {
PubServeManager manager = PubServeManager.getManager();
@@ -106,7 +158,7 @@
} else {
launchUrl = getUrlFromResourceServer(resource);
- launchOnMobile(launchUrl);
+ launchOnMobile(launchUrl, usePubServe, monitor);
}
} catch (Exception e) {
@@ -123,7 +175,7 @@
if (scheme == null) { // add scheme else browser will not launch
launchUrl = "http://" + launchUrl;
- launchOnMobile(launchUrl);
+ launchOnMobile(launchUrl, usePubServe, monitor);
}
} catch (URISyntaxException e) {
throw new CoreException(new Status(
@@ -136,32 +188,64 @@
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
}
- protected void launchOnMobile(String launchUrl) throws CoreException {
+ @Override
+ public IDebugTarget performRemoteConnection(String host, int port, IProgressMonitor monitor,
+ boolean usePubServe) throws CoreException {
+ BrowserManager browserManager = new BrowserManager();
+
+ IResourceResolver resolver = null;
+ try {
+ resolver = usePubServe ? new PubServeResourceResolver() : ResourceServerManager.getServer();
+ } catch (IOException e) {
+ return null;
+ }
+
+ return browserManager.performRemoteConnection(
+ new ChromeTabChooser(),
+ host,
+ port,
+ monitor,
+ resolver);
+
+ }
+
+ protected void launchOnMobile(String launchUrl, boolean usePubServe, IProgressMonitor monitor)
+ throws CoreException {
+
AndroidDebugBridge devBridge = AndroidDebugBridge.getAndroidDebugBridge();
devBridge.startAdbServer();
- String deviceId = devBridge.getConnectedDevice();
- if (deviceId == null) {
+ AndroidDevice device = devBridge.getConnectedDevice();
+ if (device == null) {
throw new CoreException(new Status(
IStatus.ERROR,
DartDebugCorePlugin.PLUGIN_ID,
"No devices detected.\n\nConnect device, enable USB debugging and try again."));
}
+ if (device.getDeviceId() == null) {
+ throw new CoreException(new Status(
+ IStatus.ERROR,
+ DartDebugCorePlugin.PLUGIN_ID,
+ "Unauthorized device detected.\n\nAuthorize device and try again."));
+ }
- if (wrapper.getLaunchContentShell()) {
- if (wrapper.getInstallContentShell()) {
- if (!devBridge.installContentShellApk(deviceId)) {
- throw new CoreException(new Status(
- IStatus.ERROR,
- DartDebugCorePlugin.PLUGIN_ID,
- "Failed to install content shell on mobile"));
- }
+ if (wrapper.getInstallContentShell()) {
+ if (!devBridge.installContentShellApk(device.getDeviceId())) {
+ throw new CoreException(new Status(
+ IStatus.ERROR,
+ DartDebugCorePlugin.PLUGIN_ID,
+ "Failed to install content shell on mobile"));
}
- devBridge.launchContentShell(deviceId, launchUrl);
- } else {
- devBridge.launchChromeBrowser(launchUrl);
}
+ devBridge.launchContentShell(device.getDeviceId(), launchUrl);
+
+ // check if remote connection is alive
+ if (!isRemoteConnected()) {
+ devBridge.setupPortForwarding(Integer.toString(REMOTE_DEBUG_PORT));
+ // TODO(keertip): check if host needs to be the ip for wifi connections
+ performRemoteConnection("localhost", REMOTE_DEBUG_PORT, monitor, usePubServe);
+ }
}
private String getUrlFromResourceServer(IResource resource) throws IOException, CoreException,
@@ -185,4 +269,19 @@
return launchUrl;
}
+ private boolean isRemoteConnected() {
+
+ IDebugTarget[] targets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
+ for (IDebugTarget target : targets) {
+ try {
+ if (target.getName().equals("Remote") && !target.getProcess().isTerminated()) {
+ return true;
+ }
+ } catch (DebugException e) {
+
+ }
+ }
+ return false;
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698