Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/quota_internals_ui.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/common/url_constants.h" | |
| 12 #include "content/browser/tab_contents/tab_contents.h" | |
| 13 #include "content/common/json_value_serializer.h" | |
| 14 #include "grit/quota_internals_resources.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | |
| 17 | |
| 18 QuotaInternalsUI::QuotaInternalsUI(TabContents* contents) | |
| 19 : ChromeWebUI(contents) { | |
| 20 // TODO(tzik): implement and attach message handler | |
| 21 contents->profile()->GetChromeURLDataManager()-> | |
| 22 AddDataSource(new quota_internals::QuotaInternalsHTMLSource); | |
| 23 } | |
| 24 | |
| 25 namespace quota_internals { | |
| 26 | |
| 27 const char QuotaInternalsHTMLSource::kStringsJSPath[] = "strings.js"; | |
| 28 | |
| 29 QuotaInternalsHTMLSource::QuotaInternalsHTMLSource() | |
| 30 : ChromeURLDataManager::DataSource(chrome::kChromeUIQuotaInternalsHost, | |
| 31 MessageLoop::current()) { | |
| 32 } | |
| 33 | |
| 34 void QuotaInternalsHTMLSource::StartDataRequest(const std::string& path, | |
| 35 bool is_incognito, | |
| 36 int request_id) OVERRIDE { | |
| 37 if (path == kStringsJSPath) { | |
| 38 SetFontAndTextDirection(&localized_strings_); | |
| 39 | |
| 40 // TODO(tzik): Get strings from resource | |
| 41 localized_strings_.SetString("text-not_available", "N/A"); | |
| 42 localized_strings_.SetString("text-true", "true"); | |
| 43 localized_strings_.SetString("text-false", "false"); | |
| 44 | |
| 45 std::string json; | |
| 46 JSONStringValueSerializer serializer(&json); | |
| 47 serializer.Serialize(localized_strings_); | |
| 48 | |
| 49 std::string js( | |
|
Evan Stade
2011/06/07 16:54:44
this is not a very standard way to add strings, I
tzik
2011/06/13 05:40:57
I see, I was mistaken as if this page must be inte
| |
| 50 "cr.define('cr.quota', function() {\n" | |
| 51 " return { \n" | |
| 52 " localizedStrings: " + json + "\n" | |
| 53 " };\n" | |
| 54 "});\n"); | |
| 55 | |
| 56 scoped_refptr<RefCountedBytes> response(new RefCountedBytes); | |
| 57 response->data.resize(js.size()); | |
| 58 std::copy(js.begin(), js.end(), response->data.begin()); | |
| 59 SendResponse(request_id, response); | |
| 60 } else { | |
| 61 scoped_refptr<RefCountedStaticMemory> response( | |
| 62 ResourceBundle::GetSharedInstance(). | |
| 63 LoadDataResourceBytes(IDR_QUOTA_INTERNALS_INDEX_HTML)); | |
| 64 SendResponse(request_id, response); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 std::string QuotaInternalsHTMLSource::GetMimeType( | |
| 69 const std::string& path) const { | |
| 70 if (path == kStringsJSPath) | |
| 71 return "application/javascript"; | |
| 72 else | |
| 73 return "text/html"; | |
| 74 } | |
| 75 | |
| 76 void QuotaInternalsHTMLSource::AddLocalizedString(const std::string& name, | |
| 77 int ids) { | |
| 78 localized_strings_.SetString(name, l10n_util::GetStringUTF16(ids)); | |
| 79 } | |
| 80 | |
| 81 } // namespace quota_internals | |
| OLD | NEW |