[chrome-gnome-shell] notifications: fixed inter-frame communication



commit abddd4bb1928a06805a0e47253861d1385ddeec9
Author: nE0sIghT <ykonotopov gnome org>
Date:   Wed Feb 22 00:52:32 2017 +0400

    notifications: fixed inter-frame communication
    
    runtime.sendMessage will not send message to sender frame, so we should
    use window.postMessage method to inter-frame communication.
    
    Fixes: https://github.com/nE0sIghT/chrome-gnome-shell-mirror/issues/36

 extension/extension.js             |   14 ++++++--------
 extension/include/notifications.js |    4 ++--
 2 files changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/extension/extension.js b/extension/extension.js
index dfde0b5..ec05739 100644
--- a/extension/extension.js
+++ b/extension/extension.js
@@ -153,19 +153,17 @@ port.onMessage.addListener(function (message) {
  */
 port.postMessage({execute: 'subscribeSignals'});
 
-chrome.runtime.onMessage.addListener(
-       function (request, sender, sendResponse) {
-               if(
-                       sender.id && sender.id === GS_CHROME_ID &&
-                       request && request.execute)
+window.addEventListener("message", function (event) {
+               // We only accept messages from ourselves
+               if (event.source == window && event.data && event.data.execute)
                {
-                       switch (request.execute)
+                       switch (event.data.execute)
                        {
                                case 'createNotification':
-                                       port.postMessage(request);
+                                       port.postMessage(event.data);
                                        break;
                                case 'removeNotification':
-                                       port.postMessage(request);
+                                       port.postMessage(event.data);
                                        break;
                        }
                }
diff --git a/extension/include/notifications.js b/extension/include/notifications.js
index b7ea6ab..0e70999 100644
--- a/extension/include/notifications.js
+++ b/extension/include/notifications.js
@@ -172,11 +172,11 @@ GSC.notifications = (function($) {
                function create(name, options) {
                        options = remove_list(options);
 
-                       chrome.runtime.sendMessage({
+                       window.postMessage({
                                execute: 'createNotification',
                                name: name,
                                options: $.extend(DEFAULT_NOTIFICATION_OPTIONS, options)
-                       });
+                       }, "*");
                }
 
                function remove(notificationId) {


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