Skip to content

Commit

Permalink
Get real tab state using frame script
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Feb 26, 2016
1 parent 7973197 commit 70ceefe
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3464,8 +3464,12 @@ var privateTab = {
return undefined;
},
setTabState: function(tab, isPrivate) {
if(isPrivate === undefined)
isPrivate = this.isPrivateTab(tab);
if(isPrivate === undefined) {
this.isPrivateTabAsync(tab, function(isPrivate) {
this.setTabState(tab, isPrivate);
}, this);
return;
}
if(isPrivate == tab.hasAttribute(this.privateAttr))
return;
if(isPrivate) {
Expand Down Expand Up @@ -4092,6 +4096,25 @@ var privateTab = {
}
return privacyContext.usePrivateBrowsing;
},
isPrivateTabAsync: function(tab, feedback, context) {
var privacyContext = this.getTabPrivacyContext(tab, true);
if(privacyContext) {
feedback.call(context, privacyContext.usePrivateBrowsing);
return;
}
var receiveMessage = function(msg) {
mm.removeMessageListener("PrivateTab:PrivateState", receiveMessage);
feedback.call(context, msg.data.isPrivate);
};
var data = this.trimMultilineString('\
var isPrivate = docShell\n\
.QueryInterface(Components.interfaces.nsILoadContext)\n\
.usePrivateBrowsing;\n\
sendAsyncMessage("PrivateTab:PrivateState", { isPrivate: isPrivate });');
var mm = tab.linkedBrowser.messageManager;
mm.addMessageListener("PrivateTab:PrivateState", receiveMessage);
mm.loadFrameScript("data:application/javascript," + encodeURIComponent(data), true);
},
isPendingTab: function(tab) {
return tab.hasAttribute("pending");
},
Expand Down

0 comments on commit 70ceefe

Please sign in to comment.