| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | 31 * @unrestricted |
| 33 * @extends {WebInspector.Object} | |
| 34 */ | 32 */ |
| 35 WebInspector.FileManager = function() | 33 WebInspector.FileManager = class extends WebInspector.Object { |
| 36 { | 34 constructor() { |
| 37 this._savedURLsSetting = WebInspector.settings.createLocalSetting("savedURLs
", {}); | 35 super(); |
| 36 this._savedURLsSetting = WebInspector.settings.createLocalSetting('savedURLs
', {}); |
| 38 | 37 |
| 39 /** @type {!Object.<string, ?function(boolean)>} */ | 38 /** @type {!Object.<string, ?function(boolean)>} */ |
| 40 this._saveCallbacks = {}; | 39 this._saveCallbacks = {}; |
| 41 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SavedURL, this._savedURL, this); | 40 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SavedURL, this._savedURL, this); |
| 42 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.CanceledSaveURL, this._canceledSaveURL, this); | 41 InspectorFrontendHost.events.addEventListener( |
| 43 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.AppendedToURL, this._appendedToURL, this); | 42 InspectorFrontendHostAPI.Events.CanceledSaveURL, this._canceledSaveURL,
this); |
| 43 InspectorFrontendHost.events.addEventListener( |
| 44 InspectorFrontendHostAPI.Events.AppendedToURL, this._appendedToURL, this
); |
| 45 } |
| 46 |
| 47 /** |
| 48 * @param {string} url |
| 49 * @param {string} content |
| 50 * @param {boolean} forceSaveAs |
| 51 * @param {function(boolean)=} callback |
| 52 */ |
| 53 save(url, content, forceSaveAs, callback) { |
| 54 // Remove this url from the saved URLs while it is being saved. |
| 55 var savedURLs = this._savedURLsSetting.get(); |
| 56 delete savedURLs[url]; |
| 57 this._savedURLsSetting.set(savedURLs); |
| 58 this._saveCallbacks[url] = callback || null; |
| 59 InspectorFrontendHost.save(url, content, forceSaveAs); |
| 60 } |
| 61 |
| 62 /** |
| 63 * @param {!WebInspector.Event} event |
| 64 */ |
| 65 _savedURL(event) { |
| 66 var url = /** @type {string} */ (event.data); |
| 67 var savedURLs = this._savedURLsSetting.get(); |
| 68 savedURLs[url] = true; |
| 69 this._savedURLsSetting.set(savedURLs); |
| 70 this.dispatchEventToListeners(WebInspector.FileManager.Events.SavedURL, url)
; |
| 71 this._invokeSaveCallback(url, true); |
| 72 } |
| 73 |
| 74 /** |
| 75 * @param {string} url |
| 76 * @param {boolean} accepted |
| 77 */ |
| 78 _invokeSaveCallback(url, accepted) { |
| 79 var callback = this._saveCallbacks[url]; |
| 80 delete this._saveCallbacks[url]; |
| 81 if (callback) |
| 82 callback(accepted); |
| 83 } |
| 84 |
| 85 /** |
| 86 * @param {!WebInspector.Event} event |
| 87 */ |
| 88 _canceledSaveURL(event) { |
| 89 var url = /** @type {string} */ (event.data); |
| 90 this._invokeSaveCallback(url, false); |
| 91 } |
| 92 |
| 93 /** |
| 94 * @param {string} url |
| 95 * @return {boolean} |
| 96 */ |
| 97 isURLSaved(url) { |
| 98 var savedURLs = this._savedURLsSetting.get(); |
| 99 return savedURLs[url]; |
| 100 } |
| 101 |
| 102 /** |
| 103 * @param {string} url |
| 104 * @param {string} content |
| 105 */ |
| 106 append(url, content) { |
| 107 InspectorFrontendHost.append(url, content); |
| 108 } |
| 109 |
| 110 /** |
| 111 * @param {string} url |
| 112 */ |
| 113 close(url) { |
| 114 // Currently a no-op. |
| 115 } |
| 116 |
| 117 /** |
| 118 * @param {!WebInspector.Event} event |
| 119 */ |
| 120 _appendedToURL(event) { |
| 121 var url = /** @type {string} */ (event.data); |
| 122 this.dispatchEventToListeners(WebInspector.FileManager.Events.AppendedToURL,
url); |
| 123 } |
| 44 }; | 124 }; |
| 45 | 125 |
| 46 /** @enum {symbol} */ | 126 /** @enum {symbol} */ |
| 47 WebInspector.FileManager.Events = { | 127 WebInspector.FileManager.Events = { |
| 48 SavedURL: Symbol("SavedURL"), | 128 SavedURL: Symbol('SavedURL'), |
| 49 AppendedToURL: Symbol("AppendedToURL") | 129 AppendedToURL: Symbol('AppendedToURL') |
| 50 }; | |
| 51 | |
| 52 WebInspector.FileManager.prototype = { | |
| 53 /** | |
| 54 * @param {string} url | |
| 55 * @param {string} content | |
| 56 * @param {boolean} forceSaveAs | |
| 57 * @param {function(boolean)=} callback | |
| 58 */ | |
| 59 save: function(url, content, forceSaveAs, callback) | |
| 60 { | |
| 61 // Remove this url from the saved URLs while it is being saved. | |
| 62 var savedURLs = this._savedURLsSetting.get(); | |
| 63 delete savedURLs[url]; | |
| 64 this._savedURLsSetting.set(savedURLs); | |
| 65 this._saveCallbacks[url] = callback || null; | |
| 66 InspectorFrontendHost.save(url, content, forceSaveAs); | |
| 67 }, | |
| 68 | |
| 69 /** | |
| 70 * @param {!WebInspector.Event} event | |
| 71 */ | |
| 72 _savedURL: function(event) | |
| 73 { | |
| 74 var url = /** @type {string} */ (event.data); | |
| 75 var savedURLs = this._savedURLsSetting.get(); | |
| 76 savedURLs[url] = true; | |
| 77 this._savedURLsSetting.set(savedURLs); | |
| 78 this.dispatchEventToListeners(WebInspector.FileManager.Events.SavedURL,
url); | |
| 79 this._invokeSaveCallback(url, true); | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * @param {string} url | |
| 84 * @param {boolean} accepted | |
| 85 */ | |
| 86 _invokeSaveCallback: function(url, accepted) | |
| 87 { | |
| 88 var callback = this._saveCallbacks[url]; | |
| 89 delete this._saveCallbacks[url]; | |
| 90 if (callback) | |
| 91 callback(accepted); | |
| 92 }, | |
| 93 | |
| 94 /** | |
| 95 * @param {!WebInspector.Event} event | |
| 96 */ | |
| 97 _canceledSaveURL: function(event) | |
| 98 { | |
| 99 var url = /** @type {string} */ (event.data); | |
| 100 this._invokeSaveCallback(url, false); | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * @param {string} url | |
| 105 * @return {boolean} | |
| 106 */ | |
| 107 isURLSaved: function(url) | |
| 108 { | |
| 109 var savedURLs = this._savedURLsSetting.get(); | |
| 110 return savedURLs[url]; | |
| 111 }, | |
| 112 | |
| 113 /** | |
| 114 * @param {string} url | |
| 115 * @param {string} content | |
| 116 */ | |
| 117 append: function(url, content) | |
| 118 { | |
| 119 InspectorFrontendHost.append(url, content); | |
| 120 }, | |
| 121 | |
| 122 /** | |
| 123 * @param {string} url | |
| 124 */ | |
| 125 close: function(url) | |
| 126 { | |
| 127 // Currently a no-op. | |
| 128 }, | |
| 129 | |
| 130 /** | |
| 131 * @param {!WebInspector.Event} event | |
| 132 */ | |
| 133 _appendedToURL: function(event) | |
| 134 { | |
| 135 var url = /** @type {string} */ (event.data); | |
| 136 this.dispatchEventToListeners(WebInspector.FileManager.Events.AppendedTo
URL, url); | |
| 137 }, | |
| 138 | |
| 139 __proto__: WebInspector.Object.prototype | |
| 140 }; | 130 }; |
| 141 | 131 |
| 142 /** | 132 /** |
| 143 * @type {?WebInspector.FileManager} | 133 * @type {?WebInspector.FileManager} |
| 144 */ | 134 */ |
| 145 WebInspector.fileManager = null; | 135 WebInspector.fileManager = null; |
| OLD | NEW |