diff options
19 files changed, 218 insertions, 217 deletions
diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index fbcaa23..4a2d398 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -51,12 +51,6 @@ <include name="IDR_CONSTRAINED_TOP_RIGHT_CORNER_V" file="constrained_top_right_corner_v.png" type="BINDATA" /> <include name="IDR_COOKIE_ICON" file="cookie.png" type="BINDATA" /> <include name="IDR_COOKIE_STORAGE_ICON" file="cookie_storage.png" type="BINDATA" /> - <if expr="pp_ifdef('_google_chrome')"> - <include name="IDR_CUSTOM_PRODUCT_LOGO" file="google_chrome/alt_logo.gif" type="BINDATA" /> - </if> - <if expr="not pp_ifdef('_google_chrome')"> - <include name="IDR_CUSTOM_PRODUCT_LOGO" file="chromium/product_logo.png" type="BINDATA" /> - </if> <include name="IDR_CWS_STAR_EMPTY" file="cws_star_empty.png" type="BINDATA" /> <include name="IDR_CWS_STAR_FULL" file="cws_star_full.png" type="BINDATA" /> <include name="IDR_CWS_STAR_HALF" file="cws_star_half.png" type="BINDATA" /> diff --git a/chrome/browser/resources/ntp4/apps_page.js b/chrome/browser/resources/ntp4/apps_page.js index 9611b74..022b650 100644 --- a/chrome/browser/resources/ntp4/apps_page.js +++ b/chrome/browser/resources/ntp4/apps_page.js @@ -5,8 +5,6 @@ cr.define('ntp', function() { 'use strict'; - var localStrings = new LocalStrings; - var APP_LAUNCH = { // The histogram buckets (keep in sync with extension_constants.h). NTP_APPS_MAXIMIZED: 0, @@ -97,7 +95,7 @@ cr.define('ntp', function() { this.menu.appendChild(button); cr.ui.decorate(button, cr.ui.MenuItem); if (textId) - button.textContent = localStrings.getString(textId); + button.textContent = loadTimeData.getString(textId); return button; }, @@ -650,7 +648,7 @@ cr.define('ntp', function() { initialize: function() { this.classList.add('apps-page'); - if (templateData.appInstallHintEnabled) { + if (loadTimeData.getBoolean('appInstallHintEnabled')) { this.appInstallHint_ = $('app-install-hint-template').cloneNode(true); this.appInstallHint_.addEventListener('click', function(e) { chrome.send('recordAppLaunchByURL', diff --git a/chrome/browser/resources/ntp4/most_visited_page.js b/chrome/browser/resources/ntp4/most_visited_page.js index 008e490..32835492 100644 --- a/chrome/browser/resources/ntp4/most_visited_page.js +++ b/chrome/browser/resources/ntp4/most_visited_page.js @@ -63,7 +63,7 @@ cr.define('ntp', function() { '<span class="title"></span>'; this.querySelector('.close-button').title = - templateData.removethumbnailtooltip; + loadTimeData.getString('removethumbnailtooltip'); this.tabIndex = -1; this.data_ = null; @@ -175,18 +175,19 @@ cr.define('ntp', function() { var undo = { action: doUndo, - text: templateData.undothumbnailremove, + text: loadTimeData.getString('undothumbnailremove'), }; var undoAll = { action: function() { chrome.send('clearMostVisitedURLsBlacklist'); }, - text: templateData.restoreThumbnailsShort, + text: loadTimeData.getString('restoreThumbnailsShort'), }; - ntp.showNotification(templateData.thumbnailremovednotification, - [undo, undoAll]); + ntp.showNotification( + loadTimeData.getString('thumbnailremovednotification'), + [undo, undoAll]); }, /** diff --git a/chrome/browser/resources/ntp4/new_tab.html b/chrome/browser/resources/ntp4/new_tab.html index f698ec2..4e2d7ae 100644 --- a/chrome/browser/resources/ntp4/new_tab.html +++ b/chrome/browser/resources/ntp4/new_tab.html @@ -2,7 +2,6 @@ <html i18n-values=" dir:textdirection; hasattribution:hasattribution; - customlogo:customlogo; themegravity:themegravity; bookmarkbarattached:bookmarkbarattached;" class="starting-up"> @@ -36,7 +35,7 @@ <link id="themecss" rel="stylesheet"> <script src="../shared/js/event_tracker.js"></script> -<script src="../shared/js/local_strings.js"></script> +<script src="../shared/js/load_time_data.js"></script> <script src="../shared/js/parse_html_subset.js"></script> <script src="../shared/js/util.js"></script> @@ -101,7 +100,7 @@ <div id="footer"> <div id="footer-border"></div> <div id="footer-content"> - <img id="logo-img"> + <img id="logo-img" src="chrome://theme/IDR_PRODUCT_LOGO"> <ul id="dot-list"> </ul> @@ -141,7 +140,7 @@ <!-- NTP4 intro bubble --> <div id="ntp4-intro-bubble-contents"> - <div i18n-content="ntp4_intro_message"></div> + <div></div> <a i18n-content="learn_more" target="_blank"></a> </div> @@ -149,8 +148,8 @@ <div id="login-status-bubble-contents"> <div id="login-status-message-container"> <span i18n-content="login_status_message"></span> - <a id="login-status-learn-more" i18n-content="login_status_learn_more" - target="_blank"></a> + <a id="login-status-learn-more" i18n-content="learn_more" + i18n-values="href:login_status_url" target="_blank"></a> </div> <div class="login-status-row"> <div id="login-status-advanced-container"> diff --git a/chrome/browser/resources/ntp4/new_tab.js b/chrome/browser/resources/ntp4/new_tab.js index c434844..9ca130e 100644 --- a/chrome/browser/resources/ntp4/new_tab.js +++ b/chrome/browser/resources/ntp4/new_tab.js @@ -26,12 +26,6 @@ cr.define('ntp', function() { var notificationContainer; /** - * Object for accessing localized strings. - * @type {!LocalStrings} - */ - var localStrings = new LocalStrings; - - /** * If non-null, an info bubble for showing messages to the user. It points at * the Most Visited label, and is used to draw more attention to the * navigation dot UI. @@ -76,7 +70,7 @@ cr.define('ntp', function() { function NewTabView() { var pageSwitcherStart = null; var pageSwitcherEnd = null; - if (templateData.showApps) { + if (loadTimeData.getValue('showApps')) { pageSwitcherStart = getRequiredElement('page-switcher-start'); pageSwitcherEnd = getRequiredElement('page-switcher-end'); } @@ -103,7 +97,7 @@ cr.define('ntp', function() { * Invoked at startup once the DOM is available to initialize the app. */ function onLoad() { - sectionsToWaitFor = templateData.showApps ? 2 : 1; + sectionsToWaitFor = loadTimeData.getBoolean('showApps') ? 2 : 1; measureNavDots(); // Load the current theme colors. @@ -118,10 +112,10 @@ cr.define('ntp', function() { cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); chrome.send('getRecentlyClosedTabs'); - if (templateData.showOtherSessionsMenu) { + if (loadTimeData.getBoolean('showOtherSessionsMenu')) { otherSessionsButton = getRequiredElement('other-sessions-menu-button'); cr.ui.decorate(otherSessionsButton, ntp.OtherSessionsMenuButton); - otherSessionsButton.initialize(templateData.isUserSignedIn); + otherSessionsButton.initialize(loadTimeData.getBoolean('isUserSignedIn')); } var mostVisited = new ntp.MostVisitedPage(); @@ -130,16 +124,16 @@ cr.define('ntp', function() { if (document.body.classList.contains('bare-minimum')) mostVisited.appendFooter(getRequiredElement('footer')); newTabView.appendTilePage(mostVisited, - localStrings.getString('mostvisited'), + loadTimeData.getString('mostvisited'), false); chrome.send('getMostVisited'); - if (templateData.isSuggestionsPageEnabled) { + if (loadTimeData.getBoolean('isSuggestionsPageEnabled')) { var suggestions_script = document.createElement('script'); suggestions_script.src = 'suggestions_page.js'; suggestions_script.onload = function() { newTabView.appendTilePage(new ntp.SuggestionsPage(), - localStrings.getString('suggestions'), + loadTimeData.getString('suggestions'), false, (newTabView.appsPages.length > 0) ? newTabView.appsPages[0] : null); @@ -148,9 +142,9 @@ cr.define('ntp', function() { document.querySelector('head').appendChild(suggestions_script); } - var webstoreLink = localStrings.getString('webStoreLink'); - if (templateData.isWebStoreExperimentEnabled) { - var url = appendParam(webstoreLink, 'utm_source', 'chrome-ntp-launcher'); + var webStoreLink = loadTimeData.getString('webStoreLink'); + if (loadTimeData.getBoolean('isWebStoreExperimentEnabled')) { + var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher'); $('chrome-web-store-href').href = url; $('chrome-web-store-href').addEventListener('click', onChromeWebStoreButtonClick); @@ -158,12 +152,12 @@ cr.define('ntp', function() { $('footer-content').classList.add('enable-cws-experiment'); } - if (templateData.appInstallHintEnabled) { - var url = appendParam(webstoreLink, 'utm_source', 'chrome-ntp-plus-icon'); + if (loadTimeData.getBoolean('appInstallHintEnabled')) { + var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-plus-icon'); $('app-install-hint-template').href = url; } - if (localStrings.getString('login_status_message')) { + if (loadTimeData.getString('login_status_message')) { loginBubble = new cr.ui.Bubble; loginBubble.anchorNode = $('login-container'); loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END); @@ -172,8 +166,6 @@ cr.define('ntp', function() { loginBubble.deactivateToDismissDelay = 2000; loginBubble.setCloseButtonVisible(false); - $('login-status-learn-more').href = - localStrings.getString('login_status_url'); $('login-status-advanced').onclick = function() { chrome.send('showAdvancedLoginUI'); }; @@ -185,7 +177,7 @@ cr.define('ntp', function() { // The anchor node won't be updated until updateLogin is called so don't // show the bubble yet. shouldShowLoginBubble = true; - } else if (localStrings.getString('ntp4_intro_message')) { + } else if (loadTimeData.valueExists('ntp4_intro_message')) { infoBubble = new cr.ui.Bubble; infoBubble.anchorNode = newTabView.mostVisitedPage.navigationDot; infoBubble.setArrowLocation(cr.ui.ArrowLocation.BOTTOM_START); @@ -197,8 +189,11 @@ cr.define('ntp', function() { var bubbleContent = $('ntp4-intro-bubble-contents'); infoBubble.content = bubbleContent; - var learnMoreLink = infoBubble.querySelector('a'); - learnMoreLink.href = localStrings.getString('ntp4_intro_url'); + bubbleContent.querySelector('div > div').innerHTML = + loadTimeData.getString('ntp4_intro_message'); + + var learnMoreLink = bubbleContent.querySelector('a'); + learnMoreLink.href = loadTimeData.getString('ntp4_intro_url'); learnMoreLink.onclick = infoBubble.hide.bind(infoBubble); infoBubble.show(); @@ -216,8 +211,8 @@ cr.define('ntp', function() { newTabView.cardSlider.currentCardValue.navigationDot.classList.add( 'selected'); - var promo = localStrings.getString('serverpromo'); - if (promo) { + if (loadTimeData.valueExists('serverpromo')) { + var promo = loadTimeData.getString('serverpromo'); var tags = ['IMG']; var attrs = { src: function(node, value) { @@ -291,7 +286,7 @@ cr.define('ntp', function() { */ function measureNavDots() { var measuringDiv = $('fontMeasuringDiv'); - measuringDiv.textContent = localStrings.getString('mostvisited'); + measuringDiv.textContent = loadTimeData.getString('mostvisited'); // The 4 is for border and padding. var pxWidth = Math.max(measuringDiv.clientWidth * 1.15 + 4, 80); @@ -311,7 +306,6 @@ cr.define('ntp', function() { opt_hasAttribution); } - updateLogo(); updateAttribution(); } @@ -320,17 +314,6 @@ cr.define('ntp', function() { } /** - * Sets the proper image for the logo at the bottom left. - */ - function updateLogo() { - var imageId = 'IDR_PRODUCT_LOGO'; - if (document.documentElement.getAttribute('customlogo') == 'true') - imageId = 'IDR_CUSTOM_PRODUCT_LOGO'; - - $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now(); - } - - /** * Attributes the attribution image at the bottom left. */ function updateAttribution() { diff --git a/chrome/browser/resources/ntp4/other_sessions.js b/chrome/browser/resources/ntp4/other_sessions.js index 5e2d62e..67dd826 100644 --- a/chrome/browser/resources/ntp4/other_sessions.js +++ b/chrome/browser/resources/ntp4/other_sessions.js @@ -9,7 +9,6 @@ cr.define('ntp', function() { 'use strict'; - var localStrings = new LocalStrings(); var Menu = cr.ui.Menu; var MenuItem = cr.ui.MenuItem; var MenuButton = cr.ui.MenuButton; @@ -255,7 +254,7 @@ cr.define('ntp', function() { var button = cr.doc.createElement('button'); this.menu.appendChild(button); cr.ui.decorate(button, cr.ui.MenuItem); - button.textContent = localStrings.getString(textId); + button.textContent = loadTimeData.getString(textId); return button; }, diff --git a/chrome/browser/resources/ntp4/page_list_view.js b/chrome/browser/resources/ntp4/page_list_view.js index 8b84d13..9a8fb49 100644 --- a/chrome/browser/resources/ntp4/page_list_view.js +++ b/chrome/browser/resources/ntp4/page_list_view.js @@ -14,12 +14,6 @@ cr.define('ntp', function() { 'use strict'; /** - * Object for accessing localized strings. - * @type {!LocalStrings} - */ - var localStrings = new LocalStrings; - - /** * Creates a PageListView object. * @constructor * @extends {Object} @@ -150,18 +144,18 @@ cr.define('ntp', function() { if (this.pageSwitcherEnd) ntp.initializePageSwitcher(this.pageSwitcherEnd); - this.shownPage = templateData.shown_page_type; - this.shownPageIndex = templateData.shown_page_index; + this.shownPage = loadTimeData.getInteger('shown_page_type'); + this.shownPageIndex = loadTimeData.getInteger('shown_page_index'); - if (templateData.showApps) { + if (loadTimeData.getBoolean('showApps')) { // Request data on the apps so we can fill them in. // Note that this is kicked off asynchronously. 'getAppsCallback' will // be invoked at some point after this function returns. chrome.send('getApps'); } else { // No apps page. - if (this.shownPage == templateData['apps_page_id']) { - this.shownPage = templateData['most_visited_page_id']; + if (this.shownPage == loadTimeData.getInteger('apps_page_id')) { + this.shownPage = loadTimeData.getInteger('most_visited_page_id'); this.shownPageIndex = 0; } @@ -195,7 +189,7 @@ cr.define('ntp', function() { }); this.cardSlider.initialize( - templateData.isSwipeTrackingFromScrollEventsEnabled); + loadTimeData.getBoolean('isSwipeTrackingFromScrollEventsEnabled')); // Handle events from the card slider. this.pageList.addEventListener('cardSlider:card_changed', @@ -268,7 +262,7 @@ cr.define('ntp', function() { * position indices. */ appMoved: function(appData) { - assert(templateData.showApps); + assert(loadTimeData.getBoolean('showApps')); var app = $(appData.id); assert(app, 'trying to move an app that doesn\'t exist'); @@ -287,7 +281,7 @@ cr.define('ntp', function() { * @param {boolean} fromPage True if the removal was from the current page. */ appRemoved: function(appData, isUninstall, fromPage) { - assert(templateData.showApps); + assert(loadTimeData.getBoolean('showApps')); var app = $(appData.id); assert(app, 'trying to remove an app that doesn\'t exist'); @@ -323,7 +317,7 @@ cr.define('ntp', function() { * applications. */ getAppsCallback: function(data) { - assert(templateData.showApps); + assert(loadTimeData.getBoolean('showApps')); var startTime = Date.now(); @@ -380,7 +374,7 @@ cr.define('ntp', function() { var app = apps[i]; var pageIndex = app.page_index || 0; while (pageIndex >= this.appsPages.length) { - var pageName = localStrings.getString('appDefaultPageName'); + var pageName = loadTimeData.getString('appDefaultPageName'); if (this.appsPages.length < pageNames.length) pageName = pageNames[this.appsPages.length]; @@ -425,7 +419,7 @@ cr.define('ntp', function() { * the app. */ appAdded: function(appData, opt_highlight) { - assert(templateData.showApps); + assert(loadTimeData.getBoolean('showApps')); if (appData.id == this.highlightAppId) { opt_highlight = true; @@ -437,7 +431,7 @@ cr.define('ntp', function() { if (pageIndex >= this.appsPages.length) { while (pageIndex >= this.appsPages.length) { this.appendTilePage(new ntp.AppsPage(), - localStrings.getString('appDefaultPageName'), + loadTimeData.getString('appDefaultPageName'), true); } this.updateSliderCards(); @@ -457,7 +451,7 @@ cr.define('ntp', function() { * applications. */ appsPrefChangedCallback: function(data) { - assert(templateData.showApps); + assert(loadTimeData.getBoolean('showApps')); for (var i = 0; i < data.apps.length; ++i) { $(data.apps[i].id).appData = data.apps[i]; @@ -481,16 +475,16 @@ cr.define('ntp', function() { this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), pageNo); switch (this.shownPage) { - case templateData['apps_page_id']: + case loadTimeData.getInteger('apps_page_id'): this.cardSlider.selectCardByValue( this.appsPages[Math.min(this.shownPageIndex, this.appsPages.length - 1)]); break; - case templateData['most_visited_page_id']: + case loadTimeData.getInteger('most_visited_page_id'): if (this.mostVisitedPage) this.cardSlider.selectCardByValue(this.mostVisitedPage); break; - case templateData['suggestions_page_id']: + case loadTimeData.getInteger('suggestions_page_id'): if (this.suggestionsPage) this.cardSlider.selectCardByValue(this.suggestionsPage); break; @@ -502,10 +496,10 @@ cr.define('ntp', function() { * of a moving or insert tile. */ enterRearrangeMode: function() { - if (templateData.showApps) { + if (loadTimeData.getBoolean('showApps')) { var tempPage = new ntp.AppsPage(); tempPage.classList.add('temporary'); - var pageName = localStrings.getString('appDefaultPageName'); + var pageName = loadTimeData.getString('appDefaultPageName'); this.appendTilePage(tempPage, pageName, true); } @@ -528,7 +522,7 @@ cr.define('ntp', function() { } else { tempPage.classList.remove('temporary'); this.saveAppPageName(tempPage, - localStrings.getString('appDefaultPageName')); + loadTimeData.getString('appDefaultPageName')); } } @@ -608,13 +602,13 @@ cr.define('ntp', function() { // reflect user actions). if (!this.isStartingUp_()) { if (page.classList.contains('apps-page')) { - this.shownPage = templateData.apps_page_id; + this.shownPage = loadTimeData.getInteger('apps_page_id'); this.shownPageIndex = this.getAppsPageIndex(page); } else if (page.classList.contains('most-visited-page')) { - this.shownPage = templateData.most_visited_page_id; + this.shownPage = loadTimeData.getInteger('most_visited_page_id'); this.shownPageIndex = 0; } else if (page.classList.contains('suggestions-page')) { - this.shownPage = templateData.suggestions_page_id; + this.shownPage = loadTimeData.getInteger('suggestions_page_id'); this.shownPageIndex = 0; } else { console.error('unknown page selected'); diff --git a/chrome/browser/resources/ntp4/recently_closed.js b/chrome/browser/resources/ntp4/recently_closed.js index eb01aae..34b45c0 100644 --- a/chrome/browser/resources/ntp4/recently_closed.js +++ b/chrome/browser/resources/ntp4/recently_closed.js @@ -9,8 +9,6 @@ cr.define('ntp', function() { 'use strict'; - var localStrings = new LocalStrings(); - /** * Returns the text used for a recently closed window. * @param {number} numTabs Number of tabs in the window. @@ -18,8 +16,8 @@ cr.define('ntp', function() { */ function formatTabsText(numTabs) { if (numTabs == 1) - return localStrings.getString('closedwindowsingle'); - return localStrings.getStringF('closedwindowmultiple', numTabs); + return loadTimeData.getString('closedwindowsingle'); + return loadTimeData.getStringF('closedwindowmultiple', numTabs); } var Menu = cr.ui.Menu; diff --git a/chrome/browser/resources/ntp4/suggestions_page.js b/chrome/browser/resources/ntp4/suggestions_page.js index eefd8a7..cc5a5d4 100644 --- a/chrome/browser/resources/ntp4/suggestions_page.js +++ b/chrome/browser/resources/ntp4/suggestions_page.js @@ -73,7 +73,7 @@ cr.define('ntp', function() { '<span class="title"></span>'; this.querySelector('.close-button').title = - templateData.removethumbnailtooltip; + loadTimeData.getString('removethumbnailtooltip'); this.tabIndex = -1; this.data_ = null; @@ -184,18 +184,19 @@ cr.define('ntp', function() { var undo = { action: doUndo, - text: templateData.undothumbnailremove, + text: loadTimeData.getString('undothumbnailremove'), }; var undoAll = { action: function() { chrome.send('clearSuggestionsURLsBlacklist'); }, - text: templateData.restoreThumbnailsShort, + text: loadTimeData.getString('restoreThumbnailsShort'), }; - ntp.showNotification(templateData.thumbnailremovednotification, - [undo, undoAll]); + ntp.showNotification( + loadTimeData.getString('thumbnailremovednotification'), + [undo, undoAll]); }, /** diff --git a/chrome/browser/resources/shared/js/load_time_data.js b/chrome/browser/resources/shared/js/load_time_data.js index 77aa490..d29bb2a 100644 --- a/chrome/browser/resources/shared/js/load_time_data.js +++ b/chrome/browser/resources/shared/js/load_time_data.js @@ -29,6 +29,13 @@ var loadTimeData; }, /** + * @return {boolean} True if |id| is a key in the dictionary. + */ + valueExists: function(id) { + return id in this.data_; + }, + + /** * Fetches a value, asserting that it exists. * @param {string} id The key that identifies the desired value. * @return {*} The corresponding value. @@ -47,8 +54,30 @@ var loadTimeData; */ getString: function(id) { var value = this.getValue(id); - assert(typeof value == 'string', '[' + value + '] (' + id + - ') is not a string'); + assertIsType(id, value, 'string'); + return value; + }, + + /** + * As above, but also makes sure that the value is a boolean. + * @param {string} id The key that identifies the desired boolean. + * @return {boolean} The corresponding boolean value. + */ + getBoolean: function(id) { + var value = this.getValue(id); + assertIsType(id, value, 'boolean'); + return value; + }, + + /** + * As above, but also makes sure that the value is an integer. + * @param {string} id The key that identifies the desired number. + * @return {number} The corresponding number value. + */ + getInteger: function(id) { + var value = this.getValue(id); + assertIsType(id, value, 'number'); + assert(value == Math.floor(value), 'Number isn\'t integer: ' + value); return value; }, }; @@ -59,9 +88,19 @@ var loadTimeData; * @param {string} message The message to display if the check fails. */ function assert(condition, message) { - if (!condition) { + if (!condition) console.error(message); - } + } + + /** + * Asserts that the given value has the given type. + * @param {string} id The id of the value (only used for error message). + * @param {*} value The value to check the type on. + * @param {string} type The type we expect |value| to be. + */ + function assertIsType(id, value, type) { + assert(typeof value == type, '[' + value + '] (' + id + + ') is not a ' + type); } assert(!loadTimeData, 'should only include this file once'); diff --git a/chrome/browser/ui/webui/chrome_web_ui_data_source.cc b/chrome/browser/ui/webui/chrome_web_ui_data_source.cc index 57599c5..d4a1c67 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_data_source.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_data_source.cc @@ -75,10 +75,12 @@ void ChromeWebUIDataSource::StartDataRequest(const std::string& path, void ChromeWebUIDataSource::SendLocalizedStringsAsJSON(int request_id) { std::string template_data; SetFontAndTextDirection(&localized_strings_); + + scoped_ptr<jstemplate_builder::UseVersion2> version2; if (json_js_format_v2_) - jstemplate_builder::AppendJsonJS2(&localized_strings_, &template_data); - else - jstemplate_builder::AppendJsonJS(&localized_strings_, &template_data); + version2.reset(new jstemplate_builder::UseVersion2); + + jstemplate_builder::AppendJsonJS(&localized_strings_, &template_data); SendResponse(request_id, base::RefCountedString::TakeString(&template_data)); } diff --git a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc index e9ee7bf..28c6558 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc @@ -186,8 +186,6 @@ void NewTabPageHandler::GetLocalizedValues(Profile* profile, values->SetString("ntp4_intro_message", l10n_util::GetStringUTF16(IDS_NTP4_INTRO_MESSAGE)); values->SetString("ntp4_intro_url", kNtp4IntroURL); - values->SetString("learn_more", - l10n_util::GetStringUTF16(IDS_LEARN_MORE)); } #endif } diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc index b349d05..ec17dc2b 100644 --- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc +++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc @@ -257,19 +257,19 @@ bool NTPLoginHandler::ShouldShow(Profile* profile) { void NTPLoginHandler::GetLocalizedValues(Profile* profile, DictionaryValue* values) { PrefService* prefs = profile->GetPrefs(); - if (prefs->GetString(prefs::kGoogleServicesUsername).empty() || - !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble)) { - return; - } + bool hide_sync = prefs->GetString(prefs::kGoogleServicesUsername).empty() || + !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble); values->SetString("login_status_message", + hide_sync ? string16() : l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); - values->SetString("login_status_url", chrome::kSyncLearnMoreURL); - values->SetString("login_status_learn_more", - l10n_util::GetStringUTF16(IDS_LEARN_MORE)); + values->SetString("login_status_url", + hide_sync ? std::string() : chrome::kSyncLearnMoreURL); values->SetString("login_status_advanced", + hide_sync ? string16() : l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); values->SetString("login_status_dismiss", + hide_sync ? string16() : l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); } diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 773b1a1..b2cbd6d 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -286,8 +286,7 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { ASCIIToUTF16(chrome::kChromeUIExtensionsURL))); bool bookmark_bar_attached = profile_->GetPrefs()->GetBoolean( prefs::kShowBookmarkBar); - localized_strings.SetString("bookmarkbarattached", - bookmark_bar_attached ? "true" : "false"); + localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached); ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); @@ -307,154 +306,132 @@ void NTPResourceCache::CreateNewTabHTML() { // Show the profile name in the title and most visited labels if the current // profile is not the default. PrefService* prefs = profile_->GetPrefs(); - DictionaryValue localized_strings; - localized_strings.SetString("bookmarkbarattached", - prefs->GetBoolean(prefs::kShowBookmarkBar) ? "true" : "false"); - localized_strings.SetString("hasattribution", + DictionaryValue load_time_data; + load_time_data.SetBoolean("bookmarkbarattached", + prefs->GetBoolean(prefs::kShowBookmarkBar)); + load_time_data.SetBoolean("hasattribution", ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( - IDR_THEME_NTP_ATTRIBUTION) ? - "true" : "false"); - localized_strings.SetString("title", + IDR_THEME_NTP_ATTRIBUTION)); + load_time_data.SetString("title", l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); - localized_strings.SetString("mostvisited", + load_time_data.SetString("mostvisited", l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); - localized_strings.SetString("suggestions", + load_time_data.SetString("suggestions", l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); - localized_strings.SetString("restoreThumbnailsShort", + load_time_data.SetString("restoreThumbnailsShort", l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); - localized_strings.SetString("recentlyclosed", + load_time_data.SetString("recentlyclosed", l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED)); - localized_strings.SetString("webStoreTitle", + load_time_data.SetString("webStoreTitle", l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); - localized_strings.SetString("webStoreTitleShort", + load_time_data.SetString("webStoreTitleShort", l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); - localized_strings.SetString("closedwindowsingle", + load_time_data.SetString("closedwindowsingle", l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE)); - localized_strings.SetString("closedwindowmultiple", + load_time_data.SetString("closedwindowmultiple", l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE)); - localized_strings.SetString("attributionintro", + load_time_data.SetString("attributionintro", l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); - localized_strings.SetString("thumbnailremovednotification", + load_time_data.SetString("thumbnailremovednotification", l10n_util::GetStringUTF16(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION)); - localized_strings.SetString("undothumbnailremove", + load_time_data.SetString("undothumbnailremove", l10n_util::GetStringUTF16(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE)); - localized_strings.SetString("removethumbnailtooltip", + load_time_data.SetString("removethumbnailtooltip", l10n_util::GetStringUTF16(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP)); - localized_strings.SetString("appuninstall", + load_time_data.SetString("appuninstall", l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); - localized_strings.SetString("appoptions", + load_time_data.SetString("appoptions", l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_OPTIONS)); - localized_strings.SetString("appdisablenotifications", + load_time_data.SetString("appdisablenotifications", l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_DISABLE_NOTIFICATIONS)); - localized_strings.SetString("appcreateshortcut", + load_time_data.SetString("appcreateshortcut", l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_CREATE_SHORTCUT)); - localized_strings.SetString("appDefaultPageName", + load_time_data.SetString("appDefaultPageName", l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME)); - localized_strings.SetString("applaunchtypepinned", + load_time_data.SetString("applaunchtypepinned", l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_PINNED)); - localized_strings.SetString("applaunchtyperegular", + load_time_data.SetString("applaunchtyperegular", l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_REGULAR)); - localized_strings.SetString("applaunchtypewindow", + load_time_data.SetString("applaunchtypewindow", l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_WINDOW)); - localized_strings.SetString("applaunchtypefullscreen", + load_time_data.SetString("applaunchtypefullscreen", l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN)); - localized_strings.SetString("syncpromotext", + load_time_data.SetString("syncpromotext", l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL)); - localized_strings.SetString("syncLinkText", + load_time_data.SetString("syncLinkText", l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS)); - localized_strings.SetString("otherSessions", + load_time_data.SetString("otherSessions", l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL)); - localized_strings.SetString("otherSessionsEmpty", + load_time_data.SetString("otherSessionsEmpty", l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY)); - localized_strings.SetString("otherSessionsLearnMoreUrl", + load_time_data.SetString("otherSessionsLearnMoreUrl", l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); - localized_strings.SetString("learnMore", + load_time_data.SetString("learnMore", l10n_util::GetStringUTF16(IDS_LEARN_MORE)); - localized_strings.SetString("webStoreLink", + load_time_data.SetString("webStoreLink", GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); - localized_strings.SetBoolean("isWebStoreExperimentEnabled", + load_time_data.SetBoolean("isWebStoreExperimentEnabled", NewTabUI::ShouldShowWebStoreFooterLink()); - localized_strings.SetBoolean("appInstallHintEnabled", + load_time_data.SetBoolean("appInstallHintEnabled", NewTabUI::ShouldShowAppInstallHint()); - localized_strings.SetString("appInstallHintText", + load_time_data.SetString("appInstallHintText", l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); - localized_strings.SetBoolean("isSuggestionsPageEnabled", + load_time_data.SetBoolean("isSuggestionsPageEnabled", NewTabUI::IsSuggestionsPageEnabled()); - localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps()); - localized_strings.SetString("hideSessionMenuItemText", + load_time_data.SetBoolean("showApps", NewTabUI::ShouldShowApps()); + load_time_data.SetString("hideSessionMenuItemText", l10n_util::GetStringUTF16(IDS_POLICY_HIDE)); + load_time_data.SetString("learn_more", + l10n_util::GetStringUTF16(IDS_LEARN_MORE)); // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or // forward gesture. Pass through a flag that indicates whether or not that // feature is enabled. - localized_strings.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", - is_swipe_tracking_from_scroll_events_enabled_); + load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", + is_swipe_tracking_from_scroll_events_enabled_); #if defined(OS_CHROMEOS) - localized_strings.SetString("expandMenu", + load_time_data.SetString("expandMenu", l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); #endif - NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings); - NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings); + NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data); + NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data); - // Don't initiate the sync related message passing with the page if the sync - // code is not present. - if (ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)) - localized_strings.SetString("syncispresent", "true"); - else - localized_strings.SetString("syncispresent", "false"); - - ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); + ChromeURLDataManager::DataSource::SetFontAndTextDirection(&load_time_data); // Control fade and resize animations. - std::string anim = - ui::Animation::ShouldRenderRichAnimation() ? "true" : "false"; - localized_strings.SetString("anim", anim); + load_time_data.SetBoolean("anim", ui::Animation::ShouldRenderRichAnimation()); int alignment; ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); - localized_strings.SetString("themegravity", + load_time_data.SetString("themegravity", (alignment & ThemeService::ALIGN_RIGHT) ? "right" : ""); #if defined(ENABLE_PROMO_RESOURCE_SERVICE) // If the user has preferences for a start and end time for a promo from // the server, and this promo string exists, set the localized string. if (PromoResourceService::CanShowNotificationPromo(profile_)) { - localized_strings.SetString("serverpromo", + load_time_data.SetString("serverpromo", prefs->GetString(prefs::kNtpPromoLine)); } - - // If the user has preferences for a start and end time for a custom logo, - // and the time now is between these two times, show the custom logo. - if (prefs->FindPreference(prefs::kNtpCustomLogoStart) && - prefs->FindPreference(prefs::kNtpCustomLogoEnd)) { - localized_strings.SetString("customlogo", - InDateRange(prefs->GetDouble(prefs::kNtpCustomLogoStart), - prefs->GetDouble(prefs::kNtpCustomLogoEnd)) ? - "true" : "false"); - } else { - localized_strings.SetString("customlogo", "false"); - } -#else - localized_strings.SetString("customlogo", "false"); #endif // Determine whether to show the menu for accessing tabs on other devices. bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableNTPOtherSessionsMenu); - localized_strings.SetBoolean("showOtherSessionsMenu", - show_other_sessions_menu); - localized_strings.SetBoolean("isUserSignedIn", + load_time_data.SetBoolean("showOtherSessionsMenu", + show_other_sessions_menu); + load_time_data.SetBoolean("isUserSignedIn", !prefs->GetString(prefs::kGoogleServicesUsername).empty()); // Load the new tab page appropriate for this build - std::string full_html; base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). GetRawDataResource(IDR_NEW_TAB_4_HTML)); - full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, - &localized_strings); + jstemplate_builder::UseVersion2 version2; + std::string full_html = + jstemplate_builder::GetI18nTemplateHtml(new_tab_html, &load_time_data); new_tab_html_ = base::RefCountedString::TakeString(&full_html); } diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc index 2ada4ee..09e925d 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc @@ -60,7 +60,7 @@ void NTPResourceCache::CreateNewTabHTML() { // Show the profile name in the title and most visited labels if the current // profile is not the default. DictionaryValue localized_strings; - localized_strings.SetString("hasattribution", "false"); + localized_strings.SetBoolean("hasattribution", false); localized_strings.SetString("title", l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); localized_strings.SetString("mostvisited", diff --git a/chrome/common/common_resources.grd b/chrome/common/common_resources.grd index 52463b1..a93cf88 100644 --- a/chrome/common/common_resources.grd +++ b/chrome/common/common_resources.grd @@ -13,6 +13,7 @@ <include name="IDR_EXTENSION_PERMISSION_FEATURES" file="extensions\api\_permission_features.json" type="BINDATA" /> <include name="IDR_I18N_PROCESS_JS" file="..\browser\resources\shared\js\i18n_process.js" type="BINDATA" /> <include name="IDR_I18N_TEMPLATE_JS" file="..\browser\resources\shared\js\i18n_template.js" type="BINDATA" /> + <include name="IDR_I18N_TEMPLATE2_JS" file="..\browser\resources\shared\js\i18n_template2.js" type="BINDATA" /> <include name="IDR_JSTEMPLATE_JS" file="..\browser\resources\shared\js\jstemplate_compiled.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_WEB_APP_SCHEMA" file="web_app_schema.json" type="BINDATA" /> <if expr="is_macosx"> diff --git a/chrome/common/jstemplate_builder.cc b/chrome/common/jstemplate_builder.cc index 711cba6..de66cce 100644 --- a/chrome/common/jstemplate_builder.cc +++ b/chrome/common/jstemplate_builder.cc @@ -14,8 +14,23 @@ #include "grit/common_resources.h" #include "ui/base/resource/resource_bundle.h" +namespace { + +// True when building version 2 templates. See UseVersion2 class. +bool g_version2 = false; + +} // namespace + namespace jstemplate_builder { +UseVersion2::UseVersion2() : previous_value_(g_version2) { + g_version2 = true; +} + +UseVersion2::~UseVersion2() { + g_version2 = previous_value_; +} + std::string GetTemplateHtml(const base::StringPiece& html_template, const DictionaryValue* json, const base::StringPiece& template_id) { @@ -49,7 +64,7 @@ std::string GetTemplatesHtml(const base::StringPiece& html_template, void AppendJsonHtml(const DictionaryValue* json, std::string* output) { std::string javascript_string; - AppendJsonJS(json, &javascript_string); + jstemplate_builder::AppendJsonJS(json, &javascript_string); // </ confuses the HTML parser because it could be a </script> tag. So we // replace </ with <\/. The extra \ will be ignored by the JS engine. @@ -67,19 +82,7 @@ void AppendJsonJS(const DictionaryValue* json, std::string* output) { std::string jstext; JSONStringValueSerializer serializer(&jstext); serializer.Serialize(*json); - output->append("var templateData = "); - output->append(jstext); - output->append(";"); -} - -void AppendJsonJS2(const DictionaryValue* json, std::string* output) { - // Convert the template data to a json string. - DCHECK(json) << "must include json data structure"; - - std::string jstext; - JSONStringValueSerializer serializer(&jstext); - serializer.Serialize(*json); - output->append("loadTimeData.data = "); + output->append(g_version2 ? "loadTimeData.data = " : "var templateData = "); output->append(jstext); output->append(";"); } @@ -114,7 +117,7 @@ void AppendI18nTemplateSourceHtml(std::string* output) { // fetch and cache the pointer of the jstemplate resource source text. static const base::StringPiece i18n_template_src( ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_I18N_TEMPLATE_JS)); + g_version2 ? IDR_I18N_TEMPLATE2_JS : IDR_I18N_TEMPLATE_JS)); if (i18n_template_src.empty()) { NOTREACHED() << "Unable to get i18n template src"; @@ -127,6 +130,9 @@ void AppendI18nTemplateSourceHtml(std::string* output) { } void AppendI18nTemplateProcessHtml(std::string* output) { + if (g_version2) + return; + static const base::StringPiece i18n_process_src( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_I18N_PROCESS_JS)); diff --git a/chrome/common/jstemplate_builder.h b/chrome/common/jstemplate_builder.h index 7ef6338..e925349 100644 --- a/chrome/common/jstemplate_builder.h +++ b/chrome/common/jstemplate_builder.h @@ -24,6 +24,20 @@ class DictionaryValue; namespace jstemplate_builder { +// While an object of this class is in scope, the template builder will output +// version 2 html. Version 2 uses load_time_data.js and i18n_template2.js, and +// should soon become the default. +class UseVersion2 { + public: + UseVersion2(); + ~UseVersion2(); + + private: + bool previous_value_; + + DISALLOW_COPY_AND_ASSIGN(UseVersion2); +}; + // A helper function that generates a string of HTML to be loaded. The // string includes the HTML and the javascript code necessary to generate the // full page with support for JsTemplates. @@ -54,9 +68,6 @@ void AppendJsonHtml(const base::DictionaryValue* json, std::string* output); // Same as AppendJsonHtml(), except does not include the <script></script> // tag wrappers. void AppendJsonJS(const base::DictionaryValue* json, std::string* output); -// Same as above, but uses a slightly different format which should some day -// become the default. -void AppendJsonJS2(const base::DictionaryValue* json, std::string* output); // Appends the source for JsTemplates in a script tag. void AppendJsTemplateSourceHtml(std::string* output); diff --git a/chrome/test/data/webui/ntp4.js b/chrome/test/data/webui/ntp4.js index a4a0208..378d91f 100644 --- a/chrome/test/data/webui/ntp4.js +++ b/chrome/test/data/webui/ntp4.js @@ -36,7 +36,7 @@ TEST_F('NTP4WebUITest', 'FLAKY_NTPHasThumbnails', function() { assertEquals(8, mostVisited.length, 'There should be 8 most visited tiles.'); var apps = document.querySelectorAll('.app'); - if (window.templateData.showApps) + if (loadTimeData.getBoolean('showApps')) assertGE(apps.length, 1, 'There should be at least one app.'); else assertEquals(0, apps.length, 'There should be no apps.'); @@ -44,7 +44,7 @@ TEST_F('NTP4WebUITest', 'FLAKY_NTPHasThumbnails', function() { TEST_F('NTP4WebUITest', 'NTPHasNavDots', function() { var navDots = document.querySelectorAll('.dot'); - if (window.templateData.showApps) + if (loadTimeData.getBoolean('showApps')) assertGE(navDots.length, 2, 'There should be at least two navdots.'); else assertEquals(1, navDots.length, 'There should be exactly one navdot.'); |