| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 // Navigable dialogs. These are the only non-section children of root pages. | 94 // Navigable dialogs. These are the only non-section children of root pages. |
| 95 // These are disfavored. If we add anymore, we should add explicit support. | 95 // These are disfavored. If we add anymore, we should add explicit support. |
| 96 r.IMPORT_DATA = r.BASIC.createChild('/importData'); | 96 r.IMPORT_DATA = r.BASIC.createChild('/importData'); |
| 97 r.SIGN_OUT = r.BASIC.createChild('/signOut'); | 97 r.SIGN_OUT = r.BASIC.createChild('/signOut'); |
| 98 r.CLEAR_BROWSER_DATA = r.ADVANCED.createChild('/clearBrowserData'); | 98 r.CLEAR_BROWSER_DATA = r.ADVANCED.createChild('/clearBrowserData'); |
| 99 r.RESET_DIALOG = r.ADVANCED.createChild('/resetProfileSettings'); | 99 r.RESET_DIALOG = r.ADVANCED.createChild('/resetProfileSettings'); |
| 100 r.TRIGGERED_RESET_DIALOG = | 100 r.TRIGGERED_RESET_DIALOG = |
| 101 r.ADVANCED.createChild('/triggeredResetProfileSettings'); | 101 r.ADVANCED.createChild('/triggeredResetProfileSettings'); |
| 102 | 102 |
| 103 <if expr="chromeos"> | 103 /* <if expr="chromeos"> */ |
| 104 r.INTERNET = r.BASIC.createSection('/internet', 'internet'); | 104 r.INTERNET = r.BASIC.createSection('/internet', 'internet'); |
| 105 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail'); | 105 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail'); |
| 106 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks'); | 106 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks'); |
| 107 </if> | 107 /* </if> */ |
| 108 | 108 |
| 109 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance'); | 109 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance'); |
| 110 r.FONTS = r.APPEARANCE.createChild('/fonts'); | 110 r.FONTS = r.APPEARANCE.createChild('/fonts'); |
| 111 | 111 |
| 112 r.DEFAULT_BROWSER = | 112 r.DEFAULT_BROWSER = |
| 113 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser'); | 113 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser'); |
| 114 | 114 |
| 115 r.SEARCH = r.BASIC.createSection('/search', 'search'); | 115 r.SEARCH = r.BASIC.createSection('/search', 'search'); |
| 116 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines'); | 116 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines'); |
| 117 | 117 |
| 118 <if expr="chromeos"> | 118 /* <if expr="chromeos"> */ |
| 119 r.ANDROID_APPS = r.BASIC.createSection('/androidApps', 'androidApps'); | 119 r.ANDROID_APPS = r.BASIC.createSection('/androidApps', 'androidApps'); |
| 120 </if> | 120 /* </if> */ |
| 121 | 121 |
| 122 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup'); | 122 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup'); |
| 123 | 123 |
| 124 r.PEOPLE = r.BASIC.createSection('/people', 'people'); | 124 r.PEOPLE = r.BASIC.createSection('/people', 'people'); |
| 125 r.SYNC = r.PEOPLE.createChild('/syncSetup'); | 125 r.SYNC = r.PEOPLE.createChild('/syncSetup'); |
| 126 <if expr="not chromeos"> | 126 /* <if expr="not chromeos"> */ |
| 127 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile'); | 127 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile'); |
| 128 </if> | 128 /* </if> */ |
| 129 <if expr="chromeos"> | 129 /* <if expr="chromeos"> */ |
| 130 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture'); | 130 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture'); |
| 131 r.ACCOUNTS = r.PEOPLE.createChild('/accounts'); | 131 r.ACCOUNTS = r.PEOPLE.createChild('/accounts'); |
| 132 r.LOCK_SCREEN = r.PEOPLE.createChild('/lockScreen'); | 132 r.LOCK_SCREEN = r.PEOPLE.createChild('/lockScreen'); |
| 133 | 133 |
| 134 r.DEVICE = r.BASIC.createSection('/device', 'device'); | 134 r.DEVICE = r.BASIC.createSection('/device', 'device'); |
| 135 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); | 135 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); |
| 136 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); | 136 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); |
| 137 r.DISPLAY = r.DEVICE.createChild('/display'); | 137 r.DISPLAY = r.DEVICE.createChild('/display'); |
| 138 r.STYLUS = r.DEVICE.createChild('/stylus'); | 138 r.STYLUS = r.DEVICE.createChild('/stylus'); |
| 139 r.STORAGE = r.DEVICE.createChild('/storage'); | 139 r.STORAGE = r.DEVICE.createChild('/storage'); |
| 140 </if> | 140 /* </if> */ |
| 141 | 141 |
| 142 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); | 142 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); |
| 143 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); | 143 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); |
| 144 | 144 |
| 145 r.SITE_SETTINGS = r.PRIVACY.createChild('/content'); | 145 r.SITE_SETTINGS = r.PRIVACY.createChild('/content'); |
| 146 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); | 146 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); |
| 147 r.SITE_SETTINGS_SITE_DETAILS = | 147 r.SITE_SETTINGS_SITE_DETAILS = |
| 148 r.SITE_SETTINGS_ALL.createChild('/content/siteDetails'); | 148 r.SITE_SETTINGS_ALL.createChild('/content/siteDetails'); |
| 149 | 149 |
| 150 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('/handlers'); | 150 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('/handlers'); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 164 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild('microphone'); | 164 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild('microphone'); |
| 165 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild('notifications'); | 165 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild('notifications'); |
| 166 r.SITE_SETTINGS_FLASH = r.SITE_SETTINGS.createChild('flash'); | 166 r.SITE_SETTINGS_FLASH = r.SITE_SETTINGS.createChild('flash'); |
| 167 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); | 167 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); |
| 168 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = | 168 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = |
| 169 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); | 169 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); |
| 170 r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); | 170 r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); |
| 171 r.SITE_SETTINGS_ZOOM_LEVELS = r.SITE_SETTINGS.createChild('zoomLevels'); | 171 r.SITE_SETTINGS_ZOOM_LEVELS = r.SITE_SETTINGS.createChild('zoomLevels'); |
| 172 r.SITE_SETTINGS_PDF_DOCUMENTS = r.SITE_SETTINGS.createChild('pdfDocuments'); | 172 r.SITE_SETTINGS_PDF_DOCUMENTS = r.SITE_SETTINGS.createChild('pdfDocuments'); |
| 173 | 173 |
| 174 <if expr="chromeos"> | 174 /* <if expr="chromeos"> */ |
| 175 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); | 175 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); |
| 176 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth'); | 176 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth'); |
| 177 </if> | 177 /* </if> */ |
| 178 | 178 |
| 179 r.PASSWORDS = | 179 r.PASSWORDS = |
| 180 r.ADVANCED.createSection('/passwordsAndForms', 'passwordsAndForms'); | 180 r.ADVANCED.createSection('/passwordsAndForms', 'passwordsAndForms'); |
| 181 r.AUTOFILL = r.PASSWORDS.createChild('/autofill'); | 181 r.AUTOFILL = r.PASSWORDS.createChild('/autofill'); |
| 182 r.MANAGE_PASSWORDS = r.PASSWORDS.createChild('/passwords'); | 182 r.MANAGE_PASSWORDS = r.PASSWORDS.createChild('/passwords'); |
| 183 | 183 |
| 184 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages'); | 184 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages'); |
| 185 <if expr="chromeos"> | 185 /* <if expr="chromeos"> */ |
| 186 r.INPUT_METHODS = r.LANGUAGES.createChild('/inputMethods'); | 186 r.INPUT_METHODS = r.LANGUAGES.createChild('/inputMethods'); |
| 187 </if> | 187 /* </if> */ |
| 188 <if expr="not is_macosx"> | 188 /* <if expr="not is_macosx"> */ |
| 189 r.EDIT_DICTIONARY = r.LANGUAGES.createChild('/editDictionary'); | 189 r.EDIT_DICTIONARY = r.LANGUAGES.createChild('/editDictionary'); |
| 190 </if> | 190 /* </if> */ |
| 191 | 191 |
| 192 r.DOWNLOADS = r.ADVANCED.createSection('/downloads', 'downloads'); | 192 r.DOWNLOADS = r.ADVANCED.createSection('/downloads', 'downloads'); |
| 193 | 193 |
| 194 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing'); | 194 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing'); |
| 195 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters'); | 195 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters'); |
| 196 <if expr="chromeos"> | 196 /* <if expr="chromeos"> */ |
| 197 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters'); | 197 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters'); |
| 198 r.CUPS_PRINTER_DETAIL = r.CUPS_PRINTERS.createChild('/cupsPrinterDetails'); | 198 r.CUPS_PRINTER_DETAIL = r.CUPS_PRINTERS.createChild('/cupsPrinterDetails'); |
| 199 </if> | 199 /* </if> */ |
| 200 | 200 |
| 201 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y'); | 201 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y'); |
| 202 r.MANAGE_ACCESSIBILITY = r.ACCESSIBILITY.createChild('/manageAccessibility'); | 202 r.MANAGE_ACCESSIBILITY = r.ACCESSIBILITY.createChild('/manageAccessibility'); |
| 203 | 203 |
| 204 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); | 204 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); |
| 205 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); | 205 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); |
| 206 | 206 |
| 207 <if expr="chromeos"> | 207 /* <if expr="chromeos"> */ |
| 208 // "About" is the only section in About, but we still need to create the route | 208 // "About" is the only section in About, but we still need to create the route |
| 209 // in order to show the subpage on Chrome OS. | 209 // in order to show the subpage on Chrome OS. |
| 210 r.ABOUT_ABOUT = r.ABOUT.createSection('/help/about', 'about'); | 210 r.ABOUT_ABOUT = r.ABOUT.createSection('/help/about', 'about'); |
| 211 r.DETAILED_BUILD_INFO = r.ABOUT_ABOUT.createChild('/help/details'); | 211 r.DETAILED_BUILD_INFO = r.ABOUT_ABOUT.createChild('/help/details'); |
| 212 </if> | 212 /* </if> */ |
| 213 | 213 |
| 214 var routeObservers_ = new Set(); | 214 var routeObservers_ = new Set(); |
| 215 | 215 |
| 216 /** @polymerBehavior */ | 216 /** @polymerBehavior */ |
| 217 var RouteObserverBehavior = { | 217 var RouteObserverBehavior = { |
| 218 /** @override */ | 218 /** @override */ |
| 219 attached: function() { | 219 attached: function() { |
| 220 assert(!routeObservers_.has(this)); | 220 assert(!routeObservers_.has(this)); |
| 221 routeObservers_.add(this); | 221 routeObservers_.add(this); |
| 222 | 222 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 var setCurrentRoute = function(route, queryParameters, isPopstate) { | 310 var setCurrentRoute = function(route, queryParameters, isPopstate) { |
| 311 var oldRoute = currentRoute_; | 311 var oldRoute = currentRoute_; |
| 312 currentRoute_ = route; | 312 currentRoute_ = route; |
| 313 currentQueryParameters_ = queryParameters; | 313 currentQueryParameters_ = queryParameters; |
| 314 lastRouteChangeWasPopstate_ = isPopstate; | 314 lastRouteChangeWasPopstate_ = isPopstate; |
| 315 for (var observer of routeObservers_) | 315 for (var observer of routeObservers_) |
| 316 observer.currentRouteChanged(currentRoute_, oldRoute); | 316 observer.currentRouteChanged(currentRoute_, oldRoute); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 /** @return {!settings.Route} */ | 319 /** @return {!settings.Route} */ |
| 320 var getCurrentRoute = function() { return currentRoute_; }; | 320 var getCurrentRoute = function() { |
| 321 return currentRoute_; |
| 322 }; |
| 321 | 323 |
| 322 /** @return {!URLSearchParams} */ | 324 /** @return {!URLSearchParams} */ |
| 323 var getQueryParameters = function() { | 325 var getQueryParameters = function() { |
| 324 return new URLSearchParams(currentQueryParameters_); // Defensive copy. | 326 return new URLSearchParams(currentQueryParameters_); // Defensive copy. |
| 325 }; | 327 }; |
| 326 | 328 |
| 327 /** @return {boolean} */ | 329 /** @return {boolean} */ |
| 328 var lastRouteChangeWasPopstate = function() { | 330 var lastRouteChangeWasPopstate = function() { |
| 329 return lastRouteChangeWasPopstate_; | 331 return lastRouteChangeWasPopstate_; |
| 330 }; | 332 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 356 window.history.pushState(currentRoute_.path, '', url); | 358 window.history.pushState(currentRoute_.path, '', url); |
| 357 setCurrentRoute(route, params, false); | 359 setCurrentRoute(route, params, false); |
| 358 }; | 360 }; |
| 359 | 361 |
| 360 /** | 362 /** |
| 361 * Navigates to the previous route if it has an equal or lesser depth. | 363 * Navigates to the previous route if it has an equal or lesser depth. |
| 362 * If there is no previous route in history meeting those requirements, | 364 * If there is no previous route in history meeting those requirements, |
| 363 * this navigates to the immediate parent. This will never exit Settings. | 365 * this navigates to the immediate parent. This will never exit Settings. |
| 364 */ | 366 */ |
| 365 var navigateToPreviousRoute = function() { | 367 var navigateToPreviousRoute = function() { |
| 366 var previousRoute = | 368 var previousRoute = window.history.state && |
| 367 window.history.state && | |
| 368 assert(getRouteForPath(/** @type {string} */ (window.history.state))); | 369 assert(getRouteForPath(/** @type {string} */ (window.history.state))); |
| 369 | 370 |
| 370 if (previousRoute && previousRoute.depth <= currentRoute_.depth) | 371 if (previousRoute && previousRoute.depth <= currentRoute_.depth) |
| 371 window.history.back(); | 372 window.history.back(); |
| 372 else | 373 else |
| 373 navigateTo(currentRoute_.parent || Route.BASIC); | 374 navigateTo(currentRoute_.parent || Route.BASIC); |
| 374 }; | 375 }; |
| 375 | 376 |
| 376 window.addEventListener('popstate', function(event) { | 377 window.addEventListener('popstate', function(event) { |
| 377 // On pop state, do not push the state onto the window.history again. | 378 // On pop state, do not push the state onto the window.history again. |
| 378 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, | 379 setCurrentRoute( |
| 379 new URLSearchParams(window.location.search), true); | 380 getRouteForPath(window.location.pathname) || Route.BASIC, |
| 381 new URLSearchParams(window.location.search), true); |
| 380 }); | 382 }); |
| 381 | 383 |
| 382 return { | 384 return { |
| 383 Route: Route, | 385 Route: Route, |
| 384 RouteObserverBehavior: RouteObserverBehavior, | 386 RouteObserverBehavior: RouteObserverBehavior, |
| 385 getRouteForPath: getRouteForPath, | 387 getRouteForPath: getRouteForPath, |
| 386 initializeRouteFromUrl: initializeRouteFromUrl, | 388 initializeRouteFromUrl: initializeRouteFromUrl, |
| 387 getCurrentRoute: getCurrentRoute, | 389 getCurrentRoute: getCurrentRoute, |
| 388 getQueryParameters: getQueryParameters, | 390 getQueryParameters: getQueryParameters, |
| 389 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 391 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
| 390 navigateTo: navigateTo, | 392 navigateTo: navigateTo, |
| 391 navigateToPreviousRoute: navigateToPreviousRoute, | 393 navigateToPreviousRoute: navigateToPreviousRoute, |
| 392 }; | 394 }; |
| 393 }); | 395 }); |
| OLD | NEW |