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

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

Issue 199073: Ensure that tips change when the Chrome language changes.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/web_resource/web_resource_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/dom_ui/tips_handler.h" 8 #include "chrome/browser/dom_ui/tips_handler.h"
8 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
9 #include "chrome/browser/web_resource/web_resource_service.h" 10 #include "chrome/browser/web_resource/web_resource_service.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
11 #include "chrome/common/web_resource/web_resource_unpacker.h" 12 #include "chrome/common/web_resource/web_resource_unpacker.h"
12 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 15
15 DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) { 16 DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) {
16 dom_ui_ = dom_ui; 17 dom_ui_ = dom_ui;
(...skipping 11 matching lines...) Expand all
28 // List containing the tips to be displayed. 29 // List containing the tips to be displayed.
29 ListValue list_value; 30 ListValue list_value;
30 31
31 // Holds the web resource data found in the preferences cache. 32 // Holds the web resource data found in the preferences cache.
32 ListValue* wr_list; 33 ListValue* wr_list;
33 34
34 // These values hold the data for each web resource item. 35 // These values hold the data for each web resource item.
35 int current_tip_index; 36 int current_tip_index;
36 std::string current_tip; 37 std::string current_tip;
37 38
39 // If tips are not correct for our locale, do not send. Wait for update.
40 // We need to check here because the new tab page calls for tips before
41 // the tip service starts up.
42 PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs();
43 if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) {
44 std::wstring server = current_prefs->GetString(prefs::kNTPTipsServer);
45 std::wstring locale = ASCIIToWide(
46 g_browser_process->GetApplicationLocale());
47 if (!EndsWith(server, locale, false)) {
48 dom_ui_->CallJavascriptFunction(L"tips", list_value);
49 return;
50 }
51 }
52
38 if (tips_cache_ != NULL && tips_cache_->GetSize() >= 0) { 53 if (tips_cache_ != NULL && tips_cache_->GetSize() >= 0) {
39 if (tips_cache_->GetInteger( 54 if (tips_cache_->GetInteger(
40 WebResourceService::kCurrentTipPrefName, &current_tip_index) && 55 WebResourceService::kCurrentTipPrefName, &current_tip_index) &&
41 tips_cache_->GetList( 56 tips_cache_->GetList(
42 WebResourceService::kTipCachePrefName, &wr_list)) { 57 WebResourceService::kTipCachePrefName, &wr_list)) {
43 if (wr_list && wr_list->GetSize() > 0) 58 if (wr_list && wr_list->GetSize() > 0)
44 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) 59 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index))
45 current_tip_index = 0; 60 current_tip_index = 0;
46 if (wr_list->GetString(current_tip_index, &current_tip)) { 61 if (wr_list->GetString(current_tip_index, &current_tip)) {
47 DictionaryValue* tip_dict = new DictionaryValue(); 62 DictionaryValue* tip_dict = new DictionaryValue();
(...skipping 15 matching lines...) Expand all
63 prefs->RegisterStringPref(prefs::kNTPTipsServer, 78 prefs->RegisterStringPref(prefs::kNTPTipsServer,
64 WebResourceService::kDefaultResourceServer); 79 WebResourceService::kDefaultResourceServer);
65 } 80 }
66 81
67 bool TipsHandler::IsValidURL(const std::wstring& url_string) { 82 bool TipsHandler::IsValidURL(const std::wstring& url_string) {
68 GURL url(WideToUTF8(url_string)); 83 GURL url(WideToUTF8(url_string));
69 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || 84 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) ||
70 url.SchemeIs(chrome::kHttpsScheme)); 85 url.SchemeIs(chrome::kHttpsScheme));
71 } 86 }
72 87
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/web_resource/web_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698