Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/browser/dom_ui/tips_handler.cc

Issue 258037: Fix tips in OS X to respect system language settings instead of locale.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
21 GetMutableDictionary(prefs::kNTPTipsCache); 21 GetMutableDictionary(prefs::kNTPTipsCache);
22 return DOMMessageHandler::Attach(dom_ui); 22 return DOMMessageHandler::Attach(dom_ui);
23 } 23 }
24 24
25 void TipsHandler::RegisterMessages() { 25 void TipsHandler::RegisterMessages() {
26 dom_ui_->RegisterMessageCallback("getTips", 26 dom_ui_->RegisterMessageCallback("getTips",
27 NewCallback(this, &TipsHandler::HandleGetTips)); 27 NewCallback(this, &TipsHandler::HandleGetTips));
28 } 28 }
29 29
30 void TipsHandler::HandleGetTips(const Value* content) { 30 void TipsHandler::HandleGetTips(const Value* content) {
31 // List containing the tips to be displayed. 31 // List containing the tips to be displayed.
32 ListValue list_value; 32 ListValue list_value;
33 33
34 // Holds the web resource data found in the preferences cache. 34 // Holds the web resource data found in the preferences cache.
35 ListValue* wr_list; 35 ListValue* wr_list;
36 36
37 // These values hold the data for each web resource item. 37 // These values hold the data for each web resource item.
38 int current_tip_index; 38 int current_tip_index;
39 std::string current_tip; 39 std::string current_tip;
40 40
41 // If tips are not correct for our locale, do not send. Wait for update. 41 // If tips are not correct for our language, do not send. Wait for update.
42 // We need to check here because the new tab page calls for tips before 42 // We need to check here because the new tab page calls for tips before
43 // the tip service starts up. 43 // the tip service starts up.
44 PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs(); 44 PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs();
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 = ASCIIToWide( 47 std::wstring tips_language = WebResourceService::GetWebResourceLanguage(
48 g_browser_process->GetApplicationLocale()); 48 current_prefs);
49 if (!EndsWith(server, locale, false)) { 49 if (!EndsWith(server, tips_language, 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_->GetSize() != 0) {
56 if (tips_cache_->GetInteger( 56 if (tips_cache_->GetInteger(
57 WebResourceService::kCurrentTipPrefName, &current_tip_index) && 57 WebResourceService::kCurrentTipPrefName, &current_tip_index) &&
58 tips_cache_->GetList( 58 tips_cache_->GetList(
59 WebResourceService::kTipCachePrefName, &wr_list) && 59 WebResourceService::kTipCachePrefName, &wr_list) &&
(...skipping 19 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/web_resource/web_resource_service.h » ('j') | chrome/browser/web_resource/web_resource_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698