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

Side by Side Diff: chrome/browser/resources/options/route.js

Issue 2236213002: Add quick unlock Settings in options page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try to fix browser tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 //
5 // TODO(xiaoyinh@): This file is mostly a copy of
6 // chrome/browser/resources/settings/route.js. And it is used to integrate
7 // with the polymer elements in settings.
8 // It should be removed once we don't need to support options.
9 // I add a copy in options instead of import it directly from settings
jdufault 2016/08/15 19:21:18 Can we avoid loading the polymer elements until af
xiaoyinh(OOO Sep 11-29) 2016/08/16 17:33:43 Thanks Jacob! Could you take a look at route_stub.
10 // because this file initializes the route from the URL, and return to
11 // basic path if a valid route is not found. This will make a lot of
12 // options URL not usable anymore, so I removed the logic in here.
4 13
5 cr.define('settings', function() { 14 cr.define('settings', function() {
6 /** 15 /**
7 * Class for navigable routes. May only be instantiated within this file. 16 * Class for navigable routes. May only be instantiated within this file.
8 * @constructor 17 * @constructor
9 * @param {string} path 18 * @param {string} path
10 * @private 19 * @private
11 */ 20 */
12 var Route = function(path) { 21 var Route = function(path) {
13 this.path = path; 22 this.path = path;
14 23
15 /** @type {?settings.Route} */ 24 /** @type {?settings.Route} */
16 this.parent = null; 25 this.parent = null;
17 26
18 // Below are all legacy properties to provide compatibility with the old 27 // Below are all legacy properties to provide compatibility with the old
19 // routing system. TODO(tommycli): Remove once routing refactor complete. 28 // routing system. TODO(tommycli): Remove once routing refactor complete.
20 this.section = ''; 29 this.section = '';
30 /** @type {!Array<string>} */ this.subpage = [];
21 }; 31 };
22 32
23 Route.prototype = { 33 Route.prototype = {
24 /** 34 /**
25 * Returns a new Route instance that's a child of this route. 35 * Returns a new Route instance that's a child of this route.
26 * @param {string} path Extends this route's path if it doesn't contain a 36 * @param {string} path Extends this route's path if it doesn't contain a
27 * leading slash. 37 * leading slash.
38 * @param {string=} opt_subpageName
28 * @return {!settings.Route} 39 * @return {!settings.Route}
29 * @private 40 * @private
30 */ 41 */
31 createChild: function(path) { 42 createChild: function(path, opt_subpageName) {
32 assert(path); 43 assert(path);
33 44
34 // |path| extends this route's path if it doesn't have a leading slash. 45 // |path| extends this route's path if it doesn't have a leading slash.
35 // If it does have a leading slash, it's just set as the new route's URL. 46 // If it does have a leading slash, it's just set as the new route's URL.
36 var newUrl = path[0] == '/' ? path : this.path + '/' + path; 47 var newUrl = path[0] == '/' ? path : this.path + '/' + path;
37 48
38 var route = new Route(newUrl); 49 var route = new Route(newUrl);
39 route.parent = this; 50 route.parent = this;
40 route.section = this.section; 51 route.section = this.section;
52 route.subpage = this.subpage.slice(); // Shallow copy.
41 53
54 if (opt_subpageName)
55 route.subpage.push(opt_subpageName);
56
57 return route;
58 },
59
60 /**
61 * Returns a new Route instance that's a child dialog of this route.
62 * @param {string} path
63 * @param {string} dialogName
64 * @return {!settings.Route}
65 * @private
66 */
67 createDialog: function(path, dialogName) {
68 var route = this.createChild(path);
69 route.dialog = dialogName;
42 return route; 70 return route;
43 }, 71 },
44 72
45 /** 73 /**
46 * Returns a new Route instance that's a child section of this route. 74 * Returns a new Route instance that's a child section of this route.
47 * TODO(tommycli): Remove once we've obsoleted the concept of sections. 75 * TODO(tommycli): Remove once we've obsoleted the concept of sections.
48 * @param {string} path 76 * @param {string} path
49 * @param {string} section 77 * @param {string} section
50 * @return {!settings.Route} 78 * @return {!settings.Route}
51 * @private 79 * @private
52 */ 80 */
53 createSection: function(path, section) { 81 createSection: function(path, section) {
54 var route = this.createChild(path); 82 var route = this.createChild(path);
55 route.section = section; 83 route.section = section;
56 return route; 84 return route;
57 }, 85 },
58 86
59 /** 87 /**
60 * Returns true if this route matches or is an ancestor of the parameter. 88 * Returns true if this route matches or is an ancestor of the parameter.
61 * @param {!settings.Route} route 89 * @param {!settings.Route} route
62 * @return {boolean} 90 * @return {boolean}
63 */ 91 */
64 contains: function(route) { 92 contains: function(route) {
65 for (var r = route; r != null; r = r.parent) { 93 for (var r = route; r != null; r = r.parent) {
66 if (this == r) 94 if (this == r)
67 return true; 95 return true;
68 } 96 }
69 return false; 97 return false;
70 }, 98 },
71
72 /**
73 * Returns true if this route is a subpage of a section.
74 * @return {boolean}
75 */
76 isSubpage: function() {
77 return !!this.parent && this.parent.section == this.section;
78 },
79 }; 99 };
80 100
81 // Abbreviated variable for easier definitions. 101 // Abbreviated variable for easier definitions.
82 var r = Route; 102 var r = Route;
83 103
84 // Root pages. 104 // Root pages.
85 r.BASIC = new Route('/'); 105 r.BASIC = new Route('/');
86 r.ADVANCED = new Route('/advanced'); 106 r.ADVANCED = new Route('/advanced');
87 r.ABOUT = new Route('/help'); 107 r.ABOUT = new Route('/help');
88 108
89 <if expr="chromeos"> 109 <if expr="chromeos">
90 r.INTERNET = r.BASIC.createSection('/internet', 'internet'); 110 r.INTERNET = r.BASIC.createSection('/internet', 'internet');
91 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail'); 111 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail', 'network-detail');
92 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks'); 112 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks', 'known-networks');
93 </if> 113 </if>
94 114
95 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance'); 115 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance');
96 r.FONTS = r.APPEARANCE.createChild('/fonts'); 116 r.FONTS = r.APPEARANCE.createChild('/fonts', 'appearance-fonts');
97 117
98 r.DEFAULT_BROWSER = 118 r.DEFAULT_BROWSER =
99 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser'); 119 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser');
100 120
101 r.SEARCH = r.BASIC.createSection('/search', 'search'); 121 r.SEARCH = r.BASIC.createSection('/search', 'search');
102 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines'); 122 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines', 'search-engines');
103 123
104 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup'); 124 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup');
105 125
106 r.PEOPLE = r.BASIC.createSection('/people', 'people'); 126 r.PEOPLE = r.BASIC.createSection('/people', 'people');
107 r.SYNC = r.PEOPLE.createChild('/syncSetup'); 127 r.SYNC = r.PEOPLE.createChild('/syncSetup', 'sync');
108 <if expr="not chromeos"> 128 <if expr="not chromeos">
109 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile'); 129 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile', 'manageProfile');
110 </if> 130 </if>
111 <if expr="chromeos"> 131 <if expr="chromeos">
112 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture'); 132 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture', 'changePicture');
113 r.ACCOUNTS = r.PEOPLE.createChild('/accounts'); 133 r.ACCOUNTS = r.PEOPLE.createChild('/accounts', 'users');
114 r.LOCK_SCREEN = r.PEOPLE.createChild('/lockScreen'); 134 r.LOCK_SCREEN = r.PEOPLE.createChild('/lockScreen', 'lockScreen');
135 r.SETUP_PIN = r.LOCK_SCREEN.createDialog('/setupPin', 'setupPin');
115 136
116 r.DEVICE = r.BASIC.createSection('/device', 'device'); 137 r.DEVICE = r.BASIC.createSection('/device', 'device');
117 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); 138 r.POINTERS = r.DEVICE.createChild('/pointer-overlay', 'pointers');
118 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); 139 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay', 'keyboard');
119 r.DISPLAY = r.DEVICE.createChild('/display'); 140 r.DISPLAY = r.DEVICE.createChild('/display', 'display');
120 r.NOTES = r.DEVICE.createChild('/note'); 141 r.NOTES = r.DEVICE.createChild('/note', 'note');
121 </if> 142 </if>
122 143
123 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); 144 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy');
124 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); 145 r.CERTIFICATES =
146 r.PRIVACY.createChild('/certificates', 'manage-certificates');
147 r.CLEAR_BROWSER_DATA =
148 r.PRIVACY.createDialog('/clearBrowserData', 'clear-browsing-data');
149 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings', 'site-settings');
150 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all', 'all-sites');
151 r.SITE_SETTINGS_ALL_DETAILS =
152 r.SITE_SETTINGS_ALL.createChild('details', 'site-details');
125 153
126 // CLEAR_BROWSER_DATA is the only navigable dialog route. It's the only child 154 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild(
127 // of a section that's not a subpage. Don't add any more routes like these. 155 'handlers', 'protocol-handlers');
128 // If more navigable dialogs are needed, add explicit support in Route.
129 r.CLEAR_BROWSER_DATA = r.PRIVACY.createChild('/clearBrowserData');
130 r.CLEAR_BROWSER_DATA.isSubpage = function() { return false; };
131 156
132 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings'); 157 // TODO(tommicli): Find a way to refactor these repetitive category routes.
133 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); 158 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = r.SITE_SETTINGS.createChild(
134 r.SITE_SETTINGS_ALL_DETAILS = r.SITE_SETTINGS_ALL.createChild('details'); 159 'automaticDownloads', 'site-settings-category-automatic-downloads');
135 160 r.SITE_SETTINGS_BACKGROUND_SYNC = r.SITE_SETTINGS.createChild(
136 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('handlers'); 161 'backgroundSync', 'site-settings-category-background-sync');
137 162 r.SITE_SETTINGS_CAMERA = r.SITE_SETTINGS.createChild(
138 // TODO(tommycli): Find a way to refactor these repetitive category routes. 163 'camera', 'site-settings-category-camera');
139 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = 164 r.SITE_SETTINGS_COOKIES = r.SITE_SETTINGS.createChild(
140 r.SITE_SETTINGS.createChild('automaticDownloads'); 165 'cookies', 'site-settings-category-cookies');
141 r.SITE_SETTINGS_BACKGROUND_SYNC = 166 r.SITE_SETTINGS_IMAGES = r.SITE_SETTINGS.createChild(
142 r.SITE_SETTINGS.createChild('backgroundSync'); 167 'images', 'site-settings-category-images');
143 r.SITE_SETTINGS_CAMERA = r.SITE_SETTINGS.createChild('camera'); 168 r.SITE_SETTINGS_JAVASCRIPT = r.SITE_SETTINGS.createChild(
144 r.SITE_SETTINGS_COOKIES = r.SITE_SETTINGS.createChild('cookies'); 169 'javascript', 'site-settings-category-javascript');
145 r.SITE_SETTINGS_IMAGES = r.SITE_SETTINGS.createChild('images'); 170 r.SITE_SETTINGS_KEYGEN = r.SITE_SETTINGS.createChild(
146 r.SITE_SETTINGS_JAVASCRIPT = r.SITE_SETTINGS.createChild('javascript'); 171 'keygen', 'site-settings-category-keygen');
147 r.SITE_SETTINGS_KEYGEN = r.SITE_SETTINGS.createChild('keygen'); 172 r.SITE_SETTINGS_LOCATION = r.SITE_SETTINGS.createChild(
148 r.SITE_SETTINGS_LOCATION = r.SITE_SETTINGS.createChild('location'); 173 'location', 'site-settings-category-location');
149 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild('microphone'); 174 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild(
150 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild('notifications'); 175 'microphone', 'site-settings-category-microphone');
151 r.SITE_SETTINGS_PLUGINS = r.SITE_SETTINGS.createChild('plugins'); 176 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild(
152 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); 177 'notifications', 'site-settings-category-notifications');
153 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = 178 r.SITE_SETTINGS_PLUGINS = r.SITE_SETTINGS.createChild(
154 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); 179 'plugins', 'site-settings-category-plugins');
180 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild(
181 'popups', 'site-settings-category-popups');
182 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = r.SITE_SETTINGS.createChild(
183 'unsandboxedPlugins', 'site-settings-category-unsandboxed-plugins');
155 184
156 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS_DETAILS = 185 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS_DETAILS =
157 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS.createChild('details'); 186 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS.createChild('details',
187 'site-details');
158 r.SITE_SETTINGS_BACKGROUND_SYNC_DETAILS = 188 r.SITE_SETTINGS_BACKGROUND_SYNC_DETAILS =
159 r.SITE_SETTINGS_BACKGROUND_SYNC.createChild('details'); 189 r.SITE_SETTINGS_BACKGROUND_SYNC.createChild('details', 'site-details');
160 r.SITE_SETTINGS_CAMERA_DETAILS = 190 r.SITE_SETTINGS_CAMERA_DETAILS =
161 r.SITE_SETTINGS_CAMERA.createChild('details'); 191 r.SITE_SETTINGS_CAMERA.createChild('details', 'site-details');
162 r.SITE_SETTINGS_COOKIES_DETAILS = 192 r.SITE_SETTINGS_COOKIES_DETAILS =
163 r.SITE_SETTINGS_COOKIES.createChild('details'); 193 r.SITE_SETTINGS_COOKIES.createChild('details', 'site-details');
164 r.SITE_SETTINGS_IMAGES_DETAILS = 194 r.SITE_SETTINGS_IMAGES_DETAILS =
165 r.SITE_SETTINGS_IMAGES.createChild('details'); 195 r.SITE_SETTINGS_IMAGES.createChild('details', 'site-details');
166 r.SITE_SETTINGS_JAVASCRIPT_DETAILS = 196 r.SITE_SETTINGS_JAVASCRIPT_DETAILS =
167 r.SITE_SETTINGS_JAVASCRIPT.createChild('details'); 197 r.SITE_SETTINGS_JAVASCRIPT.createChild('details', 'site-details');
168 r.SITE_SETTINGS_KEYGEN_DETAILS = 198 r.SITE_SETTINGS_KEYGEN_DETAILS =
169 r.SITE_SETTINGS_KEYGEN.createChild('details'); 199 r.SITE_SETTINGS_KEYGEN.createChild('details', 'site-details');
170 r.SITE_SETTINGS_LOCATION_DETAILS = 200 r.SITE_SETTINGS_LOCATION_DETAILS =
171 r.SITE_SETTINGS_LOCATION.createChild('details'); 201 r.SITE_SETTINGS_LOCATION.createChild('details', 'site-details');
172 r.SITE_SETTINGS_MICROPHONE_DETAILS = 202 r.SITE_SETTINGS_MICROPHONE_DETAILS =
173 r.SITE_SETTINGS_MICROPHONE.createChild('details'); 203 r.SITE_SETTINGS_MICROPHONE.createChild('details', 'site-details');
174 r.SITE_SETTINGS_NOTIFICATIONS_DETAILS = 204 r.SITE_SETTINGS_NOTIFICATIONS_DETAILS =
175 r.SITE_SETTINGS_NOTIFICATIONS.createChild('details'); 205 r.SITE_SETTINGS_NOTIFICATIONS.createChild('details', 'site-details');
176 r.SITE_SETTINGS_PLUGINS_DETAILS = 206 r.SITE_SETTINGS_PLUGINS_DETAILS =
177 r.SITE_SETTINGS_PLUGINS.createChild('details'); 207 r.SITE_SETTINGS_PLUGINS.createChild('details', 'site-details');
178 r.SITE_SETTINGS_POPUPS_DETAILS = 208 r.SITE_SETTINGS_POPUPS_DETAILS =
179 r.SITE_SETTINGS_POPUPS.createChild('details'); 209 r.SITE_SETTINGS_POPUPS.createChild('details', 'site-details');
180 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS_DETAILS = 210 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS_DETAILS =
181 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS.createChild('details'); 211 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS.createChild('details',
212 'site-details');
182 213
183 <if expr="chromeos"> 214 <if expr="chromeos">
184 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); 215 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime');
185 216
186 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth'); 217 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth');
187 r.BLUETOOTH_ADD_DEVICE = r.BLUETOOTH.createChild('/bluetoothAddDevice'); 218 r.BLUETOOTH_ADD_DEVICE =
188 r.BLUETOOTH_PAIR_DEVICE = 219 r.BLUETOOTH.createChild('/bluetoothAddDevice', 'bluetooth-add-device');
189 r.BLUETOOTH_ADD_DEVICE.createChild('bluetoothPairDevice'); 220 r.BLUETOOTH_PAIR_DEVICE = r.BLUETOOTH_ADD_DEVICE.createChild(
221 'bluetoothPairDevice', 'bluetooth-pair-device');
190 </if> 222 </if>
191 223
192 r.PASSWORDS = r.ADVANCED.createSection('/passwords', 'passwordsAndForms'); 224 r.PASSWORDS = r.ADVANCED.createSection('/passwords', 'passwordsAndForms');
193 r.AUTOFILL = r.PASSWORDS.createChild('/autofill'); 225 r.AUTOFILL = r.PASSWORDS.createChild('/autofill', 'manage-autofill');
194 r.MANAGE_PASSWORDS = r.PASSWORDS.createChild('/managePasswords'); 226 r.MANAGE_PASSWORDS =
227 r.PASSWORDS.createChild('/managePasswords', 'manage-passwords');
195 228
196 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages'); 229 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages');
197 r.LANGUAGES_DETAIL = r.LANGUAGES.createChild('edit'); 230 r.LANGUAGES_DETAIL = r.LANGUAGES.createChild('edit', 'language-detail');
198 r.MANAGE_LANGUAGES = r.LANGUAGES.createChild('/manageLanguages'); 231 r.MANAGE_LANGUAGES =
232 r.LANGUAGES.createChild('/manageLanguages', 'manage-languages');
199 <if expr="chromeos"> 233 <if expr="chromeos">
200 r.INPUT_METHODS = r.LANGUAGES.createChild('/inputMethods'); 234 r.INPUT_METHODS =
235 r.LANGUAGES.createChild('/inputMethods', 'manage-input-methods');
201 </if> 236 </if>
202 <if expr="not is_macosx"> 237 <if expr="not is_macosx">
203 r.EDIT_DICTIONARY = r.LANGUAGES.createChild('/editDictionary'); 238 r.EDIT_DICTIONARY =
239 r.LANGUAGES.createChild('/editDictionary', 'edit-dictionary');
204 </if> 240 </if>
205 241
206 r.DOWNLOADS = r.ADVANCED.createSection('/downloadsDirectory', 'downloads'); 242 r.DOWNLOADS = r.ADVANCED.createSection('/downloadsDirectory', 'downloads');
207 243
208 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing'); 244 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing');
209 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters'); 245 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters', 'cloud-printers');
210 <if expr="chromeos"> 246 <if expr="chromeos">
211 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters'); 247 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters', 'cups-printers');
212 r.CUPS_PRINTER_DETAIL = r.CUPS_PRINTERS.createChild('/cupsPrinterDetails'); 248 r.CUPS_PRINTER_DETAIL = r.CUPS_PRINTERS.createChild(
249 '/cupsPrinterDetails', 'cups-printer-details-page');
213 </if> 250 </if>
214 251
215 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y'); 252 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y');
216 r.MANAGE_ACCESSIBILITY = r.ACCESSIBILITY.createChild('/manageAccessibility'); 253 r.MANAGE_ACCESSIBILITY = r.ACCESSIBILITY.createChild(
254 '/manageAccessibility', 'manage-a11y');
217 255
218 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); 256 r.SYSTEM = r.ADVANCED.createSection('/system', 'system');
219 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); 257 r.RESET = r.ADVANCED.createSection('/reset', 'reset');
220 258
221 <if expr="chromeos"> 259 <if expr="chromeos">
222 r.INPUT_METHODS = r.LANGUAGES.createChild('/inputMethods'); 260 r.INPUT_METHODS =
223 r.DETAILED_BUILD_INFO = r.ABOUT.createChild('/help/details'); 261 r.LANGUAGES.createChild('/inputMethods', 'manage-input-methods');
262 r.DETAILED_BUILD_INFO =
263 r.ABOUT.createChild('/help/details', 'detailed-build-info');
224 r.DETAILED_BUILD_INFO.section = 'about'; 264 r.DETAILED_BUILD_INFO.section = 'about';
225 </if> 265 </if>
226 266
227 var routeObservers_ = new Set(); 267 var routeObservers_ = new Set();
228 268
229 /** @polymerBehavior */ 269 /** @polymerBehavior */
230 var RouteObserverBehavior = { 270 var RouteObserverBehavior = {
231 /** @override */ 271 /** @override */
232 attached: function() { 272 attached: function() {
233 assert(!routeObservers_.has(this)); 273 assert(!routeObservers_.has(this));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 var currentRoute_ = Route.BASIC; 309 var currentRoute_ = Route.BASIC;
270 310
271 /** 311 /**
272 * The current query parameters. This updated only by settings.navigateTo. 312 * The current query parameters. This updated only by settings.navigateTo.
273 * @private {!URLSearchParams} 313 * @private {!URLSearchParams}
274 */ 314 */
275 var currentQueryParameters_ = new URLSearchParams(); 315 var currentQueryParameters_ = new URLSearchParams();
276 316
277 // Initialize the route and query params from the URL. 317 // Initialize the route and query params from the URL.
278 (function() { 318 (function() {
279 var route = getRouteForPath(window.location.pathname);
280 if (route) {
281 currentRoute_ = route;
282 currentQueryParameters_ = new URLSearchParams(window.location.search);
283 } else {
284 window.history.pushState(undefined, '', Route.BASIC.path);
285 }
286 })(); 319 })();
287 320
288 /** 321 /**
289 * Helper function to set the current route and notify all observers. 322 * Helper function to set the current route and notify all observers.
290 * @param {!settings.Route} route 323 * @param {!settings.Route} route
291 * @param {!URLSearchParams} queryParameters 324 * @param {!URLSearchParams} queryParameters
292 */ 325 */
293 var setCurrentRoute = function(route, queryParameters) { 326 var setCurrentRoute = function(route, queryParameters) {
294 var oldRoute = currentRoute_; 327 var oldRoute = currentRoute_;
295 currentRoute_ = route; 328 currentRoute_ = route;
(...skipping 12 matching lines...) Expand all
308 341
309 /** 342 /**
310 * Navigates to a canonical route and pushes a new history entry. 343 * Navigates to a canonical route and pushes a new history entry.
311 * @param {!settings.Route} route 344 * @param {!settings.Route} route
312 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same 345 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same
313 * search parameters in a different order will still push to history. 346 * search parameters in a different order will still push to history.
314 * @private 347 * @private
315 */ 348 */
316 var navigateTo = function(route, opt_dynamicParameters) { 349 var navigateTo = function(route, opt_dynamicParameters) {
317 var params = opt_dynamicParameters || new URLSearchParams(); 350 var params = opt_dynamicParameters || new URLSearchParams();
351 if (assert(route) == currentRoute_ &&
352 params.toString() == currentQueryParameters_.toString()) {
353 return;
354 }
318 355
319 var url = route.path; 356 var url = route.path;
320 if (opt_dynamicParameters) { 357 if (opt_dynamicParameters) {
321 var queryString = opt_dynamicParameters.toString(); 358 var queryString = opt_dynamicParameters.toString();
322 if (queryString) 359 if (queryString)
323 url += '?' + queryString; 360 url += '?' + queryString;
324 } 361 }
325 362
326 // History serializes the state, so we don't push the actual route object. 363 // History serializes the state, so we don't push the actual route object.
327 var previousRoutePath = currentRoute_.path; 364 var previousRoutePath = currentRoute_.path;
328 setCurrentRoute(route, params); 365 setCurrentRoute(route, params);
329 window.history.pushState(previousRoutePath, '', url); 366 window.history.pushState(previousRoutePath, '', url);
330 }; 367 };
331 368
332 window.addEventListener('popstate', function(event) { 369 window.addEventListener('popstate', function(event) {
333 // On pop state, do not push the state onto the window.history again. 370 // On pop state, do not push the state onto the window.history again.
334 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, 371 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC,
335 new URLSearchParams(window.location.search)); 372 new URLSearchParams(window.location.search));
336 }); 373 });
337 374
338 return { 375 return {
339 Route: Route, 376 Route: Route,
340 RouteObserverBehavior: RouteObserverBehavior, 377 RouteObserverBehavior: RouteObserverBehavior,
341 getRouteForPath: getRouteForPath, 378 getRouteForPath: getRouteForPath,
342 getCurrentRoute: getCurrentRoute, 379 getCurrentRoute: getCurrentRoute,
343 getQueryParameters: getQueryParameters, 380 getQueryParameters: getQueryParameters,
344 navigateTo: navigateTo, 381 navigateTo: navigateTo,
345 }; 382 };
346 }); 383 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698