260 return False |
260 return False |
261 |
261 |
262 errorPage = sip.cast(output, QWebPage.ErrorPageExtensionReturn) |
262 errorPage = sip.cast(output, QWebPage.ErrorPageExtensionReturn) |
263 urlString = bytes(info.url.toEncoded()).decode() |
263 urlString = bytes(info.url.toEncoded()).decode() |
264 errorPage.baseUrl = info.url |
264 errorPage.baseUrl = info.url |
|
265 if info.domain == QWebPage.QtNetwork and \ |
|
266 info.error == QNetworkReply.ContentAccessDenied and \ |
|
267 info.errorString.startswith("AdBlockRule:"): |
|
268 if info.frame != info.frame.page().mainFrame(): |
|
269 # content in <iframe> |
|
270 docElement = info.frame.page().mainFrame().documentElement() |
|
271 for element in docElement.findAll("iframe"): |
|
272 src = element.attribute("src") |
|
273 if src in info.url.toString(): |
|
274 element.setAttribute("style", "display:none;") |
|
275 return False |
|
276 else: |
|
277 # the whole page is blocked |
|
278 rule = info.errorString.replace("AdBlockRule:", "") |
|
279 html = adblockPage_html |
|
280 title = self.trUtf8("Content blocked by AdBlock Plus") |
|
281 pixmap = UI.PixmapCache.getPixmap("adBlockPlus16.png") |
|
282 imageBuffer = QBuffer() |
|
283 imageBuffer.open(QIODevice.ReadWrite) |
|
284 if pixmap.save(imageBuffer, "PNG"): |
|
285 html = html.replace("@FAVICON@", |
|
286 str(imageBuffer.buffer().toBase64(), |
|
287 encoding="ascii")) |
|
288 pixmap = UI.PixmapCache.getPixmap("adBlockPlus64.png") |
|
289 imageBuffer = QBuffer() |
|
290 imageBuffer.open(QIODevice.ReadWrite) |
|
291 if pixmap.save(imageBuffer, "PNG"): |
|
292 html = html.replace("@IMAGE@", |
|
293 str(imageBuffer.buffer().toBase64(), |
|
294 encoding="ascii")) |
|
295 errorPage.content = QByteArray(html.format( |
|
296 title, |
|
297 self.trUtf8("Blocked by rule: <i>{0}</i>").format(rule) |
|
298 ).encode("utf8")) |
|
299 return True |
|
300 |
265 html = notFoundPage_html |
301 html = notFoundPage_html |
266 title = self.trUtf8("Error loading page: {0}").format(urlString) |
302 title = self.trUtf8("Error loading page: {0}").format(urlString) |
267 pixmap = qApp.style()\ |
303 pixmap = qApp.style()\ |
268 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
304 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
269 .pixmap(32, 32) |
305 .pixmap(48, 48) |
270 imageBuffer = QBuffer() |
306 imageBuffer = QBuffer() |
271 imageBuffer.open(QIODevice.ReadWrite) |
307 imageBuffer.open(QIODevice.ReadWrite) |
272 if pixmap.save(imageBuffer, "PNG"): |
308 if pixmap.save(imageBuffer, "PNG"): |
273 html = html.replace("IMAGE_BINARY_DATA_HERE", |
309 html = html.replace("@IMAGE@", |
|
310 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
|
311 pixmap = qApp.style()\ |
|
312 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
|
313 .pixmap(16, 16) |
|
314 imageBuffer = QBuffer() |
|
315 imageBuffer.open(QIODevice.ReadWrite) |
|
316 if pixmap.save(imageBuffer, "PNG"): |
|
317 html = html.replace("@FAVICON@", |
274 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
318 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
275 errorPage.content = QByteArray(html.format( |
319 errorPage.content = QByteArray(html.format( |
276 title, |
320 title, |
277 info.errorString, |
321 info.errorString, |
278 self.trUtf8("When connecting to: {0}.").format(urlString), |
322 self.trUtf8("When connecting to: {0}.").format(urlString), |