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

Fixed #1102 by changing the WKWebview privacy protection using tab's isPrivate value. #1103

Merged
merged 2 commits into from Jul 10, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -586,14 +586,11 @@
C4F3B29A1CFCF93A00966259 /* ButtonToast.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F3B2991CFCF93A00966259 /* ButtonToast.swift */; };
C615FACF2129FBD000A8168C /* ImageCacheProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C615FACE2129FBD000A8168C /* ImageCacheProtocol.swift */; };
C615FAD9212A1E2600A8168C /* WebImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = C615FAD8212A1E2600A8168C /* WebImageCache.swift */; };
C615FADF212A319C00A8168C /* PrivacyProtection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C615FADE212A319C00A8168C /* PrivacyProtection.swift */; };
C615FAE5212AC5E000A8168C /* PrivacyProtectionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C615FAE4212AC5E000A8168C /* PrivacyProtectionProtocol.swift */; };
C615FAED212ACAD200A8168C /* BraveWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C615FAEC212ACAD200A8168C /* BraveWebView.swift */; };
C6345ECB2113B3A000CFB983 /* SearchPlugins in Resources */ = {isa = PBXBuildFile; fileRef = C6345ECA2113B3A000CFB983 /* SearchPlugins */; };
C6620BBB213BCEC6009FE75A /* TabType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6620BB3213BCEC6009FE75A /* TabType.swift */; };
C690C208212FF35100E6EEE9 /* WebImageCacheWithNoPrivacyProtectionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C690C207212FF35100E6EEE9 /* WebImageCacheWithNoPrivacyProtectionManager.swift */; };
C690C2142130121E00E6EEE9 /* WebImageCacheManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C690C2132130121E00E6EEE9 /* WebImageCacheManager.swift */; };
C6B81B81212D6C1100996084 /* NoPrivacyProtection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B81B80212D6C1100996084 /* NoPrivacyProtection.swift */; };
C6B81B8A212D84BD00996084 /* ImageCacheType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B81B89212D84BD00996084 /* ImageCacheType.swift */; };
C6B81B8C212D989200996084 /* ImageCacheOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B81B8B212D989200996084 /* ImageCacheOptions.swift */; };
C6D267522136800100465DFA /* PrivateBrowsingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6D267512136800100465DFA /* PrivateBrowsingManager.swift */; };
@@ -1929,14 +1926,11 @@
C4F3B2991CFCF93A00966259 /* ButtonToast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonToast.swift; sourceTree = "<group>"; };
C615FACE2129FBD000A8168C /* ImageCacheProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCacheProtocol.swift; sourceTree = "<group>"; };
C615FAD8212A1E2600A8168C /* WebImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebImageCache.swift; sourceTree = "<group>"; };
C615FADE212A319C00A8168C /* PrivacyProtection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyProtection.swift; sourceTree = "<group>"; };
C615FAE4212AC5E000A8168C /* PrivacyProtectionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyProtectionProtocol.swift; sourceTree = "<group>"; };
C615FAEC212ACAD200A8168C /* BraveWebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BraveWebView.swift; sourceTree = "<group>"; };
C6345ECA2113B3A000CFB983 /* SearchPlugins */ = {isa = PBXFileReference; lastKnownFileType = folder; path = SearchPlugins; sourceTree = "<group>"; };
C6620BB3213BCEC6009FE75A /* TabType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabType.swift; sourceTree = "<group>"; };
C690C207212FF35100E6EEE9 /* WebImageCacheWithNoPrivacyProtectionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebImageCacheWithNoPrivacyProtectionManager.swift; sourceTree = "<group>"; };
C690C2132130121E00E6EEE9 /* WebImageCacheManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebImageCacheManager.swift; sourceTree = "<group>"; };
C6B81B80212D6C1100996084 /* NoPrivacyProtection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoPrivacyProtection.swift; sourceTree = "<group>"; };
C6B81B89212D84BD00996084 /* ImageCacheType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCacheType.swift; sourceTree = "<group>"; };
C6B81B8B212D989200996084 /* ImageCacheOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCacheOptions.swift; sourceTree = "<group>"; };
C6D267512136800100465DFA /* PrivateBrowsingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateBrowsingManager.swift; sourceTree = "<group>"; };
@@ -3541,9 +3535,6 @@
C6D267612137E45D00465DFA /* PrivacyProtection */ = {
isa = PBXGroup;
children = (
C615FAE4212AC5E000A8168C /* PrivacyProtectionProtocol.swift */,
C615FADE212A319C00A8168C /* PrivacyProtection.swift */,
C6B81B80212D6C1100996084 /* NoPrivacyProtection.swift */,
C6D267512136800100465DFA /* PrivateBrowsingManager.swift */,
);
path = PrivacyProtection;
@@ -5734,15 +5725,13 @@
4422D4E121BFFB7600BF1855 /* filter_block.cc in Sources */,
0A8C69BE225E350300988715 /* IndentedImageTableViewCell.swift in Sources */,
0A1E843D2190A57F0042F782 /* SyncSettingsTableViewController.swift in Sources */,
C615FAE5212AC5E000A8168C /* PrivacyProtectionProtocol.swift in Sources */,
4422D56C21BFFB7F00BF1855 /* bitstate.cc in Sources */,
E68E7ADE1CAC208A00FDCA76 /* RemovePasscodeViewController.swift in Sources */,
D314E7F71A37B98700426A76 /* BottomToolbarView.swift in Sources */,
4422D55321BFFB7E00BF1855 /* parse.cc in Sources */,
4422D4F421BFFB7600BF1855 /* version_edit.cc in Sources */,
EB11A1062044A90E0018F749 /* ContentBlockerHelper+TabContentScript.swift in Sources */,
3B0943811D6CC4FC004F24E1 /* FilledPageControl.swift in Sources */,
C615FADF212A319C00A8168C /* PrivacyProtection.swift in Sources */,
FA9293D41D6580E100AC8D33 /* QRCodeViewController.swift in Sources */,
E6108FF91C84E91C005D25E8 /* BasePasscodeViewController.swift in Sources */,
39F4C10A2045DB2E00746155 /* FocusHelper.swift in Sources */,
@@ -5812,7 +5801,6 @@
F84B22041A0910F600AAB793 /* AppDelegate.swift in Sources */,
0A7B5D6722689C5D00AADF22 /* AddEditHeaderView.swift in Sources */,
F930CDD12270F09000A23FE1 /* WebAuthnAuthenticateRequest.swift in Sources */,
C6B81B81212D6C1100996084 /* NoPrivacyProtection.swift in Sources */,
D8C75DF3207584C400BB8AD0 /* UIImageViewAligned.m in Sources */,
E653422D1C5944F90039DD9E /* BrowserPrompts.swift in Sources */,
4422D43621BFD29E00BF1855 /* NSFileManager+Tar.m in Sources */,
@@ -7,8 +7,8 @@ import WebKit

class BraveWebView: WKWebView {

init(frame: CGRect, configuration: WKWebViewConfiguration = WKWebViewConfiguration(), privacyProtection: PrivacyProtectionProtocol = PrivacyProtection()) {
if privacyProtection.nonPersistent {
init(frame: CGRect, configuration: WKWebViewConfiguration = WKWebViewConfiguration(), isPrivate: Bool = true) {
if isPrivate {
configuration.websiteDataStore = WKWebsiteDataStore.nonPersistent()
} else {
configuration.websiteDataStore = WKWebsiteDataStore.default()
@@ -33,9 +33,9 @@ protocol ImageCacheProtocol {

/// Initialize an image cache with privacy protection.
///
/// - parameter privacyProtection: An object representing privacy protection for this cache store.
/// - parameter isPrivate: Bool representing privacy protection for this cache store.
/// - parameter sandbox: The sandbox for this cache store.
init(withPrivacyProtection privacyProtection: PrivacyProtectionProtocol, sandbox: String?)
init(isPrivate: Bool, sandbox: String?)

/// Downloads the image at the given URL if not present in the cache otherwise returns the cached version.
///
@@ -9,7 +9,7 @@ final class WebImageCache: ImageCacheProtocol {

private let webImageManager: SDWebImageManager

private let privacyProtection: PrivacyProtectionProtocol
private let isPrivate: Bool

typealias ReturnAssociatedType = SDWebImageOperation

@@ -18,8 +18,8 @@ final class WebImageCache: ImageCacheProtocol {
clearDiskCache()
}

init(withPrivacyProtection privacyProtection: PrivacyProtectionProtocol, sandbox: String? = nil) {
self.privacyProtection = privacyProtection
init(isPrivate: Bool, sandbox: String? = nil) {
self.isPrivate = isPrivate

var imageCache: SDImageCache

@@ -52,7 +52,7 @@ final class WebImageCache: ImageCacheProtocol {
}

let imageOperation = webImageManager.loadImage(with: url, options: SDWebImageOptions(webImageOptions), progress: progressBlock) { image, data, error, webImageCacheType, _, imageURL in
if let image = image, !self.privacyProtection.nonPersistent {
if let image = image, !self.isPrivate {
self.webImageManager.saveImage(toCache: image, for: url)
}

@@ -83,11 +83,9 @@ final class WebImageCache: ImageCacheProtocol {
}

func clearDiskCache() {
if privacyProtection.nonPersistent {
return
if !isPrivate {
webImageManager.imageCache?.clearDisk()
}

webImageManager.imageCache?.clearDisk()
}

}
@@ -97,7 +95,7 @@ extension WebImageCache {
private var webImageOptions: [SDWebImageOptions] {
var options: [SDWebImageOptions] = [.retryFailed, .continueInBackground]

if privacyProtection.nonPersistent {
if isPrivate {
options.append(.cacheMemoryOnly)
}

@@ -9,14 +9,12 @@ final class WebImageCacheManager {
private let webImageCache: WebImageCache

static let shared: WebImageCache = {
let privacyProtection = PrivacyProtection()

let webImageCacheManager = WebImageCacheManager(withPrivacyProtection: privacyProtection)
let webImageCacheManager = WebImageCacheManager(isPrivate: true)
return webImageCacheManager.webImageCache
}()

private init(withPrivacyProtection privacyProtection: PrivacyProtectionProtocol) {
let webImageCache = WebImageCache(withPrivacyProtection: privacyProtection)
private init(isPrivate: Bool) {
let webImageCache = WebImageCache(isPrivate: isPrivate)
self.webImageCache = webImageCache
}

@@ -9,14 +9,12 @@ final class WebImageCacheWithNoPrivacyProtectionManager {
private let webImageCache: WebImageCache

static let shared: WebImageCache = {
let privacyProtection = NoPrivacyProtection()

let webImageCacheManager = WebImageCacheWithNoPrivacyProtectionManager(withPrivacyProtection: privacyProtection)
let webImageCacheManager = WebImageCacheWithNoPrivacyProtectionManager(isPrivate: false)
return webImageCacheManager.webImageCache
}()

private init(withPrivacyProtection privacyProtection: PrivacyProtectionProtocol) {
let webImageCache = WebImageCache(withPrivacyProtection: privacyProtection)
private init(isPrivate: Bool) {
let webImageCache = WebImageCache(isPrivate: isPrivate)
self.webImageCache = webImageCache
}

This file was deleted.

This file was deleted.

This file was deleted.

@@ -191,7 +191,7 @@ class Tab: NSObject {
configuration!.allowsInlineMediaPlayback = true
// Enables Zoom in website by ignoring their javascript based viewport Scale limits.
configuration!.ignoresViewportScaleLimits = true
let webView = TabWebView(frame: .zero, configuration: configuration!)
let webView = TabWebView(frame: .zero, configuration: configuration!, isPrivate: isPrivate)
webView.delegate = self
configuration = nil

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.