| 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/dom_ui/tips_handler.h" | 8 #include "chrome/browser/dom_ui/tips_handler.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/web_resource/web_resource_service.h" | 10 #include "chrome/browser/web_resource/web_resource_service.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 if (!EndsWith(server, locale, false)) { | 47 if (!EndsWith(server, locale, false)) { |
| 48 dom_ui_->CallJavascriptFunction(L"tips", list_value); | 48 dom_ui_->CallJavascriptFunction(L"tips", list_value); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 if (tips_cache_ != NULL && tips_cache_->GetSize() >= 0) { | 53 if (tips_cache_ != NULL && tips_cache_->GetSize() >= 0) { |
| 54 if (tips_cache_->GetInteger( | 54 if (tips_cache_->GetInteger( |
| 55 WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && | 55 WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && |
| 56 tips_cache_->GetList( | 56 tips_cache_->GetList( |
| 57 WebResourceService::kTipCachePrefName, &wr_list)) { | 57 WebResourceService::kTipCachePrefName, &wr_list) && |
| 58 if (wr_list && wr_list->GetSize() > 0) | 58 wr_list && wr_list->GetSize() > 0) { |
| 59 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) | 59 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) |
| 60 current_tip_index = 0; | 60 current_tip_index = 0; |
| 61 if (wr_list->GetString(current_tip_index, ¤t_tip)) { | 61 if (wr_list->GetString(current_tip_index, ¤t_tip)) { |
| 62 DictionaryValue* tip_dict = new DictionaryValue(); | 62 DictionaryValue* tip_dict = new DictionaryValue(); |
| 63 tip_dict->SetString(L"tip_html_text", current_tip); | 63 tip_dict->SetString(L"tip_html_text", current_tip); |
| 64 list_value.Append(tip_dict); | 64 list_value.Append(tip_dict); |
| 65 tips_cache_->SetInteger(WebResourceService::kCurrentTipPrefName, | 65 tips_cache_->SetInteger(WebResourceService::kCurrentTipPrefName, |
| 66 current_tip_index + 1); | 66 current_tip_index + 1); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Send list of web resource items back out to the DOM. | 71 // Send list of web resource items back out to the DOM. |
| 72 dom_ui_->CallJavascriptFunction(L"tips", list_value); | 72 dom_ui_->CallJavascriptFunction(L"tips", list_value); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 void TipsHandler::RegisterUserPrefs(PrefService* prefs) { | 76 void TipsHandler::RegisterUserPrefs(PrefService* prefs) { |
| 77 prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); | 77 prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); |
| 78 prefs->RegisterStringPref(prefs::kNTPTipsServer, | 78 prefs->RegisterStringPref(prefs::kNTPTipsServer, |
| 79 WebResourceService::kDefaultResourceServer); | 79 WebResourceService::kDefaultResourceServer); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool TipsHandler::IsValidURL(const std::wstring& url_string) { | 82 bool TipsHandler::IsValidURL(const std::wstring& url_string) { |
| 83 GURL url(WideToUTF8(url_string)); | 83 GURL url(WideToUTF8(url_string)); |
| 84 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || | 84 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || |
| 85 url.SchemeIs(chrome::kHttpsScheme)); | 85 url.SchemeIs(chrome::kHttpsScheme)); |
| 86 } | 86 } |
| 87 | |
| OLD | NEW |