Merge lp:~andrew-bugs-launchpad-net/ubufox/flashsaver into lp:~asac/ubufox/main

Proposed by Andrew Sayers
Status: Needs review
Proposed branch: lp:~andrew-bugs-launchpad-net/ubufox/flashsaver
Merge into: lp:~asac/ubufox/main
Diff against target: None lines
To merge this branch: bzr merge lp:~andrew-bugs-launchpad-net/ubufox/flashsaver
Reviewer Review Type Date Requested Status
Alexander Sack Pending
Review via email: mp+6768@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrew Sayers (andrew-bugs-launchpad-net) wrote :

Adobe Flash doesn't currently inhibit the screensaver when playing a video: http://bugs.adobe.com/jira/browse/FP-997?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel).

There's no sign of activity in that bug report, and users are currently working around the bug on their own: http://ubuntuforums.org/showthread.php?t=1090393

This branch includes a simple "flashsaver" which inhibits the screensaver when a Flash window is open. I think this is a better workaround, because it provides more granularity with less user involvement.

If you're interested in the principle, I'd be happy to look into further refinements. For example, the flashsaver could be toggled with a preference setting, or it could only inhibit the screensaver when there's a Flash application in the active window, or when a Flash application was the last thing the user clicked on.

167. By Andrew Sayers <email address hidden>

Now works when installed in /usr/share/ubufox instead of the user's profile directory

168. By Andrew Sayers <email address hidden>

Fixed a bug in the no-screensaver case

Revision history for this message
Andrew Sayers (andrew-bugs-launchpad-net) wrote :

Following discussion in #ubuntu-mozillateam, an improved fix has been proposed to nspluginwrapper:

https://code.launchpad.net/~andrew-bugs-launchpad-net/nspluginwrapper/flashsaver/+merge/7406

The alternate fix more closely resembles Flash's behaviour in Windows, and is likely to cause fewer bugs. Please reject this merge request if/when that merge is completed successfully.

Unmerged revisions

168. By Andrew Sayers <email address hidden>

Fixed a bug in the no-screensaver case

167. By Andrew Sayers <email address hidden>

Now works when installed in /usr/share/ubufox instead of the user's profile directory

166. By Andrew Sayers <email address hidden>

Improved FlashSaver

FlashSaver will now disable the screensaver when at least one Flash object
exists in at least one window.

165. By Andrew Sayers <email address hidden>

Added FlashSaver (initial implementation)

This will disable the screensaver if/when Firefox loads the Flash plugin.

The screensaver is disabled even if no Flash applications are currently running.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'build.sh'
2--- build.sh 2008-07-09 08:42:48 +0000
3+++ build.sh 2009-05-25 02:40:30 +0000
4@@ -63,6 +63,7 @@
5 $BEFORE_BUILD
6
7 mkdir --parents --verbose $TMP_DIR/chrome
8+cp -a chrome/* $TMP_DIR/chrome
9
10 # generate the JAR file, excluding CVS and temporary files
11 JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar
12
13=== added directory 'chrome'
14=== modified file 'chrome.manifest'
15--- chrome.manifest 2009-03-18 19:16:05 +0000
16+++ chrome.manifest 2009-05-23 20:37:28 +0000
17@@ -31,5 +31,6 @@
18 overlay chrome://mozapps/content/extensions/extensions.xul chrome://ubufox/content/ubuntuAddonsOverlay.xul appversion>=3.0b3
19 overlay chrome://mozapps/content/extensions/extensions.xul chrome://ubufox/content/ubuntuAddonsOverlay.ffox2.xul appversion<2.0.0.*
20 overlay chrome://browser/content/browser.xul chrome://ubufox/content/ubuntuAltpluginsOverlay.xul
21+overlay chrome://browser/content/browser.xul chrome://ubufox/content/flashsaver.xul
22
23 override chrome://mozapps/content/plugins/pluginInstallerWizard.xul chrome://ubufox/content/pluginInstallerWizard.xul
24
25=== added file 'chrome/flashsaver.py'
26--- chrome/flashsaver.py 1970-01-01 00:00:00 +0000
27+++ chrome/flashsaver.py 2009-05-25 02:40:30 +0000
28@@ -0,0 +1,103 @@
29+#!/usr/bin/python
30+#
31+# (Dis)inhibit the screensaver
32+
33+LICENSE = '''
34+***** BEGIN LICENSE BLOCK *****
35+ Version: MPL 1.1/GPL 2.0/LGPL 2.1
36+#
37+The contents of this file are subject to the Mozilla Public License Version
38+1.1 (the "License"); you may not use this file except in compliance with
39+the License. You may obtain a copy of the License at
40+http://www.mozilla.org/MPL/
41+
42+Software distributed under the License is distributed on an "AS IS" basis,
43+WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
44+for the specific language governing rights and limitations under the
45+License.
46+#
47+The Original Code is ubufox.
48+
49+The Initial Developer of the Original Code is
50+Canonical Ltd.
51+Portions created by the Initial Developer are Copyright (C) 2008
52+the Initial Developer. All Rights Reserved.
53+
54+Contributor(s):
55+Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
56+Arzhel Younsi <xionox@gmail.com>
57+#
58+Alternatively, the contents of this file may be used under the terms of
59+either the GNU General Public License Version 2 or later (the "GPL"), or
60+the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
61+in which case the provisions of the GPL or the LGPL are applicable instead
62+of those above. If you wish to allow use of your version of this file only
63+under the terms of either the GPL or the LGPL, and not to allow others to
64+use your version of this file under the terms of the MPL, indicate your
65+decision by deleting the provisions above and replace them with the notice
66+and other provisions required by the GPL or the LGPL. If you do not delete
67+the provisions above, a recipient may use your version of this file under
68+the terms of any one of the MPL, the GPL or the LGPL.
69+
70+***** END LICENSE BLOCK *****
71+'''
72+
73+import os, sys, signal
74+
75+pid_file = sys.argv[1] + '/flashsaver.lock'
76+
77+# Clear up any old lock files
78+# (Disinhibiting if necessary)
79+if os.path.exists(pid_file):
80+ pid = int(file(pid_file).readline())
81+ os.unlink(pid_file)
82+ try:
83+ os.kill(pid, signal.SIGTERM)
84+ except:
85+ pass
86+
87+# Unless we're supposed to inhibit, we're done now.
88+if 'inhibit' != sys.argv[2]:
89+ exit(0)
90+
91+# Fork a child process, so the parent can return as soon as it's safe
92+ppid = os.getppid()
93+pid = os.fork()
94+if pid:
95+ open(pid_file, 'w', 0).write(str(pid))
96+ exit(0)
97+
98+# DBus object that will be used to communicate with the screensaver
99+import dbus
100+bus = dbus.SessionBus()
101+
102+class ScreenSaver:
103+ def Inhibit(name, reason):
104+ pass
105+ def Uninhibit(cookie):
106+ pass
107+
108+screensaver = ScreenSaver()
109+
110+try:
111+ # KDE
112+ screensaver = dbus.Interface(bus.get_object("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver"), "org.freedesktop.ScreenSaver")
113+except:
114+ try:
115+ # GNOME
116+ screensaver = dbus.Interface(bus.get_object("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver"), "org.gnome.ScreenSaver")
117+ except:
118+ pass
119+
120+cookie = screensaver.Inhibit("npviewer", "running Flash")
121+
122+import time, os
123+while True:
124+
125+ # Die when Firefox dies
126+ try:
127+ os.kill(ppid, signal.SIG_DFL)
128+ except:
129+ exit(0)
130+
131+ time.sleep(30)
132
133=== added file 'content/flashsaver.css'
134--- content/flashsaver.css 1970-01-01 00:00:00 +0000
135+++ content/flashsaver.css 2009-05-25 02:40:30 +0000
136@@ -0,0 +1,65 @@
137+/* ***** BEGIN LICENSE BLOCK *****
138+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
139+ *
140+ * The contents of this file are subject to the Mozilla Public License Version
141+ * 1.1 (the "License"); you may not use this file except in compliance with
142+ * the License. You may obtain a copy of the License at
143+ * http://www.mozilla.org/MPL/
144+ *
145+ * Software distributed under the License is distributed on an "AS IS" basis,
146+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
147+ * for the specific language governing rights and limitations under the
148+ * License.
149+ *
150+ * The Original Code is ubufox.
151+ *
152+ * The Initial Developer of the Original Code is
153+ * Canonical Ltd.
154+ * Portions created by the Initial Developer are Copyright (C) 2008
155+ * the Initial Developer. All Rights Reserved.
156+ *
157+ * Contributor(s):
158+ * Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
159+ * Arzhel Younsi <xionox@gmail.com>
160+ *
161+ * Alternatively, the contents of this file may be used under the terms of
162+ * either the GNU General Public License Version 2 or later (the "GPL"), or
163+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
164+ * in which case the provisions of the GPL or the LGPL are applicable instead
165+ * of those above. If you wish to allow use of your version of this file only
166+ * under the terms of either the GPL or the LGPL, and not to allow others to
167+ * use your version of this file under the terms of the MPL, indicate your
168+ * decision by deleting the provisions above and replace them with the notice
169+ * and other provisions required by the GPL or the LGPL. If you do not delete
170+ * the provisions above, a recipient may use your version of this file under
171+ * the terms of any one of the MPL, the GPL or the LGPL.
172+ *
173+ * ***** END LICENSE BLOCK ***** */
174+
175+/*
176+ * THE FOLLOWING WAS TAKEN DIRECTLY FROM FLASHBLOCK 1.5.11a2
177+ *
178+ * To update this, copy the equivalent code from flashblock.js, then do:
179+ *
180+ * 1) replace all instances of 'flashblock/content/flashblock' with 'ubufox/content/flashsaver'
181+*/
182+
183+/*
184+ * Flash Click to View by Ted Mielczarek (luser_mozilla@perilith.com)
185+ * Original code by Jesse Ruderman (jruderman@hmc.edu)
186+ * taken from http://www.squarefree.com/userstyles/xbl.html
187+ *
188+ * Change XBL binding for <object> tags, click to view flash
189+ */
190+
191+/*
192+ * Flash identifiers.
193+*/
194+object[classid*=":D27CDB6E-AE6D-11cf-96B8-444553540000"],
195+object[codebase*="swflash.cab"],
196+object[data*=".swf"],
197+embed[type="application/x-shockwave-flash"],
198+embed[src*=".swf"],
199+object[type="application/x-shockwave-flash"],
200+object[src*=".swf"]
201+{ -moz-binding: url("chrome://ubufox/content/flashsaver.xml#flash") !important; }
202
203=== added file 'content/flashsaver.js'
204--- content/flashsaver.js 1970-01-01 00:00:00 +0000
205+++ content/flashsaver.js 2009-05-25 02:40:30 +0000
206@@ -0,0 +1,114 @@
207+/* ***** BEGIN LICENSE BLOCK *****
208+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
209+ *
210+ * The contents of this file are subject to the Mozilla Public License Version
211+ * 1.1 (the "License"); you may not use this file except in compliance with
212+ * the License. You may obtain a copy of the License at
213+ * http://www.mozilla.org/MPL/
214+ *
215+ * Software distributed under the License is distributed on an "AS IS" basis,
216+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
217+ * for the specific language governing rights and limitations under the
218+ * License.
219+ *
220+ * The Original Code is ubufox.
221+ *
222+ * The Initial Developer of the Original Code is
223+ * Canonical Ltd.
224+ * Portions created by the Initial Developer are Copyright (C) 2008
225+ * the Initial Developer. All Rights Reserved.
226+ *
227+ * Contributor(s):
228+ * Doron Rosenberg <doronr@us.ibm.com>
229+ * Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
230+ * Arzhel Younsi <xionox@gmail.com>
231+ *
232+ * Alternatively, the contents of this file may be used under the terms of
233+ * either the GNU General Public License Version 2 or later (the "GPL"), or
234+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
235+ * in which case the provisions of the GPL or the LGPL are applicable instead
236+ * of those above. If you wish to allow use of your version of this file only
237+ * under the terms of either the GPL or the LGPL, and not to allow others to
238+ * use your version of this file under the terms of the MPL, indicate your
239+ * decision by deleting the provisions above and replace them with the notice
240+ * and other provisions required by the GPL or the LGPL. If you do not delete
241+ * the provisions above, a recipient may use your version of this file under
242+ * the terms of any one of the MPL, the GPL or the LGPL.
243+ *
244+ * ***** END LICENSE BLOCK ***** */
245+
246+/* This file inhibits the screensaver when at least one Flash object exists in Firefox */
247+
248+var flashsaver = {
249+
250+ // Run this process to (dis)inhibit the screensaver
251+ process: null,
252+ // Number of currently-active Flash objects
253+ count: 0,
254+ // Location of the user's profile
255+ profD: null,
256+
257+ init: function() {
258+ window.removeEventListener("load", flashsaver, true);
259+
260+ try {
261+ var exec = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
262+
263+ const DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1","nsIProperties");
264+
265+ flashsaver.profD = (new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
266+
267+ exec.initWithPath(
268+ flashsaver.profD +
269+ "/extensions/ubufox@ubuntu.com/chrome/flashsaver.py"
270+ );
271+
272+ if (exec.exists()) {
273+ flashsaver.process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
274+ flashsaver.process.init(exec);
275+ flashsaver.process.run(true, [ flashsaver.profD, 'init' ], 2);
276+ };
277+
278+ } catch (e) {
279+ //alert("Error in flashsaver.init()"); alert(e);
280+ };
281+
282+ /*
283+ THE FOLLOWING WAS TAKEN DIRECTLY FROM FLASHBLOCK 1.5.11a2
284+
285+ To update this, copy the equivalent code from flashblock.js, then
286+ replace all instances of 'flashblock/content/flashblock'
287+ with 'ubufox/content/flashsaver'
288+ */
289+
290+ var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
291+ .getService(Components.interfaces.nsIStyleSheetService);
292+ var ios = Components.classes["@mozilla.org/network/io-service;1"]
293+ .getService(Components.interfaces.nsIIOService);
294+ var u = ios.newURI("chrome://ubufox/content/flashsaver.css", null, null);
295+ if(!sss.sheetRegistered(u, sss.USER_SHEET)) {
296+ sss.loadAndRegisterSheet(u, sss.USER_SHEET);
297+ }
298+
299+ /* END BLATANT THEFT */
300+
301+
302+ },
303+
304+ increment: function() {
305+ if (flashsaver.process !== null && !flashsaver.count++) {
306+ flashsaver.process.run(true, [ flashsaver.profD, 'inhibit' ], 2);
307+ };
308+ },
309+
310+ decrement: function() {
311+ if (flashsaver.file !== null && !--flashsaver.count) {
312+ flashsaver.process.run(true, [ flashsaver.profD, 'uninhibit' ], 2);
313+ };
314+ },
315+
316+};
317+
318+window.addEventListener("load", flashsaver.init, true);
319+document.addEventListener("flashsaver-increment", flashsaver.increment, false, true);
320+document.addEventListener("flashsaver-decrement", flashsaver.decrement, false, true);
321
322=== added file 'content/flashsaver.xml'
323--- content/flashsaver.xml 1970-01-01 00:00:00 +0000
324+++ content/flashsaver.xml 2009-05-25 02:40:30 +0000
325@@ -0,0 +1,74 @@
326+<?xml version="1.0"?>
327+<!-- ***** BEGIN LICENSE BLOCK *****
328+ - Version: MPL 1.1/GPL 2.0/LGPL 2.1
329+ -
330+ - The contents of this file are subject to the Mozilla Public License Version
331+ - 1.1 (the "License"); you may not use this file except in compliance with
332+ - the License. You may obtain a copy of the License at
333+ - http://www.mozilla.org/MPL/
334+ -
335+ - Software distributed under the License is distributed on an "AS IS" basis,
336+ - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
337+ - for the specific language governing rights and limitations under the
338+ - License.
339+ -
340+ - The Original Code is ubufox.
341+ -
342+ - The Initial Developer of the Original Code is
343+ - Canonical Ltd.
344+ - Portions created by the Initial Developer are Copyright (C) 2008
345+ - the Initial Developer. All Rights Reserved.
346+ -
347+ - Contributor(s):
348+ - Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
349+ - Arzhel Younsi <xionox@gmail.com>
350+ -
351+ - Alternatively, the contents of this file may be used under the terms of
352+ - either the GNU General Public License Version 2 or later (the "GPL"), or
353+ - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
354+ - in which case the provisions of the GPL or the LGPL are applicable instead
355+ - of those above. If you wish to allow use of your version of this file only
356+ - under the terms of either the GPL or the LGPL, and not to allow others to
357+ - use your version of this file under the terms of the MPL, indicate your
358+ - decision by deleting the provisions above and replace them with the notice
359+ - and other provisions required by the GPL or the LGPL. If you do not delete
360+ - the provisions above, a recipient may use your version of this file under
361+ - the terms of any one of the MPL, the GPL or the LGPL.
362+ -
363+ - ***** END LICENSE BLOCK ***** -->
364+
365+<bindings
366+ xmlns="http://www.mozilla.org/xbl"
367+ xmlns:html="http://www.w3.org/1999/xhtml"
368+ >
369+
370+ <binding id="flash">
371+ <implementation>
372+ <constructor><![CDATA[
373+ // The destructor won't fire when a tab is closed, so use an unload handler instead
374+ function unloading(e) {
375+ document.flashplayer_unloading = null;
376+ var evt = document.createEvent("Events");
377+ evt.initEvent("flashsaver-decrement", true, false);
378+ window.dispatchEvent(evt);
379+ };
380+ window.addEventListener('beforeunload', unloading, false);
381+ // Signal flashsaver.js to increment the counter
382+ var evt = document.createEvent("Events");
383+ evt.initEvent("flashsaver-increment", true, false);
384+ window.dispatchEvent(evt);
385+ ]]> </constructor>
386+
387+ <destructor> <![CDATA[
388+ // If unloading() hasn't been called, signal flashsaver.js to decrement the counter
389+ if ( ! ( 'flashplayer_unloading' in document ) ) {
390+ var evt = document.createEvent("Events");
391+ evt.initEvent("flashsaver-decrement", true, false);
392+ window.dispatchEvent(evt);
393+ };
394+
395+ ]]> </destructor>
396+ </implementation>
397+</binding>
398+
399+</bindings>
400
401=== added file 'content/flashsaver.xul'
402--- content/flashsaver.xul 1970-01-01 00:00:00 +0000
403+++ content/flashsaver.xul 2009-05-25 02:40:30 +0000
404@@ -0,0 +1,44 @@
405+<?xml version="1.0"?>
406+<!-- ***** BEGIN LICENSE BLOCK *****
407+ - Version: MPL 1.1/GPL 2.0/LGPL 2.1
408+ -
409+ - The contents of this file are subject to the Mozilla Public License Version
410+ - 1.1 (the "License"); you may not use this file except in compliance with
411+ - the License. You may obtain a copy of the License at
412+ - http://www.mozilla.org/MPL/
413+ -
414+ - Software distributed under the License is distributed on an "AS IS" basis,
415+ - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
416+ - for the specific language governing rights and limitations under the
417+ - License.
418+ -
419+ - The Original Code is ubufox.
420+ -
421+ - The Initial Developer of the Original Code is
422+ - Canonical Ltd.
423+ - Portions created by the Initial Developer are Copyright (C) 2008
424+ - the Initial Developer. All Rights Reserved.
425+ -
426+ - Contributor(s):
427+ - Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
428+ - Arzhel Younsi <xionox@gmail.com>
429+ -
430+ - Alternatively, the contents of this file may be used under the terms of
431+ - either the GNU General Public License Version 2 or later (the "GPL"), or
432+ - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
433+ - in which case the provisions of the GPL or the LGPL are applicable instead
434+ - of those above. If you wish to allow use of your version of this file only
435+ - under the terms of either the GPL or the LGPL, and not to allow others to
436+ - use your version of this file under the terms of the MPL, indicate your
437+ - decision by deleting the provisions above and replace them with the notice
438+ - and other provisions required by the GPL or the LGPL. If you do not delete
439+ - the provisions above, a recipient may use your version of this file under
440+ - the terms of any one of the MPL, the GPL or the LGPL.
441+ -
442+ - ***** END LICENSE BLOCK ***** -->
443+
444+<!DOCTYPE overlay>
445+<overlay id="flashsaver-overlay"
446+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
447+ <script type="application/x-javascript" src="chrome://ubufox/content/flashsaver.js" />
448+</overlay>

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: