InspectorFrontendAPI.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2011 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. var InspectorFrontendAPI = {
  31. _pendingCommands: [],
  32. setAttachedWindow: function(side)
  33. {
  34. },
  35. setDockSide: function(side)
  36. {
  37. if (WebInspector.dockController)
  38. WebInspector.dockController.setDockSide(side);
  39. },
  40. showConsole: function()
  41. {
  42. WebInspector.showPanel("console");
  43. },
  44. showMainResourceForFrame: function(frameId)
  45. {
  46. // FIXME: Implement this to show the source code for the main resource of a given frame.
  47. },
  48. showResources: function()
  49. {
  50. WebInspector.showPanel("resources");
  51. },
  52. setDockingUnavailable: function(unavailable)
  53. {
  54. WebInspector.setDockingUnavailable(unavailable);
  55. },
  56. enterInspectElementMode: function()
  57. {
  58. WebInspector.showPanel("elements");
  59. if (WebInspector.inspectElementModeController)
  60. WebInspector.inspectElementModeController.toggleSearch();
  61. },
  62. fileSystemsLoaded: function(fileSystems)
  63. {
  64. WebInspector.isolatedFileSystemDispatcher.fileSystemsLoaded(fileSystems);
  65. },
  66. fileSystemRemoved: function(fileSystemPath)
  67. {
  68. WebInspector.isolatedFileSystemDispatcher.fileSystemRemoved(fileSystemPath);
  69. },
  70. fileSystemAdded: function(errorMessage, fileSystem)
  71. {
  72. WebInspector.isolatedFileSystemDispatcher.fileSystemAdded(errorMessage, fileSystem);
  73. },
  74. indexingTotalWorkCalculated: function(requestId, fileSystemPath, totalWork)
  75. {
  76. var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
  77. projectDelegate.indexingTotalWorkCalculated(requestId, totalWork);
  78. },
  79. indexingWorked: function(requestId, fileSystemPath, worked)
  80. {
  81. var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
  82. projectDelegate.indexingWorked(requestId, worked);
  83. },
  84. indexingDone: function(requestId, fileSystemPath)
  85. {
  86. var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
  87. projectDelegate.indexingDone(requestId);
  88. },
  89. searchCompleted: function(requestId, fileSystemPath, files)
  90. {
  91. var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
  92. projectDelegate.searchCompleted(requestId, files);
  93. },
  94. savedURL: function(url)
  95. {
  96. WebInspector.fileManager.savedURL(url);
  97. },
  98. appendedToURL: function(url)
  99. {
  100. WebInspector.fileManager.appendedToURL(url);
  101. },
  102. setToolbarColors: function(backgroundColor, color)
  103. {
  104. WebInspector.setToolbarColors(backgroundColor, color);
  105. },
  106. evaluateForTest: function(callId, script)
  107. {
  108. WebInspector.evaluateForTestInFrontend(callId, script);
  109. },
  110. dispatch: function(signature)
  111. {
  112. if (InspectorFrontendAPI._isLoaded) {
  113. var methodName = signature.shift();
  114. return InspectorFrontendAPI[methodName].apply(InspectorFrontendAPI, signature);
  115. }
  116. InspectorFrontendAPI._pendingCommands.push(signature);
  117. },
  118. dispatchQueryParameters: function()
  119. {
  120. if ("dispatch" in WebInspector.queryParamsObject)
  121. InspectorFrontendAPI.dispatch(JSON.parse(window.decodeURI(WebInspector.queryParamsObject["dispatch"])));
  122. },
  123. /**
  124. * @param {string} url
  125. */
  126. loadTimelineFromURL: function(url)
  127. {
  128. /** @type {WebInspector.TimelinePanel} */ (WebInspector.showPanel("timeline")).loadFromURL(url);
  129. },
  130. loadCompleted: function()
  131. {
  132. InspectorFrontendAPI._isLoaded = true;
  133. for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
  134. InspectorFrontendAPI.dispatch(InspectorFrontendAPI._pendingCommands[i]);
  135. InspectorFrontendAPI._pendingCommands = [];
  136. if (window.opener)
  137. window.opener.postMessage(["loadCompleted"], "*");
  138. },
  139. contextMenuItemSelected: function(id)
  140. {
  141. WebInspector.contextMenuItemSelected(id);
  142. },
  143. contextMenuCleared: function()
  144. {
  145. WebInspector.contextMenuCleared();
  146. },
  147. dispatchMessageAsync: function(messageObject)
  148. {
  149. WebInspector.dispatch(messageObject);
  150. },
  151. dispatchMessage: function(messageObject)
  152. {
  153. InspectorBackend.dispatch(messageObject);
  154. }
  155. }
  156. if (window.opener && window.dispatchStandaloneTestRunnerMessages) {
  157. function onMessageFromOpener(event)
  158. {
  159. if (event.source === window.opener)
  160. InspectorFrontendAPI.dispatch(event.data);
  161. }
  162. window.addEventListener("message", onMessageFromOpener, true);
  163. }