blob: 03f1b1d48250fe9a01f01b58b3b47cb3edf07c1a [file] [log] [blame]
// 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.
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/values.h"
#include "ios/web/public/url_data_source_ios.h"
#include "ios/web/public/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"
namespace web {
class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl,
public WebUIIOSDataSource {
// WebUIIOSDataSource implementation:
void AddString(const std::string& name, const base::string16& value) override;
void AddString(const std::string& name, const std::string& value) override;
void AddLocalizedString(const std::string& name, int ids) override;
void AddBoolean(const std::string& name, bool value) override;
void SetJsonPath(const std::string& path) override;
void AddResourcePath(const std::string& path, int resource_id) override;
void SetDefaultResource(int resource_id) override;
void DisableDenyXFrameOptions() override;
~WebUIIOSDataSourceImpl() override;
// Completes a request by sending our dictionary of localized strings.
void SendLocalizedStringsAsJSON(
const URLDataSourceIOS::GotDataCallback& callback);
// Completes a request by sending the file specified by |idr|.
void SendFromResourceBundle(const URLDataSourceIOS::GotDataCallback& callback,
int idr);
class InternalDataSource;
friend class InternalDataSource;
friend class WebUIIOSDataSourceTest;
friend class WebUIIOSDataSource;
explicit WebUIIOSDataSourceImpl(const std::string& source_name);
// Methods that match URLDataSource which are called by
// InternalDataSource.
std::string GetSource() const;
std::string GetMimeType(const std::string& path) const;
void StartDataRequest(const std::string& path,
const URLDataSourceIOS::GotDataCallback& callback);
void disable_set_font_strings_for_testing() {
disable_set_font_strings_ = true;
// The name of this source.
// E.g., for favicons, this could be "favicon", which results in paths for
// specific resources like "favicon/34" getting sent to this source.
std::string source_name_;
int default_resource_;
std::string json_path_;
std::map<std::string, int> path_to_idr_map_;
base::DictionaryValue localized_strings_;
bool deny_xframe_options_;
bool disable_set_font_strings_;
bool replace_existing_source_;
} // web