ResourceTreeModel.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. /**
  31. * @constructor
  32. * @extends {WebInspector.Object}
  33. * @param {WebInspector.NetworkManager} networkManager
  34. */
  35. WebInspector.ResourceTreeModel = function(networkManager)
  36. {
  37. networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, this._onRequestFinished, this);
  38. networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdateDropped, this._onRequestUpdateDropped, this);
  39. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
  40. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.RepeatCountUpdated, this._consoleMessageAdded, this);
  41. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
  42. PageAgent.enable();
  43. NetworkAgent.enable();
  44. this._fetchResourceTree();
  45. InspectorBackend.registerPageDispatcher(new WebInspector.PageDispatcher(this));
  46. this._pendingConsoleMessages = {};
  47. this._securityOriginFrameCount = {};
  48. }
  49. WebInspector.ResourceTreeModel.EventTypes = {
  50. FrameAdded: "FrameAdded",
  51. FrameNavigated: "FrameNavigated",
  52. FrameDetached: "FrameDetached",
  53. MainFrameNavigated: "MainFrameNavigated",
  54. MainFrameCreatedOrNavigated: "MainFrameCreatedOrNavigated",
  55. ResourceAdded: "ResourceAdded",
  56. WillLoadCachedResources: "WillLoadCachedResources",
  57. CachedResourcesLoaded: "CachedResourcesLoaded",
  58. DOMContentLoaded: "DOMContentLoaded",
  59. Load: "Load",
  60. InspectedURLChanged: "InspectedURLChanged",
  61. SecurityOriginAdded: "SecurityOriginAdded",
  62. SecurityOriginRemoved: "SecurityOriginRemoved",
  63. ScreencastFrame: "ScreencastFrame",
  64. }
  65. WebInspector.ResourceTreeModel.prototype = {
  66. _fetchResourceTree: function()
  67. {
  68. /** @type {!Object.<string, !WebInspector.ResourceTreeFrame>} */
  69. this._frames = {};
  70. delete this._cachedResourcesProcessed;
  71. PageAgent.getResourceTree(this._processCachedResources.bind(this));
  72. },
  73. _processCachedResources: function(error, mainFramePayload)
  74. {
  75. if (error) {
  76. console.error(JSON.stringify(error));
  77. return;
  78. }
  79. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.WillLoadCachedResources);
  80. WebInspector.inspectedPageURL = mainFramePayload.frame.url;
  81. this._addFramesRecursively(null, mainFramePayload);
  82. this._dispatchInspectedURLChanged();
  83. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded);
  84. this._cachedResourcesProcessed = true;
  85. },
  86. cachedResourcesLoaded: function()
  87. {
  88. return this._cachedResourcesProcessed;
  89. },
  90. _dispatchInspectedURLChanged: function()
  91. {
  92. InspectorFrontendHost.inspectedURLChanged(WebInspector.inspectedPageURL);
  93. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, WebInspector.inspectedPageURL);
  94. },
  95. /**
  96. * @param {WebInspector.ResourceTreeFrame} frame
  97. * @param {boolean=} aboutToNavigate
  98. */
  99. _addFrame: function(frame, aboutToNavigate)
  100. {
  101. this._frames[frame.id] = frame;
  102. if (frame.isMainFrame())
  103. this.mainFrame = frame;
  104. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, frame);
  105. if (!aboutToNavigate)
  106. this._addSecurityOrigin(frame.securityOrigin);
  107. if (frame.isMainFrame())
  108. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.MainFrameCreatedOrNavigated, frame);
  109. },
  110. /**
  111. * @param {string} securityOrigin
  112. */
  113. _addSecurityOrigin: function(securityOrigin)
  114. {
  115. if (!this._securityOriginFrameCount[securityOrigin]) {
  116. this._securityOriginFrameCount[securityOrigin] = 1;
  117. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginAdded, securityOrigin);
  118. return;
  119. }
  120. this._securityOriginFrameCount[securityOrigin] += 1;
  121. },
  122. /**
  123. * @param {string} securityOrigin
  124. */
  125. _removeSecurityOrigin: function(securityOrigin)
  126. {
  127. console.assert(this._securityOriginFrameCount[securityOrigin]);
  128. if (this._securityOriginFrameCount[securityOrigin] === 1) {
  129. delete this._securityOriginFrameCount[securityOrigin];
  130. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.SecurityOriginRemoved, securityOrigin);
  131. return;
  132. }
  133. this._securityOriginFrameCount[securityOrigin] -= 1;
  134. },
  135. /**
  136. * @return {Array.<string>}
  137. */
  138. securityOrigins: function()
  139. {
  140. return Object.keys(this._securityOriginFrameCount);
  141. },
  142. /**
  143. * @param {WebInspector.ResourceTreeFrame} mainFrame
  144. */
  145. _handleMainFrameDetached: function(mainFrame)
  146. {
  147. /**
  148. * @param {WebInspector.ResourceTreeFrame} frame
  149. */
  150. function removeOriginForFrame(frame)
  151. {
  152. for (var i = 0; i < frame.childFrames.length; ++i)
  153. removeOriginForFrame.call(this, frame.childFrames[i]);
  154. if (!frame.isMainFrame())
  155. this._removeSecurityOrigin(frame.securityOrigin);
  156. }
  157. removeOriginForFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
  158. },
  159. /**
  160. * @param {PageAgent.Frame} framePayload
  161. */
  162. _frameNavigated: function(framePayload)
  163. {
  164. // Do nothing unless cached resource tree is processed - it will overwrite everything.
  165. if (!this._cachedResourcesProcessed)
  166. return;
  167. var frame = this._frames[framePayload.id];
  168. var addedOrigin;
  169. if (frame) {
  170. // Navigation within existing frame.
  171. this._removeSecurityOrigin(frame.securityOrigin);
  172. frame._navigate(framePayload);
  173. addedOrigin = frame.securityOrigin;
  174. } else {
  175. // Either a new frame or a main frame navigation to the new backend process.
  176. var parentFrame = framePayload.parentId ? this._frames[framePayload.parentId] : null;
  177. frame = new WebInspector.ResourceTreeFrame(this, parentFrame, framePayload);
  178. if (frame.isMainFrame() && this.mainFrame) {
  179. this._handleMainFrameDetached(this.mainFrame);
  180. // Definitely a navigation to the new backend process.
  181. this._frameDetached(this.mainFrame.id);
  182. }
  183. this._addFrame(frame, true);
  184. addedOrigin = frame.securityOrigin;
  185. }
  186. if (frame.isMainFrame())
  187. WebInspector.inspectedPageURL = frame.url;
  188. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, frame);
  189. if (frame.isMainFrame()) {
  190. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, frame);
  191. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.MainFrameCreatedOrNavigated, frame);
  192. }
  193. if (addedOrigin)
  194. this._addSecurityOrigin(addedOrigin);
  195. // Fill frame with retained resources (the ones loaded using new loader).
  196. var resources = frame.resources();
  197. for (var i = 0; i < resources.length; ++i)
  198. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resources[i]);
  199. if (frame.isMainFrame())
  200. this._dispatchInspectedURLChanged();
  201. },
  202. /**
  203. * @param {PageAgent.FrameId} frameId
  204. */
  205. _frameDetached: function(frameId)
  206. {
  207. // Do nothing unless cached resource tree is processed - it will overwrite everything.
  208. if (!this._cachedResourcesProcessed)
  209. return;
  210. var frame = this._frames[frameId];
  211. if (!frame)
  212. return;
  213. this._removeSecurityOrigin(frame.securityOrigin);
  214. if (frame.parentFrame)
  215. frame.parentFrame._removeChildFrame(frame);
  216. else
  217. frame._remove();
  218. },
  219. /**
  220. * @param {WebInspector.Event} event
  221. */
  222. _onRequestFinished: function(event)
  223. {
  224. if (!this._cachedResourcesProcessed)
  225. return;
  226. var request = /** @type {WebInspector.NetworkRequest} */ (event.data);
  227. if (request.failed || request.type === WebInspector.resourceTypes.XHR)
  228. return;
  229. var frame = this._frames[request.frameId];
  230. if (frame) {
  231. var resource = frame._addRequest(request);
  232. this._addPendingConsoleMessagesToResource(resource);
  233. }
  234. },
  235. /**
  236. * @param {WebInspector.Event} event
  237. */
  238. _onRequestUpdateDropped: function(event)
  239. {
  240. if (!this._cachedResourcesProcessed)
  241. return;
  242. var frameId = event.data.frameId;
  243. var frame = this._frames[frameId];
  244. if (!frame)
  245. return;
  246. var url = event.data.url;
  247. if (frame._resourcesMap[url])
  248. return;
  249. var resource = new WebInspector.Resource(null, url, frame.url, frameId, event.data.loaderId, WebInspector.resourceTypes[event.data.resourceType], event.data.mimeType);
  250. frame.addResource(resource);
  251. },
  252. /**
  253. * @param {PageAgent.FrameId} frameId
  254. * @return {WebInspector.ResourceTreeFrame}
  255. */
  256. frameForId: function(frameId)
  257. {
  258. return this._frames[frameId];
  259. },
  260. /**
  261. * @param {function(WebInspector.Resource)} callback
  262. * @return {boolean}
  263. */
  264. forAllResources: function(callback)
  265. {
  266. if (this.mainFrame)
  267. return this.mainFrame._callForFrameResources(callback);
  268. return false;
  269. },
  270. /**
  271. * @return {Array.<WebInspector.ResourceTreeFrame>}
  272. */
  273. frames: function()
  274. {
  275. return Object.values(this._frames);
  276. },
  277. /**
  278. * @param {WebInspector.Event} event
  279. */
  280. _consoleMessageAdded: function(event)
  281. {
  282. var msg = /** @type {WebInspector.ConsoleMessage} */ (event.data);
  283. var resource = msg.url ? this.resourceForURL(msg.url) : null;
  284. if (resource)
  285. this._addConsoleMessageToResource(msg, resource);
  286. else
  287. this._addPendingConsoleMessage(msg);
  288. },
  289. /**
  290. * @param {WebInspector.ConsoleMessage} msg
  291. */
  292. _addPendingConsoleMessage: function(msg)
  293. {
  294. if (!msg.url)
  295. return;
  296. if (!this._pendingConsoleMessages[msg.url])
  297. this._pendingConsoleMessages[msg.url] = [];
  298. this._pendingConsoleMessages[msg.url].push(msg);
  299. },
  300. /**
  301. * @param {WebInspector.Resource} resource
  302. */
  303. _addPendingConsoleMessagesToResource: function(resource)
  304. {
  305. var messages = this._pendingConsoleMessages[resource.url];
  306. if (messages) {
  307. for (var i = 0; i < messages.length; i++)
  308. this._addConsoleMessageToResource(messages[i], resource);
  309. delete this._pendingConsoleMessages[resource.url];
  310. }
  311. },
  312. /**
  313. * @param {WebInspector.ConsoleMessage} msg
  314. * @param {WebInspector.Resource} resource
  315. */
  316. _addConsoleMessageToResource: function(msg, resource)
  317. {
  318. switch (msg.level) {
  319. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  320. resource.warnings += msg.repeatDelta;
  321. break;
  322. case WebInspector.ConsoleMessage.MessageLevel.Error:
  323. resource.errors += msg.repeatDelta;
  324. break;
  325. }
  326. resource.addMessage(msg);
  327. },
  328. _consoleCleared: function()
  329. {
  330. function callback(resource)
  331. {
  332. resource.clearErrorsAndWarnings();
  333. }
  334. this._pendingConsoleMessages = {};
  335. this.forAllResources(callback);
  336. },
  337. /**
  338. * @param {string} url
  339. * @return {WebInspector.Resource}
  340. */
  341. resourceForURL: function(url)
  342. {
  343. // Workers call into this with no frames available.
  344. return this.mainFrame ? this.mainFrame.resourceForURL(url) : null;
  345. },
  346. /**
  347. * @param {WebInspector.ResourceTreeFrame} parentFrame
  348. * @param {PageAgent.FrameResourceTree} frameTreePayload
  349. */
  350. _addFramesRecursively: function(parentFrame, frameTreePayload)
  351. {
  352. var framePayload = frameTreePayload.frame;
  353. var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, framePayload);
  354. this._addFrame(frame);
  355. var frameResource = this._createResourceFromFramePayload(framePayload, framePayload.url, WebInspector.resourceTypes.Document, framePayload.mimeType);
  356. if (frame.isMainFrame())
  357. WebInspector.inspectedPageURL = frameResource.url;
  358. frame.addResource(frameResource);
  359. for (var i = 0; frameTreePayload.childFrames && i < frameTreePayload.childFrames.length; ++i)
  360. this._addFramesRecursively(frame, frameTreePayload.childFrames[i]);
  361. for (var i = 0; i < frameTreePayload.resources.length; ++i) {
  362. var subresource = frameTreePayload.resources[i];
  363. var resource = this._createResourceFromFramePayload(framePayload, subresource.url, WebInspector.resourceTypes[subresource.type], subresource.mimeType);
  364. frame.addResource(resource);
  365. }
  366. },
  367. /**
  368. * @param {PageAgent.Frame} frame
  369. * @param {string} url
  370. * @param {WebInspector.ResourceType} type
  371. * @param {string} mimeType
  372. * @return {!WebInspector.Resource}
  373. */
  374. _createResourceFromFramePayload: function(frame, url, type, mimeType)
  375. {
  376. return new WebInspector.Resource(null, url, frame.url, frame.id, frame.loaderId, type, mimeType);
  377. },
  378. __proto__: WebInspector.Object.prototype
  379. }
  380. /**
  381. * @constructor
  382. * @param {WebInspector.ResourceTreeModel} model
  383. * @param {?WebInspector.ResourceTreeFrame} parentFrame
  384. * @param {PageAgent.Frame} payload
  385. */
  386. WebInspector.ResourceTreeFrame = function(model, parentFrame, payload)
  387. {
  388. this._model = model;
  389. this._parentFrame = parentFrame;
  390. this._id = payload.id;
  391. this._loaderId = payload.loaderId;
  392. this._name = payload.name;
  393. this._url = payload.url;
  394. this._securityOrigin = payload.securityOrigin;
  395. this._mimeType = payload.mimeType;
  396. /**
  397. * @type {!Array.<!WebInspector.ResourceTreeFrame>}
  398. */
  399. this._childFrames = [];
  400. /**
  401. * @type {!Object.<string, !WebInspector.Resource>}
  402. */
  403. this._resourcesMap = {};
  404. if (this._parentFrame)
  405. this._parentFrame._childFrames.push(this);
  406. }
  407. WebInspector.ResourceTreeFrame.prototype = {
  408. /**
  409. * @return {string}
  410. */
  411. get id()
  412. {
  413. return this._id;
  414. },
  415. /**
  416. * @return {string}
  417. */
  418. get name()
  419. {
  420. return this._name || "";
  421. },
  422. /**
  423. * @return {string}
  424. */
  425. get url()
  426. {
  427. return this._url;
  428. },
  429. /**
  430. * @return {string}
  431. */
  432. get securityOrigin()
  433. {
  434. return this._securityOrigin;
  435. },
  436. /**
  437. * @return {string}
  438. */
  439. get loaderId()
  440. {
  441. return this._loaderId;
  442. },
  443. /**
  444. * @return {WebInspector.ResourceTreeFrame}
  445. */
  446. get parentFrame()
  447. {
  448. return this._parentFrame;
  449. },
  450. /**
  451. * @return {!Array.<!WebInspector.ResourceTreeFrame>}
  452. */
  453. get childFrames()
  454. {
  455. return this._childFrames;
  456. },
  457. /**
  458. * @return {boolean}
  459. */
  460. isMainFrame: function()
  461. {
  462. return !this._parentFrame;
  463. },
  464. /**
  465. * @param {PageAgent.Frame} framePayload
  466. */
  467. _navigate: function(framePayload)
  468. {
  469. this._loaderId = framePayload.loaderId;
  470. this._name = framePayload.name;
  471. this._url = framePayload.url;
  472. this._securityOrigin = framePayload.securityOrigin;
  473. this._mimeType = framePayload.mimeType;
  474. var mainResource = this._resourcesMap[this._url];
  475. this._resourcesMap = {};
  476. this._removeChildFrames();
  477. if (mainResource && mainResource.loaderId === this._loaderId)
  478. this.addResource(mainResource);
  479. },
  480. /**
  481. * @return {WebInspector.Resource}
  482. */
  483. get mainResource()
  484. {
  485. return this._resourcesMap[this._url];
  486. },
  487. /**
  488. * @param {!WebInspector.ResourceTreeFrame} frame
  489. */
  490. _removeChildFrame: function(frame)
  491. {
  492. this._childFrames.remove(frame);
  493. frame._remove();
  494. },
  495. _removeChildFrames: function()
  496. {
  497. var frames = this._childFrames;
  498. this._childFrames = [];
  499. for (var i = 0; i < frames.length; ++i)
  500. frames[i]._remove();
  501. },
  502. _remove: function()
  503. {
  504. this._removeChildFrames();
  505. delete this._model._frames[this.id];
  506. this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this);
  507. },
  508. /**
  509. * @param {!WebInspector.Resource} resource
  510. */
  511. addResource: function(resource)
  512. {
  513. if (this._resourcesMap[resource.url] === resource) {
  514. // Already in the tree, we just got an extra update.
  515. return;
  516. }
  517. this._resourcesMap[resource.url] = resource;
  518. this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
  519. },
  520. /**
  521. * @param {WebInspector.NetworkRequest} request
  522. * @return {WebInspector.Resource}
  523. */
  524. _addRequest: function(request)
  525. {
  526. var resource = this._resourcesMap[request.url];
  527. if (resource && resource.request === request) {
  528. // Already in the tree, we just got an extra update.
  529. return resource;
  530. }
  531. resource = new WebInspector.Resource(request, request.url, request.documentURL, request.frameId, request.loaderId, request.type, request.mimeType);
  532. this._resourcesMap[resource.url] = resource;
  533. this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
  534. return resource;
  535. },
  536. /**
  537. * @return {!Array.<!WebInspector.Resource>}
  538. */
  539. resources: function()
  540. {
  541. var result = [];
  542. for (var url in this._resourcesMap)
  543. result.push(this._resourcesMap[url]);
  544. return result;
  545. },
  546. /**
  547. * @param {string} url
  548. * @return {?WebInspector.Resource}
  549. */
  550. resourceForURL: function(url)
  551. {
  552. var result;
  553. function filter(resource)
  554. {
  555. if (resource.url === url) {
  556. result = resource;
  557. return true;
  558. }
  559. }
  560. this._callForFrameResources(filter);
  561. return result;
  562. },
  563. /**
  564. * @param {function(WebInspector.Resource)} callback
  565. * @return {boolean}
  566. */
  567. _callForFrameResources: function(callback)
  568. {
  569. for (var url in this._resourcesMap) {
  570. if (callback(this._resourcesMap[url]))
  571. return true;
  572. }
  573. for (var i = 0; i < this._childFrames.length; ++i) {
  574. if (this._childFrames[i]._callForFrameResources(callback))
  575. return true;
  576. }
  577. return false;
  578. }
  579. }
  580. /**
  581. * @constructor
  582. * @implements {PageAgent.Dispatcher}
  583. */
  584. WebInspector.PageDispatcher = function(resourceTreeModel)
  585. {
  586. this._resourceTreeModel = resourceTreeModel;
  587. }
  588. WebInspector.PageDispatcher.prototype = {
  589. domContentEventFired: function(time)
  590. {
  591. this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, time);
  592. },
  593. loadEventFired: function(time)
  594. {
  595. this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.Load, time);
  596. },
  597. frameAttached: function(frameId)
  598. {
  599. },
  600. frameNavigated: function(frame)
  601. {
  602. this._resourceTreeModel._frameNavigated(frame);
  603. },
  604. frameDetached: function(frameId)
  605. {
  606. this._resourceTreeModel._frameDetached(frameId);
  607. },
  608. frameStartedLoading: function(frameId)
  609. {
  610. },
  611. frameStoppedLoading: function(frameId)
  612. {
  613. },
  614. frameScheduledNavigation: function(frameId, delay)
  615. {
  616. },
  617. frameClearedScheduledNavigation: function(frameId)
  618. {
  619. },
  620. javascriptDialogOpening: function(message)
  621. {
  622. },
  623. javascriptDialogClosed: function()
  624. {
  625. },
  626. scriptsEnabled: function(isEnabled)
  627. {
  628. WebInspector.settings.javaScriptDisabled.set(!isEnabled);
  629. },
  630. /**
  631. * @param {string} data
  632. * @param {number=} deviceScaleFactor
  633. * @param {number=} pageScaleFactor
  634. * @param {DOMAgent.Rect=} viewport
  635. * @param {number=} offsetTop
  636. * @param {number=} offsetBottom
  637. */
  638. screencastFrame: function(data, deviceScaleFactor, pageScaleFactor, viewport, offsetTop, offsetBottom)
  639. {
  640. this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ScreencastFrame, {data:data, deviceScaleFactor: deviceScaleFactor, pageScaleFactor: pageScaleFactor, viewport:viewport, offsetTop: offsetTop, offsetBottom: offsetBottom});
  641. }
  642. }
  643. /**
  644. * @type {WebInspector.ResourceTreeModel}
  645. */
  646. WebInspector.resourceTreeModel = null;