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" | |
19 | 20 |
20 namespace web { | 21 namespace web { |
21 | 22 |
22 class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, | 23 class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, |
23 public WebUIIOSDataSource { | 24 public WebUIIOSDataSource { |
24 public: | 25 public: |
25 // WebUIIOSDataSource implementation: | 26 // WebUIIOSDataSource implementation: |
26 void AddString(const std::string& name, const base::string16& value) override; | 27 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 AddString(const std::string& name, const std::string& value) override; |
28 void AddLocalizedString(const std::string& name, int ids) override; | 29 void AddLocalizedString(const std::string& name, int ids) override; |
30 void AddLocalizedStrings( | |
31 const base::DictionaryValue& localized_strings) override; | |
29 void AddBoolean(const std::string& name, bool value) override; | 32 void AddBoolean(const std::string& name, bool value) override; |
30 void SetJsonPath(const std::string& path) override; | 33 void SetJsonPath(const std::string& path) override; |
31 void AddResourcePath(const std::string& path, int resource_id) override; | 34 void AddResourcePath(const std::string& path, int resource_id) override; |
32 void SetDefaultResource(int resource_id) override; | 35 void SetDefaultResource(int resource_id) override; |
33 void DisableDenyXFrameOptions() override; | 36 void DisableDenyXFrameOptions() override; |
34 | 37 |
35 protected: | 38 protected: |
36 ~WebUIIOSDataSourceImpl() override; | 39 ~WebUIIOSDataSourceImpl() override; |
37 | 40 |
38 // Completes a request by sending our dictionary of localized strings. | 41 // Completes a request by sending our dictionary of localized strings. |
39 void SendLocalizedStringsAsJSON( | 42 void SendLocalizedStringsAsJSON( |
40 const URLDataSourceIOS::GotDataCallback& callback); | 43 const URLDataSourceIOS::GotDataCallback& callback); |
41 | 44 |
42 // Completes a request by sending the file specified by |idr|. | 45 // Completes a request by sending the file specified by |idr|. |
43 void SendFromResourceBundle(const URLDataSourceIOS::GotDataCallback& callback, | 46 void SendFromResourceBundle(const std::string& path, |
Eugene But (OOO till 7-30)
2017/06/21 00:21:46
What is |path|? Is it related to |idr|? Please exp
michaeldo
2017/06/21 16:56:26
Done.
| |
47 const URLDataSourceIOS::GotDataCallback& callback, | |
44 int idr); | 48 int idr); |
45 | 49 |
46 private: | 50 private: |
47 class InternalDataSource; | 51 class InternalDataSource; |
48 friend class InternalDataSource; | 52 friend class InternalDataSource; |
49 friend class WebUIIOSDataSourceTest; | 53 friend class WebUIIOSDataSourceTest; |
50 friend class WebUIIOSDataSource; | 54 friend class WebUIIOSDataSource; |
51 | 55 |
52 explicit WebUIIOSDataSourceImpl(const std::string& source_name); | 56 explicit WebUIIOSDataSourceImpl(const std::string& source_name); |
53 | 57 |
58 // Add the locale to the load time data defaults. May be called repeatedly. | |
Eugene But (OOO till 7-30)
2017/06/21 00:21:46
s/Add/Adds
michaeldo
2017/06/21 16:56:26
Done.
| |
59 void EnsureLoadTimeDataDefaultsAdded(); | |
60 | |
54 // Methods that match URLDataSource which are called by | 61 // Methods that match URLDataSource which are called by |
55 // InternalDataSource. | 62 // InternalDataSource. |
56 std::string GetSource() const; | 63 std::string GetSource() const; |
57 std::string GetMimeType(const std::string& path) const; | 64 std::string GetMimeType(const std::string& path) const; |
58 void StartDataRequest(const std::string& path, | 65 void StartDataRequest(const std::string& path, |
59 const URLDataSourceIOS::GotDataCallback& callback); | 66 const URLDataSourceIOS::GotDataCallback& callback); |
60 | 67 |
61 // The name of this source. | 68 // The name of this source. |
62 // E.g., for favicons, this could be "favicon", which results in paths for | 69 // E.g., for favicons, this could be "favicon", which results in paths for |
63 // specific resources like "favicon/34" getting sent to this source. | 70 // specific resources like "favicon/34" getting sent to this source. |
64 std::string source_name_; | 71 std::string source_name_; |
65 int default_resource_; | 72 int default_resource_; |
66 std::string json_path_; | 73 std::string json_path_; |
67 std::map<std::string, int> path_to_idr_map_; | 74 std::map<std::string, int> path_to_idr_map_; |
75 // The replacements are initiallized in the main thread and then used in the | |
76 // IO thread. The map is safe to read from multiple threads as long as no | |
77 // futher changes are made to it after initialization. | |
78 ui::TemplateReplacements replacements_; | |
79 // The |replacements_| is intended to replace |localized_strings_|. | |
68 base::DictionaryValue localized_strings_; | 80 base::DictionaryValue localized_strings_; |
69 bool deny_xframe_options_; | 81 bool deny_xframe_options_; |
82 bool add_load_time_data_defaults_; | |
70 bool replace_existing_source_; | 83 bool replace_existing_source_; |
71 | 84 |
72 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl); | 85 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl); |
73 }; | 86 }; |
74 | 87 |
75 } // web | 88 } // web |
76 | 89 |
77 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ | 90 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ |
OLD | NEW |