Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3165 - The configureable whitelist #11

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -16,6 +16,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
AdblockPlusSafari.xcworkspace/

#Mac garbage
**/.DS_Store
Expand All @@ -26,4 +27,4 @@ DerivedData
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/
Pods/
332 changes: 326 additions & 6 deletions AdblockPlusSafari.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions AdblockPlusSafari/AdblockPlus.h
Expand Up @@ -17,6 +17,7 @@

#import <Foundation/Foundation.h>

extern NSString *_Nonnull AdblockPlusErrorDomain;
extern NSString *_Nonnull AdblockPlusActivated;

@interface AdblockPlus : NSObject
Expand All @@ -41,4 +42,6 @@ extern NSString *_Nonnull AdblockPlusActivated;

@property (nonatomic, strong) NSDictionary<NSString *, NSDictionary<NSString *, id> *> *__nonnull filterLists;

@property (nonatomic, strong) NSArray<NSString *> *__nonnull whitelistedWebsites;

@end
13 changes: 12 additions & 1 deletion AdblockPlusSafari/AdblockPlus.m
Expand Up @@ -17,12 +17,14 @@

#import "AdblockPlus.h"

NSString *AdblockPlusErrorDomain = @"AdblockPlusError";
NSString *AdblockPlusActivated = @"AdblockPlusActivated";
static NSString *AdblockPlusEnabled = @"AdblockPlusEnabled";
static NSString *AdblockPlusAcceptableAdsEnabled = @"AdblockPlusAcceptableAdsEnabled";
static NSString *AdblockPlusFilterLists = @"AdblockPlusFilterLists";
static NSString *AdblockPlusInstalledVersion = @"AdblockPlusInstalledVersion";
static NSString *AdblockPlusDownloadedVersion = @"AdblockPlusDownloadedVersion";
static NSString *AdblockPlusWhitelistedWebsites = @"AdblockPlusWhitelistedWebsites";

@interface AdblockPlus ()

Expand Down Expand Up @@ -50,14 +52,16 @@ - (instancetype)init
AdblockPlusAcceptableAdsEnabled: @YES,
AdblockPlusInstalledVersion: @0,
AdblockPlusDownloadedVersion: @1,
AdblockPlusFilterLists: filterLists }];
AdblockPlusFilterLists: filterLists,
AdblockPlusWhitelistedWebsites: @[]}];

_enabled = [_adblockPlusDetails boolForKey:AdblockPlusEnabled];
_acceptableAdsEnabled = [_adblockPlusDetails boolForKey:AdblockPlusAcceptableAdsEnabled];
_activated = [_adblockPlusDetails boolForKey:AdblockPlusActivated];
_filterLists = [_adblockPlusDetails objectForKey:AdblockPlusFilterLists];
_installedVersion = [_adblockPlusDetails integerForKey:AdblockPlusInstalledVersion];
_downloadedVersion = [_adblockPlusDetails integerForKey:AdblockPlusDownloadedVersion];
_whitelistedWebsites = [_adblockPlusDetails objectForKey:AdblockPlusWhitelistedWebsites];
}
return self;
}
Expand Down Expand Up @@ -106,6 +110,13 @@ - (void)setDownloadedVersion:(NSInteger)downloadedVersion
[_adblockPlusDetails synchronize];
}

- (void)setWhitelistedWebsites:(NSArray<NSString *> *)whitelistedWebsites
{
_whitelistedWebsites = whitelistedWebsites;
[_adblockPlusDetails setObject:whitelistedWebsites forKey:AdblockPlusWhitelistedWebsites];
[_adblockPlusDetails synchronize];
}

#pragma mark -

- (NSString *)contentBlockerIdentifier
Expand Down
2 changes: 1 addition & 1 deletion AdblockPlusSafari/AdblockPlusContainerController.m
Expand Up @@ -33,7 +33,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];

// Test if adblock browser is installed
// Test if adblock browser is installed
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated, but to speed things up I'll leave it out when merging this and apply it as a separate Noissue.

NSURL *adblockBrowserTestUrl = [NSURL URLWithString:@"adblockbrowser://example.com"];
if ([[UIApplication sharedApplication] canOpenURL:adblockBrowserTestUrl]) {
self.adblockBrowserBannerConstraint.constant = 0;
Expand Down
7 changes: 6 additions & 1 deletion AdblockPlusSafari/AdblockPlusController.m
Expand Up @@ -105,7 +105,8 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
} else if ([cell.reuseIdentifier isEqualToString:@"UpdateFilterLists"]) {
cell.accessoryView = self.activityIndicatorView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else if ([cell.reuseIdentifier isEqualToString:@"AcceptableAds"]) {
} else if ([cell.reuseIdentifier isEqualToString:@"AcceptableAds"]
|| [cell.reuseIdentifier isEqualToString:@"WhitelistedWebsites"]) {
BOOL enabled = self.adblockPlus.enabled;
cell.userInteractionEnabled = enabled;
cell.selectionStyle = enabled ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;
Expand Down Expand Up @@ -144,6 +145,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self.parentViewController performSegueWithIdentifier:@"AboutSegue" sender:nil];
}

if ([cell.reuseIdentifier isEqualToString:@"WhitelistedWebsites"]) {
[self.parentViewController performSegueWithIdentifier:@"WhitelistedWebsitesSegue" sender:nil];
}

if ([cell.reuseIdentifier isEqualToString:@"UpdateFilterLists"]) {
[self.adblockPlus updateFilterLists: YES];
}
Expand Down
6 changes: 6 additions & 0 deletions AdblockPlusSafari/AdblockPlusExtras.m
Expand Up @@ -121,6 +121,12 @@ - (void)setFilterLists:(NSDictionary<NSString *,NSDictionary<NSString *,NSObject
}
}

- (void)setWhitelistedWebsites:(NSArray<NSString *> *)whitelistedWebsites
{
super.whitelistedWebsites = whitelistedWebsites;
[self reloadContentBlockerWithCompletion:nil];
}

- (void)setNeedsDisplayErrorDialog:(BOOL)needsDisplayErrorDialog
{
_needsDisplayErrorDialog = needsDisplayErrorDialog;
Expand Down
2 changes: 1 addition & 1 deletion AdblockPlusSafari/Appearence.m
Expand Up @@ -43,7 +43,7 @@
NSString *name = [NSString stringWithFormat:@"%@-%@", familyName, type];

NSFont *font = [UIFont fontWithName:name size:fromFont.pointSize];

Copy link
Contributor

Choose a reason for hiding this comment

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

Also unrelated, but you can leave it in, same as above.

if (font) {
return font;
} else {
Expand Down
21 changes: 21 additions & 0 deletions AdblockPlusSafari/Assets.xcassets/trash.imageset/Contents.json
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Image.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 113 additions & 1 deletion AdblockPlusSafari/Base.lproj/Main.storyboard
Expand Up @@ -446,12 +446,29 @@
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="WhitelistedWebsites" textLabel="0Xh-gE-5Fu" style="IBUITableViewCellStyleDefault" id="YJj-Jo-jfU">
<rect key="frame" x="0.0" y="233.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="YJj-Jo-jfU" id="Dbd-ah-TvN">
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Whitelisted Websites" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="0Xh-gE-5Fu" userLabel="Subscriptions">
<rect key="frame" x="15" y="0.0" width="325" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="MORE" id="JGs-ZZ-lI9">
<cells>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="About" textLabel="3Bc-kL-vsl" style="IBUITableViewCellStyleDefault" id="1YB-NP-n3W">
<rect key="frame" x="0.0" y="275.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="319.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1YB-NP-n3W" id="Jno-x4-Oyv">
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
Expand Down Expand Up @@ -642,6 +659,7 @@
<outlet property="adblockBrowserLabel" destination="VJZ-V3-ohd" id="a5u-Oo-cp4"/>
<segue destination="Vmz-DH-jZI" kind="show" identifier="AcceptableAdsSegue" id="qrF-SL-2xa"/>
<segue destination="UNy-3X-8uc" kind="show" identifier="AboutSegue" id="ElQ-nq-a0d"/>
<segue destination="yYL-2D-lvf" kind="show" identifier="WhitelistedWebsitesSegue" id="fMU-kr-II7"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="F4J-fI-8xB" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -693,6 +711,100 @@
</objects>
<point key="canvasLocation" x="2011.5" y="-32.5"/>
</scene>
<!--Whitelisted Websites-->
<scene sceneID="nbF-od-Ak8">
<objects>
<tableViewController id="yYL-2D-lvf" customClass="WhitelistedWebsitesController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="z7R-EI-l7I">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="AddingCell" id="6Ty-zs-tal">
<rect key="frame" x="0.0" y="113.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="6Ty-zs-tal" id="lBC-b6-orZ">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="knj-pJ-rNf">
<rect key="frame" x="325" y="0.0" width="50" height="44"/>
<color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="Wwk-em-LiL"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<state key="normal" title="+"/>
<connections>
<action selector="onAddWebsiteTouched:" destination="yYL-2D-lvf" eventType="touchUpInside" id="PhQ-LV-Wbb"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" tag="121212" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="www.website.com" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="ufs-md-QOX">
<rect key="frame" x="16" y="12" width="299" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" returnKeyType="go"/>
<connections>
<outlet property="delegate" destination="yYL-2D-lvf" id="rr6-Y9-nul"/>
</connections>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="knj-pJ-rNf" secondAttribute="trailing" id="ENi-On-tq0"/>
<constraint firstItem="ufs-md-QOX" firstAttribute="centerY" secondItem="lBC-b6-orZ" secondAttribute="centerY" id="Sef-dr-tCY"/>
<constraint firstItem="knj-pJ-rNf" firstAttribute="top" secondItem="lBC-b6-orZ" secondAttribute="top" id="dmt-S1-gdv"/>
<constraint firstItem="ufs-md-QOX" firstAttribute="leading" secondItem="lBC-b6-orZ" secondAttribute="leadingMargin" constant="8" id="eMW-Lb-ze7"/>
<constraint firstItem="knj-pJ-rNf" firstAttribute="leading" secondItem="ufs-md-QOX" secondAttribute="trailing" constant="10" id="jtV-CG-60r"/>
<constraint firstAttribute="bottom" secondItem="knj-pJ-rNf" secondAttribute="bottom" id="uLL-Rf-X1u"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="NoWebsiteCell" textLabel="VES-kP-JDg" style="IBUITableViewCellStyleDefault" id="cAj-gn-13O">
<rect key="frame" x="0.0" y="157.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="cAj-gn-13O" id="gb6-f3-DwD">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="No websites added yet" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="VES-kP-JDg">
<rect key="frame" x="15" y="0.0" width="345" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="WebsiteCell" textLabel="LBD-LS-G1D" style="IBUITableViewCellStyleDefault" id="SJt-Tn-kZJ">
<rect key="frame" x="0.0" y="201.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="SJt-Tn-kZJ" id="Qe1-hR-4DA">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="LBD-LS-G1D">
<rect key="frame" x="15" y="0.0" width="345" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="yYL-2D-lvf" id="R4h-Zv-TXS"/>
<outlet property="delegate" destination="yYL-2D-lvf" id="AKT-8z-DeF"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Whitelisted Websites" id="EiF-J0-RYy"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="eb5-R8-QGQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2011.5" y="746.5"/>
</scene>
</scenes>
<resources>
<image name="adblockbrowser" width="86" height="68"/>
Expand Down
26 changes: 26 additions & 0 deletions AdblockPlusSafari/WhitelistedWebsitesController.h
@@ -0,0 +1,26 @@
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-2015 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/&gt.
*/

#import <UIKit/UIKit.h>

#import "AdblockPlusExtras.h"

@interface WhitelistedWebsitesController : UITableViewController

@property (nonatomic, strong) AdblockPlusExtras *__nullable adblockPlus;

@end