| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options2/options_ui2.h" | 5 #include "chrome/browser/ui/webui/options2/options_ui2.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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete.h" | |
| 21 #include "chrome/browser/autocomplete/autocomplete_match.h" | 20 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 21 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 22 #include "chrome/browser/browser_about_handler.h" | 22 #include "chrome/browser/browser_about_handler.h" |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 26 #include "chrome/browser/ui/webui/options2/autofill_options_handler2.h" | 26 #include "chrome/browser/ui/webui/options2/autofill_options_handler2.h" |
| 27 #include "chrome/browser/ui/webui/options2/browser_options_handler2.h" | 27 #include "chrome/browser/ui/webui/options2/browser_options_handler2.h" |
| 28 #include "chrome/browser/ui/webui/options2/clear_browser_data_handler2.h" | 28 #include "chrome/browser/ui/webui/options2/clear_browser_data_handler2.h" |
| 29 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h" | 29 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h" |
| 30 #include "chrome/browser/ui/webui/options2/cookies_view_handler2.h" | 30 #include "chrome/browser/ui/webui/options2/cookies_view_handler2.h" |
| 31 #include "chrome/browser/ui/webui/options2/core_options_handler2.h" | 31 #include "chrome/browser/ui/webui/options2/core_options_handler2.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 SetFontAndTextDirection(localized_strings_.get()); | 140 SetFontAndTextDirection(localized_strings_.get()); |
| 141 | 141 |
| 142 if (path == kLocalizedStringsFile) { | 142 if (path == kLocalizedStringsFile) { |
| 143 // Return dynamically-generated strings from memory. | 143 // Return dynamically-generated strings from memory. |
| 144 jstemplate_builder::UseVersion2 version; | 144 jstemplate_builder::UseVersion2 version; |
| 145 std::string strings_js; | 145 std::string strings_js; |
| 146 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); | 146 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &strings_js); |
| 147 response_bytes = base::RefCountedString::TakeString(&strings_js); | 147 response_bytes = base::RefCountedString::TakeString(&strings_js); |
| 148 } else if (path == kOptionsBundleJsFile) { | 148 } else if (path == kOptionsBundleJsFile) { |
| 149 // Return (and cache) the options javascript code. | 149 // Return (and cache) the options javascript code. |
| 150 response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 150 response_bytes = ui::ResourceBundle::GetSharedInstance(). |
| 151 IDR_OPTIONS2_BUNDLE_JS, ui::SCALE_FACTOR_NONE); | 151 LoadDataResourceBytes(IDR_OPTIONS2_BUNDLE_JS, ui::SCALE_FACTOR_NONE); |
| 152 } else { | 152 } else { |
| 153 // Return (and cache) the main options html page as the default. | 153 // Return (and cache) the main options html page as the default. |
| 154 response_bytes = ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 154 response_bytes = ui::ResourceBundle::GetSharedInstance(). |
| 155 IDR_OPTIONS2_HTML, ui::SCALE_FACTOR_NONE); | 155 LoadDataResourceBytes(IDR_OPTIONS2_HTML, ui::SCALE_FACTOR_NONE); |
| 156 } | 156 } |
| 157 | 157 |
| 158 SendResponse(request_id, response_bytes); | 158 SendResponse(request_id, response_bytes); |
| 159 } | 159 } |
| 160 | 160 |
| 161 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { | 161 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { |
| 162 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) | 162 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) |
| 163 return "application/javascript"; | 163 return "application/javascript"; |
| 164 | 164 |
| 165 return "text/html"; | 165 return "text/html"; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 321 } |
| 322 | 322 |
| 323 OptionsUI::~OptionsUI() { | 323 OptionsUI::~OptionsUI() { |
| 324 // Uninitialize all registered handlers. Deleted by WebUIImpl. | 324 // Uninitialize all registered handlers. Deleted by WebUIImpl. |
| 325 for (size_t i = 0; i < handlers_.size(); ++i) | 325 for (size_t i = 0; i < handlers_.size(); ++i) |
| 326 handlers_[i]->Uninitialize(); | 326 handlers_[i]->Uninitialize(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // static | 329 // static |
| 330 void OptionsUI::ProcessAutocompleteSuggestions( | 330 void OptionsUI::ProcessAutocompleteSuggestions( |
| 331 const AutocompleteResult& autocompleteResult, | 331 const AutocompleteResult& result, |
| 332 ListValue * const suggestions) { | 332 base::ListValue* const suggestions) { |
| 333 for (size_t i = 0; i < autocompleteResult.size(); ++i) { | 333 for (size_t i = 0; i < result.size(); ++i) { |
| 334 const AutocompleteMatch& match = autocompleteResult.match_at(i); | 334 const AutocompleteMatch& match = result.match_at(i); |
| 335 AutocompleteMatch::Type type = match.type; | 335 AutocompleteMatch::Type type = match.type; |
| 336 if (type != AutocompleteMatch::HISTORY_URL && | 336 if (type != AutocompleteMatch::HISTORY_URL && |
| 337 type != AutocompleteMatch::HISTORY_TITLE && | 337 type != AutocompleteMatch::HISTORY_TITLE && |
| 338 type != AutocompleteMatch::HISTORY_BODY && | 338 type != AutocompleteMatch::HISTORY_BODY && |
| 339 type != AutocompleteMatch::HISTORY_KEYWORD && | 339 type != AutocompleteMatch::HISTORY_KEYWORD && |
| 340 type != AutocompleteMatch::NAVSUGGEST) | 340 type != AutocompleteMatch::NAVSUGGEST) |
| 341 continue; | 341 continue; |
| 342 DictionaryValue* entry = new DictionaryValue(); | 342 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 343 entry->SetString("title", match.description); | 343 entry->SetString("title", match.description); |
| 344 entry->SetString("displayURL", match.contents); | 344 entry->SetString("displayURL", match.contents); |
| 345 entry->SetString("url", match.destination_url.spec()); | 345 entry->SetString("url", match.destination_url.spec()); |
| 346 suggestions->Append(entry); | 346 suggestions->Append(entry); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 // static | 350 // static |
| 351 base::RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { | 351 base::RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { |
| 352 return ResourceBundle::GetSharedInstance(). | 352 return ui::ResourceBundle::GetSharedInstance(). |
| 353 LoadDataResourceBytes(IDR_SETTINGS_FAVICON, | 353 LoadDataResourceBytes(IDR_SETTINGS_FAVICON, ui::SCALE_FACTOR_100P); |
| 354 ui::SCALE_FACTOR_100P); | |
| 355 } | 354 } |
| 356 | 355 |
| 357 void OptionsUI::InitializeHandlers() { | 356 void OptionsUI::InitializeHandlers() { |
| 358 Profile* profile = Profile::FromWebUI(web_ui()); | 357 Profile* profile = Profile::FromWebUI(web_ui()); |
| 359 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); | 358 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); |
| 360 | 359 |
| 361 // A new web page DOM has been brought up in an existing renderer, causing | 360 // A new web page DOM has been brought up in an existing renderer, causing |
| 362 // this method to be called twice. If that happens, ignore the second call. | 361 // this method to be called twice. If that happens, ignore the second call. |
| 363 if (!initialized_handlers_) { | 362 if (!initialized_handlers_) { |
| 364 for (size_t i = 0; i < handlers_.size(); ++i) | 363 for (size_t i = 0; i < handlers_.size(); ++i) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 387 // Add only if handler's service is enabled. | 386 // Add only if handler's service is enabled. |
| 388 if (handler->IsEnabled()) { | 387 if (handler->IsEnabled()) { |
| 389 // Add handler to the list and also pass the ownership. | 388 // Add handler to the list and also pass the ownership. |
| 390 web_ui()->AddMessageHandler(handler.release()); | 389 web_ui()->AddMessageHandler(handler.release()); |
| 391 handler_raw->GetLocalizedValues(localized_strings); | 390 handler_raw->GetLocalizedValues(localized_strings); |
| 392 handlers_.push_back(handler_raw); | 391 handlers_.push_back(handler_raw); |
| 393 } | 392 } |
| 394 } | 393 } |
| 395 | 394 |
| 396 } // namespace options2 | 395 } // namespace options2 |
| OLD | NEW |