Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / chromeos / internet_detail.js
index 3d392e0..3fdc203 100644 (file)
  */
 var IPInfo;
 
-/**
- * InternetDetailedInfo argument passed to showDetailedInfo.
- * @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
- * @typedef {{
- *   servicePath: string,
- *   showCarrierSelect: (boolean|undefined),
- *   showViewAccountButton: (boolean|undefined)
- * }}
- */
-var InternetDetailedInfo;
-
 cr.define('options.internet', function() {
   var OncData = cr.onc.OncData;
   var Page = cr.ui.pageManager.Page;
@@ -108,7 +97,7 @@ cr.define('options.internet', function() {
   function sendCheckedIfEnabled(path, message, checkboxId, opt_action) {
     var checkbox = assertInstanceof($(checkboxId), HTMLInputElement);
     if (!checkbox.hidden && !checkbox.disabled) {
-      chrome.send(message, [path, checkbox.checked ? 'true' : 'false']);
+      chrome.send(message, [path, !!checkbox.checked]);
       if (opt_action)
         sendChromeMetricsAction(opt_action);
     }
@@ -179,10 +168,6 @@ cr.define('options.internet', function() {
     // We show the Proxy configuration tab for remembered networks and when
     // configuring a proxy from the login screen.
     this.showProxy_ = false;
-    // In Chrome we sometimes want to enable the Cellular carrier select UI.
-    this.showCarrierSelect_ = false;
-    // In Chrome we sometimes want to show the 'View Account' button.
-    this.showViewAccountButton_ = false;
 
     Page.call(this, 'detailsInternetPage', '', 'details-internet-page');
   }
@@ -207,8 +192,9 @@ cr.define('options.internet', function() {
       var servicePath = parseQueryParams(window.location).servicePath;
       if (!servicePath || !servicePath.length)
         return;
-      var networkType = '';  // ignored for 'showDetails'
-      chrome.send('networkCommand', [networkType, servicePath, 'showDetails']);
+      // TODO(stevenjb): chrome.networkingPrivate.getManagedProperties
+      // with initializeDetailsPage as the callback.
+      chrome.send('getManagedProperties', [servicePath]);
     },
 
     /**
@@ -476,7 +462,7 @@ cr.define('options.internet', function() {
      */
     updateControls: function() {
       // Note: onc may be undefined when called from a pref update before
-      // initialized in sendNetworkDetails.
+      // initialized in initializeDetailsPage.
       var onc = this.onc_;
 
       // Always show the ipconfig section. TODO(stevenjb): Improve the display
@@ -644,7 +630,7 @@ cr.define('options.internet', function() {
     },
 
     /**
-     * Helper method called from showDetailedInfo and updateConnectionData.
+     * Helper method called from initializeDetailsPage and updateConnectionData.
      * Updates visibility/enabled of the login/disconnect/configure buttons.
      * @private
      */
@@ -683,7 +669,7 @@ cr.define('options.internet', function() {
     },
 
     /**
-     * Helper method called from showDetailedInfo and updateConnectionData.
+     * Helper method called from initializeDetailsPage and updateConnectionData.
      * Updates the connection state property and account / sim card links.
      * @private
      */
@@ -709,7 +695,7 @@ cr.define('options.internet', function() {
           $('sim-card-lock-enabled').checked = lockEnabled;
           $('change-pin').hidden = !lockEnabled;
         }
-        showViewAccount = this.showViewAccountButton_;
+        showViewAccount = onc.getActiveValue('showViewAccountButton');
         var activationState = onc.getActiveValue('Cellular.ActivationState');
         showActivate = activationState == 'NotActivated' ||
             activationState == 'PartiallyActivated';
@@ -723,7 +709,7 @@ cr.define('options.internet', function() {
     },
 
     /**
-     * Helper method called from showDetailedInfo and updateConnectionData.
+     * Helper method called from initializeDetailsPage and updateConnectionData.
      * Updates the fields in the header section of the details frame.
      * @private
      */
@@ -762,7 +748,8 @@ cr.define('options.internet', function() {
     },
 
     /**
-     * Helper method called from showDetailedInfo to initialize the Apn list.
+     * Helper method called from initializeDetailsPage to initialize the Apn
+     * list.
      * @private
      */
     initializeApnList_: function() {
@@ -1079,16 +1066,14 @@ cr.define('options.internet', function() {
 
   DetailsInternetPage.configureNetwork = function() {
     var detailsPage = DetailsInternetPage.getInstance();
-    chrome.send('networkCommand',
-                [detailsPage.type_, detailsPage.servicePath_, 'configure']);
+    chrome.send('configureNetwork', [detailsPage.servicePath_]);
     PageManager.closeOverlay();
   };
 
   DetailsInternetPage.activateFromDetails = function() {
     var detailsPage = DetailsInternetPage.getInstance();
     if (detailsPage.type_ == 'Cellular') {
-      chrome.send('networkCommand',
-                  [detailsPage.type_, detailsPage.servicePath_, 'activate']);
+      chrome.send('activateNetwork', [detailsPage.servicePath_]);
     }
     PageManager.closeOverlay();
   };
@@ -1180,32 +1165,9 @@ cr.define('options.internet', function() {
   };
 
   /**
-   * Method called from Chrome with a dictionary of non ONC configuration
-   * properties, including the HUID and service path to be used for requesting
-   * the ONC properties. Note: currently GUID is only used to confirm that the
-   * selected network still exists. It will be used instead of servicePath
-   * once switching to the networkingPrivate API (see TODO below).
-   * @param {InternetDetailedInfo} info
-   */
-  DetailsInternetPage.showDetailedInfo = function(info) {
-    if (!('GUID' in info)) {
-      // No network was found for, close the overlay.
-      PageManager.closeOverlay();
-      return;
-    }
-    var detailsPage = DetailsInternetPage.getInstance();
-    detailsPage.servicePath_ = info.servicePath;
-    detailsPage.showCarrierSelect_ = info.showCarrierSelect;
-    detailsPage.showViewAccountButton_ = info.showViewAccountButton;
-    // Ask Chrome to call sendNetworkDetails with the ONC properties.
-    // TODO(stevenjb): Use networkingPrivate.getManagedProperties(info.guid).
-    chrome.send('getManagedProperties', [info.servicePath]);
-  };
-
-  /**
    * Method called from Chrome when the ONC properties for the displayed
    * network may have changed.
-   * @param {Object} update The updated ONC dictionary for the network.
+   * @param {Object} oncData The updated ONC dictionary for the network.
    */
   DetailsInternetPage.updateConnectionData = function(oncData) {
     var detailsPage = DetailsInternetPage.getInstance();
@@ -1224,14 +1186,25 @@ cr.define('options.internet', function() {
   };
 
   /**
-   * Method called from Chrome when the initial dictionary of ONC configuration
-   * properties is available.
+   * Method called from Chrome in response to getManagedProperties.
+   * We only use this when we want to call initializeDetailsPage.
+   * TODO(stevenjb): Eliminate when we switch to networkingPrivate
+   * (initializeDetailsPage will be provided as the callback).
+   * @param {Object} oncData Dictionary of ONC properties.
+   */
+  DetailsInternetPage.getManagedPropertiesResult = function(oncData) {
+    DetailsInternetPage.initializeDetailsPage(oncData);
+  };
+
+  /**
+   * Initializes the details page with the provided ONC data.
    * @param {Object} oncData Dictionary of ONC properties.
    */
-  DetailsInternetPage.sendNetworkDetails = function(oncData) {
+  DetailsInternetPage.initializeDetailsPage = function(oncData) {
     var onc = new OncData(oncData);
 
     var detailsPage = DetailsInternetPage.getInstance();
+    detailsPage.servicePath_ = oncData.servicePath;
     detailsPage.onc_ = onc;
     var type = onc.getActiveValue('Type');
     detailsPage.type_ = type;
@@ -1309,7 +1282,9 @@ cr.define('options.internet', function() {
     }
     var savedPrefix = onc.getActiveValue('SavedIPConfig.RoutingPrefix');
     if (savedPrefix != undefined) {
-      var savedNetmask = prefixLengthToNetmask(savedPrefix);
+      assert(typeof savedPrefix == 'number');
+      var savedNetmask = prefixLengthToNetmask(
+          /** @type {number} */(savedPrefix));
       inetNetmask.automatic = savedNetmask;
       inetNetmask.value = savedNetmask;
     }
@@ -1335,7 +1310,9 @@ cr.define('options.internet', function() {
     }
     var staticPrefix = onc.getActiveValue('StaticIPConfig.RoutingPrefix');
     if (staticPrefix != undefined) {
-      var staticNetmask = prefixLengthToNetmask(staticPrefix);
+      assert(typeof staticPrefix == 'number');
+      var staticNetmask = prefixLengthToNetmask(
+          /** @type {number} */(staticPrefix));
       inetNetmask.user = staticNetmask;
       inetNetmask.value = staticNetmask;
     }
@@ -1473,7 +1450,7 @@ cr.define('options.internet', function() {
       var isGsm = onc.getActiveValue('Cellular.Family') == 'GSM';
 
       var currentCarrierIndex = -1;
-      if (this.showCarrierSelect_) {
+      if (loadTimeData.getValue('showCarrierSelect')) {
         var currentCarrier =
             isGsm ? CarrierGenericUMTS : onc.getActiveValue('Cellular.Carrier');
         var supportedCarriers =