Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: background.js

Issue 29336084: Issue 2426 - Open block.html as a popup window (Closed)
Patch Set: Reduce callback checking boilerplate Created Feb. 15, 2016, 3:45 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | block.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
});
« no previous file with comments | « no previous file | block.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld