| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/dom_ui/tips_handler.h" | 10 #include "chrome/browser/dom_ui/tips_handler.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) { | 45 if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) { |
| 46 std::wstring server = current_prefs->GetString(prefs::kNTPTipsServer); | 46 std::wstring server = current_prefs->GetString(prefs::kNTPTipsServer); |
| 47 std::wstring locale = | 47 std::wstring locale = |
| 48 ASCIIToWide(g_browser_process->GetApplicationLocale()); | 48 ASCIIToWide(g_browser_process->GetApplicationLocale()); |
| 49 if (!EndsWith(server, locale, false)) { | 49 if (!EndsWith(server, locale, false)) { |
| 50 dom_ui_->CallJavascriptFunction(L"tips", list_value); | 50 dom_ui_->CallJavascriptFunction(L"tips", list_value); |
| 51 return; | 51 return; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 if (tips_cache_ != NULL && tips_cache_->GetSize() != 0) { | 55 if (tips_cache_ != NULL && !tips_cache_->empty()) { |
| 56 if (tips_cache_->GetInteger( | 56 if (tips_cache_->GetInteger( |
| 57 WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && | 57 WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && |
| 58 tips_cache_->GetList( | 58 tips_cache_->GetList( |
| 59 WebResourceService::kTipCachePrefName, &wr_list) && | 59 WebResourceService::kTipCachePrefName, &wr_list) && |
| 60 wr_list && wr_list->GetSize() > 0) { | 60 wr_list && wr_list->GetSize() > 0) { |
| 61 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) | 61 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) |
| 62 current_tip_index = 0; | 62 current_tip_index = 0; |
| 63 if (wr_list->GetString(current_tip_index, ¤t_tip)) { | 63 if (wr_list->GetString(current_tip_index, ¤t_tip)) { |
| 64 DictionaryValue* tip_dict = new DictionaryValue(); | 64 DictionaryValue* tip_dict = new DictionaryValue(); |
| 65 tip_dict->SetString(L"tip_html_text", current_tip); | 65 tip_dict->SetString(L"tip_html_text", current_tip); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 79 prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); | 79 prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); |
| 80 prefs->RegisterStringPref(prefs::kNTPTipsServer, | 80 prefs->RegisterStringPref(prefs::kNTPTipsServer, |
| 81 WebResourceService::kDefaultResourceServer); | 81 WebResourceService::kDefaultResourceServer); |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool TipsHandler::IsValidURL(const std::wstring& url_string) { | 84 bool TipsHandler::IsValidURL(const std::wstring& url_string) { |
| 85 GURL url(WideToUTF8(url_string)); | 85 GURL url(WideToUTF8(url_string)); |
| 86 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || | 86 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || |
| 87 url.SchemeIs(chrome::kHttpsScheme)); | 87 url.SchemeIs(chrome::kHttpsScheme)); |
| 88 } | 88 } |
| OLD | NEW |