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

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_page_handler.cc

Issue 7461160: ntp4 info bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: arv review Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
6 6
7 #include "chrome/common/pref_names.h" 7 #include "chrome/common/pref_names.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/profile_sync_service.h" 10 #include "chrome/browser/sync/profile_sync_service.h"
11 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 11 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/common/notification_service.h" 13 #include "content/common/notification_service.h"
14 #include "grit/chromium_strings.h"
15 #include "ui/base/l10n/l10n_util.h"
16
17 static const int kIntroDisplayMax = 10;
14 18
15 void NewTabPageHandler::RegisterMessages() { 19 void NewTabPageHandler::RegisterMessages() {
16 web_ui_->RegisterMessageCallback("closePromo", NewCallback( 20 web_ui_->RegisterMessageCallback("closePromo", NewCallback(
17 this, &NewTabPageHandler::HandleClosePromo)); 21 this, &NewTabPageHandler::HandleClosePromo));
18 web_ui_->RegisterMessageCallback("closeSyncNotification", NewCallback( 22 web_ui_->RegisterMessageCallback("closeSyncNotification", NewCallback(
19 this, &NewTabPageHandler::HandleCloseSyncNotification)); 23 this, &NewTabPageHandler::HandleCloseSyncNotification));
20 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( 24 web_ui_->RegisterMessageCallback("pageSelected", NewCallback(
21 this, &NewTabPageHandler::HandlePageSelected)); 25 this, &NewTabPageHandler::HandlePageSelected));
26 web_ui_->RegisterMessageCallback("navigationDotUsed", NewCallback(
27 this, &NewTabPageHandler::HandleNavDotUsed));
28 web_ui_->RegisterMessageCallback("introMessageSeen", NewCallback(
29 this, &NewTabPageHandler::HandleIntroMessageSeen));
22 } 30 }
23 31
24 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { 32 void NewTabPageHandler::HandleClosePromo(const ListValue* args) {
25 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, 33 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed,
26 true); 34 true);
27 NotificationService* service = NotificationService::current(); 35 NotificationService* service = NotificationService::current();
28 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 36 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
29 Source<NewTabPageHandler>(this), 37 Source<NewTabPageHandler>(this),
30 NotificationService::NoDetails()); 38 NotificationService::NoDetails());
31 } 39 }
(...skipping 11 matching lines...) Expand all
43 int page_id = static_cast<int>(page_id_double); 51 int page_id = static_cast<int>(page_id_double);
44 52
45 double index_double; 53 double index_double;
46 CHECK(args->GetDouble(1, &index_double)); 54 CHECK(args->GetDouble(1, &index_double));
47 int index = static_cast<int>(index_double); 55 int index = static_cast<int>(index_double);
48 56
49 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); 57 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
50 prefs->SetInteger(prefs::kNTPShownPage, page_id | index); 58 prefs->SetInteger(prefs::kNTPShownPage, page_id | index);
51 } 59 }
52 60
61 void NewTabPageHandler::HandleNavDotUsed(const ListValue* args) {
62 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
63 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1);
64 }
65
66 void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) {
67 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
68 int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount);
69 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays + 1);
70 }
71
53 // static 72 // static
54 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { 73 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) {
55 // TODO(estade): should be syncable. 74 // TODO(estade): should be syncable.
56 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID, 75 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID,
57 PrefService::UNSYNCABLE_PREF); 76 PrefService::UNSYNCABLE_PREF);
77 prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0,
78 PrefService::UNSYNCABLE_PREF);
58 } 79 }
59 80
60 // static 81 // static
61 void NewTabPageHandler::GetLocalizedValues(Profile* profile, 82 void NewTabPageHandler::GetLocalizedValues(Profile* profile,
62 DictionaryValue* values) { 83 DictionaryValue* values) {
63 if (!NewTabUI::Ntp4Enabled()) 84 if (!NewTabUI::Ntp4Enabled())
64 return; 85 return;
65 86
66 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); 87 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID);
67 values->SetInteger("apps_page_id", APPS_PAGE_ID); 88 values->SetInteger("apps_page_id", APPS_PAGE_ID);
68 values->SetInteger("bookmarks_page_id", BOOKMARKS_PAGE_ID); 89 values->SetInteger("bookmarks_page_id", BOOKMARKS_PAGE_ID);
69 90
70 PrefService* prefs = profile->GetPrefs(); 91 PrefService* prefs = profile->GetPrefs();
71 int shown_page = prefs->GetInteger(prefs::kNTPShownPage); 92 int shown_page = prefs->GetInteger(prefs::kNTPShownPage);
72 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); 93 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK);
73 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); 94 values->SetInteger("shown_page_index", shown_page & INDEX_MASK);
95
96 int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount);
97 if (intro_displays <= kIntroDisplayMax) {
98 values->SetString("ntp4_intro_message",
99 l10n_util::GetStringUTF16(IDS_NTP4_INTRO_MESSAGE));
100 }
74 } 101 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_page_handler.h ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698