Skip to content

Commit

Permalink
WebUI: Remove conditional logic only applying to Polymer 1.
Browse files Browse the repository at this point in the history
Polymer 1 support has been removed from individual WebUI pages. All Polymer 1
specific logic can finally be removed as well (except for chrome://resources).

Removing the bulk of codepaths only applying to Polymer 1 in this CL, but there
are a few more that are a bit more complicated and will be addressed separately.

Bug: 944281
Change-Id: Iacc8678247673eb46cdeeab6f8105ae1e3b8e3fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1577992
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Dan Beam <dbeam@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653612}
  • Loading branch information
freshp86 authored and Commit Bot committed Apr 24, 2019
1 parent 6eaf0af commit bb6be13
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 172 deletions.
10 changes: 2 additions & 8 deletions chrome/browser/resources/downloads/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,8 @@ cr.define('downloads', function() {

// Wait for dom-if to switch to true, in case the text has just changed
// from empty.
// TODO (rbpotter): Remove this conditional when Polymer 2 migration is
// complete.
if (Polymer.DomIf) {
Polymer.RenderStatus.beforeNextRender(
this, () => this.toggleButtonClass_());
} else {
this.async(() => this.toggleButtonClass_());
}
Polymer.RenderStatus.beforeNextRender(
this, () => this.toggleButtonClass_());
},

/**
Expand Down
20 changes: 1 addition & 19 deletions chrome/browser/resources/downloads/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ cr.define('downloads', function() {
this.mojoEventTarget_.updateItem.addListener(
this.updateItem_.bind(this)),
];

// TODO(aee): Remove this conditional when the Polymer 2 migration
// is completed. Polymer.DomIf exists in Polymer 2 and not in Polymer 1.
if (typeof Polymer.DomIf == 'undefined') {
this.$.downloadsList.preserveFocus = false;
}
},

/** @override */
Expand Down Expand Up @@ -323,19 +317,7 @@ cr.define('downloads', function() {
this.items_[index] = data;
this.updateHideDates_(index, index);

// TODO(aee): Remove this conditional when the Polymer 2 migration
// is completed. Polymer.DomIf exists in Polymer 2 and not in Polymer 1.
if (Polymer.DomIf) {
this.notifyPath(`items_.${index}`);
} else {
this.notifySplices('items_', [{
index: index,
addedCount: 0,
object: this.items_,
type: 'splice',
removed: [],
}]);
}
this.notifyPath(`items_.${index}`);
this.async(() => {
const list = /** @type {!IronListElement} */ (this.$.downloadsList);
list.updateSizeForIndex(index);
Expand Down
8 changes: 1 addition & 7 deletions chrome/browser/resources/history/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ window.resultsRendered = false;
function waitForAppUpgrade() {
if (!upgradePromise) {
upgradePromise = new Promise(function(resolve, reject) {
// TODO(dpapad): Need to update this to work with Polymer 2.
if (window.Polymer && Polymer.isInstance &&
Polymer.isInstance($('history-app'))) {
resolve();
} else {
$('bundle').addEventListener('load', resolve);
}
$('bundle').addEventListener('load', resolve);
});
}
return upgradePromise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,9 @@ Polymer({

/** @override */
attached: function() {
// TODO (rbpotter): Remove this conditional when the migration to Polymer 2
// is completed.
if (Polymer.DomIf) {
Polymer.RenderStatus.beforeNextRender(this, () => {
this.updateExpandedStateAndFinishAnimations_();
});
} else {
Polymer.RenderStatus.beforeNextRender(this, () => {
this.updateExpandedStateAndFinishAnimations_();
}
});
},

/**
Expand Down
14 changes: 3 additions & 11 deletions chrome/browser/resources/print_preview/new/destination_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,9 @@ Polymer({
return;
}

// TODO (rbpotter): Remove this conditional when the Polymer 2 migration
// is completed.
if (Polymer.DomIf) {
Polymer.RenderStatus.beforeNextRender(this.$.destinationSelect, () => {
this.$.destinationSelect.updateDestination();
});
} else {
this.$.destinationSelect.async(() => {
this.$.destinationSelect.updateDestination();
});
}
Polymer.RenderStatus.beforeNextRender(this.$.destinationSelect, () => {
this.$.destinationSelect.updateDestination();
});
},
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ Polymer({
*/
onAddressMenuTap_: function(e) {
const menuEvent = /** @type {!{model: !{item: !Object}}} */ (e);

// TODO(dpapad): The [dataHost][dataHost] workaround is only necessary for
// Polymer 1. Remove once migration to Polymer 2 has completed.
const item = Polymer.DomIf ? menuEvent.model.item :
menuEvent.model['dataHost']['dataHost'].item;
const item = menuEvent.model.item;

// Copy item so dialog won't update model on cancel.
this.activeAddress = /** @type {!chrome.autofillPrivate.AddressEntry} */ (
Expand Down
22 changes: 8 additions & 14 deletions chrome/browser/resources/settings/basic_page/basic_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,15 @@ Polymer({
* @private
*/
advancedToggleExpandedChanged_: function() {
if (this.advancedToggleExpanded) {
// In Polymer2, async() does not wait long enough for layout to complete.
// Polymer.RenderStatus.beforeNextRender() must be used instead.
// TODO (rbpotter): Remove conditional when migration to Polymer 2 is
// completed.
if (Polymer.DomIf) {
Polymer.RenderStatus.beforeNextRender(this, () => {
this.$$('#advancedPageTemplate').get();
});
} else {
this.async(() => {
this.$$('#advancedPageTemplate').get();
});
}
if (!this.advancedToggleExpanded) {
return;
}

// In Polymer2, async() does not wait long enough for layout to complete.
// Polymer.RenderStatus.beforeNextRender() must be used instead.
Polymer.RenderStatus.beforeNextRender(this, () => {
this.$$('#advancedPageTemplate').get();
});
},

advancedToggleClicked_: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,6 @@ Polymer({
this.saveScroll(this.$.pairedDevices);
this.saveScroll(this.$.unpairedDevices);

// In Polymer 1, default values for |pairedDeviceList_| and
// |unpairedDeviceList_| might not have been set yet by the time
// |deviceList_| changes.
if (this.pairedDeviceList_ === undefined) {
this.pairedDeviceList_ = [];
}
if (this.unpairedDeviceList_ === undefined) {
this.unpairedDeviceList_ = [];
}

this.pairedDeviceList_ = this.getUpdatedDeviceList_(
this.pairedDeviceList_,
this.deviceList_.filter(d => d.paired || d.connecting));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ Polymer({
},

/** @private */
showingSubpage_: {
type: Boolean,
// TODO(dpapad): Initial value only needed for Polymer 1, remove once
// Polymer 2 migration is done.
value: false,
},
showingSubpage_: Boolean,

toolbarSpinnerActive: {
type: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,15 @@ Polymer({
* @private
*/
advancedToggleExpandedChanged_: function() {
if (this.advancedToggleExpanded) {
// In Polymer2, async() does not wait long enough for layout to complete.
// Polymer.RenderStatus.beforeNextRender() must be used instead.
// TODO (rbpotter): Remove conditional when migration to Polymer 2 is
// completed.
if (Polymer.DomIf) {
Polymer.RenderStatus.beforeNextRender(this, () => {
this.$$('#advancedPageTemplate').get();
});
} else {
this.async(() => {
this.$$('#advancedPageTemplate').get();
});
}
if (!this.advancedToggleExpanded) {
return;
}

// In Polymer2, async() does not wait long enough for layout to complete.
// Polymer.RenderStatus.beforeNextRender() must be used instead.
Polymer.RenderStatus.beforeNextRender(this, () => {
this.$$('#advancedPageTemplate').get();
});
},

advancedToggleClicked_: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,9 @@ Polymer({
properties: {
/**
* List of options for the drop-down menu.
* @type {?DropdownMenuOptionList}
* @type {!DropdownMenuOptionList}
*/
menuOptions: {
type: Array,
// TODO(dpapad): This seems unnecessary in Polymer 2, since any
// bindings/observers will execute anyway, even if this is undefined.
// Consider removing once migration is done.
value: null,
},
menuOptions: Array,

/** Whether the dropdown menu should be disabled. */
disabled: {
Expand Down Expand Up @@ -115,7 +109,7 @@ Polymer({
return;
}

if (this.menuOptions === null || !this.menuOptions.length) {
if (!this.menuOptions.length) {
return;
}

Expand Down Expand Up @@ -174,6 +168,6 @@ Polymer({
*/
shouldDisableMenu_: function() {
return this.disabled || this.isPrefEnforced() ||
this.menuOptions === null || this.menuOptions.length == 0;
this.menuOptions === undefined || this.menuOptions.length == 0;
},
});
22 changes: 0 additions & 22 deletions chrome/browser/resources/settings/controls/settings_idle_load.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ Polymer({
return this.loading_;
},

/**
* TODO(dpapad): Delete this method once migration to Polymer 2 has finished.
* @param {string} prop
* @param {Object} value
*/
_forwardParentProp: function(prop, value) {
if (this.child_) {
this.child_._templateInstance[prop] = value;
}
},

/**
* TODO(dpapad): Delete this method once migration to Polymer 2 has finished.
* @param {string} path
* @param {Object} value
*/
_forwardParentPath: function(path, value) {
if (this.child_) {
this.child_._templateInstance.notifyPath(path, value, true);
}
},

/**
* @param {string} prop
* @param {Object} value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ Polymer({
},

/** @private */
showingSubpage_: {
type: Boolean,
// TODO(dpapad): Initial value only needed for Polymer 1, remove once
// Polymer 2 migration is done.
value: false,
},
showingSubpage_: Boolean,

toolbarSpinnerActive: {
type: Boolean,
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/resources/settings/settings_page/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ js_library("settings_animated_pages") {
"//ui/webui/resources/js:util",
"//ui/webui/resources/js/cr/ui:focus_without_ink",
]
externs_list = [ "$externs_path/pending.js" ]
}

js_library("settings_section") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ cr.define('settings', function() {
return Promise.resolve(section);
}

// TODO(dpapad): Remove condition when Polymer 2 migration is complete.
// The function to use to wait for <dom-if>s to render.
const waitFn = Polymer.DomIf ?
Polymer.RenderStatus.beforeNextRender.bind(null, this) :
requestAnimationFrame;
const waitFn = Polymer.RenderStatus.beforeNextRender.bind(null, this);

return new Promise(resolve => {
if (this.shouldExpandAdvanced_(route)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,17 @@ Polymer({
*/
ensureSubpageInstance_: function() {
const routePath = settings.getCurrentRoute().path;
/* TODO(dpapad): Remove conditional logic once migration to Polymer 2 is
* completed. */
const domIf = this.querySelector(
(Polymer.DomIf ? 'dom-if' : 'template') +
`[route-path='${routePath}']`);

// Nothing to do if the subpage isn't wrapped in a <dom-if>
// (or <template is="dom-if" for Poylmer 1) or the template is already
// stamped.
const domIf = this.querySelector(`dom-if[route-path='${routePath}']`);

// Nothing to do if the subpage isn't wrapped in a <dom-if> or the template
// is already stamped.
if (!domIf || domIf.if) {
return;
}

// Set the subpage's id for use by neon-animated-pages.
// TODO(dpapad): Remove conditional logic once migration to Polymer 2 is
// completed.
const content = Polymer.DomIf ?
Polymer.DomIf._contentForTemplate(domIf.firstElementChild) :
/** @type {{_content: DocumentFragment}} */ (domIf)._content;
const content = Polymer.DomIf._contentForTemplate(
/** @type {!HTMLTemplateElement} */ (domIf.firstElementChild));
const subpage = content.querySelector('settings-subpage');
subpage.setAttribute('route-path', routePath);

Expand Down
13 changes: 4 additions & 9 deletions chrome/test/data/webui/settings/all_sites_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,10 @@ suite('AllSites', function() {
// Use resolver to ensure that the list container is populated.
const resolver = new PromiseResolver();
// In Polymer2, we need to wait until after the next render for the list
// to be populated. TODO (rbpotter): Remove conditional when migration to
// Polymer 2 is completed.
if (Polymer.DomIf) {
Polymer.RenderStatus.beforeNextRender(testElement, () => {
resolver.resolve();
});
} else {
testElement.async(resolver.resolve);
}
// to be populated.
Polymer.RenderStatus.beforeNextRender(testElement, () => {
resolver.resolve();
});
return resolver.promise.then(() => {
assertEquals(3, testElement.siteGroupMap.size);

Expand Down
8 changes: 3 additions & 5 deletions chrome/test/data/webui/settings/autofill_page_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ cr.define('settings_autofill_page', function() {
element.prefs = prefsElement.prefs;
document.body.appendChild(element);

// TODO(dpapad): Update this once migration to Polymer 2 is done.
const domIfTag = Polymer.DomIf ? 'dom-if' : 'template';
element.$$(`${domIfTag}[route-path="/passwords"]`).if = true;
element.$$(`${domIfTag}[route-path="/payments"]`).if = true;
element.$$(`${domIfTag}[route-path="/addresses"]`).if = true;
element.$$('dom-if[route-path="/passwords"]').if = true;
element.$$('dom-if[route-path="/payments"]').if = true;
element.$$('dom-if[route-path="/addresses"]').if = true;
Polymer.dom.flush();
return element;
}
Expand Down
15 changes: 15 additions & 0 deletions third_party/closure_compiler/externs/pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ Polymer.IronIconsetSvg = function() {};
*/
Polymer.IronIconsetSvg.prototype.createIcon = function(iconName, targetIsRTL) {};

/**
* @see
* https://polymer-library.polymer-project.org/2.0/api/elements/Polymer.DomIf
* @constructor
*/
Polymer.DomIf = function() {};

/**
* @param {!HTMLTemplateElement} template
* @return {!HTMLElement}
* TODO(dpapad): Figure out if there is a better way to type-check Polymer2
* while still using legacy Polymer1 syntax.
*/
Polymer.DomIf._contentForTemplate = function(template) {};

/**
* @see
* https://github.com/tc39/proposal-bigint
Expand Down

0 comments on commit bb6be13

Please sign in to comment.