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_H_ | 5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_H_ |
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_H_ | 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.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/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/public/browser/url_data_source.h" | 18 #include "content/public/browser/url_data_source.h" |
18 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 class WebUIDataSource; | |
22 class WebUIDataSourceTest; | |
23 } | |
24 | 22 |
25 // A data source that can help with implementing the common operations | 23 // A data source that can help with implementing the common operations |
26 // needed by the chrome WEBUI settings/history/downloads pages. | 24 // needed by the chrome WEBUI settings/history/downloads pages. |
27 class CONTENT_EXPORT ChromeWebUIDataSource | 25 class CONTENT_EXPORT WebUIDataSourceImpl |
28 : public NON_EXPORTED_BASE(URLDataSourceImpl), | 26 : public NON_EXPORTED_BASE(URLDataSourceImpl), |
29 public NON_EXPORTED_BASE(content::WebUIDataSource) { | 27 public NON_EXPORTED_BASE(WebUIDataSource) { |
30 public: | 28 public: |
31 // content::WebUIDataSource implementation: | 29 // WebUIDataSource implementation: |
32 virtual void AddString(const std::string& name, | 30 virtual void AddString(const std::string& name, |
33 const string16& value) OVERRIDE; | 31 const string16& value) OVERRIDE; |
34 virtual void AddString(const std::string& name, | 32 virtual void AddString(const std::string& name, |
35 const std::string& value) OVERRIDE; | 33 const std::string& value) OVERRIDE; |
36 virtual void AddLocalizedString(const std::string& name, int ids) OVERRIDE; | 34 virtual void AddLocalizedString(const std::string& name, int ids) OVERRIDE; |
37 virtual void AddLocalizedStrings( | 35 virtual void AddLocalizedStrings( |
38 const DictionaryValue& localized_strings) OVERRIDE; | 36 const DictionaryValue& localized_strings) OVERRIDE; |
39 virtual void AddBoolean(const std::string& name, bool value) OVERRIDE; | 37 virtual void AddBoolean(const std::string& name, bool value) OVERRIDE; |
40 virtual void SetJsonPath(const std::string& path) OVERRIDE; | 38 virtual void SetJsonPath(const std::string& path) OVERRIDE; |
41 virtual void SetUseJsonJSFormatV2() OVERRIDE; | 39 virtual void SetUseJsonJSFormatV2() OVERRIDE; |
42 virtual void AddResourcePath(const std::string &path, | 40 virtual void AddResourcePath(const std::string &path, |
43 int resource_id) OVERRIDE; | 41 int resource_id) OVERRIDE; |
44 virtual void SetDefaultResource(int resource_id) OVERRIDE; | 42 virtual void SetDefaultResource(int resource_id) OVERRIDE; |
45 virtual void SetRequestFilter( | 43 virtual void SetRequestFilter( |
46 const content::WebUIDataSource::HandleRequestCallback& callback) OVERRIDE; | 44 const WebUIDataSource::HandleRequestCallback& callback) OVERRIDE; |
47 virtual void DisableContentSecurityPolicy() OVERRIDE; | 45 virtual void DisableContentSecurityPolicy() OVERRIDE; |
48 virtual void OverrideContentSecurityPolicyObjectSrc( | 46 virtual void OverrideContentSecurityPolicyObjectSrc( |
49 const std::string& data) OVERRIDE; | 47 const std::string& data) OVERRIDE; |
50 virtual void OverrideContentSecurityPolicyFrameSrc( | 48 virtual void OverrideContentSecurityPolicyFrameSrc( |
51 const std::string& data) OVERRIDE; | 49 const std::string& data) OVERRIDE; |
52 virtual void DisableDenyXFrameOptions() OVERRIDE; | 50 virtual void DisableDenyXFrameOptions() OVERRIDE; |
53 | 51 |
54 protected: | 52 protected: |
55 virtual ~ChromeWebUIDataSource(); | 53 virtual ~WebUIDataSourceImpl(); |
56 | 54 |
57 // Completes a request by sending our dictionary of localized strings. | 55 // Completes a request by sending our dictionary of localized strings. |
58 void SendLocalizedStringsAsJSON( | 56 void SendLocalizedStringsAsJSON( |
59 const content::URLDataSource::GotDataCallback& callback); | 57 const URLDataSource::GotDataCallback& callback); |
60 | 58 |
61 // Completes a request by sending the file specified by |idr|. | 59 // Completes a request by sending the file specified by |idr|. |
62 void SendFromResourceBundle( | 60 void SendFromResourceBundle( |
63 const content::URLDataSource::GotDataCallback& callback, int idr); | 61 const URLDataSource::GotDataCallback& callback, int idr); |
64 | 62 |
65 private: | 63 private: |
66 class InternalDataSource; | 64 class InternalDataSource; |
67 friend class InternalDataSource; | 65 friend class InternalDataSource; |
68 friend class content::WebUIDataSource; | 66 friend class WebUIDataSource; |
69 friend class content::WebUIDataSourceTest; | 67 friend class WebUIDataSourceTest; |
70 | 68 |
71 explicit ChromeWebUIDataSource(const std::string& source_name); | 69 explicit WebUIDataSourceImpl(const std::string& source_name); |
72 | 70 |
73 // Methods that match content::URLDataSource which are called by | 71 // Methods that match URLDataSource which are called by |
74 // InternalDataSource. | 72 // InternalDataSource. |
75 std::string GetSource(); | 73 std::string GetSource(); |
76 std::string GetMimeType(const std::string& path) const; | 74 std::string GetMimeType(const std::string& path) const; |
77 void StartDataRequest( | 75 void StartDataRequest( |
78 const std::string& path, | 76 const std::string& path, |
79 bool is_incognito, | 77 bool is_incognito, |
80 const content::URLDataSource::GotDataCallback& callback); | 78 const URLDataSource::GotDataCallback& callback); |
81 | 79 |
82 void disable_set_font_strings_for_testing() { | 80 void disable_set_font_strings_for_testing() { |
83 disable_set_font_strings_ = true; | 81 disable_set_font_strings_ = true; |
84 } | 82 } |
85 | 83 |
86 // The name of this source. | 84 // The name of this source. |
87 // E.g., for favicons, this could be "favicon", which results in paths for | 85 // E.g., for favicons, this could be "favicon", which results in paths for |
88 // specific resources like "favicon/34" getting sent to this source. | 86 // specific resources like "favicon/34" getting sent to this source. |
89 std::string source_name_; | 87 std::string source_name_; |
90 int default_resource_; | 88 int default_resource_; |
91 bool json_js_format_v2_; | 89 bool json_js_format_v2_; |
92 std::string json_path_; | 90 std::string json_path_; |
93 std::map<std::string, int> path_to_idr_map_; | 91 std::map<std::string, int> path_to_idr_map_; |
94 DictionaryValue localized_strings_; | 92 DictionaryValue localized_strings_; |
95 content::WebUIDataSource::HandleRequestCallback filter_callback_; | 93 WebUIDataSource::HandleRequestCallback filter_callback_; |
96 bool add_csp_; | 94 bool add_csp_; |
97 bool object_src_set_; | 95 bool object_src_set_; |
98 std::string object_src_; | 96 std::string object_src_; |
99 bool frame_src_set_; | 97 bool frame_src_set_; |
100 std::string frame_src_; | 98 std::string frame_src_; |
101 bool deny_xframe_options_; | 99 bool deny_xframe_options_; |
102 bool disable_set_font_strings_; | 100 bool disable_set_font_strings_; |
103 | 101 |
104 DISALLOW_COPY_AND_ASSIGN(ChromeWebUIDataSource); | 102 DISALLOW_COPY_AND_ASSIGN(WebUIDataSourceImpl); |
105 }; | 103 }; |
106 | 104 |
| 105 } // content |
| 106 |
107 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_H_ | 107 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_H_ |
OLD | NEW |