mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Support CefResourceBundleHandler (see #3685)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
#include "cef/libcef/common/chrome/chrome_content_client_cef.h"
|
||||
#include "cef/libcef/common/main_runner_handler.h"
|
||||
#include "cef/libcef/common/resource_bundle_delegate.h"
|
||||
#include "cef/libcef/common/task_runner_manager.h"
|
||||
#include "chrome/app/chrome_main_delegate.h"
|
||||
|
||||
@@ -71,6 +72,11 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override;
|
||||
|
||||
// ChromeMainDelegate overrides.
|
||||
ui::ResourceBundle::Delegate* GetResourceBundleDelegate() override {
|
||||
return &resource_bundle_delegate_;
|
||||
}
|
||||
|
||||
private:
|
||||
ChromeContentBrowserClientCef* content_browser_client() const;
|
||||
ChromeContentRendererClientCef* content_renderer_client() const;
|
||||
@@ -81,6 +87,8 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
|
||||
|
||||
// We use this instead of ChromeMainDelegate::chrome_content_client_.
|
||||
ChromeContentClientCef chrome_content_client_cef_;
|
||||
|
||||
CefResourceBundleDelegate resource_bundle_delegate_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_COMMON_CHROME_CHROME_MAIN_DELEGATE_CEF_
|
||||
|
@@ -1,24 +1,42 @@
|
||||
#include "cef/libcef/common/resource_bundle_delegate.h"
|
||||
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
#include "cef/libcef/features/runtime.h"
|
||||
|
||||
CefResourceBundleDelegate::CefResourceBundleDelegate() {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// Alloy bootstrap explicitly enables pack file loading in
|
||||
// AlloyMainDelegate::InitializeResourceBundle, and it is otherwise disabled
|
||||
// by default. Chrome bootstrap does not support this.
|
||||
allow_pack_file_load_ = cef::IsChromeRuntimeEnabled();
|
||||
#endif
|
||||
}
|
||||
|
||||
base::FilePath CefResourceBundleDelegate::GetPathForResourcePack(
|
||||
const base::FilePath& pack_path,
|
||||
ui::ResourceScaleFactor scale_factor) {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// Only allow the cef pack file to load.
|
||||
if (!pack_loading_disabled_ && allow_pack_file_load_) {
|
||||
return pack_path;
|
||||
}
|
||||
return base::FilePath();
|
||||
#else
|
||||
return pack_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
base::FilePath CefResourceBundleDelegate::GetPathForLocalePack(
|
||||
const base::FilePath& pack_path,
|
||||
const std::string& locale) {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (!pack_loading_disabled_) {
|
||||
return pack_path;
|
||||
}
|
||||
return base::FilePath();
|
||||
#else
|
||||
return pack_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
gfx::Image CefResourceBundleDelegate::GetImageNamed(int resource_id) {
|
||||
@@ -63,7 +81,13 @@ bool CefResourceBundleDelegate::GetRawDataResource(
|
||||
}
|
||||
}
|
||||
|
||||
return (pack_loading_disabled_ || !value->empty());
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (pack_loading_disabled_) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return !value->empty();
|
||||
}
|
||||
|
||||
bool CefResourceBundleDelegate::GetLocalizedString(
|
||||
@@ -81,5 +105,11 @@ bool CefResourceBundleDelegate::GetLocalizedString(
|
||||
}
|
||||
}
|
||||
|
||||
return (pack_loading_disabled_ || !value->empty());
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (pack_loading_disabled_) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return !value->empty();
|
||||
}
|
||||
|
@@ -7,18 +7,23 @@
|
||||
#define CEF_LIBCEF_COMMON_RESOURCE_BUNDLE_DELEGATE_H_
|
||||
#pragma once
|
||||
|
||||
#include "cef/libcef/features/features.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
class AlloyContentClient;
|
||||
|
||||
class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
|
||||
public:
|
||||
CefResourceBundleDelegate() = default;
|
||||
CefResourceBundleDelegate();
|
||||
|
||||
CefResourceBundleDelegate(const CefResourceBundleDelegate&) = delete;
|
||||
CefResourceBundleDelegate& operator=(const CefResourceBundleDelegate&) =
|
||||
delete;
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
void set_pack_loading_disabled(bool val) { pack_loading_disabled_ = val; }
|
||||
bool pack_loading_disabled() const { return pack_loading_disabled_; }
|
||||
void set_allow_pack_file_load(bool val) { allow_pack_file_load_ = val; }
|
||||
bool allow_pack_file_load() const { return allow_pack_file_load_; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
// ui::ResourceBundle::Delegate methods.
|
||||
@@ -38,9 +43,11 @@ class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
|
||||
std::string_view* value) const override;
|
||||
bool GetLocalizedString(int message_id, std::u16string* value) const override;
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
private:
|
||||
bool pack_loading_disabled_ = false;
|
||||
bool allow_pack_file_load_ = false;
|
||||
bool allow_pack_file_load_;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_COMMON_RESOURCE_BUNDLE_DELEGATE_H_
|
||||
|
Reference in New Issue
Block a user