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

Side by Side Diff: chrome/browser/ui/webui/options/options_ui.cc

Issue 7397021: Re-land r93365 - add RefCountedString (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: erg comments Created 9 years, 5 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
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/options/options_ui.h" 5 #include "chrome/browser/ui/webui/options/options_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) { 108 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) {
109 DCHECK(localized_strings); 109 DCHECK(localized_strings);
110 localized_strings_.reset(localized_strings); 110 localized_strings_.reset(localized_strings);
111 } 111 }
112 112
113 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} 113 OptionsUIHTMLSource::~OptionsUIHTMLSource() {}
114 114
115 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, 115 void OptionsUIHTMLSource::StartDataRequest(const std::string& path,
116 bool is_incognito, 116 bool is_incognito,
117 int request_id) { 117 int request_id) {
118 scoped_refptr<RefCountedBytes> response_bytes(new RefCountedBytes); 118 scoped_refptr<RefCountedMemory> response_bytes;
119 SetFontAndTextDirection(localized_strings_.get()); 119 SetFontAndTextDirection(localized_strings_.get());
120 120
121 if (path == kLocalizedStringsFile) { 121 if (path == kLocalizedStringsFile) {
122 // Return dynamically-generated strings from memory. 122 // Return dynamically-generated strings from memory.
123 std::string template_data; 123 std::string strings_js;
124 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &template_data); 124 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js);
125 response_bytes->data.resize(template_data.size()); 125 response_bytes = base::RefCountedString::TakeString(&strings_js);
126 std::copy(template_data.begin(),
127 template_data.end(),
128 response_bytes->data.begin());
129 } else if (path == kOptionsBundleJsFile) { 126 } else if (path == kOptionsBundleJsFile) {
130 // Return (and cache) the options javascript code. 127 // Return (and cache) the options javascript code.
131 static const base::StringPiece options_javascript( 128 response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
132 ResourceBundle::GetSharedInstance().GetRawDataResource( 129 IDR_OPTIONS_BUNDLE_JS);
133 IDR_OPTIONS_BUNDLE_JS));
134 response_bytes->data.resize(options_javascript.size());
135 std::copy(options_javascript.begin(),
136 options_javascript.end(),
137 response_bytes->data.begin());
138 } else { 130 } else {
139 // Return (and cache) the main options html page as the default. 131 // Return (and cache) the main options html page as the default.
140 static const base::StringPiece options_html( 132 response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
141 ResourceBundle::GetSharedInstance().GetRawDataResource( 133 IDR_OPTIONS_HTML);
142 IDR_OPTIONS_HTML));
143 response_bytes->data.resize(options_html.size());
144 std::copy(options_html.begin(),
145 options_html.end(),
146 response_bytes->data.begin());
147 } 134 }
148 135
149 SendResponse(request_id, response_bytes); 136 SendResponse(request_id, response_bytes);
150 } 137 }
151 138
152 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { 139 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const {
153 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) 140 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile)
154 return "application/javascript"; 141 return "application/javascript";
155 142
156 return "text/html"; 143 return "text/html";
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 OptionsPageUIHandler* handler_raw) { 337 OptionsPageUIHandler* handler_raw) {
351 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); 338 scoped_ptr<OptionsPageUIHandler> handler(handler_raw);
352 DCHECK(handler.get()); 339 DCHECK(handler.get());
353 // Add only if handler's service is enabled. 340 // Add only if handler's service is enabled.
354 if (handler->IsEnabled()) { 341 if (handler->IsEnabled()) {
355 handler->GetLocalizedValues(localized_strings); 342 handler->GetLocalizedValues(localized_strings);
356 // Add handler to the list and also pass the ownership. 343 // Add handler to the list and also pass the ownership.
357 AddMessageHandler(handler.release()->Attach(this)); 344 AddMessageHandler(handler.release()->Attach(this));
358 } 345 }
359 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698