Files
react-native-devtools-frontend/front_end/text_utils/StaticContentProvider.js
T
Tim van der Lippe 18f0489a60 Reland: Move ContentProvider.js and StaticContentProvider.js to text_utils.
They used to live under common.

This is to avoid the dependency from common to text_utils caused by
the method performSearchInContent.

Layout tests were disabled:
https://chromium-review.googlesource.com/c/chromium/src/+/2096995

CL to fix and re enable tests
https://chromium-review.googlesource.com/c/chromium/src/+/2096018/


Bug: 1011811
Change-Id: I76415076366d748ed0b4fe6ff32c73bae0db1312
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2097337
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-03-17 12:12:17 +00:00

81 lines
2.1 KiB
JavaScript

// 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 * as Common from '../common/common.js'; // eslint-disable-line no-unused-vars
import {ContentProvider, DeferredContent, SearchMatch} from './ContentProvider.js'; // eslint-disable-line no-unused-vars
import {performSearchInContent} from './TextUtils.js';
/**
* @implements {ContentProvider}
* @unrestricted
*/
export class StaticContentProvider {
/**
* @param {string} contentURL
* @param {!Common.ResourceType.ResourceType} contentType
* @param {function():!Promise<!DeferredContent>} lazyContent
*/
constructor(contentURL, contentType, lazyContent) {
this._contentURL = contentURL;
this._contentType = contentType;
this._lazyContent = lazyContent;
}
/**
* @param {string} contentURL
* @param {!Common.ResourceType.ResourceType} contentType
* @param {string} content
* @return {!StaticContentProvider}
*/
static fromString(contentURL, contentType, content) {
const lazyContent = () => Promise.resolve({content, isEncoded: false});
return new StaticContentProvider(contentURL, contentType, lazyContent);
}
/**
* @override
* @return {string}
*/
contentURL() {
return this._contentURL;
}
/**
* @override
* @return {!Common.ResourceType.ResourceType}
*/
contentType() {
return this._contentType;
}
/**
* @override
* @return {!Promise<boolean>}
*/
contentEncoded() {
return Promise.resolve(false);
}
/**
* @override
* @return {!Promise<!DeferredContent>}
*/
requestContent() {
return this._lazyContent();
}
/**
* @override
* @param {string} query
* @param {boolean} caseSensitive
* @param {boolean} isRegex
* @return {!Promise<!Array<!SearchMatch>>}
*/
async searchInContent(query, caseSensitive, isRegex) {
const {content} = /** @type { {content: string, isEncoded: boolean} }*/ (await this._lazyContent());
return content ? performSearchInContent(content, query, caseSensitive, isRegex) : [];
}
}