OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_ |
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_ | 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_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 "content/browser/webui/url_data_manager.h" | 15 #include "content/browser/webui/url_data_manager.h" |
16 #include "content/browser/webui/url_data_source_impl.h" | 16 #include "content/browser/webui/url_data_source_impl.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "content/public/browser/url_data_source.h" | 18 #include "content/public/browser/url_data_source.h" |
19 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
| 20 #include "ui/base/template_expressions.h" |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 // A data source that can help with implementing the common operations | 24 // A data source that can help with implementing the common operations |
24 // needed by the chrome WEBUI settings/history/downloads pages. | 25 // needed by the chrome WEBUI settings/history/downloads pages. |
25 class CONTENT_EXPORT WebUIDataSourceImpl | 26 class CONTENT_EXPORT WebUIDataSourceImpl |
26 : public NON_EXPORTED_BASE(URLDataSourceImpl), | 27 : public NON_EXPORTED_BASE(URLDataSourceImpl), |
27 public NON_EXPORTED_BASE(WebUIDataSource) { | 28 public NON_EXPORTED_BASE(WebUIDataSource) { |
28 public: | 29 public: |
29 // WebUIDataSource implementation: | 30 // WebUIDataSource implementation: |
(...skipping 14 matching lines...) Expand all Loading... |
44 void OverrideContentSecurityPolicyFrameSrc(const std::string& data) override; | 45 void OverrideContentSecurityPolicyFrameSrc(const std::string& data) override; |
45 void DisableDenyXFrameOptions() override; | 46 void DisableDenyXFrameOptions() override; |
46 | 47 |
47 protected: | 48 protected: |
48 ~WebUIDataSourceImpl() override; | 49 ~WebUIDataSourceImpl() override; |
49 | 50 |
50 // Completes a request by sending our dictionary of localized strings. | 51 // Completes a request by sending our dictionary of localized strings. |
51 void SendLocalizedStringsAsJSON( | 52 void SendLocalizedStringsAsJSON( |
52 const URLDataSource::GotDataCallback& callback); | 53 const URLDataSource::GotDataCallback& callback); |
53 | 54 |
54 // Completes a request by sending the file specified by |idr|. | |
55 void SendFromResourceBundle( | |
56 const URLDataSource::GotDataCallback& callback, int idr); | |
57 | |
58 private: | 55 private: |
59 class InternalDataSource; | 56 class InternalDataSource; |
60 friend class InternalDataSource; | 57 friend class InternalDataSource; |
61 friend class WebUIDataSource; | 58 friend class WebUIDataSource; |
62 friend class WebUIDataSourceTest; | 59 friend class WebUIDataSourceTest; |
63 | 60 |
64 explicit WebUIDataSourceImpl(const std::string& source_name); | 61 explicit WebUIDataSourceImpl(const std::string& source_name); |
65 | 62 |
66 // Methods that match URLDataSource which are called by | 63 // Methods that match URLDataSource which are called by |
67 // InternalDataSource. | 64 // InternalDataSource. |
68 std::string GetSource() const; | 65 std::string GetSource() const; |
69 std::string GetMimeType(const std::string& path) const; | 66 std::string GetMimeType(const std::string& path) const; |
70 void StartDataRequest( | 67 void StartDataRequest( |
71 const std::string& path, | 68 const std::string& path, |
72 int render_process_id, | 69 int render_process_id, |
73 int render_frame_id, | 70 int render_frame_id, |
74 const URLDataSource::GotDataCallback& callback); | 71 const URLDataSource::GotDataCallback& callback); |
75 | 72 |
76 void disable_set_font_strings_for_testing() { | 73 void disable_set_font_strings_for_testing() { |
77 disable_set_font_strings_ = true; | 74 disable_set_font_strings_ = true; |
78 } | 75 } |
79 | 76 |
80 // The name of this source. | 77 // The name of this source. |
81 // E.g., for favicons, this could be "favicon", which results in paths for | 78 // E.g., for favicons, this could be "favicon", which results in paths for |
82 // specific resources like "favicon/34" getting sent to this source. | 79 // specific resources like "favicon/34" getting sent to this source. |
83 std::string source_name_; | 80 std::string source_name_; |
84 int default_resource_; | 81 int default_resource_; |
85 std::string json_path_; | 82 std::string json_path_; |
86 std::map<std::string, int> path_to_idr_map_; | 83 std::map<std::string, int> path_to_idr_map_; |
| 84 // The |replacements_| is intended to replace |localized_strings_|. |
| 85 // TODO(dschuyler): phase out |localized_strings_| in Q1 2016. (Or rename |
| 86 // to |load_time_flags_| if the usage is reduced to storing flags only). |
| 87 ui::TemplateReplacements replacements_; |
87 base::DictionaryValue localized_strings_; | 88 base::DictionaryValue localized_strings_; |
88 WebUIDataSource::HandleRequestCallback filter_callback_; | 89 WebUIDataSource::HandleRequestCallback filter_callback_; |
89 bool add_csp_; | 90 bool add_csp_; |
90 bool object_src_set_; | 91 bool object_src_set_; |
91 std::string object_src_; | 92 std::string object_src_; |
92 bool frame_src_set_; | 93 bool frame_src_set_; |
93 std::string frame_src_; | 94 std::string frame_src_; |
94 bool deny_xframe_options_; | 95 bool deny_xframe_options_; |
95 bool disable_set_font_strings_; | 96 bool disable_set_font_strings_; |
96 bool replace_existing_source_; | 97 bool replace_existing_source_; |
97 | 98 |
98 DISALLOW_COPY_AND_ASSIGN(WebUIDataSourceImpl); | 99 DISALLOW_COPY_AND_ASSIGN(WebUIDataSourceImpl); |
99 }; | 100 }; |
100 | 101 |
101 } // content | 102 } // namespace content |
102 | 103 |
103 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_ | 104 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_ |
OLD | NEW |