# HG changeset patch # User Eugene Ostroukhov # Date 1276030963 25200 # Node ID 8e561bc07a21b26593c3743fc1480703900de4ee # Parent 8726e95bcbba395b8181c90f514b15ea070f8334 Migrated to latest Chrome Java SDK diff -r 8726e95bcbba -r 8e561bc07a21 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/HtmlBreakpointProvider.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/HtmlBreakpointProvider.java Mon Jun 07 16:51:19 2010 -0700 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/HtmlBreakpointProvider.java Tue Jun 08 14:02:43 2010 -0700 @@ -14,6 +14,7 @@ import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools; import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider; +import org.symbian.tools.wrttools.debug.internal.launch.WRTProjectWorkspaceBridge; @SuppressWarnings("restriction") public class HtmlBreakpointProvider implements IBreakpointProvider { @@ -23,7 +24,8 @@ boolean hasScript = hasJavaScript(document, lineNumber); if (hasScript) { - ChromiumLineBreakpoint breakpoint = new ChromiumLineBreakpoint(getResource(input), lineNumber); + ChromiumLineBreakpoint breakpoint = new ChromiumLineBreakpoint(getResource(input), lineNumber, + WRTProjectWorkspaceBridge.DEBUG_MODEL_ID); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint); } return Status.OK_STATUS; diff -r 8726e95bcbba -r 8e561bc07a21 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java Mon Jun 07 16:51:19 2010 -0700 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java Tue Jun 08 14:02:43 2010 -0700 @@ -4,14 +4,17 @@ import java.util.ArrayList; import java.util.Collection; +import org.chromium.debug.core.model.BreakpointSynchronizer.Callback; +import org.chromium.debug.core.model.BreakpointSynchronizer.Direction; import org.chromium.debug.core.model.ChromiumLineBreakpoint; import org.chromium.debug.core.model.DebugTargetImpl; import org.chromium.debug.core.model.StackFrame; +import org.chromium.debug.core.model.VmResource; import org.chromium.debug.core.model.WorkspaceBridge; import org.chromium.sdk.CallFrame; import org.chromium.sdk.JavascriptVm; +import org.chromium.sdk.JavascriptVm.ScriptsCallback; import org.chromium.sdk.Script; -import org.chromium.sdk.JavascriptVm.ScriptsCallback; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -51,7 +54,6 @@ } -// public final static String DEBUG_MODEL_ID = VProjectWorkspaceBridge.DEBUG_MODEL_ID; public final static String DEBUG_MODEL_ID = "org.symbian.debug"; private final BreakpointHandler breakpointHandler; @@ -63,9 +65,8 @@ JavascriptVm javascriptVm, IProject project) { this.javascriptVm = javascriptVm; this.project = project; - this.resourceManager = new ResourceManager(); - breakpointHandler = new WorkspaceBreakpointHandler(debugTargetImpl, - javascriptVm, resourceManager); + this.resourceManager = new ResourceManager(); + breakpointHandler = new WorkspaceBreakpointHandler(debugTargetImpl, resourceManager); ILaunch launch = debugTargetImpl.getLaunch(); launch.setSourceLocator(sourceLocator); } @@ -78,10 +79,6 @@ return breakpointHandler; } - public IFile getScriptResource(Script script) { - return resourceManager.getResource(script); - } - public void handleVmResetEvent() { resourceManager.clear(); } @@ -175,4 +172,19 @@ } }; + public VmResource findVmResourceFromWorkspaceFile(IFile resource) throws CoreException { + System.out.println(resource); + return null; + } + + public void reloadScript(Script script) { + System.out.println(script); + + } + + public void synchronizeBreakpoints(Direction direction, Callback callback) { + System.out.println(direction); + + } + } diff -r 8726e95bcbba -r 8e561bc07a21 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java Mon Jun 07 16:51:19 2010 -0700 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java Tue Jun 08 14:02:43 2010 -0700 @@ -15,29 +15,29 @@ public class WrtLabelProvider implements JsLabelProvider { - public String getStackFrameLabel(StackFrame stackFrame) - throws DebugException { - CallFrame callFrame = stackFrame.getCallFrame(); - String name = callFrame.getFunctionName(); - Script script = callFrame.getScript(); - if (script == null) { - return ""; - } - IFile resource = stackFrame.getDebugTarget().getScriptResource(script); - int line = script.getStartLine() + stackFrame.getLineNumber(); - if (line != -1) { - String resourcePath = resource != null ? resource - .getProjectRelativePath().toString() : script.getName(); - name = NLS.bind("{0} [{1}:{2}]", new Object[] { name, resourcePath, - line }); - } - return name; - } + public String getStackFrameLabel(StackFrame stackFrame) throws DebugException { + CallFrame callFrame = stackFrame.getCallFrame(); + String name = callFrame.getFunctionName(); + Script script = callFrame.getScript(); + if (script == null) { + return ""; + } + Object element = stackFrame.getLaunch().getSourceLocator().getSourceElement(stackFrame); + if (element instanceof IFile) { + IFile resource = (IFile) element; + int line = script.getStartLine() + stackFrame.getLineNumber(); + if (line != -1) { + String resourcePath = resource != null ? resource.getProjectRelativePath().toString() : script + .getName(); + name = NLS.bind("{0} [{1}:{2}]", new Object[] { name, resourcePath, line }); + } + } + return name; + } - public String getTargetLabel(DebugTargetImpl debugTarget) - throws DebugException { - return "WRT Runtime"; - } + public String getTargetLabel(DebugTargetImpl debugTarget) throws DebugException { + return "WRT Runtime"; + } public String getThreadLabel(JavascriptThread thread) throws DebugException { return NLS.bind("JavaScript Thread ({0})", getThreadStateLabel(thread)); @@ -48,8 +48,8 @@ DebugContext context = thread.getDebugTarget().getDebugContext(); ExceptionData exceptionData = context.getExceptionData(); if (exceptionData != null) { - return NLS.bind(Messages.JsThread_ThreadLabelSuspendedExceptionFormat, exceptionData - .getExceptionMessage()); + return NLS.bind(Messages.JsThread_ThreadLabelSuspendedExceptionFormat, + exceptionData.getExceptionMessage()); } else { return Messages.JsThread_ThreadLabelSuspended; } diff -r 8726e95bcbba -r 8e561bc07a21 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/ResourceManager.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/ResourceManager.java Mon Jun 07 16:51:19 2010 -0700 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/ResourceManager.java Tue Jun 08 14:02:43 2010 -0700 @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map; +import org.chromium.debug.core.model.VmResourceId; import org.chromium.sdk.Script; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -15,77 +16,19 @@ /** * This object handles the mapping between {@link Script}s and their * corresponding resources inside Eclipse. - * - * Symbian branch is currently based on Revision 138 */ public class ResourceManager { - /** - * Script identifier for a breakpoint location. - */ - public static class ScriptIdentifier { - public static ScriptIdentifier forScript(Script script) { - String name = script.getName(); - return new ScriptIdentifier(name, name != null ? -1 : script - .getId(), script.getStartLine(), script.getEndLine()); - } - - private final int endLine; - private final long id; - private final String name; - private final int startLine; - - private ScriptIdentifier(String name, long id, int startLine, - int endLine) { - this.name = name; - this.id = id; - this.startLine = startLine; - this.endLine = endLine; - } + private final Map resourceToScript = new HashMap(); + private final Map scriptIdToResource = new HashMap(); - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ScriptIdentifier)) { - return false; - } - ScriptIdentifier that = (ScriptIdentifier) obj; - if (this.startLine != that.startLine - || this.endLine != that.endLine) { - return false; - } - if (name == null) { - // an unnamed script, only id is known - return that.name == null && this.id == that.id; - } - // a named script - return this.name.equals(that.name); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (int) (id ^ (id >>> 32)); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + 17 * startLine + 19 * endLine; - return result; - } - } - - private Object fileBeingAdded; - private final Map resourceToScript = new HashMap(); - private final Map scriptIdToResource = new HashMap(); - - public synchronized void addScript(Script script) { + public synchronized void addScript(Script script) { IFile scriptFile = getResource(script); if (scriptFile == null) { scriptFile = getFile(script.getName()); if (scriptFile != null) { - fileBeingAdded = scriptFile; - try { - putScript(script, scriptFile); - } finally { - fileBeingAdded = null; - } + VmResourceId scriptId = VmResourceId.forScript(script); + resourceToScript.put(scriptFile, script); + scriptIdToResource.put(scriptId, scriptFile); } } } @@ -106,32 +49,20 @@ return file; } - public synchronized IFile getResource(Script script) { - return scriptIdToResource.get(ScriptIdentifier.forScript(script)); - } - - public synchronized Script getScript(IFile resource) { - return resourceToScript.get(resource); + public synchronized IFile getResource(Script script) { + return scriptIdToResource.get(VmResourceId.forScript(script)); } - /** - * @return whether the given file is being added to the target project - */ - public boolean isAddingFile(IFile file) { - return file.equals(fileBeingAdded); - } - - public synchronized void putScript(Script script, IFile resource) { - ScriptIdentifier scriptId = ScriptIdentifier.forScript(script); - resourceToScript.put(resource, script); - scriptIdToResource.put(scriptId, resource); - } - - public synchronized boolean scriptHasResource(Script script) { + public synchronized boolean scriptHasResource(Script script) { return getResource(script) != null; } public String translateResourceToScript(IResource resource) { return PreviewerPlugin.getDefault().getHttpPreviewer().getHttpUrl(resource); } + + public VmResourceId findVmResource(IFile resource) { + Script script = resourceToScript.get(resource); + return script != null ? VmResourceId.forScript(script) : null; + } } diff -r 8726e95bcbba -r 8e561bc07a21 org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/WorkspaceBreakpointHandler.java --- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/WorkspaceBreakpointHandler.java Mon Jun 07 16:51:19 2010 -0700 +++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/WorkspaceBreakpointHandler.java Tue Jun 08 14:02:43 2010 -0700 @@ -6,123 +6,190 @@ import java.util.Collection; import org.chromium.debug.core.ChromiumDebugPlugin; +import org.chromium.debug.core.model.BreakpointMap; +import org.chromium.debug.core.model.BreakpointSynchronizer.BreakpointHelper.CreateCallback; import org.chromium.debug.core.model.ChromiumLineBreakpoint; import org.chromium.debug.core.model.DebugTargetImpl; import org.chromium.debug.core.model.VProjectWorkspaceBridge; +import org.chromium.debug.core.model.VmResourceId; import org.chromium.debug.core.model.WorkspaceBridge.BreakpointHandler; import org.chromium.sdk.Breakpoint; import org.chromium.sdk.JavascriptVm; -import org.chromium.sdk.JavascriptVm.BreakpointCallback; +import org.chromium.sdk.SyncCallback; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarkerDelta; import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IBreakpoint; -import org.symbian.tools.wrttools.debug.internal.Activator; import org.symbian.tools.wrttools.debug.internal.launch.WRTProjectWorkspaceBridge; +import org.symbian.tools.wrttools.previewer.PreviewerPlugin; public final class WorkspaceBreakpointHandler implements BreakpointHandler { - private final ResourceManager resourceManager; + private final BreakpointMap.InTargetMap breakpointInTargetMap = new BreakpointMap.InTargetMap(); private final DebugTargetImpl debugTarget; - private final JavascriptVm vm; - - public WorkspaceBreakpointHandler(DebugTargetImpl debugTarget, JavascriptVm vm, ResourceManager resourceManager) { + private final ResourceManager resourceManager; + + public WorkspaceBreakpointHandler(DebugTargetImpl debugTarget, ResourceManager resourceManager) { this.debugTarget = debugTarget; - this.vm = vm; + // this.vm = vm; this.resourceManager = resourceManager; } - - public boolean supportsBreakpoint(IBreakpoint breakpoint) { + + public void breakpointAdded(IBreakpoint breakpoint) { + ChromiumLineBreakpoint lineBreakpoint = tryCastBreakpoint(breakpoint); + if (lineBreakpoint == null) { + return; + } + if (ChromiumLineBreakpoint.getIgnoreList().contains(breakpoint)) { + return; + } + if (!lineBreakpoint.isEnabled()) { + return; + } + IFile file = (IFile) lineBreakpoint.getMarker().getResource(); + VmResourceId vmResourceId; + try { + vmResourceId = findVmResourceIdFromWorkspaceFile(file); + } catch (CoreException e) { + ChromiumDebugPlugin.log(new Exception("Failed to resolve script for the file " + file, e)); //$NON-NLS-1$ + return; + } + if (vmResourceId == null) { + // Might be a script from a different debug target + return; + } + createBreakpointOnRemote(lineBreakpoint, vmResourceId, null, null); + } + + public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { + ChromiumLineBreakpoint lineBreakpoint = tryCastBreakpoint(breakpoint); + if (lineBreakpoint == null) { + return; + } + if (ChromiumLineBreakpoint.getIgnoreList().contains(lineBreakpoint)) { + return; + } + Breakpoint sdkBreakpoint = breakpointInTargetMap.getSdkBreakpoint(lineBreakpoint); + if (sdkBreakpoint == null) { + return; + } + + try { + ChromiumLineBreakpoint.Helper.updateOnRemote(sdkBreakpoint, lineBreakpoint); + } catch (RuntimeException e) { + ChromiumDebugPlugin.log(new Exception("Failed to change breakpoint in " + //$NON-NLS-1$ + getTargetNameSafe(), e)); + } + + } + + public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { + ChromiumLineBreakpoint lineBreakpoint = tryCastBreakpoint(breakpoint); + if (lineBreakpoint == null) { + return; + } + if (ChromiumLineBreakpoint.getIgnoreList().contains(lineBreakpoint)) { + return; + } + + Breakpoint sdkBreakpoint = breakpointInTargetMap.getSdkBreakpoint(lineBreakpoint); + if (sdkBreakpoint == null) { + return; + } + + try { + if (!breakpoint.isEnabled()) { + return; + } + } catch (CoreException e) { + ChromiumDebugPlugin.log(e); + return; + } + JavascriptVm.BreakpointCallback callback = new JavascriptVm.BreakpointCallback() { + public void failure(String errorMessage) { + ChromiumDebugPlugin.log(new Exception("Failed to remove breakpoint in " + //$NON-NLS-1$ + getTargetNameSafe() + ": " + errorMessage)); //$NON-NLS-1$ + } + + public void success(Breakpoint breakpoint) { + } + }; + try { + sdkBreakpoint.clear(callback, null); + } catch (RuntimeException e) { + ChromiumDebugPlugin.log(new Exception("Failed to remove breakpoint in " + //$NON-NLS-1$ + getTargetNameSafe(), e)); + } + breakpointInTargetMap.remove(lineBreakpoint); + } + + public void breakpointsHit(Collection breakpointsHit) { + if (breakpointsHit.isEmpty()) { + return; + } + + for (Breakpoint sdkBreakpoint : breakpointsHit) { + ChromiumLineBreakpoint uiBreakpoint = breakpointInTargetMap.getUiBreakpoint(sdkBreakpoint); + if (uiBreakpoint != null) { + uiBreakpoint.setIgnoreCount(-1); // reset ignore count as we've hit it + } + } + } + + public void createBreakpointOnRemote(final ChromiumLineBreakpoint lineBreakpoint, final VmResourceId vmResourceId, + final CreateCallback createCallback, SyncCallback syncCallback) { + try { + ChromiumLineBreakpoint.Helper.CreateOnRemoveCallback callback = new ChromiumLineBreakpoint.Helper.CreateOnRemoveCallback() { + public void failure(String errorMessage) { + if (createCallback == null) { + ChromiumDebugPlugin.logError(errorMessage); + } else { + createCallback.failure(new Exception(errorMessage)); + } + } + + public void success(Breakpoint breakpoint) { + breakpointInTargetMap.add(breakpoint, lineBreakpoint); + if (createCallback != null) { + createCallback.success(); + } + } + }; + + ChromiumLineBreakpoint.Helper.createOnRemote(lineBreakpoint, vmResourceId, debugTarget, callback, + syncCallback); + } catch (CoreException e) { + ChromiumDebugPlugin.log(new Exception("Failed to create breakpoint in " + //$NON-NLS-1$ + getTargetNameSafe(), e)); + } + } + + private VmResourceId findVmResourceIdFromWorkspaceFile(IFile resource) throws CoreException { + return VmResourceId.forName(PreviewerPlugin.getDefault().getHttpPreviewer().getHttpUrl(resource)); + } + + private String getTargetNameSafe() { + try { + return debugTarget.getLaunch().getLaunchConfiguration().getName(); + } catch (RuntimeException e) { + return ""; //$NON-NLS-1$ + } + } + + public boolean supportsBreakpoint(IBreakpoint breakpoint) { return (WRTProjectWorkspaceBridge.DEBUG_MODEL_ID.equals(breakpoint .getModelIdentifier()) || VProjectWorkspaceBridge.DEBUG_MODEL_ID .equals(breakpoint.getModelIdentifier())) && !debugTarget.isDisconnected(); } - public void registerBreakpoint(final ChromiumLineBreakpoint breakpoint, - final String script) throws CoreException { - final int line = (breakpoint.getLineNumber() - 1); - BreakpointCallback callback = new BreakpointCallback() { - public void success(Breakpoint b) { - breakpoint.setBreakpoint(b); - } - - public void failure(String errorMessage) { - Activator.log(errorMessage); - } - }; - // ILineBreakpoint lines are 1-based while V8 lines are 0-based - JavascriptVm javascriptVm = vm; - if (script != null) { - javascriptVm.setBreakpoint(Breakpoint.Type.SCRIPT_NAME, script - ,line, Breakpoint.EMPTY_VALUE, breakpoint - .isEnabled(), breakpoint.getCondition(), breakpoint - .getIgnoreCount(), callback); - } else { - javascriptVm.setBreakpoint(Breakpoint.Type.SCRIPT_ID, String - .valueOf(script), line, Breakpoint.EMPTY_VALUE, - breakpoint.isEnabled(), breakpoint.getCondition(), - breakpoint.getIgnoreCount(), callback); - } - } - - public void breakpointAdded(IBreakpoint breakpoint) { - if (!supportsBreakpoint(breakpoint)) { - return; - } - try { - // Class cast is ensured by the supportsBreakpoint implementation - final ChromiumLineBreakpoint lineBreakpoint = (ChromiumLineBreakpoint) breakpoint; - IFile file = (IFile) breakpoint.getMarker().getResource(); - if (!resourceManager.isAddingFile(file)) { - final String script = resourceManager.translateResourceToScript(file); - if (script != null) { - registerBreakpoint(lineBreakpoint, script); - } - } - } catch (CoreException e) { - Activator.log(e); + public ChromiumLineBreakpoint tryCastBreakpoint(IBreakpoint breakpoint) { + if (!supportsBreakpoint(breakpoint)) { + return null; } - } - - public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { - if (!supportsBreakpoint(breakpoint)) { - return; - } - // Class cast is ensured by the supportsBreakpoint implementation - ((ChromiumLineBreakpoint) breakpoint).changed(); - } + if (breakpoint instanceof ChromiumLineBreakpoint == false) { + return null; + } + return (ChromiumLineBreakpoint) breakpoint; + } - public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { - if (!supportsBreakpoint(breakpoint)) { - return; - } - try { - if (breakpoint.isEnabled()) { - // Class cast is ensured by the supportsBreakpoint - // implementation - ChromiumLineBreakpoint lineBreakpoint = (ChromiumLineBreakpoint) breakpoint; - lineBreakpoint.clear(); - } - } catch (CoreException e) { - ChromiumDebugPlugin.log(e); - } - } - - public void breakpointsHit( - Collection breakpointsHit) { - if (breakpointsHit.isEmpty()) { - return; - } - IBreakpoint[] breakpoints = DebugPlugin.getDefault() - .getBreakpointManager().getBreakpoints(WRTProjectWorkspaceBridge.DEBUG_MODEL_ID); - for (IBreakpoint breakpoint : breakpoints) { - ChromiumLineBreakpoint jsBreakpoint = (ChromiumLineBreakpoint) breakpoint; - if (breakpointsHit - .contains(jsBreakpoint.getBrowserBreakpoint())) { - jsBreakpoint.setIgnoreCount(-1); // reset ignore count as - // we've hit it - } - } - } } \ No newline at end of file diff -r 8726e95bcbba -r 8e561bc07a21 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java Mon Jun 07 16:51:19 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java Tue Jun 08 14:02:43 2010 -0700 @@ -453,7 +453,7 @@ ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { final IPath path = new Path(entry.getName()); - if (path.segmentCount() == 2 && CoreUtil.METADATA_FILE.equals(path.segment(1))) { + if (path.segmentCount() == 2 && CoreUtil.METADATA_FILE.equalsIgnoreCase(path.segment(1))) { return true; } }