Commit 5b5dcbd5 authored by Kristi Park's avatar Kristi Park Committed by Commit Bot

[NTP Cleanup] Rename tid to rid

The tile's restricted ID is referenced in multiple places as "rid" and
"tid". Standardize naming by changing all references of "tid" to "rid".

Change-Id: I285d7b21abb404adb0c97cdecad38c38ae3a39d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1642235Reviewed-by: default avatarGayane Petrosyan <gayane@chromium.org>
Commit-Queue: Kristi Park <kristipark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666472}
parent a9191e06
......@@ -197,7 +197,7 @@ function closeDialog() {
*/
function focusBackOnCancel(event) {
if (event.keyCode === KEYCODES.ENTER || event.keyCode === KEYCODES.SPACE) {
const message = {cmd: 'focusMenu', tid: prepopulatedLink.rid};
const message = {cmd: 'focusMenu', rid: prepopulatedLink.rid};
window.parent.postMessage(message, DOMAIN_ORIGIN);
event.preventDefault();
closeDialog();
......@@ -222,10 +222,10 @@ function handlePostMessage(event) {
const cmd = event.data.cmd;
const args = event.data;
if (cmd === 'linkData') {
if (args.tid) { // We are editing a link, prepopulate the link data.
if (args.rid) { // We are editing a link, prepopulate the link data.
document.title = editLinkTitle;
$(IDS.DIALOG_TITLE).textContent = editLinkTitle;
prepopulateFields(args.tid);
prepopulateFields(args.rid);
} else { // We are adding a link, disable the delete button.
document.title = addLinkTitle;
$(IDS.DIALOG_TITLE).textContent = addLinkTitle;
......
......@@ -14,7 +14,7 @@
* InstantMostVisitedItem
* @typedef {{dataGenerationTime: Date,
* isAddButton: boolean,
* tid: number,
* rid: number,
* tileSource: number,
* tileTitleSource: number,
* title: ?,
......@@ -170,7 +170,7 @@ window.chrome.embeddedSearch.newTabPage.blacklistSearchSuggestion;
window.chrome.embeddedSearch.newTabPage.blacklistSearchSuggestionWithHash;
/**
* @param {number} tid
* @param {number} rid
*/
window.chrome.embeddedSearch.newTabPage.deleteMostVisitedItem;
......@@ -180,7 +180,7 @@ window.chrome.embeddedSearch.newTabPage.deleteMostVisitedItem;
window.chrome.embeddedSearch.newTabPage.fixupAndValidateUrl;
/**
* @param {number} tid
* @param {number} rid
*/
window.chrome.embeddedSearch.newTabPage.getMostVisitedItemData;
......
......@@ -1029,14 +1029,14 @@ function handlePostMessage(event) {
showNotification(
configData.translatedStrings.thumbnailRemovedNotification);
}
lastBlacklistedTile = args.tid;
lastBlacklistedTile = args.rid;
ntpApiHandle.deleteMostVisitedItem(args.tid);
ntpApiHandle.deleteMostVisitedItem(args.rid);
} else if (cmd === 'resizeDoodle') {
doodles.resizeDoodleHandler(args);
} else if (cmd === 'startEditLink') {
$(IDS.CUSTOM_LINKS_EDIT_IFRAME)
.contentWindow.postMessage({cmd: 'linkData', tid: args.tid}, '*');
.contentWindow.postMessage({cmd: 'linkData', rid: args.rid}, '*');
// Small delay to allow the dialog to finish setting up before displaying.
window.setTimeout(function() {
$(IDS.CUSTOM_LINKS_EDIT_IFRAME_DIALOG).showModal();
......@@ -1047,7 +1047,7 @@ function handlePostMessage(event) {
// Focus the edited tile's menu or the add shortcut tile after closing the
// custom link edit dialog without saving.
$(IDS.TILES_IFRAME)
.contentWindow.postMessage({cmd: 'focusMenu', tid: args.tid}, '*');
.contentWindow.postMessage({cmd: 'focusMenu', rid: args.rid}, '*');
}
}
......
......@@ -903,8 +903,8 @@ function updateTheme(info) {
* @param {!Object} info Data received in the message.
*/
function focusTileMenu(info) {
const tile = document.querySelector(`a.md-tile[data-tid="${info.tid}"]`);
if (info.tid === -1 /* Add shortcut tile */) {
const tile = document.querySelector(`a.md-tile[data-rid="${info.rid}"]`);
if (info.rid === -1 /* Add shortcut tile */) {
tile.focus();
} else {
tile.parentNode.childNodes[1].focus();
......@@ -937,7 +937,7 @@ function swapInNewTiles() {
// number of tiles.
if (isCustomLinksEnabled && cur.childNodes.length < maxNumTiles) {
const data = {
'tid': -1,
'rid': -1,
'title': queryArgs['addLink'],
'url': '',
'isAddButton': true,
......@@ -1033,10 +1033,9 @@ function addTile(args) {
return;
}
data.tid = data.rid;
if (!data.faviconUrl) {
data.faviconUrl = 'chrome-search://favicon/size/16@' +
window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid;
window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.rid;
}
tiles.appendChild(renderTile(data));
} else {
......@@ -1052,10 +1051,10 @@ function addTile(args) {
* @param {Element} tile DOM node of the tile we want to remove.
*/
function blacklistTile(tile) {
const tid = Number(tile.firstChild.getAttribute('data-tid'));
const rid = Number(tile.firstChild.getAttribute('data-rid'));
if (isCustomLinksEnabled) {
chrome.embeddedSearch.newTabPage.deleteMostVisitedItem(tid);
chrome.embeddedSearch.newTabPage.deleteMostVisitedItem(rid);
} else {
tile.classList.add('blacklisted');
tile.addEventListener('transitionend', function(ev) {
......@@ -1063,7 +1062,7 @@ function blacklistTile(tile) {
return;
}
window.parent.postMessage(
{cmd: 'tileBlacklisted', tid: Number(tid)}, DOMAIN_ORIGIN);
{cmd: 'tileBlacklisted', rid: Number(rid)}, DOMAIN_ORIGIN);
});
}
}
......@@ -1072,10 +1071,10 @@ function blacklistTile(tile) {
/**
* Starts edit custom link flow. Tells host page to show the edit custom link
* dialog and pre-populate it with data obtained using the link's id.
* @param {?number} tid Restricted id of the tile we want to edit.
* @param {?number} rid Restricted id of the tile we want to edit.
*/
function editCustomLink(tid) {
window.parent.postMessage({cmd: 'startEditLink', tid: tid}, DOMAIN_ORIGIN);
function editCustomLink(rid) {
window.parent.postMessage({cmd: 'startEditLink', rid: rid}, DOMAIN_ORIGIN);
}
......@@ -1117,7 +1116,7 @@ function stopReorder(tile) {
allTiles[i].setAttribute('data-pos', i);
}
chrome.embeddedSearch.newTabPage.reorderCustomLink(
Number(tile.firstChild.getAttribute('data-tid')),
Number(tile.firstChild.getAttribute('data-rid')),
Number(tile.firstChild.getAttribute('data-pos')));
}
......@@ -1225,7 +1224,7 @@ function renderMaterialDesignTile(data) {
const mdTile = document.createElement('a');
mdTile.className = CLASSES.MD_TILE;
mdTile.tabIndex = 0;
mdTile.setAttribute('data-tid', data.tid);
mdTile.setAttribute('data-rid', data.rid);
mdTile.setAttribute('data-pos', position);
if (utils.isSchemeAllowed(data.url)) {
mdTile.href = data.url;
......@@ -1355,7 +1354,7 @@ function renderMaterialDesignTile(data) {
'aria-label',
(queryArgs['editLinkTooltip'] || '') + ' ' + data.title);
mdMenu.addEventListener('click', function(ev) {
editCustomLink(data.tid);
editCustomLink(data.rid);
ev.preventDefault();
ev.stopPropagation();
logEvent(LOG_TYPE.NTP_CUSTOMIZE_EDIT_SHORTCUT_CLICKED);
......@@ -1383,7 +1382,7 @@ function renderMaterialDesignTile(data) {
if (isGridEnabled) {
return currGrid.createGridTile(
mdTileContainer, data.tid, !!data.isAddButton);
mdTileContainer, data.rid, !!data.isAddButton);
} else {
// Enable reordering.
if (isCustomLinksEnabled && !data.isAddButton) {
......
......@@ -610,15 +610,15 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, ReorderCustomLinks) {
&title));
// Move the tile to the front.
std::string tid;
std::string rid;
ASSERT_TRUE(instant_test_utils::GetStringFromJS(
iframe,
"document.querySelectorAll('#mv-tiles "
".md-tile')[1].getAttribute('data-tid')",
&tid));
".md-tile')[1].getAttribute('data-rid')",
&rid));
local_ntp_test_utils::ExecuteScriptOnNTPAndWaitUntilLoaded(
iframe, "window.chrome.embeddedSearch.newTabPage.reorderCustomLink(" +
tid + ", 0)");
rid + ", 0)");
// Check that the first tile is the tile that was moved.
std::string new_title;
......@@ -632,11 +632,11 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, ReorderCustomLinks) {
ASSERT_TRUE(instant_test_utils::GetStringFromJS(
iframe,
"document.querySelectorAll('#mv-tiles "
".md-tile')[0].getAttribute('data-tid')",
&tid));
".md-tile')[0].getAttribute('data-rid')",
&rid));
local_ntp_test_utils::ExecuteScriptOnNTPAndWaitUntilLoaded(
iframe, "window.chrome.embeddedSearch.newTabPage.reorderCustomLink(" +
tid + ", " + end_index + ")");
rid + ", " + end_index + ")");
// Check that the last tile is the tile that was moved.
new_title = std::string();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment