Skip to content

Commit

Permalink
Fix up intercept and filter notification bar
Browse files Browse the repository at this point in the history
Per Felipe's suggestion, replaced timer with a flag set on the
msg.target, which is cleared on pageshow events.
  • Loading branch information
squarewave committed May 10, 2017
1 parent 6076a2b commit 7aec1d9
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions lib/ui.js
Expand Up @@ -176,41 +176,30 @@ function listenOnContentProcessMessages(chromeGlobal) {
// the content process to ourselves.
mm.loadFrameScript(data.url('messageBouncer.js'), true);

let removeNextPluginBar = null;
mm.addMessageListener('PluginSafety:BrowserEventRelay', (msg) => {
if (!msg.data.error && msg.data.type == 'PluginFound' &&
if (msg.data.type == 'PluginFound' &&
msg.data.flashObj.classification.startsWith('ctp-')) {

// We want to ensure that if no notification bar shows up, we don't clobber
// any future legitimate notification bars
const clearRemoveNextPluginBarTimeout = 1000;

// null means that we're okay to set removeNextPluginBar to either true
// undefined means that we're okay to set removeNextPluginBar to either true
// or false. We want to ensure that if any valid ctp- flash objects come
// through, we clear removeNextPluginBar.
if (msg.data.flashObj.path === null && removeNextPluginBar === null) {
removeNextPluginBar = true;

setTimeout(() => {
removeNextPluginBar = null;
}, clearRemoveNextPluginBarTimeout);
if (msg.data.flashObj.path === null && msg.target.removeNextPluginBar === undefined) {
msg.target.removeNextPluginBar = true;
} else if (msg.data.flashObj.path !== null) {
removeNextPluginBar = false;

setTimeout(() => {
removeNextPluginBar = null;
}, clearRemoveNextPluginBarTimeout);
msg.target.removeNextPluginBar = false;
}
} else if (msg.data.type == 'pageshow') {
delete msg.target.removeNextPluginBar;
}
});

mm.addMessageListener('PluginContent:UpdateHiddenPluginUI', (msg) => {
if (removeNextPluginBar) {
removeNextPluginBar = null;
} else {
if (!msg.target.removeNextPluginBar) {
chromeGlobal.gPluginHandler.updateHiddenPluginUI(msg.target,
msg.data.haveInsecure, msg.data.actions, msg.principal, msg.data.location);
}

delete msg.target.removeNextPluginBar;
});

mm.addMessageListener('PluginContent:ShowClickToPlayNotification', (msg) => {
Expand Down Expand Up @@ -318,15 +307,15 @@ function wireUpWindow(win) {

// Clear gPluginHandler from listening to this, because we're going to
// intercept it and filter.
mm.removeMessageListener('PluginContent:UpdateHiddenPluginUI',
chromeGlobal.messageManager.removeMessageListener('PluginContent:UpdateHiddenPluginUI',
chromeGlobal.gPluginHandler);
}

function resetWindow(win) {
const chromeGlobal = viewFor(win);

// Add gPluginHandler back on these messages (see wireUpWindow)
mm.removeMessageListener('PluginContent:UpdateHiddenPluginUI',
chromeGlobal.messageManager.addMessageListener('PluginContent:UpdateHiddenPluginUI',
chromeGlobal.gPluginHandler);
}

Expand Down

1 comment on commit 7aec1d9

@felipc
Copy link

@felipc felipc commented on 7aec1d9 May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Please sign in to comment.