OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/webui/quota_internals_ui.h" | 5 #include "chrome/browser/ui/webui/quota_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 10 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
11 #include "chrome/browser/ui/webui/quota_internals_handler.h" | 12 #include "chrome/browser/ui/webui/quota_internals_handler.h" |
12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/common/json_value_serializer.h" | 15 #include "content/common/json_value_serializer.h" |
15 #include "grit/quota_internals_resources.h" | 16 #include "grit/quota_internals_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 | 19 |
| 20 |
| 21 namespace { |
| 22 |
| 23 ChromeWebUIDataSource* CreateQuotaInternalsHTMLSource() { |
| 24 ChromeWebUIDataSource* source = |
| 25 new ChromeWebUIDataSource(chrome::kChromeUIQuotaInternalsHost); |
| 26 |
| 27 source->set_json_path("strings.js"); |
| 28 source->add_resource_path( |
| 29 "event_handler.js", IDR_QUOTA_INTERNALS_EVENT_HANDLER_JS); |
| 30 source->add_resource_path( |
| 31 "message_dispatcher.js", IDR_QUOTA_INTERNALS_MESSAGE_DISPATCHER_JS); |
| 32 source->set_default_resource(IDR_QUOTA_INTERNALS_MAIN_HTML); |
| 33 return source; |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
19 QuotaInternalsUI::QuotaInternalsUI(TabContents* contents) | 38 QuotaInternalsUI::QuotaInternalsUI(TabContents* contents) |
20 : ChromeWebUI(contents) { | 39 : ChromeWebUI(contents) { |
21 WebUIMessageHandler* handler = new quota_internals::QuotaInternalsHandler; | 40 WebUIMessageHandler* handler = new quota_internals::QuotaInternalsHandler; |
22 AddMessageHandler(handler->Attach(this)); | 41 AddMessageHandler(handler->Attach(this)); |
23 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 42 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
24 profile->GetChromeURLDataManager()->AddDataSource( | 43 profile->GetChromeURLDataManager()->AddDataSource( |
25 new quota_internals::QuotaInternalsHTMLSource); | 44 CreateQuotaInternalsHTMLSource()); |
26 } | 45 } |
27 | |
28 namespace quota_internals { | |
29 | |
30 const char QuotaInternalsHTMLSource::kStringsJSPath[] = "strings.js"; | |
31 | |
32 QuotaInternalsHTMLSource::QuotaInternalsHTMLSource() | |
33 : ChromeWebUIDataSource(chrome::kChromeUIQuotaInternalsHost) { | |
34 } | |
35 | |
36 void QuotaInternalsHTMLSource::StartDataRequest(const std::string& path, | |
37 bool is_incognito, | |
38 int request_id) { | |
39 if (path == kStringsJSPath) | |
40 SendLocalizedStringsAsJSON(request_id); | |
41 else | |
42 SendFromResourceBundle(request_id, IDR_QUOTA_INTERNALS_MAIN_HTML); | |
43 } | |
44 | |
45 std::string QuotaInternalsHTMLSource::GetMimeType( | |
46 const std::string& path) const { | |
47 if (path == kStringsJSPath) | |
48 return "application/javascript"; | |
49 else | |
50 return "text/html"; | |
51 } | |
52 | |
53 } // namespace quota_internals | |
OLD | NEW |