OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 assert(condition,opt_message){if(!condition){var message="Assertion fai
led";if(opt_message)message=message+": "+opt_message;var error=new Error(message
);var global=function(){return this}();if(global.traceAssertionsForTesting)conso
le.warn(error.stack);throw error}return condition}function assertNotReached(opt_
message){assert(false,opt_message||"Unreachable code hit")}function assertInstan
ceof(value,type,opt_message){if(!(value instanceof type)){assertNotReached(opt_m
essage||"Value "+value+" is not a[n] "+(type.name||typeof type))}return value} | 4 function assert(condition,opt_message){if(!condition){var message="Assertion fai
led";if(opt_message)message=message+": "+opt_message;var error=new Error(message
);var global=function(){return this}();if(global.traceAssertionsForTesting)conso
le.warn(error.stack);throw error}return condition}function assertNotReached(opt_
message){assert(false,opt_message||"Unreachable code hit")}function assertInstan
ceof(value,type,opt_message){if(!(value instanceof type)){assertNotReached(opt_m
essage||"Value "+value+" is not a[n] "+(type.name||typeof type))}return value} |
5 // Copyright 2016 The Chromium Authors. All rights reserved. | 5 // Copyright 2016 The Chromium Authors. All rights reserved. |
6 // Use of this source code is governed by a BSD-style license that can be | 6 // Use of this source code is governed by a BSD-style license that can be |
7 // found in the LICENSE file. | 7 // found in the LICENSE file. |
8 function PromiseResolver(){this.resolve_;this.reject_;this.promise_=new Promise(
function(resolve,reject){this.resolve_=resolve;this.reject_=reject}.bind(this))}
PromiseResolver.prototype={get promise(){return this.promise_},set promise(p){as
sertNotReached()},get resolve(){return this.resolve_},set resolve(r){assertNotRe
ached()},get reject(){return this.reject_},set reject(s){assertNotReached()}}; | 8 function PromiseResolver(){this.resolve_;this.reject_;this.promise_=new Promise(
function(resolve,reject){this.resolve_=resolve;this.reject_=reject}.bind(this))}
PromiseResolver.prototype={get promise(){return this.promise_},set promise(p){as
sertNotReached()},get resolve(){return this.resolve_},set resolve(r){assertNotRe
ached()},get reject(){return this.reject_},set reject(s){assertNotReached()}}; |
9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
10 // Use of this source code is governed by a BSD-style license that can be | 10 // Use of this source code is governed by a BSD-style license that can be |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // Use of this source code is governed by a BSD-style license that can be | 57 // Use of this source code is governed by a BSD-style license that can be |
58 // found in the LICENSE file. | 58 // found in the LICENSE file. |
59 Polymer({is:"cr-toolbar",properties:{pageName:String,searchPrompt:String,clearLa
bel:String,menuLabel:String,menuPromo:String,spinnerActive:Boolean,showMenu:{typ
e:Boolean,value:false},showMenuPromo:{type:Boolean,value:false},closeMenuPromo:S
tring,narrow_:{type:Boolean,reflectToAttribute:true},showingSearch_:{type:Boolea
n,reflectToAttribute:true}},observers:["possiblyShowMenuPromo_(showMenu, showMen
uPromo, showingSearch_)"],getSearchField:function(){return this.$.search},onClos
ePromoTap_:function(){this.fire("cr-toolbar-menu-promo-close")},onMenuTap_:funct
ion(){this.fire("cr-toolbar-menu-tap")},possiblyShowMenuPromo_:function(){Polyme
r.RenderStatus.afterNextRender(this,function(){if(this.showMenu&&this.showMenuPr
omo&&!this.showingSearch_){this.$$("#menuPromo").animate({opacity:[0,.9]},{durat
ion:500,fill:"forwards"});this.fire("cr-toolbar-menu-promo-shown")}}.bind(this))
},titleIfNotShowMenuPromo_:function(title,showMenuPromo){return showMenuPromo?""
:title}}); | 59 Polymer({is:"cr-toolbar",properties:{pageName:String,searchPrompt:String,clearLa
bel:String,menuLabel:String,menuPromo:String,spinnerActive:Boolean,showMenu:{typ
e:Boolean,value:false},showMenuPromo:{type:Boolean,value:false},closeMenuPromo:S
tring,narrow_:{type:Boolean,reflectToAttribute:true},showingSearch_:{type:Boolea
n,reflectToAttribute:true}},observers:["possiblyShowMenuPromo_(showMenu, showMen
uPromo, showingSearch_)"],getSearchField:function(){return this.$.search},onClos
ePromoTap_:function(){this.fire("cr-toolbar-menu-promo-close")},onMenuTap_:funct
ion(){this.fire("cr-toolbar-menu-tap")},possiblyShowMenuPromo_:function(){Polyme
r.RenderStatus.afterNextRender(this,function(){if(this.showMenu&&this.showMenuPr
omo&&!this.showingSearch_){this.$$("#menuPromo").animate({opacity:[0,.9]},{durat
ion:500,fill:"forwards"});this.fire("cr-toolbar-menu-promo-shown")}}.bind(this))
},titleIfNotShowMenuPromo_:function(title,showMenuPromo){return showMenuPromo?""
:title}}); |
60 // Copyright 2015 The Chromium Authors. All rights reserved. | 60 // Copyright 2015 The Chromium Authors. All rights reserved. |
61 // Use of this source code is governed by a BSD-style license that can be | 61 // Use of this source code is governed by a BSD-style license that can be |
62 // found in the LICENSE file. | 62 // found in the LICENSE file. |
63 cr.define("downloads",function(){var Toolbar=Polymer({is:"downloads-toolbar",pro
perties:{downloadsShowing:{reflectToAttribute:true,type:Boolean,value:false,obse
rver:"downloadsShowingChanged_"},spinnerActive:{type:Boolean,notify:true}},liste
ners:{"paper-dropdown-close":"onPaperDropdownClose_","paper-dropdown-open":"onPa
perDropdownOpen_"},canUndo:function(){return!this.$.toolbar.getSearchField().isS
earchFocused()},canClearAll:function(){return!this.$.toolbar.getSearchField().ge
tValue()&&this.downloadsShowing},onFindCommand:function(){this.$.toolbar.getSear
chField().showAndFocus()},closeMoreActions_:function(){this.$.more.close()},down
loadsShowingChanged_:function(){this.updateClearAll_()},onClearAllTap_:function(
){assert(this.canClearAll());downloads.ActionService.getInstance().clearAll()},o
nPaperDropdownClose_:function(){window.removeEventListener("resize",assert(this.
boundClose_))},onItemBlur_:function(e){var menu=this.$$("paper-menu");if(menu.it
ems.indexOf(e.relatedTarget)>=0)return;this.$.more.restoreFocusOnClose=false;thi
s.closeMoreActions_();this.$.more.restoreFocusOnClose=true},onPaperDropdownOpen_
:function(){this.boundClose_=this.boundClose_||this.closeMoreActions_.bind(this)
;window.addEventListener("resize",this.boundClose_)},onSearchChanged_:function(e
vent){var actionService=downloads.ActionService.getInstance();if(actionService.s
earch(event.detail))this.spinnerActive=actionService.isSearching();this.updateCl
earAll_()},onOpenDownloadsFolderTap_:function(){downloads.ActionService.getInsta
nce().openDownloadsFolder()},updateClearAll_:function(){this.$$("paper-menu .cle
ar-all").hidden=!this.canClearAll()}});return{Toolbar:Toolbar}}); | 63 cr.define("downloads",function(){var Toolbar=Polymer({is:"downloads-toolbar",pro
perties:{downloadsShowing:{reflectToAttribute:true,type:Boolean,value:false,obse
rver:"downloadsShowingChanged_"},spinnerActive:{type:Boolean,notify:true}},liste
ners:{"paper-dropdown-close":"onPaperDropdownClose_","paper-dropdown-open":"onPa
perDropdownOpen_"},canUndo:function(){return!this.$.toolbar.getSearchField().isS
earchFocused()},canClearAll:function(){return!this.$.toolbar.getSearchField().ge
tValue()&&this.downloadsShowing},onFindCommand:function(){this.$.toolbar.getSear
chField().showAndFocus()},closeMoreActions_:function(){this.$.more.close()},down
loadsShowingChanged_:function(){this.updateClearAll_()},onClearAllTap_:function(
){assert(this.canClearAll());downloads.ActionService.getInstance().clearAll()},o
nPaperDropdownClose_:function(){window.removeEventListener("resize",assert(this.
boundClose_))},onItemBlur_:function(e){var menu=this.$$("paper-menu");if(menu.it
ems.indexOf(e.relatedTarget)>=0)return;this.$.more.restoreFocusOnClose=false;thi
s.closeMoreActions_();this.$.more.restoreFocusOnClose=true},onPaperDropdownOpen_
:function(){this.boundClose_=this.boundClose_||this.closeMoreActions_.bind(this)
;window.addEventListener("resize",this.boundClose_)},onSearchChanged_:function(e
vent){var actionService=downloads.ActionService.getInstance();if(actionService.s
earch(event.detail))this.spinnerActive=actionService.isSearching();this.updateCl
earAll_()},onOpenDownloadsFolderTap_:function(){downloads.ActionService.getInsta
nce().openDownloadsFolder()},updateClearAll_:function(){this.$$("paper-menu .cle
ar-all").hidden=!this.canClearAll()}});return{Toolbar:Toolbar}}); |
64 // Copyright 2015 The Chromium Authors. All rights reserved. | 64 // Copyright 2015 The Chromium Authors. All rights reserved. |
65 // Use of this source code is governed by a BSD-style license that can be | 65 // Use of this source code is governed by a BSD-style license that can be |
66 // found in the LICENSE file. | 66 // found in the LICENSE file. |
67 cr.define("downloads",function(){var Manager=Polymer({is:"downloads-manager",pro
perties:{hasDownloads_:{observer:"hasDownloadsChanged_",type:Boolean},hasShadow_
:{type:Boolean,value:false,reflectToAttribute:true},inSearchMode_:{type:Boolean,
value:false},items_:{type:Array,value:function(){return[]}},spinnerActive_:{type
:Boolean,notify:true}},hostAttributes:{loading:true},listeners:{"downloads-list.
scroll":"onListScroll_","toolbar.search-changed":"onSearchChanged_"},observers:[
"itemsChanged_(items_.*)"],clearAll_:function(){this.set("items_",[])},hasDownlo
adsChanged_:function(){if(loadTimeData.getBoolean("allowDeletingHistory"))this.$
.toolbar.downloadsShowing=this.hasDownloads_;if(this.hasDownloads_)this.$["downl
oads-list"].fire("iron-resize")},insertItems_:function(index,list){this.splice.a
pply(this,["items_",index,0].concat(list));this.updateHideDates_(index,index+lis
t.length);this.removeAttribute("loading");this.spinnerActive_=false},itemsChange
d_:function(){this.hasDownloads_=this.items_.length>0},noDownloadsText_:function
(){return loadTimeData.getString(this.inSearchMode_?"noSearchResults":"noDownloa
ds")},onCanExecute_:function(e){e=e;switch(e.command.id){case"undo-command":e.ca
nExecute=this.$.toolbar.canUndo();break;case"clear-all-command":e.canExecute=thi
s.$.toolbar.canClearAll();break;case"find-command":e.canExecute=true;break}},onC
ommand_:function(e){if(e.command.id=="clear-all-command")downloads.ActionService
.getInstance().clearAll();else if(e.command.id=="undo-command")downloads.ActionS
ervice.getInstance().undo();else if(e.command.id=="find-command")this.$.toolbar.
onFindCommand()},onListScroll_:function(){var list=this.$["downloads-list"];if(l
ist.scrollHeight-list.scrollTop-list.offsetHeight<=100){downloads.ActionService.
getInstance().loadMore()}this.hasShadow_=list.scrollTop>0},onLoad_:function(){cr
.ui.decorate("command",cr.ui.Command);document.addEventListener("canExecute",thi
s.onCanExecute_.bind(this));document.addEventListener("command",this.onCommand_.
bind(this));downloads.ActionService.getInstance().loadMore()},onSearchChanged_:f
unction(){this.inSearchMode_=downloads.ActionService.getInstance().isSearching()
},removeItem_:function(index){this.splice("items_",index,1);this.updateHideDates
_(index,index);this.onListScroll_()},updateHideDates_:function(start,end){for(va
r i=start;i<=end;++i){var current=this.items_[i];if(!current)continue;var prev=t
his.items_[i-1];var hideDate=!!prev&&prev.date_string==current.date_string;this.
set("items_."+i+".hideDate",hideDate)}},updateItem_:function(index,data){this.se
t("items_."+index,data);this.updateHideDates_(index,index);var list=this.$["down
loads-list"];list.updateSizeForItem(index)}});Manager.clearAll=function(){Manage
r.get().clearAll_()};Manager.get=function(){return queryRequiredElement("downloa
ds-manager")};Manager.insertItems=function(index,list){Manager.get().insertItems
_(index,list)};Manager.onLoad=function(){Manager.get().onLoad_()};Manager.remove
Item=function(index){Manager.get().removeItem_(index)};Manager.updateItem=functi
on(index,data){Manager.get().updateItem_(index,data)};return{Manager:Manager}}); | 67 cr.define("downloads",function(){var Manager=Polymer({is:"downloads-manager",pro
perties:{hasDownloads_:{observer:"hasDownloadsChanged_",type:Boolean},hasShadow_
:{type:Boolean,value:false,reflectToAttribute:true},inSearchMode_:{type:Boolean,
value:false},items_:{type:Array,value:function(){return[]}},spinnerActive_:{type
:Boolean,notify:true}},hostAttributes:{loading:true},listeners:{"downloads-list.
scroll":"onListScroll_","toolbar.search-changed":"onSearchChanged_"},observers:[
"itemsChanged_(items_.*)"],loaded_:new PromiseResolver,clearAll_:function(){this
.set("items_",[])},hasDownloadsChanged_:function(){if(loadTimeData.getBoolean("a
llowDeletingHistory"))this.$.toolbar.downloadsShowing=this.hasDownloads_;if(this
.hasDownloads_)this.$["downloads-list"].fire("iron-resize")},insertItems_:functi
on(index,list){this.splice.apply(this,["items_",index,0].concat(list));this.upda
teHideDates_(index,index+list.length);if(this.hasAttribute("loading")){this.remo
veAttribute("loading");this.loaded_.resolve()}this.spinnerActive_=false},itemsCh
anged_:function(){this.hasDownloads_=this.items_.length>0},noDownloadsText_:func
tion(){return loadTimeData.getString(this.inSearchMode_?"noSearchResults":"noDow
nloads")},onCanExecute_:function(e){e=e;switch(e.command.id){case"undo-command":
e.canExecute=this.$.toolbar.canUndo();break;case"clear-all-command":e.canExecute
=this.$.toolbar.canClearAll();break;case"find-command":e.canExecute=true;break}}
,onCommand_:function(e){if(e.command.id=="clear-all-command")downloads.ActionSer
vice.getInstance().clearAll();else if(e.command.id=="undo-command")downloads.Act
ionService.getInstance().undo();else if(e.command.id=="find-command")this.$.tool
bar.onFindCommand()},onListScroll_:function(){var list=this.$["downloads-list"];
if(list.scrollHeight-list.scrollTop-list.offsetHeight<=100){downloads.ActionServ
ice.getInstance().loadMore()}this.hasShadow_=list.scrollTop>0},onLoad_:function(
){cr.ui.decorate("command",cr.ui.Command);document.addEventListener("canExecute"
,this.onCanExecute_.bind(this));document.addEventListener("command",this.onComma
nd_.bind(this));downloads.ActionService.getInstance().loadMore();return this.loa
ded_.promise},onSearchChanged_:function(){this.inSearchMode_=downloads.ActionSer
vice.getInstance().isSearching()},removeItem_:function(index){this.splice("items
_",index,1);this.updateHideDates_(index,index);this.onListScroll_()},updateHideD
ates_:function(start,end){for(var i=start;i<=end;++i){var current=this.items_[i]
;if(!current)continue;var prev=this.items_[i-1];var hideDate=!!prev&&prev.date_s
tring==current.date_string;this.set("items_."+i+".hideDate",hideDate)}},updateIt
em_:function(index,data){this.set("items_."+index,data);this.updateHideDates_(in
dex,index);var list=this.$["downloads-list"];list.updateSizeForItem(index)}});Ma
nager.clearAll=function(){Manager.get().clearAll_()};Manager.get=function(){retu
rn queryRequiredElement("downloads-manager")};Manager.insertItems=function(index
,list){Manager.get().insertItems_(index,list)};Manager.onLoad=function(){return
Manager.get().onLoad_()};Manager.removeItem=function(index){Manager.get().remove
Item_(index)};Manager.updateItem=function(index,data){Manager.get().updateItem_(
index,data)};return{Manager:Manager}}); |
68 // Copyright 2015 The Chromium Authors. All rights reserved. | 68 // Copyright 2015 The Chromium Authors. All rights reserved. |
69 // Use of this source code is governed by a BSD-style license that can be | 69 // Use of this source code is governed by a BSD-style license that can be |
70 // found in the LICENSE file. | 70 // found in the LICENSE file. |
71 window.addEventListener("load",function(){downloads.Manager.onLoad();document.fo
nts.load("bold 12px Roboto")}); | 71 window.addEventListener("load",function(){downloads.Manager.onLoad().then(functi
on(){requestIdleCallback(function(){chrome.send("metricsHandler:recordTime",["Do
wnload.ResultsRenderedTime",window.performance.now()]);document.fonts.load("bold
12px Roboto")})})}); |
OLD | NEW |