mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
Bug: 1299773 Change-Id: I377daea5d94e73326e77e56bbd8b94bad2c86b58 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3468517 Reviewed-by: Simon Zünd <szuend@chromium.org> Reviewed-by: Eric Leese <leese@chromium.org> Commit-Queue: Kateryna Prokopenko <kprokopenko@chromium.org>
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
// Copyright 2014 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 type * as Common from '../../core/common/common.js';
|
|
import type * as Platform from '../../core/platform/platform.js';
|
|
|
|
import type {ContentProvider, DeferredContent, SearchMatch} from './ContentProvider.js';
|
|
import {performSearchInContent} from './TextUtils.js';
|
|
|
|
export class StaticContentProvider implements ContentProvider {
|
|
private readonly contentURLInternal: Platform.DevToolsPath.UrlString;
|
|
private readonly contentTypeInternal: Common.ResourceType.ResourceType;
|
|
private readonly lazyContent: () => Promise<DeferredContent>;
|
|
|
|
constructor(
|
|
contentURL: Platform.DevToolsPath.UrlString, contentType: Common.ResourceType.ResourceType,
|
|
lazyContent: () => Promise<DeferredContent>) {
|
|
this.contentURLInternal = contentURL;
|
|
this.contentTypeInternal = contentType;
|
|
this.lazyContent = lazyContent;
|
|
}
|
|
|
|
static fromString(
|
|
contentURL: Platform.DevToolsPath.UrlString, contentType: Common.ResourceType.ResourceType,
|
|
content: string): StaticContentProvider {
|
|
const lazyContent = (): Promise<{
|
|
content: string,
|
|
isEncoded: boolean,
|
|
}> => Promise.resolve({content, isEncoded: false});
|
|
return new StaticContentProvider(contentURL, contentType, lazyContent);
|
|
}
|
|
|
|
contentURL(): Platform.DevToolsPath.UrlString {
|
|
return this.contentURLInternal;
|
|
}
|
|
|
|
contentType(): Common.ResourceType.ResourceType {
|
|
return this.contentTypeInternal;
|
|
}
|
|
|
|
contentEncoded(): Promise<boolean> {
|
|
return Promise.resolve(false);
|
|
}
|
|
|
|
requestContent(): Promise<DeferredContent> {
|
|
return this.lazyContent();
|
|
}
|
|
|
|
async searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<SearchMatch[]> {
|
|
const {content} = (await this.lazyContent() as {
|
|
content: string,
|
|
isEncoded: boolean,
|
|
});
|
|
return content ? performSearchInContent(content, query, caseSensitive, isRegex) : [];
|
|
}
|
|
}
|