| |
| /* |
| * 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/Native |
| |
| requireClass ../common/IDLTools |
| requireClass ../common/Callback |
| requireClass ../common/Weinre |
| requireClass ../common/MessageDispatcher |
| requireClass ../common/Binding |
| |
| requireClass ./InspectorBackendImpl |
| requireClass ./InspectorFrontendHostImpl |
| requireClass ./WeinreClientEventsImpl |
| requireClass ./RemotePanel |
| |
| //----------------------------------------------------------------------------- |
| class Client |
| |
| //----------------------------------------------------------------------------- |
| init |
| var AutoConnect = true |
| |
| Weinre.showNotImplemented() |
| |
| //----------------------------------------------------------------------------- |
| method initialize |
| |
| // validate InspectorFrontendHost against IDL |
| // IDLTools.validateAgainstIDL(InspectorFrontendHostImpl, 'InspectorFrontendHost') |
| |
| // add a load handler for the window |
| window.addEventListener("load", Binding(this, "onLoaded"), false) |
| |
| // create the socket |
| var messageDispatcher = new MessageDispatcher("../ws/client") |
| Weinre.messageDispatcher = messageDispatcher |
| |
| // finish setting up InspectorBackend |
| InspectorBackendImpl.setupProxies() |
| |
| // create the client commands proxy |
| Weinre.WeinreClientCommands = messageDispatcher.createProxy("WeinreClientCommands") |
| |
| // register WebInspector interface |
| messageDispatcher.registerInterface("WebInspector", WebInspector, false) |
| |
| // hack |
| WebInspector.mainResource = {} |
| WebInspector.mainResource.url = location.href |
| |
| //----------------------------------------------------------------------------- |
| method uiAvailable |
| return WebInspector.panels && WebInspector.panels.remote |
| |
| //----------------------------------------------------------------------------- |
| method autoConnect(value) |
| if (arguments.length >= 1) { |
| AutoConnect = !!value |
| } |
| |
| return AutoConnect |
| |
| //----------------------------------------------------------------------------- |
| method _installRemotePanel |
| WebInspector.panels.remote = new RemotePanel(); |
| |
| var panel = WebInspector.panels.remote; |
| |
| var toolbar = document.getElementById("toolbar") |
| WebInspector.addPanelToolbarIcon(toolbar, panel, toolbar.childNodes[1]) |
| |
| WebInspector.currentPanel = panel |
| |
| var toolButtonsToHide = ["scripts"] |
| toolButtonsToHide.forEach(function(toolButtonToHide){ |
| if (!WebInspector.panels[toolButtonToHide]) return |
| if (!WebInspector.panels[toolButtonToHide].toolbarItem) return |
| WebInspector.panels[toolButtonToHide].toolbarItem.style.display = "none" |
| }) |
| |
| var button = document.getElementById("dock-status-bar-item") |
| if (button) button.style.display = "none" |
| |
| //----------------------------------------------------------------------------- |
| method onLoaded |
| |
| this._installRemotePanel() |
| |
| var messageDispatcher = Weinre.messageDispatcher |
| |
| // Weinre.Socket.verbose(true) |
| |
| messageDispatcher.registerInterface("WeinreClientEvents", new WeinreClientEventsImpl(this), false) |
| messageDispatcher.registerInterface("InspectorFrontendHost", InspectorFrontendHost, false) |
| |
| Weinre.WeinreClientCommands.registerClient(Binding(this, this.cb_registerClient)) |
| |
| //----------------------------------------------------------------------------- |
| method cb_registerClient(clientId) |
| Weinre.clientId = clientId |
| Weinre.connectorId = clientId |
| Callback.setConnectorId(clientId) |
| |
| if (this.uiAvailable()) { |
| WebInspector.panels.remote.setCurrentClient(clientId) |
| WebInspector.panels.remote.afterInitialConnection() |
| } |
| |
| Weinre.messageDispatcher.getWebSocket().addEventListener("close", Binding(this, this.cb_webSocketClosed)) |
| |
| //----------------------------------------------------------------------------- |
| method cb_webSocketClosed |
| |
| // use a delay, otherwise reloading will cause this stuff to flash |
| // before page is actually reloaded |
| Native.setTimeout(function() { |
| WebInspector.panels.remote.connectionClosed() |
| WebInspector.currentPanel = WebInspector.panels.remote |
| }, 1000) |
| |
| //----------------------------------------------------------------------------- |
| static method main |
| Weinre.client = new Client() |
| Weinre.client.initialize() |