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

Unified Diff: chrome/browser/resources/options/route_stub.js

Issue 2236213002: Add quick unlock Settings in options page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporate comments from jdufault@ 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options/route_stub.js
diff --git a/chrome/browser/resources/options/route_stub.js b/chrome/browser/resources/options/route_stub.js
new file mode 100644
index 0000000000000000000000000000000000000000..35867d6a52e2c9ee08a34e0bb768fc835e0d96af
--- /dev/null
+++ b/chrome/browser/resources/options/route_stub.js
@@ -0,0 +1,114 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// TODO(xiaoyinh@): This file is a stub class of
+// chrome/browser/resources/settings/route.js. And it is used to integrate
+// with the polymer elements in settings.
+// It should be removed once we don't need to support options.
stevenjb 2016/08/16 20:59:52 This is one of the pieces that strikes me as somew
xiaoyinh(OOO Sep 11-29) 2016/08/17 20:52:11 I have removed most of it, please take a look. Tha
+
+cr.define('settings', function() {
+ /**
+ * Class for navigable routes. May only be instantiated within this file.
+ * @constructor
+ * @param {string} path
+ * @private
+ */
+ var Route = function(path) {
+ this.path = path;
+ };
+
+ // Abbreviated variable for easier definitions.
+ var r = Route;
+
+ // Root pages.
+ r.BASIC = new Route('/');
+ r.PEOPLE = r.BASIC;
+<if expr="chromeos">
jdufault 2016/08/16 17:43:14 This file should only be included if we're on cros
xiaoyinh(OOO Sep 11-29) 2016/08/17 20:52:11 Removed, thanks!
+ r.LOCK_SCREEN = new Route('/quickUnlockConfigureOverlay');
+</if>
+
+ var routeObservers_ = new Set();
+
+ /** @polymerBehavior */
+ var RouteObserverBehavior = {
+ /** @override */
+ attached: function() {
+ assert(!routeObservers_.has(this));
+ routeObservers_.add(this);
+
+ // Emulating Polymer data bindings, the observer is called when the
+ // element starts observing the route.
+ this.currentRouteChanged(currentRoute_, undefined);
+ },
+
+ /** @override */
+ detached: function() {
+ assert(routeObservers_.delete(this));
+ },
+
+ /** @abstract */
+ currentRouteChanged: assertNotReached,
+ };
+
+ /**
+ * Returns the matching canonical route, or null if none matches.
+ * @param {string} path
+ * @return {?settings.Route}
+ * @private
+ */
+ var getRouteForPath = function(path) {
+ var matchingKey = Object.keys(Route).find(function(key) {
+ return Route[key].path == path;
+ });
+
+ return Route[matchingKey] || null;
+ };
+
+ /**
+ * The current active route. This updated only by settings.navigateTo.
+ * @private {!settings.Route}
+ */
+ var currentRoute_ = Route.BASIC;
+
+
+ // Initialize the route from the URL.
+ (function() {
+ var route = getRouteForPath(window.location.pathname);
+ if (route) {
+ currentRoute_ = route;
+ } else {
+ // Do nothing
+ }
+ })();
+
+ /**
+ * Helper function to set the current route and notify all observers.
+ * @param {!settings.Route} route
+ */
+ var setCurrentRoute = function(route) {
+ var oldRoute = currentRoute_;
+ currentRoute_ = route;
+ for (var observer of routeObservers_)
+ observer.currentRouteChanged(currentRoute_, oldRoute);
+ };
+
+ var getCurrentRoute = function() { return currentRoute_; };
+
+ var navigateTo = function(route) {
+ setCurrentRoute(route);
+ };
+
+ window.addEventListener('popstate', function(event) {
+ // On pop state, do not push the state onto the window.history again.
+ setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC);
+ });
+
+ return {
tommycli 2016/08/17 21:19:58 I think in this whole file, all you need is: var
xiaoyinh(OOO Sep 11-29) 2016/08/18 22:41:12 This file has been removed. Thanks!
+ Route: Route,
+ RouteObserverBehavior: RouteObserverBehavior,
+ getRouteForPath: getRouteForPath,
+ getCurrentRoute: getCurrentRoute,
+ navigateTo: navigateTo,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698