| Index: chrome/browser/resources/settings/controls/settings_idle_render.js
|
| diff --git a/chrome/browser/resources/settings/controls/settings_idle_render.js b/chrome/browser/resources/settings/controls/settings_idle_render.js
|
| index 8e224c9e5414b54437e08f556a7411fdbb2a9868..89c8fde70e60a88bcc85cb1fea306b5575978c36 100644
|
| --- a/chrome/browser/resources/settings/controls/settings_idle_render.js
|
| +++ b/chrome/browser/resources/settings/controls/settings_idle_render.js
|
| @@ -12,11 +12,19 @@
|
| */
|
|
|
| Polymer({
|
| - is: 'settings-idle-render',
|
| + is: 'settings-idle-load',
|
| extends: 'template',
|
|
|
| behaviors: [Polymer.Templatizer],
|
|
|
| + properties: {
|
| + /**
|
| + * If specified, it will be loaded via an HTML import before stamping the
|
| + * template.
|
| + */
|
| + url: String,
|
| + },
|
| +
|
| /** @private {TemplatizerNode} */
|
| child_: null,
|
|
|
| @@ -25,7 +33,7 @@ Polymer({
|
|
|
| /** @override */
|
| attached: function() {
|
| - this.idleCallback_ = requestIdleCallback(this.render_.bind(this));
|
| + this.idleCallback_ = requestIdleCallback(this.get.bind(this));
|
| },
|
|
|
| /** @override */
|
| @@ -35,25 +43,31 @@ Polymer({
|
| },
|
|
|
| /**
|
| - * Stamp the template into the DOM tree synchronously
|
| - * @return {Element} Child element which has been stamped into the DOM tree.
|
| + * @return {!Promise<Element>} Child element which has been stamped into the
|
| + * DOM tree.
|
| */
|
| get: function() {
|
| - if (!this.child_)
|
| - this.render_();
|
| - return this.child_;
|
| - },
|
| + if (this.loading_)
|
| + return this.loading_;
|
| +
|
| + this.loading_ = new Promise(function(resolve, reject) {
|
| + this.importHref(
|
| + this.url,
|
| + function() {
|
| + assert(!this.ctor);
|
| + this.templatize(this);
|
| + assert(this.ctor);
|
| + var instance = this.stamp({});
|
| + assert(!this.child_);
|
| + this.child_ = instance.root.firstElementChild;
|
| + this.parentNode.insertBefore(instance.root, this);
|
| + resolve(this.child_);
|
| + this.fire('lazy-loaded');
|
| + }.bind(this),
|
| + reject, true);
|
| + }.bind(this));
|
|
|
| - /** @private */
|
| - render_: function() {
|
| - if (!this.ctor)
|
| - this.templatize(this);
|
| - var parentNode = this.parentNode;
|
| - if (parentNode && !this.child_) {
|
| - var instance = this.stamp({});
|
| - this.child_ = instance.root.firstElementChild;
|
| - parentNode.insertBefore(instance.root, this);
|
| - }
|
| + return this.loading_;
|
| },
|
|
|
| /**
|
|
|