Skip to content

Commit

Permalink
cmplete vfsmanager basic function (Tencent#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
eksea authored and sohotz committed May 14, 2024
1 parent 2f5642f commit 382feff
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 56 deletions.
38 changes: 35 additions & 3 deletions framework/ohos/src/main/ets/hippy_framework/HippyEngineImpl.ets
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ import { EngineInitParams,
ModuleLoadParams,
ModuleLoadStatus
} from '.';
import { DefaultProcessor } from '../vfs/DefaultProcessor'
import { DomManager } from './connector/DomManager';
import { FrameworkProxy } from '../renderer_native/FrameworkProxy';
import { JsDriver } from './connector/JsDriver';
import { NativeRenderer } from './connector/NativeRenderer';
import { VfsManager } from '../vfs/VfsManager';
import { NativeRenderContext } from '../renderer_native/NativeRenderContext';
import { NativeRenderProvider } from '../renderer_native/NativeRenderProvider';
import { PixelUtil } from '../support/utils/PixelUtil';
import { HippyLibrary } from '../hippy_library/HippyLibrary';
import { HippyException } from '../support/common/HippyException';
import { HippyResourceLoader } from './adapter/http/HippyResourceLoader';

export class HippyEngineImpl implements HippyEngine {
export class HippyEngineImpl implements HippyEngine, FrameworkProxy {
private libHippy: HippyLibrary
private resourceManager: resmgr.ResourceManager

public vfsManager: VfsManager | null = null
public vfsManager: VfsManager
public jsDriver: JsDriver | null = null
public domMgr: DomManager | null = null
public nativeRenderProvider: NativeRenderProvider | null = null
Expand All @@ -48,12 +52,15 @@ export class HippyEngineImpl implements HippyEngine {
constructor(params: EngineInitParams) {
this.libHippy = params.libHippy
this.resourceManager = params.context.resourceManager
this.vfsManager = new VfsManager(this.libHippy)
const resourceLoader = new HippyResourceLoader()
this.vfsManager.addProcessorAtFirst(new DefaultProcessor(resourceLoader))
}

initEngine(initCallbak: HippyEngineInitCallback): void {
this.vfsManager = new VfsManager(this.libHippy)
this.domMgr = new DomManager(this.libHippy)
this.nativeRenderProvider = new NativeRenderProvider(this.libHippy)
this.nativeRenderProvider.getNativeRenderImpl().setFrameworkProxy(this)
this.nativeRenderer = new NativeRenderer(this.libHippy, this.nativeRenderProvider)
this.nativeRenderer.attachToDom(this.domMgr.instanceId)
this.domMgr.attachToRenderer(this.nativeRenderer.instanceId)
Expand Down Expand Up @@ -95,6 +102,31 @@ export class HippyEngineImpl implements HippyEngine {
this.loadJsModule()
}

getVfsManager(): VfsManager {
return this.vfsManager;
}

getBundlePath(): string {
// TODO(eksea)
return "asset:/vue2";
}

getEngineId(): number {
return 0;
}

onFirstViewAdded(): void {
}

handleNativeException(exception: HippyException): void {
}

updateDimension(width: number, height: number, shouldUseScreenDisplay: boolean, systemUiVisibilityChanged: boolean): void {
}

onSizeChanged(rootId: number, w: number, h: number, ow: number, oh: number): void {
}

loadJsModule() {
if (!this.jsDriver || !this.vfsManager) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { HttpTaskCallbackImpl } from './HttpTaskCallbackImpl';
import Url from '@ohos.url'
import { TextUtils } from '../../../support/utils/TextUtils';
import { ResourceDataHolder } from 'ets/vfs/ResourceDataHolder';
import { ProcessorCallback } from './ProcessorCallback';
import { ProcessorCallback } from '../../../vfs/ProcessorCallback';
import { HippyExecutor, HippyTask } from '../../../support/common/HippyExecutor';
import connection from '@ohos.net.connection';
import { HippyException } from '../../../support/common/HippyException';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { HippyHttpRequest } from './HippyHttpRequest'
import HashMap from '@ohos.util.HashMap';
import { HippyHttpResponse } from './HippyHttpResponse';
import { BusinessError } from '@ohos.base';
import { ProcessorCallback } from './ProcessorCallback';
import { ProcessorCallback } from '../../../vfs/ProcessorCallback';
import { ResourceDataHolder } from '../../../vfs/ResourceDataHolder';
import { HippyException } from '../../../support/common/HippyException';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ResourceDataHolder } from 'ets/vfs/ResourceDataHolder';
import { ResourceDataHolder } from '../../../vfs/ResourceDataHolder';
import { ResourceLoader } from '../../../vfs/ResourceLoader';
import { ProcessorCallback } from './ProcessorCallback';
import { ProcessorCallback } from '../../../vfs/ProcessorCallback';
import { UrlUtils } from '../../../support/utils/UrlUtils';

export enum FetchResultCode {
OK,
Expand All @@ -29,13 +30,30 @@ export enum FetchResultCode {
}

export class HippyResourceLoader implements ResourceLoader {
private static readonly RAWFILE_PREFIX = "hpfile://";
private static readonly ASSETS_IMAGE_PREFIX = "assets://"

constructor() {
}

fetchResourceAsync(holder: ResourceDataHolder, callback: ProcessorCallback) {
holder.resource = holder.uri
callback.onHandleCompleted()
}

fetchResourceSync(holder: ResourceDataHolder): boolean {
if (UrlUtils.isWebUrl(holder.uri)) {
// TODO(eksea)
holder.resource = holder.uri
} else if (holder.uri.startsWith(HippyResourceLoader.RAWFILE_PREFIX)) {
let realUri = "vue2/assets/" + holder.uri.substring(HippyResourceLoader.RAWFILE_PREFIX.length)
holder.resource = $rawfile(realUri)
}
else if (holder.uri.startsWith(HippyResourceLoader.ASSETS_IMAGE_PREFIX)) {
holder.resource = $rawfile(holder.uri.substring(HippyResourceLoader.ASSETS_IMAGE_PREFIX.length))
} else {
holder.resource = holder.uri
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { HippyHttpAdapter, HttpTaskCallback } from './HippyHttpAdapter';
import { HippyHttpRequest } from './HippyHttpRequest';
import { HippyHttpResponse } from './HippyHttpResponse';
import { BusinessError } from '@ohos.base';
import { ProcessorCallback } from './ProcessorCallback';
import { ProcessorCallback } from '../../../vfs/ProcessorCallback';
import { ResourceDataHolder } from '../../../vfs/ResourceDataHolder';
import { FetchResultCode } from './HippyResourceLoader';
import { HippyException } from '../../../support/common/HippyException';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import { ImageDecoderAdapter } from './components/image/ImageDecoderAdapter';
import { FontAdapter } from './components/richtext/FontAdapter';

export interface FrameworkProxy {
getImageDecoderAdapter(): ImageDecoderAdapter
// TODO(eksea)
// getImageDecoderAdapter(): ImageDecoderAdapter

getFontAdapter(): FontAdapter
// TODO(eksea)
// getFontAdapter(): FontAdapter

getVfsManager(): VfsManager

getBackgroundExecutor(): HippyExecutor
// TODO(eksea)
// getBackgroundExecutor(): HippyExecutor

getBundlePath(): string

Expand Down
12 changes: 9 additions & 3 deletions framework/ohos/src/main/ets/renderer_native/NativeRender.ets
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { VfsManager } from '../vfs/VfsManager';
import { ImageDecoderAdapter } from './components/image/ImageDecoderAdapter';
import { ImageLoaderAdapter } from './components/image/ImageLoaderAdapter';
import { FontAdapter } from './components/richtext/FontAdapter';
import { FrameworkProxy } from './FrameworkProxy'
import { HRManager } from './uimanager/HRManager';

export interface NativeRender {
Expand All @@ -31,13 +32,16 @@ export interface NativeRender {

getImageLoader(): ImageLoaderAdapter | null

getImageDecoderAdapter(): ImageDecoderAdapter | null
// TODO(eksea)
// getImageDecoderAdapter(): ImageDecoderAdapter | null

getVfsManager(): VfsManager | null

getFontAdapter(): FontAdapter | null
// TODO(eksea)
// getFontAdapter(): FontAdapter | null

getBackgroundExecutor(): HippyExecutor | null
// TODO(eksea)
// getBackgroundExecutor(): HippyExecutor | null

getEngineId(): number

Expand All @@ -46,4 +50,6 @@ export interface NativeRender {
onSizeChanged2(rootId: number, nodeId: number, width: number, height: number, isSync: boolean): void

updateDimension(width: number, height: number, shouldUseScreenDisplay: boolean, systemUiVisibilityChanged: boolean): void

setFrameworkProxy(proxy: FrameworkProxy)
}
21 changes: 12 additions & 9 deletions framework/ohos/src/main/ets/renderer_native/NativeRenderImpl.ets
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,24 @@ export class NativeRenderImpl implements NativeRender {
return this.imageLoader
}

getImageDecoderAdapter(): ImageDecoderAdapter | null {
return this.frameworkProxy ? this.frameworkProxy.getImageDecoderAdapter() : null
}
// TODO(eksea)
// getImageDecoderAdapter(): ImageDecoderAdapter | null {
// return this.frameworkProxy ? this.frameworkProxy.getImageDecoderAdapter() : null
// }

getVfsManager(): VfsManager | null {
return this.frameworkProxy ? this.frameworkProxy.getVfsManager() : null
}

getFontAdapter(): FontAdapter | null {
return this.frameworkProxy ? this.frameworkProxy.getFontAdapter() : null
}
// TODO(eksea)
// getFontAdapter(): FontAdapter | null {
// return this.frameworkProxy ? this.frameworkProxy.getFontAdapter() : null
// }

getBackgroundExecutor(): HippyExecutor | null {
return this.frameworkProxy ? this.frameworkProxy.getBackgroundExecutor() : null
}
// TODO(eksea)
// getBackgroundExecutor(): HippyExecutor | null {
// return this.frameworkProxy ? this.frameworkProxy.getBackgroundExecutor() : null
// }

getEngineId(): number {
return this.frameworkProxy ? this.frameworkProxy.getEngineId() : -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { HippyAny, HippyRecord, HippyRenderCallback } from '../../../support/common/HippyTypes';
import { HippyAny, HippyRecord, HippyRenderCallback,
HippyResource } from '../../../support/common/HippyTypes';
import { HRNodeProps } from '../../dom_node/HRNodeProps';
import { NativeRenderContext } from '../../NativeRenderContext';
import { HRConvertUtil } from '../../utils/HRConvertUtil';
import HippyRenderBaseView from '../base/HippyRenderBaseView';
import { LogUtils } from '../../../support/utils/LogUtils';
import { ResourceDataHolder } from '../../../vfs/ResourceDataHolder';

interface ImageLoadEvent {
width: number
Expand Down Expand Up @@ -178,19 +180,14 @@ export class HRImageView extends HippyRenderBaseView {
}
}

getImage() {
console.log(`hrimageview getImage`)
if (this.cssSrc?.startsWith(HRImageView.BASE64_IMAGE_PREFIX)) {
return this.cssSrc
} else if (this.cssSrc?.startsWith(HRImageView.RAW_IMAGE_PREFIX)){
let splitList = this.cssSrc.split("/")
this.cssSrc = "vue2/assets/" + splitList[splitList.length - 1]
LogUtils.d(this.TAG, "hrimageview getImage: cssSrc= " + this.cssSrc)
this.cssAlt = this.cssSrc
return $rawfile(this.cssSrc)
getImage(): HippyResource {
let imageLoader = this.ctx.getNativeRender()!.getImageLoader()!
if (this.cssSrc) {
return imageLoader.fetchImageSync(this.cssSrc)
}
return this.cssSrc
return ""
}

}

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { HippyResource } from '../../../support/common/HippyTypes';
import { VfsManager } from '../../../vfs/VfsManager';
import { ImageLoaderAdapter } from './ImageLoaderAdapter';

Expand All @@ -33,4 +34,9 @@ export class ImageLoader implements ImageLoaderAdapter {

}

fetchImageSync(url: string) : HippyResource {
let dataHolder = this.vfsManager!.fetchResourceSync(url, undefined, undefined)
return dataHolder.resource
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { HippyResource } from '../../../support/common/HippyTypes'

export interface ImageLoaderAdapter {
fetchImageAsync(url: string): void

fetchImageSync(url: string): HippyResource
}
2 changes: 2 additions & 0 deletions framework/ohos/src/main/ets/support/common/HippyTypes.ets
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export type HippyAny = HippyValue | HippyMap | Hippy2Map | Hippy3Map | HippyReco
export type HippyRenderCallback = (result: HippyAny) => void
export type HippyModuleCallback = (result: HippyAny) => void
export type HippyTouchParamType = Record<string, HippyValue | HippyRecord[]>
export type HippyResource = PixelMap | ResourceStr| DrawableDescriptor;

27 changes: 27 additions & 0 deletions framework/ohos/src/main/ets/support/utils/UrlUtils.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2022 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class UrlUtils {

public static isWebUrl(url: string) : boolean {
const regex = new RegExp('^https?:\/\/.+', 'i');
return regex.test(url);
}
}
49 changes: 49 additions & 0 deletions framework/ohos/src/main/ets/vfs/DefaultProcessor.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2022 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Processor } from './Processor';
import { ResourceLoader } from './ResourceLoader';
import {ResourceDataHolder} from './ResourceDataHolder'
import { ProcessorCallback } from './ProcessorCallback';

export class DefaultProcessor extends Processor {
private resourceLoader: ResourceLoader

constructor(resourceLoader: ResourceLoader) {
super()
this.resourceLoader = resourceLoader
}

handleRequestAsync(holder: ResourceDataHolder, callback: ProcessorCallback) {
if (holder.resultCode == ResourceDataHolder.RESOURCE_LOAD_SUCCESS_CODE) {
callback.onHandleCompleted()
} else {
this.resourceLoader.fetchResourceAsync(holder, callback)
}
}

handleRequestSync(holder: ResourceDataHolder): boolean {
if (holder.resultCode == ResourceDataHolder.RESOURCE_LOAD_SUCCESS_CODE) {
return true
} else {
return this.resourceLoader.fetchResourceSync(holder)
}
}

}
Loading

0 comments on commit 382feff

Please sign in to comment.