Chromium Code Reviews| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 std::string response; |
| 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 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &response); |
| 124 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &template_data); | |
| 125 response_bytes->data.resize(template_data.size()); | |
| 126 std::copy(template_data.begin(), | |
| 127 template_data.end(), | |
| 128 response_bytes->data.begin()); | |
| 129 } else if (path == kOptionsBundleJsFile) { | 124 } else if (path == kOptionsBundleJsFile) { |
| 130 // Return (and cache) the options javascript code. | 125 // Return (and cache) the options javascript code. |
| 131 static const base::StringPiece options_javascript( | 126 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 132 ResourceBundle::GetSharedInstance().GetRawDataResource( | 127 IDR_OPTIONS_BUNDLE_JS).CopyToString(&response); |
| 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 { | 128 } else { |
| 139 // Return (and cache) the main options html page as the default. | 129 // Return (and cache) the main options html page as the default. |
| 140 static const base::StringPiece options_html( | 130 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 141 ResourceBundle::GetSharedInstance().GetRawDataResource( | 131 IDR_OPTIONS_HTML).CopyToString(&response); |
|
Elliot Glaysher
2011/07/19 17:59:02
Both versions here are wrong.
Data that comes fro
| |
| 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 } | 132 } |
| 148 | 133 |
| 149 SendResponse(request_id, response_bytes); | 134 SendResponse(request_id, base::RefCountedString::TakeString(&response)); |
| 150 } | 135 } |
| 151 | 136 |
| 152 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { | 137 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { |
| 153 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) | 138 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) |
| 154 return "application/javascript"; | 139 return "application/javascript"; |
| 155 | 140 |
| 156 return "text/html"; | 141 return "text/html"; |
| 157 } | 142 } |
| 158 | 143 |
| 159 //////////////////////////////////////////////////////////////////////////////// | 144 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 OptionsPageUIHandler* handler_raw) { | 335 OptionsPageUIHandler* handler_raw) { |
| 351 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); | 336 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); |
| 352 DCHECK(handler.get()); | 337 DCHECK(handler.get()); |
| 353 // Add only if handler's service is enabled. | 338 // Add only if handler's service is enabled. |
| 354 if (handler->IsEnabled()) { | 339 if (handler->IsEnabled()) { |
| 355 handler->GetLocalizedValues(localized_strings); | 340 handler->GetLocalizedValues(localized_strings); |
| 356 // Add handler to the list and also pass the ownership. | 341 // Add handler to the list and also pass the ownership. |
| 357 AddMessageHandler(handler.release()->Attach(this)); | 342 AddMessageHandler(handler.release()->Attach(this)); |
| 358 } | 343 } |
| 359 } | 344 } |
| OLD | NEW |