fix the web file path.

Signed-off-by: lovelxc <lxclxc@126.com>
This commit is contained in:
lovelxc
2022-03-23 09:36:43 +08:00
parent 03c35ccd19
commit 55c682d92e
6 changed files with 48 additions and 4 deletions
+2
View File
@@ -288,6 +288,8 @@ void AceAbility::OnStart(const Want& want)
aceResCfg.SetDeviceType(SystemProperties::GetDeviceType());
container->SetResourceConfiguration(aceResCfg);
container->SetPackagePathStr(resPath);
container->SetBundlePath(abilityContext->GetBundleCodeDir());
container->SetFilesDataPath(abilityContext->GetFilesDir());
}
container->SetWindowName(window->GetWindowName());
SubwindowManager::GetInstance()->AddContainerId(window->GetWindowId(), abilityId_);
@@ -456,6 +456,8 @@ void UIContentImpl::CommonInitialize(OHOS::Rosen::Window* window, const std::str
container->SetResourceConfiguration(aceResCfg);
container->SetPackagePathStr(resPath);
container->SetAssetManager(flutterAssetManager);
container->SetBundlePath(context->GetBundleCodeDir());
container->SetFilesDataPath(context->GetFilesDir());
if (window_->IsDecorEnable()) {
LOGI("Container modal is enabled.");
+18
View File
@@ -147,6 +147,22 @@ public:
return settings_;
}
void SetBundlePath(const std::string& path) {
bundlePath_ = path;
}
const std::string& GetBundlePath() const {
return bundlePath_;
}
void SetFilesDataPath(const std::string& path) {
filesDataPath_ = path;
}
const std::string& GetFilesDataPath() const {
return filesDataPath_;
}
virtual void SetViewFirstUpdating(std::chrono::time_point<std::chrono::high_resolution_clock> time) {}
virtual void UpdateResourceConfiguration(const std::string& jsonStr) {}
@@ -163,6 +179,8 @@ protected:
private:
std::string moduleName_;
std::string bundlePath_;
std::string filesDataPath_;
Settings settings_;
ACE_DISALLOW_COPY_AND_MOVE(Container);
};
@@ -657,7 +657,25 @@ void WebDelegate::InitWebEvent()
void WebDelegate::InitOHOSWeb(const WeakPtr<PipelineContext>& context, sptr<Surface> surface)
{
state_ = State::CREATING;
// obtain hap data path
auto container = Container::Current();
if (container == nullptr) {
LOGE("Fail to get container");
return;
}
const std::string& bundlePath = container->GetBundlePath();
const std::string& filesDataPath = container->GetFilesDataPath();
std::string baseDir = "base";
std::size_t baseIndex = filesDataPath.find(baseDir);
if (baseIndex == std::string::npos) {
LOGE("Fail to parse hap data base path");
return;
}
std::string dataPath = filesDataPath.substr(0, baseIndex + baseDir.length());
bundlePath_ = bundlePath;
bundleDataPath_ = dataPath;
// load webview so
OHOS::NWeb::NWebHelper::Instance().SetBundlePath(bundlePath_);
if (!OHOS::NWeb::NWebHelper::Instance().Init()) {
LOGE("Fail to init NWebHelper");
return;
@@ -992,10 +1010,10 @@ void WebDelegate::InitWebViewWithSurface(sptr<Surface> surface)
return;
}
OHOS::NWeb::NWebInitArgs initArgs;
const std::string& app_path = GetDataPath();
if (!app_path.empty()) {
initArgs.web_engine_args_to_add.push_back(std::string("--user-data-dir=").append(app_path));
}
initArgs.web_engine_args_to_add.push_back(
std::string("--user-data-dir=").append(delegate->bundleDataPath_));
initArgs.web_engine_args_to_add.push_back(
std::string("--bundle-installation-dir=").append(delegate->bundlePath_));
sptr<Surface> surface = surfaceWeak.promote();
if (surface == nullptr) {
LOGE("surface is nullptr or has expired");
@@ -241,6 +241,9 @@ private:
EventCallbackV2 onDownloadStartV2_;
EventCallbackV2 onFocusV2_;
std::string bundlePath_;
std::string bundleDataPath_;
#endif
};
@@ -1467,6 +1467,7 @@ private:
std::unordered_map<int32_t, std::string> restoreNodeInfo_;
bool isSubPipeline_ = false;
ACE_DISALLOW_COPY_AND_MOVE(PipelineContext);
};