Commit a332bbea authored by Tim van der Lippe's avatar Tim van der Lippe Committed by Commit Bot

Migrate extensions/ to ESM

Bug: 1006759
Change-Id: I55ff55840cbf00a108cb0f3630cf5b489bf3aac2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849386Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704574}
parent ca0e3774
......@@ -259,11 +259,6 @@ if (!external_devtools_frontend) {
"front_end/event_listeners/eventListenersView.css",
"front_end/event_listeners/EventListenersView.js",
"front_end/event_listeners/module.json",
"front_end/extensions/ExtensionAPI.js",
"front_end/extensions/ExtensionPanel.js",
"front_end/extensions/ExtensionServer.js",
"front_end/extensions/ExtensionTraceProvider.js",
"front_end/extensions/ExtensionView.js",
"front_end/extensions/module.json",
"front_end/extensions_test_runner/ExtensionsNetworkTestRunner.js",
"front_end/extensions_test_runner/ExtensionsTestRunner.js",
......@@ -820,6 +815,12 @@ if (!external_devtools_frontend) {
all_devtools_files += lighthouse_locale_files
all_devtools_modules = [
"front_end/extensions/extensions.js",
"front_end/extensions/ExtensionAPI.js",
"front_end/extensions/ExtensionPanel.js",
"front_end/extensions/ExtensionServer.js",
"front_end/extensions/ExtensionTraceProvider.js",
"front_end/extensions/ExtensionView.js",
"front_end/browser_sdk/browser_sdk.js",
"front_end/browser_sdk/LogManager.js",
"front_end/persistence/persistence.js",
......@@ -1210,6 +1211,12 @@ if (!external_devtools_frontend) {
]
copied_devtools_modules = [
"$resources_out_dir/extensions/extensions.js",
"$resources_out_dir/extensions/ExtensionAPI.js",
"$resources_out_dir/extensions/ExtensionPanel.js",
"$resources_out_dir/extensions/ExtensionServer.js",
"$resources_out_dir/extensions/ExtensionTraceProvider.js",
"$resources_out_dir/extensions/ExtensionView.js",
"$resources_out_dir/browser_sdk/browser_sdk.js",
"$resources_out_dir/browser_sdk/LogManager.js",
"$resources_out_dir/persistence/persistence.js",
......
......@@ -28,8 +28,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* eslint-disable indent */
function defineCommonExtensionSymbols(apiPrivate) {
if (!apiPrivate.panels) {
apiPrivate.panels = {};
......@@ -95,7 +93,8 @@ function defineCommonExtensionSymbols(apiPrivate) {
* @param {function(!Object, !Object)} testHook
* @suppressGlobalPropertiesCheck
*/
function injectedExtensionAPI(extensionInfo, inspectedTabId, themeName, keysToForward, testHook, injectedScriptId) {
self.injectedExtensionAPI = function(
extensionInfo, inspectedTabId, themeName, keysToForward, testHook, injectedScriptId) {
const keysToForwardSet = new Set(keysToForward);
const chrome = window.chrome || {};
const devtools_descriptor = Object.getOwnPropertyDescriptor(chrome, 'devtools');
......@@ -827,7 +826,7 @@ function injectedExtensionAPI(extensionInfo, inspectedTabId, themeName, keysToFo
window.webInspector = coreAPI;
}
testHook(extensionServer, coreAPI);
}
};
/**
* @param {!ExtensionDescriptor} extensionInfo
......@@ -843,6 +842,15 @@ self.buildExtensionAPIInjectedScript = function(extensionInfo, inspectedTabId, t
testHook = () => {};
}
return '(function(injectedScriptId){ ' + defineCommonExtensionSymbols.toString() + ';' +
'(' + injectedExtensionAPI.toString() + ')(' + argumentsJSON + ',' + testHook + ', injectedScriptId);' +
'(' + self.injectedExtensionAPI.toString() + ')(' + argumentsJSON + ',' + testHook + ', injectedScriptId);' +
'})';
};
/* Legacy exported object */
self.Extensions = self.Extensions || {};
/* Legacy exported object */
Extensions = Extensions || {};
Extensions.extensionAPI = {};
defineCommonExtensionSymbols(Extensions.extensionAPI);
\ No newline at end of file
......@@ -31,7 +31,7 @@
* @implements {UI.Searchable}
* @unrestricted
*/
Extensions.ExtensionPanel = class extends UI.Panel {
export default class ExtensionPanel extends UI.Panel {
/**
* @param {!Extensions.ExtensionServer} server
* @param {string} panelName
......@@ -116,12 +116,12 @@ Extensions.ExtensionPanel = class extends UI.Panel {
supportsRegexSearch() {
return false;
}
};
}
/**
* @unrestricted
*/
Extensions.ExtensionButton = class {
export class ExtensionButton {
/**
* @param {!Extensions.ExtensionServer} server
* @param {string} id
......@@ -161,12 +161,12 @@ Extensions.ExtensionButton = class {
toolbarButton() {
return this._toolbarButton;
}
};
}
/**
* @unrestricted
*/
Extensions.ExtensionSidebarPane = class extends UI.SimpleView {
export class ExtensionSidebarPane extends UI.SimpleView {
/**
* @param {!Extensions.ExtensionServer} server
* @param {string} panelName
......@@ -296,4 +296,19 @@ Extensions.ExtensionSidebarPane = class extends UI.SimpleView {
callback();
});
}
};
}
/* Legacy exported object */
self.Extensions = self.Extensions || {};
/* Legacy exported object */
Extensions = Extensions || {};
/** @constructor */
Extensions.ExtensionPanel = ExtensionPanel;
/** @constructor */
Extensions.ExtensionButton = ExtensionButton;
/** @constructor */
Extensions.ExtensionSidebarPane = ExtensionSidebarPane;
\ No newline at end of file
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Extensions.ExtensionServer = class extends Common.Object {
export default class ExtensionServer extends Common.Object {
/**
* @suppressGlobalPropertiesCheck
*/
......@@ -46,7 +46,7 @@ Extensions.ExtensionServer = class extends Common.Object {
this._requests = {};
this._lastRequestId = 0;
this._registeredExtensions = {};
this._status = new Extensions.ExtensionStatus();
this._status = new ExtensionStatus();
/** @type {!Array<!Extensions.ExtensionSidebarPane>} */
this._sidebarPanes = [];
/** @type {!Array<!Extensions.ExtensionTraceProvider>} */
......@@ -263,7 +263,7 @@ Extensions.ExtensionServer = class extends Common.Object {
const page = this._expandResourcePath(port._extensionOrigin, message.page);
let persistentId = port._extensionOrigin + message.title;
persistentId = persistentId.replace(/\s/g, '');
const panelView = new Extensions.ExtensionServerPanelView(
const panelView = new ExtensionServerPanelView(
persistentId, message.title, new Extensions.ExtensionPanel(this, persistentId, id, page));
this._clientObjects[id] = panelView;
UI.inspectorView.addPanel(panelView);
......@@ -273,7 +273,7 @@ Extensions.ExtensionServer = class extends Common.Object {
_onShowPanel(message) {
let panelViewId = message.id;
const panelView = this._clientObjects[message.id];
if (panelView && panelView instanceof Extensions.ExtensionServerPanelView) {
if (panelView && panelView instanceof ExtensionServerPanelView) {
panelViewId = panelView.viewId();
}
UI.inspectorView.showPanel(panelViewId);
......@@ -281,7 +281,7 @@ Extensions.ExtensionServer = class extends Common.Object {
_onCreateToolbarButton(message, port) {
const panelView = this._clientObjects[message.panel];
if (!panelView || !(panelView instanceof Extensions.ExtensionServerPanelView)) {
if (!panelView || !(panelView instanceof ExtensionServerPanelView)) {
return this._status.E_NOTFOUND(message.panel);
}
const button = new Extensions.ExtensionButton(
......@@ -330,7 +330,7 @@ Extensions.ExtensionServer = class extends Common.Object {
const sidebar = new Extensions.ExtensionSidebarPane(this, message.panel, message.title, id);
this._sidebarPanes.push(sidebar);
this._clientObjects[id] = sidebar;
this.dispatchEventToListeners(Extensions.ExtensionServer.Events.SidebarPaneAdded, sidebar);
this.dispatchEventToListeners(Events.SidebarPaneAdded, sidebar);
return this._status.OK();
}
......@@ -358,7 +358,7 @@ Extensions.ExtensionServer = class extends Common.Object {
}
/**
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function callback(error) {
const result = error ? this._status.E_FAILED(error) : this._status.OK();
......@@ -432,7 +432,7 @@ Extensions.ExtensionServer = class extends Common.Object {
* @param {?Protocol.Error} error
* @param {?SDK.RemoteObject} object
* @param {boolean} wasThrown
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function callback(error, object, wasThrown) {
let result;
......@@ -474,7 +474,7 @@ Extensions.ExtensionServer = class extends Common.Object {
const resources = new Map();
/**
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function pushResourceData(contentProvider) {
if (!resources.has(contentProvider.contentURL())) {
......@@ -522,7 +522,7 @@ Extensions.ExtensionServer = class extends Common.Object {
_onSetResourceContent(message, port) {
/**
* @param {?Protocol.Error} error
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function callbackWrapper(error) {
const response = error ? this._status.E_FAILED(error) : this._status.OK();
......@@ -566,7 +566,7 @@ Extensions.ExtensionServer = class extends Common.Object {
port._extensionOrigin, message.id, message.categoryName, message.categoryTooltip);
this._clientObjects[message.id] = provider;
this._traceProviders.push(provider);
this.dispatchEventToListeners(Extensions.ExtensionServer.Events.TraceProviderAdded, provider);
this.dispatchEventToListeners(Events.TraceProviderAdded, provider);
}
/**
......@@ -627,14 +627,14 @@ Extensions.ExtensionServer = class extends Common.Object {
SDK.NetworkManager.Events.RequestFinished, this._notifyRequestFinished);
/**
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function onElementsSubscriptionStarted() {
UI.context.addFlavorChangeListener(SDK.DOMNode, this._notifyElementsSelectionChanged, this);
}
/**
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function onElementsSubscriptionStopped() {
UI.context.removeFlavorChangeListener(SDK.DOMNode, this._notifyElementsSelectionChanged, this);
......@@ -709,9 +709,8 @@ Extensions.ExtensionServer = class extends Common.Object {
const extensionOrigin = originMatch[1];
if (!this._registeredExtensions[extensionOrigin]) {
// See ExtensionAPI.js for details.
const injectedAPI = buildExtensionAPIInjectedScript(
extensionInfo, this._inspectedTabId, UI.themeSupport.themeName(),
UI.shortcutRegistry.globalShortcutKeys(),
const injectedAPI = self.buildExtensionAPIInjectedScript(
extensionInfo, this._inspectedTabId, UI.themeSupport.themeName(), UI.shortcutRegistry.globalShortcutKeys(),
Extensions.extensionServer['_extensionAPITestHook']);
Host.InspectorFrontendHost.setInjectedScriptForOrigin(extensionOrigin, injectedAPI);
this._registeredExtensions[extensionOrigin] = {name: name};
......@@ -798,7 +797,7 @@ Extensions.ExtensionServer = class extends Common.Object {
_registerResourceContentCommittedHandler(handler) {
/**
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function addFirstEventListener() {
Workspace.workspace.addEventListener(Workspace.Workspace.Events.WorkingCopyCommittedByUser, handler, this);
......@@ -806,7 +805,7 @@ Extensions.ExtensionServer = class extends Common.Object {
}
/**
* @this {Extensions.ExtensionServer}
* @this {ExtensionServer}
*/
function removeLastEventListener() {
Workspace.workspace.setHasResourceContentTrackingExtensions(false);
......@@ -947,10 +946,10 @@ Extensions.ExtensionServer = class extends Common.Object {
callback(null, result.object || null, !!result.exceptionDetails);
}
}
};
}
/** @enum {symbol} */
Extensions.ExtensionServer.Events = {
export const Events = {
SidebarPaneAdded: Symbol('SidebarPaneAdded'),
TraceProviderAdded: Symbol('TraceProviderAdded')
};
......@@ -958,7 +957,7 @@ Extensions.ExtensionServer.Events = {
/**
* @unrestricted
*/
Extensions.ExtensionServerPanelView = class extends UI.SimpleView {
export class ExtensionServerPanelView extends UI.SimpleView {
/**
* @param {string} name
* @param {string} title
......@@ -985,12 +984,12 @@ Extensions.ExtensionServerPanelView = class extends UI.SimpleView {
widget() {
return /** @type {!Promise.<!UI.Widget>} */ (Promise.resolve(this._panel));
}
};
}
/**
* @unrestricted
*/
Extensions.ExtensionStatus = class {
export class ExtensionStatus {
constructor() {
/**
* @param {string} code
......@@ -1016,15 +1015,30 @@ Extensions.ExtensionStatus = class {
this.E_PROTOCOLERROR = makeStatus.bind(null, 'E_PROTOCOLERROR', 'Inspector protocol error: %s');
this.E_FAILED = makeStatus.bind(null, 'E_FAILED', 'Operation failed: %s');
}
};
}
/* Legacy exported object */
self.Extensions = self.Extensions || {};
/* Legacy exported object */
Extensions = Extensions || {};
/** @constructor */
Extensions.ExtensionServer = ExtensionServer;
/** @enum {symbol} */
Extensions.ExtensionServer.Events = Events;
/** @constructor */
Extensions.ExtensionServerPanelView = ExtensionServerPanelView;
/** @constructor */
Extensions.ExtensionStatus = ExtensionStatus;
/**
* @typedef {{code: string, description: string, details: !Array.<*>}}
*/
Extensions.ExtensionStatus.Record;
Extensions.extensionAPI = {};
defineCommonExtensionSymbols(Extensions.extensionAPI);
/** @type {!Extensions.ExtensionServer} */
/** @type {!ExtensionServer} */
Extensions.extensionServer;
......@@ -5,7 +5,7 @@
/**
* @unrestricted
*/
Extensions.ExtensionTraceProvider = class {
export default class ExtensionTraceProvider {
/**
* @param {string} extensionOrigin
* @param {string} id
......@@ -20,10 +20,10 @@ Extensions.ExtensionTraceProvider = class {
}
/**
* @param {!Extensions.TracingSession} session
* @param {!TracingSession} session
*/
start(session) {
const sessionId = String(++Extensions.ExtensionTraceProvider._lastSessionId);
const sessionId = String(++_lastSessionId);
Extensions.extensionServer.startTraceRecording(this._id, sessionId, session);
}
......@@ -51,19 +51,32 @@ Extensions.ExtensionTraceProvider = class {
persistentIdentifier() {
return `${this._extensionOrigin}/${this._categoryName}`;
}
};
}
Extensions.ExtensionTraceProvider._lastSessionId = 0;
export let _lastSessionId = 0;
/**
* @interface
*/
Extensions.TracingSession = function() {};
Extensions.TracingSession.prototype = {
export class TracingSession {
/**
* @param {string} url
* @param {number} timeOffsetMicroseconds
*/
complete: function(url, timeOffsetMicroseconds) {}
};
complete(url, timeOffsetMicroseconds) {
}
}
/* Legacy exported object */
self.Extensions = self.Extensions || {};
/* Legacy exported object */
Extensions = Extensions || {};
/** @constructor */
Extensions.ExtensionTraceProvider = ExtensionTraceProvider;
Extensions.ExtensionTraceProvider._lastSessionId = _lastSessionId;
/** @interface */
Extensions.TracingSession = TracingSession;
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Extensions.ExtensionView = class extends UI.Widget {
export default class ExtensionView extends UI.Widget {
/**
* @param {!Extensions.ExtensionServer} server
* @param {string} id
......@@ -84,12 +84,12 @@ Extensions.ExtensionView = class extends UI.Widget {
this._server.notifyViewShown(this._id, this._frameIndex);
}
}
};
}
/**
* @unrestricted
*/
Extensions.ExtensionNotifierView = class extends UI.VBox {
export class ExtensionNotifierView extends UI.VBox {
/**
* @param {!Extensions.ExtensionServer} server
* @param {string} id
......@@ -114,4 +114,16 @@ Extensions.ExtensionNotifierView = class extends UI.VBox {
willHide() {
this._server.notifyViewHidden(this._id);
}
};
}
/* Legacy exported object */
self.Extensions = self.Extensions || {};
/* Legacy exported object */
Extensions = Extensions || {};
/** @constructor */
Extensions.ExtensionView = ExtensionView;
/** @constructor */
Extensions.ExtensionNotifierView = ExtensionNotifierView;
\ No newline at end of file
// Copyright 2019 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.
import './ExtensionAPI.js';
import * as ExtensionPanel from './ExtensionPanel.js';
import * as ExtensionServer from './ExtensionServer.js';
import * as ExtensionTraceProvider from './ExtensionTraceProvider.js';
import * as ExtensionView from './ExtensionView.js';
export {
ExtensionPanel,
ExtensionServer,
ExtensionTraceProvider,
ExtensionView,
};
......@@ -4,7 +4,9 @@
"browser_sdk",
"common"
],
"scripts": [
"scripts": [],
"modules": [
"extensions.js",
"ExtensionAPI.js",
"ExtensionTraceProvider.js",
"ExtensionServer.js",
......
......@@ -16,4 +16,5 @@ import './workspace/workspace.js';
import './bindings/bindings.js';
import './components/components.js';
import './persistence/persistence.js';
import './browser_sdk/browser_sdk.js';
\ No newline at end of file
import './browser_sdk/browser_sdk.js';
import './extensions/extensions.js';
......@@ -42,7 +42,7 @@ def write_devtools_extension_api(output, input_names):
var tabId;
var extensionInfo = {};
var extensionServer;
platformExtensionAPI(injectedExtensionAPI("remote-" + window.parent.frames.length));
platformExtensionAPI(self.injectedExtensionAPI("remote-" + window.parent.frames.length));
})();""")
......
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