| OLD | NEW | 
|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> | 
| 2 <html> | 2 <html> | 
| 3 <head> | 3 <head> | 
| 4   <script> | 4   <link href="popup.css" rel="stylesheet" type="text/css"> | 
| 5 var pref = chrome.experimental.contentSettings.global.referrersEnabled; | 5   <script src="popup.js"></script> | 
|  | 6 </head> | 
|  | 7 <body> | 
| 6 | 8 | 
| 7 /** | 9 <div id="container"> | 
| 8  * Returns whether the |levelOfControl| means that the extension can change the | 10   <input type="checkbox" id="regularValue" /> | 
| 9  * preference value. | 11   Enable referrers | 
| 10  * | 12   <div id="incognito"> | 
| 11  * @param levelOfControl{string} | 13     <input type="checkbox" id="useSeparateIncognitoSettings" /> | 
| 12  */ | 14     Use separate setting for incognito mode: | 
| 13 function settingIsControllable(levelOfControl) { | 15     <br> | 
| 14   return (levelOfControl == "controllable_by_this_extension" || | 16     <input type="checkbox" id="incognitoValue" disabled="disabled"/> | 
| 15           levelOfControl == "controlled_by_this_extension"); | 17     Enable referrers in incognito sessions | 
| 16 } | 18   </div> | 
| 17 | 19   <div id="incognito-forbidden"> | 
| 18 /** | 20     Select "Allow in incognito" to access incognito preferences | 
| 19  * Updates the UI to reflect the state of the preference. | 21   </div> | 
| 20  * |  | 
| 21  * @param settings{object} A settings object, as returned from |get()| or the |  | 
| 22  * |onchange| event. |  | 
| 23  */ |  | 
| 24 function updateUI(settings) { |  | 
| 25   var disableUI = !settingIsControllable(settings.levelOfControl); |  | 
| 26   document.getElementById("regularValue").disabled = disableUI; |  | 
| 27   document.getElementById("useSeparateIncognitoSettings").disabled = disableUI; |  | 
| 28   if (settings.hasOwnProperty('incognitoSpecific')) { |  | 
| 29     var hasIncognitoValue = settings.incognitoSpecific; |  | 
| 30     document.getElementById("useSeparateIncognitoSettings").checked = |  | 
| 31         hasIncognitoValue; |  | 
| 32     document.getElementById("incognitoValue").disabled = |  | 
| 33         disableUI || !hasIncognitoValue; |  | 
| 34     document.getElementById("incognitoValue").checked = settings.value; |  | 
| 35   } else { |  | 
| 36     document.getElementById("regularValue").checked = settings.value; |  | 
| 37   } |  | 
| 38 } |  | 
| 39 |  | 
| 40 /** |  | 
| 41  * Wrapper for |updateUI| which is used as callback for the |get()| method and |  | 
| 42  * which logs the result. |  | 
| 43  * If there was an error getting the preference, does nothing. |  | 
| 44  * |  | 
| 45  * @param settings{object} A settings object, as returned from |get()|. |  | 
| 46  */ |  | 
| 47 function updateUIFromGet(settings) { |  | 
| 48   if (settings) { |  | 
| 49     console.log('pref.get result:' + JSON.stringify(settings)); |  | 
| 50     updateUI(settings); |  | 
| 51   } |  | 
| 52 } |  | 
| 53 |  | 
| 54 /** |  | 
| 55  * Wrapper for |updateUI| which is used as handler for the |onchange| event |  | 
| 56  * and which logs the result. |  | 
| 57  * |  | 
| 58  * @param settings{object} A settings object, as returned from the |onchange| |  | 
| 59  * event. |  | 
| 60  */ |  | 
| 61 function updateUIFromOnChange(settings) { |  | 
| 62   console.log('pref.onChange event:' + JSON.stringify(settings)); |  | 
| 63   updateUI(settings); |  | 
| 64 } |  | 
| 65 |  | 
| 66 /* |  | 
| 67  * Initializes the UI. |  | 
| 68  */ |  | 
| 69 function init() { |  | 
| 70   chrome.extension.isAllowedIncognitoAccess(function(allowed) { |  | 
| 71     if (allowed) { |  | 
| 72       pref.get({'incognito': true}, updateUIFromGet); |  | 
| 73       document.getElementById("incognito").style.display = "block"; |  | 
| 74       document.getElementById("incognito-forbidden").style.display = "none"; |  | 
| 75     } |  | 
| 76   }); |  | 
| 77   pref.get({}, updateUIFromGet); |  | 
| 78   pref.onChange.addListener(updateUIFromOnChange); |  | 
| 79 } |  | 
| 80 |  | 
| 81 /** |  | 
| 82  * Called from the UI to change the preference value. |  | 
| 83  * |  | 
| 84  * @param enabled{boolean} The new preference value. |  | 
| 85  * @param incognito{boolean} Whether the value is specific to incognito mode. |  | 
| 86  */ |  | 
| 87 function setPrefValue(enabled, incognito) { |  | 
| 88   var scope = incognito ? 'incognito_session_only' : 'regular'; |  | 
| 89   pref.set({'value': enabled, 'scope': scope}); |  | 
| 90 } |  | 
| 91 |  | 
| 92 /** |  | 
| 93  * Called from the UI to change whether to use separate settings for |  | 
| 94  * incognito mode. |  | 
| 95  * |  | 
| 96  * @param value{boolean} whether to use separate settings for |  | 
| 97  * incognito mode. |  | 
| 98  */ |  | 
| 99 function setUseSeparateIncognitoSettings(value) { |  | 
| 100   if (!value) { |  | 
| 101     pref.clear({'incognito': true}); |  | 
| 102   } else { |  | 
| 103     // Explicitly set the value for incognito mode. |  | 
| 104     pref.get({'incognito': true}, function(settings) { |  | 
| 105       pref.set({'incognito': true, 'value': settings.value}); |  | 
| 106     }); |  | 
| 107   } |  | 
| 108   document.getElementById("incognitoValue").disabled = !value; |  | 
| 109 } |  | 
| 110 |  | 
| 111   </script> |  | 
| 112 </head> |  | 
| 113 <body onload="init()"> |  | 
| 114 |  | 
| 115 <div style="width: 300px"> |  | 
| 116 <input type="checkbox" onclick="setPrefValue(this.checked)" id="regularValue" />
      Enable referrers |  | 
| 117 |  | 
| 118 <div id="incognito" style="display:none"> |  | 
| 119 <input type="checkbox" onclick="setUseSeparateIncognitoSettings(this.checked)" i
     d="useSeparateIncognitoSettings" /> Use separate setting for incognito mode: |  | 
| 120 <br> |  | 
| 121 <input type="checkbox" onclick="setPrefValue(this.checked, true)" id="incognitoV
     alue" disabled="disabled"/> Enable referrers in incognito sessions |  | 
| 122 </div> |  | 
| 123 <div id="incognito-forbidden"> |  | 
| 124 Select "Allow in incognito" to access incognito preferences |  | 
| 125 </div> |  | 
| 126 </div> | 22 </div> | 
| 127 | 23 | 
| 128 </body> | 24 </body> | 
| 129 </html> | 25 </html> | 
| OLD | NEW | 
|---|