NetworkItemView.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. * @constructor
  32. * @extends {WebInspector.TabbedPane}
  33. * @param {WebInspector.NetworkRequest} request
  34. */
  35. WebInspector.NetworkItemView = function(request)
  36. {
  37. WebInspector.TabbedPane.call(this);
  38. this.element.addStyleClass("network-item-view");
  39. var headersView = new WebInspector.RequestHeadersView(request);
  40. this.appendTab("headers", WebInspector.UIString("Headers"), headersView);
  41. this.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  42. if (request.type === WebInspector.resourceTypes.WebSocket) {
  43. var frameView = new WebInspector.ResourceWebSocketFrameView(request);
  44. this.appendTab("webSocketFrames", WebInspector.UIString("Frames"), frameView);
  45. } else {
  46. var responseView = new WebInspector.RequestResponseView(request);
  47. var previewView = new WebInspector.RequestPreviewView(request, responseView);
  48. this.appendTab("preview", WebInspector.UIString("Preview"), previewView);
  49. this.appendTab("response", WebInspector.UIString("Response"), responseView);
  50. }
  51. if (request.requestCookies || request.responseCookies) {
  52. this._cookiesView = new WebInspector.RequestCookiesView(request);
  53. this.appendTab("cookies", WebInspector.UIString("Cookies"), this._cookiesView);
  54. }
  55. if (request.timing) {
  56. var timingView = new WebInspector.RequestTimingView(request);
  57. this.appendTab("timing", WebInspector.UIString("Timing"), timingView);
  58. }
  59. this._request = request;
  60. }
  61. WebInspector.NetworkItemView.prototype = {
  62. wasShown: function()
  63. {
  64. WebInspector.TabbedPane.prototype.wasShown.call(this);
  65. this._selectTab();
  66. },
  67. /**
  68. * @param {string=} tabId
  69. */
  70. _selectTab: function(tabId)
  71. {
  72. if (!tabId)
  73. tabId = WebInspector.settings.resourceViewTab.get();
  74. if (!this.selectTab(tabId)) {
  75. this._isInFallbackSelection = true;
  76. this.selectTab("headers");
  77. delete this._isInFallbackSelection;
  78. }
  79. },
  80. _tabSelected: function(event)
  81. {
  82. if (!event.data.isUserGesture)
  83. return;
  84. WebInspector.settings.resourceViewTab.set(event.data.tabId);
  85. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  86. action: WebInspector.UserMetrics.UserActionNames.NetworkRequestTabSelected,
  87. tab: event.data.tabId,
  88. url: this._request.url
  89. });
  90. },
  91. /**
  92. * @return {WebInspector.NetworkRequest}
  93. */
  94. request: function()
  95. {
  96. return this._request;
  97. },
  98. __proto__: WebInspector.TabbedPane.prototype
  99. }
  100. /**
  101. * @constructor
  102. * @extends {WebInspector.RequestView}
  103. * @param {WebInspector.NetworkRequest} request
  104. */
  105. WebInspector.RequestContentView = function(request)
  106. {
  107. WebInspector.RequestView.call(this, request);
  108. }
  109. WebInspector.RequestContentView.prototype = {
  110. hasContent: function()
  111. {
  112. return true;
  113. },
  114. get innerView()
  115. {
  116. return this._innerView;
  117. },
  118. set innerView(innerView)
  119. {
  120. this._innerView = innerView;
  121. },
  122. wasShown: function()
  123. {
  124. this._ensureInnerViewShown();
  125. },
  126. _ensureInnerViewShown: function()
  127. {
  128. if (this._innerViewShowRequested)
  129. return;
  130. this._innerViewShowRequested = true;
  131. /**
  132. * @param {?string} content
  133. * @param {boolean} contentEncoded
  134. * @param {string} mimeType
  135. */
  136. function callback(content, contentEncoded, mimeType)
  137. {
  138. this._innerViewShowRequested = false;
  139. this.contentLoaded();
  140. }
  141. this.request.requestContent(callback.bind(this));
  142. },
  143. contentLoaded: function()
  144. {
  145. // Should be implemented by subclasses.
  146. },
  147. canHighlightLine: function()
  148. {
  149. return this._innerView && this._innerView.canHighlightLine();
  150. },
  151. highlightLine: function(line)
  152. {
  153. if (this.canHighlightLine())
  154. this._innerView.highlightLine(line);
  155. },
  156. __proto__: WebInspector.RequestView.prototype
  157. }