#ifndef IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
#define IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
#include <string>
#include <string_view>
#include "base/functional/callback.h"
#include "base/values.h"
#include "ios/web/public/webui/url_data_source_ios.h"
#include "ios/web/public/webui/web_ui_ios_data_source.h"
#include "ios/web/webui/url_data_manager_ios.h"
#include "ios/web/webui/url_data_source_ios_impl.h"
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
#include "ui/base/template_expressions.h"
namespace web {
class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl,
public WebUIIOSDataSource {
public:
WebUIIOSDataSourceImpl(const WebUIIOSDataSourceImpl&) = delete;
WebUIIOSDataSourceImpl& operator=(const WebUIIOSDataSourceImpl&) = delete;
void AddString(const std::string& name, const std::u16string& value) override;
void AddString(const std::string& name, const std::string& value) override;
void AddLocalizedString(const std::string& name, int ids) override;
void AddLocalizedStrings(const base::Value::Dict& localized_strings) override;
void AddLocalizedStrings(
base::span<const webui::LocalizedString> strings) override;
void AddBoolean(const std::string& name, bool value) override;
void UseStringsJs() override;
void EnableReplaceI18nInJS() override;
bool ShouldReplaceI18nInJS() const override;
void AddResourcePath(const std::string& path, int resource_id) override;
void AddResourcePaths(base::span<const webui::ResourcePath> paths) override;
void SetDefaultResource(int resource_id) override;
void DisableDenyXFrameOptions() override;
const ui::TemplateReplacements* GetReplacements() const override;
protected:
~WebUIIOSDataSourceImpl() override;
void SendLocalizedStringsAsJSON(URLDataSourceIOS::GotDataCallback callback,
bool from_js_module);
private:
class InternalDataSource;
friend class InternalDataSource;
friend class WebUIIOSDataSourceTest;
friend class WebUIIOSDataSource;
explicit WebUIIOSDataSourceImpl(std::string_view source_name);
void EnsureLoadTimeDataDefaultsAdded();
std::string GetSource() const;
std::string GetMimeType(std::string_view path) const;
void StartDataRequest(std::string_view path,
URLDataSourceIOS::GotDataCallback callback);
int PathToIdrOrDefault(std::string_view path) const;
std::string source_name_;
int default_resource_;
bool use_strings_js_ = false;
absl::flat_hash_map<std::string, int> path_to_idr_map_;
ui::TemplateReplacements replacements_;
base::Value::Dict localized_strings_;
bool deny_xframe_options_;
bool load_time_data_defaults_added_;
bool replace_existing_source_;
bool should_replace_i18n_in_js_;
};
}
#endif