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

Unified Diff: ui/webui/resources/cr_elements/v1_0/network/cr_network_select.js

Issue 1277223002: Add cr-network-select element for selecting a Chrome OS network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_515987_network_configure
Patch Set: Compile fix Created 5 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: ui/webui/resources/cr_elements/v1_0/network/cr_network_select.js
diff --git a/ui/webui/resources/cr_elements/v1_0/network/cr_network_select.js b/ui/webui/resources/cr_elements/v1_0/network/cr_network_select.js
new file mode 100644
index 0000000000000000000000000000000000000000..75677b5ef928ca1bc5c08cdac0367f2ecceed9d8
--- /dev/null
+++ b/ui/webui/resources/cr_elements/v1_0/network/cr_network_select.js
@@ -0,0 +1,154 @@
+// Copyright 2015 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.
+
+/**
+ * @fileoverview Polymer element wrapping cr-network-list including the
+ * networkingPrivate calls to populate it.
+ */
+
+/**
+ * @element cr-network-select
+ */
+Polymer({
+ is: 'cr-network-select',
+
+ properties: {
+ /**
+ * Network state for the active network.
+ * @type {?CrOnc.NetworkStateProperties}
+ */
+ activeNetworkState: {
+ type: Object,
+ value: null
+ },
+
+ /**
+ * If true, the element includes an 'expand' button that toggles the
+ * expanded state of the network list.
+ */
+ expandable: {
+ type: Boolean,
+ value: false
+ },
+
+ /**
+ * The maximum height in pixels for the list.
+ */
+ maxHeight: {
+ type: Number,
+ value: 1000
+ },
+
+ /**
+ * If true, expand the network list.
+ */
+ networkListOpened: {
+ type: Boolean,
+ value: true,
+ observer: "networkListOpenedChanged_"
+ },
+
+ /**
+ * If true, show the active network state.
+ */
+ showActive: {
+ type: Boolean,
+ value: false
+ },
+
+ /**
+ * List of all network state data for all visible networks.
+ * @type {!Array<!CrOnc.NetworkStateProperties>}
+ */
+ networkStateList: {
+ type: Array,
+ value: function() { return []; }
+ }
+ },
+
+ /**
+ * Listener function for chrome.networkingPrivate.onNetworkListChanged event.
+ * @type {?function(!Array<string>)}
+ * @private
+ */
+ networkListChangedListener_: null,
+
+ /**
+ * Listener function for chrome.networkingPrivate.onDeviceStateListChanged
+ * event.
+ * @type {?function(!Array<string>)}
+ * @private
+ */
+ deviceStateListChangedListener_: null,
+
+ /** @override */
+ attached: function() {
+ this.networkListChangedListener_ = this.refreshNetworks_.bind(this);
+ chrome.networkingPrivate.onNetworkListChanged.addListener(
+ this.networkListChangedListener_);
+
+ this.deviceStateListChangedListener_ = this.refreshNetworks_.bind(this);
+ chrome.networkingPrivate.onDeviceStateListChanged.addListener(
+ this.deviceStateListChangedListener_);
+
+ this.refreshNetworks_();
+ chrome.networkingPrivate.requestNetworkScan();
+ },
+
+ /** @override */
+ detached: function() {
+ chrome.networkingPrivate.onNetworksChanged.removeListener(
+ this.networksChangedListener_);
+ chrome.networkingPrivate.onDeviceStateListChanged.removeListener(
+ this.deviceStateListChangedListener_);
+ },
+
+ /**
+ * Polymer chnaged function.
+ * @private
+ */
+ networkListOpenedChanged_: function() {
+ if (this.networkListOpened)
+ chrome.networkingPrivate.requestNetworkScan();
+ },
+
+ /**
+ * Request the list of visible networks.
+ * @private
+ */
+ refreshNetworks_: function() {
+ var filter = {
+ networkType: 'All',
+ visible: true,
+ configured: false
+ };
+ chrome.networkingPrivate.getNetworks(
+ filter, this.getNetworksCallback_.bind(this));
+ },
+
+ /**
+ * @param {!Array<!CrOnc.NetworkStateProperties>} states
+ * @private
+ */
+ getNetworksCallback_: function(states) {
+ this.activeNetworkState = states[0] || null;
+ this.networkStateList = states;
+ },
+
+ /**
+ * Event triggered when a cr-network-list-item is selected.
+ * @param {!{detail: !CrOnc.NetworkStateProperties}} event
+ * @private
+ */
+ onNetworkListItemSelected_: function(event) {
+ var state = event.detail;
+ if (state.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED)
+ return;
+ chrome.networkingPrivate.startConnect(state.GUID, function() {
+ var lastError = chrome.runtime.lastError;
+ if (lastError && lastError != 'connecting')
+ console.error('networkingPrivate.startConnect error:', lastError);
+ });
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698