1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
6 #define IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/values.h"
15 #include "ios/web/public/url_data_source_ios.h"
16 #include "ios/web/public/web_ui_ios_data_source.h"
17 #include "ios/web/webui/url_data_manager_ios.h"
18 #include "ios/web/webui/url_data_source_ios_impl.h"
22 class WebUIIOSDataSourceImpl
: public URLDataSourceIOSImpl
,
23 public WebUIIOSDataSource
{
25 // WebUIIOSDataSource implementation:
26 void AddString(const std::string
& name
, const base::string16
& value
) override
;
27 void AddString(const std::string
& name
, const std::string
& value
) override
;
28 void AddLocalizedString(const std::string
& name
, int ids
) override
;
29 void AddBoolean(const std::string
& name
, bool value
) override
;
30 void SetJsonPath(const std::string
& path
) override
;
31 void AddResourcePath(const std::string
& path
, int resource_id
) override
;
32 void SetDefaultResource(int resource_id
) override
;
33 void DisableDenyXFrameOptions() override
;
36 ~WebUIIOSDataSourceImpl() override
;
38 // Completes a request by sending our dictionary of localized strings.
39 void SendLocalizedStringsAsJSON(
40 const URLDataSourceIOS::GotDataCallback
& callback
);
42 // Completes a request by sending the file specified by |idr|.
43 void SendFromResourceBundle(const URLDataSourceIOS::GotDataCallback
& callback
,
47 class InternalDataSource
;
48 friend class InternalDataSource
;
49 friend class WebUIIOSDataSourceTest
;
50 friend class WebUIIOSDataSource
;
52 explicit WebUIIOSDataSourceImpl(const std::string
& source_name
);
54 // Methods that match URLDataSource which are called by
55 // InternalDataSource.
56 std::string
GetSource() const;
57 std::string
GetMimeType(const std::string
& path
) const;
58 void StartDataRequest(const std::string
& path
,
59 const URLDataSourceIOS::GotDataCallback
& callback
);
61 void disable_set_font_strings_for_testing() {
62 disable_set_font_strings_
= true;
65 // The name of this source.
66 // E.g., for favicons, this could be "favicon", which results in paths for
67 // specific resources like "favicon/34" getting sent to this source.
68 std::string source_name_
;
69 int default_resource_
;
70 std::string json_path_
;
71 std::map
<std::string
, int> path_to_idr_map_
;
72 base::DictionaryValue localized_strings_
;
73 bool deny_xframe_options_
;
74 bool disable_set_font_strings_
;
75 bool replace_existing_source_
;
77 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl
);
82 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_