OLD | NEW |
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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 this.stopPropagation(); | 500 this.stopPropagation(); |
501 this.preventDefault(); | 501 this.preventDefault(); |
502 } | 502 } |
503 }; | 503 }; |
504 return { | 504 return { |
505 Command: Command, | 505 Command: Command, |
506 CanExecuteEvent: CanExecuteEvent | 506 CanExecuteEvent: CanExecuteEvent |
507 }; | 507 }; |
508 }); | 508 }); |
509 | 509 |
510 (function() { | |
511 'use strict'; | |
512 Polymer({ | |
513 is: 'iron-location', | |
514 properties: { | |
515 path: { | |
516 type: String, | |
517 notify: true, | |
518 value: function() { | |
519 return window.decodeURIComponent(window.location.pathname); | |
520 } | |
521 }, | |
522 query: { | |
523 type: String, | |
524 notify: true, | |
525 value: function() { | |
526 return window.decodeURIComponent(window.location.search.slice(1)); | |
527 } | |
528 }, | |
529 hash: { | |
530 type: String, | |
531 notify: true, | |
532 value: function() { | |
533 return window.decodeURIComponent(window.location.hash.slice(1)); | |
534 } | |
535 }, | |
536 dwellTime: { | |
537 type: Number, | |
538 value: 2e3 | |
539 }, | |
540 urlSpaceRegex: { | |
541 type: String, | |
542 value: '' | |
543 }, | |
544 _urlSpaceRegExp: { | |
545 computed: '_makeRegExp(urlSpaceRegex)' | |
546 }, | |
547 _lastChangedAt: { | |
548 type: Number | |
549 }, | |
550 _initialized: { | |
551 type: Boolean, | |
552 value: false | |
553 } | |
554 }, | |
555 hostAttributes: { | |
556 hidden: true | |
557 }, | |
558 observers: [ '_updateUrl(path, query, hash)' ], | |
559 attached: function() { | |
560 this.listen(window, 'hashchange', '_hashChanged'); | |
561 this.listen(window, 'location-changed', '_urlChanged'); | |
562 this.listen(window, 'popstate', '_urlChanged'); | |
563 this.listen(document.body, 'click', '_globalOnClick'); | |
564 this._lastChangedAt = window.performance.now() - (this.dwellTime - 200); | |
565 this._initialized = true; | |
566 this._urlChanged(); | |
567 }, | |
568 detached: function() { | |
569 this.unlisten(window, 'hashchange', '_hashChanged'); | |
570 this.unlisten(window, 'location-changed', '_urlChanged'); | |
571 this.unlisten(window, 'popstate', '_urlChanged'); | |
572 this.unlisten(document.body, 'click', '_globalOnClick'); | |
573 this._initialized = false; | |
574 }, | |
575 _hashChanged: function() { | |
576 this.hash = window.decodeURIComponent(window.location.hash.substring(1)); | |
577 }, | |
578 _urlChanged: function() { | |
579 this._dontUpdateUrl = true; | |
580 this._hashChanged(); | |
581 this.path = window.decodeURIComponent(window.location.pathname); | |
582 this.query = window.decodeURIComponent(window.location.search.substring(1)
); | |
583 this._dontUpdateUrl = false; | |
584 this._updateUrl(); | |
585 }, | |
586 _getUrl: function() { | |
587 var partiallyEncodedPath = window.encodeURI(this.path).replace(/\#/g, '%23
').replace(/\?/g, '%3F'); | |
588 var partiallyEncodedQuery = ''; | |
589 if (this.query) { | |
590 partiallyEncodedQuery = '?' + window.encodeURI(this.query).replace(/\#/g
, '%23'); | |
591 } | |
592 var partiallyEncodedHash = ''; | |
593 if (this.hash) { | |
594 partiallyEncodedHash = '#' + window.encodeURI(this.hash); | |
595 } | |
596 return partiallyEncodedPath + partiallyEncodedQuery + partiallyEncodedHash
; | |
597 }, | |
598 _updateUrl: function() { | |
599 if (this._dontUpdateUrl || !this._initialized) { | |
600 return; | |
601 } | |
602 if (this.path === window.decodeURIComponent(window.location.pathname) && t
his.query === window.decodeURIComponent(window.location.search.substring(1)) &&
this.hash === window.decodeURIComponent(window.location.hash.substring(1))) { | |
603 return; | |
604 } | |
605 var newUrl = this._getUrl(); | |
606 var fullNewUrl = new URL(newUrl, window.location.protocol + '//' + window.
location.host).href; | |
607 var now = window.performance.now(); | |
608 var shouldReplace = this._lastChangedAt + this.dwellTime > now; | |
609 this._lastChangedAt = now; | |
610 if (shouldReplace) { | |
611 window.history.replaceState({}, '', fullNewUrl); | |
612 } else { | |
613 window.history.pushState({}, '', fullNewUrl); | |
614 } | |
615 this.fire('location-changed', {}, { | |
616 node: window | |
617 }); | |
618 }, | |
619 _globalOnClick: function(event) { | |
620 if (event.defaultPrevented) { | |
621 return; | |
622 } | |
623 var href = this._getSameOriginLinkHref(event); | |
624 if (!href) { | |
625 return; | |
626 } | |
627 event.preventDefault(); | |
628 if (href === window.location.href) { | |
629 return; | |
630 } | |
631 window.history.pushState({}, '', href); | |
632 this.fire('location-changed', {}, { | |
633 node: window | |
634 }); | |
635 }, | |
636 _getSameOriginLinkHref: function(event) { | |
637 if (event.button !== 0) { | |
638 return null; | |
639 } | |
640 if (event.metaKey || event.ctrlKey) { | |
641 return null; | |
642 } | |
643 var eventPath = Polymer.dom(event).path; | |
644 var anchor = null; | |
645 for (var i = 0; i < eventPath.length; i++) { | |
646 var element = eventPath[i]; | |
647 if (element.tagName === 'A' && element.href) { | |
648 anchor = element; | |
649 break; | |
650 } | |
651 } | |
652 if (!anchor) { | |
653 return null; | |
654 } | |
655 if (anchor.target === '_blank') { | |
656 return null; | |
657 } | |
658 if ((anchor.target === '_top' || anchor.target === '_parent') && window.to
p !== window) { | |
659 return null; | |
660 } | |
661 var href = anchor.href; | |
662 var url; | |
663 if (document.baseURI != null) { | |
664 url = new URL(href, document.baseURI); | |
665 } else { | |
666 url = new URL(href); | |
667 } | |
668 var origin; | |
669 if (window.location.origin) { | |
670 origin = window.location.origin; | |
671 } else { | |
672 origin = window.location.protocol + '//' + window.location.hostname; | |
673 if (window.location.port) { | |
674 origin += ':' + window.location.port; | |
675 } | |
676 } | |
677 if (url.origin !== origin) { | |
678 return null; | |
679 } | |
680 var normalizedHref = url.pathname + url.search + url.hash; | |
681 if (this._urlSpaceRegExp && !this._urlSpaceRegExp.test(normalizedHref)) { | |
682 return null; | |
683 } | |
684 var fullNormalizedHref = new URL(normalizedHref, window.location.href).hre
f; | |
685 return fullNormalizedHref; | |
686 }, | |
687 _makeRegExp: function(urlSpaceRegex) { | |
688 return RegExp(urlSpaceRegex); | |
689 } | |
690 }); | |
691 })(); | |
692 | |
693 'use strict'; | |
694 | |
695 Polymer({ | |
696 is: 'iron-query-params', | |
697 properties: { | |
698 paramsString: { | |
699 type: String, | |
700 notify: true, | |
701 observer: 'paramsStringChanged' | |
702 }, | |
703 paramsObject: { | |
704 type: Object, | |
705 notify: true, | |
706 value: function() { | |
707 return {}; | |
708 } | |
709 }, | |
710 _dontReact: { | |
711 type: Boolean, | |
712 value: false | |
713 } | |
714 }, | |
715 hostAttributes: { | |
716 hidden: true | |
717 }, | |
718 observers: [ 'paramsObjectChanged(paramsObject.*)' ], | |
719 paramsStringChanged: function() { | |
720 this._dontReact = true; | |
721 this.paramsObject = this._decodeParams(this.paramsString); | |
722 this._dontReact = false; | |
723 }, | |
724 paramsObjectChanged: function() { | |
725 if (this._dontReact) { | |
726 return; | |
727 } | |
728 this.paramsString = this._encodeParams(this.paramsObject); | |
729 }, | |
730 _encodeParams: function(params) { | |
731 var encodedParams = []; | |
732 for (var key in params) { | |
733 var value = params[key]; | |
734 if (value === '') { | |
735 encodedParams.push(encodeURIComponent(key)); | |
736 } else if (value) { | |
737 encodedParams.push(encodeURIComponent(key) + '=' + encodeURIComponent(va
lue.toString())); | |
738 } | |
739 } | |
740 return encodedParams.join('&'); | |
741 }, | |
742 _decodeParams: function(paramString) { | |
743 var params = {}; | |
744 paramString = (paramString || '').replace(/\+/g, '%20'); | |
745 var paramList = paramString.split('&'); | |
746 for (var i = 0; i < paramList.length; i++) { | |
747 var param = paramList[i].split('='); | |
748 if (param[0]) { | |
749 params[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || ''
); | |
750 } | |
751 } | |
752 return params; | |
753 } | |
754 }); | |
755 | |
756 'use strict'; | |
757 | |
758 Polymer.AppRouteConverterBehavior = { | |
759 properties: { | |
760 route: { | |
761 type: Object, | |
762 notify: true | |
763 }, | |
764 queryParams: { | |
765 type: Object, | |
766 notify: true | |
767 }, | |
768 path: { | |
769 type: String, | |
770 notify: true | |
771 } | |
772 }, | |
773 observers: [ '_locationChanged(path, queryParams)', '_routeChanged(route.prefi
x, route.path)', '_routeQueryParamsChanged(route.__queryParams)' ], | |
774 created: function() { | |
775 this.linkPaths('route.__queryParams', 'queryParams'); | |
776 this.linkPaths('queryParams', 'route.__queryParams'); | |
777 }, | |
778 _locationChanged: function() { | |
779 if (this.route && this.route.path === this.path && this.queryParams === this
.route.__queryParams) { | |
780 return; | |
781 } | |
782 this.route = { | |
783 prefix: '', | |
784 path: this.path, | |
785 __queryParams: this.queryParams | |
786 }; | |
787 }, | |
788 _routeChanged: function() { | |
789 if (!this.route) { | |
790 return; | |
791 } | |
792 this.path = this.route.prefix + this.route.path; | |
793 }, | |
794 _routeQueryParamsChanged: function(queryParams) { | |
795 if (!this.route) { | |
796 return; | |
797 } | |
798 this.queryParams = queryParams; | |
799 } | |
800 }; | |
801 | |
802 'use strict'; | |
803 | |
804 Polymer({ | |
805 is: 'app-location', | |
806 properties: { | |
807 route: { | |
808 type: Object, | |
809 notify: true | |
810 }, | |
811 useHashAsPath: { | |
812 type: Boolean, | |
813 value: false | |
814 }, | |
815 urlSpaceRegex: { | |
816 type: String, | |
817 notify: true | |
818 }, | |
819 __queryParams: { | |
820 type: Object | |
821 }, | |
822 __path: { | |
823 type: String | |
824 }, | |
825 __query: { | |
826 type: String | |
827 }, | |
828 __hash: { | |
829 type: String | |
830 }, | |
831 path: { | |
832 type: String, | |
833 observer: '__onPathChanged' | |
834 } | |
835 }, | |
836 behaviors: [ Polymer.AppRouteConverterBehavior ], | |
837 observers: [ '__computeRoutePath(useHashAsPath, __hash, __path)' ], | |
838 __computeRoutePath: function() { | |
839 this.path = this.useHashAsPath ? this.__hash : this.__path; | |
840 }, | |
841 __onPathChanged: function() { | |
842 if (!this._readied) { | |
843 return; | |
844 } | |
845 if (this.useHashAsPath) { | |
846 this.__hash = this.path; | |
847 } else { | |
848 this.__path = this.path; | |
849 } | |
850 } | |
851 }); | |
852 | |
853 'use strict'; | |
854 | |
855 Polymer({ | |
856 is: 'app-route', | |
857 properties: { | |
858 route: { | |
859 type: Object, | |
860 notify: true | |
861 }, | |
862 pattern: { | |
863 type: String | |
864 }, | |
865 data: { | |
866 type: Object, | |
867 value: function() { | |
868 return {}; | |
869 }, | |
870 notify: true | |
871 }, | |
872 queryParams: { | |
873 type: Object, | |
874 value: function() { | |
875 return {}; | |
876 }, | |
877 notify: true | |
878 }, | |
879 tail: { | |
880 type: Object, | |
881 value: function() { | |
882 return { | |
883 path: null, | |
884 prefix: null, | |
885 __queryParams: null | |
886 }; | |
887 }, | |
888 notify: true | |
889 }, | |
890 active: { | |
891 type: Boolean, | |
892 notify: true, | |
893 readOnly: true | |
894 }, | |
895 _queryParamsUpdating: { | |
896 type: Boolean, | |
897 value: false | |
898 }, | |
899 _matched: { | |
900 type: String, | |
901 value: '' | |
902 } | |
903 }, | |
904 observers: [ '__tryToMatch(route.path, pattern)', '__updatePathOnDataChange(da
ta.*)', '__tailPathChanged(tail.path)', '__routeQueryParamsChanged(route.__query
Params)', '__tailQueryParamsChanged(tail.__queryParams)', '__queryParamsChanged(
queryParams.*)' ], | |
905 created: function() { | |
906 this.linkPaths('route.__queryParams', 'tail.__queryParams'); | |
907 this.linkPaths('tail.__queryParams', 'route.__queryParams'); | |
908 }, | |
909 __routeQueryParamsChanged: function(queryParams) { | |
910 if (queryParams && this.tail) { | |
911 this.set('tail.__queryParams', queryParams); | |
912 if (!this.active || this._queryParamsUpdating) { | |
913 return; | |
914 } | |
915 var copyOfQueryParams = {}; | |
916 var anythingChanged = false; | |
917 for (var key in queryParams) { | |
918 copyOfQueryParams[key] = queryParams[key]; | |
919 if (anythingChanged || !this.queryParams || queryParams[key] !== this.qu
eryParams[key]) { | |
920 anythingChanged = true; | |
921 } | |
922 } | |
923 for (var key in this.queryParams) { | |
924 if (anythingChanged || !(key in queryParams)) { | |
925 anythingChanged = true; | |
926 break; | |
927 } | |
928 } | |
929 if (!anythingChanged) { | |
930 return; | |
931 } | |
932 this._queryParamsUpdating = true; | |
933 this.set('queryParams', copyOfQueryParams); | |
934 this._queryParamsUpdating = false; | |
935 } | |
936 }, | |
937 __tailQueryParamsChanged: function(queryParams) { | |
938 if (queryParams && this.route) { | |
939 this.set('route.__queryParams', queryParams); | |
940 } | |
941 }, | |
942 __queryParamsChanged: function(changes) { | |
943 if (!this.active || this._queryParamsUpdating) { | |
944 return; | |
945 } | |
946 this.set('route.__' + changes.path, changes.value); | |
947 }, | |
948 __resetProperties: function() { | |
949 this._setActive(false); | |
950 this._matched = null; | |
951 }, | |
952 __tryToMatch: function() { | |
953 if (!this.route) { | |
954 return; | |
955 } | |
956 var path = this.route.path; | |
957 var pattern = this.pattern; | |
958 if (!pattern) { | |
959 return; | |
960 } | |
961 if (!path) { | |
962 this.__resetProperties(); | |
963 return; | |
964 } | |
965 var remainingPieces = path.split('/'); | |
966 var patternPieces = pattern.split('/'); | |
967 var matched = []; | |
968 var namedMatches = {}; | |
969 for (var i = 0; i < patternPieces.length; i++) { | |
970 var patternPiece = patternPieces[i]; | |
971 if (!patternPiece && patternPiece !== '') { | |
972 break; | |
973 } | |
974 var pathPiece = remainingPieces.shift(); | |
975 if (!pathPiece && pathPiece !== '') { | |
976 this.__resetProperties(); | |
977 return; | |
978 } | |
979 matched.push(pathPiece); | |
980 if (patternPiece.charAt(0) == ':') { | |
981 namedMatches[patternPiece.slice(1)] = pathPiece; | |
982 } else if (patternPiece !== pathPiece) { | |
983 this.__resetProperties(); | |
984 return; | |
985 } | |
986 } | |
987 this._matched = matched.join('/'); | |
988 var propertyUpdates = {}; | |
989 if (!this.active) { | |
990 propertyUpdates.active = true; | |
991 } | |
992 var tailPrefix = this.route.prefix + this._matched; | |
993 var tailPath = remainingPieces.join('/'); | |
994 if (remainingPieces.length > 0) { | |
995 tailPath = '/' + tailPath; | |
996 } | |
997 if (!this.tail || this.tail.prefix !== tailPrefix || this.tail.path !== tail
Path) { | |
998 propertyUpdates.tail = { | |
999 prefix: tailPrefix, | |
1000 path: tailPath, | |
1001 __queryParams: this.route.__queryParams | |
1002 }; | |
1003 } | |
1004 propertyUpdates.data = namedMatches; | |
1005 this._dataInUrl = {}; | |
1006 for (var key in namedMatches) { | |
1007 this._dataInUrl[key] = namedMatches[key]; | |
1008 } | |
1009 this.__setMulti(propertyUpdates); | |
1010 }, | |
1011 __tailPathChanged: function() { | |
1012 if (!this.active) { | |
1013 return; | |
1014 } | |
1015 var tailPath = this.tail.path; | |
1016 var newPath = this._matched; | |
1017 if (tailPath) { | |
1018 if (tailPath.charAt(0) !== '/') { | |
1019 tailPath = '/' + tailPath; | |
1020 } | |
1021 newPath += tailPath; | |
1022 } | |
1023 this.set('route.path', newPath); | |
1024 }, | |
1025 __updatePathOnDataChange: function() { | |
1026 if (!this.route || !this.active) { | |
1027 return; | |
1028 } | |
1029 var newPath = this.__getLink({}); | |
1030 var oldPath = this.__getLink(this._dataInUrl); | |
1031 if (newPath === oldPath) { | |
1032 return; | |
1033 } | |
1034 this.set('route.path', newPath); | |
1035 }, | |
1036 __getLink: function(overrideValues) { | |
1037 var values = { | |
1038 tail: null | |
1039 }; | |
1040 for (var key in this.data) { | |
1041 values[key] = this.data[key]; | |
1042 } | |
1043 for (var key in overrideValues) { | |
1044 values[key] = overrideValues[key]; | |
1045 } | |
1046 var patternPieces = this.pattern.split('/'); | |
1047 var interp = patternPieces.map(function(value) { | |
1048 if (value[0] == ':') { | |
1049 value = values[value.slice(1)]; | |
1050 } | |
1051 return value; | |
1052 }, this); | |
1053 if (values.tail && values.tail.path) { | |
1054 if (interp.length > 0 && values.tail.path.charAt(0) === '/') { | |
1055 interp.push(values.tail.path.slice(1)); | |
1056 } else { | |
1057 interp.push(values.tail.path); | |
1058 } | |
1059 } | |
1060 return interp.join('/'); | |
1061 }, | |
1062 __setMulti: function(setObj) { | |
1063 for (var property in setObj) { | |
1064 this._propertySetter(property, setObj[property]); | |
1065 } | |
1066 for (var property in setObj) { | |
1067 this._pathEffector(property, this[property]); | |
1068 this._notifyPathUp(property, this[property]); | |
1069 } | |
1070 } | |
1071 }); | |
1072 | |
1073 Polymer({ | 510 Polymer({ |
1074 is: 'iron-media-query', | 511 is: 'iron-media-query', |
1075 properties: { | 512 properties: { |
1076 queryMatches: { | 513 queryMatches: { |
1077 type: Boolean, | 514 type: Boolean, |
1078 value: false, | 515 value: false, |
1079 readOnly: true, | 516 readOnly: true, |
1080 notify: true | 517 notify: true |
1081 }, | 518 }, |
1082 query: { | 519 query: { |
(...skipping 2570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3653 value: 0, | 3090 value: 0, |
3654 observer: 'changeToolbarView_' | 3091 observer: 'changeToolbarView_' |
3655 }, | 3092 }, |
3656 itemsSelected_: { | 3093 itemsSelected_: { |
3657 type: Boolean, | 3094 type: Boolean, |
3658 value: false, | 3095 value: false, |
3659 reflectToAttribute: true | 3096 reflectToAttribute: true |
3660 }, | 3097 }, |
3661 searchTerm: { | 3098 searchTerm: { |
3662 type: String, | 3099 type: String, |
| 3100 observer: 'searchTermChanged_', |
3663 notify: true | 3101 notify: true |
3664 }, | 3102 }, |
3665 spinnerActive: { | 3103 spinnerActive: { |
3666 type: Boolean, | 3104 type: Boolean, |
3667 value: false | 3105 value: false |
3668 }, | 3106 }, |
3669 hasDrawer: { | 3107 hasDrawer: { |
3670 type: Boolean, | 3108 type: Boolean, |
3671 observer: 'hasDrawerChanged_', | 3109 observer: 'hasDrawerChanged_', |
3672 reflectToAttribute: true | 3110 reflectToAttribute: true |
(...skipping 11 matching lines...) Expand all Loading... |
3684 }, | 3122 }, |
3685 queryStartTime: String, | 3123 queryStartTime: String, |
3686 queryEndTime: String, | 3124 queryEndTime: String, |
3687 showMenuPromo_: { | 3125 showMenuPromo_: { |
3688 type: Boolean, | 3126 type: Boolean, |
3689 value: function() { | 3127 value: function() { |
3690 return loadTimeData.getBoolean('showMenuPromo'); | 3128 return loadTimeData.getBoolean('showMenuPromo'); |
3691 } | 3129 } |
3692 } | 3130 } |
3693 }, | 3131 }, |
| 3132 get searchField() { |
| 3133 return this.$['main-toolbar'].getSearchField(); |
| 3134 }, |
| 3135 showSearchField: function() { |
| 3136 this.searchField.showAndFocus(); |
| 3137 }, |
3694 changeToolbarView_: function() { | 3138 changeToolbarView_: function() { |
3695 this.itemsSelected_ = this.count > 0; | 3139 this.itemsSelected_ = this.count > 0; |
3696 }, | 3140 }, |
3697 setSearchTerm: function(search) { | 3141 searchTermChanged_: function() { |
3698 if (this.searchTerm == search) return; | 3142 if (this.searchField.getValue() != this.searchTerm) { |
3699 this.searchTerm = search; | 3143 this.searchField.showAndFocus(); |
3700 var searchField = this.$['main-toolbar'].getSearchField(); | 3144 this.searchField.setValue(this.searchTerm); |
3701 searchField.showAndFocus(); | 3145 } |
3702 searchField.setValue(search); | |
3703 }, | 3146 }, |
3704 onMenuPromoShown_: function() { | 3147 onMenuPromoShown_: function() { |
3705 md_history.BrowserService.getInstance().menuPromoShown(); | 3148 md_history.BrowserService.getInstance().menuPromoShown(); |
3706 }, | 3149 }, |
3707 onSearchChanged_: function(event) { | 3150 onSearchChanged_: function(event) { |
3708 this.searchTerm = event.detail; | 3151 this.searchTerm = event.detail; |
3709 }, | 3152 }, |
3710 onInfoButtonTap_: function() { | 3153 onInfoButtonTap_: function() { |
3711 var dropdown = this.$.syncNotice.get(); | 3154 var dropdown = this.$.syncNotice.get(); |
3712 dropdown.positionTarget = this.$$('#info-button-icon'); | 3155 dropdown.positionTarget = this.$$('#info-button-icon'); |
3713 if (dropdown.style.display == 'none') dropdown.open(); | 3156 if (dropdown.style.display == 'none') dropdown.open(); |
3714 }, | 3157 }, |
3715 onClearSelectionTap_: function() { | 3158 onClearSelectionTap_: function() { |
3716 this.fire('unselect-all'); | 3159 this.fire('unselect-all'); |
3717 }, | 3160 }, |
3718 onDeleteTap_: function() { | 3161 onDeleteTap_: function() { |
3719 this.fire('delete-selected'); | 3162 this.fire('delete-selected'); |
3720 }, | 3163 }, |
3721 get searchBar() { | |
3722 return this.$['main-toolbar'].getSearchField(); | |
3723 }, | |
3724 showSearchField: function() { | |
3725 this.$['main-toolbar'].getSearchField().showAndFocus(); | |
3726 }, | |
3727 deletingAllowed_: function() { | 3164 deletingAllowed_: function() { |
3728 return loadTimeData.getBoolean('allowDeletingHistory'); | 3165 return loadTimeData.getBoolean('allowDeletingHistory'); |
3729 }, | 3166 }, |
3730 numberOfItemsSelected_: function(count) { | 3167 numberOfItemsSelected_: function(count) { |
3731 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; | 3168 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; |
3732 }, | 3169 }, |
3733 getHistoryInterval_: function(queryStartTime, queryEndTime) { | 3170 getHistoryInterval_: function(queryStartTime, queryEndTime) { |
3734 return loadTimeData.getStringF('historyInterval', queryStartTime, queryEndTi
me); | 3171 return loadTimeData.getStringF('historyInterval', queryStartTime, queryEndTi
me); |
3735 }, | 3172 }, |
3736 hasDrawerChanged_: function() { | 3173 hasDrawerChanged_: function() { |
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5294 return i == length - 1 || this.historyData_[i].dateRelativeDay != this.histo
ryData_[i + 1].dateRelativeDay; | 4731 return i == length - 1 || this.historyData_[i].dateRelativeDay != this.histo
ryData_[i + 1].dateRelativeDay; |
5295 }, | 4732 }, |
5296 notifyListScroll_: function() { | 4733 notifyListScroll_: function() { |
5297 this.fire('history-list-scrolled'); | 4734 this.fire('history-list-scrolled'); |
5298 }, | 4735 }, |
5299 pathForItem_: function(index) { | 4736 pathForItem_: function(index) { |
5300 return 'historyData_.' + index; | 4737 return 'historyData_.' + index; |
5301 } | 4738 } |
5302 }); | 4739 }); |
5303 | 4740 |
| 4741 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 4742 // Use of this source code is governed by a BSD-style license that can be |
| 4743 // found in the LICENSE file. |
| 4744 Polymer({ |
| 4745 is: 'history-list-container', |
| 4746 properties: { |
| 4747 selectedPage_: String, |
| 4748 grouped: Boolean, |
| 4749 groupedRange: { |
| 4750 type: Number, |
| 4751 observer: 'groupedRangeChanged_' |
| 4752 }, |
| 4753 queryState: Object, |
| 4754 queryResult: Object |
| 4755 }, |
| 4756 observers: [ 'searchTermChanged_(queryState.searchTerm)' ], |
| 4757 listeners: { |
| 4758 'history-list-scrolled': 'closeMenu_', |
| 4759 'load-more-history': 'loadMoreHistory_', |
| 4760 'toggle-menu': 'toggleMenu_' |
| 4761 }, |
| 4762 historyResult: function(info, results) { |
| 4763 this.initializeResults_(info, results); |
| 4764 this.closeMenu_(); |
| 4765 if (this.selectedPage_ == 'grouped-list') { |
| 4766 this.$$('#grouped-list').historyData = results; |
| 4767 return; |
| 4768 } |
| 4769 var list = this.$['infinite-list']; |
| 4770 list.addNewResults(results, this.queryState.incremental); |
| 4771 if (info.finished) list.disableResultLoading(); |
| 4772 }, |
| 4773 queryHistory: function(incremental) { |
| 4774 var queryState = this.queryState; |
| 4775 var noResults = !this.queryResult || this.queryResult.results == null; |
| 4776 if (queryState.queryingDisabled || !this.queryState.searchTerm && noResults)
{ |
| 4777 return; |
| 4778 } |
| 4779 var dialog = this.$.dialog.getIfExists(); |
| 4780 if (!incremental && dialog && dialog.open) dialog.close(); |
| 4781 this.set('queryState.querying', true); |
| 4782 this.set('queryState.incremental', incremental); |
| 4783 var lastVisitTime = 0; |
| 4784 if (incremental) { |
| 4785 var lastVisit = this.queryResult.results.slice(-1)[0]; |
| 4786 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 4787 } |
| 4788 var maxResults = this.groupedRange == HistoryRange.ALL_TIME ? RESULTS_PER_PA
GE : 0; |
| 4789 chrome.send('queryHistory', [ queryState.searchTerm, queryState.groupedOffse
t, queryState.range, lastVisitTime, maxResults ]); |
| 4790 }, |
| 4791 historyDeleted: function() { |
| 4792 if (this.getSelectedItemCount() > 0) return; |
| 4793 this.queryHistory(false); |
| 4794 }, |
| 4795 getContentScrollTarget: function() { |
| 4796 return this.getSelectedList_(); |
| 4797 }, |
| 4798 getSelectedItemCount: function() { |
| 4799 return this.getSelectedList_().selectedPaths.size; |
| 4800 }, |
| 4801 unselectAllItems: function(count) { |
| 4802 var selectedList = this.getSelectedList_(); |
| 4803 if (selectedList) selectedList.unselectAllItems(count); |
| 4804 }, |
| 4805 deleteSelectedWithPrompt: function() { |
| 4806 if (!loadTimeData.getBoolean('allowDeletingHistory')) return; |
| 4807 var browserService = md_history.BrowserService.getInstance(); |
| 4808 browserService.recordAction('RemoveSelected'); |
| 4809 if (this.queryState.searchTerm != '') browserService.recordAction('SearchRes
ultRemove'); |
| 4810 this.$.dialog.get().showModal(); |
| 4811 }, |
| 4812 groupedRangeChanged_: function(range, oldRange) { |
| 4813 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 'infinite-list' : 'gro
uped-list'; |
| 4814 if (oldRange == undefined) return; |
| 4815 this.queryHistory(false); |
| 4816 this.fire('history-view-changed'); |
| 4817 }, |
| 4818 searchTermChanged_: function() { |
| 4819 this.queryHistory(false); |
| 4820 if (this.queryState.searchTerm) md_history.BrowserService.getInstance().reco
rdAction('Search'); |
| 4821 }, |
| 4822 loadMoreHistory_: function() { |
| 4823 this.queryHistory(true); |
| 4824 }, |
| 4825 initializeResults_: function(info, results) { |
| 4826 if (results.length == 0) return; |
| 4827 var currentDate = results[0].dateRelativeDay; |
| 4828 for (var i = 0; i < results.length; i++) { |
| 4829 results[i].selected = false; |
| 4830 results[i].readableTimestamp = info.term == '' ? results[i].dateTimeOfDay
: results[i].dateShort; |
| 4831 if (results[i].dateRelativeDay != currentDate) { |
| 4832 currentDate = results[i].dateRelativeDay; |
| 4833 } |
| 4834 } |
| 4835 }, |
| 4836 onDialogConfirmTap_: function() { |
| 4837 md_history.BrowserService.getInstance().recordAction('ConfirmRemoveSelected'
); |
| 4838 this.getSelectedList_().deleteSelected(); |
| 4839 var dialog = assert(this.$.dialog.getIfExists()); |
| 4840 dialog.close(); |
| 4841 }, |
| 4842 onDialogCancelTap_: function() { |
| 4843 md_history.BrowserService.getInstance().recordAction('CancelRemoveSelected')
; |
| 4844 var dialog = assert(this.$.dialog.getIfExists()); |
| 4845 dialog.close(); |
| 4846 }, |
| 4847 closeMenu_: function() { |
| 4848 var menu = this.$.sharedMenu.getIfExists(); |
| 4849 if (menu) menu.closeMenu(); |
| 4850 }, |
| 4851 toggleMenu_: function(e) { |
| 4852 var target = e.detail.target; |
| 4853 var menu = this.$.sharedMenu.get(); |
| 4854 menu.toggleMenu(target, e.detail); |
| 4855 }, |
| 4856 onMoreFromSiteTap_: function() { |
| 4857 md_history.BrowserService.getInstance().recordAction('EntryMenuShowMoreFromS
ite'); |
| 4858 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 4859 this.set('queryState.searchTerm', menu.itemData.item.domain); |
| 4860 menu.closeMenu(); |
| 4861 }, |
| 4862 onRemoveFromHistoryTap_: function() { |
| 4863 var browserService = md_history.BrowserService.getInstance(); |
| 4864 browserService.recordAction('EntryMenuRemoveFromHistory'); |
| 4865 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 4866 var itemData = menu.itemData; |
| 4867 browserService.deleteItems([ itemData.item ]).then(function(items) { |
| 4868 this.getSelectedList_().removeItemsByPath([ itemData.path ]); |
| 4869 this.fire('unselect-all'); |
| 4870 var index = itemData.index; |
| 4871 if (index == undefined) return; |
| 4872 var browserService = md_history.BrowserService.getInstance(); |
| 4873 browserService.recordHistogram('HistoryPage.RemoveEntryPosition', index, U
MA_MAX_BUCKET_VALUE); |
| 4874 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { |
| 4875 browserService.recordHistogram('HistoryPage.RemoveEntryPositionSubset',
index, UMA_MAX_SUBSET_BUCKET_VALUE); |
| 4876 } |
| 4877 }.bind(this)); |
| 4878 menu.closeMenu(); |
| 4879 }, |
| 4880 getSelectedList_: function() { |
| 4881 return this.$.content.selectedItem; |
| 4882 } |
| 4883 }); |
| 4884 |
| 4885 (function() { |
| 4886 'use strict'; |
| 4887 Polymer({ |
| 4888 is: 'iron-location', |
| 4889 properties: { |
| 4890 path: { |
| 4891 type: String, |
| 4892 notify: true, |
| 4893 value: function() { |
| 4894 return window.decodeURIComponent(window.location.pathname); |
| 4895 } |
| 4896 }, |
| 4897 query: { |
| 4898 type: String, |
| 4899 notify: true, |
| 4900 value: function() { |
| 4901 return window.decodeURIComponent(window.location.search.slice(1)); |
| 4902 } |
| 4903 }, |
| 4904 hash: { |
| 4905 type: String, |
| 4906 notify: true, |
| 4907 value: function() { |
| 4908 return window.decodeURIComponent(window.location.hash.slice(1)); |
| 4909 } |
| 4910 }, |
| 4911 dwellTime: { |
| 4912 type: Number, |
| 4913 value: 2e3 |
| 4914 }, |
| 4915 urlSpaceRegex: { |
| 4916 type: String, |
| 4917 value: '' |
| 4918 }, |
| 4919 _urlSpaceRegExp: { |
| 4920 computed: '_makeRegExp(urlSpaceRegex)' |
| 4921 }, |
| 4922 _lastChangedAt: { |
| 4923 type: Number |
| 4924 }, |
| 4925 _initialized: { |
| 4926 type: Boolean, |
| 4927 value: false |
| 4928 } |
| 4929 }, |
| 4930 hostAttributes: { |
| 4931 hidden: true |
| 4932 }, |
| 4933 observers: [ '_updateUrl(path, query, hash)' ], |
| 4934 attached: function() { |
| 4935 this.listen(window, 'hashchange', '_hashChanged'); |
| 4936 this.listen(window, 'location-changed', '_urlChanged'); |
| 4937 this.listen(window, 'popstate', '_urlChanged'); |
| 4938 this.listen(document.body, 'click', '_globalOnClick'); |
| 4939 this._lastChangedAt = window.performance.now() - (this.dwellTime - 200); |
| 4940 this._initialized = true; |
| 4941 this._urlChanged(); |
| 4942 }, |
| 4943 detached: function() { |
| 4944 this.unlisten(window, 'hashchange', '_hashChanged'); |
| 4945 this.unlisten(window, 'location-changed', '_urlChanged'); |
| 4946 this.unlisten(window, 'popstate', '_urlChanged'); |
| 4947 this.unlisten(document.body, 'click', '_globalOnClick'); |
| 4948 this._initialized = false; |
| 4949 }, |
| 4950 _hashChanged: function() { |
| 4951 this.hash = window.decodeURIComponent(window.location.hash.substring(1)); |
| 4952 }, |
| 4953 _urlChanged: function() { |
| 4954 this._dontUpdateUrl = true; |
| 4955 this._hashChanged(); |
| 4956 this.path = window.decodeURIComponent(window.location.pathname); |
| 4957 this.query = window.decodeURIComponent(window.location.search.substring(1)
); |
| 4958 this._dontUpdateUrl = false; |
| 4959 this._updateUrl(); |
| 4960 }, |
| 4961 _getUrl: function() { |
| 4962 var partiallyEncodedPath = window.encodeURI(this.path).replace(/\#/g, '%23
').replace(/\?/g, '%3F'); |
| 4963 var partiallyEncodedQuery = ''; |
| 4964 if (this.query) { |
| 4965 partiallyEncodedQuery = '?' + window.encodeURI(this.query).replace(/\#/g
, '%23'); |
| 4966 } |
| 4967 var partiallyEncodedHash = ''; |
| 4968 if (this.hash) { |
| 4969 partiallyEncodedHash = '#' + window.encodeURI(this.hash); |
| 4970 } |
| 4971 return partiallyEncodedPath + partiallyEncodedQuery + partiallyEncodedHash
; |
| 4972 }, |
| 4973 _updateUrl: function() { |
| 4974 if (this._dontUpdateUrl || !this._initialized) { |
| 4975 return; |
| 4976 } |
| 4977 if (this.path === window.decodeURIComponent(window.location.pathname) && t
his.query === window.decodeURIComponent(window.location.search.substring(1)) &&
this.hash === window.decodeURIComponent(window.location.hash.substring(1))) { |
| 4978 return; |
| 4979 } |
| 4980 var newUrl = this._getUrl(); |
| 4981 var fullNewUrl = new URL(newUrl, window.location.protocol + '//' + window.
location.host).href; |
| 4982 var now = window.performance.now(); |
| 4983 var shouldReplace = this._lastChangedAt + this.dwellTime > now; |
| 4984 this._lastChangedAt = now; |
| 4985 if (shouldReplace) { |
| 4986 window.history.replaceState({}, '', fullNewUrl); |
| 4987 } else { |
| 4988 window.history.pushState({}, '', fullNewUrl); |
| 4989 } |
| 4990 this.fire('location-changed', {}, { |
| 4991 node: window |
| 4992 }); |
| 4993 }, |
| 4994 _globalOnClick: function(event) { |
| 4995 if (event.defaultPrevented) { |
| 4996 return; |
| 4997 } |
| 4998 var href = this._getSameOriginLinkHref(event); |
| 4999 if (!href) { |
| 5000 return; |
| 5001 } |
| 5002 event.preventDefault(); |
| 5003 if (href === window.location.href) { |
| 5004 return; |
| 5005 } |
| 5006 window.history.pushState({}, '', href); |
| 5007 this.fire('location-changed', {}, { |
| 5008 node: window |
| 5009 }); |
| 5010 }, |
| 5011 _getSameOriginLinkHref: function(event) { |
| 5012 if (event.button !== 0) { |
| 5013 return null; |
| 5014 } |
| 5015 if (event.metaKey || event.ctrlKey) { |
| 5016 return null; |
| 5017 } |
| 5018 var eventPath = Polymer.dom(event).path; |
| 5019 var anchor = null; |
| 5020 for (var i = 0; i < eventPath.length; i++) { |
| 5021 var element = eventPath[i]; |
| 5022 if (element.tagName === 'A' && element.href) { |
| 5023 anchor = element; |
| 5024 break; |
| 5025 } |
| 5026 } |
| 5027 if (!anchor) { |
| 5028 return null; |
| 5029 } |
| 5030 if (anchor.target === '_blank') { |
| 5031 return null; |
| 5032 } |
| 5033 if ((anchor.target === '_top' || anchor.target === '_parent') && window.to
p !== window) { |
| 5034 return null; |
| 5035 } |
| 5036 var href = anchor.href; |
| 5037 var url; |
| 5038 if (document.baseURI != null) { |
| 5039 url = new URL(href, document.baseURI); |
| 5040 } else { |
| 5041 url = new URL(href); |
| 5042 } |
| 5043 var origin; |
| 5044 if (window.location.origin) { |
| 5045 origin = window.location.origin; |
| 5046 } else { |
| 5047 origin = window.location.protocol + '//' + window.location.hostname; |
| 5048 if (window.location.port) { |
| 5049 origin += ':' + window.location.port; |
| 5050 } |
| 5051 } |
| 5052 if (url.origin !== origin) { |
| 5053 return null; |
| 5054 } |
| 5055 var normalizedHref = url.pathname + url.search + url.hash; |
| 5056 if (this._urlSpaceRegExp && !this._urlSpaceRegExp.test(normalizedHref)) { |
| 5057 return null; |
| 5058 } |
| 5059 var fullNormalizedHref = new URL(normalizedHref, window.location.href).hre
f; |
| 5060 return fullNormalizedHref; |
| 5061 }, |
| 5062 _makeRegExp: function(urlSpaceRegex) { |
| 5063 return RegExp(urlSpaceRegex); |
| 5064 } |
| 5065 }); |
| 5066 })(); |
| 5067 |
| 5068 'use strict'; |
| 5069 |
| 5070 Polymer({ |
| 5071 is: 'iron-query-params', |
| 5072 properties: { |
| 5073 paramsString: { |
| 5074 type: String, |
| 5075 notify: true, |
| 5076 observer: 'paramsStringChanged' |
| 5077 }, |
| 5078 paramsObject: { |
| 5079 type: Object, |
| 5080 notify: true, |
| 5081 value: function() { |
| 5082 return {}; |
| 5083 } |
| 5084 }, |
| 5085 _dontReact: { |
| 5086 type: Boolean, |
| 5087 value: false |
| 5088 } |
| 5089 }, |
| 5090 hostAttributes: { |
| 5091 hidden: true |
| 5092 }, |
| 5093 observers: [ 'paramsObjectChanged(paramsObject.*)' ], |
| 5094 paramsStringChanged: function() { |
| 5095 this._dontReact = true; |
| 5096 this.paramsObject = this._decodeParams(this.paramsString); |
| 5097 this._dontReact = false; |
| 5098 }, |
| 5099 paramsObjectChanged: function() { |
| 5100 if (this._dontReact) { |
| 5101 return; |
| 5102 } |
| 5103 this.paramsString = this._encodeParams(this.paramsObject); |
| 5104 }, |
| 5105 _encodeParams: function(params) { |
| 5106 var encodedParams = []; |
| 5107 for (var key in params) { |
| 5108 var value = params[key]; |
| 5109 if (value === '') { |
| 5110 encodedParams.push(encodeURIComponent(key)); |
| 5111 } else if (value) { |
| 5112 encodedParams.push(encodeURIComponent(key) + '=' + encodeURIComponent(va
lue.toString())); |
| 5113 } |
| 5114 } |
| 5115 return encodedParams.join('&'); |
| 5116 }, |
| 5117 _decodeParams: function(paramString) { |
| 5118 var params = {}; |
| 5119 paramString = (paramString || '').replace(/\+/g, '%20'); |
| 5120 var paramList = paramString.split('&'); |
| 5121 for (var i = 0; i < paramList.length; i++) { |
| 5122 var param = paramList[i].split('='); |
| 5123 if (param[0]) { |
| 5124 params[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || ''
); |
| 5125 } |
| 5126 } |
| 5127 return params; |
| 5128 } |
| 5129 }); |
| 5130 |
5304 // Copyright 2016 The Chromium Authors. All rights reserved. | 5131 // Copyright 2016 The Chromium Authors. All rights reserved. |
5305 // Use of this source code is governed by a BSD-style license that can be | 5132 // Use of this source code is governed by a BSD-style license that can be |
5306 // found in the LICENSE file. | 5133 // found in the LICENSE file. |
5307 Polymer({ | 5134 Polymer({ |
5308 is: 'history-list-container', | 5135 is: 'history-router', |
5309 properties: { | 5136 properties: { |
5310 selectedPage_: String, | 5137 selectedPage: { |
5311 grouped: Boolean, | 5138 type: String, |
5312 groupedRange: { | 5139 observer: 'serializePath_', |
5313 type: Number, | 5140 notify: true |
5314 observer: 'groupedRangeChanged_' | |
5315 }, | 5141 }, |
5316 queryState: Object, | 5142 queryState: { |
5317 queryResult: Object | 5143 type: Object, |
| 5144 notify: true |
| 5145 }, |
| 5146 path_: { |
| 5147 type: String, |
| 5148 observer: 'pathChanged_' |
| 5149 }, |
| 5150 queryParams_: Object |
5318 }, | 5151 }, |
5319 listeners: { | 5152 observers: [ 'queryParamsChanged_(queryParams_.*)', 'searchTermChanged_(queryS
tate.searchTerm)' ], |
5320 'history-list-scrolled': 'closeMenu_', | 5153 attached: function() { |
5321 'load-more-history': 'loadMoreHistory_', | 5154 if (window.location.hash) { |
5322 'toggle-menu': 'toggleMenu_' | 5155 window.location.href = window.location.href.split('#')[0] + '?' + window.l
ocation.hash.substr(1); |
5323 }, | |
5324 historyResult: function(info, results) { | |
5325 this.initializeResults_(info, results); | |
5326 this.closeMenu_(); | |
5327 if (this.selectedPage_ == 'grouped-list') { | |
5328 this.$$('#grouped-list').historyData = results; | |
5329 return; | |
5330 } | |
5331 var list = this.$['infinite-list']; | |
5332 list.addNewResults(results, this.queryState.incremental); | |
5333 if (info.finished) list.disableResultLoading(); | |
5334 }, | |
5335 queryHistory: function(incremental) { | |
5336 var queryState = this.queryState; | |
5337 var noResults = !this.queryResult || this.queryResult.results == null; | |
5338 if (queryState.queryingDisabled || !this.queryState.searchTerm && noResults)
{ | |
5339 return; | |
5340 } | |
5341 var dialog = this.$.dialog.getIfExists(); | |
5342 if (!incremental && dialog && dialog.open) dialog.close(); | |
5343 this.set('queryState.querying', true); | |
5344 this.set('queryState.incremental', incremental); | |
5345 var lastVisitTime = 0; | |
5346 if (incremental) { | |
5347 var lastVisit = this.queryResult.results.slice(-1)[0]; | |
5348 lastVisitTime = lastVisit ? lastVisit.time : 0; | |
5349 } | |
5350 var maxResults = this.groupedRange == HistoryRange.ALL_TIME ? RESULTS_PER_PA
GE : 0; | |
5351 chrome.send('queryHistory', [ queryState.searchTerm, queryState.groupedOffse
t, queryState.range, lastVisitTime, maxResults ]); | |
5352 }, | |
5353 historyDeleted: function() { | |
5354 if (this.getSelectedItemCount() > 0) return; | |
5355 this.queryHistory(false); | |
5356 }, | |
5357 getContentScrollTarget: function() { | |
5358 return this.getSelectedList_(); | |
5359 }, | |
5360 getSelectedItemCount: function() { | |
5361 return this.getSelectedList_().selectedPaths.size; | |
5362 }, | |
5363 unselectAllItems: function(count) { | |
5364 var selectedList = this.getSelectedList_(); | |
5365 if (selectedList) selectedList.unselectAllItems(count); | |
5366 }, | |
5367 deleteSelectedWithPrompt: function() { | |
5368 if (!loadTimeData.getBoolean('allowDeletingHistory')) return; | |
5369 var browserService = md_history.BrowserService.getInstance(); | |
5370 browserService.recordAction('RemoveSelected'); | |
5371 if (this.queryState.searchTerm != '') browserService.recordAction('SearchRes
ultRemove'); | |
5372 this.$.dialog.get().showModal(); | |
5373 }, | |
5374 groupedRangeChanged_: function(range, oldRange) { | |
5375 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 'infinite-list' : 'gro
uped-list'; | |
5376 if (oldRange == undefined) return; | |
5377 this.queryHistory(false); | |
5378 this.fire('history-view-changed'); | |
5379 }, | |
5380 loadMoreHistory_: function() { | |
5381 this.queryHistory(true); | |
5382 }, | |
5383 initializeResults_: function(info, results) { | |
5384 if (results.length == 0) return; | |
5385 var currentDate = results[0].dateRelativeDay; | |
5386 for (var i = 0; i < results.length; i++) { | |
5387 results[i].selected = false; | |
5388 results[i].readableTimestamp = info.term == '' ? results[i].dateTimeOfDay
: results[i].dateShort; | |
5389 if (results[i].dateRelativeDay != currentDate) { | |
5390 currentDate = results[i].dateRelativeDay; | |
5391 } | |
5392 } | 5156 } |
5393 }, | 5157 }, |
5394 onDialogConfirmTap_: function() { | 5158 serializePath_: function() { |
5395 md_history.BrowserService.getInstance().recordAction('ConfirmRemoveSelected'
); | 5159 var page = this.selectedPage == 'history' ? '' : this.selectedPage; |
5396 this.getSelectedList_().deleteSelected(); | 5160 this.path_ = '/' + page; |
5397 var dialog = assert(this.$.dialog.getIfExists()); | |
5398 dialog.close(); | |
5399 }, | 5161 }, |
5400 onDialogCancelTap_: function() { | 5162 pathChanged_: function() { |
5401 md_history.BrowserService.getInstance().recordAction('CancelRemoveSelected')
; | 5163 var sections = this.path_.substr(1).split('/'); |
5402 var dialog = assert(this.$.dialog.getIfExists()); | 5164 this.selectedPage = sections[0] || 'history'; |
5403 dialog.close(); | |
5404 }, | 5165 }, |
5405 closeMenu_: function() { | 5166 queryParamsChanged_: function() { |
5406 var menu = this.$.sharedMenu.getIfExists(); | 5167 this.set('queryState.searchTerm', this.queryParams_.q || ''); |
5407 if (menu) menu.closeMenu(); | |
5408 }, | 5168 }, |
5409 toggleMenu_: function(e) { | 5169 searchTermChanged_: function() { |
5410 var target = e.detail.target; | 5170 this.set('queryParams_.q', this.queryState.searchTerm || null); |
5411 var menu = this.$.sharedMenu.get(); | |
5412 menu.toggleMenu(target, e.detail); | |
5413 }, | |
5414 onMoreFromSiteTap_: function() { | |
5415 md_history.BrowserService.getInstance().recordAction('EntryMenuShowMoreFromS
ite'); | |
5416 var menu = assert(this.$.sharedMenu.getIfExists()); | |
5417 this.fire('search-domain', { | |
5418 domain: menu.itemData.item.domain | |
5419 }); | |
5420 menu.closeMenu(); | |
5421 }, | |
5422 onRemoveFromHistoryTap_: function() { | |
5423 var browserService = md_history.BrowserService.getInstance(); | |
5424 browserService.recordAction('EntryMenuRemoveFromHistory'); | |
5425 var menu = assert(this.$.sharedMenu.getIfExists()); | |
5426 var itemData = menu.itemData; | |
5427 browserService.deleteItems([ itemData.item ]).then(function(items) { | |
5428 this.getSelectedList_().removeItemsByPath([ itemData.path ]); | |
5429 this.fire('unselect-all'); | |
5430 var index = itemData.index; | |
5431 if (index == undefined) return; | |
5432 var browserService = md_history.BrowserService.getInstance(); | |
5433 browserService.recordHistogram('HistoryPage.RemoveEntryPosition', index, U
MA_MAX_BUCKET_VALUE); | |
5434 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { | |
5435 browserService.recordHistogram('HistoryPage.RemoveEntryPositionSubset',
index, UMA_MAX_SUBSET_BUCKET_VALUE); | |
5436 } | |
5437 }.bind(this)); | |
5438 menu.closeMenu(); | |
5439 }, | |
5440 getSelectedList_: function() { | |
5441 return this.$.content.selectedItem; | |
5442 } | 5171 } |
5443 }); | 5172 }); |
5444 | 5173 |
5445 Polymer.IronMultiSelectableBehaviorImpl = { | 5174 Polymer.IronMultiSelectableBehaviorImpl = { |
5446 properties: { | 5175 properties: { |
5447 multi: { | 5176 multi: { |
5448 type: Boolean, | 5177 type: Boolean, |
5449 value: false, | 5178 value: false, |
5450 observer: 'multiChanged' | 5179 observer: 'multiChanged' |
5451 }, | 5180 }, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5548 // Use of this source code is governed by a BSD-style license that can be | 5277 // Use of this source code is governed by a BSD-style license that can be |
5549 // found in the LICENSE file. | 5278 // found in the LICENSE file. |
5550 Polymer({ | 5279 Polymer({ |
5551 is: 'history-side-bar', | 5280 is: 'history-side-bar', |
5552 behaviors: [ Polymer.IronA11yKeysBehavior ], | 5281 behaviors: [ Polymer.IronA11yKeysBehavior ], |
5553 properties: { | 5282 properties: { |
5554 selectedPage: { | 5283 selectedPage: { |
5555 type: String, | 5284 type: String, |
5556 notify: true | 5285 notify: true |
5557 }, | 5286 }, |
5558 route: Object, | |
5559 showFooter: Boolean, | 5287 showFooter: Boolean, |
5560 drawer: { | 5288 drawer: { |
5561 type: Boolean, | 5289 type: Boolean, |
5562 reflectToAttribute: true | 5290 reflectToAttribute: true |
5563 } | 5291 } |
5564 }, | 5292 }, |
5565 keyBindings: { | 5293 keyBindings: { |
5566 'space:keydown': 'onSpacePressed_' | 5294 'space:keydown': 'onSpacePressed_' |
5567 }, | 5295 }, |
5568 onSpacePressed_: function(e) { | 5296 onSpacePressed_: function(e) { |
5569 e.detail.keyboardEvent.path[0].click(); | 5297 e.detail.keyboardEvent.path[0].click(); |
5570 }, | 5298 }, |
5571 onSelectorActivate_: function() { | 5299 onSelectorActivate_: function() { |
5572 this.fire('history-close-drawer'); | 5300 this.fire('history-close-drawer'); |
5573 }, | 5301 }, |
5574 onClearBrowsingDataTap_: function(e) { | 5302 onClearBrowsingDataTap_: function(e) { |
5575 var browserService = md_history.BrowserService.getInstance(); | 5303 var browserService = md_history.BrowserService.getInstance(); |
5576 browserService.recordAction('InitClearBrowsingData'); | 5304 browserService.recordAction('InitClearBrowsingData'); |
5577 browserService.openClearBrowsingData(); | 5305 browserService.openClearBrowsingData(); |
5578 this.$['cbd-ripple'].upAction(); | 5306 this.$['cbd-ripple'].upAction(); |
5579 e.preventDefault(); | 5307 e.preventDefault(); |
5580 }, | 5308 }, |
5581 getQueryString_: function(route) { | 5309 onItemClick_: function(e) { |
5582 return window.location.search; | 5310 e.preventDefault(); |
5583 } | 5311 } |
5584 }); | 5312 }); |
5585 | 5313 |
5586 // Copyright 2016 The Chromium Authors. All rights reserved. | 5314 // Copyright 2016 The Chromium Authors. All rights reserved. |
5587 // Use of this source code is governed by a BSD-style license that can be | 5315 // Use of this source code is governed by a BSD-style license that can be |
5588 // found in the LICENSE file. | 5316 // found in the LICENSE file. |
5589 cr.define('md_history', function() { | 5317 cr.define('md_history', function() { |
5590 var lazyLoadPromise = null; | 5318 var lazyLoadPromise = null; |
5591 function ensureLazyLoaded() { | 5319 function ensureLazyLoaded() { |
5592 if (!lazyLoadPromise) { | 5320 if (!lazyLoadPromise) { |
5593 lazyLoadPromise = new Promise(function(resolve, reject) { | 5321 lazyLoadPromise = new Promise(function(resolve, reject) { |
5594 Polymer.Base.importHref('chrome://history/lazy_load.html', resolve, reje
ct, true); | 5322 Polymer.Base.importHref('chrome://history/lazy_load.html', resolve, reje
ct, true); |
5595 }); | 5323 }); |
5596 } | 5324 } |
5597 return lazyLoadPromise; | 5325 return lazyLoadPromise; |
5598 } | 5326 } |
5599 return { | 5327 return { |
5600 ensureLazyLoaded: ensureLazyLoaded | 5328 ensureLazyLoaded: ensureLazyLoaded |
5601 }; | 5329 }; |
5602 }); | 5330 }); |
5603 | 5331 |
5604 Polymer({ | 5332 Polymer({ |
5605 is: 'history-app', | 5333 is: 'history-app', |
5606 behaviors: [ Polymer.IronScrollTargetBehavior ], | 5334 behaviors: [ Polymer.IronScrollTargetBehavior ], |
5607 properties: { | 5335 properties: { |
5608 showSidebarFooter: Boolean, | 5336 showSidebarFooter: Boolean, |
5609 hasSyncedResults: Boolean, | 5337 hasSyncedResults: Boolean, |
5610 selectedPage_: { | 5338 selectedPage_: { |
5611 type: String, | 5339 type: String, |
5612 observer: 'unselectAll' | 5340 observer: 'selectedPageChanged_' |
5613 }, | 5341 }, |
5614 grouped_: { | 5342 grouped_: { |
5615 type: Boolean, | 5343 type: Boolean, |
5616 reflectToAttribute: true | 5344 reflectToAttribute: true |
5617 }, | 5345 }, |
5618 queryState_: { | 5346 queryState_: { |
5619 type: Object, | 5347 type: Object, |
5620 value: function() { | 5348 value: function() { |
5621 return { | 5349 return { |
5622 incremental: false, | 5350 incremental: false, |
(...skipping 14 matching lines...) Expand all Loading... |
5637 queryResult_: { | 5365 queryResult_: { |
5638 type: Object, | 5366 type: Object, |
5639 value: function() { | 5367 value: function() { |
5640 return { | 5368 return { |
5641 info: null, | 5369 info: null, |
5642 results: null, | 5370 results: null, |
5643 sessionList: null | 5371 sessionList: null |
5644 }; | 5372 }; |
5645 } | 5373 } |
5646 }, | 5374 }, |
5647 routeData_: Object, | |
5648 queryParams_: Object, | |
5649 hasDrawer_: Boolean, | 5375 hasDrawer_: Boolean, |
5650 isUserSignedIn_: { | 5376 isUserSignedIn_: { |
5651 type: Boolean, | 5377 type: Boolean, |
5652 value: loadTimeData.getBoolean('isUserSignedIn') | 5378 value: loadTimeData.getBoolean('isUserSignedIn') |
5653 }, | 5379 }, |
5654 toolbarShadow_: { | 5380 toolbarShadow_: { |
5655 type: Boolean, | 5381 type: Boolean, |
5656 reflectToAttribute: true, | 5382 reflectToAttribute: true, |
5657 notify: true | 5383 notify: true |
5658 } | 5384 } |
5659 }, | 5385 }, |
5660 observers: [ 'routeDataChanged_(routeData_.page)', 'selectedPageChanged_(selec
tedPage_)', 'searchTermChanged_(queryState_.searchTerm)', 'searchQueryParamChang
ed_(queryParams_.q)' ], | |
5661 listeners: { | 5386 listeners: { |
5662 'cr-menu-tap': 'onMenuTap_', | 5387 'cr-menu-tap': 'onMenuTap_', |
5663 'history-checkbox-select': 'checkboxSelected', | 5388 'history-checkbox-select': 'checkboxSelected', |
5664 'unselect-all': 'unselectAll', | 5389 'unselect-all': 'unselectAll', |
5665 'delete-selected': 'deleteSelected', | 5390 'delete-selected': 'deleteSelected', |
5666 'search-domain': 'searchDomain_', | |
5667 'history-close-drawer': 'closeDrawer_', | 5391 'history-close-drawer': 'closeDrawer_', |
5668 'history-view-changed': 'historyViewChanged_' | 5392 'history-view-changed': 'historyViewChanged_' |
5669 }, | 5393 }, |
5670 ready: function() { | 5394 ready: function() { |
5671 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); | 5395 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); |
5672 cr.ui.decorate('command', cr.ui.Command); | 5396 cr.ui.decorate('command', cr.ui.Command); |
5673 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 5397 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
5674 document.addEventListener('command', this.onCommand_.bind(this)); | 5398 document.addEventListener('command', this.onCommand_.bind(this)); |
5675 if (window.location.hash) { | |
5676 window.location.href = window.location.href.split('#')[0] + '?' + window.l
ocation.hash.substr(1); | |
5677 } | |
5678 }, | 5399 }, |
5679 onFirstRender: function() { | 5400 onFirstRender: function() { |
5680 setTimeout(function() { | 5401 setTimeout(function() { |
5681 chrome.send('metricsHandler:recordTime', [ 'History.ResultsRenderedTime',
window.performance.now() ]); | 5402 chrome.send('metricsHandler:recordTime', [ 'History.ResultsRenderedTime',
window.performance.now() ]); |
5682 }); | 5403 }); |
5683 if (!this.hasDrawer_) { | 5404 if (!this.hasDrawer_) { |
5684 this.focusToolbarSearchField(); | 5405 this.focusToolbarSearchField(); |
5685 } | 5406 } |
5686 md_history.ensureLazyLoaded(); | 5407 md_history.ensureLazyLoaded(); |
5687 }, | 5408 }, |
5688 _scrollHandler: function() { | 5409 _scrollHandler: function() { |
5689 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0; | 5410 if (this.scrollTarget) this.toolbarShadow_ = this.scrollTarget.scrollTop !=
0; |
5690 }, | 5411 }, |
5691 onMenuTap_: function() { | 5412 onMenuTap_: function() { |
5692 var drawer = this.$$('#drawer'); | 5413 var drawer = this.$$('#drawer'); |
5693 if (drawer) drawer.toggle(); | 5414 if (drawer) drawer.toggle(); |
5694 }, | 5415 }, |
5695 checkboxSelected: function(e) { | 5416 checkboxSelected: function(e) { |
5696 var toolbar = this.$.toolbar; | 5417 var toolbar = this.$.toolbar; |
5697 toolbar.count = this.$.history.getSelectedItemCount(); | 5418 toolbar.count = this.$.history.getSelectedItemCount(); |
5698 }, | 5419 }, |
5699 unselectAll: function() { | 5420 unselectAll: function() { |
5700 var listContainer = this.$.history; | 5421 var listContainer = this.$.history; |
5701 var toolbar = this.$.toolbar; | 5422 var toolbar = this.$.toolbar; |
5702 listContainer.unselectAllItems(toolbar.count); | 5423 listContainer.unselectAllItems(toolbar.count); |
5703 toolbar.count = 0; | 5424 toolbar.count = 0; |
5704 }, | 5425 }, |
5705 deleteSelected: function() { | 5426 deleteSelected: function() { |
5706 this.$.history.deleteSelectedWithPrompt(); | 5427 this.$.history.deleteSelectedWithPrompt(); |
5707 }, | 5428 }, |
5708 historyResult: function(info, results) { | 5429 historyResult: function(info, results) { |
5709 this.set('queryState_.querying', false); | 5430 this.set('queryState_.querying', false); |
5710 this.set('queryResult_.info', info); | 5431 this.set('queryResult_.info', info); |
5711 this.set('queryResult_.results', results); | 5432 this.set('queryResult_.results', results); |
5712 var listContainer = this.$['history']; | 5433 var listContainer = this.$['history']; |
5713 listContainer.historyResult(info, results); | 5434 listContainer.historyResult(info, results); |
5714 }, | 5435 }, |
5715 focusToolbarSearchField: function() { | 5436 focusToolbarSearchField: function() { |
5716 this.$.toolbar.showSearchField(); | 5437 this.$.toolbar.showSearchField(); |
5717 }, | 5438 }, |
5718 searchDomain_: function(e) { | |
5719 this.$.toolbar.setSearchTerm(e.detail.domain); | |
5720 }, | |
5721 onCanExecute_: function(e) { | 5439 onCanExecute_: function(e) { |
5722 e = e; | 5440 e = e; |
5723 switch (e.command.id) { | 5441 switch (e.command.id) { |
5724 case 'find-command': | 5442 case 'find-command': |
5725 e.canExecute = true; | 5443 e.canExecute = true; |
5726 break; | 5444 break; |
5727 | 5445 |
5728 case 'slash-command': | 5446 case 'slash-command': |
5729 e.canExecute = !this.$.toolbar.searchBar.isSearchFocused(); | 5447 e.canExecute = !this.$.toolbar.searchField.isSearchFocused(); |
5730 break; | 5448 break; |
5731 | 5449 |
5732 case 'delete-command': | 5450 case 'delete-command': |
5733 e.canExecute = this.$.toolbar.count > 0; | 5451 e.canExecute = this.$.toolbar.count > 0; |
5734 break; | 5452 break; |
5735 } | 5453 } |
5736 }, | 5454 }, |
5737 searchTermChanged_: function(searchTerm) { | |
5738 this.set('queryParams_.q', searchTerm || null); | |
5739 this.$['history'].queryHistory(false); | |
5740 if (this.queryState_.searchTerm) md_history.BrowserService.getInstance().rec
ordAction('Search'); | |
5741 }, | |
5742 searchQueryParamChanged_: function(searchQuery) { | |
5743 this.$.toolbar.setSearchTerm(searchQuery || ''); | |
5744 }, | |
5745 onCommand_: function(e) { | 5455 onCommand_: function(e) { |
5746 if (e.command.id == 'find-command' || e.command.id == 'slash-command') this.
focusToolbarSearchField(); | 5456 if (e.command.id == 'find-command' || e.command.id == 'slash-command') this.
focusToolbarSearchField(); |
5747 if (e.command.id == 'delete-command') this.deleteSelected(); | 5457 if (e.command.id == 'delete-command') this.deleteSelected(); |
5748 }, | 5458 }, |
5749 setForeignSessions: function(sessionList, isTabSyncEnabled) { | 5459 setForeignSessions: function(sessionList, isTabSyncEnabled) { |
5750 if (!isTabSyncEnabled) { | 5460 if (!isTabSyncEnabled) { |
5751 var syncedDeviceManagerElem = this.$$('history-synced-device-manager'); | 5461 var syncedDeviceManagerElem = this.$$('history-synced-device-manager'); |
5752 if (syncedDeviceManagerElem) syncedDeviceManagerElem.tabSyncDisabled(); | 5462 if (syncedDeviceManagerElem) syncedDeviceManagerElem.tabSyncDisabled(); |
5753 return; | 5463 return; |
5754 } | 5464 } |
5755 this.set('queryResult_.sessionList', sessionList); | 5465 this.set('queryResult_.sessionList', sessionList); |
5756 }, | 5466 }, |
5757 historyDeleted: function() { | 5467 historyDeleted: function() { |
5758 this.$.history.historyDeleted(); | 5468 this.$.history.historyDeleted(); |
5759 }, | 5469 }, |
5760 updateSignInState: function(isUserSignedIn) { | 5470 updateSignInState: function(isUserSignedIn) { |
5761 this.isUserSignedIn_ = isUserSignedIn; | 5471 this.isUserSignedIn_ = isUserSignedIn; |
5762 }, | 5472 }, |
5763 syncedTabsSelected_: function(selectedPage) { | 5473 syncedTabsSelected_: function(selectedPage) { |
5764 return selectedPage == 'syncedTabs'; | 5474 return selectedPage == 'syncedTabs'; |
5765 }, | 5475 }, |
5766 shouldShowSpinner_: function(querying, incremental, searchTerm) { | 5476 shouldShowSpinner_: function(querying, incremental, searchTerm) { |
5767 return querying && !incremental && searchTerm != ''; | 5477 return querying && !incremental && searchTerm != ''; |
5768 }, | 5478 }, |
5769 showSyncNotice_: function(hasSyncedResults, selectedPage) { | 5479 showSyncNotice_: function(hasSyncedResults, selectedPage) { |
5770 return hasSyncedResults && selectedPage != 'syncedTabs'; | 5480 return hasSyncedResults && selectedPage != 'syncedTabs'; |
5771 }, | 5481 }, |
5772 routeDataChanged_: function(page) { | 5482 selectedPageChanged_: function() { |
5773 this.selectedPage_ = page; | 5483 this.unselectAll(); |
5774 }, | |
5775 selectedPageChanged_: function(selectedPage) { | |
5776 this.set('routeData_.page', selectedPage); | |
5777 this.historyViewChanged_(); | 5484 this.historyViewChanged_(); |
5778 }, | 5485 }, |
5779 historyViewChanged_: function() { | 5486 historyViewChanged_: function() { |
5780 requestAnimationFrame(function() { | 5487 requestAnimationFrame(function() { |
| 5488 if (!this.$.content.selectedItem) return; |
5781 this.scrollTarget = this.$.content.selectedItem.getContentScrollTarget(); | 5489 this.scrollTarget = this.$.content.selectedItem.getContentScrollTarget(); |
5782 this._scrollHandler(); | 5490 this._scrollHandler(); |
5783 }.bind(this)); | 5491 }.bind(this)); |
5784 this.recordHistoryPageView_(); | 5492 this.recordHistoryPageView_(); |
5785 }, | 5493 }, |
5786 getSelectedPage_: function(selectedPage, items) { | 5494 getSelectedPage_: function(selectedPage, items) { |
5787 return selectedPage; | 5495 return selectedPage; |
5788 }, | 5496 }, |
5789 closeDrawer_: function() { | 5497 closeDrawer_: function() { |
5790 var drawer = this.$$('#drawer'); | 5498 var drawer = this.$$('#drawer'); |
(...skipping 18 matching lines...) Expand all Loading... |
5809 | 5517 |
5810 case HistoryRange.MONTH: | 5518 case HistoryRange.MONTH: |
5811 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; | 5519 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; |
5812 break; | 5520 break; |
5813 } | 5521 } |
5814 break; | 5522 break; |
5815 } | 5523 } |
5816 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage
View', histogramValue, HistoryPageViewHistogram.END); | 5524 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage
View', histogramValue, HistoryPageViewHistogram.END); |
5817 } | 5525 } |
5818 }); | 5526 }); |
OLD | NEW |