home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 July / CAG7.ISO / Internetas / SafariSetup.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_WorkersSidebarPane.js < prev    next >
Encoding:
Text File  |  2010-06-03  |  4.2 KB  |  117 lines

  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. WebInspector.WorkersSidebarPane = function()
  32. {
  33.     WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
  34.     
  35.     this._workers = {};
  36.  
  37.     this._enableWorkersCheckbox = new WebInspector.Checkbox(
  38.         WebInspector.UIString("Debug"),
  39.         this._onTriggerInstrument.bind(this),
  40.         false,
  41.         "sidebar-pane-subtitle",
  42.         WebInspector.UIString("Allow debugging workers. Enabling this option will replace native workers with the iframe-based JavaScript implementation"));
  43.  
  44.     this.titleElement.insertBefore(this._enableWorkersCheckbox.element, this.titleElement.firstChild);
  45.  
  46.     this._listElement = document.createElement("ol");
  47.     this._listElement.className = "workers-list";
  48.  
  49.     this.bodyElement.appendChild(this._listElement);
  50.     this._treeOutline = new TreeOutline(this._listElement);
  51. }
  52.  
  53. WebInspector.WorkersSidebarPane.prototype = {
  54.     addWorker: function(id, url, isShared)
  55.     {
  56.         if (id in this._workers) 
  57.             return;
  58.         var worker = new WebInspector.Worker(id, url, isShared);
  59.         this._workers[id] = worker;
  60.  
  61.         var title = WebInspector.linkifyURL(url, WebInspector.displayNameForURL(url), "worker-item", true, url);
  62.         var treeElement = new TreeElement(title, worker, false);
  63.         this._treeOutline.appendChild(treeElement);
  64.     },
  65.  
  66.     removeWorker: function(id)
  67.     {
  68.         if (id in this._workers) {
  69.             this._treeOutline.removeChild(this._treeOutline.findTreeElement(this._workers[id]));
  70.             delete this._workers[id];
  71.         }
  72.     },
  73.  
  74.     setInstrumentation: function(enabled)
  75.     {
  76.         InspectorBackend.removeAllScriptsToEvaluateOnLoad();
  77.         if (enabled)
  78.             InspectorBackend.addScriptToEvaluateOnLoad("(" + InjectedFakeWorker + ")");
  79.     },
  80.  
  81.     reset: function()
  82.     {
  83.         InspectorBackend.removeAllScriptsToEvaluateOnLoad();
  84.         this.setInstrumentation(this._enableWorkersCheckbox.checked());
  85.         this._treeOutline.removeChildren();
  86.         this._workers = {};
  87.     },
  88.  
  89.     _onTriggerInstrument: function(event)
  90.     {
  91.         this.setInstrumentation(this._enableWorkersCheckbox.checked());
  92.     }
  93. };
  94.  
  95. WebInspector.WorkersSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
  96.  
  97. WebInspector.Worker = function(id, url, shared)
  98. {
  99.     this.id = id;
  100.     this.url = url;
  101.     this.shared = shared;
  102. }
  103.  
  104. WebInspector.didCreateWorker = function()
  105. {
  106.     var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
  107.     if (workersPane)
  108.         workersPane.addWorker.apply(workersPane, arguments);
  109. }
  110.  
  111. WebInspector.didDestroyWorker = function()
  112. {
  113.     var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
  114.     if (workersPane)
  115.         workersPane.removeWorker.apply(workersPane, arguments);
  116. }
  117.