Skip to content

Commit 7bb6e09

Browse files
paulirishDevtools-frontend LUCI CQ
authored andcommitted
[DeepLink] Rename filter to shouldHandleOpenResource
Bug:427430112 Change-Id: I0d1fbf067daaf69fd5e31074a27698531973a0a1 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6758891 Reviewed-by: Finnur Thorarinsson <[email protected]> Auto-Submit: Paul Irish <[email protected]> Commit-Queue: Finnur Thorarinsson <[email protected]>
1 parent d7968a8 commit 7bb6e09

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

front_end/models/extensions/ExtensionServer.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describeWithDevtoolsExtension('Extensions', {}, context => {
194194
assert.strictEqual(registration.title, 'TestExtension');
195195
assert.isUndefined(registration.scheme);
196196
assert.isFunction(registration.handler);
197-
assert.isFunction(registration.filter);
197+
assert.isFunction(registration.shouldHandleOpenResource);
198198

199199
// Now unregister the extension.
200200
context.chrome.devtools?.panels.setOpenResourceHandler();
@@ -203,7 +203,7 @@ describeWithDevtoolsExtension('Extensions', {}, context => {
203203
assert.strictEqual(unregistration.title, 'TestExtension');
204204
assert.isUndefined(unregistration.scheme);
205205
assert.isFunction(unregistration.handler);
206-
assert.isFunction(unregistration.filter);
206+
assert.isFunction(unregistration.shouldHandleOpenResource);
207207
});
208208

209209
it('can register and unregister a scheme specific open resource handler', async () => {
@@ -216,7 +216,7 @@ describeWithDevtoolsExtension('Extensions', {}, context => {
216216
assert.strictEqual(registration.title, 'TestExtension');
217217
assert.strictEqual(registration.scheme, 'foo-extension:');
218218
assert.isFunction(registration.handler);
219-
assert.isFunction(registration.filter);
219+
assert.isFunction(registration.shouldHandleOpenResource);
220220

221221
// Now unregister the extension.
222222
context.chrome.devtools?.panels.setOpenResourceHandler();
@@ -225,7 +225,7 @@ describeWithDevtoolsExtension('Extensions', {}, context => {
225225
assert.strictEqual(unregistration.title, 'TestExtension');
226226
assert.isUndefined(unregistration.scheme);
227227
assert.isFunction(unregistration.handler);
228-
assert.isFunction(unregistration.filter);
228+
assert.isFunction(unregistration.shouldHandleOpenResource);
229229
});
230230
});
231231

front_end/models/extensions/ExtensionServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ export class ExtensionServer extends Common.ObjectWrapper.ObjectWrapper<EventTyp
832832
origin: extensionOrigin,
833833
scheme: message.urlScheme,
834834
handler: this.handleOpenURL.bind(this, port),
835-
filter: (url: Platform.DevToolsPath.UrlString, schemes: Set<string>) =>
835+
shouldHandleOpenResource: (url: Platform.DevToolsPath.UrlString, schemes: Set<string>) =>
836836
Components.Linkifier.Linkifier.shouldHandleOpenResource(extension.openResourceScheme, url, schemes),
837837
};
838838
if (message.handlerPresent) {

front_end/ui/legacy/components/utils/Linkifier.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ describeWithMockConnection('Linkifier', () => {
412412
origin: urlString`foo-extension:abcdefghijklmnop`,
413413
scheme: urlString`foo-extension:`,
414414
handler,
415-
filter: (url, schemes) =>
415+
shouldHandleOpenResource: (url, schemes) =>
416416
Components.Linkifier.Linkifier.shouldHandleOpenResource(urlString`foo-extension:`, url, schemes),
417417
});
418418

@@ -442,7 +442,8 @@ describeWithMockConnection('Linkifier', () => {
442442
origin: urlString`global:abcdefghijklmnop`,
443443
scheme: undefined,
444444
handler: () => {},
445-
filter: (url, schemes) => Components.Linkifier.Linkifier.shouldHandleOpenResource(null, url, schemes),
445+
shouldHandleOpenResource: (url, schemes) =>
446+
Components.Linkifier.Linkifier.shouldHandleOpenResource(null, url, schemes),
446447
});
447448

448449
// Register a scheme-specific handler for the foo-extension: origin.
@@ -451,7 +452,7 @@ describeWithMockConnection('Linkifier', () => {
451452
origin: urlString`foo-extension:abcdefghijklmnop`,
452453
scheme: urlString`foo-extension:`,
453454
handler: () => {},
454-
filter: (url, schemes) =>
455+
shouldHandleOpenResource: (url, schemes) =>
455456
Components.Linkifier.Linkifier.shouldHandleOpenResource(urlString`foo-extension:`, url, schemes),
456457
});
457458

front_end/ui/legacy/components/utils/Linkifier.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -798,20 +798,20 @@ export class Linkifier extends Common.ObjectWrapper.ObjectWrapper<EventTypes> im
798798
// does not match. If no openResourceScheme is provided, it means the handler is
799799
// interested in all urls (except those handled by scheme-specific handlers, see
800800
// otherSchemeRegistrations).
801-
static shouldHandleOpenResource =
802-
(openResourceScheme: string|null, url: Platform.DevToolsPath.UrlString, otherSchemeRegistrations: Set<string>):
803-
boolean => {
804-
// If this is a scheme-specific handler, make sure the registered scheme is
805-
// present in the url.
806-
if (openResourceScheme) {
807-
return url.startsWith(openResourceScheme);
808-
}
809-
810-
// Global handlers (that register for no scheme) can handle all urls, with the
811-
// exception of urls that scheme-specific handlers have registered for.
812-
const scheme = URL.parse(url)?.protocol || '';
813-
return !otherSchemeRegistrations.has(scheme);
814-
};
801+
static shouldHandleOpenResource(
802+
openResourceScheme: string|null, url: Platform.DevToolsPath.UrlString,
803+
otherSchemeRegistrations: Set<string>): boolean {
804+
// If this is a scheme-specific handler, make sure the registered scheme is
805+
// present in the url.
806+
if (openResourceScheme) {
807+
return url.startsWith(openResourceScheme);
808+
}
809+
810+
// Global handlers (that register for no scheme) can handle all urls, with the
811+
// exception of urls that scheme-specific handlers have registered for.
812+
const scheme = URL.parse(url)?.protocol || '';
813+
return !otherSchemeRegistrations.has(scheme);
814+
}
815815

816816
static uiLocation(link: Element): Workspace.UISourceCode.UILocation|null {
817817
const info = Linkifier.linkInfo(link);
@@ -874,11 +874,8 @@ export class Linkifier extends Common.ObjectWrapper.ObjectWrapper<EventTypes> im
874874
}
875875
}
876876

877-
for (const registration of linkHandlers.values()) {
878-
if (!registration?.handler) {
879-
continue;
880-
}
881-
const {title, handler, filter: shouldHandleOpenResource} = registration;
877+
for (const registration of linkHandlers.values().filter(r => r.handler)) {
878+
const {title, handler, shouldHandleOpenResource} = registration;
882879
if (url && !shouldHandleOpenResource(url, specificSchemeHandlers)) {
883880
continue;
884881
}
@@ -1172,7 +1169,7 @@ export interface LinkHandlerRegistration {
11721169
// The openResourceHandler handling the requests to open a resource.
11731170
handler: LinkHandler;
11741171
// A filter function used to determine whether the `handler` wants to handle the link clicks.
1175-
filter: LinkHandlerPredicate;
1172+
shouldHandleOpenResource: LinkHandlerPredicate;
11761173
}
11771174

11781175
export const enum Events {

0 commit comments

Comments
 (0)