Chromium Code Reviews| 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/message_loop.h" | |
| 15 #include "base/values.h" | 14 #include "base/values.h" |
| 16 #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" | |
| 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 ChromeURLDataManager::DataSource { | 21 class ChromeWebUIDataSource : public URLDataSource, |
| 22 public content::URLDataSourceDelegate { | |
| 22 public: | 23 public: |
| 23 // Used as a parameter to GotDataCallback. The caller has to run this callback | 24 // Used as a parameter to GotDataCallback. The caller has to run this callback |
| 24 // with the result for the path that they filtered, passing ownership of the | 25 // with the result for the path that they filtered, passing ownership of the |
| 25 // memory. | 26 // memory. |
| 26 typedef base::Callback<void(base::RefCountedMemory*)> GotDataCallback; | 27 typedef base::Callback<void(base::RefCountedMemory*)> GotDataCallback; |
| 27 | 28 |
| 28 // Used by SetRequestFilter. The string parameter is the path of the request. | 29 // Used by SetRequestFilter. The string parameter is the path of the request. |
| 29 // If the callee doesn't want to handle the data, false is returned. Otherwise | 30 // If the callee doesn't want to handle the data, false is returned. Otherwise |
| 30 // true is returned and the GotDataCallback parameter is called either then or | 31 // true is returned and the GotDataCallback parameter is called either then or |
| 31 // asynchronously with the response. | 32 // asynchronously with the response. |
| 32 typedef base::Callback<bool(const std::string&, const GotDataCallback&)> | 33 typedef base::Callback<bool(const std::string&, const GotDataCallback&)> |
| 33 HandleRequestCallback; | 34 HandleRequestCallback; |
| 34 | 35 |
| 35 explicit ChromeWebUIDataSource(const std::string& source_name); | 36 explicit ChromeWebUIDataSource(const std::string& source_name);; |
| 36 ChromeWebUIDataSource(const std::string& source_name, MessageLoop* loop); | |
| 37 | 37 |
| 38 // Adds a string keyed to its name to our dictionary. | 38 // Adds a string keyed to its name to our dictionary. |
| 39 void AddString(const std::string& name, const string16& value); | 39 void AddString(const std::string& name, const string16& value); |
| 40 | 40 |
| 41 // Adds a string keyed to its name to our dictionary. | 41 // Adds a string keyed to its name to our dictionary. |
| 42 void AddString(const std::string& name, const std::string& value); | 42 void AddString(const std::string& name, const std::string& value); |
| 43 | 43 |
| 44 // Adds a localized string with resource |ids| keyed to its name to our | 44 // Adds a localized string with resource |ids| keyed to its name to our |
| 45 // dictionary. | 45 // dictionary. |
| 46 void AddLocalizedString(const std::string& name, int ids); | 46 void AddLocalizedString(const std::string& name, int ids); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 virtual ~ChromeWebUIDataSource(); | 77 virtual ~ChromeWebUIDataSource(); |
| 78 | 78 |
| 79 // Completes a request by sending our dictionary of localized strings. | 79 // Completes a request by sending our dictionary of localized strings. |
| 80 void SendLocalizedStringsAsJSON(int request_id); | 80 void SendLocalizedStringsAsJSON(int request_id); |
| 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(int request_id, int idr); |
| 84 | 84 |
| 85 // ChromeURLDataManager | 85 // content::URLDataSourceDelegate implementation: |
|
James Hawkins
2013/01/14 18:53:54
webui/ files use:
// content::URLDataSourceDelega
jam
2013/01/14 19:21:18
Done.
| |
| 86 virtual std::string GetSource() OVERRIDE; | |
| 86 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; | 87 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; |
| 87 virtual void StartDataRequest(const std::string& path, | 88 virtual void StartDataRequest(const std::string& path, |
| 88 bool is_incognito, | 89 bool is_incognito, |
| 89 int request_id) OVERRIDE; | 90 int request_id) OVERRIDE; |
| 90 | 91 |
| 91 private: | 92 private: |
| 93 std::string source_name_; | |
|
James Hawkins
2013/01/14 18:53:54
nit: Document member variable.
Yes, none of the o
jam
2013/01/14 19:21:18
Done.
| |
| 92 int default_resource_; | 94 int default_resource_; |
| 93 bool json_js_format_v2_; | 95 bool json_js_format_v2_; |
| 94 std::string json_path_; | 96 std::string json_path_; |
| 95 std::map<std::string, int> path_to_idr_map_; | 97 std::map<std::string, int> path_to_idr_map_; |
| 96 DictionaryValue localized_strings_; | 98 DictionaryValue localized_strings_; |
| 97 HandleRequestCallback filter_callback_; | 99 HandleRequestCallback filter_callback_; |
| 98 | 100 |
| 99 DISALLOW_COPY_AND_ASSIGN(ChromeWebUIDataSource); | 101 DISALLOW_COPY_AND_ASSIGN(ChromeWebUIDataSource); |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ | 104 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_WEB_UI_DATA_SOURCE_H_ |
| OLD | NEW |