ResourcesPanel.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363
  1. /*
  2. * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2009 Joseph Pecoraro
  4. * Copyright (C) 2013 Samsung Electronics. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  16. * its contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. importScript("ApplicationCacheItemsView.js");
  31. importScript("DOMStorageItemsView.js");
  32. importScript("DatabaseQueryView.js");
  33. importScript("DatabaseTableView.js");
  34. importScript("DirectoryContentView.js");
  35. importScript("IndexedDBViews.js");
  36. importScript("FileContentView.js");
  37. importScript("FileSystemView.js");
  38. /**
  39. * @constructor
  40. * @extends {WebInspector.Panel}
  41. */
  42. WebInspector.ResourcesPanel = function(database)
  43. {
  44. WebInspector.Panel.call(this, "resources");
  45. this.registerRequiredCSS("resourcesPanel.css");
  46. WebInspector.settings.resourcesLastSelectedItem = WebInspector.settings.createSetting("resourcesLastSelectedItem", {});
  47. this.createSidebarViewWithTree();
  48. this.sidebarElement.addStyleClass("outline-disclosure");
  49. this.sidebarElement.addStyleClass("filter-all");
  50. this.sidebarElement.addStyleClass("children");
  51. this.sidebarElement.addStyleClass("small");
  52. this.sidebarTreeElement.removeStyleClass("sidebar-tree");
  53. this.resourcesListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Frames"), "Frames", ["frame-storage-tree-item"]);
  54. this.sidebarTree.appendChild(this.resourcesListTreeElement);
  55. this.databasesListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Web SQL"), "Databases", ["database-storage-tree-item"]);
  56. this.sidebarTree.appendChild(this.databasesListTreeElement);
  57. this.indexedDBListTreeElement = new WebInspector.IndexedDBTreeElement(this);
  58. this.sidebarTree.appendChild(this.indexedDBListTreeElement);
  59. this.localStorageListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Local Storage"), "LocalStorage", ["domstorage-storage-tree-item", "local-storage"]);
  60. this.sidebarTree.appendChild(this.localStorageListTreeElement);
  61. this.sessionStorageListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Session Storage"), "SessionStorage", ["domstorage-storage-tree-item", "session-storage"]);
  62. this.sidebarTree.appendChild(this.sessionStorageListTreeElement);
  63. this.cookieListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Cookies"), "Cookies", ["cookie-storage-tree-item"]);
  64. this.sidebarTree.appendChild(this.cookieListTreeElement);
  65. this.applicationCacheListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Application Cache"), "ApplicationCache", ["application-cache-storage-tree-item"]);
  66. this.sidebarTree.appendChild(this.applicationCacheListTreeElement);
  67. if (WebInspector.experimentsSettings.fileSystemInspection.isEnabled()) {
  68. this.fileSystemListTreeElement = new WebInspector.FileSystemListTreeElement(this);
  69. this.sidebarTree.appendChild(this.fileSystemListTreeElement);
  70. }
  71. this.storageViews = this.splitView.mainElement;
  72. this.storageViews.addStyleClass("diff-container");
  73. this.storageViewStatusBarItemsContainer = document.createElement("div");
  74. this.storageViewStatusBarItemsContainer.className = "status-bar-items";
  75. /** @type {!Map.<!WebInspector.Database, !Object.<string, !WebInspector.DatabaseTableView>>} */
  76. this._databaseTableViews = new Map();
  77. /** @type {!Map.<!WebInspector.Database, !WebInspector.DatabaseQueryView>} */
  78. this._databaseQueryViews = new Map();
  79. /** @type {!Map.<!WebInspector.Database, !WebInspector.DatabaseTreeElement>} */
  80. this._databaseTreeElements = new Map();
  81. /** @type {!Map.<!WebInspector.DOMStorage, !WebInspector.DOMStorageItemsView>} */
  82. this._domStorageViews = new Map();
  83. /** @type {!Map.<!WebInspector.DOMStorage, !WebInspector.DOMStorageTreeElement>} */
  84. this._domStorageTreeElements = new Map();
  85. /** @type {!Object.<string, !WebInspector.CookieItemsView>} */
  86. this._cookieViews = {};
  87. /** @type {!Object.<string, boolean>} */
  88. this._domains = {};
  89. this.sidebarElement.addEventListener("mousemove", this._onmousemove.bind(this), false);
  90. this.sidebarElement.addEventListener("mouseout", this._onmouseout.bind(this), false);
  91. function viewGetter()
  92. {
  93. return this.visibleView;
  94. }
  95. WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
  96. if (WebInspector.resourceTreeModel.cachedResourcesLoaded())
  97. this._cachedResourcesLoaded();
  98. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.Load, this._loadEventFired, this);
  99. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded, this._cachedResourcesLoaded, this);
  100. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.WillLoadCachedResources, this._resetWithFrames, this);
  101. WebInspector.databaseModel.databases().forEach(this._addDatabase.bind(this));
  102. WebInspector.databaseModel.addEventListener(WebInspector.DatabaseModel.Events.DatabaseAdded, this._databaseAdded, this);
  103. }
  104. WebInspector.ResourcesPanel.prototype = {
  105. get statusBarItems()
  106. {
  107. return [this.storageViewStatusBarItemsContainer];
  108. },
  109. wasShown: function()
  110. {
  111. WebInspector.Panel.prototype.wasShown.call(this);
  112. this._initialize();
  113. },
  114. _initialize: function()
  115. {
  116. if (!this._initialized && this.isShowing() && this._cachedResourcesWereLoaded) {
  117. this._populateResourceTree();
  118. this._populateDOMStorageTree();
  119. this._populateApplicationCacheTree();
  120. this._initDefaultSelection();
  121. this._initialized = true;
  122. }
  123. },
  124. _loadEventFired: function()
  125. {
  126. this._initDefaultSelection();
  127. },
  128. _initDefaultSelection: function()
  129. {
  130. if (!this._initialized)
  131. return;
  132. var itemURL = WebInspector.settings.resourcesLastSelectedItem.get();
  133. if (itemURL) {
  134. for (var treeElement = this.sidebarTree.children[0]; treeElement; treeElement = treeElement.traverseNextTreeElement(false, this.sidebarTree, true)) {
  135. if (treeElement.itemURL === itemURL) {
  136. treeElement.revealAndSelect(true);
  137. return;
  138. }
  139. }
  140. }
  141. var mainResource = WebInspector.inspectedPageURL && this.resourcesListTreeElement && this.resourcesListTreeElement.expanded && WebInspector.resourceTreeModel.resourceForURL(WebInspector.inspectedPageURL);
  142. if (mainResource)
  143. this.showResource(mainResource);
  144. },
  145. _resetWithFrames: function()
  146. {
  147. this.resourcesListTreeElement.removeChildren();
  148. this._treeElementForFrameId = {};
  149. this._reset();
  150. },
  151. _reset: function()
  152. {
  153. this._domains = {};
  154. var queryViews = this._databaseQueryViews.values();
  155. for (var i = 0; i < queryViews.length; ++i)
  156. queryViews[i].removeEventListener(WebInspector.DatabaseQueryView.Events.SchemaUpdated, this._updateDatabaseTables, this);
  157. this._databaseTableViews.clear();
  158. this._databaseQueryViews.clear();
  159. this._databaseTreeElements.clear();
  160. this._domStorageViews.clear();
  161. this._domStorageTreeElements.clear();
  162. this._cookieViews = {};
  163. this.databasesListTreeElement.removeChildren();
  164. this.localStorageListTreeElement.removeChildren();
  165. this.sessionStorageListTreeElement.removeChildren();
  166. this.cookieListTreeElement.removeChildren();
  167. if (this.visibleView && !(this.visibleView instanceof WebInspector.StorageCategoryView))
  168. this.visibleView.detach();
  169. this.storageViewStatusBarItemsContainer.removeChildren();
  170. if (this.sidebarTree.selectedTreeElement)
  171. this.sidebarTree.selectedTreeElement.deselect();
  172. },
  173. _populateResourceTree: function()
  174. {
  175. this._treeElementForFrameId = {};
  176. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
  177. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  178. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
  179. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
  180. function populateFrame(frame)
  181. {
  182. this._frameAdded({data:frame});
  183. for (var i = 0; i < frame.childFrames.length; ++i)
  184. populateFrame.call(this, frame.childFrames[i]);
  185. var resources = frame.resources();
  186. for (var i = 0; i < resources.length; ++i)
  187. this._resourceAdded({data:resources[i]});
  188. }
  189. populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
  190. },
  191. _frameAdded: function(event)
  192. {
  193. var frame = event.data;
  194. var parentFrame = frame.parentFrame;
  195. var parentTreeElement = parentFrame ? this._treeElementForFrameId[parentFrame.id] : this.resourcesListTreeElement;
  196. if (!parentTreeElement) {
  197. console.warn("No frame to route " + frame.url + " to.")
  198. return;
  199. }
  200. var frameTreeElement = new WebInspector.FrameTreeElement(this, frame);
  201. this._treeElementForFrameId[frame.id] = frameTreeElement;
  202. parentTreeElement.appendChild(frameTreeElement);
  203. },
  204. _frameDetached: function(event)
  205. {
  206. var frame = event.data;
  207. var frameTreeElement = this._treeElementForFrameId[frame.id];
  208. if (!frameTreeElement)
  209. return;
  210. delete this._treeElementForFrameId[frame.id];
  211. if (frameTreeElement.parent)
  212. frameTreeElement.parent.removeChild(frameTreeElement);
  213. },
  214. _resourceAdded: function(event)
  215. {
  216. var resource = event.data;
  217. var frameId = resource.frameId;
  218. if (resource.statusCode >= 301 && resource.statusCode <= 303)
  219. return;
  220. var frameTreeElement = this._treeElementForFrameId[frameId];
  221. if (!frameTreeElement) {
  222. // This is a frame's main resource, it will be retained
  223. // and re-added by the resource manager;
  224. return;
  225. }
  226. frameTreeElement.appendResource(resource);
  227. },
  228. _frameNavigated: function(event)
  229. {
  230. var frame = event.data;
  231. if (!frame.parentFrame)
  232. this._reset();
  233. var frameId = frame.id;
  234. var frameTreeElement = this._treeElementForFrameId[frameId];
  235. if (frameTreeElement)
  236. frameTreeElement.frameNavigated(frame);
  237. var applicationCacheFrameTreeElement = this._applicationCacheFrameElements[frameId];
  238. if (applicationCacheFrameTreeElement)
  239. applicationCacheFrameTreeElement.frameNavigated(frame);
  240. },
  241. _cachedResourcesLoaded: function()
  242. {
  243. this._cachedResourcesWereLoaded = true;
  244. this._initialize();
  245. },
  246. /**
  247. * @param {WebInspector.Event} event
  248. */
  249. _databaseAdded: function(event)
  250. {
  251. var database = /** @type {WebInspector.Database} */ (event.data);
  252. this._addDatabase(database);
  253. },
  254. /**
  255. * @param {WebInspector.Database} database
  256. */
  257. _addDatabase: function(database)
  258. {
  259. var databaseTreeElement = new WebInspector.DatabaseTreeElement(this, database);
  260. this._databaseTreeElements.put(database, databaseTreeElement);
  261. this.databasesListTreeElement.appendChild(databaseTreeElement);
  262. },
  263. addDocumentURL: function(url)
  264. {
  265. var parsedURL = url.asParsedURL();
  266. if (!parsedURL)
  267. return;
  268. var domain = parsedURL.host;
  269. if (!this._domains[domain]) {
  270. this._domains[domain] = true;
  271. var cookieDomainTreeElement = new WebInspector.CookieTreeElement(this, domain);
  272. this.cookieListTreeElement.appendChild(cookieDomainTreeElement);
  273. }
  274. },
  275. /**
  276. * @param {WebInspector.Event} event
  277. */
  278. _domStorageAdded: function(event)
  279. {
  280. var domStorage = /** @type {WebInspector.DOMStorage} */ (event.data);
  281. this._addDOMStorage(domStorage);
  282. },
  283. /**
  284. * @param {WebInspector.DOMStorage} domStorage
  285. */
  286. _addDOMStorage: function(domStorage)
  287. {
  288. console.assert(!this._domStorageTreeElements.get(domStorage));
  289. var domStorageTreeElement = new WebInspector.DOMStorageTreeElement(this, domStorage, (domStorage.isLocalStorage ? "local-storage" : "session-storage"));
  290. this._domStorageTreeElements.put(domStorage, domStorageTreeElement);
  291. if (domStorage.isLocalStorage)
  292. this.localStorageListTreeElement.appendChild(domStorageTreeElement);
  293. else
  294. this.sessionStorageListTreeElement.appendChild(domStorageTreeElement);
  295. },
  296. /**
  297. * @param {WebInspector.Event} event
  298. */
  299. _domStorageRemoved: function(event)
  300. {
  301. var domStorage = /** @type {WebInspector.DOMStorage} */ (event.data);
  302. this._removeDOMStorage(domStorage);
  303. },
  304. /**
  305. * @param {WebInspector.DOMStorage} domStorage
  306. */
  307. _removeDOMStorage: function(domStorage)
  308. {
  309. var treeElement = this._domStorageTreeElements.get(domStorage);
  310. if (!treeElement)
  311. return;
  312. var wasSelected = treeElement.selected;
  313. var parentListTreeElement = treeElement.parent;
  314. parentListTreeElement.removeChild(treeElement);
  315. if (wasSelected)
  316. parentListTreeElement.select();
  317. this._domStorageTreeElements.remove(treeElement);
  318. this._domStorageViews.remove(domStorage);
  319. },
  320. /**
  321. * @param {WebInspector.Database} database
  322. */
  323. selectDatabase: function(database)
  324. {
  325. if (database) {
  326. this._showDatabase(database);
  327. this._databaseTreeElements.get(database).select();
  328. }
  329. },
  330. /**
  331. * @param {WebInspector.DOMStorage} domStorage
  332. */
  333. selectDOMStorage: function(domStorage)
  334. {
  335. if (domStorage) {
  336. this._showDOMStorage(domStorage);
  337. this._domStorageTreeElements.get(domStorage).select();
  338. }
  339. },
  340. canShowAnchorLocation: function(anchor)
  341. {
  342. return !!WebInspector.resourceForURL(anchor.href);
  343. },
  344. showAnchorLocation: function(anchor)
  345. {
  346. var resource = WebInspector.resourceForURL(anchor.href);
  347. this.showResource(resource, anchor.lineNumber);
  348. },
  349. /**
  350. * @param {WebInspector.Resource} resource
  351. * @param {number=} line
  352. * @param {number=} column
  353. */
  354. showResource: function(resource, line, column)
  355. {
  356. var resourceTreeElement = this._findTreeElementForResource(resource);
  357. if (resourceTreeElement)
  358. resourceTreeElement.revealAndSelect(true);
  359. if (typeof line === "number") {
  360. var view = this._resourceViewForResource(resource);
  361. if (view.canHighlightPosition())
  362. view.highlightPosition(line, column);
  363. }
  364. return true;
  365. },
  366. _showResourceView: function(resource)
  367. {
  368. var view = this._resourceViewForResource(resource);
  369. if (!view) {
  370. this.visibleView.detach();
  371. return;
  372. }
  373. if (view.searchCanceled)
  374. view.searchCanceled();
  375. this._innerShowView(view);
  376. },
  377. _resourceViewForResource: function(resource)
  378. {
  379. if (WebInspector.ResourceView.hasTextContent(resource)) {
  380. var treeElement = this._findTreeElementForResource(resource);
  381. if (!treeElement)
  382. return null;
  383. return treeElement.sourceView();
  384. }
  385. return WebInspector.ResourceView.nonSourceViewForResource(resource);
  386. },
  387. /**
  388. * @param {WebInspector.Database} database
  389. * @param {string=} tableName
  390. */
  391. _showDatabase: function(database, tableName)
  392. {
  393. if (!database)
  394. return;
  395. var view;
  396. if (tableName) {
  397. var tableViews = this._databaseTableViews.get(database);
  398. if (!tableViews) {
  399. tableViews = /** @type {!Object.<string, !WebInspector.DatabaseTableView>} */ ({});
  400. this._databaseTableViews.put(database, tableViews);
  401. }
  402. view = tableViews[tableName];
  403. if (!view) {
  404. view = new WebInspector.DatabaseTableView(database, tableName);
  405. tableViews[tableName] = view;
  406. }
  407. } else {
  408. view = this._databaseQueryViews.get(database);
  409. if (!view) {
  410. view = new WebInspector.DatabaseQueryView(database);
  411. this._databaseQueryViews.put(database, view);
  412. view.addEventListener(WebInspector.DatabaseQueryView.Events.SchemaUpdated, this._updateDatabaseTables, this);
  413. }
  414. }
  415. this._innerShowView(view);
  416. },
  417. /**
  418. * @param {WebInspector.View} view
  419. */
  420. showIndexedDB: function(view)
  421. {
  422. this._innerShowView(view);
  423. },
  424. /**
  425. * @param {WebInspector.DOMStorage} domStorage
  426. */
  427. _showDOMStorage: function(domStorage)
  428. {
  429. if (!domStorage)
  430. return;
  431. var view;
  432. view = this._domStorageViews.get(domStorage);
  433. if (!view) {
  434. view = new WebInspector.DOMStorageItemsView(domStorage);
  435. this._domStorageViews.put(domStorage, view);
  436. }
  437. this._innerShowView(view);
  438. },
  439. /**
  440. * @param {!WebInspector.CookieTreeElement} treeElement
  441. * @param {string} cookieDomain
  442. */
  443. showCookies: function(treeElement, cookieDomain)
  444. {
  445. var view = this._cookieViews[cookieDomain];
  446. if (!view) {
  447. view = new WebInspector.CookieItemsView(treeElement, cookieDomain);
  448. this._cookieViews[cookieDomain] = view;
  449. }
  450. this._innerShowView(view);
  451. },
  452. /**
  453. * @param {string} cookieDomain
  454. */
  455. clearCookies: function(cookieDomain)
  456. {
  457. this._cookieViews[cookieDomain].clear();
  458. },
  459. showApplicationCache: function(frameId)
  460. {
  461. if (!this._applicationCacheViews[frameId])
  462. this._applicationCacheViews[frameId] = new WebInspector.ApplicationCacheItemsView(this._applicationCacheModel, frameId);
  463. this._innerShowView(this._applicationCacheViews[frameId]);
  464. },
  465. /**
  466. * @param {WebInspector.View} view
  467. */
  468. showFileSystem: function(view)
  469. {
  470. this._innerShowView(view);
  471. },
  472. showCategoryView: function(categoryName)
  473. {
  474. if (!this._categoryView)
  475. this._categoryView = new WebInspector.StorageCategoryView();
  476. this._categoryView.setText(categoryName);
  477. this._innerShowView(this._categoryView);
  478. },
  479. _innerShowView: function(view)
  480. {
  481. if (this.visibleView === view)
  482. return;
  483. if (this.visibleView)
  484. this.visibleView.detach();
  485. view.show(this.storageViews);
  486. this.visibleView = view;
  487. this.storageViewStatusBarItemsContainer.removeChildren();
  488. var statusBarItems = view.statusBarItems || [];
  489. for (var i = 0; i < statusBarItems.length; ++i)
  490. this.storageViewStatusBarItemsContainer.appendChild(statusBarItems[i]);
  491. },
  492. closeVisibleView: function()
  493. {
  494. if (!this.visibleView)
  495. return;
  496. this.visibleView.detach();
  497. delete this.visibleView;
  498. },
  499. _updateDatabaseTables: function(event)
  500. {
  501. var database = event.data;
  502. if (!database)
  503. return;
  504. var databasesTreeElement = this._databaseTreeElements.get(database);
  505. if (!databasesTreeElement)
  506. return;
  507. databasesTreeElement.shouldRefreshChildren = true;
  508. var tableViews = this._databaseTableViews.get(database);
  509. if (!tableViews)
  510. return;
  511. var tableNamesHash = {};
  512. var self = this;
  513. function tableNamesCallback(tableNames)
  514. {
  515. var tableNamesLength = tableNames.length;
  516. for (var i = 0; i < tableNamesLength; ++i)
  517. tableNamesHash[tableNames[i]] = true;
  518. for (var tableName in tableViews) {
  519. if (!(tableName in tableNamesHash)) {
  520. if (self.visibleView === tableViews[tableName])
  521. self.closeVisibleView();
  522. delete tableViews[tableName];
  523. }
  524. }
  525. }
  526. database.getTableNames(tableNamesCallback);
  527. },
  528. _populateDOMStorageTree: function()
  529. {
  530. WebInspector.domStorageModel.storages().forEach(this._addDOMStorage.bind(this));
  531. WebInspector.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOMStorageAdded, this._domStorageAdded, this);
  532. WebInspector.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOMStorageRemoved, this._domStorageRemoved, this);
  533. },
  534. _populateApplicationCacheTree: function()
  535. {
  536. this._applicationCacheModel = new WebInspector.ApplicationCacheModel();
  537. this._applicationCacheViews = {};
  538. this._applicationCacheFrameElements = {};
  539. this._applicationCacheManifestElements = {};
  540. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestAdded, this._applicationCacheFrameManifestAdded, this);
  541. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestRemoved, this._applicationCacheFrameManifestRemoved, this);
  542. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestStatusUpdated, this._applicationCacheFrameManifestStatusChanged, this);
  543. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.NetworkStateChanged, this._applicationCacheNetworkStateChanged, this);
  544. },
  545. _applicationCacheFrameManifestAdded: function(event)
  546. {
  547. var frameId = event.data;
  548. var manifestURL = this._applicationCacheModel.frameManifestURL(frameId);
  549. var status = this._applicationCacheModel.frameManifestStatus(frameId)
  550. var manifestTreeElement = this._applicationCacheManifestElements[manifestURL]
  551. if (!manifestTreeElement) {
  552. manifestTreeElement = new WebInspector.ApplicationCacheManifestTreeElement(this, manifestURL);
  553. this.applicationCacheListTreeElement.appendChild(manifestTreeElement);
  554. this._applicationCacheManifestElements[manifestURL] = manifestTreeElement;
  555. }
  556. var frameTreeElement = new WebInspector.ApplicationCacheFrameTreeElement(this, frameId, manifestURL);
  557. manifestTreeElement.appendChild(frameTreeElement);
  558. manifestTreeElement.expand();
  559. this._applicationCacheFrameElements[frameId] = frameTreeElement;
  560. },
  561. _applicationCacheFrameManifestRemoved: function(event)
  562. {
  563. var frameId = event.data;
  564. var frameTreeElement = this._applicationCacheFrameElements[frameId];
  565. if (!frameTreeElement)
  566. return;
  567. var manifestURL = frameTreeElement.manifestURL;
  568. delete this._applicationCacheFrameElements[frameId];
  569. delete this._applicationCacheViews[frameId];
  570. frameTreeElement.parent.removeChild(frameTreeElement);
  571. var manifestTreeElement = this._applicationCacheManifestElements[manifestURL];
  572. if (manifestTreeElement.children.length !== 0)
  573. return;
  574. delete this._applicationCacheManifestElements[manifestURL];
  575. manifestTreeElement.parent.removeChild(manifestTreeElement);
  576. },
  577. _applicationCacheFrameManifestStatusChanged: function(event)
  578. {
  579. var frameId = event.data;
  580. var status = this._applicationCacheModel.frameManifestStatus(frameId)
  581. if (this._applicationCacheViews[frameId])
  582. this._applicationCacheViews[frameId].updateStatus(status);
  583. },
  584. _applicationCacheNetworkStateChanged: function(event)
  585. {
  586. var isNowOnline = event.data;
  587. for (var manifestURL in this._applicationCacheViews)
  588. this._applicationCacheViews[manifestURL].updateNetworkState(isNowOnline);
  589. },
  590. sidebarResized: function(event)
  591. {
  592. var width = event.data;
  593. this.storageViewStatusBarItemsContainer.style.left = width + "px";
  594. },
  595. /**
  596. * @param {string} query
  597. * @param {boolean} shouldJump
  598. */
  599. performSearch: function(query, shouldJump)
  600. {
  601. this._resetSearchResults();
  602. var regex = WebInspector.SourceFrame.createSearchRegex(query);
  603. var totalMatchesCount = 0;
  604. /**
  605. * @param {WebInspector.Resource} resource
  606. * @param {number} matchesCount
  607. */
  608. function addMatchesToResource(resource, matchesCount)
  609. {
  610. this._findTreeElementForResource(resource).searchMatchesFound(matchesCount);
  611. totalMatchesCount += matchesCount;
  612. }
  613. /**
  614. * @param {?Protocol.Error} error
  615. * @param {Array.<PageAgent.SearchResult>} result
  616. */
  617. function searchInResourcesCallback(error, result)
  618. {
  619. if (error)
  620. return;
  621. for (var i = 0; i < result.length; i++) {
  622. var searchResult = result[i];
  623. var frameTreeElement = this._treeElementForFrameId[searchResult.frameId];
  624. if (!frameTreeElement)
  625. continue;
  626. var resource = frameTreeElement.resourceByURL(searchResult.url);
  627. // FIXME: When the same script is used in several frames and this script contains at least
  628. // one search result then some search results can not be matched with a resource on panel.
  629. // https://bugs.webkit.org/show_bug.cgi?id=66005
  630. if (!resource)
  631. continue;
  632. addMatchesToResource.call(this, resource, searchResult.matchesCount)
  633. }
  634. if (!--callbacksLeft)
  635. searchFinished.call(this);
  636. }
  637. /**
  638. * @param {WebInspector.Resource} resource
  639. * @param {Array.<WebInspector.ContentProvider.SearchMatch>} result
  640. */
  641. function searchInContentCallback(resource, result)
  642. {
  643. addMatchesToResource.call(this, resource, result.length);
  644. if (!--callbacksLeft)
  645. searchFinished.call(this);
  646. }
  647. function searchFinished()
  648. {
  649. WebInspector.searchController.updateSearchMatchesCount(totalMatchesCount, this);
  650. this._searchController = new WebInspector.ResourcesSearchController(this.resourcesListTreeElement, totalMatchesCount);
  651. if (shouldJump && this.sidebarTree.selectedTreeElement && this.sidebarTree.selectedTreeElement.searchMatchesCount)
  652. this.jumpToNextSearchResult();
  653. }
  654. var frames = WebInspector.resourceTreeModel.frames();
  655. var callbacksLeft = 1 + frames.length;
  656. for (var i = 0; i < frames.length; ++i) {
  657. var mainResource = frames[i].mainResource;
  658. mainResource.searchInContent(regex.source, !regex.ignoreCase, true, searchInContentCallback.bind(this, mainResource));
  659. }
  660. PageAgent.searchInResources(regex.source, !regex.ignoreCase, true, searchInResourcesCallback.bind(this));
  661. },
  662. _ensureViewSearchPerformed: function(callback)
  663. {
  664. function viewSearchPerformedCallback(searchId)
  665. {
  666. if (searchId !== this._lastViewSearchId)
  667. return; // Search is obsolete.
  668. this._viewSearchInProgress = false;
  669. callback();
  670. }
  671. if (!this._viewSearchInProgress) {
  672. if (!this.visibleView.hasSearchResults()) {
  673. // We give id to each search, so that we can skip callbacks for obsolete searches.
  674. this._lastViewSearchId = this._lastViewSearchId ? this._lastViewSearchId + 1 : 0;
  675. this._viewSearchInProgress = true;
  676. this.visibleView.performSearch(this.currentQuery, false, viewSearchPerformedCallback.bind(this, this._lastViewSearchId));
  677. } else
  678. callback();
  679. }
  680. },
  681. _showSearchResult: function(searchResult)
  682. {
  683. this._lastSearchResultIndex = searchResult.index;
  684. this._lastSearchResultTreeElement = searchResult.treeElement;
  685. // At first show view for treeElement.
  686. if (searchResult.treeElement !== this.sidebarTree.selectedTreeElement)
  687. this.showResource(searchResult.treeElement.representedObject);
  688. function callback(searchId)
  689. {
  690. if (this.sidebarTree.selectedTreeElement !== this._lastSearchResultTreeElement)
  691. return; // User has selected another view while we were searching.
  692. if (this._lastSearchResultIndex != -1)
  693. this.visibleView.jumpToSearchResult(this._lastSearchResultIndex);
  694. WebInspector.searchController.updateCurrentMatchIndex(searchResult.currentMatchIndex - 1, this);
  695. }
  696. // Then run SourceFrame search if needed and jump to search result index when done.
  697. this._ensureViewSearchPerformed(callback.bind(this));
  698. },
  699. _resetSearchResults: function()
  700. {
  701. function callback(resourceTreeElement)
  702. {
  703. resourceTreeElement._resetSearchResults();
  704. }
  705. this._forAllResourceTreeElements(callback);
  706. if (this.visibleView && this.visibleView.searchCanceled)
  707. this.visibleView.searchCanceled();
  708. this._lastSearchResultTreeElement = null;
  709. this._lastSearchResultIndex = -1;
  710. this._viewSearchInProgress = false;
  711. },
  712. searchCanceled: function()
  713. {
  714. function callback(resourceTreeElement)
  715. {
  716. resourceTreeElement._updateErrorsAndWarningsBubbles();
  717. }
  718. WebInspector.searchController.updateSearchMatchesCount(0, this);
  719. this._resetSearchResults();
  720. this._forAllResourceTreeElements(callback);
  721. },
  722. jumpToNextSearchResult: function()
  723. {
  724. if (!this.currentSearchMatches)
  725. return;
  726. var currentTreeElement = this.sidebarTree.selectedTreeElement;
  727. var nextSearchResult = this._searchController.nextSearchResult(currentTreeElement);
  728. this._showSearchResult(nextSearchResult);
  729. },
  730. jumpToPreviousSearchResult: function()
  731. {
  732. if (!this.currentSearchMatches)
  733. return;
  734. var currentTreeElement = this.sidebarTree.selectedTreeElement;
  735. var previousSearchResult = this._searchController.previousSearchResult(currentTreeElement);
  736. this._showSearchResult(previousSearchResult);
  737. },
  738. _forAllResourceTreeElements: function(callback)
  739. {
  740. var stop = false;
  741. for (var treeElement = this.resourcesListTreeElement; !stop && treeElement; treeElement = treeElement.traverseNextTreeElement(false, this.resourcesListTreeElement, true)) {
  742. if (treeElement instanceof WebInspector.FrameResourceTreeElement)
  743. stop = callback(treeElement);
  744. }
  745. },
  746. _findTreeElementForResource: function(resource)
  747. {
  748. function isAncestor(ancestor, object)
  749. {
  750. // Redirects, XHRs do not belong to the tree, it is fine to silently return false here.
  751. return false;
  752. }
  753. function getParent(object)
  754. {
  755. // Redirects, XHRs do not belong to the tree, it is fine to silently return false here.
  756. return null;
  757. }
  758. return this.sidebarTree.findTreeElement(resource, isAncestor, getParent);
  759. },
  760. showView: function(view)
  761. {
  762. if (view)
  763. this.showResource(view.resource);
  764. },
  765. _onmousemove: function(event)
  766. {
  767. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  768. if (!nodeUnderMouse)
  769. return;
  770. var listNode = nodeUnderMouse.enclosingNodeOrSelfWithNodeName("li");
  771. if (!listNode)
  772. return;
  773. var element = listNode.treeElement;
  774. if (this._previousHoveredElement === element)
  775. return;
  776. if (this._previousHoveredElement) {
  777. this._previousHoveredElement.hovered = false;
  778. delete this._previousHoveredElement;
  779. }
  780. if (element instanceof WebInspector.FrameTreeElement) {
  781. this._previousHoveredElement = element;
  782. element.hovered = true;
  783. }
  784. },
  785. _onmouseout: function(event)
  786. {
  787. if (this._previousHoveredElement) {
  788. this._previousHoveredElement.hovered = false;
  789. delete this._previousHoveredElement;
  790. }
  791. },
  792. __proto__: WebInspector.Panel.prototype
  793. }
  794. /**
  795. * @constructor
  796. * @extends {TreeElement}
  797. * @param {boolean=} hasChildren
  798. * @param {boolean=} noIcon
  799. */
  800. WebInspector.BaseStorageTreeElement = function(storagePanel, representedObject, title, iconClasses, hasChildren, noIcon)
  801. {
  802. TreeElement.call(this, "", representedObject, hasChildren);
  803. this._storagePanel = storagePanel;
  804. this._titleText = title;
  805. this._iconClasses = iconClasses;
  806. this._noIcon = noIcon;
  807. }
  808. WebInspector.BaseStorageTreeElement.prototype = {
  809. onattach: function()
  810. {
  811. this.listItemElement.removeChildren();
  812. if (this._iconClasses) {
  813. for (var i = 0; i < this._iconClasses.length; ++i)
  814. this.listItemElement.addStyleClass(this._iconClasses[i]);
  815. }
  816. var selectionElement = document.createElement("div");
  817. selectionElement.className = "selection";
  818. this.listItemElement.appendChild(selectionElement);
  819. if (!this._noIcon) {
  820. this.imageElement = document.createElement("img");
  821. this.imageElement.className = "icon";
  822. this.listItemElement.appendChild(this.imageElement);
  823. }
  824. this.titleElement = document.createElement("div");
  825. this.titleElement.className = "base-storage-tree-element-title";
  826. this._titleTextNode = document.createTextNode("");
  827. this.titleElement.appendChild(this._titleTextNode);
  828. this._updateTitle();
  829. this._updateSubtitle();
  830. this.listItemElement.appendChild(this.titleElement);
  831. },
  832. get displayName()
  833. {
  834. return this._displayName;
  835. },
  836. _updateDisplayName: function()
  837. {
  838. this._displayName = this._titleText || "";
  839. if (this._subtitleText)
  840. this._displayName += " (" + this._subtitleText + ")";
  841. },
  842. _updateTitle: function()
  843. {
  844. this._updateDisplayName();
  845. if (!this.titleElement)
  846. return;
  847. this._titleTextNode.textContent = this._titleText || "";
  848. },
  849. _updateSubtitle: function()
  850. {
  851. this._updateDisplayName();
  852. if (!this.titleElement)
  853. return;
  854. if (this._subtitleText) {
  855. if (!this._subtitleElement) {
  856. this._subtitleElement = document.createElement("span");
  857. this._subtitleElement.className = "base-storage-tree-element-subtitle";
  858. this.titleElement.appendChild(this._subtitleElement);
  859. }
  860. this._subtitleElement.textContent = "(" + this._subtitleText + ")";
  861. } else if (this._subtitleElement) {
  862. this.titleElement.removeChild(this._subtitleElement);
  863. delete this._subtitleElement;
  864. }
  865. },
  866. onselect: function(selectedByUser)
  867. {
  868. if (!selectedByUser)
  869. return;
  870. var itemURL = this.itemURL;
  871. if (itemURL)
  872. WebInspector.settings.resourcesLastSelectedItem.set(itemURL);
  873. },
  874. onreveal: function()
  875. {
  876. if (this.listItemElement)
  877. this.listItemElement.scrollIntoViewIfNeeded(false);
  878. },
  879. get titleText()
  880. {
  881. return this._titleText;
  882. },
  883. set titleText(titleText)
  884. {
  885. this._titleText = titleText;
  886. this._updateTitle();
  887. },
  888. get subtitleText()
  889. {
  890. return this._subtitleText;
  891. },
  892. set subtitleText(subtitleText)
  893. {
  894. this._subtitleText = subtitleText;
  895. this._updateSubtitle();
  896. },
  897. get searchMatchesCount()
  898. {
  899. return 0;
  900. },
  901. __proto__: TreeElement.prototype
  902. }
  903. /**
  904. * @constructor
  905. * @extends {WebInspector.BaseStorageTreeElement}
  906. * @param {boolean=} noIcon
  907. */
  908. WebInspector.StorageCategoryTreeElement = function(storagePanel, categoryName, settingsKey, iconClasses, noIcon)
  909. {
  910. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, categoryName, iconClasses, true, noIcon);
  911. this._expandedSettingKey = "resources" + settingsKey + "Expanded";
  912. WebInspector.settings[this._expandedSettingKey] = WebInspector.settings.createSetting(this._expandedSettingKey, settingsKey === "Frames");
  913. this._categoryName = categoryName;
  914. }
  915. WebInspector.StorageCategoryTreeElement.prototype = {
  916. get itemURL()
  917. {
  918. return "category://" + this._categoryName;
  919. },
  920. onselect: function(selectedByUser)
  921. {
  922. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  923. this._storagePanel.showCategoryView(this._categoryName);
  924. },
  925. onattach: function()
  926. {
  927. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  928. if (WebInspector.settings[this._expandedSettingKey].get())
  929. this.expand();
  930. },
  931. onexpand: function()
  932. {
  933. WebInspector.settings[this._expandedSettingKey].set(true);
  934. },
  935. oncollapse: function()
  936. {
  937. WebInspector.settings[this._expandedSettingKey].set(false);
  938. },
  939. __proto__: WebInspector.BaseStorageTreeElement.prototype
  940. }
  941. /**
  942. * @constructor
  943. * @extends {WebInspector.BaseStorageTreeElement}
  944. */
  945. WebInspector.FrameTreeElement = function(storagePanel, frame)
  946. {
  947. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, "", ["frame-storage-tree-item"]);
  948. this._frame = frame;
  949. this.frameNavigated(frame);
  950. }
  951. WebInspector.FrameTreeElement.prototype = {
  952. frameNavigated: function(frame)
  953. {
  954. this.removeChildren();
  955. this._frameId = frame.id;
  956. this.titleText = frame.name;
  957. this.subtitleText = new WebInspector.ParsedURL(frame.url).displayName;
  958. this._categoryElements = {};
  959. this._treeElementForResource = {};
  960. this._storagePanel.addDocumentURL(frame.url);
  961. },
  962. get itemURL()
  963. {
  964. return "frame://" + encodeURI(this.displayName);
  965. },
  966. onselect: function(selectedByUser)
  967. {
  968. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  969. this._storagePanel.showCategoryView(this.displayName);
  970. this.listItemElement.removeStyleClass("hovered");
  971. DOMAgent.hideHighlight();
  972. },
  973. set hovered(hovered)
  974. {
  975. if (hovered) {
  976. this.listItemElement.addStyleClass("hovered");
  977. DOMAgent.highlightFrame(this._frameId, WebInspector.Color.PageHighlight.Content.toProtocolRGBA(), WebInspector.Color.PageHighlight.ContentOutline.toProtocolRGBA());
  978. } else {
  979. this.listItemElement.removeStyleClass("hovered");
  980. DOMAgent.hideHighlight();
  981. }
  982. },
  983. appendResource: function(resource)
  984. {
  985. if (resource.isHidden())
  986. return;
  987. var categoryName = resource.type.name();
  988. var categoryElement = resource.type === WebInspector.resourceTypes.Document ? this : this._categoryElements[categoryName];
  989. if (!categoryElement) {
  990. categoryElement = new WebInspector.StorageCategoryTreeElement(this._storagePanel, resource.type.categoryTitle(), categoryName, null, true);
  991. this._categoryElements[resource.type.name()] = categoryElement;
  992. this._insertInPresentationOrder(this, categoryElement);
  993. }
  994. var resourceTreeElement = new WebInspector.FrameResourceTreeElement(this._storagePanel, resource);
  995. this._insertInPresentationOrder(categoryElement, resourceTreeElement);
  996. this._treeElementForResource[resource.url] = resourceTreeElement;
  997. },
  998. resourceByURL: function(url)
  999. {
  1000. var treeElement = this._treeElementForResource[url];
  1001. return treeElement ? treeElement.representedObject : null;
  1002. },
  1003. appendChild: function(treeElement)
  1004. {
  1005. this._insertInPresentationOrder(this, treeElement);
  1006. },
  1007. _insertInPresentationOrder: function(parentTreeElement, childTreeElement)
  1008. {
  1009. // Insert in the alphabetical order, first frames, then resources. Document resource goes last.
  1010. function typeWeight(treeElement)
  1011. {
  1012. if (treeElement instanceof WebInspector.StorageCategoryTreeElement)
  1013. return 2;
  1014. if (treeElement instanceof WebInspector.FrameTreeElement)
  1015. return 1;
  1016. return 3;
  1017. }
  1018. function compare(treeElement1, treeElement2)
  1019. {
  1020. var typeWeight1 = typeWeight(treeElement1);
  1021. var typeWeight2 = typeWeight(treeElement2);
  1022. var result;
  1023. if (typeWeight1 > typeWeight2)
  1024. result = 1;
  1025. else if (typeWeight1 < typeWeight2)
  1026. result = -1;
  1027. else {
  1028. var title1 = treeElement1.displayName || treeElement1.titleText;
  1029. var title2 = treeElement2.displayName || treeElement2.titleText;
  1030. result = title1.localeCompare(title2);
  1031. }
  1032. return result;
  1033. }
  1034. var children = parentTreeElement.children;
  1035. var i;
  1036. for (i = 0; i < children.length; ++i) {
  1037. if (compare(childTreeElement, children[i]) < 0)
  1038. break;
  1039. }
  1040. parentTreeElement.insertChild(childTreeElement, i);
  1041. },
  1042. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1043. }
  1044. /**
  1045. * @constructor
  1046. * @extends {WebInspector.BaseStorageTreeElement}
  1047. */
  1048. WebInspector.FrameResourceTreeElement = function(storagePanel, resource)
  1049. {
  1050. WebInspector.BaseStorageTreeElement.call(this, storagePanel, resource, resource.displayName, ["resource-sidebar-tree-item", "resources-type-" + resource.type.name()]);
  1051. this._resource = resource;
  1052. this._resource.addEventListener(WebInspector.Resource.Events.MessageAdded, this._consoleMessageAdded, this);
  1053. this._resource.addEventListener(WebInspector.Resource.Events.MessagesCleared, this._consoleMessagesCleared, this);
  1054. this.tooltip = resource.url;
  1055. }
  1056. WebInspector.FrameResourceTreeElement.prototype = {
  1057. get itemURL()
  1058. {
  1059. return this._resource.url;
  1060. },
  1061. onselect: function(selectedByUser)
  1062. {
  1063. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1064. this._storagePanel._showResourceView(this._resource);
  1065. },
  1066. ondblclick: function(event)
  1067. {
  1068. InspectorFrontendHost.openInNewTab(this._resource.url);
  1069. },
  1070. onattach: function()
  1071. {
  1072. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  1073. if (this._resource.type === WebInspector.resourceTypes.Image) {
  1074. var previewImage = document.createElement("img");
  1075. previewImage.className = "image-resource-icon-preview";
  1076. this._resource.populateImageSource(previewImage);
  1077. var iconElement = document.createElement("div");
  1078. iconElement.className = "icon";
  1079. iconElement.appendChild(previewImage);
  1080. this.listItemElement.replaceChild(iconElement, this.imageElement);
  1081. }
  1082. this._statusElement = document.createElement("div");
  1083. this._statusElement.className = "status";
  1084. this.listItemElement.insertBefore(this._statusElement, this.titleElement);
  1085. this.listItemElement.draggable = true;
  1086. this.listItemElement.addEventListener("dragstart", this._ondragstart.bind(this), false);
  1087. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  1088. this._updateErrorsAndWarningsBubbles();
  1089. },
  1090. _ondragstart: function(event)
  1091. {
  1092. event.dataTransfer.setData("text/plain", this._resource.content);
  1093. event.dataTransfer.effectAllowed = "copy";
  1094. return true;
  1095. },
  1096. _handleContextMenuEvent: function(event)
  1097. {
  1098. var contextMenu = new WebInspector.ContextMenu(event);
  1099. contextMenu.appendApplicableItems(this._resource);
  1100. contextMenu.show();
  1101. },
  1102. _setBubbleText: function(x)
  1103. {
  1104. if (!this._bubbleElement) {
  1105. this._bubbleElement = document.createElement("div");
  1106. this._bubbleElement.className = "bubble";
  1107. this._statusElement.appendChild(this._bubbleElement);
  1108. }
  1109. this._bubbleElement.textContent = x;
  1110. },
  1111. _resetBubble: function()
  1112. {
  1113. if (this._bubbleElement) {
  1114. this._bubbleElement.textContent = "";
  1115. this._bubbleElement.removeStyleClass("search-matches");
  1116. this._bubbleElement.removeStyleClass("warning");
  1117. this._bubbleElement.removeStyleClass("error");
  1118. }
  1119. },
  1120. _resetSearchResults: function()
  1121. {
  1122. this._resetBubble();
  1123. this._searchMatchesCount = 0;
  1124. },
  1125. get searchMatchesCount()
  1126. {
  1127. return this._searchMatchesCount;
  1128. },
  1129. searchMatchesFound: function(matchesCount)
  1130. {
  1131. this._resetSearchResults();
  1132. this._searchMatchesCount = matchesCount;
  1133. this._setBubbleText(matchesCount);
  1134. this._bubbleElement.addStyleClass("search-matches");
  1135. // Expand, do not scroll into view.
  1136. var currentAncestor = this.parent;
  1137. while (currentAncestor && !currentAncestor.root) {
  1138. if (!currentAncestor.expanded)
  1139. currentAncestor.expand();
  1140. currentAncestor = currentAncestor.parent;
  1141. }
  1142. },
  1143. _updateErrorsAndWarningsBubbles: function()
  1144. {
  1145. if (this._storagePanel.currentQuery)
  1146. return;
  1147. this._resetBubble();
  1148. if (this._resource.warnings || this._resource.errors)
  1149. this._setBubbleText(this._resource.warnings + this._resource.errors);
  1150. if (this._resource.warnings)
  1151. this._bubbleElement.addStyleClass("warning");
  1152. if (this._resource.errors)
  1153. this._bubbleElement.addStyleClass("error");
  1154. },
  1155. _consoleMessagesCleared: function()
  1156. {
  1157. // FIXME: move to the SourceFrame.
  1158. if (this._sourceView)
  1159. this._sourceView.clearMessages();
  1160. this._updateErrorsAndWarningsBubbles();
  1161. },
  1162. _consoleMessageAdded: function(event)
  1163. {
  1164. var msg = event.data;
  1165. if (this._sourceView)
  1166. this._sourceView.addMessage(msg);
  1167. this._updateErrorsAndWarningsBubbles();
  1168. },
  1169. sourceView: function()
  1170. {
  1171. if (!this._sourceView) {
  1172. this._sourceView = new WebInspector.ResourceSourceFrame(this._resource);
  1173. if (this._resource.messages) {
  1174. for (var i = 0; i < this._resource.messages.length; i++)
  1175. this._sourceView.addMessage(this._resource.messages[i]);
  1176. }
  1177. }
  1178. return this._sourceView;
  1179. },
  1180. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1181. }
  1182. /**
  1183. * @constructor
  1184. * @extends {WebInspector.BaseStorageTreeElement}
  1185. * @param {WebInspector.Database} database
  1186. */
  1187. WebInspector.DatabaseTreeElement = function(storagePanel, database)
  1188. {
  1189. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, database.name, ["database-storage-tree-item"], true);
  1190. this._database = database;
  1191. }
  1192. WebInspector.DatabaseTreeElement.prototype = {
  1193. get itemURL()
  1194. {
  1195. return "database://" + encodeURI(this._database.name);
  1196. },
  1197. onselect: function(selectedByUser)
  1198. {
  1199. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1200. this._storagePanel._showDatabase(this._database);
  1201. },
  1202. onexpand: function()
  1203. {
  1204. this._updateChildren();
  1205. },
  1206. _updateChildren: function()
  1207. {
  1208. this.removeChildren();
  1209. function tableNamesCallback(tableNames)
  1210. {
  1211. var tableNamesLength = tableNames.length;
  1212. for (var i = 0; i < tableNamesLength; ++i)
  1213. this.appendChild(new WebInspector.DatabaseTableTreeElement(this._storagePanel, this._database, tableNames[i]));
  1214. }
  1215. this._database.getTableNames(tableNamesCallback.bind(this));
  1216. },
  1217. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1218. }
  1219. /**
  1220. * @constructor
  1221. * @extends {WebInspector.BaseStorageTreeElement}
  1222. */
  1223. WebInspector.DatabaseTableTreeElement = function(storagePanel, database, tableName)
  1224. {
  1225. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, tableName, ["database-storage-tree-item"]);
  1226. this._database = database;
  1227. this._tableName = tableName;
  1228. }
  1229. WebInspector.DatabaseTableTreeElement.prototype = {
  1230. get itemURL()
  1231. {
  1232. return "database://" + encodeURI(this._database.name) + "/" + encodeURI(this._tableName);
  1233. },
  1234. onselect: function(selectedByUser)
  1235. {
  1236. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1237. this._storagePanel._showDatabase(this._database, this._tableName);
  1238. },
  1239. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1240. }
  1241. /**
  1242. * @constructor
  1243. * @extends {WebInspector.StorageCategoryTreeElement}
  1244. * @param {WebInspector.ResourcesPanel} storagePanel
  1245. */
  1246. WebInspector.IndexedDBTreeElement = function(storagePanel)
  1247. {
  1248. WebInspector.StorageCategoryTreeElement.call(this, storagePanel, WebInspector.UIString("IndexedDB"), "IndexedDB", ["indexed-db-storage-tree-item"]);
  1249. }
  1250. WebInspector.IndexedDBTreeElement.prototype = {
  1251. onexpand: function()
  1252. {
  1253. WebInspector.StorageCategoryTreeElement.prototype.onexpand.call(this);
  1254. if (!this._indexedDBModel)
  1255. this._createIndexedDBModel();
  1256. },
  1257. onattach: function()
  1258. {
  1259. WebInspector.StorageCategoryTreeElement.prototype.onattach.call(this);
  1260. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  1261. },
  1262. _handleContextMenuEvent: function(event)
  1263. {
  1264. var contextMenu = new WebInspector.ContextMenu(event);
  1265. contextMenu.appendItem(WebInspector.UIString("Refresh IndexedDB"), this.refreshIndexedDB.bind(this));
  1266. contextMenu.show();
  1267. },
  1268. _createIndexedDBModel: function()
  1269. {
  1270. this._indexedDBModel = new WebInspector.IndexedDBModel();
  1271. this._idbDatabaseTreeElements = [];
  1272. this._indexedDBModel.addEventListener(WebInspector.IndexedDBModel.EventTypes.DatabaseAdded, this._indexedDBAdded, this);
  1273. this._indexedDBModel.addEventListener(WebInspector.IndexedDBModel.EventTypes.DatabaseRemoved, this._indexedDBRemoved, this);
  1274. this._indexedDBModel.addEventListener(WebInspector.IndexedDBModel.EventTypes.DatabaseLoaded, this._indexedDBLoaded, this);
  1275. },
  1276. refreshIndexedDB: function()
  1277. {
  1278. if (!this._indexedDBModel) {
  1279. this._createIndexedDBModel();
  1280. return;
  1281. }
  1282. this._indexedDBModel.refreshDatabaseNames();
  1283. },
  1284. /**
  1285. * @param {WebInspector.Event} event
  1286. */
  1287. _indexedDBAdded: function(event)
  1288. {
  1289. var databaseId = /** @type {WebInspector.IndexedDBModel.DatabaseId} */ (event.data);
  1290. var idbDatabaseTreeElement = new WebInspector.IDBDatabaseTreeElement(this._storagePanel, this._indexedDBModel, databaseId);
  1291. this._idbDatabaseTreeElements.push(idbDatabaseTreeElement);
  1292. this.appendChild(idbDatabaseTreeElement);
  1293. this._indexedDBModel.refreshDatabase(databaseId);
  1294. },
  1295. /**
  1296. * @param {WebInspector.Event} event
  1297. */
  1298. _indexedDBRemoved: function(event)
  1299. {
  1300. var databaseId = /** @type {WebInspector.IndexedDBModel.DatabaseId} */ (event.data);
  1301. var idbDatabaseTreeElement = this._idbDatabaseTreeElement(databaseId)
  1302. if (!idbDatabaseTreeElement)
  1303. return;
  1304. idbDatabaseTreeElement.clear();
  1305. this.removeChild(idbDatabaseTreeElement);
  1306. this._idbDatabaseTreeElements.remove(idbDatabaseTreeElement);
  1307. },
  1308. /**
  1309. * @param {WebInspector.Event} event
  1310. */
  1311. _indexedDBLoaded: function(event)
  1312. {
  1313. var database = /** @type {WebInspector.IndexedDBModel.Database} */ (event.data);
  1314. var idbDatabaseTreeElement = this._idbDatabaseTreeElement(database.databaseId)
  1315. if (!idbDatabaseTreeElement)
  1316. return;
  1317. idbDatabaseTreeElement.update(database);
  1318. },
  1319. /**
  1320. * @param {WebInspector.IndexedDBModel.DatabaseId} databaseId
  1321. * @return {WebInspector.IDBDatabaseTreeElement}
  1322. */
  1323. _idbDatabaseTreeElement: function(databaseId)
  1324. {
  1325. var index = -1;
  1326. for (var i = 0; i < this._idbDatabaseTreeElements.length; ++i) {
  1327. if (this._idbDatabaseTreeElements[i]._databaseId.equals(databaseId)) {
  1328. index = i;
  1329. break;
  1330. }
  1331. }
  1332. if (index !== -1)
  1333. return this._idbDatabaseTreeElements[i];
  1334. return null;
  1335. },
  1336. __proto__: WebInspector.StorageCategoryTreeElement.prototype
  1337. }
  1338. /**
  1339. * @constructor
  1340. * @extends {WebInspector.StorageCategoryTreeElement}
  1341. * @param {WebInspector.ResourcesPanel} storagePanel
  1342. */
  1343. WebInspector.FileSystemListTreeElement = function(storagePanel)
  1344. {
  1345. WebInspector.StorageCategoryTreeElement.call(this, storagePanel, WebInspector.UIString("FileSystem"), "FileSystem", ["file-system-storage-tree-item"]);
  1346. }
  1347. WebInspector.FileSystemListTreeElement.prototype = {
  1348. onexpand: function()
  1349. {
  1350. WebInspector.StorageCategoryTreeElement.prototype.onexpand.call(this);
  1351. this._refreshFileSystem();
  1352. },
  1353. onattach: function()
  1354. {
  1355. WebInspector.StorageCategoryTreeElement.prototype.onattach.call(this);
  1356. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  1357. },
  1358. _handleContextMenuEvent: function(event)
  1359. {
  1360. var contextMenu = new WebInspector.ContextMenu(event);
  1361. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Refresh FileSystem list" : "Refresh FileSystem List"), this._refreshFileSystem.bind(this));
  1362. contextMenu.show();
  1363. },
  1364. _fileSystemAdded: function(event)
  1365. {
  1366. var fileSystem = /** @type {WebInspector.FileSystemModel.FileSystem} */ (event.data);
  1367. var fileSystemTreeElement = new WebInspector.FileSystemTreeElement(this._storagePanel, fileSystem);
  1368. this.appendChild(fileSystemTreeElement);
  1369. },
  1370. _fileSystemRemoved: function(event)
  1371. {
  1372. var fileSystem = /** @type {WebInspector.FileSystemModel.FileSystem} */ (event.data);
  1373. var fileSystemTreeElement = this._fileSystemTreeElementByName(fileSystem.name);
  1374. if (!fileSystemTreeElement)
  1375. return;
  1376. fileSystemTreeElement.clear();
  1377. this.removeChild(fileSystemTreeElement);
  1378. },
  1379. _fileSystemTreeElementByName: function(fileSystemName)
  1380. {
  1381. for (var i = 0; i < this.children.length; ++i) {
  1382. var child = /** @type {WebInspector.FileSystemTreeElement} */ (this.children[i]);
  1383. if (child.fileSystemName === fileSystemName)
  1384. return this.children[i];
  1385. }
  1386. return null;
  1387. },
  1388. _refreshFileSystem: function()
  1389. {
  1390. if (!this._fileSystemModel) {
  1391. this._fileSystemModel = new WebInspector.FileSystemModel();
  1392. this._fileSystemModel.addEventListener(WebInspector.FileSystemModel.EventTypes.FileSystemAdded, this._fileSystemAdded, this);
  1393. this._fileSystemModel.addEventListener(WebInspector.FileSystemModel.EventTypes.FileSystemRemoved, this._fileSystemRemoved, this);
  1394. }
  1395. this._fileSystemModel.refreshFileSystemList();
  1396. },
  1397. __proto__: WebInspector.StorageCategoryTreeElement.prototype
  1398. }
  1399. /**
  1400. * @constructor
  1401. * @extends {WebInspector.BaseStorageTreeElement}
  1402. * @param {WebInspector.ResourcesPanel} storagePanel
  1403. * @param {WebInspector.IndexedDBModel} model
  1404. * @param {WebInspector.IndexedDBModel.DatabaseId} databaseId
  1405. */
  1406. WebInspector.IDBDatabaseTreeElement = function(storagePanel, model, databaseId)
  1407. {
  1408. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, databaseId.name + " - " + databaseId.securityOrigin, ["indexed-db-storage-tree-item"]);
  1409. this._model = model;
  1410. this._databaseId = databaseId;
  1411. this._idbObjectStoreTreeElements = {};
  1412. }
  1413. WebInspector.IDBDatabaseTreeElement.prototype = {
  1414. get itemURL()
  1415. {
  1416. return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._databaseId.name;
  1417. },
  1418. onattach: function()
  1419. {
  1420. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  1421. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  1422. },
  1423. _handleContextMenuEvent: function(event)
  1424. {
  1425. var contextMenu = new WebInspector.ContextMenu(event);
  1426. contextMenu.appendItem(WebInspector.UIString("Refresh IndexedDB"), this._refreshIndexedDB.bind(this));
  1427. contextMenu.show();
  1428. },
  1429. _refreshIndexedDB: function()
  1430. {
  1431. this._model.refreshDatabaseNames();
  1432. },
  1433. /**
  1434. * @param {WebInspector.IndexedDBModel.Database} database
  1435. */
  1436. update: function(database)
  1437. {
  1438. this._database = database;
  1439. var objectStoreNames = {};
  1440. for (var objectStoreName in this._database.objectStores) {
  1441. var objectStore = this._database.objectStores[objectStoreName];
  1442. objectStoreNames[objectStore.name] = true;
  1443. if (!this._idbObjectStoreTreeElements[objectStore.name]) {
  1444. var idbObjectStoreTreeElement = new WebInspector.IDBObjectStoreTreeElement(this._storagePanel, this._model, this._databaseId, objectStore);
  1445. this._idbObjectStoreTreeElements[objectStore.name] = idbObjectStoreTreeElement;
  1446. this.appendChild(idbObjectStoreTreeElement);
  1447. }
  1448. this._idbObjectStoreTreeElements[objectStore.name].update(objectStore);
  1449. }
  1450. for (var objectStoreName in this._idbObjectStoreTreeElements) {
  1451. if (!objectStoreNames[objectStoreName])
  1452. this._objectStoreRemoved(objectStoreName);
  1453. }
  1454. if (this.children.length) {
  1455. this.hasChildren = true;
  1456. this.expand();
  1457. }
  1458. if (this._view)
  1459. this._view.update(database);
  1460. this._updateTooltip();
  1461. },
  1462. _updateTooltip: function()
  1463. {
  1464. this.tooltip = WebInspector.UIString("Version") + ": " + this._database.version;
  1465. },
  1466. onselect: function(selectedByUser)
  1467. {
  1468. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1469. if (!this._view)
  1470. this._view = new WebInspector.IDBDatabaseView(this._database);
  1471. this._storagePanel.showIndexedDB(this._view);
  1472. },
  1473. /**
  1474. * @param {string} objectStoreName
  1475. */
  1476. _objectStoreRemoved: function(objectStoreName)
  1477. {
  1478. var objectStoreTreeElement = this._idbObjectStoreTreeElements[objectStoreName];
  1479. objectStoreTreeElement.clear();
  1480. this.removeChild(objectStoreTreeElement);
  1481. delete this._idbObjectStoreTreeElements[objectStoreName];
  1482. },
  1483. clear: function()
  1484. {
  1485. for (var objectStoreName in this._idbObjectStoreTreeElements)
  1486. this._objectStoreRemoved(objectStoreName);
  1487. },
  1488. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1489. }
  1490. /**
  1491. * @constructor
  1492. * @extends {WebInspector.BaseStorageTreeElement}
  1493. * @param {WebInspector.ResourcesPanel} storagePanel
  1494. * @param {WebInspector.IndexedDBModel} model
  1495. * @param {WebInspector.IndexedDBModel.DatabaseId} databaseId
  1496. * @param {WebInspector.IndexedDBModel.ObjectStore} objectStore
  1497. */
  1498. WebInspector.IDBObjectStoreTreeElement = function(storagePanel, model, databaseId, objectStore)
  1499. {
  1500. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, objectStore.name, ["indexed-db-object-store-storage-tree-item"]);
  1501. this._model = model;
  1502. this._databaseId = databaseId;
  1503. this._idbIndexTreeElements = {};
  1504. }
  1505. WebInspector.IDBObjectStoreTreeElement.prototype = {
  1506. get itemURL()
  1507. {
  1508. return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._databaseId.name + "/" + this._objectStore.name;
  1509. },
  1510. onattach: function()
  1511. {
  1512. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  1513. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  1514. },
  1515. _handleContextMenuEvent: function(event)
  1516. {
  1517. var contextMenu = new WebInspector.ContextMenu(event);
  1518. contextMenu.appendItem(WebInspector.UIString("Clear"), this._clearObjectStore.bind(this));
  1519. contextMenu.show();
  1520. },
  1521. _clearObjectStore: function()
  1522. {
  1523. function callback() {
  1524. this.update(this._objectStore);
  1525. }
  1526. this._model.clearObjectStore(this._databaseId, this._objectStore.name, callback.bind(this));
  1527. },
  1528. /**
  1529. * @param {WebInspector.IndexedDBModel.ObjectStore} objectStore
  1530. */
  1531. update: function(objectStore)
  1532. {
  1533. this._objectStore = objectStore;
  1534. var indexNames = {};
  1535. for (var indexName in this._objectStore.indexes) {
  1536. var index = this._objectStore.indexes[indexName];
  1537. indexNames[index.name] = true;
  1538. if (!this._idbIndexTreeElements[index.name]) {
  1539. var idbIndexTreeElement = new WebInspector.IDBIndexTreeElement(this._storagePanel, this._model, this._databaseId, this._objectStore, index);
  1540. this._idbIndexTreeElements[index.name] = idbIndexTreeElement;
  1541. this.appendChild(idbIndexTreeElement);
  1542. }
  1543. this._idbIndexTreeElements[index.name].update(index);
  1544. }
  1545. for (var indexName in this._idbIndexTreeElements) {
  1546. if (!indexNames[indexName])
  1547. this._indexRemoved(indexName);
  1548. }
  1549. for (var indexName in this._idbIndexTreeElements) {
  1550. if (!indexNames[indexName]) {
  1551. this.removeChild(this._idbIndexTreeElements[indexName]);
  1552. delete this._idbIndexTreeElements[indexName];
  1553. }
  1554. }
  1555. if (this.children.length) {
  1556. this.hasChildren = true;
  1557. this.expand();
  1558. }
  1559. if (this._view)
  1560. this._view.update(this._objectStore);
  1561. this._updateTooltip();
  1562. },
  1563. _updateTooltip: function()
  1564. {
  1565. var keyPathString = this._objectStore.keyPathString;
  1566. var tooltipString = keyPathString !== null ? (WebInspector.UIString("Key path: ") + keyPathString) : "";
  1567. if (this._objectStore.autoIncrement)
  1568. tooltipString += "\n" + WebInspector.UIString("autoIncrement");
  1569. this.tooltip = tooltipString
  1570. },
  1571. onselect: function(selectedByUser)
  1572. {
  1573. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1574. if (!this._view)
  1575. this._view = new WebInspector.IDBDataView(this._model, this._databaseId, this._objectStore, null);
  1576. this._storagePanel.showIndexedDB(this._view);
  1577. },
  1578. /**
  1579. * @param {string} indexName
  1580. */
  1581. _indexRemoved: function(indexName)
  1582. {
  1583. var indexTreeElement = this._idbIndexTreeElements[indexName];
  1584. indexTreeElement.clear();
  1585. this.removeChild(indexTreeElement);
  1586. delete this._idbIndexTreeElements[indexName];
  1587. },
  1588. clear: function()
  1589. {
  1590. for (var indexName in this._idbIndexTreeElements)
  1591. this._indexRemoved(indexName);
  1592. if (this._view)
  1593. this._view.clear();
  1594. },
  1595. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1596. }
  1597. /**
  1598. * @constructor
  1599. * @extends {WebInspector.BaseStorageTreeElement}
  1600. * @param {WebInspector.ResourcesPanel} storagePanel
  1601. * @param {WebInspector.IndexedDBModel} model
  1602. * @param {WebInspector.IndexedDBModel.DatabaseId} databaseId
  1603. * @param {WebInspector.IndexedDBModel.ObjectStore} objectStore
  1604. * @param {WebInspector.IndexedDBModel.Index} index
  1605. */
  1606. WebInspector.IDBIndexTreeElement = function(storagePanel, model, databaseId, objectStore, index)
  1607. {
  1608. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, index.name, ["indexed-db-index-storage-tree-item"]);
  1609. this._model = model;
  1610. this._databaseId = databaseId;
  1611. this._objectStore = objectStore;
  1612. this._index = index;
  1613. }
  1614. WebInspector.IDBIndexTreeElement.prototype = {
  1615. get itemURL()
  1616. {
  1617. return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._databaseId.name + "/" + this._objectStore.name + "/" + this._index.name;
  1618. },
  1619. /**
  1620. * @param {WebInspector.IndexedDBModel.Index} index
  1621. */
  1622. update: function(index)
  1623. {
  1624. this._index = index;
  1625. if (this._view)
  1626. this._view.update(this._index);
  1627. this._updateTooltip();
  1628. },
  1629. _updateTooltip: function()
  1630. {
  1631. var tooltipLines = [];
  1632. var keyPathString = this._index.keyPathString;
  1633. tooltipLines.push(WebInspector.UIString("Key path: ") + keyPathString);
  1634. if (this._index.unique)
  1635. tooltipLines.push(WebInspector.UIString("unique"));
  1636. if (this._index.multiEntry)
  1637. tooltipLines.push(WebInspector.UIString("multiEntry"));
  1638. this.tooltip = tooltipLines.join("\n");
  1639. },
  1640. onselect: function(selectedByUser)
  1641. {
  1642. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1643. if (!this._view)
  1644. this._view = new WebInspector.IDBDataView(this._model, this._databaseId, this._objectStore, this._index);
  1645. this._storagePanel.showIndexedDB(this._view);
  1646. },
  1647. clear: function()
  1648. {
  1649. if (this._view)
  1650. this._view.clear();
  1651. },
  1652. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1653. }
  1654. /**
  1655. * @constructor
  1656. * @extends {WebInspector.BaseStorageTreeElement}
  1657. */
  1658. WebInspector.DOMStorageTreeElement = function(storagePanel, domStorage, className)
  1659. {
  1660. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, domStorage.securityOrigin ? domStorage.securityOrigin : WebInspector.UIString("Local Files"), ["domstorage-storage-tree-item", className]);
  1661. this._domStorage = domStorage;
  1662. }
  1663. WebInspector.DOMStorageTreeElement.prototype = {
  1664. get itemURL()
  1665. {
  1666. return "storage://" + this._domStorage.securityOrigin + "/" + (this._domStorage.isLocalStorage ? "local" : "session");
  1667. },
  1668. onselect: function(selectedByUser)
  1669. {
  1670. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1671. this._storagePanel._showDOMStorage(this._domStorage);
  1672. },
  1673. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1674. }
  1675. /**
  1676. * @constructor
  1677. * @extends {WebInspector.BaseStorageTreeElement}
  1678. */
  1679. WebInspector.CookieTreeElement = function(storagePanel, cookieDomain)
  1680. {
  1681. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, cookieDomain ? cookieDomain : WebInspector.UIString("Local Files"), ["cookie-storage-tree-item"]);
  1682. this._cookieDomain = cookieDomain;
  1683. }
  1684. WebInspector.CookieTreeElement.prototype = {
  1685. get itemURL()
  1686. {
  1687. return "cookies://" + this._cookieDomain;
  1688. },
  1689. onattach: function()
  1690. {
  1691. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  1692. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  1693. },
  1694. /**
  1695. * @param {Event} event
  1696. */
  1697. _handleContextMenuEvent: function(event)
  1698. {
  1699. var contextMenu = new WebInspector.ContextMenu(event);
  1700. contextMenu.appendItem(WebInspector.UIString("Clear"), this._clearCookies.bind(this));
  1701. contextMenu.show();
  1702. },
  1703. /**
  1704. * @param {string} domain
  1705. */
  1706. _clearCookies: function(domain)
  1707. {
  1708. this._storagePanel.clearCookies(this._cookieDomain);
  1709. },
  1710. onselect: function(selectedByUser)
  1711. {
  1712. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1713. this._storagePanel.showCookies(this, this._cookieDomain);
  1714. },
  1715. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1716. }
  1717. /**
  1718. * @constructor
  1719. * @extends {WebInspector.BaseStorageTreeElement}
  1720. */
  1721. WebInspector.ApplicationCacheManifestTreeElement = function(storagePanel, manifestURL)
  1722. {
  1723. var title = new WebInspector.ParsedURL(manifestURL).displayName;
  1724. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, title, ["application-cache-storage-tree-item"]);
  1725. this.tooltip = manifestURL;
  1726. this._manifestURL = manifestURL;
  1727. }
  1728. WebInspector.ApplicationCacheManifestTreeElement.prototype = {
  1729. get itemURL()
  1730. {
  1731. return "appcache://" + this._manifestURL;
  1732. },
  1733. get manifestURL()
  1734. {
  1735. return this._manifestURL;
  1736. },
  1737. onselect: function(selectedByUser)
  1738. {
  1739. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1740. this._storagePanel.showCategoryView(this._manifestURL);
  1741. },
  1742. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1743. }
  1744. /**
  1745. * @constructor
  1746. * @extends {WebInspector.BaseStorageTreeElement}
  1747. */
  1748. WebInspector.ApplicationCacheFrameTreeElement = function(storagePanel, frameId, manifestURL)
  1749. {
  1750. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, "", ["frame-storage-tree-item"]);
  1751. this._frameId = frameId;
  1752. this._manifestURL = manifestURL;
  1753. this._refreshTitles();
  1754. }
  1755. WebInspector.ApplicationCacheFrameTreeElement.prototype = {
  1756. get itemURL()
  1757. {
  1758. return "appcache://" + this._manifestURL + "/" + encodeURI(this.displayName);
  1759. },
  1760. get frameId()
  1761. {
  1762. return this._frameId;
  1763. },
  1764. get manifestURL()
  1765. {
  1766. return this._manifestURL;
  1767. },
  1768. _refreshTitles: function()
  1769. {
  1770. var frame = WebInspector.resourceTreeModel.frameForId(this._frameId);
  1771. if (!frame) {
  1772. this.subtitleText = WebInspector.UIString("new frame");
  1773. return;
  1774. }
  1775. this.titleText = frame.name;
  1776. this.subtitleText = new WebInspector.ParsedURL(frame.url).displayName;
  1777. },
  1778. frameNavigated: function()
  1779. {
  1780. this._refreshTitles();
  1781. },
  1782. onselect: function(selectedByUser)
  1783. {
  1784. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1785. this._storagePanel.showApplicationCache(this._frameId);
  1786. },
  1787. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1788. }
  1789. /**
  1790. * @constructor
  1791. * @extends {WebInspector.BaseStorageTreeElement}
  1792. * @param {WebInspector.ResourcesPanel} storagePanel
  1793. * @param {WebInspector.FileSystemModel.FileSystem} fileSystem
  1794. */
  1795. WebInspector.FileSystemTreeElement = function(storagePanel, fileSystem)
  1796. {
  1797. var displayName = fileSystem.type + " - " + fileSystem.origin;
  1798. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, displayName, ["file-system-storage-tree-item"]);
  1799. this._fileSystem = fileSystem;
  1800. }
  1801. WebInspector.FileSystemTreeElement.prototype = {
  1802. get fileSystemName()
  1803. {
  1804. return this._fileSystem.name;
  1805. },
  1806. get itemURL()
  1807. {
  1808. return "filesystem://" + this._fileSystem.name;
  1809. },
  1810. onselect: function(selectedByUser)
  1811. {
  1812. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
  1813. this._fileSystemView = new WebInspector.FileSystemView(this._fileSystem);
  1814. this._storagePanel.showFileSystem(this._fileSystemView);
  1815. },
  1816. clear: function()
  1817. {
  1818. if (this.fileSystemView && this._storagePanel.visibleView === this.fileSystemView)
  1819. this._storagePanel.closeVisibleView();
  1820. },
  1821. __proto__: WebInspector.BaseStorageTreeElement.prototype
  1822. }
  1823. /**
  1824. * @constructor
  1825. * @extends {WebInspector.View}
  1826. */
  1827. WebInspector.StorageCategoryView = function()
  1828. {
  1829. WebInspector.View.call(this);
  1830. this.element.addStyleClass("storage-view");
  1831. this._emptyView = new WebInspector.EmptyView("");
  1832. this._emptyView.show(this.element);
  1833. }
  1834. WebInspector.StorageCategoryView.prototype = {
  1835. setText: function(text)
  1836. {
  1837. this._emptyView.text = text;
  1838. },
  1839. __proto__: WebInspector.View.prototype
  1840. }
  1841. /**
  1842. * @constructor
  1843. * @param {WebInspector.BaseStorageTreeElement} rootElement
  1844. * @param {number} matchesCount
  1845. */
  1846. WebInspector.ResourcesSearchController = function(rootElement, matchesCount)
  1847. {
  1848. this._root = rootElement;
  1849. this._matchesCount = matchesCount;
  1850. this._traverser = new WebInspector.SearchResultsTreeElementsTraverser(rootElement);
  1851. this._lastTreeElement = null;
  1852. this._lastIndex = -1;
  1853. }
  1854. WebInspector.ResourcesSearchController.prototype = {
  1855. /**
  1856. * @param {WebInspector.BaseStorageTreeElement} currentTreeElement
  1857. */
  1858. nextSearchResult: function(currentTreeElement)
  1859. {
  1860. if (!currentTreeElement)
  1861. return this._searchResult(this._traverser.first(), 0, 1);
  1862. if (!currentTreeElement.searchMatchesCount)
  1863. return this._searchResult(this._traverser.next(currentTreeElement), 0);
  1864. if (this._lastTreeElement !== currentTreeElement || this._lastIndex === -1)
  1865. return this._searchResult(currentTreeElement, 0);
  1866. if (this._lastIndex === currentTreeElement.searchMatchesCount - 1)
  1867. return this._searchResult(this._traverser.next(currentTreeElement), 0, this._currentMatchIndex % this._matchesCount + 1);
  1868. return this._searchResult(currentTreeElement, this._lastIndex + 1, this._currentMatchIndex + 1);
  1869. },
  1870. /**
  1871. * @param {WebInspector.BaseStorageTreeElement} currentTreeElement
  1872. */
  1873. previousSearchResult: function(currentTreeElement)
  1874. {
  1875. if (!currentTreeElement) {
  1876. var treeElement = this._traverser.last();
  1877. return this._searchResult(treeElement, treeElement.searchMatchesCount - 1, this._matchesCount);
  1878. }
  1879. if (currentTreeElement.searchMatchesCount && this._lastTreeElement === currentTreeElement) {
  1880. if (this._lastIndex > 0)
  1881. return this._searchResult(currentTreeElement, this._lastIndex - 1, this._currentMatchIndex - 1);
  1882. else {
  1883. var treeElement = this._traverser.previous(currentTreeElement);
  1884. var currentMatchIndex = this._currentMatchIndex - 1 ? this._currentMatchIndex - 1 : this._matchesCount;
  1885. return this._searchResult(treeElement, treeElement.searchMatchesCount - 1, currentMatchIndex);
  1886. }
  1887. }
  1888. var treeElement = this._traverser.previous(currentTreeElement)
  1889. return this._searchResult(treeElement, treeElement.searchMatchesCount - 1);
  1890. },
  1891. /**
  1892. * @param {WebInspector.BaseStorageTreeElement} treeElement
  1893. * @param {number} index
  1894. * @param {number=} currentMatchIndex
  1895. * @return {Object}
  1896. */
  1897. _searchResult: function(treeElement, index, currentMatchIndex)
  1898. {
  1899. this._lastTreeElement = treeElement;
  1900. this._lastIndex = index;
  1901. if (!currentMatchIndex)
  1902. currentMatchIndex = this._traverser.matchIndex(treeElement, index);
  1903. this._currentMatchIndex = currentMatchIndex;
  1904. return {treeElement: treeElement, index: index, currentMatchIndex: currentMatchIndex};
  1905. }
  1906. }
  1907. /**
  1908. * @constructor
  1909. * @param {WebInspector.BaseStorageTreeElement} rootElement
  1910. */
  1911. WebInspector.SearchResultsTreeElementsTraverser = function(rootElement)
  1912. {
  1913. this._root = rootElement;
  1914. }
  1915. WebInspector.SearchResultsTreeElementsTraverser.prototype = {
  1916. /**
  1917. * @return {WebInspector.BaseStorageTreeElement}
  1918. */
  1919. first: function()
  1920. {
  1921. return this.next(this._root);
  1922. },
  1923. /**
  1924. * @return {WebInspector.BaseStorageTreeElement}
  1925. */
  1926. last: function()
  1927. {
  1928. return this.previous(this._root);
  1929. },
  1930. /**
  1931. * @param {WebInspector.BaseStorageTreeElement} startTreeElement
  1932. * @return {WebInspector.BaseStorageTreeElement}
  1933. */
  1934. next: function(startTreeElement)
  1935. {
  1936. var treeElement = startTreeElement;
  1937. do {
  1938. treeElement = this._traverseNext(treeElement) || this._root;
  1939. } while (treeElement != startTreeElement && !this._elementSearchMatchesCount(treeElement));
  1940. return treeElement;
  1941. },
  1942. /**
  1943. * @param {WebInspector.BaseStorageTreeElement} startTreeElement
  1944. * @return {WebInspector.BaseStorageTreeElement}
  1945. */
  1946. previous: function(startTreeElement)
  1947. {
  1948. var treeElement = startTreeElement;
  1949. do {
  1950. treeElement = this._traversePrevious(treeElement) || this._lastTreeElement();
  1951. } while (treeElement != startTreeElement && !this._elementSearchMatchesCount(treeElement));
  1952. return treeElement;
  1953. },
  1954. /**
  1955. * @param {WebInspector.BaseStorageTreeElement} startTreeElement
  1956. * @param {number} index
  1957. * @return {number}
  1958. */
  1959. matchIndex: function(startTreeElement, index)
  1960. {
  1961. var matchIndex = 1;
  1962. var treeElement = this._root;
  1963. while (treeElement != startTreeElement) {
  1964. matchIndex += this._elementSearchMatchesCount(treeElement);
  1965. treeElement = this._traverseNext(treeElement) || this._root;
  1966. if (treeElement === this._root)
  1967. return 0;
  1968. }
  1969. return matchIndex + index;
  1970. },
  1971. /**
  1972. * @param {WebInspector.BaseStorageTreeElement} treeElement
  1973. * @return {number}
  1974. */
  1975. _elementSearchMatchesCount: function(treeElement)
  1976. {
  1977. return treeElement.searchMatchesCount;
  1978. },
  1979. /**
  1980. * @param {WebInspector.BaseStorageTreeElement} treeElement
  1981. * @return {WebInspector.BaseStorageTreeElement}
  1982. */
  1983. _traverseNext: function(treeElement)
  1984. {
  1985. return /** @type {WebInspector.BaseStorageTreeElement} */ (treeElement.traverseNextTreeElement(false, this._root, true));
  1986. },
  1987. /**
  1988. * @param {WebInspector.BaseStorageTreeElement} treeElement
  1989. * @return {WebInspector.BaseStorageTreeElement}
  1990. */
  1991. _traversePrevious: function(treeElement)
  1992. {
  1993. return /** @type {WebInspector.BaseStorageTreeElement} */ (treeElement.traversePreviousTreeElement(false, true));
  1994. },
  1995. /**
  1996. * @return {WebInspector.BaseStorageTreeElement}
  1997. */
  1998. _lastTreeElement: function()
  1999. {
  2000. var treeElement = this._root;
  2001. var nextTreeElement;
  2002. while (nextTreeElement = this._traverseNext(treeElement))
  2003. treeElement = nextTreeElement;
  2004. return treeElement;
  2005. }
  2006. }