Chromium Code Reviews| Index: chrome/browser/ui/webui/quota_internals_ui.cc |
| diff --git a/chrome/browser/ui/webui/quota_internals_ui.cc b/chrome/browser/ui/webui/quota_internals_ui.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b8e8e341f1d839e091fd689e58a1f2ebd1ee8ac5 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/quota_internals_ui.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/quota_internals_ui.h" |
| + |
| +#include <algorithm> |
| +#include <string> |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "content/browser/tab_contents/tab_contents.h" |
| +#include "content/common/json_value_serializer.h" |
| +#include "grit/quota_internals_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| + |
| +QuotaInternalsUI::QuotaInternalsUI(TabContents* contents) |
| + : ChromeWebUI(contents) { |
| + // TODO(tzik): implement and attach message handler |
| + contents->profile()->GetChromeURLDataManager()-> |
| + AddDataSource(new quota_internals::QuotaInternalsHTMLSource); |
| +} |
| + |
| +namespace quota_internals { |
| + |
| +const char QuotaInternalsHTMLSource::kStringsJSPath[] = "strings.js"; |
| + |
| +QuotaInternalsHTMLSource::QuotaInternalsHTMLSource() |
| + : ChromeURLDataManager::DataSource(chrome::kChromeUIQuotaInternalsHost, |
| + MessageLoop::current()) { |
| +} |
| + |
| +void QuotaInternalsHTMLSource::StartDataRequest(const std::string& path, |
| + bool is_incognito, |
| + int request_id) OVERRIDE { |
| + if (path == kStringsJSPath) { |
| + SetFontAndTextDirection(&localized_strings_); |
| + |
| + // TODO(tzik): Get strings from resource |
| + localized_strings_.SetString("text-not_available", "N/A"); |
| + localized_strings_.SetString("text-true", "true"); |
| + localized_strings_.SetString("text-false", "false"); |
| + |
| + std::string json; |
| + JSONStringValueSerializer serializer(&json); |
| + serializer.Serialize(localized_strings_); |
| + |
| + 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
|
| + "cr.define('cr.quota', function() {\n" |
| + " return { \n" |
| + " localizedStrings: " + json + "\n" |
| + " };\n" |
| + "});\n"); |
| + |
| + scoped_refptr<RefCountedBytes> response(new RefCountedBytes); |
| + response->data.resize(js.size()); |
| + std::copy(js.begin(), js.end(), response->data.begin()); |
| + SendResponse(request_id, response); |
| + } else { |
| + scoped_refptr<RefCountedStaticMemory> response( |
| + ResourceBundle::GetSharedInstance(). |
| + LoadDataResourceBytes(IDR_QUOTA_INTERNALS_INDEX_HTML)); |
| + SendResponse(request_id, response); |
| + } |
| +} |
| + |
| +std::string QuotaInternalsHTMLSource::GetMimeType( |
| + const std::string& path) const { |
| + if (path == kStringsJSPath) |
| + return "application/javascript"; |
| + else |
| + return "text/html"; |
| +} |
| + |
| +void QuotaInternalsHTMLSource::AddLocalizedString(const std::string& name, |
| + int ids) { |
| + localized_strings_.SetString(name, l10n_util::GetStringUTF16(ids)); |
| +} |
| + |
| +} // namespace quota_internals |