Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: chrome/browser/ui/webui/quota_internals_ui.cc

Issue 7053009: Add chrome://quota-internals/ resources (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 : WebUI(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(
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698