| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 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 /** | |
| 32 * @constructor | |
| 33 * @extends {WebInspector.DialogDelegate} | |
| 34 * @param {string} fileSystemPath | |
| 35 */ | |
| 36 WebInspector.EditFileSystemDialog = function(fileSystemPath) | |
| 37 { | |
| 38 WebInspector.DialogDelegate.call(this); | |
| 39 this._fileSystemPath = fileSystemPath; | |
| 40 | |
| 41 this.element = document.createElement("div"); | |
| 42 this.element.className = "edit-file-system-dialog"; | |
| 43 | |
| 44 var header = this.element.createChild("div", "header"); | |
| 45 var headerText = header.createChild("span"); | |
| 46 headerText.textContent = WebInspector.UIString("Edit file system"); | |
| 47 | |
| 48 var closeButton = header.createChild("div", "close-button-gray done-button")
; | |
| 49 closeButton.addEventListener("click", this._onDoneClick.bind(this), false); | |
| 50 | |
| 51 var contents = this.element.createChild("div", "contents"); | |
| 52 | |
| 53 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.FileMappingAdded, this._fileMappingAdded, this); | |
| 54 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.FileMappingRemoved, this._fileMappingRemoved, this); | |
| 55 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.ExcludedFolderAdded, this._excludedFolderAdded, this
); | |
| 56 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.ExcludedFolderRemoved, this._excludedFolderRemoved,
this); | |
| 57 | |
| 58 var blockHeader = contents.createChild("div", "block-header"); | |
| 59 blockHeader.textContent = WebInspector.UIString("Mappings"); | |
| 60 this._fileMappingsSection = contents.createChild("div", "section file-mappin
gs-section"); | |
| 61 this._fileMappingsListContainer = this._fileMappingsSection.createChild("div
", "settings-list-container"); | |
| 62 var entries = WebInspector.isolatedFileSystemManager.mapping().mappingEntrie
s(this._fileSystemPath); | |
| 63 | |
| 64 this._fileMappingsList = new WebInspector.EditableSettingsList(["url", "path
"], this._fileMappingValuesProvider.bind(this), this._fileMappingValidate.bind(t
his), this._fileMappingEdit.bind(this)); | |
| 65 this._fileMappingsList.addEventListener(WebInspector.SettingsList.Events.Rem
oved, this._fileMappingRemovedfromList.bind(this)); | |
| 66 | |
| 67 this._fileMappingsList.element.classList.add("file-mappings-list"); | |
| 68 this._fileMappingsListContainer.appendChild(this._fileMappingsList.element); | |
| 69 | |
| 70 this._entries = {}; | |
| 71 for (var i = 0; i < entries.length; ++i) | |
| 72 this._addMappingRow(entries[i]); | |
| 73 | |
| 74 blockHeader = contents.createChild("div", "block-header"); | |
| 75 blockHeader.textContent = WebInspector.UIString("Excluded folders"); | |
| 76 this._excludedFolderListSection = contents.createChild("div", "section exclu
ded-folders-section"); | |
| 77 this._excludedFolderListContainer = this._excludedFolderListSection.createCh
ild("div", "settings-list-container"); | |
| 78 var excludedFolderEntries = WebInspector.isolatedFileSystemManager.mapping()
.excludedFolders(fileSystemPath); | |
| 79 | |
| 80 this._excludedFolderList = new WebInspector.EditableSettingsList(["path"], t
his._excludedFolderValueProvider.bind(this), this._excludedFolderValidate.bind(t
his), this._excludedFolderEdit.bind(this)); | |
| 81 this._excludedFolderList.addEventListener(WebInspector.SettingsList.Events.R
emoved, this._excludedFolderRemovedfromList.bind(this)); | |
| 82 this._excludedFolderList.element.classList.add("excluded-folders-list"); | |
| 83 this._excludedFolderListContainer.appendChild(this._excludedFolderList.eleme
nt); | |
| 84 this._excludedFolderEntries = new StringMap(); | |
| 85 for (var i = 0; i < excludedFolderEntries.length; ++i) | |
| 86 this._addExcludedFolderRow(excludedFolderEntries[i]); | |
| 87 | |
| 88 this.element.tabIndex = 0; | |
| 89 } | |
| 90 | |
| 91 WebInspector.EditFileSystemDialog.show = function(element, fileSystemPath) | |
| 92 { | |
| 93 WebInspector.Dialog.show(element, new WebInspector.EditFileSystemDialog(file
SystemPath)); | |
| 94 var glassPane = document.getElementById("glass-pane"); | |
| 95 glassPane.classList.add("settings-glass-pane"); | |
| 96 } | |
| 97 | |
| 98 WebInspector.EditFileSystemDialog.prototype = { | |
| 99 /** | |
| 100 * @param {!Element} element | |
| 101 */ | |
| 102 show: function(element) | |
| 103 { | |
| 104 element.appendChild(this.element); | |
| 105 this.element.classList.add("dialog-contents"); | |
| 106 element.classList.add("settings-dialog"); | |
| 107 element.classList.add("settings-tab"); | |
| 108 this._dialogElement = element; | |
| 109 }, | |
| 110 | |
| 111 _resize: function() | |
| 112 { | |
| 113 if (!this._dialogElement || !this._relativeToElement) | |
| 114 return; | |
| 115 | |
| 116 const minWidth = 200; | |
| 117 const minHeight = 150; | |
| 118 var maxHeight = this._relativeToElement.offsetHeight - 10; | |
| 119 maxHeight = Math.max(minHeight, maxHeight); | |
| 120 var maxWidth = Math.min(540, this._relativeToElement.offsetWidth - 10); | |
| 121 maxWidth = Math.max(minWidth, maxWidth); | |
| 122 this._dialogElement.style.maxHeight = maxHeight + "px"; | |
| 123 this._dialogElement.style.width = maxWidth + "px"; | |
| 124 | |
| 125 WebInspector.DialogDelegate.prototype.position(this._dialogElement, this
._relativeToElement); | |
| 126 }, | |
| 127 | |
| 128 /** | |
| 129 * @param {!Element} element | |
| 130 * @param {!Element} relativeToElement | |
| 131 */ | |
| 132 position: function(element, relativeToElement) | |
| 133 { | |
| 134 this._relativeToElement = relativeToElement; | |
| 135 this._resize(); | |
| 136 }, | |
| 137 | |
| 138 willHide: function(event) | |
| 139 { | |
| 140 }, | |
| 141 | |
| 142 _fileMappingAdded: function(event) | |
| 143 { | |
| 144 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (event.
data); | |
| 145 this._addMappingRow(entry); | |
| 146 }, | |
| 147 | |
| 148 _fileMappingRemoved: function(event) | |
| 149 { | |
| 150 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (event.
data); | |
| 151 if (this._fileSystemPath !== entry.fileSystemPath) | |
| 152 return; | |
| 153 delete this._entries[entry.urlPrefix]; | |
| 154 if (this._fileMappingsList.itemForId(entry.urlPrefix)) | |
| 155 this._fileMappingsList.removeItem(entry.urlPrefix); | |
| 156 this._resize(); | |
| 157 }, | |
| 158 | |
| 159 /** | |
| 160 * @param {string} itemId | |
| 161 * @param {string} columnId | |
| 162 * @return {string} | |
| 163 */ | |
| 164 _fileMappingValuesProvider: function(itemId, columnId) | |
| 165 { | |
| 166 if (!itemId) | |
| 167 return ""; | |
| 168 var entry = this._entries[itemId]; | |
| 169 switch (columnId) { | |
| 170 case "url": | |
| 171 return entry.urlPrefix; | |
| 172 case "path": | |
| 173 return entry.pathPrefix; | |
| 174 default: | |
| 175 console.assert("Should not be reached."); | |
| 176 } | |
| 177 return ""; | |
| 178 }, | |
| 179 | |
| 180 /** | |
| 181 * @param {?string} itemId | |
| 182 * @param {!Object} data | |
| 183 */ | |
| 184 _fileMappingValidate: function(itemId, data) | |
| 185 { | |
| 186 var oldPathPrefix = itemId ? this._entries[itemId].pathPrefix : null; | |
| 187 return this._validateMapping(data["url"], itemId, data["path"], oldPathP
refix); | |
| 188 }, | |
| 189 | |
| 190 /** | |
| 191 * @param {?string} itemId | |
| 192 * @param {!Object} data | |
| 193 */ | |
| 194 _fileMappingEdit: function(itemId, data) | |
| 195 { | |
| 196 if (itemId) { | |
| 197 var urlPrefix = itemId; | |
| 198 var pathPrefix = this._entries[itemId].pathPrefix; | |
| 199 var fileSystemPath = this._entries[itemId].fileSystemPath; | |
| 200 WebInspector.isolatedFileSystemManager.mapping().removeFileMapping(f
ileSystemPath, urlPrefix, pathPrefix); | |
| 201 } | |
| 202 this._addFileMapping(data["url"], data["path"]); | |
| 203 }, | |
| 204 | |
| 205 /** | |
| 206 * @param {string} urlPrefix | |
| 207 * @param {?string} allowedURLPrefix | |
| 208 * @param {string} path | |
| 209 * @param {?string} allowedPathPrefix | |
| 210 */ | |
| 211 _validateMapping: function(urlPrefix, allowedURLPrefix, path, allowedPathPre
fix) | |
| 212 { | |
| 213 var columns = []; | |
| 214 if (!this._checkURLPrefix(urlPrefix, allowedURLPrefix)) | |
| 215 columns.push("url"); | |
| 216 if (!this._checkPathPrefix(path, allowedPathPrefix)) | |
| 217 columns.push("path"); | |
| 218 return columns; | |
| 219 }, | |
| 220 | |
| 221 /** | |
| 222 * @param {!WebInspector.Event} event | |
| 223 */ | |
| 224 _fileMappingRemovedfromList: function(event) | |
| 225 { | |
| 226 var urlPrefix = /** @type{?string} */ (event.data); | |
| 227 if (!urlPrefix) | |
| 228 return; | |
| 229 | |
| 230 var entry = this._entries[urlPrefix]; | |
| 231 WebInspector.isolatedFileSystemManager.mapping().removeFileMapping(entry
.fileSystemPath, entry.urlPrefix, entry.pathPrefix); | |
| 232 }, | |
| 233 | |
| 234 /** | |
| 235 * @param {string} urlPrefix | |
| 236 * @param {string} pathPrefix | |
| 237 * @return {boolean} | |
| 238 */ | |
| 239 _addFileMapping: function(urlPrefix, pathPrefix) | |
| 240 { | |
| 241 var normalizedURLPrefix = this._normalizePrefix(urlPrefix); | |
| 242 var normalizedPathPrefix = this._normalizePrefix(pathPrefix); | |
| 243 WebInspector.isolatedFileSystemManager.mapping().addFileMapping(this._fi
leSystemPath, normalizedURLPrefix, normalizedPathPrefix); | |
| 244 this._fileMappingsList.selectItem(normalizedURLPrefix); | |
| 245 return true; | |
| 246 }, | |
| 247 | |
| 248 /** | |
| 249 * @param {string} prefix | |
| 250 * @return {string} | |
| 251 */ | |
| 252 _normalizePrefix: function(prefix) | |
| 253 { | |
| 254 if (!prefix) | |
| 255 return ""; | |
| 256 return prefix + (prefix[prefix.length - 1] === "/" ? "" : "/"); | |
| 257 }, | |
| 258 | |
| 259 _addMappingRow: function(entry) | |
| 260 { | |
| 261 var fileSystemPath = entry.fileSystemPath; | |
| 262 var urlPrefix = entry.urlPrefix; | |
| 263 if (!this._fileSystemPath || this._fileSystemPath !== fileSystemPath) | |
| 264 return; | |
| 265 | |
| 266 this._entries[urlPrefix] = entry; | |
| 267 var fileMappingListItem = this._fileMappingsList.addItem(urlPrefix, null
); | |
| 268 this._resize(); | |
| 269 }, | |
| 270 | |
| 271 _excludedFolderAdded: function(event) | |
| 272 { | |
| 273 var entry = /** @type {!WebInspector.FileSystemMapping.ExcludedFolderEnt
ry} */ (event.data); | |
| 274 this._addExcludedFolderRow(entry); | |
| 275 }, | |
| 276 | |
| 277 _excludedFolderRemoved: function(event) | |
| 278 { | |
| 279 var entry = /** @type {!WebInspector.FileSystemMapping.ExcludedFolderEnt
ry} */ (event.data); | |
| 280 var fileSystemPath = entry.fileSystemPath; | |
| 281 if (!fileSystemPath || this._fileSystemPath !== fileSystemPath) | |
| 282 return; | |
| 283 delete this._excludedFolderEntries[entry.path]; | |
| 284 if (this._excludedFolderList.itemForId(entry.path)) | |
| 285 this._excludedFolderList.removeItem(entry.path); | |
| 286 }, | |
| 287 | |
| 288 /** | |
| 289 * @param {string} itemId | |
| 290 * @param {string} columnId | |
| 291 * @return {string} | |
| 292 */ | |
| 293 _excludedFolderValueProvider: function(itemId, columnId) | |
| 294 { | |
| 295 return itemId; | |
| 296 }, | |
| 297 | |
| 298 /** | |
| 299 * @param {?string} itemId | |
| 300 * @param {!Object} data | |
| 301 */ | |
| 302 _excludedFolderValidate: function(itemId, data) | |
| 303 { | |
| 304 var fileSystemPath = this._fileSystemPath; | |
| 305 var columns = []; | |
| 306 if (!this._validateExcludedFolder(data["path"], itemId)) | |
| 307 columns.push("path"); | |
| 308 return columns; | |
| 309 }, | |
| 310 | |
| 311 /** | |
| 312 * @param {string} path | |
| 313 * @param {?string} allowedPath | |
| 314 * @return {boolean} | |
| 315 */ | |
| 316 _validateExcludedFolder: function(path, allowedPath) | |
| 317 { | |
| 318 return !!path && (path === allowedPath || !this._excludedFolderEntries.c
ontains(path)); | |
| 319 }, | |
| 320 | |
| 321 /** | |
| 322 * @param {?string} itemId | |
| 323 * @param {!Object} data | |
| 324 */ | |
| 325 _excludedFolderEdit: function(itemId, data) | |
| 326 { | |
| 327 var fileSystemPath = this._fileSystemPath; | |
| 328 if (itemId) | |
| 329 WebInspector.isolatedFileSystemManager.mapping().removeExcludedFolde
r(fileSystemPath, itemId); | |
| 330 var excludedFolderPath = data["path"]; | |
| 331 WebInspector.isolatedFileSystemManager.mapping().addExcludedFolder(fileS
ystemPath, excludedFolderPath); | |
| 332 }, | |
| 333 | |
| 334 /** | |
| 335 * @param {!WebInspector.Event} event | |
| 336 */ | |
| 337 _excludedFolderRemovedfromList: function(event) | |
| 338 { | |
| 339 var itemId = /** @type{?string} */ (event.data); | |
| 340 if (!itemId) | |
| 341 return; | |
| 342 WebInspector.isolatedFileSystemManager.mapping().removeExcludedFolder(th
is._fileSystemPath, itemId); | |
| 343 }, | |
| 344 | |
| 345 /** | |
| 346 * @param {!WebInspector.FileSystemMapping.ExcludedFolderEntry} entry | |
| 347 */ | |
| 348 _addExcludedFolderRow: function(entry) | |
| 349 { | |
| 350 var fileSystemPath = entry.fileSystemPath; | |
| 351 if (!fileSystemPath || this._fileSystemPath !== fileSystemPath) | |
| 352 return; | |
| 353 var path = entry.path; | |
| 354 this._excludedFolderEntries.put(path, entry); | |
| 355 this._excludedFolderList.addItem(path, null); | |
| 356 this._resize(); | |
| 357 }, | |
| 358 | |
| 359 /** | |
| 360 * @param {string} value | |
| 361 * @param {?string} allowedPrefix | |
| 362 * @return {boolean} | |
| 363 */ | |
| 364 _checkURLPrefix: function(value, allowedPrefix) | |
| 365 { | |
| 366 var prefix = this._normalizePrefix(value); | |
| 367 return !!prefix && (prefix === allowedPrefix || !this._entries[prefix]); | |
| 368 }, | |
| 369 | |
| 370 /** | |
| 371 * @param {string} value | |
| 372 * @param {?string} allowedPrefix | |
| 373 * @return {boolean} | |
| 374 */ | |
| 375 _checkPathPrefix: function(value, allowedPrefix) | |
| 376 { | |
| 377 var prefix = this._normalizePrefix(value); | |
| 378 if (!prefix) | |
| 379 return false; | |
| 380 if (prefix === allowedPrefix) | |
| 381 return true; | |
| 382 for (var urlPrefix in this._entries) { | |
| 383 var entry = this._entries[urlPrefix]; | |
| 384 if (urlPrefix && entry.pathPrefix === prefix) | |
| 385 return false; | |
| 386 } | |
| 387 return true; | |
| 388 }, | |
| 389 | |
| 390 focus: function() | |
| 391 { | |
| 392 WebInspector.setCurrentFocusElement(this.element); | |
| 393 }, | |
| 394 | |
| 395 _onDoneClick: function() | |
| 396 { | |
| 397 WebInspector.Dialog.hide(); | |
| 398 }, | |
| 399 | |
| 400 onEnter: function() | |
| 401 { | |
| 402 }, | |
| 403 | |
| 404 __proto__: WebInspector.DialogDelegate.prototype | |
| 405 } | |
| OLD | NEW |