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 | 4 |
5 cr.define('settings', function() { | 5 cr.define('settings', function() { |
6 /** | 6 /** |
7 * Class for navigable routes. May only be instantiated within this file. | 7 * Class for navigable routes. May only be instantiated within this file. |
8 * @constructor | 8 * @constructor |
9 * @param {string} path | 9 * @param {string} path |
10 * @private | 10 * @private |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 r.SIGN_OUT = r.BASIC.createChild('/signOut'); | 106 r.SIGN_OUT = r.BASIC.createChild('/signOut'); |
107 r.SIGN_OUT.isNavigableDialog = true; | 107 r.SIGN_OUT.isNavigableDialog = true; |
108 r.CLEAR_BROWSER_DATA = r.ADVANCED.createChild('/clearBrowserData'); | 108 r.CLEAR_BROWSER_DATA = r.ADVANCED.createChild('/clearBrowserData'); |
109 r.CLEAR_BROWSER_DATA.isNavigableDialog = true; | 109 r.CLEAR_BROWSER_DATA.isNavigableDialog = true; |
110 r.RESET_DIALOG = r.ADVANCED.createChild('/resetProfileSettings'); | 110 r.RESET_DIALOG = r.ADVANCED.createChild('/resetProfileSettings'); |
111 r.RESET_DIALOG.isNavigableDialog = true; | 111 r.RESET_DIALOG.isNavigableDialog = true; |
112 r.TRIGGERED_RESET_DIALOG = | 112 r.TRIGGERED_RESET_DIALOG = |
113 r.ADVANCED.createChild('/triggeredResetProfileSettings'); | 113 r.ADVANCED.createChild('/triggeredResetProfileSettings'); |
114 r.TRIGGERED_RESET_DIALOG.isNavigableDialog = true; | 114 r.TRIGGERED_RESET_DIALOG.isNavigableDialog = true; |
115 | 115 |
116 // <if expr="chromeos"> | 116 // <if expr="chromeos"> |
117 r.INTERNET = r.BASIC.createSection('/internet', 'internet'); | 117 r.INTERNET = r.BASIC.createSection('/internet', 'internet'); |
118 r.INTERNET_NETWORKS = r.INTERNET.createChild('/networks'); | 118 r.INTERNET_NETWORKS = r.INTERNET.createChild('/networks'); |
119 r.NETWORK_CONFIG = r.INTERNET.createChild('/networkConfig'); | 119 r.NETWORK_CONFIG = r.INTERNET.createChild('/networkConfig'); |
120 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail'); | 120 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail'); |
121 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks'); | 121 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks'); |
122 r.BLUETOOTH = r.BASIC.createSection('/bluetooth', 'bluetooth'); | 122 r.BLUETOOTH = r.BASIC.createSection('/bluetooth', 'bluetooth'); |
123 r.BLUETOOTH_DEVICES = r.BLUETOOTH.createChild('/bluetoothDevices'); | 123 r.BLUETOOTH_DEVICES = r.BLUETOOTH.createChild('/bluetoothDevices'); |
124 // </if> | 124 // </if> |
125 | 125 |
126 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance'); | 126 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance'); |
127 r.FONTS = r.APPEARANCE.createChild('/fonts'); | 127 r.FONTS = r.APPEARANCE.createChild('/fonts'); |
128 | 128 |
129 r.DEFAULT_BROWSER = | 129 r.DEFAULT_BROWSER = |
130 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser'); | 130 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser'); |
131 | 131 |
132 r.SEARCH = r.BASIC.createSection('/search', 'search'); | 132 r.SEARCH = r.BASIC.createSection('/search', 'search'); |
133 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines'); | 133 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines'); |
134 | 134 |
135 // <if expr="chromeos"> | 135 // <if expr="chromeos"> |
136 r.ANDROID_APPS = r.BASIC.createSection('/androidApps', 'androidApps'); | 136 r.ANDROID_APPS = r.BASIC.createSection('/androidApps', 'androidApps'); |
137 r.ANDROID_APPS_DETAILS = r.ANDROID_APPS.createChild('/androidApps/details'); | 137 r.ANDROID_APPS_DETAILS = r.ANDROID_APPS.createChild('/androidApps/details'); |
138 // </if> | 138 // </if> |
139 | 139 |
140 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup'); | 140 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup'); |
141 | 141 |
142 r.PEOPLE = r.BASIC.createSection('/people', 'people'); | 142 r.PEOPLE = r.BASIC.createSection('/people', 'people'); |
143 r.SYNC = r.PEOPLE.createChild('/syncSetup'); | 143 r.SYNC = r.PEOPLE.createChild('/syncSetup'); |
144 // <if expr="not chromeos"> | 144 // <if expr="not chromeos"> |
145 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile'); | 145 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile'); |
146 // </if> | 146 // </if> |
147 // <if expr="chromeos"> | 147 // <if expr="chromeos"> |
148 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture'); | 148 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture'); |
149 r.ACCOUNTS = r.PEOPLE.createChild('/accounts'); | 149 r.ACCOUNTS = r.PEOPLE.createChild('/accounts'); |
150 r.LOCK_SCREEN = r.PEOPLE.createChild('/lockScreen'); | 150 r.LOCK_SCREEN = r.PEOPLE.createChild('/lockScreen'); |
151 r.FINGERPRINT = r.LOCK_SCREEN.createChild('/lockScreen/fingerprint'); | 151 r.FINGERPRINT = r.LOCK_SCREEN.createChild('/lockScreen/fingerprint'); |
152 | 152 |
153 r.DEVICE = r.BASIC.createSection('/device', 'device'); | 153 r.DEVICE = r.BASIC.createSection('/device', 'device'); |
154 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); | 154 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); |
155 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); | 155 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); |
156 r.STYLUS = r.DEVICE.createChild('/stylus'); | 156 r.STYLUS = r.DEVICE.createChild('/stylus'); |
157 r.DISPLAY = r.DEVICE.createChild('/display'); | 157 r.DISPLAY = r.DEVICE.createChild('/display'); |
158 r.STORAGE = r.DEVICE.createChild('/storage'); | 158 r.STORAGE = r.DEVICE.createChild('/storage'); |
159 r.POWER = r.DEVICE.createChild('/power'); | 159 r.POWER = r.DEVICE.createChild('/power'); |
160 // </if> | 160 // </if> |
161 | 161 |
162 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); | 162 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); |
163 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); | 163 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); |
164 | 164 |
165 r.SITE_SETTINGS = r.PRIVACY.createChild('/content'); | 165 r.SITE_SETTINGS = r.PRIVACY.createChild('/content'); |
166 | 166 |
167 if (loadTimeData.getBoolean('enableSiteSettings')) { | 167 if (loadTimeData.getBoolean('enableSiteSettings')) { |
168 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); | 168 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); |
169 r.SITE_SETTINGS_SITE_DETAILS = | 169 r.SITE_SETTINGS_SITE_DETAILS = |
170 r.SITE_SETTINGS_ALL.createChild('/content/siteDetails'); | 170 r.SITE_SETTINGS_ALL.createChild('/content/siteDetails'); |
(...skipping 26 matching lines...) Expand all Loading... |
197 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); | 197 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); |
198 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = | 198 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = |
199 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); | 199 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); |
200 r.SITE_SETTINGS_MIDI_DEVICES = r.SITE_SETTINGS.createChild('midiDevices'); | 200 r.SITE_SETTINGS_MIDI_DEVICES = r.SITE_SETTINGS.createChild('midiDevices'); |
201 r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); | 201 r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); |
202 r.SITE_SETTINGS_ZOOM_LEVELS = r.SITE_SETTINGS.createChild('zoomLevels'); | 202 r.SITE_SETTINGS_ZOOM_LEVELS = r.SITE_SETTINGS.createChild('zoomLevels'); |
203 r.SITE_SETTINGS_PDF_DOCUMENTS = r.SITE_SETTINGS.createChild('pdfDocuments'); | 203 r.SITE_SETTINGS_PDF_DOCUMENTS = r.SITE_SETTINGS.createChild('pdfDocuments'); |
204 r.SITE_SETTINGS_PROTECTED_CONTENT = | 204 r.SITE_SETTINGS_PROTECTED_CONTENT = |
205 r.SITE_SETTINGS.createChild('protectedContent'); | 205 r.SITE_SETTINGS.createChild('protectedContent'); |
206 | 206 |
207 // <if expr="chromeos"> | 207 // <if expr="chromeos"> |
208 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); | 208 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); |
209 // </if> | 209 // </if> |
210 | 210 |
211 r.PASSWORDS = | 211 r.PASSWORDS = |
212 r.ADVANCED.createSection('/passwordsAndForms', 'passwordsAndForms'); | 212 r.ADVANCED.createSection('/passwordsAndForms', 'passwordsAndForms'); |
213 r.AUTOFILL = r.PASSWORDS.createChild('/autofill'); | 213 r.AUTOFILL = r.PASSWORDS.createChild('/autofill'); |
214 r.MANAGE_PASSWORDS = r.PASSWORDS.createChild('/passwords'); | 214 r.MANAGE_PASSWORDS = r.PASSWORDS.createChild('/passwords'); |
215 | 215 |
216 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages'); | 216 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages'); |
217 // <if expr="chromeos"> | 217 // <if expr="chromeos"> |
218 r.INPUT_METHODS = r.LANGUAGES.createChild('/inputMethods'); | 218 r.INPUT_METHODS = r.LANGUAGES.createChild('/inputMethods'); |
219 // </if> | 219 // </if> |
220 // <if expr="not is_macosx"> | 220 // <if expr="not is_macosx"> |
221 r.EDIT_DICTIONARY = r.LANGUAGES.createChild('/editDictionary'); | 221 r.EDIT_DICTIONARY = r.LANGUAGES.createChild('/editDictionary'); |
222 // </if> | 222 // </if> |
223 | 223 |
224 r.DOWNLOADS = r.ADVANCED.createSection('/downloads', 'downloads'); | 224 r.DOWNLOADS = r.ADVANCED.createSection('/downloads', 'downloads'); |
225 | 225 |
226 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing'); | 226 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing'); |
227 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters'); | 227 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters'); |
228 // <if expr="chromeos"> | 228 // <if expr="chromeos"> |
229 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters'); | 229 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters'); |
230 r.CUPS_PRINTER_DETAIL = r.CUPS_PRINTERS.createChild('/cupsPrinterDetails'); | 230 r.CUPS_PRINTER_DETAIL = r.CUPS_PRINTERS.createChild('/cupsPrinterDetails'); |
231 // </if> | 231 // </if> |
232 | 232 |
233 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y'); | 233 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y'); |
234 // <if expr="chromeos"> | 234 // <if expr="chromeos"> |
235 r.MANAGE_ACCESSIBILITY = r.ACCESSIBILITY.createChild('/manageAccessibility'); | 235 r.MANAGE_ACCESSIBILITY = r.ACCESSIBILITY.createChild('/manageAccessibility'); |
236 // </if> | 236 // </if> |
237 | 237 |
238 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); | 238 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); |
239 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); | 239 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); |
240 | 240 |
241 // <if expr="chromeos"> | 241 // <if expr="chromeos"> |
242 // "About" is the only section in About, but we still need to create the route | 242 // "About" is the only section in About, but we still need to create the route |
243 // in order to show the subpage on Chrome OS. | 243 // in order to show the subpage on Chrome OS. |
244 r.ABOUT_ABOUT = r.ABOUT.createSection('/help/about', 'about'); | 244 r.ABOUT_ABOUT = r.ABOUT.createSection('/help/about', 'about'); |
245 r.DETAILED_BUILD_INFO = r.ABOUT_ABOUT.createChild('/help/details'); | 245 r.DETAILED_BUILD_INFO = r.ABOUT_ABOUT.createChild('/help/details'); |
246 // </if> | 246 // </if> |
247 | 247 |
248 var routeObservers = new Set(); | 248 var routeObservers = new Set(); |
249 | 249 |
250 /** @polymerBehavior */ | 250 /** @polymerBehavior */ |
251 var RouteObserverBehavior = { | 251 var RouteObserverBehavior = { |
252 /** @override */ | 252 /** @override */ |
253 attached: function() { | 253 attached: function() { |
254 assert(!routeObservers.has(this)); | 254 assert(!routeObservers.has(this)); |
255 routeObservers.add(this); | 255 routeObservers.add(this); |
256 | 256 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 var oldRoute = currentRoute; | 352 var oldRoute = currentRoute; |
353 currentRoute = route; | 353 currentRoute = route; |
354 currentQueryParameters = queryParameters; | 354 currentQueryParameters = queryParameters; |
355 wasLastRouteChangePopstate = isPopstate; | 355 wasLastRouteChangePopstate = isPopstate; |
356 routeObservers.forEach(function(observer) { | 356 routeObservers.forEach(function(observer) { |
357 observer.currentRouteChanged(currentRoute, oldRoute); | 357 observer.currentRouteChanged(currentRoute, oldRoute); |
358 }); | 358 }); |
359 }; | 359 }; |
360 | 360 |
361 /** @return {!settings.Route} */ | 361 /** @return {!settings.Route} */ |
362 var getCurrentRoute = function() { return currentRoute; }; | 362 var getCurrentRoute = function() { |
| 363 return currentRoute; |
| 364 }; |
363 | 365 |
364 /** @return {!URLSearchParams} */ | 366 /** @return {!URLSearchParams} */ |
365 var getQueryParameters = function() { | 367 var getQueryParameters = function() { |
366 return new URLSearchParams(currentQueryParameters); // Defensive copy. | 368 return new URLSearchParams(currentQueryParameters); // Defensive copy. |
367 }; | 369 }; |
368 | 370 |
369 /** @return {boolean} */ | 371 /** @return {boolean} */ |
370 var lastRouteChangeWasPopstate = function() { | 372 var lastRouteChangeWasPopstate = function() { |
371 return wasLastRouteChangePopstate; | 373 return wasLastRouteChangePopstate; |
372 }; | 374 }; |
(...skipping 30 matching lines...) Expand all Loading... |
403 window.history.pushState(currentRoute.path, '', url); | 405 window.history.pushState(currentRoute.path, '', url); |
404 setCurrentRoute(route, params, false); | 406 setCurrentRoute(route, params, false); |
405 }; | 407 }; |
406 | 408 |
407 /** | 409 /** |
408 * Navigates to the previous route if it has an equal or lesser depth. | 410 * Navigates to the previous route if it has an equal or lesser depth. |
409 * If there is no previous route in history meeting those requirements, | 411 * If there is no previous route in history meeting those requirements, |
410 * this navigates to the immediate parent. This will never exit Settings. | 412 * this navigates to the immediate parent. This will never exit Settings. |
411 */ | 413 */ |
412 var navigateToPreviousRoute = function() { | 414 var navigateToPreviousRoute = function() { |
413 var previousRoute = | 415 var previousRoute = window.history.state && |
414 window.history.state && | |
415 assert(getRouteForPath(/** @type {string} */ (window.history.state))); | 416 assert(getRouteForPath(/** @type {string} */ (window.history.state))); |
416 | 417 |
417 if (previousRoute && previousRoute.depth <= currentRoute.depth) | 418 if (previousRoute && previousRoute.depth <= currentRoute.depth) |
418 window.history.back(); | 419 window.history.back(); |
419 else | 420 else |
420 navigateTo(currentRoute.parent || Route.BASIC); | 421 navigateTo(currentRoute.parent || Route.BASIC); |
421 }; | 422 }; |
422 | 423 |
423 window.addEventListener('popstate', function(event) { | 424 window.addEventListener('popstate', function(event) { |
424 // On pop state, do not push the state onto the window.history again. | 425 // On pop state, do not push the state onto the window.history again. |
425 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, | 426 setCurrentRoute( |
426 new URLSearchParams(window.location.search), true); | 427 getRouteForPath(window.location.pathname) || Route.BASIC, |
| 428 new URLSearchParams(window.location.search), true); |
427 }); | 429 }); |
428 | 430 |
429 return { | 431 return { |
430 Route: Route, | 432 Route: Route, |
431 RouteObserverBehavior: RouteObserverBehavior, | 433 RouteObserverBehavior: RouteObserverBehavior, |
432 getRouteForPath: getRouteForPath, | 434 getRouteForPath: getRouteForPath, |
433 initializeRouteFromUrl: initializeRouteFromUrl, | 435 initializeRouteFromUrl: initializeRouteFromUrl, |
434 resetRouteForTesting: resetRouteForTesting, | 436 resetRouteForTesting: resetRouteForTesting, |
435 getCurrentRoute: getCurrentRoute, | 437 getCurrentRoute: getCurrentRoute, |
436 getQueryParameters: getQueryParameters, | 438 getQueryParameters: getQueryParameters, |
437 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 439 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
438 navigateTo: navigateTo, | 440 navigateTo: navigateTo, |
439 navigateToPreviousRoute: navigateToPreviousRoute, | 441 navigateToPreviousRoute: navigateToPreviousRoute, |
440 }; | 442 }; |
441 }); | 443 }); |
OLD | NEW |