[chrome-gnome-shell] firefox: added local shim for idle permission events.



commit 7946036d06c6d4118f605d942f8d7b679a8d777f
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Wed Mar 21 08:16:24 2018 +0400

    firefox: added local shim for idle permission events.
    
    Mozilla-Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1444294

 extension/include/compat-common.js |   44 +++++++++++++++++++++++++++--------
 extension/include/constants.js     |    2 +
 extension/options.js               |   20 ++++++++++++++++
 3 files changed, 56 insertions(+), 10 deletions(-)
---
diff --git a/extension/include/compat-common.js b/extension/include/compat-common.js
index ca60151..da9ef8d 100644
--- a/extension/include/compat-common.js
+++ b/extension/include/compat-common.js
@@ -11,6 +11,7 @@
 /* global chrome, COMPAT */
 
 COMPAT.PERMISSIONS_CONTAINS            = true;
+COMPAT.PERMISSIONS_EVENTS              = true;
 COMPAT.SYNC_STORAGE                            = (!COMPAT.IS_OPERA || false);
 COMPAT.NOTIFICATIONS_BUTTONS   = (!COMPAT.IS_OPERA && !COMPAT.IS_FIREFOX || false);
 
@@ -31,34 +32,57 @@ if(typeof(chrome.permissions) === 'undefined')
        COMPAT.PERMISSIONS_CONTAINS = false;
 }
 
-if(typeof(chrome.permissions.onAdded) === 'undefined')
+if(typeof(chrome.permissions.onAdded) === 'undefined' || typeof(chrome.permissions.onRemoved) === 
'undefined')
 {
        chrome.permissions.onAdded = {
                addListener: function(callback) {
-                       // Do nothing
+                       chrome.runtime.onMessage.addListener(
+                               function (request, sender, sendResponse) {
+                                       if (sender.id && sender.id === GS_CHROME_ID && request)
+                                       {
+                                               if (request === MESSAGE_IDLE_PERMISSION_ADDED)
+                                               {
+                                                       callback({
+                                                               permissions: ['idle']
+                                                       });
+                                               }
+                                       }
+                               }
+                       );
                },
                removeListener: function(callback) {
-                       // Do nothing
+                       chrome.runtime.onMessage.removeListener(callback);
                },
                hasListener: function(callback) {
-                       // Do nothing
+                       return chrome.runtime.onMessage.hasListener(callback);
                }
        }
-}
 
-if(typeof(chrome.permissions.onRemoved) === 'undefined')
-{
        chrome.permissions.onRemoved = {
                addListener: function(callback) {
-                       // Do nothing
+                       chrome.runtime.onMessage.addListener(
+                               function (request, sender, sendResponse) {
+                                       if (sender.id && sender.id === GS_CHROME_ID && request)
+                                       {
+                                               if (request === MESSAGE_IDLE_PERMISSION_REMOVED)
+                                               {
+                                                       callback({
+                                                               permissions: ['idle']
+                                                       });
+                                               }
+                                       }
+                               }
+                       );
                },
                removeListener: function(callback) {
-                       // Do nothing
+                       chrome.runtime.onMessage.removeListener(callback);
                },
                hasListener: function(callback) {
-                       // Do nothing
+                       return chrome.runtime.onMessage.hasListener(callback);
                }
        }
+
+       COMPAT.PERMISSIONS_EVENTS = false;
 }
 
 if(typeof(chrome.storage.sync) === 'undefined')
diff --git a/extension/include/constants.js b/extension/include/constants.js
index 901dd96..5e33d1d 100644
--- a/extension/include/constants.js
+++ b/extension/include/constants.js
@@ -22,6 +22,8 @@ ALARM_UPDATE_CHECK                    = 'gs-chrome-update-check';
 
 MESSAGE_NEXT_UPDATE_CHANGED            = 'gs-next-update-changed';
 MESSAGE_SYNC_FROM_REMOTE               = 'gs-sync-from-remote';
+MESSAGE_IDLE_PERMISSION_ADDED  = 'gs-idle-added';
+MESSAGE_IDLE_PERMISSION_REMOVED        = 'gs-idle-removed';
 
 SIGNAL_EXTENSION_CHANGED               = 'ExtensionStatusChanged';
 SIGNAL_NOTIFICATION_ACTION             = 'NotificationAction';
diff --git a/extension/options.js b/extension/options.js
index bd4c44c..a5efb2e 100644
--- a/extension/options.js
+++ b/extension/options.js
@@ -277,6 +277,11 @@ function handleSynchronize()
                }, function(granted) {
                        if(granted)
                        {
+                               if(!COMPAT.PERMISSIONS_EVENTS)
+                               {
+                                       chrome.runtime.sendMessage(GS_CHROME_ID, 
MESSAGE_IDLE_PERMISSION_ADDED);
+                               }
+
                                chrome.storage.sync.get({
                                        extensions: {}
                                }, function (options) {
@@ -288,6 +293,11 @@ function handleSynchronize()
                        }
                        else
                        {
+                               if(!COMPAT.PERMISSIONS_EVENTS)
+                               {
+                                       chrome.runtime.sendMessage(GS_CHROME_ID, 
MESSAGE_IDLE_PERMISSION_REMOVED);
+                               }
+
                                setSyncExtensions(false);
                        }
                });
@@ -297,6 +307,11 @@ function handleSynchronize()
                chrome.permissions.remove({
                        permissions: ["idle"]
                }, function(removed) {
+                       if(removed && !COMPAT.PERMISSIONS_EVENTS)
+                       {
+                               chrome.runtime.sendMessage(GS_CHROME_ID, MESSAGE_IDLE_PERMISSION_REMOVED);
+                       }
+
                        setSyncExtensions(!removed);
                });
        }
@@ -375,6 +390,11 @@ document.getElementById('syncChoice').addEventListener('close', function() {
                chrome.permissions.remove({
                        permissions: ["idle"]
                }, function(removed) {
+                       if(removed && !COMPAT.PERMISSIONS_EVENTS)
+                       {
+                               chrome.runtime.sendMessage(GS_CHROME_ID, MESSAGE_IDLE_PERMISSION_REMOVED);
+                       }
+
                        setSyncExtensions(!removed);
                });
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]