| |
| /* |
| * weinre is available under *either* the terms of the modified BSD license *or* the |
| * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. |
| * |
| * Copyright (c) 2010, 2011 IBM Corporation |
| */ |
| |
| requireClass ../common/Ex |
| requireClass ../common/Binding |
| requireClass ../common/Callback |
| requireClass ../common/MessageDispatcher |
| requireClass ../common/Weinre |
| |
| requireClass ./NodeStore |
| requireClass ./CSSStore |
| requireClass ./ElementHighlighter |
| requireClass ./InjectedScriptHostImpl |
| |
| requireClass ./WeinreTargetEventsImpl |
| |
| // require ./WebInspectorApplicationCacheHandlerImpl |
| // require ./WebInspectorBackendHandlerImpl |
| // require ./WebInspectorControllerHandlerImpl |
| // require ./WebInspectorDOMHandlerImpl |
| // require ./WebInspectorDebugHandlerImpl |
| // require ./WebInspectorProfilerHandlerImpl |
| // require ./WebInspectorResourceHandlerImpl |
| |
| requireClass ./WiApplicationCacheImpl |
| requireClass ./WiBrowserDebuggerImpl |
| requireClass ./WiCSSImpl |
| requireClass ./WiConsoleImpl |
| requireClass ./WiDOMImpl |
| requireClass ./WiDOMStorageImpl |
| requireClass ./WiDatabaseImpl |
| requireClass ./WiDebuggerImpl |
| requireClass ./WiInjectedScriptImpl |
| requireClass ./WiInspectorImpl |
| requireClass ./WiNetworkImpl |
| requireClass ./WiProfilerImpl |
| requireClass ./WiRuntimeImpl |
| |
| //----------------------------------------------------------------------------- |
| class Target |
| this.initialize() |
| |
| //----------------------------------------------------------------------------- |
| static method main |
| Weinre.target = new Target() |
| |
| Weinre.addCSSProperties = function addCSSProperties(properties) { |
| CSSStore.addCSSProperties(properties) |
| } |
| |
| //------------------------------------------------------------------------------ |
| method setWeinreServerURLFromScriptSrc() |
| if (window.WeinreServerURL) return |
| |
| var elements = document.getElementsByTagName("script") |
| |
| var scripts = ["Target.", "target-script.", "target-script-min."] |
| for (var i=0; i<elements.length; i++) { |
| var element = elements[i] |
| |
| for (j=0; j<scripts.length; j++) { |
| if (-1 != element.src.indexOf("/" + scripts[j])) { |
| var pattern = /(http:\/\/(.*?)\/)/ |
| var match = pattern.exec(element.src) |
| if (match) { |
| window.WeinreServerURL = match[1] |
| return |
| } |
| } |
| } |
| } |
| |
| var message = "unable to calculate the weinre server url; explicity set the variable window.WeinreServerURL instead" |
| alert(message) |
| throw new Ex(arguments, message) |
| |
| //----------------------------------------------------------------------------- |
| method initialize() |
| this.setWeinreServerURLFromScriptSrc() |
| |
| if (window.WeinreServerURL[window.WeinreServerURL.length-1] != "/") { |
| window.WeinreServerURL += "/" |
| } |
| |
| var injectedScriptHost = new InjectedScriptHostImpl() |
| Weinre.injectedScript = injectedScriptConstructor(injectedScriptHost, window, 0, "?") |
| |
| window.addEventListener("load", Binding(this, "onLoaded"), false) |
| |
| var messageDispatcher = new MessageDispatcher(window.WeinreServerURL + "ws/target") |
| Weinre.messageDispatcher = messageDispatcher |
| |
| Weinre.wi = {} |
| |
| Weinre.wi.ApplicationCache = new WiApplicationCacheImpl() |
| Weinre.wi.BrowserDebugger = new WiBrowserDebuggerImpl() |
| Weinre.wi.Console = new WiConsoleImpl() |
| Weinre.wi.CSS = new WiCSSImpl() |
| Weinre.wi.Database = new WiDatabaseImpl() |
| Weinre.wi.Debugger = new WiDebuggerImpl() |
| Weinre.wi.DOM = new WiDOMImpl() |
| Weinre.wi.DOMStorage = new WiDOMStorageImpl() |
| Weinre.wi.InjectedScript = new WiInjectedScriptImpl() |
| Weinre.wi.Inspector = new WiInspectorImpl() |
| Weinre.wi.Network = new WiNetworkImpl() |
| Weinre.wi.Profiler = new WiProfilerImpl() |
| Weinre.wi.Runtime = new WiRuntimeImpl() |
| |
| messageDispatcher.registerInterface("ApplicationCache", Weinre.wi.ApplicationCache , true) |
| messageDispatcher.registerInterface("BrowserDebugger" , Weinre.wi.BrowserDebugger , true) |
| messageDispatcher.registerInterface("Console", Weinre.wi.Console , true) |
| messageDispatcher.registerInterface("CSS", Weinre.wi.CSS , true) |
| messageDispatcher.registerInterface("Database", Weinre.wi.Database , true) |
| messageDispatcher.registerInterface("Debugger", Weinre.wi.Debugger , true) |
| messageDispatcher.registerInterface("DOM", Weinre.wi.DOM , true) |
| messageDispatcher.registerInterface("DOMStorage", Weinre.wi.DOMStorage , true) |
| messageDispatcher.registerInterface("InjectedScript", Weinre.wi.InjectedScript , true) |
| messageDispatcher.registerInterface("Inspector", Weinre.wi.Inspector , true) |
| messageDispatcher.registerInterface("Network", Weinre.wi.Network , true) |
| messageDispatcher.registerInterface("Profiler", Weinre.wi.Profiler , true) |
| messageDispatcher.registerInterface("Runtime", Weinre.wi.Runtime , true) |
| |
| messageDispatcher.registerInterface("WeinreTargetEvents", new WeinreTargetEventsImpl(), true) |
| |
| Weinre.wi.ApplicationCacheNotify = messageDispatcher.createProxy("ApplicationCacheNotify") |
| Weinre.wi.ConsoleNotify = messageDispatcher.createProxy("ConsoleNotify") |
| Weinre.wi.DOMNotify = messageDispatcher.createProxy("DOMNotify") |
| Weinre.wi.DOMStorageNotify = messageDispatcher.createProxy("DOMStorageNotify") |
| Weinre.wi.DatabaseNotify = messageDispatcher.createProxy("DatabaseNotify") |
| Weinre.wi.DebuggerNotify = messageDispatcher.createProxy("DebuggerNotify") |
| Weinre.wi.InspectorNotify = messageDispatcher.createProxy("InspectorNotify") |
| Weinre.wi.NetworkNotify = messageDispatcher.createProxy("NetworkNotify") |
| Weinre.wi.ProfilerNotify = messageDispatcher.createProxy("ProfilerNotify") |
| Weinre.wi.TimelineNotify = messageDispatcher.createProxy("TimelineNotify") |
| |
| Weinre.WeinreTargetCommands = messageDispatcher.createProxy("WeinreTargetCommands") |
| |
| messageDispatcher.getWebSocket().addEventListener("open", Binding(this, this.cb_webSocketOpened)) |
| |
| Weinre.nodeStore = new NodeStore() |
| Weinre.cssStore = new CSSStore() |
| |
| //----------------------------------------------------------------------------- |
| method cb_webSocketOpened() |
| Weinre.WeinreTargetCommands.registerTarget(window.location.href, Binding(this, this.cb_registerTarget)) |
| |
| //----------------------------------------------------------------------------- |
| method cb_registerTarget(targetId) |
| Weinre.targetId = targetId |
| Weinre.connectorId = targetId |
| |
| Callback.setConnectorId(targetId) |
| |
| //----------------------------------------------------------------------------- |
| method onLoaded() |
| |
| //----------------------------------------------------------------------------- |
| method setDocument() |
| Weinre.elementHighlighter = new ElementHighlighter() |
| |
| var nodeId = Weinre.nodeStore.getNodeId(document) |
| var nodeData = Weinre.nodeStore.getNodeData(nodeId, 2) |
| |
| Weinre.wi.DOMNotify.setDocument(nodeData) |