Commit de706cc8 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

DevTools: expose wired front-end API for editors interop [blink]

BUG=529471

Review URL: https://codereview.chromium.org/1314853006

git-svn-id: svn://svn.chromium.org/blink/trunk@202006 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 157fbe18
...@@ -289,6 +289,7 @@ ...@@ -289,6 +289,7 @@
], ],
'devtools_main_js_files': [ 'devtools_main_js_files': [
'front_end/main/AdvancedApp.js', 'front_end/main/AdvancedApp.js',
'front_end/main/FrontendWebSocketAPI.js',
'front_end/main/HelpScreenUntilReload.js', 'front_end/main/HelpScreenUntilReload.js',
'front_end/main/Main.js', 'front_end/main/Main.js',
'front_end/main/OverlayController.js', 'front_end/main/OverlayController.js',
......
...@@ -272,6 +272,24 @@ DevToolsAPIImpl.prototype = { ...@@ -272,6 +272,24 @@ DevToolsAPIImpl.prototype = {
streamWrite: function(id, chunk) streamWrite: function(id, chunk)
{ {
this._dispatchOnInspectorFrontendAPI("streamWrite", [id, chunk]); this._dispatchOnInspectorFrontendAPI("streamWrite", [id, chunk]);
},
frontendAPIAttached: function()
{
this._dispatchOnInspectorFrontendAPI("frontendAPIAttached", []);
},
frontendAPIDetached: function()
{
this._dispatchOnInspectorFrontendAPI("frontendAPIDetached", []);
},
/**
* @param {string} command
*/
dispatchFrontendAPIMessage: function(command)
{
this._dispatchOnInspectorFrontendAPI("dispatchFrontendAPIMessage", [command]);
} }
} }
...@@ -494,6 +512,15 @@ InspectorFrontendHostImpl.prototype = { ...@@ -494,6 +512,15 @@ InspectorFrontendHostImpl.prototype = {
DevToolsAPI.sendMessageToEmbedder("recordEnumeratedHistogram", [actionName, actionCode, bucketSize], null); DevToolsAPI.sendMessageToEmbedder("recordEnumeratedHistogram", [actionName, actionCode, bucketSize], null);
}, },
/**
* @override
* @param {string} message
*/
sendFrontendAPINotification: function(message)
{
DevToolsAPI.sendMessageToEmbedder("sendFrontendAPINotification", [message], null);
},
/** /**
* @override * @override
*/ */
......
...@@ -406,6 +406,14 @@ WebInspector.InspectorFrontendHostStub.prototype = { ...@@ -406,6 +406,14 @@ WebInspector.InspectorFrontendHostStub.prototype = {
isHostedMode: function() isHostedMode: function()
{ {
return true; return true;
},
/**
* @override
* @param {string} message
*/
sendFrontendAPINotification: function(message)
{
} }
}; };
......
...@@ -36,10 +36,13 @@ InspectorFrontendHostAPI.Events = { ...@@ -36,10 +36,13 @@ InspectorFrontendHostAPI.Events = {
DevicesUpdated: "devicesUpdated", DevicesUpdated: "devicesUpdated",
DispatchMessage: "dispatchMessage", DispatchMessage: "dispatchMessage",
DispatchMessageChunk: "dispatchMessageChunk", DispatchMessageChunk: "dispatchMessageChunk",
DispatchFrontendAPIMessage: "dispatchFrontendAPIMessage",
EnterInspectElementMode: "enterInspectElementMode", EnterInspectElementMode: "enterInspectElementMode",
FileSystemsLoaded: "fileSystemsLoaded", FileSystemsLoaded: "fileSystemsLoaded",
FileSystemRemoved: "fileSystemRemoved", FileSystemRemoved: "fileSystemRemoved",
FileSystemAdded: "fileSystemAdded", FileSystemAdded: "fileSystemAdded",
FrontendAPIAttached: "frontendAPIAttached",
FrontendAPIDetached: "frontendAPIDetached",
IndexingTotalWorkCalculated: "indexingTotalWorkCalculated", IndexingTotalWorkCalculated: "indexingTotalWorkCalculated",
IndexingWorked: "indexingWorked", IndexingWorked: "indexingWorked",
IndexingDone: "indexingDone", IndexingDone: "indexingDone",
...@@ -63,10 +66,13 @@ InspectorFrontendHostAPI.EventDescriptors = [ ...@@ -63,10 +66,13 @@ InspectorFrontendHostAPI.EventDescriptors = [
[InspectorFrontendHostAPI.Events.DevicesUpdated, ["devices"]], [InspectorFrontendHostAPI.Events.DevicesUpdated, ["devices"]],
[InspectorFrontendHostAPI.Events.DispatchMessage, ["messageObject"]], [InspectorFrontendHostAPI.Events.DispatchMessage, ["messageObject"]],
[InspectorFrontendHostAPI.Events.DispatchMessageChunk, ["messageChunk", "messageSize"]], [InspectorFrontendHostAPI.Events.DispatchMessageChunk, ["messageChunk", "messageSize"]],
[InspectorFrontendHostAPI.Events.DispatchFrontendAPIMessage, ["messageObject"]],
[InspectorFrontendHostAPI.Events.EnterInspectElementMode, []], [InspectorFrontendHostAPI.Events.EnterInspectElementMode, []],
[InspectorFrontendHostAPI.Events.FileSystemsLoaded, ["fileSystems"]], [InspectorFrontendHostAPI.Events.FileSystemsLoaded, ["fileSystems"]],
[InspectorFrontendHostAPI.Events.FileSystemRemoved, ["fileSystemPath"]], [InspectorFrontendHostAPI.Events.FileSystemRemoved, ["fileSystemPath"]],
[InspectorFrontendHostAPI.Events.FileSystemAdded, ["errorMessage", "fileSystem"]], [InspectorFrontendHostAPI.Events.FileSystemAdded, ["errorMessage", "fileSystem"]],
[InspectorFrontendHostAPI.Events.FrontendAPIAttached, ["frontendAPIAttached"]],
[InspectorFrontendHostAPI.Events.FrontendAPIDetached, ["frontendAPIDetached"]],
[InspectorFrontendHostAPI.Events.IndexingTotalWorkCalculated, ["requestId", "fileSystemPath", "totalWork"]], [InspectorFrontendHostAPI.Events.IndexingTotalWorkCalculated, ["requestId", "fileSystemPath", "totalWork"]],
[InspectorFrontendHostAPI.Events.IndexingWorked, ["requestId", "fileSystemPath", "worked"]], [InspectorFrontendHostAPI.Events.IndexingWorked, ["requestId", "fileSystemPath", "worked"]],
[InspectorFrontendHostAPI.Events.IndexingDone, ["requestId", "fileSystemPath"]], [InspectorFrontendHostAPI.Events.IndexingDone, ["requestId", "fileSystemPath"]],
...@@ -261,5 +267,10 @@ InspectorFrontendHostAPI.prototype = { ...@@ -261,5 +267,10 @@ InspectorFrontendHostAPI.prototype = {
/** /**
* @return {boolean} * @return {boolean}
*/ */
isHostedMode: function() { } isHostedMode: function() { },
/**
* @param {string} message
*/
sendFrontendAPINotification: function(message) { }
} }
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @constructor
*/
WebInspector.FrontendWebSocketAPI = function()
{
InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.DispatchFrontendAPIMessage, this._onFrontendAPIMessage, this);
InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FrontendAPIAttached, this._onAttach, this);
InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FrontendAPIDetached, this._onDetach, this);
}
WebInspector.FrontendWebSocketAPI.prototype = {
_onAttach: function()
{
WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._workingCopyChanged, this);
WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeWorkingCopyChanged, this._workingCopyChanged, this);
},
_onDetach: function()
{
WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._workingCopyChanged, this);
WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeWorkingCopyChanged, this._workingCopyChanged, this);
},
/**
* @param {!WebInspector.Event} event
*/
_onFrontendAPIMessage: function(event)
{
var message = JSON.parse(/** @type {string} */ (event.data));
this._dispatchFrontendAPIMessage(message["id"], message["method"], message["params"] || null);
},
/**
* @param {number} id
* @param {string} method
* @param {?Object} params
*/
_dispatchFrontendAPIMessage: function(id, method, params)
{
this._dispatchingFrontendMessage = true;
switch (method) {
case "Frontend.updateBuffer":
var file = params["file"];
var buffer = params["buffer"];
var save = params["save"];
var uiSourceCode = WebInspector.workspace.filesystemUISourceCode("file://" + file);
if (uiSourceCode) {
if (buffer !== uiSourceCode.workingCopy())
uiSourceCode.setWorkingCopy(buffer);
if (save && uiSourceCode.workingCopy())
uiSourceCode.commitWorkingCopy();
else if (uiSourceCode.workingCopy() === uiSourceCode.content())
uiSourceCode.resetWorkingCopy();
}
this._issueResponse(id);
break;
default:
WebInspector.console.log("Unhandled API message: " + method);
}
this._dispatchingFrontendMessage = false;
},
/**
* @param {!WebInspector.Event} event
*/
_workingCopyChanged: function(event)
{
if (this._dispatchingFrontendMessage)
return;
var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data["uiSourceCode"]);
var url = uiSourceCode.originURL();
if (url.startsWith("file://"))
url = url.substring(7);
this._issueFrontendAPINotification("Frontend.bufferUpdated", { file: url, buffer: uiSourceCode.workingCopy() });
},
/**
* @param {number} id
* @param {!Object=} params
*/
_issueResponse: function(id, params)
{
var object = {id: id};
if (params)
object.params = params;
InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify(object));
},
/**
* @param {string} method
* @param {?Object} params
*/
_issueFrontendAPINotification: function(method, params)
{
InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify({ method: method, params: params }));
}
}
...@@ -322,6 +322,7 @@ WebInspector.Main.prototype = { ...@@ -322,6 +322,7 @@ WebInspector.Main.prototype = {
console.timeStamp("Main._mainTargetCreated"); console.timeStamp("Main._mainTargetCreated");
this._mainTarget = /** @type {!WebInspector.Target} */(target); this._mainTarget = /** @type {!WebInspector.Target} */(target);
this._registerShortcuts(); this._registerShortcuts();
var main = this;
this._mainTarget.registerInspectorDispatcher(this); this._mainTarget.registerInspectorDispatcher(this);
InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ReloadInspectedPage, this._reloadInspectedPage, this); InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ReloadInspectedPage, this._reloadInspectedPage, this);
...@@ -344,7 +345,13 @@ WebInspector.Main.prototype = { ...@@ -344,7 +345,13 @@ WebInspector.Main.prototype = {
console.timeStamp("Main.inspectorAgentEnableCallback"); console.timeStamp("Main.inspectorAgentEnableCallback");
WebInspector.notifications.dispatchEventToListeners(WebInspector.NotificationService.Events.InspectorAgentEnabledForTests); WebInspector.notifications.dispatchEventToListeners(WebInspector.NotificationService.Events.InspectorAgentEnabledForTests);
// Asynchronously run the extensions. // Asynchronously run the extensions.
setTimeout(function() { WebInspector.extensionServer.initializeExtensions(); }, 0); setTimeout(lateInitialization, 0);
}
function lateInitialization()
{
WebInspector.extensionServer.initializeExtensions();
new WebInspector.FrontendWebSocketAPI();
} }
}, },
......
...@@ -308,6 +308,7 @@ ...@@ -308,6 +308,7 @@
"scripts": [ "scripts": [
"HelpScreenUntilReload.js", "HelpScreenUntilReload.js",
"AdvancedApp.js", "AdvancedApp.js",
"FrontendWebSocketAPI.js",
"RenderingOptions.js", "RenderingOptions.js",
"SimpleApp.js", "SimpleApp.js",
"TestController.js", "TestController.js",
......
...@@ -485,12 +485,14 @@ WebInspector.UISourceCode.prototype = { ...@@ -485,12 +485,14 @@ WebInspector.UISourceCode.prototype = {
this._workingCopy = newWorkingCopy; this._workingCopy = newWorkingCopy;
delete this._workingCopyGetter; delete this._workingCopyGetter;
this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyChanged); this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyChanged);
this._project.workspace().dispatchEventToListeners(WebInspector.Workspace.Events.UISourceCodeWorkingCopyChanged, { uiSourceCode: this });
}, },
setWorkingCopyGetter: function(workingCopyGetter) setWorkingCopyGetter: function(workingCopyGetter)
{ {
this._workingCopyGetter = workingCopyGetter; this._workingCopyGetter = workingCopyGetter;
this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyChanged); this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyChanged);
this._project.workspace().dispatchEventToListeners(WebInspector.Workspace.Events.UISourceCodeWorkingCopyChanged, { uiSourceCode: this });
}, },
removeWorkingCopyGetter: function() removeWorkingCopyGetter: function()
......
...@@ -574,6 +574,7 @@ WebInspector.Workspace.Events = { ...@@ -574,6 +574,7 @@ WebInspector.Workspace.Events = {
UISourceCodeAdded: "UISourceCodeAdded", UISourceCodeAdded: "UISourceCodeAdded",
UISourceCodeRemoved: "UISourceCodeRemoved", UISourceCodeRemoved: "UISourceCodeRemoved",
UISourceCodeContentCommitted: "UISourceCodeContentCommitted", UISourceCodeContentCommitted: "UISourceCodeContentCommitted",
UISourceCodeWorkingCopyChanged: "UISourceCodeWorkingCopyChanged",
ProjectAdded: "ProjectAdded", ProjectAdded: "ProjectAdded",
ProjectRemoved: "ProjectRemoved" ProjectRemoved: "ProjectRemoved"
} }
...@@ -629,6 +630,22 @@ WebInspector.Workspace.prototype = { ...@@ -629,6 +630,22 @@ WebInspector.Workspace.prototype = {
return null; return null;
}, },
/**
* @param {string} originURL
* @return {?WebInspector.UISourceCode}
*/
filesystemUISourceCode: function(originURL)
{
var projects = this.projectsForType(WebInspector.projectTypes.FileSystem);
for (var i = 0; i < projects.length; ++i) {
var project = projects[i];
var uiSourceCode = project.uiSourceCodeForOriginURL(originURL);
if (uiSourceCode)
return uiSourceCode;
}
return null;
},
/** /**
* @param {string} type * @param {string} type
* @return {!Array.<!WebInspector.UISourceCode>} * @return {!Array.<!WebInspector.UISourceCode>}
......
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