358 @param encodedUrl string encoded URL to be checked |
358 @param encodedUrl string encoded URL to be checked |
359 @type str |
359 @type str |
360 @return flag indicating a match |
360 @return flag indicating a match |
361 @rtype bool |
361 @rtype bool |
362 """ |
362 """ |
363 if self.__type == AdBlockRuleType.CssRule or \ |
363 if ( |
364 not self.__isEnabled or \ |
364 self.__type == AdBlockRuleType.CssRule or |
365 self.__isInternalDisabled: |
365 not self.__isEnabled or |
|
366 self.__isInternalDisabled |
|
367 ): |
366 return False |
368 return False |
367 |
369 |
368 matched = self.__stringMatch(domain, encodedUrl) |
370 matched = self.__stringMatch(domain, encodedUrl) |
369 |
371 |
370 if matched: |
372 if matched: |
371 # check domain restrictions |
373 # check domain restrictions |
372 if self.__hasOption(AdBlockRuleOption.DomainRestrictedOption) and \ |
374 if ( |
373 not self.matchDomain(request.firstPartyUrl().host()): |
375 self.__hasOption(AdBlockRuleOption.DomainRestrictedOption) and |
|
376 not self.matchDomain(request.firstPartyUrl().host()) |
|
377 ): |
374 return False |
378 return False |
375 |
379 |
376 # check third-party restrictions |
380 # check third-party restrictions |
377 if self.__hasOption(AdBlockRuleOption.ThirdPartyOption) and \ |
381 if ( |
378 not self.matchThirdParty(request): |
382 self.__hasOption(AdBlockRuleOption.ThirdPartyOption) and |
|
383 not self.matchThirdParty(request) |
|
384 ): |
379 return False |
385 return False |
380 |
386 |
381 # check object restrictions |
387 # check object restrictions |
382 if self.__hasOption(AdBlockRuleOption.ObjectOption) and \ |
388 if ( |
383 not self.matchObject(request): |
389 self.__hasOption(AdBlockRuleOption.ObjectOption) and |
|
390 not self.matchObject(request) |
|
391 ): |
384 return False |
392 return False |
385 |
393 |
386 # check subdocument restrictions |
394 # check subdocument restrictions |
387 if self.__hasOption(AdBlockRuleOption.SubdocumentOption) and \ |
395 if ( |
388 not self.matchSubdocument(request): |
396 self.__hasOption(AdBlockRuleOption.SubdocumentOption) and |
|
397 not self.matchSubdocument(request) |
|
398 ): |
389 return False |
399 return False |
390 |
400 |
391 # check xmlhttprequest restriction |
401 # check xmlhttprequest restriction |
392 if self.__hasOption(AdBlockRuleOption.XMLHttpRequestOption) and \ |
402 if ( |
393 not self.matchXmlHttpRequest(request): |
403 self.__hasOption(AdBlockRuleOption.XMLHttpRequestOption) and |
|
404 not self.matchXmlHttpRequest(request) |
|
405 ): |
394 return False |
406 return False |
395 |
407 |
396 # check image restriction |
408 # check image restriction |
397 if self.__hasOption(AdBlockRuleOption.ImageOption) and \ |
409 if ( |
398 not self.matchImage(request): |
410 self.__hasOption(AdBlockRuleOption.ImageOption) and |
|
411 not self.matchImage(request) |
|
412 ): |
399 return False |
413 return False |
400 |
414 |
401 # check script restriction |
415 # check script restriction |
402 if self.__hasOption(AdBlockRuleOption.ScriptOption) and \ |
416 if ( |
403 not self.matchScript(request): |
417 self.__hasOption(AdBlockRuleOption.ScriptOption) and |
|
418 not self.matchScript(request) |
|
419 ): |
404 return False |
420 return False |
405 |
421 |
406 # check stylesheet restriction |
422 # check stylesheet restriction |
407 if self.__hasOption(AdBlockRuleOption.StyleSheetOption) and \ |
423 if ( |
408 not self.matchStyleSheet(request): |
424 self.__hasOption(AdBlockRuleOption.StyleSheetOption) and |
|
425 not self.matchStyleSheet(request) |
|
426 ): |
409 return False |
427 return False |
410 |
428 |
411 # check object-subrequest restriction |
429 # check object-subrequest restriction |
412 if self.__hasOption(AdBlockRuleOption.ObjectSubrequestOption) and \ |
430 if ( |
413 not self.matchObjectSubrequest(request): |
431 self.__hasOption(AdBlockRuleOption.ObjectSubrequestOption) and |
|
432 not self.matchObjectSubrequest(request) |
|
433 ): |
414 return False |
434 return False |
415 |
435 |
416 # check ping restriction |
436 # check ping restriction |
417 if self.__hasOption(AdBlockRuleOption.PingOption) and \ |
437 if ( |
418 not self.matchPing(request): |
438 self.__hasOption(AdBlockRuleOption.PingOption) and |
|
439 not self.matchPing(request) |
|
440 ): |
419 return False |
441 return False |
420 |
442 |
421 # check media restriction |
443 # check media restriction |
422 if self.__hasOption(AdBlockRuleOption.MediaOption) and \ |
444 if ( |
423 not self.matchMedia(request): |
445 self.__hasOption(AdBlockRuleOption.MediaOption) and |
|
446 not self.matchMedia(request) |
|
447 ): |
424 return False |
448 return False |
425 |
449 |
426 # check font restriction |
450 # check font restriction |
427 if self.__hasOption(AdBlockRuleOption.FontOption) and \ |
451 if ( |
428 not self.matchFont(request): |
452 self.__hasOption(AdBlockRuleOption.FontOption) and |
|
453 not self.matchFont(request) |
|
454 ): |
429 return False |
455 return False |
430 |
456 |
431 return matched |
457 return matched |
432 |
458 |
433 def urlMatch(self, url): |
459 def urlMatch(self, url): |