Commit 49abc1fa authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

DevTools: allow saving files in the hosted mode.

Change-Id: I34db4fd1972bc42289f1f88031057ec7dfd4e5f8
Reviewed-on: https://chromium-review.googlesource.com/1154204
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578918}
parent 8899a436
...@@ -515,6 +515,13 @@ ...@@ -515,6 +515,13 @@
DevToolsAPI.sendMessageToEmbedder('append', [url, content], null); DevToolsAPI.sendMessageToEmbedder('append', [url, content], null);
} }
/**
* @override
* @param {string} url
*/
close(url) {
}
/** /**
* @override * @override
* @param {string} message * @param {string} message
...@@ -811,59 +818,6 @@ ...@@ -811,59 +818,6 @@
return true; return true;
} }
/**
* Support for legacy front-ends (<M28).
* @return {boolean}
*/
canInspectWorkers() {
return true;
}
/**
* Support for legacy front-ends (<M28).
* @return {boolean}
*/
canSaveAs() {
return true;
}
/**
* Support for legacy front-ends (<M28).
* @return {boolean}
*/
canSave() {
return true;
}
/**
* Support for legacy front-ends (<M28).
*/
loaded() {
}
/**
* Support for legacy front-ends (<M28).
* @return {string}
*/
hiddenPanels() {
return '';
}
/**
* Support for legacy front-ends (<M28).
* @return {string}
*/
localizedStringsURL() {
return '';
}
/**
* Support for legacy front-ends (<M28).
* @param {string} url
*/
close(url) {
}
/** /**
* Support for legacy front-ends (<M44). * Support for legacy front-ends (<M44).
* @param {number} actionCode * @param {number} actionCode
......
...@@ -46,6 +46,10 @@ Host.InspectorFrontendHostStub = class { ...@@ -46,6 +46,10 @@ Host.InspectorFrontendHostStub = class {
event.stopPropagation(); event.stopPropagation();
} }
document.addEventListener('keydown', stopEventPropagation, true); document.addEventListener('keydown', stopEventPropagation, true);
/**
* @type {!Map<string, !Array<string>>}
*/
this._urlsBeingSaved = new Map();
} }
/** /**
...@@ -197,8 +201,13 @@ Host.InspectorFrontendHostStub = class { ...@@ -197,8 +201,13 @@ Host.InspectorFrontendHostStub = class {
* @param {boolean} forceSaveAs * @param {boolean} forceSaveAs
*/ */
save(url, content, forceSaveAs) { save(url, content, forceSaveAs) {
Common.console.error('Saving files is not enabled in hosted mode. Please inspect using chrome://inspect'); let buffer = this._urlsBeingSaved.get(url);
this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.CanceledSaveURL, url); if (!buffer) {
buffer = [];
this._urlsBeingSaved.set(url, buffer);
}
buffer.push(content);
this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.SavedURL, {url, fileSystemPath: url});
} }
/** /**
...@@ -207,7 +216,24 @@ Host.InspectorFrontendHostStub = class { ...@@ -207,7 +216,24 @@ Host.InspectorFrontendHostStub = class {
* @param {string} content * @param {string} content
*/ */
append(url, content) { append(url, content) {
Common.console.error('Saving files is not enabled in hosted mode. Please inspect using chrome://inspect'); const buffer = this._urlsBeingSaved.get(url);
buffer.push(content);
this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.AppendedToURL, url);
}
/**
* @override
* @param {string} url
*/
close(url) {
const buffer = this._urlsBeingSaved.get(url);
this._urlsBeingSaved.delete(url);
const fileName = url ? url.trimURL().removeURLFragment() : '';
const link = createElement('a');
link.download = fileName;
const blob = new Blob([buffer.join('')], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
} }
/** /**
......
...@@ -100,12 +100,6 @@ InspectorFrontendHostAPI.prototype = { ...@@ -100,12 +100,6 @@ InspectorFrontendHostAPI.prototype = {
*/ */
addFileSystem(type) {}, addFileSystem(type) {},
/**
* @param {string} url
* @param {string} content
*/
append(url, content) {},
loadCompleted() {}, loadCompleted() {},
/** /**
...@@ -182,6 +176,17 @@ InspectorFrontendHostAPI.prototype = { ...@@ -182,6 +176,17 @@ InspectorFrontendHostAPI.prototype = {
*/ */
save(url, content, forceSaveAs) {}, save(url, content, forceSaveAs) {},
/**
* @param {string} url
* @param {string} content
*/
append(url, content) {},
/**
* @param {string} url
*/
close(url) {},
/** /**
* @param {number} requestId * @param {number} requestId
* @param {string} fileSystemPath * @param {string} fileSystemPath
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment