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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs(); | 47 PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs(); |
48 if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) { | 48 if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) { |
49 std::string server = current_prefs->GetString(prefs::kNTPTipsServer); | 49 std::string server = current_prefs->GetString(prefs::kNTPTipsServer); |
50 std::string locale = g_browser_process->GetApplicationLocale(); | 50 std::string locale = g_browser_process->GetApplicationLocale(); |
51 if (!EndsWith(server, locale, false)) { | 51 if (!EndsWith(server, locale, false)) { |
52 dom_ui_->CallJavascriptFunction(L"tips", list_value); | 52 dom_ui_->CallJavascriptFunction(L"tips", list_value); |
53 return; | 53 return; |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 // If the user has just started using Chrome with a fresh profile, send only | |
58 // the "Import bookmarks" promo until the user has either seen it five times | |
59 // or added or imported bookmarks. | |
60 if (current_prefs->GetInteger(prefs::kNTPPromoViewsRemaining) > 0) { | |
61 SendTip(WideToUTF8(l10n_util::GetStringF(IDS_IMPORT_BOOKMARKS_PROMO, | |
62 std::wstring(L"<button class='link'>"), | |
63 std::wstring(L"</button>"))), | |
64 L"set_promo_tip", 0); | |
65 return; | |
66 } | |
67 | |
68 if (tips_cache_ != NULL && !tips_cache_->empty()) { | 57 if (tips_cache_ != NULL && !tips_cache_->empty()) { |
69 if (tips_cache_->GetInteger( | 58 if (tips_cache_->GetInteger( |
70 WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && | 59 WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && |
71 tips_cache_->GetList( | 60 tips_cache_->GetList( |
72 WebResourceService::kTipCachePrefName, &wr_list) && | 61 WebResourceService::kTipCachePrefName, &wr_list) && |
73 wr_list && wr_list->GetSize() > 0) { | 62 wr_list && wr_list->GetSize() > 0) { |
74 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) { | 63 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) { |
75 // Check to see whether the home page is set to NTP; if not, add tip | 64 // Check to see whether the home page is set to NTP; if not, add tip |
76 // to set home page before resetting tip index to 0. | 65 // to set home page before resetting tip index to 0. |
77 current_tip_index = 0; | 66 current_tip_index = 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); | 101 prefs->RegisterDictionaryPref(prefs::kNTPTipsCache); |
113 prefs->RegisterStringPref(prefs::kNTPTipsServer, | 102 prefs->RegisterStringPref(prefs::kNTPTipsServer, |
114 WebResourceService::kDefaultResourceServer); | 103 WebResourceService::kDefaultResourceServer); |
115 } | 104 } |
116 | 105 |
117 bool TipsHandler::IsValidURL(const std::wstring& url_string) { | 106 bool TipsHandler::IsValidURL(const std::wstring& url_string) { |
118 GURL url(WideToUTF8(url_string)); | 107 GURL url(WideToUTF8(url_string)); |
119 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || | 108 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || |
120 url.SchemeIs(chrome::kHttpsScheme)); | 109 url.SchemeIs(chrome::kHttpsScheme)); |
121 } | 110 } |
OLD | NEW |