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

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

Issue 394005: Add message and image to NTP to promote extensions and bookmark sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/dom_ui/new_tab_ui.h" 7 #include "chrome/browser/dom_ui/new_tab_ui.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 static const base::StringPiece incognito_tab_html( 193 static const base::StringPiece incognito_tab_html(
194 ResourceBundle::GetSharedInstance().GetRawDataResource( 194 ResourceBundle::GetSharedInstance().GetRawDataResource(
195 IDR_INCOGNITO_TAB_HTML)); 195 IDR_INCOGNITO_TAB_HTML));
196 196
197 full_html_ = jstemplate_builder::GetI18nTemplateHtml(incognito_tab_html, 197 full_html_ = jstemplate_builder::GetI18nTemplateHtml(incognito_tab_html,
198 &localized_strings); 198 &localized_strings);
199 } 199 }
200 200
201 /////////////////////////////////////////////////////////////////////////////// 201 ///////////////////////////////////////////////////////////////////////////////
202 // PromotionalMessageHandler
203
204 class PromotionalMessageHandler : public DOMMessageHandler {
205 public:
206 PromotionalMessageHandler() {}
207 virtual ~PromotionalMessageHandler() {}
208
209 // DOMMessageHandler implementation.
210 virtual void RegisterMessages();
211
212 // Zero promotional message counter.
213 void HandleClosePromotionalMessage(const Value* content);
214
215 private:
216 DISALLOW_COPY_AND_ASSIGN(PromotionalMessageHandler);
217 };
218
219 void PromotionalMessageHandler::RegisterMessages() {
220 dom_ui_->RegisterMessageCallback("stopPromoMessages",
221 NewCallback(this,
222 &PromotionalMessageHandler::HandleClosePromotionalMessage));
223 }
224
225 void PromotionalMessageHandler::HandleClosePromotionalMessage(
226 const Value* content) {
227 dom_ui_->GetProfile()->GetPrefs()->SetInteger(prefs::kNTPPromoRemaining, 0);
228 }
229
230
231 ///////////////////////////////////////////////////////////////////////////////
202 // RecentlyClosedTabsHandler 232 // RecentlyClosedTabsHandler
203 233
204 class RecentlyClosedTabsHandler : public DOMMessageHandler, 234 class RecentlyClosedTabsHandler : public DOMMessageHandler,
205 public TabRestoreService::Observer { 235 public TabRestoreService::Observer {
206 public: 236 public:
207 RecentlyClosedTabsHandler() : tab_restore_service_(NULL) {} 237 RecentlyClosedTabsHandler() : tab_restore_service_(NULL) {}
208 virtual ~RecentlyClosedTabsHandler(); 238 virtual ~RecentlyClosedTabsHandler();
209 239
210 // DOMMessageHandler implementation. 240 // DOMMessageHandler implementation.
211 virtual void RegisterMessages(); 241 virtual void RegisterMessages();
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 AddMessageHandler((new MostVisitedHandler())->Attach(this)); 592 AddMessageHandler((new MostVisitedHandler())->Attach(this));
563 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); 593 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this));
564 AddMessageHandler((new MetricsHandler())->Attach(this)); 594 AddMessageHandler((new MetricsHandler())->Attach(this));
565 if (WebResourcesEnabled()) 595 if (WebResourcesEnabled())
566 AddMessageHandler((new TipsHandler())->Attach(this)); 596 AddMessageHandler((new TipsHandler())->Attach(this));
567 if (ProfileSyncService::IsSyncEnabled()) { 597 if (ProfileSyncService::IsSyncEnabled()) {
568 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); 598 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this));
569 } 599 }
570 600
571 AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); 601 AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this));
602 AddMessageHandler((new PromotionalMessageHandler())->Attach(this));
572 603
573 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); 604 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile());
574 bool posted = ChromeThread::PostTask( 605 bool posted = ChromeThread::PostTask(
575 ChromeThread::IO, FROM_HERE, 606 ChromeThread::IO, FROM_HERE,
576 NewRunnableMethod( 607 NewRunnableMethod(
577 Singleton<ChromeURLDataManager>::get(), 608 Singleton<ChromeURLDataManager>::get(),
578 &ChromeURLDataManager::AddDataSource, 609 &ChromeURLDataManager::AddDataSource,
579 html_source)); 610 html_source));
580 if (!posted) { 611 if (!posted) {
581 html_source->AddRef(); 612 html_source->AddRef();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 localized_strings.SetString(L"closefirstrunnotification", 907 localized_strings.SetString(L"closefirstrunnotification",
877 l10n_util::GetString(IDS_NEW_TAB_CLOSE_FIRST_RUN_NOTIFICATION)); 908 l10n_util::GetString(IDS_NEW_TAB_CLOSE_FIRST_RUN_NOTIFICATION));
878 localized_strings.SetString(L"makethishomepage", 909 localized_strings.SetString(L"makethishomepage",
879 l10n_util::GetString(IDS_NEW_TAB_MAKE_THIS_HOMEPAGE)); 910 l10n_util::GetString(IDS_NEW_TAB_MAKE_THIS_HOMEPAGE));
880 localized_strings.SetString(L"themelink", 911 localized_strings.SetString(L"themelink",
881 l10n_util::GetString(IDS_THEMES_GALLERY_URL)); 912 l10n_util::GetString(IDS_THEMES_GALLERY_URL));
882 localized_strings.SetString(L"tips", 913 localized_strings.SetString(L"tips",
883 l10n_util::GetString(IDS_NEW_TAB_TIPS)); 914 l10n_util::GetString(IDS_NEW_TAB_TIPS));
884 localized_strings.SetString(L"sync", 915 localized_strings.SetString(L"sync",
885 l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_BOOKMARK_SYNC)); 916 l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_BOOKMARK_SYNC));
917 localized_strings.SetString(L"promonew",
918 l10n_util::GetString(IDS_NTP_PROMOTION_NEW));
919 localized_strings.SetString(L"promomessage",
920 l10n_util::GetStringF(IDS_NTP_PROMOTION_MESSAGE,
921 l10n_util::GetString(IDS_PRODUCT_NAME),
922 ASCIIToWide(Extension::kGalleryBrowseUrl),
923 l10n_util::GetString(IDS_SYNC_SERVICE_HELP_URL)));
924 localized_strings.SetString(L"extensionslink",
925 ASCIIToWide(Extension::kGalleryBrowseUrl));
886 926
887 // Don't initiate the sync related message passing with the page if the sync 927 // Don't initiate the sync related message passing with the page if the sync
888 // code is not present. 928 // code is not present.
889 if (profile->GetProfileSyncService()) 929 if (profile->GetProfileSyncService())
890 localized_strings.SetString(L"syncispresent", "true"); 930 localized_strings.SetString(L"syncispresent", "true");
891 else 931 else
892 localized_strings.SetString(L"syncispresent", "false"); 932 localized_strings.SetString(L"syncispresent", "false");
893 933
894 if (!profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) 934 if (!profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
895 localized_strings.SetString(L"showsetashomepage", "true"); 935 localized_strings.SetString(L"showsetashomepage", "true");
896 936
897 SetFontAndTextDirection(&localized_strings); 937 SetFontAndTextDirection(&localized_strings);
898 938
899 // Let the tab know whether it's the first tab being viewed. 939 // Let the tab know whether it's the first tab being viewed.
900 if (first_view_) { 940 if (first_view_) {
901 localized_strings.SetString(L"firstview", L"true"); 941 localized_strings.SetString(L"firstview", L"true");
902 942
903 // Decrement ntp promo counter; the default value is specified in 943 // Decrement ntp promo counter; the default value is specified in
904 // Browser::RegisterUserPrefs. 944 // Browser::RegisterUserPrefs.
905 profile->GetPrefs()->SetInteger(prefs::kNTPThemePromoRemaining, 945 profile->GetPrefs()->SetInteger(prefs::kNTPPromoRemaining,
906 profile->GetPrefs()->GetInteger(prefs::kNTPThemePromoRemaining) - 1); 946 profile->GetPrefs()->GetInteger(prefs::kNTPPromoRemaining) - 1);
907 first_view_ = false; 947 first_view_ = false;
908 } 948 }
909 949
910 // Control fade and resize animations. 950 // Control fade and resize animations.
911 std::wstring anim = 951 std::wstring anim =
912 Animation::ShouldRenderRichAnimation() ? L"true" : L"false"; 952 Animation::ShouldRenderRichAnimation() ? L"true" : L"false";
913 localized_strings.SetString(L"anim", anim); 953 localized_strings.SetString(L"anim", anim);
914 954
915 // Pass the shown_sections pref early so that we can prevent flicker. 955 // Pass the shown_sections pref early so that we can prevent flicker.
916 const int shown_sections = profile->GetPrefs()->GetInteger( 956 const int shown_sections = profile->GetPrefs()->GetInteger(
(...skipping 30 matching lines...) Expand all
947 full_html_.append(json_html); 987 full_html_.append(json_html);
948 size_t after_offset = pos + template_data_placeholder.size(); 988 size_t after_offset = pos + template_data_placeholder.size();
949 full_html_.append(new_tab_html.data() + after_offset, 989 full_html_.append(new_tab_html.data() + after_offset,
950 new_tab_html.size() - after_offset); 990 new_tab_html.size() - after_offset);
951 } else { 991 } else {
952 NOTREACHED(); 992 NOTREACHED();
953 full_html_.assign(new_tab_html.data(), new_tab_html.size()); 993 full_html_.assign(new_tab_html.data(), new_tab_html.size());
954 } 994 }
955 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); 995 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_);
956 } 996 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698