Skip to content

Commit aec1575

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[cleanup] Introduce UI.UIUtils.openInNewTab() helper.
This merges the logic for adding missing UTM parameters to links to Google owned documentation sets into a single helper which we use to open links that potentially contain documentation set references in a new Chrome tab. This way we reduce the chance of missing the `utm_source` or the `utm_campaign` parameters in the future. Fixed: 402611137 Change-Id: I1efc7ae90beb59dee12741470f8deae16e1c7fca Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6346913 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]> Auto-Submit: Benedikt Meurer <[email protected]>
1 parent e16f380 commit aec1575

File tree

16 files changed

+170
-160
lines changed

16 files changed

+170
-160
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {isAiAssistancePatchingEnabled} from './PatchWidget.js';
6060
const {html} = Lit;
6161

6262
const AI_ASSISTANCE_SEND_FEEDBACK = 'https://crbug.com/364805393' as Platform.DevToolsPath.UrlString;
63-
const AI_ASSISTANCE_HELP = 'https://goo.gle/devtools-ai-assistance' as Platform.DevToolsPath.UrlString;
63+
const AI_ASSISTANCE_HELP = 'https://developer.chrome.com/docs/devtools/ai-assistance';
6464
const SCREENSHOT_QUALITY = 100;
6565
const SHOW_LOADING_STATE_TIMEOUT = 100;
6666

@@ -857,7 +857,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
857857
onHistoryClick: this.#onHistoryClicked.bind(this),
858858
onDeleteClick: this.#onDeleteClicked.bind(this),
859859
onHelpClick: () => {
860-
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(AI_ASSISTANCE_HELP);
860+
UI.UIUtils.openInNewTab(AI_ASSISTANCE_HELP);
861861
},
862862
onSettingsClick: () => {
863863
void UI.ViewManager.ViewManager.instance().showView('chrome-ai');

front_end/panels/ai_assistance/components/UserActionRow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class UserActionRow extends UI.Widget.Widget implements UserActionRowWidg
302302
{
303303
onSuggestionClick: this.onSuggestionClick,
304304
onRatingClick: this.#handleRateClick.bind(this),
305-
onReportClick: () => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(REPORT_URL),
305+
onReportClick: () => UI.UIUtils.openInNewTab(REPORT_URL),
306306
scrollSuggestionsScrollContainer: this.#scrollSuggestionsScrollContainer.bind(this),
307307
onSuggestionsScrollOrResize: this.#handleSuggestionsScrollOrResize.bind(this),
308308
onSubmit: this.#handleSubmit.bind(this),

front_end/panels/common/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ export class FreDialog {
8282
</main>
8383
<footer>
8484
<devtools-button
85-
@click=${() => {
86-
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(learnMoreHref);
87-
}}
85+
@click=${() => UI.UIUtils.openInNewTab(learnMoreHref)}
8886
.jslogContext=${'fre-disclaimer.learn-more'}
8987
.variant=${Buttons.Button.Variant.OUTLINED}>
9088
${i18nString(UIStrings.learnMore)}

front_end/panels/elements/ElementStatePaneWidget.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import * as Common from '../../core/common/common.js';
55
import * as Host from '../../core/host/host.js';
66
import * as i18n from '../../core/i18n/i18n.js';
7-
import type * as Platform from '../../core/platform/platform.js';
87
import * as SDK from '../../core/sdk/sdk.js';
98
import * as Buttons from '../../ui/components/buttons/buttons.js';
109
import * as UI from '../../ui/legacy/legacy.js';
@@ -147,8 +146,8 @@ export class ElementStatePaneWidget extends UI.Widget.Widget {
147146
};
148147
learnMoreButton.addEventListener(
149148
'click',
150-
() => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
151-
'https://goo.gle/devtools-emulate-focused-page' as Platform.DevToolsPath.UrlString));
149+
() => UI.UIUtils.openInNewTab(
150+
'https://developer.chrome.com/docs/devtools/rendering/apply-effects#emulate_a_focused_page'));
152151

153152
div.appendChild(label);
154153
div.appendChild(learnMoreButton);

front_end/panels/settings/FrameworkIgnoreListSettingsTab.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import '../../ui/components/cards/cards.js';
66

77
import * as Common from '../../core/common/common.js';
8-
import * as Host from '../../core/host/host.js';
98
import * as i18n from '../../core/i18n/i18n.js';
10-
import type * as Platform from '../../core/platform/platform.js';
119
import * as Buttons from '../../ui/components/buttons/buttons.js';
1210
import * as UI from '../../ui/legacy/legacy.js';
1311
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
@@ -140,8 +138,8 @@ export class FrameworkIgnoreListSettingsTab extends UI.Widget.VBox implements
140138
};
141139
automaticallyIgnoreLinkButton.addEventListener(
142140
'click',
143-
() => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
144-
'http://goo.gle/skip-third-party' as Platform.DevToolsPath.UrlString));
141+
() => UI.UIUtils.openInNewTab(
142+
'https://developer.chrome.com/docs/devtools/settings/ignore-list/#skip-third-party'));
145143
automaticallyIgnoreList.appendChild(automaticallyIgnoreLinkButton);
146144

147145
const ignoreListAnonymousScripts = generalExclusionGroup.createChild('div', 'ignore-list-option');

front_end/panels/settings/SettingsScreen.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import '../../ui/components/cards/cards.js';
3333
import * as Common from '../../core/common/common.js';
3434
import * as Host from '../../core/host/host.js';
3535
import * as i18n from '../../core/i18n/i18n.js';
36-
import type * as Platform from '../../core/platform/platform.js';
3736
import * as Root from '../../core/root/root.js';
3837
import * as Buttons from '../../ui/components/buttons/buttons.js';
3938
import type * as Cards from '../../ui/components/cards/cards.js';
@@ -504,8 +503,7 @@ export class ExperimentsSettingsTab extends SettingsTab {
504503
jslogContext: `${experiment.name}-documentation`,
505504
title: i18nString(UIStrings.learnMore),
506505
};
507-
linkButton.addEventListener(
508-
'click', () => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(experimentLink));
506+
linkButton.addEventListener('click', () => UI.UIUtils.openInNewTab(experimentLink));
509507
linkButton.classList.add('link-icon');
510508

511509
p.appendChild(linkButton);
@@ -555,8 +553,7 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
555553
void SettingsScreen.showSettingsScreen({focusTabHeader: true} as ShowSettingsScreenOptions);
556554
return true;
557555
case 'settings.documentation':
558-
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(UI.UIUtils.addUTMParametersToURL(
559-
'https://developer.chrome.com/docs/devtools/' as Platform.DevToolsPath.UrlString));
556+
UI.UIUtils.openInNewTab('https://developer.chrome.com/docs/devtools/');
560557
return true;
561558
case 'settings.shortcuts':
562559
void SettingsScreen.showSettingsScreen({name: 'keybinds', focusTabHeader: true});

front_end/panels/timeline/components/MetricCard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import * as Host from '../../../core/host/host.js';
65
import * as i18n from '../../../core/i18n/i18n.js';
76
import * as Platform from '../../../core/platform/platform.js';
87
import * as CrUXManager from '../../../models/crux-manager/crux-manager.js';
98
import type * as Trace from '../../../models/trace/trace.js';
109
import * as Buttons from '../../../ui/components/buttons/buttons.js';
1110
import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js';
11+
import * as UI from '../../../ui/legacy/legacy.js';
1212
import * as Lit from '../../../ui/lit/lit.js';
1313

1414
import metricCardStylesRaw from './metricCard.css.js';
@@ -629,7 +629,7 @@ export class MetricCard extends HTMLElement {
629629
title=${this.#getHelpTooltip()}
630630
.iconName=${'help'}
631631
.variant=${Buttons.Button.Variant.ICON}
632-
@click=${() => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(helpLink)}
632+
@click=${() => UI.UIUtils.openInNewTab(helpLink)}
633633
></devtools-button>
634634
</h3>
635635
<div tabindex="0" class="metric-values-section"

front_end/panels/whats_new/ReleaseNoteView.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describeWithEnvironment('Release Note View', () => {
123123
button.click();
124124
assert.strictEqual(openInNewTabStub.callCount, 1);
125125
assert.isTrue(
126-
openInNewTabStub.firstCall.calledWith(urlString`https://google.com`),
126+
openInNewTabStub.firstCall.calledWith(urlString`https://google.com/`),
127127
'openInNewTab was not called with the expected URL.');
128128
});
129129

front_end/panels/whats_new/ReleaseNoteView.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import * as Host from '../../core/host/host.js';
65
import * as i18n from '../../core/i18n/i18n.js';
76
import type * as Platform from '../../core/platform/platform.js';
87
import * as Marked from '../../third_party/marked/marked.js';
@@ -78,7 +77,7 @@ export class ReleaseNoteView extends UI.Widget.VBox {
7877
<devtools-button
7978
.variant=${Buttons.Button.Variant.PRIMARY}
8079
.jslogContext=${'learn-more'}
81-
@click=${() => input.openNewTab(UI.UIUtils.addUTMParametersToURLIfNecessary(releaseNote.link as Platform.DevToolsPath.UrlString))}
80+
@click=${() => input.openNewTab(releaseNote.link)}
8281
>${i18nString(UIStrings.seeFeatures)}</devtools-button>
8382
</div>
8483
@@ -87,7 +86,7 @@ export class ReleaseNoteView extends UI.Widget.VBox {
8786
${releaseNote.videoLinks.map((value: {description: string, link: Platform.DevToolsPath.UrlString, type?: VideoType}) => {
8887
return html`
8988
<x-link
90-
href=${UI.UIUtils.addUTMParametersToURLIfNecessary(value.link)}
89+
href=${value.link}
9190
jslog=${VisualLogging.link().track({click: true}).context('learn-more')}>
9291
<div class="video">
9392
<img class="thumbnail" src=${input.getThumbnailPath(value.type ?? VideoType.WHATS_NEW)}>
@@ -128,7 +127,7 @@ export class ReleaseNoteView extends UI.Widget.VBox {
128127
this.#view(
129128
{
130129
getReleaseNote,
131-
openNewTab: this.#openNewTab,
130+
openNewTab: UI.UIUtils.openInNewTab,
132131
markdownContent,
133132
getThumbnailPath: this.#getThumbnailPath,
134133
},
@@ -150,8 +149,4 @@ export class ReleaseNoteView extends UI.Widget.VBox {
150149
}
151150
return new URL(img, import.meta.url).toString() as Platform.DevToolsPath.UrlString;
152151
}
153-
154-
#openNewTab(link: string): void {
155-
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(link as Platform.DevToolsPath.UrlString);
156-
}
157152
}

front_end/panels/whats_new/WhatsNewImpl.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as Common from '../../core/common/common.js';
66
import * as Host from '../../core/host/host.js';
7-
import type * as Platform from '../../core/platform/platform.js';
87
import * as UI from '../../ui/legacy/legacy.js';
98

109
import {getReleaseNote} from './ReleaseNoteText.js';
@@ -70,8 +69,7 @@ let releaseNotesActionDelegateInstance: ReleaseNotesActionDelegate;
7069
export class ReleaseNotesActionDelegate implements UI.ActionRegistration.ActionDelegate {
7170
handleAction(_context: UI.Context.Context, _actionId: string): boolean {
7271
const releaseNote = getReleaseNote();
73-
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
74-
releaseNote.link as Platform.DevToolsPath.UrlString);
72+
UI.UIUtils.openInNewTab(releaseNote.link);
7573
return true;
7674
}
7775
static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReleaseNotesActionDelegate {
@@ -87,8 +85,7 @@ export class ReleaseNotesActionDelegate implements UI.ActionRegistration.ActionD
8785
let reportIssueActionDelegateInstance: ReportIssueActionDelegate;
8886
export class ReportIssueActionDelegate implements UI.ActionRegistration.ActionDelegate {
8987
handleAction(_context: UI.Context.Context, _actionId: string): boolean {
90-
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
91-
'https://goo.gle/devtools-bug' as Platform.DevToolsPath.UrlString);
88+
UI.UIUtils.openInNewTab('https://goo.gle/devtools-bug');
9289
return true;
9390
}
9491
static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReportIssueActionDelegate {

0 commit comments

Comments
 (0)