OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ | 5 #ifndef IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ |
6 #define IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ | 6 #define IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "ios/web/public/url_data_source_ios.h" | 15 #include "ios/web/public/url_data_source_ios.h" |
16 #include "ios/web/public/web_ui_ios_data_source.h" | 16 #include "ios/web/public/web_ui_ios_data_source.h" |
17 #include "ios/web/webui/url_data_manager_ios.h" | 17 #include "ios/web/webui/url_data_manager_ios.h" |
18 #include "ios/web/webui/url_data_source_ios_impl.h" | 18 #include "ios/web/webui/url_data_source_ios_impl.h" |
19 #include "ui/base/template_expressions.h" | |
20 | 19 |
21 namespace web { | 20 namespace web { |
22 | 21 |
23 class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, | 22 class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, |
24 public WebUIIOSDataSource { | 23 public WebUIIOSDataSource { |
25 public: | 24 public: |
26 // WebUIIOSDataSource implementation: | 25 // WebUIIOSDataSource implementation: |
27 void AddString(const std::string& name, const base::string16& value) override; | 26 void AddString(const std::string& name, const base::string16& value) override; |
28 void AddString(const std::string& name, const std::string& value) override; | 27 void AddString(const std::string& name, const std::string& value) override; |
29 void AddLocalizedString(const std::string& name, int ids) override; | 28 void AddLocalizedString(const std::string& name, int ids) override; |
30 void AddLocalizedStrings( | |
31 const base::DictionaryValue& localized_strings) override; | |
32 void AddBoolean(const std::string& name, bool value) override; | 29 void AddBoolean(const std::string& name, bool value) override; |
33 void SetJsonPath(const std::string& path) override; | 30 void SetJsonPath(const std::string& path) override; |
34 void AddResourcePath(const std::string& path, int resource_id) override; | 31 void AddResourcePath(const std::string& path, int resource_id) override; |
35 void SetDefaultResource(int resource_id) override; | 32 void SetDefaultResource(int resource_id) override; |
36 void DisableDenyXFrameOptions() override; | 33 void DisableDenyXFrameOptions() override; |
37 | 34 |
38 protected: | 35 protected: |
39 ~WebUIIOSDataSourceImpl() override; | 36 ~WebUIIOSDataSourceImpl() override; |
40 | 37 |
41 // Completes a request by sending our dictionary of localized strings. | 38 // Completes a request by sending our dictionary of localized strings. |
42 void SendLocalizedStringsAsJSON( | 39 void SendLocalizedStringsAsJSON( |
43 const URLDataSourceIOS::GotDataCallback& callback); | 40 const URLDataSourceIOS::GotDataCallback& callback); |
44 | 41 |
45 // Completes a request to |path| by sending the file specified by |idr| as the | 42 // Completes a request by sending the file specified by |idr|. |
46 // response. | 43 void SendFromResourceBundle(const URLDataSourceIOS::GotDataCallback& callback, |
47 void SendFromResourceBundle(const std::string& path, | |
48 const URLDataSourceIOS::GotDataCallback& callback, | |
49 int idr); | 44 int idr); |
50 | 45 |
51 private: | 46 private: |
52 class InternalDataSource; | 47 class InternalDataSource; |
53 friend class InternalDataSource; | 48 friend class InternalDataSource; |
54 friend class WebUIIOSDataSourceTest; | 49 friend class WebUIIOSDataSourceTest; |
55 friend class WebUIIOSDataSource; | 50 friend class WebUIIOSDataSource; |
56 | 51 |
57 explicit WebUIIOSDataSourceImpl(const std::string& source_name); | 52 explicit WebUIIOSDataSourceImpl(const std::string& source_name); |
58 | 53 |
59 // Adds the locale to the load time data defaults. May be called repeatedly. | |
60 void EnsureLoadTimeDataDefaultsAdded(); | |
61 | |
62 // Methods that match URLDataSource which are called by | 54 // Methods that match URLDataSource which are called by |
63 // InternalDataSource. | 55 // InternalDataSource. |
64 std::string GetSource() const; | 56 std::string GetSource() const; |
65 std::string GetMimeType(const std::string& path) const; | 57 std::string GetMimeType(const std::string& path) const; |
66 void StartDataRequest(const std::string& path, | 58 void StartDataRequest(const std::string& path, |
67 const URLDataSourceIOS::GotDataCallback& callback); | 59 const URLDataSourceIOS::GotDataCallback& callback); |
68 | 60 |
69 // The name of this source. | 61 // The name of this source. |
70 // E.g., for favicons, this could be "favicon", which results in paths for | 62 // E.g., for favicons, this could be "favicon", which results in paths for |
71 // specific resources like "favicon/34" getting sent to this source. | 63 // specific resources like "favicon/34" getting sent to this source. |
72 std::string source_name_; | 64 std::string source_name_; |
73 int default_resource_; | 65 int default_resource_; |
74 std::string json_path_; | 66 std::string json_path_; |
75 std::map<std::string, int> path_to_idr_map_; | 67 std::map<std::string, int> path_to_idr_map_; |
76 // The replacements are initiallized in the main thread and then used in the | |
77 // IO thread. The map is safe to read from multiple threads as long as no | |
78 // futher changes are made to it after initialization. | |
79 ui::TemplateReplacements replacements_; | |
80 // The |replacements_| is intended to replace |localized_strings_|. | |
81 base::DictionaryValue localized_strings_; | 68 base::DictionaryValue localized_strings_; |
82 bool deny_xframe_options_; | 69 bool deny_xframe_options_; |
83 bool load_time_data_defaults_added_; | |
84 bool replace_existing_source_; | 70 bool replace_existing_source_; |
85 | 71 |
86 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl); | 72 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl); |
87 }; | 73 }; |
88 | 74 |
89 } // web | 75 } // web |
90 | 76 |
91 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ | 77 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ |
OLD | NEW |