Index: background.js |
diff --git a/background.js b/background.js |
index 355905b59296b91571fc4739253be3b1f6dd8be7..2c3ee1b3ac946f1eaba81dd8ac6d3f83338b9f11 100644 |
--- a/background.js |
+++ b/background.js |
@@ -119,7 +119,7 @@ var contextMenuItem = { |
contexts: ["image", "video", "audio"], |
onclick: function(page) |
{ |
- page.sendMessage({type: "clickhide-new-filter"}); |
+ page.sendMessage({type: "blockelement-context-menu-clicked"}); |
} |
}; |
@@ -283,6 +283,39 @@ ext.onMessage.addListener(function (msg, sender, sendResponse) |
{ |
switch (msg.type) |
{ |
+ case "blockelement-open-popup": |
+ var url = ext.getURL("block.html") + "?targetPageId=" + sender.page.id + |
+ "&filters=" + encodeURIComponent(JSON.stringify(msg.filters)); |
+ ext.windows.create({ |
+ url: url, |
+ left: 50, |
+ top: 50, |
+ width: 420, |
+ height: 200, |
+ focused: true, |
+ type: "popup" |
+ }, |
+ function (popupPage) { |
+ var popupPageId = popupPage.id; |
+ function onRemoved(removedPageId) |
+ { |
+ if (popupPageId == removedPageId) |
+ { |
+ sender.page.sendMessage({ |
+ type: "blockelement-popup-closed", |
+ popupId: popupPageId |
+ }); |
+ ext.pages.onRemoved.removeListener(onRemoved); |
+ } |
+ } |
+ ext.pages.onRemoved.addListener(onRemoved); |
+ |
+ sender.page.sendMessage({ |
+ type: "blockelement-popup-opened", |
+ popupId: popupPageId |
+ }); |
+ }); |
+ break; |
case "get-selectors": |
var selectors = []; |
var trace = devtools && devtools.hasPanel(sender.page); |
@@ -402,15 +435,21 @@ ext.onMessage.addListener(function (msg, sender, sendResponse) |
); |
break; |
case "forward": |
- if (sender.page) |
+ var targetPage; |
+ if (msg.targetPageId) |
+ targetPage = ext.getPage(msg.targetPageId); |
+ else |
+ targetPage = sender.page; |
+ |
+ if (targetPage) |
{ |
if (msg.expectsResponse) |
{ |
- sender.page.sendMessage(msg.payload, sendResponse); |
+ targetPage.sendMessage(msg.payload, sendResponse); |
return true; |
} |
- sender.page.sendMessage(msg.payload); |
+ targetPage.sendMessage(msg.payload); |
} |
break; |
} |
@@ -419,7 +458,7 @@ ext.onMessage.addListener(function (msg, sender, sendResponse) |
// update icon when page changes location |
ext.pages.onLoading.addListener(function(page) |
{ |
- page.sendMessage({type: "clickhide-deactivate"}); |
+ page.sendMessage({type: "blockelement-finished"}); |
refreshIconAndContextMenu(page); |
showNextNotificationForUrl(page.url); |
}); |