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