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
=== modified file 'build.sh'
--- build.sh 2008-07-09 08:42:48 +0000
+++ build.sh 2009-05-25 02:40:30 +0000
@@ -63,6 +63,7 @@
63$BEFORE_BUILD63$BEFORE_BUILD
6464
65mkdir --parents --verbose $TMP_DIR/chrome65mkdir --parents --verbose $TMP_DIR/chrome
66cp -a chrome/* $TMP_DIR/chrome
6667
67# generate the JAR file, excluding CVS and temporary files68# generate the JAR file, excluding CVS and temporary files
68JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar69JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar
6970
=== added directory 'chrome'
=== modified file 'chrome.manifest'
--- chrome.manifest 2009-03-18 19:16:05 +0000
+++ chrome.manifest 2009-05-23 20:37:28 +0000
@@ -31,5 +31,6 @@
31overlay chrome://mozapps/content/extensions/extensions.xul chrome://ubufox/content/ubuntuAddonsOverlay.xul appversion>=3.0b331overlay chrome://mozapps/content/extensions/extensions.xul chrome://ubufox/content/ubuntuAddonsOverlay.xul appversion>=3.0b3
32overlay chrome://mozapps/content/extensions/extensions.xul chrome://ubufox/content/ubuntuAddonsOverlay.ffox2.xul appversion<2.0.0.*32overlay chrome://mozapps/content/extensions/extensions.xul chrome://ubufox/content/ubuntuAddonsOverlay.ffox2.xul appversion<2.0.0.*
33overlay chrome://browser/content/browser.xul chrome://ubufox/content/ubuntuAltpluginsOverlay.xul33overlay chrome://browser/content/browser.xul chrome://ubufox/content/ubuntuAltpluginsOverlay.xul
34overlay chrome://browser/content/browser.xul chrome://ubufox/content/flashsaver.xul
3435
35override chrome://mozapps/content/plugins/pluginInstallerWizard.xul chrome://ubufox/content/pluginInstallerWizard.xul36override chrome://mozapps/content/plugins/pluginInstallerWizard.xul chrome://ubufox/content/pluginInstallerWizard.xul
3637
=== added file 'chrome/flashsaver.py'
--- chrome/flashsaver.py 1970-01-01 00:00:00 +0000
+++ chrome/flashsaver.py 2009-05-25 02:40:30 +0000
@@ -0,0 +1,103 @@
1#!/usr/bin/python
2#
3# (Dis)inhibit the screensaver
4
5LICENSE = '''
6***** BEGIN LICENSE BLOCK *****
7 Version: MPL 1.1/GPL 2.0/LGPL 2.1
8#
9The contents of this file are subject to the Mozilla Public License Version
101.1 (the "License"); you may not use this file except in compliance with
11the License. You may obtain a copy of the License at
12http://www.mozilla.org/MPL/
13
14Software distributed under the License is distributed on an "AS IS" basis,
15WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16for the specific language governing rights and limitations under the
17License.
18#
19The Original Code is ubufox.
20
21The Initial Developer of the Original Code is
22Canonical Ltd.
23Portions created by the Initial Developer are Copyright (C) 2008
24the Initial Developer. All Rights Reserved.
25
26Contributor(s):
27Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
28Arzhel Younsi <xionox@gmail.com>
29#
30Alternatively, the contents of this file may be used under the terms of
31either the GNU General Public License Version 2 or later (the "GPL"), or
32the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33in which case the provisions of the GPL or the LGPL are applicable instead
34of those above. If you wish to allow use of your version of this file only
35under the terms of either the GPL or the LGPL, and not to allow others to
36use your version of this file under the terms of the MPL, indicate your
37decision by deleting the provisions above and replace them with the notice
38and other provisions required by the GPL or the LGPL. If you do not delete
39the provisions above, a recipient may use your version of this file under
40the terms of any one of the MPL, the GPL or the LGPL.
41
42***** END LICENSE BLOCK *****
43'''
44
45import os, sys, signal
46
47pid_file = sys.argv[1] + '/flashsaver.lock'
48
49# Clear up any old lock files
50# (Disinhibiting if necessary)
51if os.path.exists(pid_file):
52 pid = int(file(pid_file).readline())
53 os.unlink(pid_file)
54 try:
55 os.kill(pid, signal.SIGTERM)
56 except:
57 pass
58
59# Unless we're supposed to inhibit, we're done now.
60if 'inhibit' != sys.argv[2]:
61 exit(0)
62
63# Fork a child process, so the parent can return as soon as it's safe
64ppid = os.getppid()
65pid = os.fork()
66if pid:
67 open(pid_file, 'w', 0).write(str(pid))
68 exit(0)
69
70# DBus object that will be used to communicate with the screensaver
71import dbus
72bus = dbus.SessionBus()
73
74class ScreenSaver:
75 def Inhibit(name, reason):
76 pass
77 def Uninhibit(cookie):
78 pass
79
80screensaver = ScreenSaver()
81
82try:
83 # KDE
84 screensaver = dbus.Interface(bus.get_object("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver"), "org.freedesktop.ScreenSaver")
85except:
86 try:
87 # GNOME
88 screensaver = dbus.Interface(bus.get_object("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver"), "org.gnome.ScreenSaver")
89 except:
90 pass
91
92cookie = screensaver.Inhibit("npviewer", "running Flash")
93
94import time, os
95while True:
96
97 # Die when Firefox dies
98 try:
99 os.kill(ppid, signal.SIG_DFL)
100 except:
101 exit(0)
102
103 time.sleep(30)
0104
=== added file 'content/flashsaver.css'
--- content/flashsaver.css 1970-01-01 00:00:00 +0000
+++ content/flashsaver.css 2009-05-25 02:40:30 +0000
@@ -0,0 +1,65 @@
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is ubufox.
15 *
16 * The Initial Developer of the Original Code is
17 * Canonical Ltd.
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
23 * Arzhel Younsi <xionox@gmail.com>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39/*
40 * THE FOLLOWING WAS TAKEN DIRECTLY FROM FLASHBLOCK 1.5.11a2
41 *
42 * To update this, copy the equivalent code from flashblock.js, then do:
43 *
44 * 1) replace all instances of 'flashblock/content/flashblock' with 'ubufox/content/flashsaver'
45*/
46
47/*
48 * Flash Click to View by Ted Mielczarek (luser_mozilla@perilith.com)
49 * Original code by Jesse Ruderman (jruderman@hmc.edu)
50 * taken from http://www.squarefree.com/userstyles/xbl.html
51 *
52 * Change XBL binding for <object> tags, click to view flash
53 */
54
55/*
56 * Flash identifiers.
57*/
58object[classid*=":D27CDB6E-AE6D-11cf-96B8-444553540000"],
59object[codebase*="swflash.cab"],
60object[data*=".swf"],
61embed[type="application/x-shockwave-flash"],
62embed[src*=".swf"],
63object[type="application/x-shockwave-flash"],
64object[src*=".swf"]
65{ -moz-binding: url("chrome://ubufox/content/flashsaver.xml#flash") !important; }
066
=== added file 'content/flashsaver.js'
--- content/flashsaver.js 1970-01-01 00:00:00 +0000
+++ content/flashsaver.js 2009-05-25 02:40:30 +0000
@@ -0,0 +1,114 @@
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is ubufox.
15 *
16 * The Initial Developer of the Original Code is
17 * Canonical Ltd.
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Doron Rosenberg <doronr@us.ibm.com>
23 * Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
24 * Arzhel Younsi <xionox@gmail.com>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40/* This file inhibits the screensaver when at least one Flash object exists in Firefox */
41
42var flashsaver = {
43
44 // Run this process to (dis)inhibit the screensaver
45 process: null,
46 // Number of currently-active Flash objects
47 count: 0,
48 // Location of the user's profile
49 profD: null,
50
51 init: function() {
52 window.removeEventListener("load", flashsaver, true);
53
54 try {
55 var exec = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
56
57 const DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1","nsIProperties");
58
59 flashsaver.profD = (new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
60
61 exec.initWithPath(
62 flashsaver.profD +
63 "/extensions/ubufox@ubuntu.com/chrome/flashsaver.py"
64 );
65
66 if (exec.exists()) {
67 flashsaver.process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
68 flashsaver.process.init(exec);
69 flashsaver.process.run(true, [ flashsaver.profD, 'init' ], 2);
70 };
71
72 } catch (e) {
73 //alert("Error in flashsaver.init()"); alert(e);
74 };
75
76 /*
77 THE FOLLOWING WAS TAKEN DIRECTLY FROM FLASHBLOCK 1.5.11a2
78
79 To update this, copy the equivalent code from flashblock.js, then
80 replace all instances of 'flashblock/content/flashblock'
81 with 'ubufox/content/flashsaver'
82 */
83
84 var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
85 .getService(Components.interfaces.nsIStyleSheetService);
86 var ios = Components.classes["@mozilla.org/network/io-service;1"]
87 .getService(Components.interfaces.nsIIOService);
88 var u = ios.newURI("chrome://ubufox/content/flashsaver.css", null, null);
89 if(!sss.sheetRegistered(u, sss.USER_SHEET)) {
90 sss.loadAndRegisterSheet(u, sss.USER_SHEET);
91 }
92
93 /* END BLATANT THEFT */
94
95
96 },
97
98 increment: function() {
99 if (flashsaver.process !== null && !flashsaver.count++) {
100 flashsaver.process.run(true, [ flashsaver.profD, 'inhibit' ], 2);
101 };
102 },
103
104 decrement: function() {
105 if (flashsaver.file !== null && !--flashsaver.count) {
106 flashsaver.process.run(true, [ flashsaver.profD, 'uninhibit' ], 2);
107 };
108 },
109
110};
111
112window.addEventListener("load", flashsaver.init, true);
113document.addEventListener("flashsaver-increment", flashsaver.increment, false, true);
114document.addEventListener("flashsaver-decrement", flashsaver.decrement, false, true);
0115
=== added file 'content/flashsaver.xml'
--- content/flashsaver.xml 1970-01-01 00:00:00 +0000
+++ content/flashsaver.xml 2009-05-25 02:40:30 +0000
@@ -0,0 +1,74 @@
1<?xml version="1.0"?>
2<!-- ***** BEGIN LICENSE BLOCK *****
3 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 -
5 - The contents of this file are subject to the Mozilla Public License Version
6 - 1.1 (the "License"); you may not use this file except in compliance with
7 - the License. You may obtain a copy of the License at
8 - http://www.mozilla.org/MPL/
9 -
10 - Software distributed under the License is distributed on an "AS IS" basis,
11 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 - for the specific language governing rights and limitations under the
13 - License.
14 -
15 - The Original Code is ubufox.
16 -
17 - The Initial Developer of the Original Code is
18 - Canonical Ltd.
19 - Portions created by the Initial Developer are Copyright (C) 2008
20 - the Initial Developer. All Rights Reserved.
21 -
22 - Contributor(s):
23 - Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
24 - Arzhel Younsi <xionox@gmail.com>
25 -
26 - Alternatively, the contents of this file may be used under the terms of
27 - either the GNU General Public License Version 2 or later (the "GPL"), or
28 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 - in which case the provisions of the GPL or the LGPL are applicable instead
30 - of those above. If you wish to allow use of your version of this file only
31 - under the terms of either the GPL or the LGPL, and not to allow others to
32 - use your version of this file under the terms of the MPL, indicate your
33 - decision by deleting the provisions above and replace them with the notice
34 - and other provisions required by the GPL or the LGPL. If you do not delete
35 - the provisions above, a recipient may use your version of this file under
36 - the terms of any one of the MPL, the GPL or the LGPL.
37 -
38 - ***** END LICENSE BLOCK ***** -->
39
40<bindings
41 xmlns="http://www.mozilla.org/xbl"
42 xmlns:html="http://www.w3.org/1999/xhtml"
43 >
44
45 <binding id="flash">
46 <implementation>
47 <constructor><![CDATA[
48 // The destructor won't fire when a tab is closed, so use an unload handler instead
49 function unloading(e) {
50 document.flashplayer_unloading = null;
51 var evt = document.createEvent("Events");
52 evt.initEvent("flashsaver-decrement", true, false);
53 window.dispatchEvent(evt);
54 };
55 window.addEventListener('beforeunload', unloading, false);
56 // Signal flashsaver.js to increment the counter
57 var evt = document.createEvent("Events");
58 evt.initEvent("flashsaver-increment", true, false);
59 window.dispatchEvent(evt);
60 ]]> </constructor>
61
62 <destructor> <![CDATA[
63 // If unloading() hasn't been called, signal flashsaver.js to decrement the counter
64 if ( ! ( 'flashplayer_unloading' in document ) ) {
65 var evt = document.createEvent("Events");
66 evt.initEvent("flashsaver-decrement", true, false);
67 window.dispatchEvent(evt);
68 };
69
70 ]]> </destructor>
71 </implementation>
72</binding>
73
74</bindings>
075
=== added file 'content/flashsaver.xul'
--- content/flashsaver.xul 1970-01-01 00:00:00 +0000
+++ content/flashsaver.xul 2009-05-25 02:40:30 +0000
@@ -0,0 +1,44 @@
1<?xml version="1.0"?>
2<!-- ***** BEGIN LICENSE BLOCK *****
3 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 -
5 - The contents of this file are subject to the Mozilla Public License Version
6 - 1.1 (the "License"); you may not use this file except in compliance with
7 - the License. You may obtain a copy of the License at
8 - http://www.mozilla.org/MPL/
9 -
10 - Software distributed under the License is distributed on an "AS IS" basis,
11 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 - for the specific language governing rights and limitations under the
13 - License.
14 -
15 - The Original Code is ubufox.
16 -
17 - The Initial Developer of the Original Code is
18 - Canonical Ltd.
19 - Portions created by the Initial Developer are Copyright (C) 2008
20 - the Initial Developer. All Rights Reserved.
21 -
22 - Contributor(s):
23 - Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
24 - Arzhel Younsi <xionox@gmail.com>
25 -
26 - Alternatively, the contents of this file may be used under the terms of
27 - either the GNU General Public License Version 2 or later (the "GPL"), or
28 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 - in which case the provisions of the GPL or the LGPL are applicable instead
30 - of those above. If you wish to allow use of your version of this file only
31 - under the terms of either the GPL or the LGPL, and not to allow others to
32 - use your version of this file under the terms of the MPL, indicate your
33 - decision by deleting the provisions above and replace them with the notice
34 - and other provisions required by the GPL or the LGPL. If you do not delete
35 - the provisions above, a recipient may use your version of this file under
36 - the terms of any one of the MPL, the GPL or the LGPL.
37 -
38 - ***** END LICENSE BLOCK ***** -->
39
40<!DOCTYPE overlay>
41<overlay id="flashsaver-overlay"
42 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
43 <script type="application/x-javascript" src="chrome://ubufox/content/flashsaver.js" />
44</overlay>

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: