Home | History | Annotate | Download | only in js
      1 /*
      2  * Copyright (C) 2010 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 /**
     32  * @fileoverview DevTools' implementation of the InspectorController API.
     33  */
     34 
     35 if (!this.devtools)
     36     devtools = {};
     37 
     38 devtools.InspectorBackendImpl = function()
     39 {
     40     WebInspector.InspectorBackendStub.call(this);
     41     this.installInspectorControllerDelegate_("clearMessages");
     42     this.installInspectorControllerDelegate_("copyNode");
     43     this.installInspectorControllerDelegate_("deleteCookie");
     44     this.installInspectorControllerDelegate_("didEvaluateForTestInFrontend");
     45     this.installInspectorControllerDelegate_("disableResourceTracking");
     46     this.installInspectorControllerDelegate_("disableTimeline");
     47     this.installInspectorControllerDelegate_("enableResourceTracking");
     48     this.installInspectorControllerDelegate_("enableTimeline");
     49     this.installInspectorControllerDelegate_("getChildNodes");
     50     this.installInspectorControllerDelegate_("getCookies");
     51     this.installInspectorControllerDelegate_("getDatabaseTableNames");
     52     this.installInspectorControllerDelegate_("getDOMStorageEntries");
     53     this.installInspectorControllerDelegate_("getEventListenersForNode");
     54     this.installInspectorControllerDelegate_("getResourceContent");
     55     this.installInspectorControllerDelegate_("highlightDOMNode");
     56     this.installInspectorControllerDelegate_("hideDOMNodeHighlight");
     57     this.installInspectorControllerDelegate_("releaseWrapperObjectGroup");
     58     this.installInspectorControllerDelegate_("removeAttribute");
     59     this.installInspectorControllerDelegate_("removeDOMStorageItem");
     60     this.installInspectorControllerDelegate_("removeNode");
     61     this.installInspectorControllerDelegate_("saveFrontendSettings");
     62     this.installInspectorControllerDelegate_("setAttribute");
     63     this.installInspectorControllerDelegate_("setDOMStorageItem");
     64     this.installInspectorControllerDelegate_("setInjectedScriptSource");
     65     this.installInspectorControllerDelegate_("setTextNodeValue");
     66     this.installInspectorControllerDelegate_("startTimelineProfiler");
     67     this.installInspectorControllerDelegate_("stopTimelineProfiler");
     68     this.installInspectorControllerDelegate_("storeLastActivePanel");
     69 };
     70 devtools.InspectorBackendImpl.prototype.__proto__ = WebInspector.InspectorBackendStub.prototype;
     71 
     72 
     73 /**
     74  * {@inheritDoc}.
     75  */
     76 devtools.InspectorBackendImpl.prototype.toggleNodeSearch = function()
     77 {
     78     WebInspector.InspectorBackendStub.prototype.toggleNodeSearch.call(this);
     79     this.callInspectorController_.call(this, "toggleNodeSearch");
     80     if (!this.searchingForNode()) {
     81         // This is called from ElementsPanel treeOutline's focusNodeChanged().
     82         DevToolsHost.activateWindow();
     83     }
     84 };
     85 
     86 
     87 /**
     88  * @override
     89  */
     90 devtools.InspectorBackendImpl.prototype.debuggerEnabled = function()
     91 {
     92     return true;
     93 };
     94 
     95 
     96 /**
     97  * @override
     98  */
     99 devtools.InspectorBackendImpl.prototype.profilerEnabled = function()
    100 {
    101     return true;
    102 };
    103 
    104 
    105 devtools.InspectorBackendImpl.prototype.addBreakpoint = function(sourceID, line, condition)
    106 {
    107     devtools.tools.getDebuggerAgent().addBreakpoint(sourceID, line, condition);
    108 };
    109 
    110 
    111 devtools.InspectorBackendImpl.prototype.removeBreakpoint = function(sourceID, line)
    112 {
    113     devtools.tools.getDebuggerAgent().removeBreakpoint(sourceID, line);
    114 };
    115 
    116 devtools.InspectorBackendImpl.prototype.updateBreakpoint = function(sourceID, line, condition)
    117 {
    118     devtools.tools.getDebuggerAgent().updateBreakpoint(sourceID, line, condition);
    119 };
    120 
    121 devtools.InspectorBackendImpl.prototype.pauseInDebugger = function()
    122 {
    123     devtools.tools.getDebuggerAgent().pauseExecution();
    124 };
    125 
    126 
    127 devtools.InspectorBackendImpl.prototype.resumeDebugger = function()
    128 {
    129     devtools.tools.getDebuggerAgent().resumeExecution();
    130 };
    131 
    132 
    133 devtools.InspectorBackendImpl.prototype.stepIntoStatementInDebugger = function()
    134 {
    135     devtools.tools.getDebuggerAgent().stepIntoStatement();
    136 };
    137 
    138 
    139 devtools.InspectorBackendImpl.prototype.stepOutOfFunctionInDebugger = function()
    140 {
    141     devtools.tools.getDebuggerAgent().stepOutOfFunction();
    142 };
    143 
    144 
    145 devtools.InspectorBackendImpl.prototype.stepOverStatementInDebugger = function()
    146 {
    147     devtools.tools.getDebuggerAgent().stepOverStatement();
    148 };
    149 
    150 /**
    151  * @override
    152  */
    153 devtools.InspectorBackendImpl.prototype.setPauseOnExceptionsState = function(state)
    154 {
    155     this._setPauseOnExceptionsState = state;
    156     // TODO(yurys): support all three states. See http://crbug.com/32877
    157     var enabled = (state !== WebInspector.ScriptsPanel.PauseOnExceptionsState.DontPauseOnExceptions);
    158     return devtools.tools.getDebuggerAgent().setPauseOnExceptions(enabled);
    159 };
    160 
    161 /**
    162  * @override
    163  */
    164 devtools.InspectorBackendImpl.prototype.pauseOnExceptionsState = function()
    165 {
    166     return (this._setPauseOnExceptionsState || WebInspector.ScriptsPanel.PauseOnExceptionsState.DontPauseOnExceptions);
    167 };
    168 
    169 /**
    170  * @override
    171  */
    172 devtools.InspectorBackendImpl.prototype.pauseOnExceptions = function()
    173 {
    174     return devtools.tools.getDebuggerAgent().pauseOnExceptions();
    175 };
    176 
    177 
    178 /**
    179  * @override
    180  */
    181 devtools.InspectorBackendImpl.prototype.setPauseOnExceptions = function(value)
    182 {
    183     return devtools.tools.getDebuggerAgent().setPauseOnExceptions(value);
    184 };
    185 
    186 
    187 /**
    188  * @override
    189  */
    190 devtools.InspectorBackendImpl.prototype.startProfiling = function()
    191 {
    192     devtools.tools.getProfilerAgent().startProfiling(devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_CPU);
    193 };
    194 
    195 
    196 /**
    197  * @override
    198  */
    199 devtools.InspectorBackendImpl.prototype.stopProfiling = function()
    200 {
    201     devtools.tools.getProfilerAgent().stopProfiling( devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_CPU);
    202 };
    203 
    204 
    205 /**
    206  * @override
    207  */
    208 devtools.InspectorBackendImpl.prototype.getProfileHeaders = function(callId)
    209 {
    210     WebInspector.didGetProfileHeaders(callId, []);
    211 };
    212 
    213 
    214 /**
    215  * Emulate WebKit InspectorController behavior. It stores profiles on renderer side,
    216  * and is able to retrieve them by uid using "getProfile".
    217  */
    218 devtools.InspectorBackendImpl.prototype.addFullProfile = function(profile)
    219 {
    220     WebInspector.__fullProfiles = WebInspector.__fullProfiles || {};
    221     WebInspector.__fullProfiles[profile.uid] = profile;
    222 };
    223 
    224 
    225 /**
    226  * @override
    227  */
    228 devtools.InspectorBackendImpl.prototype.getProfile = function(callId, uid)
    229 {
    230     if (WebInspector.__fullProfiles && (uid in WebInspector.__fullProfiles))
    231         WebInspector.didGetProfile(callId, WebInspector.__fullProfiles[uid]);
    232 };
    233 
    234 
    235 /**
    236  * @override
    237  */
    238 devtools.InspectorBackendImpl.prototype.takeHeapSnapshot = function()
    239 {
    240     devtools.tools.getProfilerAgent().startProfiling(devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_HEAP_SNAPSHOT
    241         | devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_HEAP_STATS
    242         | devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_JS_CONSTRUCTORS);
    243 };
    244 
    245 
    246 /**
    247  * @override
    248  */
    249 devtools.InspectorBackendImpl.prototype.dispatchOnInjectedScript = function(callId, injectedScriptId, methodName, argsString, async)
    250 {
    251     // Encode injectedScriptId into callId
    252     if (typeof injectedScriptId !== "number")
    253         injectedScriptId = 0;
    254     RemoteToolsAgent.dispatchOnInjectedScript(callId, injectedScriptId, methodName, argsString, async);
    255 };
    256 
    257 
    258 /**
    259  * Installs delegating handler into the inspector controller.
    260  * @param {string} methodName Method to install delegating handler for.
    261  */
    262 devtools.InspectorBackendImpl.prototype.installInspectorControllerDelegate_ = function(methodName)
    263 {
    264     this[methodName] = this.callInspectorController_.bind(this, methodName);
    265 };
    266 
    267 
    268 /**
    269  * Bound function with the installInjectedScriptDelegate_ actual
    270  * implementation.
    271  */
    272 devtools.InspectorBackendImpl.prototype.callInspectorController_ = function(methodName, var_arg)
    273 {
    274     var args = Array.prototype.slice.call(arguments, 1);
    275     RemoteToolsAgent.dispatchOnInspectorController(WebInspector.Callback.wrap(function(){}), methodName, JSON.stringify(args));
    276 };
    277 
    278 
    279 InspectorBackend = new devtools.InspectorBackendImpl();
    280