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 CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_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 "chrome/browser/ui/webui/chrome_url_data_manager.h" | 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
16 #include "content/public/browser/url_data_source_delegate.h" | 16 #include "content/public/browser/url_data_source.h" |
17 | 17 |
18 // A data source that can help with implementing the common operations | 18 // A data source that can help with implementing the common operations |
19 // needed by the chrome WEBUI settings/history/downloads pages. | 19 // needed by the chrome WEBUI settings/history/downloads pages. |
20 // DO NOT DERIVE FROM THIS CLASS! http://crbug.com/169170 | 20 // DO NOT DERIVE FROM THIS CLASS! http://crbug.com/169170 |
21 class ChromeWebUIDataSource : public URLDataSource, | 21 class ChromeWebUIDataSource : public URLDataSourceImpl { |
22 public content::URLDataSourceDelegate { | |
23 public: | 22 public: |
24 // Used as a parameter to GotDataCallback. The caller has to run this callback | 23 // Used as a parameter to GotDataCallback. The caller has to run this callback |
25 // with the result for the path that they filtered, passing ownership of the | 24 // with the result for the path that they filtered, passing ownership of the |
26 // memory. | 25 // memory. |
27 typedef base::Callback<void(base::RefCountedMemory*)> GotDataCallback; | 26 typedef base::Callback<void(base::RefCountedMemory*)> GotDataCallback; |
28 | 27 |
29 // Used by SetRequestFilter. The string parameter is the path of the request. | 28 // Used by SetRequestFilter. The string parameter is the path of the request. |
30 // If the callee doesn't want to handle the data, false is returned. Otherwise | 29 // If the callee doesn't want to handle the data, false is returned. Otherwise |
31 // true is returned and the GotDataCallback parameter is called either then or | 30 // true is returned and the GotDataCallback parameter is called either then or |
32 // asynchronously with the response. | 31 // asynchronously with the response. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 69 |
71 // Sets the resource to returned when no other paths match. | 70 // Sets the resource to returned when no other paths match. |
72 void set_default_resource(int resource_id) { | 71 void set_default_resource(int resource_id) { |
73 default_resource_ = resource_id; | 72 default_resource_ = resource_id; |
74 } | 73 } |
75 | 74 |
76 protected: | 75 protected: |
77 virtual ~ChromeWebUIDataSource(); | 76 virtual ~ChromeWebUIDataSource(); |
78 | 77 |
79 // Completes a request by sending our dictionary of localized strings. | 78 // Completes a request by sending our dictionary of localized strings. |
80 void SendLocalizedStringsAsJSON(int request_id); | 79 void SendLocalizedStringsAsJSON( |
| 80 const content::URLDataSource::GotDataCallback& callback); |
81 | 81 |
82 // Completes a request by sending the file specified by |idr|. | 82 // Completes a request by sending the file specified by |idr|. |
83 void SendFromResourceBundle(int request_id, int idr); | 83 void SendFromResourceBundle( |
84 | 84 const content::URLDataSource::GotDataCallback& callback, int idr); |
85 // content::URLDataSourceDelegate implementation. | |
86 virtual std::string GetSource() OVERRIDE; | |
87 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; | |
88 virtual void StartDataRequest(const std::string& path, | |
89 bool is_incognito, | |
90 int request_id) OVERRIDE; | |
91 | 85 |
92 private: | 86 private: |
| 87 class InternalDataSource; |
| 88 friend class InternalDataSource; |
| 89 friend class MockChromeWebUIDataSource; |
| 90 |
| 91 // Methods that match content::URLDataSource which are called by |
| 92 // InternalDataSource. |
| 93 std::string GetSource(); |
| 94 std::string GetMimeType(const std::string& path) const; |
| 95 void StartDataRequest( |
| 96 const std::string& path, |
| 97 bool is_incognito, |
| 98 const content::URLDataSource::GotDataCallback& callback); |
| 99 |
93 // The name of this source. | 100 // The name of this source. |
94 // E.g., for favicons, this could be "favicon", which results in paths for | 101 // E.g., for favicons, this could be "favicon", which results in paths for |
95 // specific resources like "favicon/34" getting sent to this source. | 102 // specific resources like "favicon/34" getting sent to this source. |
96 std::string source_name_; | 103 std::string source_name_; |
97 int default_resource_; | 104 int default_resource_; |
98 bool json_js_format_v2_; | 105 bool json_js_format_v2_; |
99 std::string json_path_; | 106 std::string json_path_; |
100 std::map<std::string, int> path_to_idr_map_; | 107 std::map<std::string, int> path_to_idr_map_; |
101 DictionaryValue localized_strings_; | 108 DictionaryValue localized_strings_; |
102 HandleRequestCallback filter_callback_; | 109 HandleRequestCallback filter_callback_; |
103 | 110 |
104 DISALLOW_COPY_AND_ASSIGN(ChromeWebUIDataSource); | 111 DISALLOW_COPY_AND_ASSIGN(ChromeWebUIDataSource); |
105 }; | 112 }; |
106 | 113 |
107 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ | 114 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ |
OLD | NEW |