mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-09 05:08:28 +08:00
- Migrate sources to use Localization V2 APIs. - Removed sources grdps Tested with en-XL.json https://imgur.com/a/vDrfTAv Bug: 1136655 Change-Id: I01d4fcdc3f115e9edb3fae933c7d5c6b9ffb77c0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2692743 Commit-Queue: Vidal Diazleal <vidorteg@microsoft.com> Reviewed-by: Peter Marshall <petermarshall@chromium.org>
101 lines
3.6 KiB
JavaScript
101 lines
3.6 KiB
JavaScript
// Copyright 2018 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 * as Bindings from '../bindings/bindings.js';
|
|
import * as Components from '../components/components.js';
|
|
import * as i18n from '../i18n/i18n.js';
|
|
import * as SDK from '../sdk/sdk.js'; // eslint-disable-line no-unused-vars
|
|
import * as SourceFrame from '../source_frame/source_frame.js'; // eslint-disable-line no-unused-vars
|
|
import * as UI from '../ui/ui.js';
|
|
import * as Workspace from '../workspace/workspace.js'; // eslint-disable-line no-unused-vars
|
|
|
|
import {Plugin} from './Plugin.js';
|
|
|
|
export const UIStrings = {
|
|
/**
|
|
*@description Text in Script Origin Plugin of the Sources panel
|
|
*@example {example.com} PH1
|
|
*/
|
|
sourceMappedFromS: '(source mapped from {PH1})',
|
|
/**
|
|
*@description Text in Script Origin Plugin of the Sources panel
|
|
*@example {http://localhost/file.wasm} PH1
|
|
*/
|
|
providedViaDebugInfoByS: '(provided via debug info by {PH1})',
|
|
};
|
|
const str_ = i18n.i18n.registerUIStrings('sources/ScriptOriginPlugin.js', UIStrings);
|
|
|
|
export class ScriptOriginPlugin extends Plugin {
|
|
/**
|
|
* @param {!SourceFrame.SourcesTextEditor.SourcesTextEditor} textEditor
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
*/
|
|
constructor(textEditor, uiSourceCode) {
|
|
super();
|
|
this._textEditor = textEditor;
|
|
this._uiSourceCode = uiSourceCode;
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
* @return {boolean}
|
|
*/
|
|
static accepts(uiSourceCode) {
|
|
return uiSourceCode.contentType().hasScripts() || Boolean(ScriptOriginPlugin._script(uiSourceCode));
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @return {!Promise<!Array<!UI.Toolbar.ToolbarItem>>}
|
|
*/
|
|
async rightToolbarItems() {
|
|
const originURL = Bindings.CompilerScriptMapping.CompilerScriptMapping.uiSourceCodeOrigin(this._uiSourceCode);
|
|
if (originURL) {
|
|
const item = i18n.i18n.getFormatLocalizedString(
|
|
str_, UIStrings.sourceMappedFromS, {PH1: Components.Linkifier.Linkifier.linkifyURL(originURL)});
|
|
return [new UI.Toolbar.ToolbarItem(item)];
|
|
}
|
|
|
|
const pluginManager = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().pluginManager;
|
|
if (pluginManager) {
|
|
for (const originScript of pluginManager.scriptsForUISourceCode(this._uiSourceCode)) {
|
|
if (originScript.hasSourceURL) {
|
|
const item = i18n.i18n.getFormatLocalizedString(
|
|
str_, UIStrings.providedViaDebugInfoByS,
|
|
{PH1: Components.Linkifier.Linkifier.linkifyURL(originScript.sourceURL)});
|
|
return [new UI.Toolbar.ToolbarItem(item)];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle anonymous scripts with an originStackTrace.
|
|
const script = await ScriptOriginPlugin._script(this._uiSourceCode);
|
|
if (!script || !script.originStackTrace) {
|
|
return [];
|
|
}
|
|
const link = linkifier.linkifyStackTraceTopFrame(script.debuggerModel.target(), script.originStackTrace);
|
|
return [new UI.Toolbar.ToolbarItem(link)];
|
|
}
|
|
|
|
/**
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
* @return {!Promise<?SDK.Script.Script>}
|
|
*/
|
|
static async _script(uiSourceCode) {
|
|
const locations =
|
|
await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().uiLocationToRawLocations(
|
|
uiSourceCode, 0, 0);
|
|
for (const location of locations) {
|
|
const script = location.script();
|
|
if (script && script.originStackTrace) {
|
|
return script;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const linkifier = new Components.Linkifier.Linkifier();
|