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

Unified Diff: chrome/browser/dom_ui/new_tab_ui.cc

Issue 411004: Special case the gallery to not show the scary download roadblock. (Closed)
Patch Set: add comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/dom_ui/new_tab_ui.cc
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index b11d7b425407ff21a843f8779fd39db5c71c094f..b48e0c13180cb0dce248ca8144fc385cb24c8ac9 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -29,6 +29,8 @@
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -686,3 +688,213 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path,
SendResponse(request_id, html_bytes);
}
+
+// static
+std::string NewTabUI::NewTabHTMLSource::GetCustomNewTabPageFromCommandLine() {
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ const std::wstring file_path_wstring = command_line->GetSwitchValue(
+ switches::kNewTabPage);
+
+#if defined(OS_WIN)
+ const FilePath::StringType file_path = file_path_wstring;
+#else
+ const FilePath::StringType file_path = WideToASCII(file_path_wstring);
+#endif
+
+ if (!file_path.empty()) {
+ // Read the file contents in, blocking the UI thread of the browser.
+ // This is for testing purposes only! It is used to test new versions of
+ // the new tab page using a special command line option. Never use this
+ // in a way that will be used by default in product.
+ std::string file_contents;
+ if (file_util::ReadFileToString(FilePath(file_path), &file_contents))
+ return file_contents;
+ }
+
+ return std::string();
+}
+
+void NewTabUI::NewTabHTMLSource::InitFullHTML(Profile* profile) {
+ // Show the profile name in the title and most visited labels if the current
+ // profile is not the default.
+ std::wstring title;
+ std::wstring most_visited;
+ if (UserDataManager::Get()->is_current_profile_default()) {
+ title = l10n_util::GetString(IDS_NEW_TAB_TITLE);
+ most_visited = l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED);
+ } else {
+ // Get the current profile name.
+ std::wstring profile_name =
+ UserDataManager::Get()->current_profile_name();
+ title = l10n_util::GetStringF(IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME,
+ profile_name);
+ most_visited = l10n_util::GetStringF(
+ IDS_NEW_TAB_MOST_VISITED_WITH_PROFILE_NAME,
+ profile_name);
+ }
+ DictionaryValue localized_strings;
+ localized_strings.SetString(L"bookmarkbarattached",
+ profile->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ?
+ "true" : "false");
+ localized_strings.SetString(L"hasattribution",
+ profile->GetThemeProvider()->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ?
+ "true" : "false");
+ localized_strings.SetString(L"title", title);
+ localized_strings.SetString(L"mostvisited", most_visited);
+ localized_strings.SetString(L"searches",
+ l10n_util::GetString(IDS_NEW_TAB_SEARCHES));
+ localized_strings.SetString(L"bookmarks",
+ l10n_util::GetString(IDS_NEW_TAB_BOOKMARKS));
+ localized_strings.SetString(L"recent",
+ l10n_util::GetString(IDS_NEW_TAB_RECENT));
+ localized_strings.SetString(L"showhistory",
+ l10n_util::GetString(IDS_NEW_TAB_HISTORY_SHOW));
+ localized_strings.SetString(L"showhistoryurl",
+ chrome::kChromeUIHistoryURL);
+ localized_strings.SetString(L"editthumbnails",
+ l10n_util::GetString(IDS_NEW_TAB_REMOVE_THUMBNAILS));
+ localized_strings.SetString(L"restorethumbnails",
+ l10n_util::GetString(IDS_NEW_TAB_RESTORE_THUMBNAILS_LINK));
+ localized_strings.SetString(L"editmodeheading",
+ l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED_EDIT_MODE_HEADING));
+ localized_strings.SetString(L"doneediting",
+ l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED_DONE_REMOVING_BUTTON));
+ localized_strings.SetString(L"cancelediting",
+ l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED_CANCEL_REMOVING_BUTTON));
+ localized_strings.SetString(L"searchhistory",
+ l10n_util::GetString(IDS_NEW_TAB_HISTORY_SEARCH));
+ localized_strings.SetString(L"recentlyclosed",
+ l10n_util::GetString(IDS_NEW_TAB_RECENTLY_CLOSED));
+ localized_strings.SetString(L"mostvisitedintro",
+ l10n_util::GetStringF(IDS_NEW_TAB_MOST_VISITED_INTRO,
+ l10n_util::GetString(IDS_WELCOME_PAGE_URL)));
+ localized_strings.SetString(L"closedwindowsingle",
+ l10n_util::GetString(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE));
+ localized_strings.SetString(L"closedwindowmultiple",
+ l10n_util::GetString(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE));
+ localized_strings.SetString(L"attributionintro",
+ l10n_util::GetString(IDS_NEW_TAB_ATTRIBUTION_INTRO));
+ localized_strings.SetString(L"viewfullhistory",
+ l10n_util::GetString(IDS_NEW_TAB_VIEW_FULL_HISTORY));
+ localized_strings.SetString(L"showthumbnails",
+ l10n_util::GetString(IDS_NEW_TAB_SHOW_THUMBNAILS));
+ localized_strings.SetString(L"hidethumbnails",
+ l10n_util::GetString(IDS_NEW_TAB_HIDE_THUMBNAILS));
+ localized_strings.SetString(L"showlist",
+ l10n_util::GetString(IDS_NEW_TAB_SHOW_LIST));
+ localized_strings.SetString(L"hidelist",
+ l10n_util::GetString(IDS_NEW_TAB_HIDE_LIST));
+ localized_strings.SetString(L"showrecentlyclosedtabs",
+ l10n_util::GetString(IDS_NEW_TAB_SHOW_RECENTLY_CLOSED_TABS));
+ localized_strings.SetString(L"hiderecentlyclosedtabs",
+ l10n_util::GetString(IDS_NEW_TAB_HIDE_RECENTLY_CLOSED_TABS));
+ localized_strings.SetString(L"thumbnailremovednotification",
+ l10n_util::GetString(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION));
+ localized_strings.SetString(L"undothumbnailremove",
+ l10n_util::GetString(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE));
+ localized_strings.SetString(L"otrmessage",
+ l10n_util::GetString(IDS_NEW_TAB_OTR_MESSAGE));
+ localized_strings.SetString(L"removethumbnailtooltip",
+ l10n_util::GetString(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP));
+ localized_strings.SetString(L"pinthumbnailtooltip",
+ l10n_util::GetString(IDS_NEW_TAB_PIN_THUMBNAIL_TOOLTIP));
+ localized_strings.SetString(L"unpinthumbnailtooltip",
+ l10n_util::GetString(IDS_NEW_TAB_UNPIN_THUMBNAIL_TOOLTIP));
+ localized_strings.SetString(L"showhidethumbnailtooltip",
+ l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_THUMBNAIL_TOOLTIP));
+ localized_strings.SetString(L"showhidelisttooltip",
+ l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_LIST_TOOLTIP));
+ localized_strings.SetString(L"pagedisplaytooltip",
+ l10n_util::GetString(IDS_NEW_TAB_PAGE_DISPLAY_TOOLTIP));
+ localized_strings.SetString(L"firstrunnotification",
+ l10n_util::GetString(IDS_NEW_TAB_FIRST_RUN_NOTIFICATION));
+ localized_strings.SetString(L"closefirstrunnotification",
+ l10n_util::GetString(IDS_NEW_TAB_CLOSE_FIRST_RUN_NOTIFICATION));
+ localized_strings.SetString(L"makethishomepage",
+ l10n_util::GetString(IDS_NEW_TAB_MAKE_THIS_HOMEPAGE));
+ localized_strings.SetString(L"themelink",
+ l10n_util::GetString(IDS_THEMES_GALLERY_URL));
+ localized_strings.SetString(L"tips",
+ l10n_util::GetString(IDS_NEW_TAB_TIPS));
+ localized_strings.SetString(L"sync",
+ l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_BOOKMARK_SYNC));
+ localized_strings.SetString(L"promonew",
+ l10n_util::GetString(IDS_NTP_PROMOTION_NEW));
+ localized_strings.SetString(L"promomessage",
+ l10n_util::GetStringF(IDS_NTP_PROMOTION_MESSAGE,
+ l10n_util::GetString(IDS_PRODUCT_NAME),
+ ASCIIToWide(extension_urls::kGalleryBrowsePrefix),
+ l10n_util::GetString(IDS_SYNC_SERVICE_HELP_URL)));
+ localized_strings.SetString(L"extensionslink",
+ ASCIIToWide(extension_urls::kGalleryBrowsePrefix));
+
+ // Don't initiate the sync related message passing with the page if the sync
+ // code is not present.
+ if (profile->GetProfileSyncService())
+ localized_strings.SetString(L"syncispresent", "true");
+ else
+ localized_strings.SetString(L"syncispresent", "false");
+
+ if (!profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
+ localized_strings.SetString(L"showsetashomepage", "true");
+
+ SetFontAndTextDirection(&localized_strings);
+
+ // Let the tab know whether it's the first tab being viewed.
+ if (first_view_) {
+ // Decrement ntp promo counters; the default values are specified in
+ // Browser::RegisterUserPrefs.
+ profile->GetPrefs()->SetInteger(prefs::kNTPPromoLineRemaining,
+ profile->GetPrefs()->GetInteger(prefs::kNTPPromoLineRemaining) - 1);
+ profile->GetPrefs()->SetInteger(prefs::kNTPPromoImageRemaining,
+ profile->GetPrefs()->GetInteger(prefs::kNTPPromoImageRemaining) - 1);
+ first_view_ = false;
+ }
+
+ // Control fade and resize animations.
+ std::wstring anim =
+ Animation::ShouldRenderRichAnimation() ? L"true" : L"false";
+ localized_strings.SetString(L"anim", anim);
+
+ // Pass the shown_sections pref early so that we can prevent flicker.
+ const int shown_sections = profile->GetPrefs()->GetInteger(
+ prefs::kNTPShownSections);
+ localized_strings.SetInteger(L"shown_sections", shown_sections);
+
+ // In case we have the new new tab page enabled we first try to read the file
+ // provided on the command line. If that fails we just get the resource from
+ // the resource bundle.
+ base::StringPiece new_tab_html;
+ std::string new_tab_html_str;
+ new_tab_html_str = GetCustomNewTabPageFromCommandLine();
+
+ if (!new_tab_html_str.empty()) {
+ new_tab_html = base::StringPiece(new_tab_html_str);
+ }
+
+ if (new_tab_html.empty()) {
+ new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_NEW_NEW_TAB_HTML);
+ }
+
+ // Inject the template data into the HTML so that it is available before any
+ // layout is needed.
+ std::string json_html;
+ jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html);
+
+ static const base::StringPiece template_data_placeholder(
+ "<!-- template data placeholder -->");
+ size_t pos = new_tab_html.find(template_data_placeholder);
+
+ if (pos != base::StringPiece::npos) {
+ full_html_.assign(new_tab_html.data(), pos);
+ full_html_.append(json_html);
+ size_t after_offset = pos + template_data_placeholder.size();
+ full_html_.append(new_tab_html.data() + after_offset,
+ new_tab_html.size() - after_offset);
+ } else {
+ NOTREACHED();
+ full_html_.assign(new_tab_html.data(), new_tab_html.size());
+ }
+ jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_);
+}
« no previous file with comments | « no previous file | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698