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/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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) { | 109 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) { |
110 DCHECK(localized_strings); | 110 DCHECK(localized_strings); |
111 localized_strings_.reset(localized_strings); | 111 localized_strings_.reset(localized_strings); |
112 } | 112 } |
113 | 113 |
114 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} | 114 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} |
115 | 115 |
116 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, | 116 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, |
117 bool is_incognito, | 117 bool is_incognito, |
118 int request_id) { | 118 int request_id) { |
119 scoped_refptr<RefCountedBytes> response_bytes(new RefCountedBytes); | 119 scoped_refptr<RefCountedMemory> response_bytes; |
120 SetFontAndTextDirection(localized_strings_.get()); | 120 SetFontAndTextDirection(localized_strings_.get()); |
121 | 121 |
122 if (path == kLocalizedStringsFile) { | 122 if (path == kLocalizedStringsFile) { |
123 // Return dynamically-generated strings from memory. | 123 // Return dynamically-generated strings from memory. |
124 std::string template_data; | 124 std::string strings_js; |
125 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &template_data); | 125 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); |
126 response_bytes->data.resize(template_data.size()); | 126 response_bytes = base::RefCountedString::TakeString(&strings_js); |
127 std::copy(template_data.begin(), | |
128 template_data.end(), | |
129 response_bytes->data.begin()); | |
130 } else if (path == kOptionsBundleJsFile) { | 127 } else if (path == kOptionsBundleJsFile) { |
131 // Return (and cache) the options javascript code. | 128 // Return (and cache) the options javascript code. |
132 static const base::StringPiece options_javascript( | 129 response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
133 ResourceBundle::GetSharedInstance().GetRawDataResource( | 130 IDR_OPTIONS_BUNDLE_JS); |
134 IDR_OPTIONS_BUNDLE_JS)); | |
135 response_bytes->data.resize(options_javascript.size()); | |
136 std::copy(options_javascript.begin(), | |
137 options_javascript.end(), | |
138 response_bytes->data.begin()); | |
139 } else { | 131 } else { |
140 // Return (and cache) the main options html page as the default. | 132 // Return (and cache) the main options html page as the default. |
141 static const base::StringPiece options_html( | 133 response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
142 ResourceBundle::GetSharedInstance().GetRawDataResource( | 134 IDR_OPTIONS_HTML); |
143 IDR_OPTIONS_HTML)); | |
144 response_bytes->data.resize(options_html.size()); | |
145 std::copy(options_html.begin(), | |
146 options_html.end(), | |
147 response_bytes->data.begin()); | |
148 } | 135 } |
149 | 136 |
150 SendResponse(request_id, response_bytes); | 137 SendResponse(request_id, response_bytes); |
151 } | 138 } |
152 | 139 |
153 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { | 140 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { |
154 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) | 141 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) |
155 return "application/javascript"; | 142 return "application/javascript"; |
156 | 143 |
157 return "text/html"; | 144 return "text/html"; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 OptionsPageUIHandler* handler_raw) { | 341 OptionsPageUIHandler* handler_raw) { |
355 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); | 342 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); |
356 DCHECK(handler.get()); | 343 DCHECK(handler.get()); |
357 // Add only if handler's service is enabled. | 344 // Add only if handler's service is enabled. |
358 if (handler->IsEnabled()) { | 345 if (handler->IsEnabled()) { |
359 handler->GetLocalizedValues(localized_strings); | 346 handler->GetLocalizedValues(localized_strings); |
360 // Add handler to the list and also pass the ownership. | 347 // Add handler to the list and also pass the ownership. |
361 AddMessageHandler(handler.release()->Attach(this)); | 348 AddMessageHandler(handler.release()->Attach(this)); |
362 } | 349 } |
363 } | 350 } |
OLD | NEW |