Skip to content

Commit

Permalink
Fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Jul 16, 2015
1 parent 421d154 commit 9e24a5a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 22 deletions.
46 changes: 32 additions & 14 deletions Extension/browser/firefox/lib/contentPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ var WebRequestHelper = exports.WebRequestHelper = {
* @returns XUL tab
*/
getTabForChannel: function (channel) {
var browser = this.getBrowserForChannel(channel);
if (browser) {
return tabUtils.getTabForBrowser(browser);
var contextData = this.getChannelContextData(channel);
if (contextData && contextData.tab) {
return contextData.tab;
}
if (contextData && contextData.browser) {
return tabUtils.getTabForBrowser(contextData.browser);
}
return null;
},
Expand Down Expand Up @@ -203,10 +206,13 @@ var WebRequestHelper = exports.WebRequestHelper = {
* We've used a method from HTTPS Everywhere to fix e10s incompatibility:
* https://github.com/pde/https-everywhere/blob/1afa2d65874403c7c89ce8af320bbd79b0827823/src/components/https-everywhere.js
*
* Returns an instance of https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/browser.
* Also returns DOMWindow, tab and contentWindow if possible.
*
* @param channel nsIChannel implementation
* @returns An instance of https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/browser
* @returns {*}
*/
getBrowserForChannel: function (channel) {
getChannelContextData: function (channel) {
let topFrameElement, associatedWindow;
let spec = channel.URI.spec;
let loadContext = this._getLoadContext(channel);
Expand All @@ -233,7 +239,9 @@ var WebRequestHelper = exports.WebRequestHelper = {
if (!associatedWindow) {
WorkaroundUtils.setMultiProcessFirefoxMode(true);
}
return topFrameElement;
return {
browser: topFrameElement
};
} else if (associatedWindow) {
// For non-e10s Firefox, get the XUL <browser> element using this rather
// magical / opaque code cribbed from
Expand All @@ -257,9 +265,14 @@ var WebRequestHelper = exports.WebRequestHelper = {
// of the firefox window, aTab.linkedBrowser is same as browser var above
// this is the browser within the tab
if (aTab) {
return aTab.linkedBrowser;
return {
tab: aTab,
browser: aTab.linkedBrowser,
DOMWindow: aDOMWindow,
contentWindow: contentWindow
};
} else {
Log.debug("getBrowserForChannel: aTab was null for " + spec);
Log.debug("getChannelContextData: aTab was null for " + spec);
return null;
}
} else if (aDOMWindow.BrowserApp) {
Expand All @@ -273,17 +286,22 @@ var WebRequestHelper = exports.WebRequestHelper = {
// Also TODO: Where are these log messages going? They don't show up in remote debug console.
var mTab = aDOMWindow.BrowserApp.getTabForWindow(contentWindow.top);
if (mTab) {
return mTab.browser;
return {
tab: mTab,
browser: mTab.browser,
DOMWindow: aDOMWindow,
contentWindow: contentWindow
};
} else {
Log.error("getBrowserForChannel: mTab was null for " + spec);
Log.error("getChannelContextData: mTab was null for " + spec);
return null;
}
} else {
Log.error("getBrowserForChannel: No gBrowser and no BrowserApp for " + spec);
Log.error("getChannelContextData: No gBrowser and no BrowserApp for " + spec);
return null;
}
} else {
Log.debug("getBrowserForChannel: No loadContext for " + spec);
Log.debug("getChannelContextData: No loadContext for " + spec);
return null;
}
},
Expand Down Expand Up @@ -543,7 +561,7 @@ var WebRequestImpl = exports.WebRequestImpl = {
} else if (!requestType) {
requestType = RequestTypes.OTHER;
}
isMainFrame = (requestType == RequestTypes.DOCUMENT);
var isMainFrame = (requestType == RequestTypes.DOCUMENT);

// We record frame data here because shouldLoad is not always called (shouldLoad issue)
if (isMainFrame) {
Expand Down Expand Up @@ -722,7 +740,7 @@ var WebRequestImpl = exports.WebRequestImpl = {
//TODO: check for not http
if (this.framesMap.isTabAdguardDetected(tab) ||
this.framesMap.isTabProtectionDisabled(tab) ||
this.framesMap.isTabWhiteListed(tab)) {
this.framesMap.isTabWhiteListedForSafebrowsing(tab)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Extension/browser/firefox/lib/elemHide.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ ElemHide = exports.ElemHide = {

/**
* In case of e10s we use the same way as in Chromium - blocked elements are collapsed in content script.
* In single process mode blocked elements are collapsed in the elements.
* In single process mode blocked elements are collapsed by content policy.
*/
if (WorkaroundUtils.isMultiProcessFirefoxMode()) {
var collapse = this.webRequestService.processShouldCollapse(worker.tab, message.elementUrl, message.documentUrl, message.requestType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var ext, BaseEvent, OnMessageEvent, sendMessage;

defaultLocale: 'en',

supportedLocales: ['ru', 'en', 'tr', 'uk', 'de', 'pl', 'pt_BR', 'pt_PT', 'ko', 'zh_CN', 'sr', 'fr', 'sk', 'hy'],
supportedLocales: ['ru', 'en', 'tr', 'uk', 'de', 'pl', 'pt_BR', 'pt_PT', 'ko', 'zh_CN', 'sr', 'fr', 'sk', 'hy', 'es', 'es_419', 'it', 'id'],

_getLocale: function () {
var prefix = navigator.language;
Expand Down
18 changes: 12 additions & 6 deletions Extension/browser/webkit/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function onHeadersReceived(requestDetails) {

function filterSafebrowsing(tab, mainFrameUrl) {

if (framesMap.isTabAdguardDetected(tab) || framesMap.isTabProtectionDisabled(tab) || framesMap.isTabWhiteListed(tab)) {
if (framesMap.isTabAdguardDetected(tab) || framesMap.isTabProtectionDisabled(tab) || framesMap.isTabWhiteListedForSafebrowsing(tab)) {
return;
}

Expand All @@ -108,11 +108,17 @@ function filterSafebrowsing(tab, mainFrameUrl) {
var incognitoTab = framesMap.isIncognitoTab(tab);

antiBannerService.getRequestFilter().checkSafebrowsingFilter(mainFrameUrl, referrerUrl, function (safebrowsingUrl) {
UI.openTab(safebrowsingUrl, {
onOpen: function () {
tab.close();
}
});
// Chrome doesn't allow open extension url in incognito mode
// So close current tab and open new
if (incognitoTab && !Utils.isSafariBrowser()) {
UI.openTab(safebrowsingUrl, {
onOpen: function () {
tab.close();
}
});
} else {
tab.reload(safebrowsingUrl);
}
}, incognitoTab);
}

Expand Down
4 changes: 4 additions & 0 deletions Extension/lib/filter/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ WhiteListService.prototype = {
}
},

isDefaultMode: function () {
return this.defaultWhiteListMode;
},

changeDefaultWhiteListMode: function (defaultWhiteListMode) {
this.defaultWhiteListMode = defaultWhiteListMode;
userSettings.changeDefaultWhiteListMode(defaultWhiteListMode);
Expand Down
9 changes: 9 additions & 0 deletions Extension/lib/utils/frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ var FramesMap = exports.FramesMap = function (antiBannerService, BrowserTabsClas
return frameData && frameData.frameWhiteListRule;
};

/**
* @param tab Tab
* @returns true if Tab have white list rule and white list isn't invert
*/
this.isTabWhiteListedForSafebrowsing = function (tab) {
var frameData = this.getMainFrame(tab);
return frameData && frameData.frameWhiteListRule && whiteListService.isDefaultMode();
};

/**
* @param tab Tab
* @returns true if protection is paused
Expand Down

0 comments on commit 9e24a5a

Please sign in to comment.