ginebra2/chrome/bedrockchrome/geolocation.snippet/geolocationDialog.js
changeset 16 3c88a81ff781
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
       
     1 /*!
       
     2   \file geolocationDialog.js This module contains GeolocationDialog class which
       
     3   prompts user for accepting/rejection geolocation request.
       
     4 */
       
     5 function GeolocationDialog() {
       
     6 	  var _frame;
       
     7 	  var _page;
       
     8 	
       
     9     var onChromeComplete = function()
       
    10     {
       
    11         // Watch for geolocation permission request. ".bind(this)" is used to resolve amibiguous this pointer.
       
    12         window.pageController.requestGeolocationPermission.connect(
       
    13             function(frame, page, domain) {
       
    14        
       
    15         	      _frame = frame;
       
    16         	      _page = page;
       
    17         	      
       
    18         	      this.showDialog(domain);
       
    19         	      
       
    20             }.bind(this)
       
    21         );
       
    22     }
       
    23     
       
    24     //! Create the html/DOM elements for the Dialog.
       
    25     this.setupPage = function() {
       
    26         var html =
       
    27             '<div class="top"></div>' +
       
    28               '<div class="body">' +
       
    29                 '<div class="geolocationTextLabel" id="geolocationDialogTitle">Location Permissions</div>' +
       
    30                 '<div class="geolocationWarningLabel" id="geolocationDialogWarning"></div>' +
       
    31                 '<div class="geolocationCheckboxTextLabel"><input type="checkbox" id="geolocationCheckboxId"/>' +
       
    32                 '<label id="geolocationCheckboxTextLabelId" onmouseup="GeolocationDialog.toggleCheckbox();"> Save This Setting</label></div>' +
       
    33                 '<div class="controls">' +
       
    34                   '<div type="button" onmouseup="GeolocationDialog.permissionGranted();" class="geolocationAcceptButton"></div>' + 
       
    35                   '<div type="button" onmouseup="GeolocationDialog.permissionDenied();" class="geolocationRejectButton"></div>' +
       
    36                 '</div>' + /*controls*/
       
    37               '</div>' + /*body*/
       
    38             '<div class="bottom"></div>';
       
    39         document.write(html);
       
    40     }
       
    41     
       
    42     //! Show the Dialog to display the request domain and ask user for permission.
       
    43     this.showDialog = function(domain) {
       
    44     	  snippets.BookmarkViewToolbarId.enabled = false;
       
    45         snippets.WebViewToolbarId.enabled = false;
       
    46         
       
    47         // Translate these texts
       
    48         var dialogTitle = document.getElementById("geolocationDialogTitle");
       
    49         dialogTitle.firstChild.nodeValue = window.localeDelegate.translateText("txt_browser_location_dialog_location_permissions");
       
    50                
       
    51     	  var dialogWarning = document.getElementById("geolocationDialogWarning");
       
    52     	  dialogWarning.innerHTML = "Allow " + domain + " to Use Your Location?";
       
    53 	      dialogWarning.firstChild.nodeValue = window.localeDelegate.translateText("txt_browser_location_dialog_allow");
       
    54 	      
       
    55 	      var checkboxTitle = document.getElementById("geolocationCheckboxTextLabelId");
       
    56         checkboxTitle.firstChild.nodeValue= window.localeDelegate.translateText("txt_browser_location_dialog_save_setting");
       
    57 	      
       
    58         window.snippets.GeolocationDialogId.show(false);
       
    59     }
       
    60     
       
    61     //! Hide the Dialog.
       
    62     this.hideDialog = function() {
       
    63         window.snippets.GeolocationDialogId.hide();
       
    64         
       
    65         snippets.BookmarkViewToolbarId.enabled = true;
       
    66         snippets.WebViewToolbarId.enabled = true;
       
    67     }
       
    68     
       
    69     //! Allow the text label for the checkbox to toggle the checkbox
       
    70     GeolocationDialog.toggleCheckbox = function() {
       
    71         document.getElementById("geolocationCheckboxId").checked = !document.getElementById("geolocationCheckboxId").checked;
       
    72     }.bind(this)
       
    73     
       
    74     //! Grant the permission.
       
    75     GeolocationDialog.permissionGranted = function() {
       
    76 	      window.pageController.setGeolocationPermission(_frame, _page, true,
       
    77 	          document.getElementById("geolocationCheckboxId").checked);
       
    78 	          
       
    79 	      document.getElementById("geolocationCheckboxId").checked = false;
       
    80 	      
       
    81 	      this.hideDialog();
       
    82     }.bind(this)
       
    83 
       
    84     //! Deny the permission.
       
    85     GeolocationDialog.permissionDenied = function() {
       
    86 	      window.pageController.setGeolocationPermission(_frame, _page, false,
       
    87 	          document.getElementById("geolocationCheckboxId").checked);
       
    88 	          
       
    89 	      document.getElementById("geolocationCheckboxId").checked = false;
       
    90 	      
       
    91 	      this.hideDialog();
       
    92     }.bind(this)
       
    93     
       
    94     this.setupPage();
       
    95     
       
    96     chrome.chromeComplete.connect(onChromeComplete.bind(this));
       
    97 }