123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982 |
- /*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- /**
- * @constructor
- * @extends {WebInspector.Object}
- * @implements {WebInspector.ContentProvider}
- * @param {NetworkAgent.RequestId} requestId
- * @param {string} url
- * @param {string} documentURL
- * @param {PageAgent.FrameId} frameId
- * @param {NetworkAgent.LoaderId} loaderId
- */
- WebInspector.NetworkRequest = function(requestId, url, documentURL, frameId, loaderId)
- {
- this._requestId = requestId;
- this.url = url;
- this._documentURL = documentURL;
- this._frameId = frameId;
- this._loaderId = loaderId;
- this._startTime = -1;
- this._endTime = -1;
- this.statusCode = 0;
- this.statusText = "";
- this.requestMethod = "";
- this.requestTime = 0;
- this.receiveHeadersEnd = 0;
- this._type = WebInspector.resourceTypes.Other;
- this._contentEncoded = false;
- this._pendingContentCallbacks = [];
- this._frames = [];
- this._responseHeaderValues = {};
- }
- WebInspector.NetworkRequest.Events = {
- FinishedLoading: "FinishedLoading",
- TimingChanged: "TimingChanged",
- RequestHeadersChanged: "RequestHeadersChanged",
- ResponseHeadersChanged: "ResponseHeadersChanged",
- }
- /** @enum {string} */
- WebInspector.NetworkRequest.InitiatorType = {
- Other: "other",
- Parser: "parser",
- Redirect: "redirect",
- Script: "script"
- }
- /** @typedef {{name: string, value: string}} */
- WebInspector.NetworkRequest.NameValue;
- WebInspector.NetworkRequest.prototype = {
- /**
- * @return {NetworkAgent.RequestId}
- */
- get requestId()
- {
- return this._requestId;
- },
- set requestId(requestId)
- {
- this._requestId = requestId;
- },
- /**
- * @return {string}
- */
- get url()
- {
- return this._url;
- },
- set url(x)
- {
- if (this._url === x)
- return;
- this._url = x;
- this._parsedURL = new WebInspector.ParsedURL(x);
- delete this._parsedQueryParameters;
- delete this._name;
- delete this._path;
- },
- /**
- * @return {string}
- */
- get documentURL()
- {
- return this._documentURL;
- },
- get parsedURL()
- {
- return this._parsedURL;
- },
- /**
- * @return {PageAgent.FrameId}
- */
- get frameId()
- {
- return this._frameId;
- },
- /**
- * @return {NetworkAgent.LoaderId}
- */
- get loaderId()
- {
- return this._loaderId;
- },
- /**
- * @return {number}
- */
- get startTime()
- {
- return this._startTime || -1;
- },
- set startTime(x)
- {
- this._startTime = x;
- },
- /**
- * @return {number}
- */
- get responseReceivedTime()
- {
- return this._responseReceivedTime || -1;
- },
- set responseReceivedTime(x)
- {
- this._responseReceivedTime = x;
- },
- /**
- * @return {number}
- */
- get endTime()
- {
- return this._endTime || -1;
- },
- set endTime(x)
- {
- if (this.timing && this.timing.requestTime) {
- // Check against accurate responseReceivedTime.
- this._endTime = Math.max(x, this.responseReceivedTime);
- } else {
- // Prefer endTime since it might be from the network stack.
- this._endTime = x;
- if (this._responseReceivedTime > x)
- this._responseReceivedTime = x;
- }
- },
- /**
- * @return {number}
- */
- get duration()
- {
- if (this._endTime === -1 || this._startTime === -1)
- return -1;
- return this._endTime - this._startTime;
- },
- /**
- * @return {number}
- */
- get latency()
- {
- if (this._responseReceivedTime === -1 || this._startTime === -1)
- return -1;
- return this._responseReceivedTime - this._startTime;
- },
- /**
- * @return {number}
- */
- get receiveDuration()
- {
- if (this._endTime === -1 || this._responseReceivedTime === -1)
- return -1;
- return this._endTime - this._responseReceivedTime;
- },
- /**
- * @return {number}
- */
- get resourceSize()
- {
- return this._resourceSize || 0;
- },
- set resourceSize(x)
- {
- this._resourceSize = x;
- },
- /**
- * @return {number}
- */
- get transferSize()
- {
- if (typeof this._transferSize === "number")
- return this._transferSize;
- if (this.statusCode === 304) // Not modified
- return this.responseHeadersSize;
- if (this._cached)
- return 0;
- // If we did not receive actual transfer size from network
- // stack, we prefer using Content-Length over resourceSize as
- // resourceSize may differ from actual transfer size if platform's
- // network stack performed decoding (e.g. gzip decompression).
- // The Content-Length, though, is expected to come from raw
- // response headers and will reflect actual transfer length.
- // This won't work for chunked content encoding, so fall back to
- // resourceSize when we don't have Content-Length. This still won't
- // work for chunks with non-trivial encodings. We need a way to
- // get actual transfer size from the network stack.
- var bodySize = Number(this.responseHeaderValue("Content-Length") || this.resourceSize);
- return this.responseHeadersSize + bodySize;
- },
- /**
- * @param {number} x
- */
- increaseTransferSize: function(x)
- {
- this._transferSize = (this._transferSize || 0) + x;
- },
- /**
- * @return {boolean}
- */
- get finished()
- {
- return this._finished;
- },
- set finished(x)
- {
- if (this._finished === x)
- return;
- this._finished = x;
- if (x) {
- this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.FinishedLoading, this);
- if (this._pendingContentCallbacks.length)
- this._innerRequestContent();
- }
- },
- /**
- * @return {boolean}
- */
- get failed()
- {
- return this._failed;
- },
- set failed(x)
- {
- this._failed = x;
- },
- /**
- * @return {boolean}
- */
- get canceled()
- {
- return this._canceled;
- },
- set canceled(x)
- {
- this._canceled = x;
- },
- /**
- * @return {boolean}
- */
- get cached()
- {
- return this._cached && !this._transferSize;
- },
- set cached(x)
- {
- this._cached = x;
- if (x)
- delete this._timing;
- },
- /**
- * @return {NetworkAgent.ResourceTiming|undefined}
- */
- get timing()
- {
- return this._timing;
- },
- set timing(x)
- {
- if (x && !this._cached) {
- // Take startTime and responseReceivedTime from timing data for better accuracy.
- // Timing's requestTime is a baseline in seconds, rest of the numbers there are ticks in millis.
- this._startTime = x.requestTime;
- this._responseReceivedTime = x.requestTime + x.receiveHeadersEnd / 1000.0;
- this._timing = x;
- this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.TimingChanged, this);
- }
- },
- /**
- * @return {string}
- */
- get mimeType()
- {
- return this._mimeType;
- },
- set mimeType(x)
- {
- this._mimeType = x;
- },
- /**
- * @return {string}
- */
- get displayName()
- {
- return this._parsedURL.displayName;
- },
- name: function()
- {
- if (this._name)
- return this._name;
- this._parseNameAndPathFromURL();
- return this._name;
- },
- path: function()
- {
- if (this._path)
- return this._path;
- this._parseNameAndPathFromURL();
- return this._path;
- },
- _parseNameAndPathFromURL: function()
- {
- if (this._parsedURL.isDataURL()) {
- this._name = this._parsedURL.dataURLDisplayName();
- this._path = "";
- } else if (this._parsedURL.isAboutBlank()) {
- this._name = this._parsedURL.url;
- this._path = "";
- } else {
- this._path = this._parsedURL.host + this._parsedURL.folderPathComponents;
- this._path = this._path.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : "");
- if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams)
- this._name = this._parsedURL.lastPathComponent + (this._parsedURL.queryParams ? "?" + this._parsedURL.queryParams : "");
- else if (this._parsedURL.folderPathComponents) {
- this._name = this._parsedURL.folderPathComponents.substring(this._parsedURL.folderPathComponents.lastIndexOf("/") + 1) + "/";
- this._path = this._path.substring(0, this._path.lastIndexOf("/"));
- } else {
- this._name = this._parsedURL.host;
- this._path = "";
- }
- }
- },
- /**
- * @return {string}
- */
- get folder()
- {
- var path = this._parsedURL.path;
- var indexOfQuery = path.indexOf("?");
- if (indexOfQuery !== -1)
- path = path.substring(0, indexOfQuery);
- var lastSlashIndex = path.lastIndexOf("/");
- return lastSlashIndex !== -1 ? path.substring(0, lastSlashIndex) : "";
- },
- /**
- * @return {WebInspector.ResourceType}
- */
- get type()
- {
- return this._type;
- },
- set type(x)
- {
- this._type = x;
- },
- /**
- * @return {string}
- */
- get domain()
- {
- return this._parsedURL.host;
- },
- /**
- * @return {string}
- */
- get scheme()
- {
- return this._parsedURL.scheme;
- },
- /**
- * @return {?WebInspector.NetworkRequest}
- */
- get redirectSource()
- {
- if (this.redirects && this.redirects.length > 0)
- return this.redirects[this.redirects.length - 1];
- return this._redirectSource;
- },
- set redirectSource(x)
- {
- this._redirectSource = x;
- delete this._initiatorInfo;
- },
- /**
- * @return {!Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- get requestHeaders()
- {
- return this._requestHeaders || [];
- },
- set requestHeaders(x)
- {
- this._requestHeaders = x;
- delete this._sortedRequestHeaders;
- delete this._requestCookies;
- this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RequestHeadersChanged);
- },
- /**
- * @return {string}
- */
- get requestHeadersText()
- {
- if (typeof this._requestHeadersText === "undefined") {
- this._requestHeadersText = this.requestMethod + " " + this.url + " HTTP/1.1\r\n";
- for (var i = 0; i < this.requestHeaders.length; ++i)
- this._requestHeadersText += this.requestHeaders[i].name + ": " + this.requestHeaders[i].value + "\r\n";
- }
- return this._requestHeadersText;
- },
- set requestHeadersText(x)
- {
- this._requestHeadersText = x;
- this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RequestHeadersChanged);
- },
- /**
- * @return {number}
- */
- get requestHeadersSize()
- {
- return this.requestHeadersText.length;
- },
- /**
- * @return {!Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- get sortedRequestHeaders()
- {
- if (this._sortedRequestHeaders !== undefined)
- return this._sortedRequestHeaders;
- this._sortedRequestHeaders = [];
- this._sortedRequestHeaders = this.requestHeaders.slice();
- this._sortedRequestHeaders.sort(function(a,b) { return a.name.toLowerCase().compareTo(b.name.toLowerCase()) });
- return this._sortedRequestHeaders;
- },
- /**
- * @param {string} headerName
- * @return {string|undefined}
- */
- requestHeaderValue: function(headerName)
- {
- return this._headerValue(this.requestHeaders, headerName);
- },
- /**
- * @return {Array.<WebInspector.Cookie>}
- */
- get requestCookies()
- {
- if (!this._requestCookies)
- this._requestCookies = WebInspector.CookieParser.parseCookie(this.requestHeaderValue("Cookie"));
- return this._requestCookies;
- },
- /**
- * @return {string|undefined}
- */
- get requestFormData()
- {
- return this._requestFormData;
- },
- set requestFormData(x)
- {
- this._requestFormData = x;
- delete this._parsedFormParameters;
- },
- /**
- * @return {string|undefined}
- */
- get requestHttpVersion()
- {
- var firstLine = this.requestHeadersText.split(/\r\n/)[0];
- var match = firstLine.match(/(HTTP\/\d+\.\d+)$/);
- return match ? match[1] : undefined;
- },
- /**
- * @return {!Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- get responseHeaders()
- {
- return this._responseHeaders || [];
- },
- set responseHeaders(x)
- {
- this._responseHeaders = x;
- delete this._sortedResponseHeaders;
- delete this._responseCookies;
- this._responseHeaderValues = {};
- this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.ResponseHeadersChanged);
- },
- /**
- * @return {string}
- */
- get responseHeadersText()
- {
- if (typeof this._responseHeadersText === "undefined") {
- this._responseHeadersText = "HTTP/1.1 " + this.statusCode + " " + this.statusText + "\r\n";
- for (var i = 0; i < this.responseHeaders.length; ++i)
- this._responseHeadersText += this.responseHeaders[i].name + ": " + this.responseHeaders[i].value + "\r\n";
- }
- return this._responseHeadersText;
- },
- set responseHeadersText(x)
- {
- this._responseHeadersText = x;
- this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.ResponseHeadersChanged);
- },
- /**
- * @return {number}
- */
- get responseHeadersSize()
- {
- return this.responseHeadersText.length;
- },
- /**
- * @return {!Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- get sortedResponseHeaders()
- {
- if (this._sortedResponseHeaders !== undefined)
- return this._sortedResponseHeaders;
- this._sortedResponseHeaders = [];
- this._sortedResponseHeaders = this.responseHeaders.slice();
- this._sortedResponseHeaders.sort(function(a, b) { return a.name.toLowerCase().compareTo(b.name.toLowerCase()); });
- return this._sortedResponseHeaders;
- },
- /**
- * @param {string} headerName
- * @return {string|undefined}
- */
- responseHeaderValue: function(headerName)
- {
- var value = this._responseHeaderValues[headerName];
- if (value === undefined) {
- value = this._headerValue(this.responseHeaders, headerName);
- this._responseHeaderValues[headerName] = (value !== undefined) ? value : null;
- }
- return (value !== null) ? value : undefined;
- },
- /**
- * @return {Array.<WebInspector.Cookie>}
- */
- get responseCookies()
- {
- if (!this._responseCookies)
- this._responseCookies = WebInspector.CookieParser.parseSetCookie(this.responseHeaderValue("Set-Cookie"));
- return this._responseCookies;
- },
- /**
- * @return {?string}
- */
- queryString: function()
- {
- if (this._queryString)
- return this._queryString;
- var queryString = this.url.split("?", 2)[1];
- if (!queryString)
- return null;
- this._queryString = queryString.split("#", 2)[0];
- return this._queryString;
- },
- /**
- * @return {?Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- get queryParameters()
- {
- if (this._parsedQueryParameters)
- return this._parsedQueryParameters;
- var queryString = this.queryString();
- if (!queryString)
- return null;
- this._parsedQueryParameters = this._parseParameters(queryString);
- return this._parsedQueryParameters;
- },
- /**
- * @return {?Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- get formParameters()
- {
- if (this._parsedFormParameters)
- return this._parsedFormParameters;
- if (!this.requestFormData)
- return null;
- var requestContentType = this.requestContentType();
- if (!requestContentType || !requestContentType.match(/^application\/x-www-form-urlencoded\s*(;.*)?$/i))
- return null;
- this._parsedFormParameters = this._parseParameters(this.requestFormData);
- return this._parsedFormParameters;
- },
- /**
- * @return {string|undefined}
- */
- get responseHttpVersion()
- {
- var match = this.responseHeadersText.match(/^(HTTP\/\d+\.\d+)/);
- return match ? match[1] : undefined;
- },
- /**
- * @param {string} queryString
- * @return {!Array.<!WebInspector.NetworkRequest.NameValue>}
- */
- _parseParameters: function(queryString)
- {
- function parseNameValue(pair)
- {
- var splitPair = pair.split("=", 2);
- return {name: splitPair[0], value: splitPair[1] || ""};
- }
- return queryString.split("&").map(parseNameValue);
- },
- /**
- * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers
- * @param {string} headerName
- * @return {string|undefined}
- */
- _headerValue: function(headers, headerName)
- {
- headerName = headerName.toLowerCase();
- var values = [];
- for (var i = 0; i < headers.length; ++i) {
- if (headers[i].name.toLowerCase() === headerName)
- values.push(headers[i].value);
- }
- if (!values.length)
- return undefined;
- // Set-Cookie values should be separated by '\n', not comma, otherwise cookies could not be parsed.
- if (headerName === "set-cookie")
- return values.join("\n");
- return values.join(", ");
- },
- /**
- * @return {?string|undefined}
- */
- get content()
- {
- return this._content;
- },
- /**
- * @return {boolean}
- */
- get contentEncoded()
- {
- return this._contentEncoded;
- },
- /**
- * @return {string}
- */
- contentURL: function()
- {
- return this._url;
- },
- /**
- * @return {WebInspector.ResourceType}
- */
- contentType: function()
- {
- return this._type;
- },
- /**
- * @param {function(?string, boolean, string)} callback
- */
- requestContent: function(callback)
- {
- // We do not support content retrieval for WebSockets at the moment.
- // Since WebSockets are potentially long-living, fail requests immediately
- // to prevent caller blocking until resource is marked as finished.
- if (this.type === WebInspector.resourceTypes.WebSocket) {
- callback(null, false, this._mimeType);
- return;
- }
- if (typeof this._content !== "undefined") {
- callback(this.content || null, this._contentEncoded, this.type.canonicalMimeType() || this._mimeType);
- return;
- }
- this._pendingContentCallbacks.push(callback);
- if (this.finished)
- this._innerRequestContent();
- },
- /**
- * @param {string} query
- * @param {boolean} caseSensitive
- * @param {boolean} isRegex
- * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
- */
- searchInContent: function(query, caseSensitive, isRegex, callback)
- {
- callback([]);
- },
- /**
- * @return {boolean}
- */
- isHttpFamily: function()
- {
- return !!this.url.match(/^https?:/i);
- },
- /**
- * @return {string|undefined}
- */
- requestContentType: function()
- {
- return this.requestHeaderValue("Content-Type");
- },
- /**
- * @return {boolean}
- */
- isPingRequest: function()
- {
- return "text/ping" === this.requestContentType();
- },
- /**
- * @return {boolean}
- */
- hasErrorStatusCode: function()
- {
- return this.statusCode >= 400;
- },
- /**
- * @param {Element} image
- */
- populateImageSource: function(image)
- {
- /**
- * @this {WebInspector.NetworkRequest}
- * @param {?string} content
- * @param {boolean} contentEncoded
- * @param {string} mimeType
- */
- function onResourceContent(content, contentEncoded, mimeType)
- {
- var imageSrc = this.asDataURL();
- if (imageSrc === null)
- imageSrc = this.url;
- image.src = imageSrc;
- }
- this.requestContent(onResourceContent.bind(this));
- },
- /**
- * @return {?string}
- */
- asDataURL: function()
- {
- return WebInspector.contentAsDataURL(this._content, this.mimeType, this._contentEncoded);
- },
- _innerRequestContent: function()
- {
- if (this._contentRequested)
- return;
- this._contentRequested = true;
- /**
- * @param {?Protocol.Error} error
- * @param {string} content
- * @param {boolean} contentEncoded
- */
- function onResourceContent(error, content, contentEncoded)
- {
- this._content = error ? null : content;
- this._contentEncoded = contentEncoded;
- var callbacks = this._pendingContentCallbacks.slice();
- for (var i = 0; i < callbacks.length; ++i)
- callbacks[i](this._content, this._contentEncoded, this._mimeType);
- this._pendingContentCallbacks.length = 0;
- delete this._contentRequested;
- }
- NetworkAgent.getResponseBody(this._requestId, onResourceContent.bind(this));
- },
- /**
- * @return {{type: WebInspector.NetworkRequest.InitiatorType, url: string, source: string, lineNumber: number, columnNumber: number}}
- */
- initiatorInfo: function()
- {
- if (this._initiatorInfo)
- return this._initiatorInfo;
- var type = WebInspector.NetworkRequest.InitiatorType.Other;
- var url = "";
- var lineNumber = -Infinity;
- var columnNumber = -Infinity;
- if (this.redirectSource) {
- type = WebInspector.NetworkRequest.InitiatorType.Redirect;
- url = this.redirectSource.url;
- } else if (this.initiator) {
- if (this.initiator.type === NetworkAgent.InitiatorType.Parser) {
- type = WebInspector.NetworkRequest.InitiatorType.Parser;
- url = this.initiator.url;
- lineNumber = this.initiator.lineNumber;
- } else if (this.initiator.type === NetworkAgent.InitiatorType.Script) {
- var topFrame = this.initiator.stackTrace[0];
- if (topFrame.url) {
- type = WebInspector.NetworkRequest.InitiatorType.Script;
- url = topFrame.url;
- lineNumber = topFrame.lineNumber;
- columnNumber = topFrame.columnNumber;
- }
- }
- }
- this._initiatorInfo = {type: type, url: url, source: WebInspector.displayNameForURL(url), lineNumber: lineNumber, columnNumber: columnNumber};
- return this._initiatorInfo;
- },
- /**
- * @return {!Array.<!Object>}
- */
- frames: function()
- {
- return this._frames;
- },
- /**
- * @param {number} position
- * @return {Object|undefined}
- */
- frame: function(position)
- {
- return this._frames[position];
- },
- /**
- * @param {string} errorMessage
- * @param {number} time
- */
- addFrameError: function(errorMessage, time)
- {
- this._pushFrame({errorMessage: errorMessage, time: time});
- },
- /**
- * @param {!NetworkAgent.WebSocketFrame} response
- * @param {number} time
- * @param {boolean} sent
- */
- addFrame: function(response, time, sent)
- {
- response.time = time;
- if (sent)
- response.sent = sent;
- this._pushFrame(response);
- },
- /**
- * @param {!Object} frameOrError
- */
- _pushFrame: function(frameOrError)
- {
- if (this._frames.length >= 100)
- this._frames.splice(0, 10);
- this._frames.push(frameOrError);
- },
- __proto__: WebInspector.Object.prototype
- }
|