remoteAPI.js
Go to the documentation of this file.
1 // BEGIN SONGBIRD GPL
2 //
3 // This file is part of the Songbird web player.
4 //
5 // Copyright(c) 2005-2008 POTI, Inc.
6 // http://songbirdnest.com
7 //
8 // This file may be licensed under the terms of of the
9 // GNU General Public License Version 2 (the "GPL").
10 //
11 // Software distributed under the License is distributed
12 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
13 // express or implied. See the GPL for the specific language
14 // governing rights and limitations.
15 //
16 // You should have received a copy of the GPL along with this
17 // program. If not, go to http://www.gnu.org/licenses/gpl.html
18 // or write to the Free Software Foundation, Inc.,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 // END SONGBIRD GPL
22 
24  // the prefs for the checkboxes in the pane
25  // these are both the XUL DOM id and pref key
26  _prefKeys: [
27  'songbird.rapi.playback_control_disable',
28  'songbird.rapi.playback_read_disable',
29  'songbird.rapi.library_read_disable',
30  'songbird.rapi.library_write_disable',
31  ],
32  isChanged: false,
33 
34  configureWhitelist: function (aType, aScope)
35  {
36  // get ref to the properties file string bundle
37  var bundlePreferences = document.getElementById("bundleSongbirdPreferences");
38 
39  // set up a parmater object to pass to permission window
40  var params = {
41  blockVisible: false,
42  sessionVisible: false,
43  allowVisible: true,
44  prefilledHost: (aScope ? aScope : ""),
45  permissionType: "rapi." + aType,
46  windowTitle: bundlePreferences.getString("rapi." + aType + ".permissions_title"),
47  introText: bundlePreferences.getString("rapi." + aType + ".permissions_text"),
48  blocking: {
49  settings: bundlePreferences.getString("rapi." + aType + ".block_settings"),
50  prompt: bundlePreferences.getString("rapi.block_prompt"),
51  pref: "songbird.rapi." + aType + "_notify"
52  },
53  remoteAPIPane: gRemoteAPIPane
54  };
55 
56  // open the permission window to set allow/disallow/session permissions
57  document.documentElement.openWindow("Browser:Permissions",
58  "chrome://browser/content/preferences/permissions.xul",
59  "",
60  params);
61  },
62 
63  updateDisabledState: function() {
64  for (var i=0; i<this._prefKeys.length; i++) {
65  var pref_element = document.getElementById(this._prefKeys[i]);
66  if (!pref_element) {
67  continue;
68  }
69  var button_element = document.getElementById(this._prefKeys[i]+'.button');
70  if (!button_element) {
71  continue;
72  }
73  if (!pref_element.value) {
74  button_element.setAttribute('disabled', 'true');
75  } else {
76  button_element.removeAttribute('disabled');
77  }
78 
79  }
80  },
81 
82  onPaneLoad: function(event) {
83  if (event.target.getAttribute('id') != 'paneRemoteAPI') {
84  // this isn't us
85  return;
86  }
87  window.removeEventListener('paneload', gRemoteAPIPane.onLoad, false);
88  gRemoteAPIPane.updateDisabledState();
89 
90  if (window.pleaseConfigureWhitelist) {
91  gRemoteAPIPane.configureWhitelist(window.pleaseConfigureWhitelist[0],
92  window.pleaseConfigureWhitelist[1]);
93  window.pleaseConfigureWhitelist = null;
94  }
95  },
96 
97  onUnload: function(event) {
98  if (gRemoteAPIPane.isChanged && window.opener && window.opener.document) {
99  var evt = document.createEvent("Events");
100  evt.initEvent("RemoteAPIPermissionChanged", true, false);
101  window.opener.document.dispatchEvent(evt);
102  }
103  },
104 
105  onChange: function(event) {
106  gRemoteAPIPane.updateDisabledState();
107  gRemoteAPIPane.isChanged = true;
108  },
109 
110  restoreDefaults: function() {
111  gRemoteAPIPane.isChanged = true;
112  for (var i=0; i<this._prefKeys.length; i++) {
113  var pref_element = document.getElementById(this._prefKeys[i]);
114  if (!pref_element) {
115  continue;
116  }
117 
118  // because we may be in non instantApply mode, it's not enough to reset
119  // the pref to default, because some controls may have been toggled
120  // yet their associated pref has not changed (that will happen when OK is
121  // pressed in non instantApply mode). Since the pref has not been changed
122  // yet, calling reset on the pref will not do anything.
123  //
124  // So to handle both cases, we first reload the value from the preferences
125  // into the element (which cascades down to any object linked to its pref)
126  // and then we reset anything that's been changed in the prefs to the
127  // factory defaults.
128  if (!pref_element.instantApply) {
129  pref_element.value = pref_element.valueFromPreferences;
130  }
131  if (pref_element.hasUserValue) {
132  pref_element.reset();
133  }
134  }
135  }
136 
137 };
138 
139 window.addEventListener('paneload', gRemoteAPIPane.onPaneLoad, false);
140 window.addEventListener('unload', gRemoteAPIPane.onUnload, false);
141 
var pref
Definition: openLocation.js:44
var event
let window
inst settings prompt
var gRemoteAPIPane
Definition: remoteAPI.js:23
_dialogDatepicker settings
return null
Definition: FeedWriter.js:1143
function onUnload()
onUnload - called when the cover preview window unloads.
Definition: coverPreview.js:36
_getSelectedPageStyle s i