| 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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 _DRAWER_STATE: { | 823 _DRAWER_STATE: { |
| 824 INIT: 0, | 824 INIT: 0, |
| 825 OPENED: 1, | 825 OPENED: 1, |
| 826 OPENED_PERSISTENT: 2, | 826 OPENED_PERSISTENT: 2, |
| 827 CLOSED: 3, | 827 CLOSED: 3, |
| 828 TRACKING: 4, | 828 TRACKING: 4, |
| 829 FLINGING: 5 | 829 FLINGING: 5 |
| 830 } | 830 } |
| 831 }); | 831 }); |
| 832 | 832 |
| 833 (function() { | |
| 834 'use strict'; | |
| 835 Polymer({ | |
| 836 is: 'iron-location', | |
| 837 properties: { | |
| 838 path: { | |
| 839 type: String, | |
| 840 notify: true, | |
| 841 value: function() { | |
| 842 return window.decodeURIComponent(window.location.pathname); | |
| 843 } | |
| 844 }, | |
| 845 query: { | |
| 846 type: String, | |
| 847 notify: true, | |
| 848 value: function() { | |
| 849 return window.decodeURIComponent(window.location.search.slice(1)); | |
| 850 } | |
| 851 }, | |
| 852 hash: { | |
| 853 type: String, | |
| 854 notify: true, | |
| 855 value: function() { | |
| 856 return window.decodeURIComponent(window.location.hash.slice(1)); | |
| 857 } | |
| 858 }, | |
| 859 dwellTime: { | |
| 860 type: Number, | |
| 861 value: 2e3 | |
| 862 }, | |
| 863 urlSpaceRegex: { | |
| 864 type: String, | |
| 865 value: '' | |
| 866 }, | |
| 867 _urlSpaceRegExp: { | |
| 868 computed: '_makeRegExp(urlSpaceRegex)' | |
| 869 }, | |
| 870 _lastChangedAt: { | |
| 871 type: Number | |
| 872 }, | |
| 873 _initialized: { | |
| 874 type: Boolean, | |
| 875 value: false | |
| 876 } | |
| 877 }, | |
| 878 hostAttributes: { | |
| 879 hidden: true | |
| 880 }, | |
| 881 observers: [ '_updateUrl(path, query, hash)' ], | |
| 882 attached: function() { | |
| 883 this.listen(window, 'hashchange', '_hashChanged'); | |
| 884 this.listen(window, 'location-changed', '_urlChanged'); | |
| 885 this.listen(window, 'popstate', '_urlChanged'); | |
| 886 this.listen(document.body, 'click', '_globalOnClick'); | |
| 887 this._lastChangedAt = window.performance.now() - (this.dwellTime - 200); | |
| 888 this._initialized = true; | |
| 889 this._urlChanged(); | |
| 890 }, | |
| 891 detached: function() { | |
| 892 this.unlisten(window, 'hashchange', '_hashChanged'); | |
| 893 this.unlisten(window, 'location-changed', '_urlChanged'); | |
| 894 this.unlisten(window, 'popstate', '_urlChanged'); | |
| 895 this.unlisten(document.body, 'click', '_globalOnClick'); | |
| 896 this._initialized = false; | |
| 897 }, | |
| 898 _hashChanged: function() { | |
| 899 this.hash = window.decodeURIComponent(window.location.hash.substring(1)); | |
| 900 }, | |
| 901 _urlChanged: function() { | |
| 902 this._dontUpdateUrl = true; | |
| 903 this._hashChanged(); | |
| 904 this.path = window.decodeURIComponent(window.location.pathname); | |
| 905 this.query = window.decodeURIComponent(window.location.search.substring(1)
); | |
| 906 this._dontUpdateUrl = false; | |
| 907 this._updateUrl(); | |
| 908 }, | |
| 909 _getUrl: function() { | |
| 910 var partiallyEncodedPath = window.encodeURI(this.path).replace(/\#/g, '%23
').replace(/\?/g, '%3F'); | |
| 911 var partiallyEncodedQuery = ''; | |
| 912 if (this.query) { | |
| 913 partiallyEncodedQuery = '?' + window.encodeURI(this.query).replace(/\#/g
, '%23'); | |
| 914 } | |
| 915 var partiallyEncodedHash = ''; | |
| 916 if (this.hash) { | |
| 917 partiallyEncodedHash = '#' + window.encodeURI(this.hash); | |
| 918 } | |
| 919 return partiallyEncodedPath + partiallyEncodedQuery + partiallyEncodedHash
; | |
| 920 }, | |
| 921 _updateUrl: function() { | |
| 922 if (this._dontUpdateUrl || !this._initialized) { | |
| 923 return; | |
| 924 } | |
| 925 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))) { | |
| 926 return; | |
| 927 } | |
| 928 var newUrl = this._getUrl(); | |
| 929 var fullNewUrl = new URL(newUrl, window.location.protocol + '//' + window.
location.host).href; | |
| 930 var now = window.performance.now(); | |
| 931 var shouldReplace = this._lastChangedAt + this.dwellTime > now; | |
| 932 this._lastChangedAt = now; | |
| 933 if (shouldReplace) { | |
| 934 window.history.replaceState({}, '', fullNewUrl); | |
| 935 } else { | |
| 936 window.history.pushState({}, '', fullNewUrl); | |
| 937 } | |
| 938 this.fire('location-changed', {}, { | |
| 939 node: window | |
| 940 }); | |
| 941 }, | |
| 942 _globalOnClick: function(event) { | |
| 943 if (event.defaultPrevented) { | |
| 944 return; | |
| 945 } | |
| 946 var href = this._getSameOriginLinkHref(event); | |
| 947 if (!href) { | |
| 948 return; | |
| 949 } | |
| 950 event.preventDefault(); | |
| 951 if (href === window.location.href) { | |
| 952 return; | |
| 953 } | |
| 954 window.history.pushState({}, '', href); | |
| 955 this.fire('location-changed', {}, { | |
| 956 node: window | |
| 957 }); | |
| 958 }, | |
| 959 _getSameOriginLinkHref: function(event) { | |
| 960 if (event.button !== 0) { | |
| 961 return null; | |
| 962 } | |
| 963 if (event.metaKey || event.ctrlKey) { | |
| 964 return null; | |
| 965 } | |
| 966 var eventPath = Polymer.dom(event).path; | |
| 967 var anchor = null; | |
| 968 for (var i = 0; i < eventPath.length; i++) { | |
| 969 var element = eventPath[i]; | |
| 970 if (element.tagName === 'A' && element.href) { | |
| 971 anchor = element; | |
| 972 break; | |
| 973 } | |
| 974 } | |
| 975 if (!anchor) { | |
| 976 return null; | |
| 977 } | |
| 978 if (anchor.target === '_blank') { | |
| 979 return null; | |
| 980 } | |
| 981 if ((anchor.target === '_top' || anchor.target === '_parent') && window.to
p !== window) { | |
| 982 return null; | |
| 983 } | |
| 984 var href = anchor.href; | |
| 985 var url; | |
| 986 if (document.baseURI != null) { | |
| 987 url = new URL(href, document.baseURI); | |
| 988 } else { | |
| 989 url = new URL(href); | |
| 990 } | |
| 991 var origin; | |
| 992 if (window.location.origin) { | |
| 993 origin = window.location.origin; | |
| 994 } else { | |
| 995 origin = window.location.protocol + '//' + window.location.hostname; | |
| 996 if (window.location.port) { | |
| 997 origin += ':' + window.location.port; | |
| 998 } | |
| 999 } | |
| 1000 if (url.origin !== origin) { | |
| 1001 return null; | |
| 1002 } | |
| 1003 var normalizedHref = url.pathname + url.search + url.hash; | |
| 1004 if (this._urlSpaceRegExp && !this._urlSpaceRegExp.test(normalizedHref)) { | |
| 1005 return null; | |
| 1006 } | |
| 1007 var fullNormalizedHref = new URL(normalizedHref, window.location.href).hre
f; | |
| 1008 return fullNormalizedHref; | |
| 1009 }, | |
| 1010 _makeRegExp: function(urlSpaceRegex) { | |
| 1011 return RegExp(urlSpaceRegex); | |
| 1012 } | |
| 1013 }); | |
| 1014 })(); | |
| 1015 | |
| 1016 'use strict'; | |
| 1017 | |
| 1018 Polymer({ | |
| 1019 is: 'iron-query-params', | |
| 1020 properties: { | |
| 1021 paramsString: { | |
| 1022 type: String, | |
| 1023 notify: true, | |
| 1024 observer: 'paramsStringChanged' | |
| 1025 }, | |
| 1026 paramsObject: { | |
| 1027 type: Object, | |
| 1028 notify: true, | |
| 1029 value: function() { | |
| 1030 return {}; | |
| 1031 } | |
| 1032 }, | |
| 1033 _dontReact: { | |
| 1034 type: Boolean, | |
| 1035 value: false | |
| 1036 } | |
| 1037 }, | |
| 1038 hostAttributes: { | |
| 1039 hidden: true | |
| 1040 }, | |
| 1041 observers: [ 'paramsObjectChanged(paramsObject.*)' ], | |
| 1042 paramsStringChanged: function() { | |
| 1043 this._dontReact = true; | |
| 1044 this.paramsObject = this._decodeParams(this.paramsString); | |
| 1045 this._dontReact = false; | |
| 1046 }, | |
| 1047 paramsObjectChanged: function() { | |
| 1048 if (this._dontReact) { | |
| 1049 return; | |
| 1050 } | |
| 1051 this.paramsString = this._encodeParams(this.paramsObject); | |
| 1052 }, | |
| 1053 _encodeParams: function(params) { | |
| 1054 var encodedParams = []; | |
| 1055 for (var key in params) { | |
| 1056 var value = params[key]; | |
| 1057 if (value === '') { | |
| 1058 encodedParams.push(encodeURIComponent(key)); | |
| 1059 } else if (value) { | |
| 1060 encodedParams.push(encodeURIComponent(key) + '=' + encodeURIComponent(va
lue.toString())); | |
| 1061 } | |
| 1062 } | |
| 1063 return encodedParams.join('&'); | |
| 1064 }, | |
| 1065 _decodeParams: function(paramString) { | |
| 1066 var params = {}; | |
| 1067 paramString = (paramString || '').replace(/\+/g, '%20'); | |
| 1068 var paramList = paramString.split('&'); | |
| 1069 for (var i = 0; i < paramList.length; i++) { | |
| 1070 var param = paramList[i].split('='); | |
| 1071 if (param[0]) { | |
| 1072 params[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || ''
); | |
| 1073 } | |
| 1074 } | |
| 1075 return params; | |
| 1076 } | |
| 1077 }); | |
| 1078 | |
| 1079 'use strict'; | |
| 1080 | |
| 1081 Polymer.AppRouteConverterBehavior = { | |
| 1082 properties: { | |
| 1083 route: { | |
| 1084 type: Object, | |
| 1085 notify: true | |
| 1086 }, | |
| 1087 queryParams: { | |
| 1088 type: Object, | |
| 1089 notify: true | |
| 1090 }, | |
| 1091 path: { | |
| 1092 type: String, | |
| 1093 notify: true | |
| 1094 } | |
| 1095 }, | |
| 1096 observers: [ '_locationChanged(path, queryParams)', '_routeChanged(route.prefi
x, route.path)', '_routeQueryParamsChanged(route.__queryParams)' ], | |
| 1097 created: function() { | |
| 1098 this.linkPaths('route.__queryParams', 'queryParams'); | |
| 1099 this.linkPaths('queryParams', 'route.__queryParams'); | |
| 1100 }, | |
| 1101 _locationChanged: function() { | |
| 1102 if (this.route && this.route.path === this.path && this.queryParams === this
.route.__queryParams) { | |
| 1103 return; | |
| 1104 } | |
| 1105 this.route = { | |
| 1106 prefix: '', | |
| 1107 path: this.path, | |
| 1108 __queryParams: this.queryParams | |
| 1109 }; | |
| 1110 }, | |
| 1111 _routeChanged: function() { | |
| 1112 if (!this.route) { | |
| 1113 return; | |
| 1114 } | |
| 1115 this.path = this.route.prefix + this.route.path; | |
| 1116 }, | |
| 1117 _routeQueryParamsChanged: function(queryParams) { | |
| 1118 if (!this.route) { | |
| 1119 return; | |
| 1120 } | |
| 1121 this.queryParams = queryParams; | |
| 1122 } | |
| 1123 }; | |
| 1124 | |
| 1125 'use strict'; | |
| 1126 | |
| 1127 Polymer({ | |
| 1128 is: 'app-location', | |
| 1129 properties: { | |
| 1130 route: { | |
| 1131 type: Object, | |
| 1132 notify: true | |
| 1133 }, | |
| 1134 useHashAsPath: { | |
| 1135 type: Boolean, | |
| 1136 value: false | |
| 1137 }, | |
| 1138 urlSpaceRegex: { | |
| 1139 type: String, | |
| 1140 notify: true | |
| 1141 }, | |
| 1142 __queryParams: { | |
| 1143 type: Object | |
| 1144 }, | |
| 1145 __path: { | |
| 1146 type: String | |
| 1147 }, | |
| 1148 __query: { | |
| 1149 type: String | |
| 1150 }, | |
| 1151 __hash: { | |
| 1152 type: String | |
| 1153 }, | |
| 1154 path: { | |
| 1155 type: String, | |
| 1156 observer: '__onPathChanged' | |
| 1157 } | |
| 1158 }, | |
| 1159 behaviors: [ Polymer.AppRouteConverterBehavior ], | |
| 1160 observers: [ '__computeRoutePath(useHashAsPath, __hash, __path)' ], | |
| 1161 __computeRoutePath: function() { | |
| 1162 this.path = this.useHashAsPath ? this.__hash : this.__path; | |
| 1163 }, | |
| 1164 __onPathChanged: function() { | |
| 1165 if (!this._readied) { | |
| 1166 return; | |
| 1167 } | |
| 1168 if (this.useHashAsPath) { | |
| 1169 this.__hash = this.path; | |
| 1170 } else { | |
| 1171 this.__path = this.path; | |
| 1172 } | |
| 1173 } | |
| 1174 }); | |
| 1175 | |
| 1176 'use strict'; | |
| 1177 | |
| 1178 Polymer({ | |
| 1179 is: 'app-route', | |
| 1180 properties: { | |
| 1181 route: { | |
| 1182 type: Object, | |
| 1183 notify: true | |
| 1184 }, | |
| 1185 pattern: { | |
| 1186 type: String | |
| 1187 }, | |
| 1188 data: { | |
| 1189 type: Object, | |
| 1190 value: function() { | |
| 1191 return {}; | |
| 1192 }, | |
| 1193 notify: true | |
| 1194 }, | |
| 1195 queryParams: { | |
| 1196 type: Object, | |
| 1197 value: function() { | |
| 1198 return {}; | |
| 1199 }, | |
| 1200 notify: true | |
| 1201 }, | |
| 1202 tail: { | |
| 1203 type: Object, | |
| 1204 value: function() { | |
| 1205 return { | |
| 1206 path: null, | |
| 1207 prefix: null, | |
| 1208 __queryParams: null | |
| 1209 }; | |
| 1210 }, | |
| 1211 notify: true | |
| 1212 }, | |
| 1213 active: { | |
| 1214 type: Boolean, | |
| 1215 notify: true, | |
| 1216 readOnly: true | |
| 1217 }, | |
| 1218 _queryParamsUpdating: { | |
| 1219 type: Boolean, | |
| 1220 value: false | |
| 1221 }, | |
| 1222 _matched: { | |
| 1223 type: String, | |
| 1224 value: '' | |
| 1225 } | |
| 1226 }, | |
| 1227 observers: [ '__tryToMatch(route.path, pattern)', '__updatePathOnDataChange(da
ta.*)', '__tailPathChanged(tail.path)', '__routeQueryParamsChanged(route.__query
Params)', '__tailQueryParamsChanged(tail.__queryParams)', '__queryParamsChanged(
queryParams.*)' ], | |
| 1228 created: function() { | |
| 1229 this.linkPaths('route.__queryParams', 'tail.__queryParams'); | |
| 1230 this.linkPaths('tail.__queryParams', 'route.__queryParams'); | |
| 1231 }, | |
| 1232 __routeQueryParamsChanged: function(queryParams) { | |
| 1233 if (queryParams && this.tail) { | |
| 1234 this.set('tail.__queryParams', queryParams); | |
| 1235 if (!this.active || this._queryParamsUpdating) { | |
| 1236 return; | |
| 1237 } | |
| 1238 var copyOfQueryParams = {}; | |
| 1239 var anythingChanged = false; | |
| 1240 for (var key in queryParams) { | |
| 1241 copyOfQueryParams[key] = queryParams[key]; | |
| 1242 if (anythingChanged || !this.queryParams || queryParams[key] !== this.qu
eryParams[key]) { | |
| 1243 anythingChanged = true; | |
| 1244 } | |
| 1245 } | |
| 1246 for (var key in this.queryParams) { | |
| 1247 if (anythingChanged || !(key in queryParams)) { | |
| 1248 anythingChanged = true; | |
| 1249 break; | |
| 1250 } | |
| 1251 } | |
| 1252 if (!anythingChanged) { | |
| 1253 return; | |
| 1254 } | |
| 1255 this._queryParamsUpdating = true; | |
| 1256 this.set('queryParams', copyOfQueryParams); | |
| 1257 this._queryParamsUpdating = false; | |
| 1258 } | |
| 1259 }, | |
| 1260 __tailQueryParamsChanged: function(queryParams) { | |
| 1261 if (queryParams && this.route) { | |
| 1262 this.set('route.__queryParams', queryParams); | |
| 1263 } | |
| 1264 }, | |
| 1265 __queryParamsChanged: function(changes) { | |
| 1266 if (!this.active || this._queryParamsUpdating) { | |
| 1267 return; | |
| 1268 } | |
| 1269 this.set('route.__' + changes.path, changes.value); | |
| 1270 }, | |
| 1271 __resetProperties: function() { | |
| 1272 this._setActive(false); | |
| 1273 this._matched = null; | |
| 1274 }, | |
| 1275 __tryToMatch: function() { | |
| 1276 if (!this.route) { | |
| 1277 return; | |
| 1278 } | |
| 1279 var path = this.route.path; | |
| 1280 var pattern = this.pattern; | |
| 1281 if (!pattern) { | |
| 1282 return; | |
| 1283 } | |
| 1284 if (!path) { | |
| 1285 this.__resetProperties(); | |
| 1286 return; | |
| 1287 } | |
| 1288 var remainingPieces = path.split('/'); | |
| 1289 var patternPieces = pattern.split('/'); | |
| 1290 var matched = []; | |
| 1291 var namedMatches = {}; | |
| 1292 for (var i = 0; i < patternPieces.length; i++) { | |
| 1293 var patternPiece = patternPieces[i]; | |
| 1294 if (!patternPiece && patternPiece !== '') { | |
| 1295 break; | |
| 1296 } | |
| 1297 var pathPiece = remainingPieces.shift(); | |
| 1298 if (!pathPiece && pathPiece !== '') { | |
| 1299 this.__resetProperties(); | |
| 1300 return; | |
| 1301 } | |
| 1302 matched.push(pathPiece); | |
| 1303 if (patternPiece.charAt(0) == ':') { | |
| 1304 namedMatches[patternPiece.slice(1)] = pathPiece; | |
| 1305 } else if (patternPiece !== pathPiece) { | |
| 1306 this.__resetProperties(); | |
| 1307 return; | |
| 1308 } | |
| 1309 } | |
| 1310 this._matched = matched.join('/'); | |
| 1311 var propertyUpdates = {}; | |
| 1312 if (!this.active) { | |
| 1313 propertyUpdates.active = true; | |
| 1314 } | |
| 1315 var tailPrefix = this.route.prefix + this._matched; | |
| 1316 var tailPath = remainingPieces.join('/'); | |
| 1317 if (remainingPieces.length > 0) { | |
| 1318 tailPath = '/' + tailPath; | |
| 1319 } | |
| 1320 if (!this.tail || this.tail.prefix !== tailPrefix || this.tail.path !== tail
Path) { | |
| 1321 propertyUpdates.tail = { | |
| 1322 prefix: tailPrefix, | |
| 1323 path: tailPath, | |
| 1324 __queryParams: this.route.__queryParams | |
| 1325 }; | |
| 1326 } | |
| 1327 propertyUpdates.data = namedMatches; | |
| 1328 this._dataInUrl = {}; | |
| 1329 for (var key in namedMatches) { | |
| 1330 this._dataInUrl[key] = namedMatches[key]; | |
| 1331 } | |
| 1332 this.__setMulti(propertyUpdates); | |
| 1333 }, | |
| 1334 __tailPathChanged: function() { | |
| 1335 if (!this.active) { | |
| 1336 return; | |
| 1337 } | |
| 1338 var tailPath = this.tail.path; | |
| 1339 var newPath = this._matched; | |
| 1340 if (tailPath) { | |
| 1341 if (tailPath.charAt(0) !== '/') { | |
| 1342 tailPath = '/' + tailPath; | |
| 1343 } | |
| 1344 newPath += tailPath; | |
| 1345 } | |
| 1346 this.set('route.path', newPath); | |
| 1347 }, | |
| 1348 __updatePathOnDataChange: function() { | |
| 1349 if (!this.route || !this.active) { | |
| 1350 return; | |
| 1351 } | |
| 1352 var newPath = this.__getLink({}); | |
| 1353 var oldPath = this.__getLink(this._dataInUrl); | |
| 1354 if (newPath === oldPath) { | |
| 1355 return; | |
| 1356 } | |
| 1357 this.set('route.path', newPath); | |
| 1358 }, | |
| 1359 __getLink: function(overrideValues) { | |
| 1360 var values = { | |
| 1361 tail: null | |
| 1362 }; | |
| 1363 for (var key in this.data) { | |
| 1364 values[key] = this.data[key]; | |
| 1365 } | |
| 1366 for (var key in overrideValues) { | |
| 1367 values[key] = overrideValues[key]; | |
| 1368 } | |
| 1369 var patternPieces = this.pattern.split('/'); | |
| 1370 var interp = patternPieces.map(function(value) { | |
| 1371 if (value[0] == ':') { | |
| 1372 value = values[value.slice(1)]; | |
| 1373 } | |
| 1374 return value; | |
| 1375 }, this); | |
| 1376 if (values.tail && values.tail.path) { | |
| 1377 if (interp.length > 0 && values.tail.path.charAt(0) === '/') { | |
| 1378 interp.push(values.tail.path.slice(1)); | |
| 1379 } else { | |
| 1380 interp.push(values.tail.path); | |
| 1381 } | |
| 1382 } | |
| 1383 return interp.join('/'); | |
| 1384 }, | |
| 1385 __setMulti: function(setObj) { | |
| 1386 for (var property in setObj) { | |
| 1387 this._propertySetter(property, setObj[property]); | |
| 1388 } | |
| 1389 for (var property in setObj) { | |
| 1390 this._pathEffector(property, this[property]); | |
| 1391 this._notifyPathUp(property, this[property]); | |
| 1392 } | |
| 1393 } | |
| 1394 }); | |
| 1395 | |
| 1396 Polymer({ | 833 Polymer({ |
| 1397 is: 'iron-media-query', | 834 is: 'iron-media-query', |
| 1398 properties: { | 835 properties: { |
| 1399 queryMatches: { | 836 queryMatches: { |
| 1400 type: Boolean, | 837 type: Boolean, |
| 1401 value: false, | 838 value: false, |
| 1402 readOnly: true, | 839 readOnly: true, |
| 1403 notify: true | 840 notify: true |
| 1404 }, | 841 }, |
| 1405 query: { | 842 query: { |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 } | 1354 } |
| 1918 return 0; | 1355 return 0; |
| 1919 }, | 1356 }, |
| 1920 _isValidScrollTarget: function() { | 1357 _isValidScrollTarget: function() { |
| 1921 return this.scrollTarget instanceof HTMLElement; | 1358 return this.scrollTarget instanceof HTMLElement; |
| 1922 } | 1359 } |
| 1923 }; | 1360 }; |
| 1924 | 1361 |
| 1925 (function() { | 1362 (function() { |
| 1926 'use strict'; | 1363 'use strict'; |
| 1364 Polymer({ |
| 1365 is: 'iron-location', |
| 1366 properties: { |
| 1367 path: { |
| 1368 type: String, |
| 1369 notify: true, |
| 1370 value: function() { |
| 1371 return window.decodeURIComponent(window.location.pathname); |
| 1372 } |
| 1373 }, |
| 1374 query: { |
| 1375 type: String, |
| 1376 notify: true, |
| 1377 value: function() { |
| 1378 return window.decodeURIComponent(window.location.search.slice(1)); |
| 1379 } |
| 1380 }, |
| 1381 hash: { |
| 1382 type: String, |
| 1383 notify: true, |
| 1384 value: function() { |
| 1385 return window.decodeURIComponent(window.location.hash.slice(1)); |
| 1386 } |
| 1387 }, |
| 1388 dwellTime: { |
| 1389 type: Number, |
| 1390 value: 2e3 |
| 1391 }, |
| 1392 urlSpaceRegex: { |
| 1393 type: String, |
| 1394 value: '' |
| 1395 }, |
| 1396 _urlSpaceRegExp: { |
| 1397 computed: '_makeRegExp(urlSpaceRegex)' |
| 1398 }, |
| 1399 _lastChangedAt: { |
| 1400 type: Number |
| 1401 }, |
| 1402 _initialized: { |
| 1403 type: Boolean, |
| 1404 value: false |
| 1405 } |
| 1406 }, |
| 1407 hostAttributes: { |
| 1408 hidden: true |
| 1409 }, |
| 1410 observers: [ '_updateUrl(path, query, hash)' ], |
| 1411 attached: function() { |
| 1412 this.listen(window, 'hashchange', '_hashChanged'); |
| 1413 this.listen(window, 'location-changed', '_urlChanged'); |
| 1414 this.listen(window, 'popstate', '_urlChanged'); |
| 1415 this.listen(document.body, 'click', '_globalOnClick'); |
| 1416 this._lastChangedAt = window.performance.now() - (this.dwellTime - 200); |
| 1417 this._initialized = true; |
| 1418 this._urlChanged(); |
| 1419 }, |
| 1420 detached: function() { |
| 1421 this.unlisten(window, 'hashchange', '_hashChanged'); |
| 1422 this.unlisten(window, 'location-changed', '_urlChanged'); |
| 1423 this.unlisten(window, 'popstate', '_urlChanged'); |
| 1424 this.unlisten(document.body, 'click', '_globalOnClick'); |
| 1425 this._initialized = false; |
| 1426 }, |
| 1427 _hashChanged: function() { |
| 1428 this.hash = window.decodeURIComponent(window.location.hash.substring(1)); |
| 1429 }, |
| 1430 _urlChanged: function() { |
| 1431 this._dontUpdateUrl = true; |
| 1432 this._hashChanged(); |
| 1433 this.path = window.decodeURIComponent(window.location.pathname); |
| 1434 this.query = window.decodeURIComponent(window.location.search.substring(1)
); |
| 1435 this._dontUpdateUrl = false; |
| 1436 this._updateUrl(); |
| 1437 }, |
| 1438 _getUrl: function() { |
| 1439 var partiallyEncodedPath = window.encodeURI(this.path).replace(/\#/g, '%23
').replace(/\?/g, '%3F'); |
| 1440 var partiallyEncodedQuery = ''; |
| 1441 if (this.query) { |
| 1442 partiallyEncodedQuery = '?' + window.encodeURI(this.query).replace(/\#/g
, '%23'); |
| 1443 } |
| 1444 var partiallyEncodedHash = ''; |
| 1445 if (this.hash) { |
| 1446 partiallyEncodedHash = '#' + window.encodeURI(this.hash); |
| 1447 } |
| 1448 return partiallyEncodedPath + partiallyEncodedQuery + partiallyEncodedHash
; |
| 1449 }, |
| 1450 _updateUrl: function() { |
| 1451 if (this._dontUpdateUrl || !this._initialized) { |
| 1452 return; |
| 1453 } |
| 1454 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))) { |
| 1455 return; |
| 1456 } |
| 1457 var newUrl = this._getUrl(); |
| 1458 var fullNewUrl = new URL(newUrl, window.location.protocol + '//' + window.
location.host).href; |
| 1459 var now = window.performance.now(); |
| 1460 var shouldReplace = this._lastChangedAt + this.dwellTime > now; |
| 1461 this._lastChangedAt = now; |
| 1462 if (shouldReplace) { |
| 1463 window.history.replaceState({}, '', fullNewUrl); |
| 1464 } else { |
| 1465 window.history.pushState({}, '', fullNewUrl); |
| 1466 } |
| 1467 this.fire('location-changed', {}, { |
| 1468 node: window |
| 1469 }); |
| 1470 }, |
| 1471 _globalOnClick: function(event) { |
| 1472 if (event.defaultPrevented) { |
| 1473 return; |
| 1474 } |
| 1475 var href = this._getSameOriginLinkHref(event); |
| 1476 if (!href) { |
| 1477 return; |
| 1478 } |
| 1479 event.preventDefault(); |
| 1480 if (href === window.location.href) { |
| 1481 return; |
| 1482 } |
| 1483 window.history.pushState({}, '', href); |
| 1484 this.fire('location-changed', {}, { |
| 1485 node: window |
| 1486 }); |
| 1487 }, |
| 1488 _getSameOriginLinkHref: function(event) { |
| 1489 if (event.button !== 0) { |
| 1490 return null; |
| 1491 } |
| 1492 if (event.metaKey || event.ctrlKey) { |
| 1493 return null; |
| 1494 } |
| 1495 var eventPath = Polymer.dom(event).path; |
| 1496 var anchor = null; |
| 1497 for (var i = 0; i < eventPath.length; i++) { |
| 1498 var element = eventPath[i]; |
| 1499 if (element.tagName === 'A' && element.href) { |
| 1500 anchor = element; |
| 1501 break; |
| 1502 } |
| 1503 } |
| 1504 if (!anchor) { |
| 1505 return null; |
| 1506 } |
| 1507 if (anchor.target === '_blank') { |
| 1508 return null; |
| 1509 } |
| 1510 if ((anchor.target === '_top' || anchor.target === '_parent') && window.to
p !== window) { |
| 1511 return null; |
| 1512 } |
| 1513 var href = anchor.href; |
| 1514 var url; |
| 1515 if (document.baseURI != null) { |
| 1516 url = new URL(href, document.baseURI); |
| 1517 } else { |
| 1518 url = new URL(href); |
| 1519 } |
| 1520 var origin; |
| 1521 if (window.location.origin) { |
| 1522 origin = window.location.origin; |
| 1523 } else { |
| 1524 origin = window.location.protocol + '//' + window.location.hostname; |
| 1525 if (window.location.port) { |
| 1526 origin += ':' + window.location.port; |
| 1527 } |
| 1528 } |
| 1529 if (url.origin !== origin) { |
| 1530 return null; |
| 1531 } |
| 1532 var normalizedHref = url.pathname + url.search + url.hash; |
| 1533 if (this._urlSpaceRegExp && !this._urlSpaceRegExp.test(normalizedHref)) { |
| 1534 return null; |
| 1535 } |
| 1536 var fullNormalizedHref = new URL(normalizedHref, window.location.href).hre
f; |
| 1537 return fullNormalizedHref; |
| 1538 }, |
| 1539 _makeRegExp: function(urlSpaceRegex) { |
| 1540 return RegExp(urlSpaceRegex); |
| 1541 } |
| 1542 }); |
| 1543 })(); |
| 1544 |
| 1545 'use strict'; |
| 1546 |
| 1547 Polymer({ |
| 1548 is: 'iron-query-params', |
| 1549 properties: { |
| 1550 paramsString: { |
| 1551 type: String, |
| 1552 notify: true, |
| 1553 observer: 'paramsStringChanged' |
| 1554 }, |
| 1555 paramsObject: { |
| 1556 type: Object, |
| 1557 notify: true, |
| 1558 value: function() { |
| 1559 return {}; |
| 1560 } |
| 1561 }, |
| 1562 _dontReact: { |
| 1563 type: Boolean, |
| 1564 value: false |
| 1565 } |
| 1566 }, |
| 1567 hostAttributes: { |
| 1568 hidden: true |
| 1569 }, |
| 1570 observers: [ 'paramsObjectChanged(paramsObject.*)' ], |
| 1571 paramsStringChanged: function() { |
| 1572 this._dontReact = true; |
| 1573 this.paramsObject = this._decodeParams(this.paramsString); |
| 1574 this._dontReact = false; |
| 1575 }, |
| 1576 paramsObjectChanged: function() { |
| 1577 if (this._dontReact) { |
| 1578 return; |
| 1579 } |
| 1580 this.paramsString = this._encodeParams(this.paramsObject); |
| 1581 }, |
| 1582 _encodeParams: function(params) { |
| 1583 var encodedParams = []; |
| 1584 for (var key in params) { |
| 1585 var value = params[key]; |
| 1586 if (value === '') { |
| 1587 encodedParams.push(encodeURIComponent(key)); |
| 1588 } else if (value) { |
| 1589 encodedParams.push(encodeURIComponent(key) + '=' + encodeURIComponent(va
lue.toString())); |
| 1590 } |
| 1591 } |
| 1592 return encodedParams.join('&'); |
| 1593 }, |
| 1594 _decodeParams: function(paramString) { |
| 1595 var params = {}; |
| 1596 paramString = (paramString || '').replace(/\+/g, '%20'); |
| 1597 var paramList = paramString.split('&'); |
| 1598 for (var i = 0; i < paramList.length; i++) { |
| 1599 var param = paramList[i].split('='); |
| 1600 if (param[0]) { |
| 1601 params[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || ''
); |
| 1602 } |
| 1603 } |
| 1604 return params; |
| 1605 } |
| 1606 }); |
| 1607 |
| 1608 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 1609 // Use of this source code is governed by a BSD-style license that can be |
| 1610 // found in the LICENSE file. |
| 1611 Polymer({ |
| 1612 is: 'history-router', |
| 1613 properties: { |
| 1614 selectedPage: { |
| 1615 type: String, |
| 1616 observer: 'serializePath_', |
| 1617 notify: true |
| 1618 }, |
| 1619 queryState: { |
| 1620 type: Object, |
| 1621 notify: true |
| 1622 }, |
| 1623 path_: { |
| 1624 type: String, |
| 1625 observer: 'pathChanged_' |
| 1626 }, |
| 1627 queryParams_: Object |
| 1628 }, |
| 1629 observers: [ 'queryParamsChanged_(queryParams_.*)', 'queryStateChanged_(queryS
tate.searchTerm)' ], |
| 1630 attached: function() { |
| 1631 if (window.location.hash) { |
| 1632 window.location.href = window.location.href.split('#')[0] + '?' + window.l
ocation.hash.substr(1); |
| 1633 } |
| 1634 }, |
| 1635 serializePath_: function() { |
| 1636 var page = this.selectedPage == 'history' ? '' : this.selectedPage; |
| 1637 this.path_ = '/' + page; |
| 1638 }, |
| 1639 pathChanged_: function() { |
| 1640 var sections = this.path_.substr(1).split('/'); |
| 1641 this.selectedPage = sections[0] || 'history'; |
| 1642 }, |
| 1643 queryParamsChanged_: function() { |
| 1644 this.set('queryState.searchTerm', this.queryParams_.q || ''); |
| 1645 }, |
| 1646 queryStateChanged_: function() { |
| 1647 this.set('queryParams_.q', this.queryState.searchTerm || null); |
| 1648 } |
| 1649 }); |
| 1650 |
| 1651 (function() { |
| 1652 'use strict'; |
| 1927 var KEY_IDENTIFIER = { | 1653 var KEY_IDENTIFIER = { |
| 1928 'U+0008': 'backspace', | 1654 'U+0008': 'backspace', |
| 1929 'U+0009': 'tab', | 1655 'U+0009': 'tab', |
| 1930 'U+001B': 'esc', | 1656 'U+001B': 'esc', |
| 1931 'U+0020': 'space', | 1657 'U+0020': 'space', |
| 1932 'U+007F': 'del' | 1658 'U+007F': 'del' |
| 1933 }; | 1659 }; |
| 1934 var KEY_CODE = { | 1660 var KEY_CODE = { |
| 1935 8: 'backspace', | 1661 8: 'backspace', |
| 1936 9: 'tab', | 1662 9: 'tab', |
| (...skipping 4152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6089 value: 0, | 5815 value: 0, |
| 6090 observer: 'changeToolbarView_' | 5816 observer: 'changeToolbarView_' |
| 6091 }, | 5817 }, |
| 6092 itemsSelected_: { | 5818 itemsSelected_: { |
| 6093 type: Boolean, | 5819 type: Boolean, |
| 6094 value: false, | 5820 value: false, |
| 6095 reflectToAttribute: true | 5821 reflectToAttribute: true |
| 6096 }, | 5822 }, |
| 6097 searchTerm: { | 5823 searchTerm: { |
| 6098 type: String, | 5824 type: String, |
| 5825 observer: 'searchTermChanged_', |
| 6099 notify: true | 5826 notify: true |
| 6100 }, | 5827 }, |
| 6101 spinnerActive: { | 5828 spinnerActive: { |
| 6102 type: Boolean, | 5829 type: Boolean, |
| 6103 value: false | 5830 value: false |
| 6104 }, | 5831 }, |
| 6105 hasDrawer: { | 5832 hasDrawer: { |
| 6106 type: Boolean, | 5833 type: Boolean, |
| 6107 observer: 'hasDrawerChanged_', | 5834 observer: 'hasDrawerChanged_', |
| 6108 reflectToAttribute: true | 5835 reflectToAttribute: true |
| 6109 }, | 5836 }, |
| 6110 showSyncNotice: Boolean, | 5837 showSyncNotice: Boolean, |
| 6111 isGroupedMode: { | 5838 isGroupedMode: { |
| 6112 type: Boolean, | 5839 type: Boolean, |
| 6113 reflectToAttribute: true | 5840 reflectToAttribute: true |
| 6114 }, | 5841 }, |
| 6115 groupedRange: { | 5842 groupedRange: { |
| 6116 type: Number, | 5843 type: Number, |
| 6117 value: 0, | 5844 value: 0, |
| 6118 reflectToAttribute: true, | 5845 reflectToAttribute: true, |
| 6119 notify: true | 5846 notify: true |
| 6120 }, | 5847 }, |
| 6121 queryStartTime: String, | 5848 queryStartTime: String, |
| 6122 queryEndTime: String | 5849 queryEndTime: String |
| 6123 }, | 5850 }, |
| 5851 get searchBar() { |
| 5852 return this.$['main-toolbar'].getSearchField(); |
| 5853 }, |
| 5854 showSearchField: function() { |
| 5855 this.searchBar.showAndFocus(); |
| 5856 }, |
| 6124 changeToolbarView_: function() { | 5857 changeToolbarView_: function() { |
| 6125 this.itemsSelected_ = this.count > 0; | 5858 this.itemsSelected_ = this.count > 0; |
| 6126 }, | 5859 }, |
| 6127 setSearchTerm: function(search) { | 5860 searchTermChanged_: function() { |
| 6128 if (this.searchTerm == search) return; | 5861 if (this.searchBar.getValue() != this.searchTerm) { |
| 6129 this.searchTerm = search; | 5862 this.searchBar.showAndFocus(); |
| 6130 var searchField = this.$['main-toolbar'].getSearchField(); | 5863 this.searchBar.setValue(this.searchTerm); |
| 6131 searchField.showAndFocus(); | 5864 } |
| 6132 searchField.setValue(search); | |
| 6133 }, | 5865 }, |
| 6134 onSearchChanged_: function(event) { | 5866 onSearchChanged_: function(event) { |
| 6135 this.searchTerm = event.detail; | 5867 this.searchTerm = event.detail; |
| 6136 }, | 5868 }, |
| 6137 onInfoButtonTap_: function() { | 5869 onInfoButtonTap_: function() { |
| 6138 var dropdown = this.$.syncNotice.get(); | 5870 var dropdown = this.$.syncNotice.get(); |
| 6139 dropdown.positionTarget = this.$$('#info-button-icon'); | 5871 dropdown.positionTarget = this.$$('#info-button-icon'); |
| 6140 if (dropdown.style.display == 'none') dropdown.open(); | 5872 if (dropdown.style.display == 'none') dropdown.open(); |
| 6141 }, | 5873 }, |
| 6142 onClearSelectionTap_: function() { | 5874 onClearSelectionTap_: function() { |
| 6143 this.fire('unselect-all'); | 5875 this.fire('unselect-all'); |
| 6144 }, | 5876 }, |
| 6145 onDeleteTap_: function() { | 5877 onDeleteTap_: function() { |
| 6146 this.fire('delete-selected'); | 5878 this.fire('delete-selected'); |
| 6147 }, | 5879 }, |
| 6148 get searchBar() { | |
| 6149 return this.$['main-toolbar'].getSearchField(); | |
| 6150 }, | |
| 6151 showSearchField: function() { | |
| 6152 this.$['main-toolbar'].getSearchField().showAndFocus(); | |
| 6153 }, | |
| 6154 deletingAllowed_: function() { | 5880 deletingAllowed_: function() { |
| 6155 return loadTimeData.getBoolean('allowDeletingHistory'); | 5881 return loadTimeData.getBoolean('allowDeletingHistory'); |
| 6156 }, | 5882 }, |
| 6157 numberOfItemsSelected_: function(count) { | 5883 numberOfItemsSelected_: function(count) { |
| 6158 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; | 5884 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; |
| 6159 }, | 5885 }, |
| 6160 getHistoryInterval_: function(queryStartTime, queryEndTime) { | 5886 getHistoryInterval_: function(queryStartTime, queryEndTime) { |
| 6161 return loadTimeData.getStringF('historyInterval', queryStartTime, queryEndTi
me); | 5887 return loadTimeData.getStringF('historyInterval', queryStartTime, queryEndTi
me); |
| 6162 }, | 5888 }, |
| 6163 hasDrawerChanged_: function() { | 5889 hasDrawerChanged_: function() { |
| (...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8284 properties: { | 8010 properties: { |
| 8285 selectedPage_: String, | 8011 selectedPage_: String, |
| 8286 grouped: Boolean, | 8012 grouped: Boolean, |
| 8287 groupedRange: { | 8013 groupedRange: { |
| 8288 type: Number, | 8014 type: Number, |
| 8289 observer: 'groupedRangeChanged_' | 8015 observer: 'groupedRangeChanged_' |
| 8290 }, | 8016 }, |
| 8291 queryState: Object, | 8017 queryState: Object, |
| 8292 queryResult: Object | 8018 queryResult: Object |
| 8293 }, | 8019 }, |
| 8020 observers: [ 'searchTermChanged_(queryState.searchTerm)' ], |
| 8294 listeners: { | 8021 listeners: { |
| 8295 'history-list-scrolled': 'closeMenu_', | 8022 'history-list-scrolled': 'closeMenu_', |
| 8296 'load-more-history': 'loadMoreHistory_', | 8023 'load-more-history': 'loadMoreHistory_', |
| 8297 'toggle-menu': 'toggleMenu_' | 8024 'toggle-menu': 'toggleMenu_' |
| 8298 }, | 8025 }, |
| 8299 historyResult: function(info, results) { | 8026 historyResult: function(info, results) { |
| 8300 this.initializeResults_(info, results); | 8027 this.initializeResults_(info, results); |
| 8301 this.closeMenu_(); | 8028 this.closeMenu_(); |
| 8302 if (this.selectedPage_ == 'grouped-list') { | 8029 if (this.selectedPage_ == 'grouped-list') { |
| 8303 this.$$('#grouped-list').historyData = results; | 8030 this.$$('#grouped-list').historyData = results; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8345 browserService.recordAction('RemoveSelected'); | 8072 browserService.recordAction('RemoveSelected'); |
| 8346 if (this.queryState.searchTerm != '') browserService.recordAction('SearchRes
ultRemove'); | 8073 if (this.queryState.searchTerm != '') browserService.recordAction('SearchRes
ultRemove'); |
| 8347 this.$.dialog.get().showModal(); | 8074 this.$.dialog.get().showModal(); |
| 8348 }, | 8075 }, |
| 8349 groupedRangeChanged_: function(range, oldRange) { | 8076 groupedRangeChanged_: function(range, oldRange) { |
| 8350 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 'infinite-list' : 'gro
uped-list'; | 8077 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 'infinite-list' : 'gro
uped-list'; |
| 8351 if (oldRange == undefined) return; | 8078 if (oldRange == undefined) return; |
| 8352 this.queryHistory(false); | 8079 this.queryHistory(false); |
| 8353 this.fire('history-view-changed'); | 8080 this.fire('history-view-changed'); |
| 8354 }, | 8081 }, |
| 8082 searchTermChanged_: function() { |
| 8083 this.queryHistory(false); |
| 8084 if (this.queryState.searchTerm) md_history.BrowserService.getInstance().reco
rdAction('Search'); |
| 8085 }, |
| 8355 loadMoreHistory_: function() { | 8086 loadMoreHistory_: function() { |
| 8356 this.queryHistory(true); | 8087 this.queryHistory(true); |
| 8357 }, | 8088 }, |
| 8358 initializeResults_: function(info, results) { | 8089 initializeResults_: function(info, results) { |
| 8359 if (results.length == 0) return; | 8090 if (results.length == 0) return; |
| 8360 var currentDate = results[0].dateRelativeDay; | 8091 var currentDate = results[0].dateRelativeDay; |
| 8361 for (var i = 0; i < results.length; i++) { | 8092 for (var i = 0; i < results.length; i++) { |
| 8362 results[i].selected = false; | 8093 results[i].selected = false; |
| 8363 results[i].readableTimestamp = info.term == '' ? results[i].dateTimeOfDay
: results[i].dateShort; | 8094 results[i].readableTimestamp = info.term == '' ? results[i].dateTimeOfDay
: results[i].dateShort; |
| 8364 if (results[i].dateRelativeDay != currentDate) { | 8095 if (results[i].dateRelativeDay != currentDate) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 8382 if (menu) menu.closeMenu(); | 8113 if (menu) menu.closeMenu(); |
| 8383 }, | 8114 }, |
| 8384 toggleMenu_: function(e) { | 8115 toggleMenu_: function(e) { |
| 8385 var target = e.detail.target; | 8116 var target = e.detail.target; |
| 8386 var menu = this.$.sharedMenu.get(); | 8117 var menu = this.$.sharedMenu.get(); |
| 8387 menu.toggleMenu(target, e.detail); | 8118 menu.toggleMenu(target, e.detail); |
| 8388 }, | 8119 }, |
| 8389 onMoreFromSiteTap_: function() { | 8120 onMoreFromSiteTap_: function() { |
| 8390 md_history.BrowserService.getInstance().recordAction('EntryMenuShowMoreFromS
ite'); | 8121 md_history.BrowserService.getInstance().recordAction('EntryMenuShowMoreFromS
ite'); |
| 8391 var menu = assert(this.$.sharedMenu.getIfExists()); | 8122 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 8392 this.fire('search-domain', { | 8123 this.set('queryState.searchTerm', menu.itemData.item.domain); |
| 8393 domain: menu.itemData.item.domain | |
| 8394 }); | |
| 8395 menu.closeMenu(); | 8124 menu.closeMenu(); |
| 8396 }, | 8125 }, |
| 8397 onRemoveFromHistoryTap_: function() { | 8126 onRemoveFromHistoryTap_: function() { |
| 8398 var browserService = md_history.BrowserService.getInstance(); | 8127 var browserService = md_history.BrowserService.getInstance(); |
| 8399 browserService.recordAction('EntryMenuRemoveFromHistory'); | 8128 browserService.recordAction('EntryMenuRemoveFromHistory'); |
| 8400 var menu = assert(this.$.sharedMenu.getIfExists()); | 8129 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 8401 var itemData = menu.itemData; | 8130 var itemData = menu.itemData; |
| 8402 browserService.deleteItems([ itemData.item ]).then(function(items) { | 8131 browserService.deleteItems([ itemData.item ]).then(function(items) { |
| 8403 this.getSelectedList_().removeItemsByPath([ itemData.path ]); | 8132 this.getSelectedList_().removeItemsByPath([ itemData.path ]); |
| 8404 this.fire('unselect-all'); | 8133 this.fire('unselect-all'); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8656 // Use of this source code is governed by a BSD-style license that can be | 8385 // Use of this source code is governed by a BSD-style license that can be |
| 8657 // found in the LICENSE file. | 8386 // found in the LICENSE file. |
| 8658 Polymer({ | 8387 Polymer({ |
| 8659 is: 'history-side-bar', | 8388 is: 'history-side-bar', |
| 8660 behaviors: [ Polymer.IronA11yKeysBehavior ], | 8389 behaviors: [ Polymer.IronA11yKeysBehavior ], |
| 8661 properties: { | 8390 properties: { |
| 8662 selectedPage: { | 8391 selectedPage: { |
| 8663 type: String, | 8392 type: String, |
| 8664 notify: true | 8393 notify: true |
| 8665 }, | 8394 }, |
| 8666 route: Object, | |
| 8667 showFooter: Boolean, | 8395 showFooter: Boolean, |
| 8668 drawer: { | 8396 drawer: { |
| 8669 type: Boolean, | 8397 type: Boolean, |
| 8670 reflectToAttribute: true | 8398 reflectToAttribute: true |
| 8671 } | 8399 } |
| 8672 }, | 8400 }, |
| 8673 keyBindings: { | 8401 keyBindings: { |
| 8674 'space:keydown': 'onSpacePressed_' | 8402 'space:keydown': 'onSpacePressed_' |
| 8675 }, | 8403 }, |
| 8676 onSpacePressed_: function(e) { | 8404 onSpacePressed_: function(e) { |
| 8677 e.detail.keyboardEvent.path[0].click(); | 8405 e.detail.keyboardEvent.path[0].click(); |
| 8678 }, | 8406 }, |
| 8679 onSelectorActivate_: function() { | 8407 onSelectorActivate_: function() { |
| 8680 this.fire('history-close-drawer'); | 8408 this.fire('history-close-drawer'); |
| 8681 }, | 8409 }, |
| 8682 onClearBrowsingDataTap_: function(e) { | 8410 onClearBrowsingDataTap_: function(e) { |
| 8683 var browserService = md_history.BrowserService.getInstance(); | 8411 var browserService = md_history.BrowserService.getInstance(); |
| 8684 browserService.recordAction('InitClearBrowsingData'); | 8412 browserService.recordAction('InitClearBrowsingData'); |
| 8685 browserService.openClearBrowsingData(); | 8413 browserService.openClearBrowsingData(); |
| 8686 this.$['cbd-ripple'].upAction(); | 8414 this.$['cbd-ripple'].upAction(); |
| 8687 e.preventDefault(); | 8415 e.preventDefault(); |
| 8688 }, | 8416 }, |
| 8689 getQueryString_: function(route) { | 8417 onItemClick_: function(e) { |
| 8690 return window.location.search; | 8418 e.preventDefault(); |
| 8691 } | 8419 } |
| 8692 }); | 8420 }); |
| 8693 | 8421 |
| 8694 // Copyright 2016 The Chromium Authors. All rights reserved. | 8422 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 8695 // Use of this source code is governed by a BSD-style license that can be | 8423 // Use of this source code is governed by a BSD-style license that can be |
| 8696 // found in the LICENSE file. | 8424 // found in the LICENSE file. |
| 8697 Polymer({ | 8425 Polymer({ |
| 8698 is: 'history-app', | 8426 is: 'history-app', |
| 8699 behaviors: [ Polymer.IronScrollTargetBehavior ], | 8427 behaviors: [ Polymer.IronScrollTargetBehavior ], |
| 8700 properties: { | 8428 properties: { |
| 8701 showSidebarFooter: Boolean, | 8429 showSidebarFooter: Boolean, |
| 8702 hasSyncedResults: Boolean, | 8430 hasSyncedResults: Boolean, |
| 8703 selectedPage_: { | 8431 selectedPage_: { |
| 8704 type: String, | 8432 type: String, |
| 8705 observer: 'unselectAll' | 8433 observer: 'selectedPageChanged_' |
| 8706 }, | 8434 }, |
| 8707 grouped_: { | 8435 grouped_: { |
| 8708 type: Boolean, | 8436 type: Boolean, |
| 8709 reflectToAttribute: true | 8437 reflectToAttribute: true |
| 8710 }, | 8438 }, |
| 8711 queryState_: { | 8439 queryState_: { |
| 8712 type: Object, | 8440 type: Object, |
| 8713 value: function() { | 8441 value: function() { |
| 8714 return { | 8442 return { |
| 8715 incremental: false, | 8443 incremental: false, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8730 queryResult_: { | 8458 queryResult_: { |
| 8731 type: Object, | 8459 type: Object, |
| 8732 value: function() { | 8460 value: function() { |
| 8733 return { | 8461 return { |
| 8734 info: null, | 8462 info: null, |
| 8735 results: null, | 8463 results: null, |
| 8736 sessionList: null | 8464 sessionList: null |
| 8737 }; | 8465 }; |
| 8738 } | 8466 } |
| 8739 }, | 8467 }, |
| 8740 routeData_: Object, | |
| 8741 queryParams_: Object, | |
| 8742 hasDrawer_: Boolean, | 8468 hasDrawer_: Boolean, |
| 8743 isUserSignedIn_: { | 8469 isUserSignedIn_: { |
| 8744 type: Boolean, | 8470 type: Boolean, |
| 8745 value: loadTimeData.getBoolean('isUserSignedIn') | 8471 value: loadTimeData.getBoolean('isUserSignedIn') |
| 8746 }, | 8472 }, |
| 8747 toolbarShadow_: { | 8473 toolbarShadow_: { |
| 8748 type: Boolean, | 8474 type: Boolean, |
| 8749 reflectToAttribute: true, | 8475 reflectToAttribute: true, |
| 8750 notify: true | 8476 notify: true |
| 8751 } | 8477 } |
| 8752 }, | 8478 }, |
| 8753 observers: [ 'routeDataChanged_(routeData_.page)', 'selectedPageChanged_(selec
tedPage_)', 'searchTermChanged_(queryState_.searchTerm)', 'searchQueryParamChang
ed_(queryParams_.q)' ], | |
| 8754 listeners: { | 8479 listeners: { |
| 8755 'cr-menu-tap': 'onMenuTap_', | 8480 'cr-menu-tap': 'onMenuTap_', |
| 8756 'history-checkbox-select': 'checkboxSelected', | 8481 'history-checkbox-select': 'checkboxSelected', |
| 8757 'unselect-all': 'unselectAll', | 8482 'unselect-all': 'unselectAll', |
| 8758 'delete-selected': 'deleteSelected', | 8483 'delete-selected': 'deleteSelected', |
| 8759 'search-domain': 'searchDomain_', | 8484 'search-domain': 'searchDomain_', |
| 8760 'history-close-drawer': 'closeDrawer_', | 8485 'history-close-drawer': 'closeDrawer_', |
| 8761 'history-view-changed': 'historyViewChanged_' | 8486 'history-view-changed': 'historyViewChanged_' |
| 8762 }, | 8487 }, |
| 8763 ready: function() { | 8488 ready: function() { |
| 8764 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); | 8489 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); |
| 8765 cr.ui.decorate('command', cr.ui.Command); | 8490 cr.ui.decorate('command', cr.ui.Command); |
| 8766 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 8491 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
| 8767 document.addEventListener('command', this.onCommand_.bind(this)); | 8492 document.addEventListener('command', this.onCommand_.bind(this)); |
| 8768 if (window.location.hash) { | |
| 8769 window.location.href = window.location.href.split('#')[0] + '?' + window.l
ocation.hash.substr(1); | |
| 8770 } | |
| 8771 }, | 8493 }, |
| 8772 onFirstRender: function() { | 8494 onFirstRender: function() { |
| 8773 requestAnimationFrame(function() { | 8495 requestAnimationFrame(function() { |
| 8774 chrome.send('metricsHandler:recordTime', [ 'History.ResultsRenderedTime',
window.performance.now() ]); | 8496 chrome.send('metricsHandler:recordTime', [ 'History.ResultsRenderedTime',
window.performance.now() ]); |
| 8775 }); | 8497 }); |
| 8776 if (!this.hasDrawer_) { | 8498 if (!this.hasDrawer_) { |
| 8777 this.focusToolbarSearchField(); | 8499 this.focusToolbarSearchField(); |
| 8778 } | 8500 } |
| 8779 }, | 8501 }, |
| 8780 _scrollHandler: function() { | 8502 _scrollHandler: function() { |
| 8781 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0; | 8503 if (this.scrollTarget) this.toolbarShadow_ = this.scrollTarget.scrollTop !=
0; |
| 8782 }, | 8504 }, |
| 8783 onMenuTap_: function() { | 8505 onMenuTap_: function() { |
| 8784 var drawer = this.$$('#drawer'); | 8506 var drawer = this.$$('#drawer'); |
| 8785 if (drawer) drawer.toggle(); | 8507 if (drawer) drawer.toggle(); |
| 8786 }, | 8508 }, |
| 8787 checkboxSelected: function(e) { | 8509 checkboxSelected: function(e) { |
| 8788 var toolbar = this.$.toolbar; | 8510 var toolbar = this.$.toolbar; |
| 8789 toolbar.count = this.$.history.getSelectedItemCount(); | 8511 toolbar.count = this.$.history.getSelectedItemCount(); |
| 8790 }, | 8512 }, |
| 8791 unselectAll: function() { | 8513 unselectAll: function() { |
| 8792 var listContainer = this.$.history; | 8514 var listContainer = this.$.history; |
| 8793 var toolbar = this.$.toolbar; | 8515 var toolbar = this.$.toolbar; |
| 8794 listContainer.unselectAllItems(toolbar.count); | 8516 listContainer.unselectAllItems(toolbar.count); |
| 8795 toolbar.count = 0; | 8517 toolbar.count = 0; |
| 8796 }, | 8518 }, |
| 8797 deleteSelected: function() { | 8519 deleteSelected: function() { |
| 8798 this.$.history.deleteSelectedWithPrompt(); | 8520 this.$.history.deleteSelectedWithPrompt(); |
| 8799 }, | 8521 }, |
| 8800 historyResult: function(info, results) { | 8522 historyResult: function(info, results) { |
| 8801 this.set('queryState_.querying', false); | 8523 this.set('queryState_.querying', false); |
| 8802 this.set('queryResult_.info', info); | 8524 this.set('queryResult_.info', info); |
| 8803 this.set('queryResult_.results', results); | 8525 this.set('queryResult_.results', results); |
| 8804 var listContainer = this.$['history']; | 8526 var listContainer = this.$['history']; |
| 8805 listContainer.historyResult(info, results); | 8527 listContainer.historyResult(info, results); |
| 8806 }, | 8528 }, |
| 8807 focusToolbarSearchField: function() { | 8529 focusToolbarSearchField: function() { |
| 8808 this.$.toolbar.showSearchField(); | 8530 this.$.toolbar.showSearchField(); |
| 8809 }, | 8531 }, |
| 8810 searchDomain_: function(e) { | |
| 8811 this.$.toolbar.setSearchTerm(e.detail.domain); | |
| 8812 }, | |
| 8813 onCanExecute_: function(e) { | 8532 onCanExecute_: function(e) { |
| 8814 e = e; | 8533 e = e; |
| 8815 switch (e.command.id) { | 8534 switch (e.command.id) { |
| 8816 case 'find-command': | 8535 case 'find-command': |
| 8817 e.canExecute = true; | 8536 e.canExecute = true; |
| 8818 break; | 8537 break; |
| 8819 | 8538 |
| 8820 case 'slash-command': | 8539 case 'slash-command': |
| 8821 e.canExecute = !this.$.toolbar.searchBar.isSearchFocused(); | 8540 e.canExecute = !this.$.toolbar.searchBar.isSearchFocused(); |
| 8822 break; | 8541 break; |
| 8823 | 8542 |
| 8824 case 'delete-command': | 8543 case 'delete-command': |
| 8825 e.canExecute = this.$.toolbar.count > 0; | 8544 e.canExecute = this.$.toolbar.count > 0; |
| 8826 break; | 8545 break; |
| 8827 } | 8546 } |
| 8828 }, | 8547 }, |
| 8829 searchTermChanged_: function(searchTerm) { | |
| 8830 this.set('queryParams_.q', searchTerm || null); | |
| 8831 this.$['history'].queryHistory(false); | |
| 8832 if (this.queryState_.searchTerm) md_history.BrowserService.getInstance().rec
ordAction('Search'); | |
| 8833 }, | |
| 8834 searchQueryParamChanged_: function(searchQuery) { | |
| 8835 this.$.toolbar.setSearchTerm(searchQuery || ''); | |
| 8836 }, | |
| 8837 onCommand_: function(e) { | 8548 onCommand_: function(e) { |
| 8838 if (e.command.id == 'find-command' || e.command.id == 'slash-command') this.
focusToolbarSearchField(); | 8549 if (e.command.id == 'find-command' || e.command.id == 'slash-command') this.
focusToolbarSearchField(); |
| 8839 if (e.command.id == 'delete-command') this.deleteSelected(); | 8550 if (e.command.id == 'delete-command') this.deleteSelected(); |
| 8840 }, | 8551 }, |
| 8841 setForeignSessions: function(sessionList, isTabSyncEnabled) { | 8552 setForeignSessions: function(sessionList, isTabSyncEnabled) { |
| 8842 if (!isTabSyncEnabled) { | 8553 if (!isTabSyncEnabled) { |
| 8843 var syncedDeviceManagerElem = this.$$('history-synced-device-manager'); | 8554 var syncedDeviceManagerElem = this.$$('history-synced-device-manager'); |
| 8844 if (syncedDeviceManagerElem) syncedDeviceManagerElem.tabSyncDisabled(); | 8555 if (syncedDeviceManagerElem) syncedDeviceManagerElem.tabSyncDisabled(); |
| 8845 return; | 8556 return; |
| 8846 } | 8557 } |
| 8847 this.set('queryResult_.sessionList', sessionList); | 8558 this.set('queryResult_.sessionList', sessionList); |
| 8848 }, | 8559 }, |
| 8849 historyDeleted: function() { | 8560 historyDeleted: function() { |
| 8850 this.$.history.historyDeleted(); | 8561 this.$.history.historyDeleted(); |
| 8851 }, | 8562 }, |
| 8852 updateSignInState: function(isUserSignedIn) { | 8563 updateSignInState: function(isUserSignedIn) { |
| 8853 this.isUserSignedIn_ = isUserSignedIn; | 8564 this.isUserSignedIn_ = isUserSignedIn; |
| 8854 }, | 8565 }, |
| 8855 syncedTabsSelected_: function(selectedPage) { | 8566 syncedTabsSelected_: function(selectedPage) { |
| 8856 return selectedPage == 'syncedTabs'; | 8567 return selectedPage == 'syncedTabs'; |
| 8857 }, | 8568 }, |
| 8858 shouldShowSpinner_: function(querying, incremental, searchTerm) { | 8569 shouldShowSpinner_: function(querying, incremental, searchTerm) { |
| 8859 return querying && !incremental && searchTerm != ''; | 8570 return querying && !incremental && searchTerm != ''; |
| 8860 }, | 8571 }, |
| 8861 showSyncNotice_: function(hasSyncedResults, selectedPage) { | 8572 showSyncNotice_: function(hasSyncedResults, selectedPage) { |
| 8862 return hasSyncedResults && selectedPage != 'syncedTabs'; | 8573 return hasSyncedResults && selectedPage != 'syncedTabs'; |
| 8863 }, | 8574 }, |
| 8864 routeDataChanged_: function(page) { | 8575 selectedPageChanged_: function() { |
| 8865 this.selectedPage_ = page; | 8576 this.unselectAll(); |
| 8866 }, | |
| 8867 selectedPageChanged_: function(selectedPage) { | |
| 8868 this.set('routeData_.page', selectedPage); | |
| 8869 this.historyViewChanged_(); | 8577 this.historyViewChanged_(); |
| 8870 }, | 8578 }, |
| 8871 historyViewChanged_: function() { | 8579 historyViewChanged_: function() { |
| 8872 requestAnimationFrame(function() { | 8580 requestAnimationFrame(function() { |
| 8873 this.scrollTarget = this.$.content.selectedItem.getContentScrollTarget(); | 8581 if (this.$.content.selectedItem) { |
| 8874 this._scrollHandler(); | 8582 this.scrollTarget = this.$.content.selectedItem.getContentScrollTarget()
; |
| 8583 this._scrollHandler(); |
| 8584 } |
| 8875 }.bind(this)); | 8585 }.bind(this)); |
| 8876 this.recordHistoryPageView_(); | 8586 this.recordHistoryPageView_(); |
| 8877 }, | 8587 }, |
| 8878 getSelectedPage_: function(selectedPage, items) { | 8588 getSelectedPage_: function(selectedPage, items) { |
| 8879 return selectedPage; | 8589 return selectedPage; |
| 8880 }, | 8590 }, |
| 8881 closeDrawer_: function() { | 8591 closeDrawer_: function() { |
| 8882 var drawer = this.$$('#drawer'); | 8592 var drawer = this.$$('#drawer'); |
| 8883 if (drawer) drawer.close(); | 8593 if (drawer) drawer.close(); |
| 8884 }, | 8594 }, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 8901 | 8611 |
| 8902 case HistoryRange.MONTH: | 8612 case HistoryRange.MONTH: |
| 8903 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; | 8613 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; |
| 8904 break; | 8614 break; |
| 8905 } | 8615 } |
| 8906 break; | 8616 break; |
| 8907 } | 8617 } |
| 8908 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage
View', histogramValue, HistoryPageViewHistogram.END); | 8618 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage
View', histogramValue, HistoryPageViewHistogram.END); |
| 8909 } | 8619 } |
| 8910 }); | 8620 }); |
| OLD | NEW |