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

Side by Side Diff: chrome/browser/resources/md_history/app.crisper.js

Issue 2341923005: MD WebUI: Make cr-lazy-render get() synchronous (Closed)
Patch Set: Simplify test more Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 function PromiseResolver() { 4 function PromiseResolver() {
5 this.resolve_; 5 this.resolve_;
6 this.reject_; 6 this.reject_;
7 this.promise_ = new Promise(function(resolve, reject) { 7 this.promise_ = new Promise(function(resolve, reject) {
8 this.resolve_ = resolve; 8 this.resolve_ = resolve;
9 this.reject_ = reject; 9 this.reject_ = reject;
10 }.bind(this)); 10 }.bind(this));
(...skipping 5369 matching lines...) Expand 10 before | Expand all | Expand 10 after
5380 } 5380 }
5381 }); 5381 });
5382 5382
5383 // Copyright 2016 The Chromium Authors. All rights reserved. 5383 // Copyright 2016 The Chromium Authors. All rights reserved.
5384 // Use of this source code is governed by a BSD-style license that can be 5384 // Use of this source code is governed by a BSD-style license that can be
5385 // found in the LICENSE file. 5385 // found in the LICENSE file.
5386 Polymer({ 5386 Polymer({
5387 is: 'cr-lazy-render', 5387 is: 'cr-lazy-render',
5388 "extends": 'template', 5388 "extends": 'template',
5389 behaviors: [ Polymer.Templatizer ], 5389 behaviors: [ Polymer.Templatizer ],
5390 _renderPromise: null, 5390 child_: null,
5391 _child: null,
5392 get: function() { 5391 get: function() {
5393 if (!this._renderPromise) { 5392 if (!this.child_) this.render_();
5394 this._renderPromise = new Promise(function(resolve) { 5393 return this.child_;
5395 this._debounceTemplate(function() {
5396 this._render();
5397 this._renderPromise = null;
5398 resolve(this.getIfExists());
5399 }.bind(this));
5400 }.bind(this));
5401 }
5402 return this._renderPromise;
5403 }, 5394 },
5404 getIfExists: function() { 5395 getIfExists: function() {
5405 return this._child; 5396 return this.child_;
5406 }, 5397 },
5407 _render: function() { 5398 render_: function() {
5408 if (!this.ctor) this.templatize(this); 5399 if (!this.ctor) this.templatize(this);
5409 var parentNode = this.parentNode; 5400 var parentNode = this.parentNode;
5410 if (parentNode && !this._child) { 5401 if (parentNode && !this.child_) {
5411 var instance = this.stamp({}); 5402 var instance = this.stamp({});
5412 this._child = instance.root.querySelector('*'); 5403 this.child_ = instance.root.firstElementChild;
5413 parentNode.insertBefore(instance.root, this); 5404 parentNode.insertBefore(instance.root, this);
5414 } 5405 }
5415 }, 5406 },
5416 _forwardParentProp: function(prop, value) { 5407 _forwardParentProp: function(prop, value) {
5417 if (this._child) this._child._templateInstance[prop] = value; 5408 if (this.child_) this.child_._templateInstance[prop] = value;
5418 }, 5409 },
5419 _forwardParentPath: function(path, value) { 5410 _forwardParentPath: function(path, value) {
5420 if (this._child) this._child._templateInstance.notifyPath(path, value, true) ; 5411 if (this.child_) this.child_._templateInstance.notifyPath(path, value, true) ;
5421 } 5412 }
5422 }); 5413 });
5423 5414
5424 (function() { 5415 (function() {
5425 'use strict'; 5416 'use strict';
5426 Polymer.IronA11yAnnouncer = Polymer({ 5417 Polymer.IronA11yAnnouncer = Polymer({
5427 is: 'iron-a11y-announcer', 5418 is: 'iron-a11y-announcer',
5428 properties: { 5419 properties: {
5429 mode: { 5420 mode: {
5430 type: String, 5421 type: String,
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
6131 if (this.searchTerm == search) return; 6122 if (this.searchTerm == search) return;
6132 this.searchTerm = search; 6123 this.searchTerm = search;
6133 var searchField = this.$['main-toolbar'].getSearchField(); 6124 var searchField = this.$['main-toolbar'].getSearchField();
6134 searchField.showAndFocus(); 6125 searchField.showAndFocus();
6135 searchField.setValue(search); 6126 searchField.setValue(search);
6136 }, 6127 },
6137 onSearchChanged_: function(event) { 6128 onSearchChanged_: function(event) {
6138 this.searchTerm = event.detail; 6129 this.searchTerm = event.detail;
6139 }, 6130 },
6140 onInfoButtonTap_: function() { 6131 onInfoButtonTap_: function() {
6141 this.$.syncNotice.get().then(function(dropdown) { 6132 var dropdown = this.$.syncNotice.get();
6142 dropdown.positionTarget = this.$$('#info-button-icon'); 6133 dropdown.positionTarget = this.$$('#info-button-icon');
6143 if (dropdown.style.display == 'none') dropdown.open(); 6134 if (dropdown.style.display == 'none') dropdown.open();
6144 }.bind(this));
6145 }, 6135 },
6146 onClearSelectionTap_: function() { 6136 onClearSelectionTap_: function() {
6147 this.fire('unselect-all'); 6137 this.fire('unselect-all');
6148 }, 6138 },
6149 onDeleteTap_: function() { 6139 onDeleteTap_: function() {
6150 this.fire('delete-selected'); 6140 this.fire('delete-selected');
6151 }, 6141 },
6152 get searchBar() { 6142 get searchBar() {
6153 return this.$['main-toolbar'].getSearchField(); 6143 return this.$['main-toolbar'].getSearchField();
6154 }, 6144 },
(...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after
8124 }, 8114 },
8125 unselectAllItems: function(count) { 8115 unselectAllItems: function(count) {
8126 var selectedList = this.getSelectedList_(); 8116 var selectedList = this.getSelectedList_();
8127 if (selectedList) selectedList.unselectAllItems(count); 8117 if (selectedList) selectedList.unselectAllItems(count);
8128 }, 8118 },
8129 deleteSelectedWithPrompt: function() { 8119 deleteSelectedWithPrompt: function() {
8130 if (!loadTimeData.getBoolean('allowDeletingHistory')) return; 8120 if (!loadTimeData.getBoolean('allowDeletingHistory')) return;
8131 var browserService = md_history.BrowserService.getInstance(); 8121 var browserService = md_history.BrowserService.getInstance();
8132 browserService.recordAction('RemoveSelected'); 8122 browserService.recordAction('RemoveSelected');
8133 if (this.queryState.searchTerm != '') browserService.recordAction('SearchRes ultRemove'); 8123 if (this.queryState.searchTerm != '') browserService.recordAction('SearchRes ultRemove');
8134 this.$.dialog.get().then(function(dialog) { 8124 this.$.dialog.get().showModal();
8135 dialog.showModal();
8136 });
8137 }, 8125 },
8138 groupedRangeChanged_: function(range, oldRange) { 8126 groupedRangeChanged_: function(range, oldRange) {
8139 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 'infinite-list' : 'gro uped-list'; 8127 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 'infinite-list' : 'gro uped-list';
8140 if (oldRange == undefined) return; 8128 if (oldRange == undefined) return;
8141 this.queryHistory(false); 8129 this.queryHistory(false);
8142 this.fire('history-view-changed'); 8130 this.fire('history-view-changed');
8143 }, 8131 },
8144 loadMoreHistory_: function() { 8132 loadMoreHistory_: function() {
8145 this.queryHistory(true); 8133 this.queryHistory(true);
8146 }, 8134 },
(...skipping 18 matching lines...) Expand all
8165 md_history.BrowserService.getInstance().recordAction('CancelRemoveSelected') ; 8153 md_history.BrowserService.getInstance().recordAction('CancelRemoveSelected') ;
8166 var dialog = assert(this.$.dialog.getIfExists()); 8154 var dialog = assert(this.$.dialog.getIfExists());
8167 dialog.close(); 8155 dialog.close();
8168 }, 8156 },
8169 closeMenu_: function() { 8157 closeMenu_: function() {
8170 var menu = this.$.sharedMenu.getIfExists(); 8158 var menu = this.$.sharedMenu.getIfExists();
8171 if (menu) menu.closeMenu(); 8159 if (menu) menu.closeMenu();
8172 }, 8160 },
8173 toggleMenu_: function(e) { 8161 toggleMenu_: function(e) {
8174 var target = e.detail.target; 8162 var target = e.detail.target;
8175 return this.$.sharedMenu.get().then(function(menu) { 8163 var menu = this.$.sharedMenu.get();
8176 menu.toggleMenu(target, e.detail); 8164 menu.toggleMenu(target, e.detail);
8177 });
8178 }, 8165 },
8179 onMoreFromSiteTap_: function() { 8166 onMoreFromSiteTap_: function() {
8180 md_history.BrowserService.getInstance().recordAction('EntryMenuShowMoreFromS ite'); 8167 md_history.BrowserService.getInstance().recordAction('EntryMenuShowMoreFromS ite');
8181 var menu = assert(this.$.sharedMenu.getIfExists()); 8168 var menu = assert(this.$.sharedMenu.getIfExists());
8182 this.fire('search-domain', { 8169 this.fire('search-domain', {
8183 domain: menu.itemData.item.domain 8170 domain: menu.itemData.item.domain
8184 }); 8171 });
8185 menu.closeMenu(); 8172 menu.closeMenu();
8186 }, 8173 },
8187 onRemoveFromHistoryTap_: function() { 8174 onRemoveFromHistoryTap_: function() {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
8353 }; 8340 };
8354 }, 8341 },
8355 onSignInTap_: function() { 8342 onSignInTap_: function() {
8356 chrome.send('startSignInFlow'); 8343 chrome.send('startSignInFlow');
8357 }, 8344 },
8358 onListScroll_: function() { 8345 onListScroll_: function() {
8359 var menu = this.$.menu.getIfExists(); 8346 var menu = this.$.menu.getIfExists();
8360 if (menu) menu.closeMenu(); 8347 if (menu) menu.closeMenu();
8361 }, 8348 },
8362 onToggleMenu_: function(e) { 8349 onToggleMenu_: function(e) {
8363 this.$.menu.get().then(function(menu) { 8350 var menu = this.$.menu.get();
8364 menu.toggleMenu(e.detail.target, e.detail.tag); 8351 menu.toggleMenu(e.detail.target, e.detail.tag);
8365 if (menu.menuOpen) { 8352 if (menu.menuOpen) {
8366 md_history.BrowserService.getInstance().recordHistogram(SYNCED_TABS_HIST OGRAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU, SyncedTabsHistogram.LIMIT); 8353 md_history.BrowserService.getInstance().recordHistogram(SYNCED_TABS_HISTOG RAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU, SyncedTabsHistogram.LIMIT);
8367 } 8354 }
8368 });
8369 }, 8355 },
8370 onOpenAllTap_: function() { 8356 onOpenAllTap_: function() {
8371 var menu = assert(this.$.menu.getIfExists()); 8357 var menu = assert(this.$.menu.getIfExists());
8372 var browserService = md_history.BrowserService.getInstance(); 8358 var browserService = md_history.BrowserService.getInstance();
8373 browserService.recordHistogram(SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogr am.OPEN_ALL, SyncedTabsHistogram.LIMIT); 8359 browserService.recordHistogram(SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogr am.OPEN_ALL, SyncedTabsHistogram.LIMIT);
8374 browserService.openForeignSessionAllTabs(menu.itemData); 8360 browserService.openForeignSessionAllTabs(menu.itemData);
8375 menu.closeMenu(); 8361 menu.closeMenu();
8376 }, 8362 },
8377 onDeleteSessionTap_: function() { 8363 onDeleteSessionTap_: function() {
8378 var menu = assert(this.$.menu.getIfExists()); 8364 var menu = assert(this.$.menu.getIfExists());
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
8691 8677
8692 case HistoryRange.MONTH: 8678 case HistoryRange.MONTH:
8693 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; 8679 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH;
8694 break; 8680 break;
8695 } 8681 }
8696 break; 8682 break;
8697 } 8683 }
8698 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage View', histogramValue, HistoryPageViewHistogram.END); 8684 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage View', histogramValue, HistoryPageViewHistogram.END);
8699 } 8685 }
8700 }); 8686 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698