Skip to content

Commit

Permalink
Merge branch 'main' into zazz/add-feature-flag-for-new-pull-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippo committed Nov 26, 2024
2 parents bb2c5d5 + ad0a142 commit 958b4d4
Show file tree
Hide file tree
Showing 62 changed files with 420 additions and 725 deletions.
3 changes: 3 additions & 0 deletions BrowserKit/Sources/Common/Logger/LoggerCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ public enum LoggerCategory: String {

/// Remote settings
case remoteSettings

/// Password Generator
case passwordGenerator
}

This file was deleted.

6 changes: 3 additions & 3 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2106,17 +2106,17 @@ app:
BITRISE_NIGHTLY_VERSION: '9000'
- opts:
is_expand: false
BITRISE_RELEASE_VERSION: '134.0'
BITRISE_RELEASE_VERSION: '135.0'
- opts:
is_expand: false
BITRISE_BETA_VERSION: '134.0'
BITRISE_BETA_VERSION: '135.0'

trigger_map:
- push_branch: main
pipeline: pipeline_build_and_test
- push_branch: epic-branch/*
pipeline: pipeline_build_and_test
- push_branch: release/v134
- push_branch: release/v135
pipeline: pipeline_build_and_test
- pull_request_target_branch: main
pipeline: pipeline_build_and_test
Expand Down
5 changes: 3 additions & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ cp -r .githooks/* .git/hooks/
# Make the hooks are executable
chmod +x .git/hooks/*

# Run and update content blocker
./content_blocker_update.sh
# Install Node.js dependencies and build user scripts
npm install
npm run build
20 changes: 0 additions & 20 deletions content_blocker_update.sh

This file was deleted.

134 changes: 77 additions & 57 deletions firefox-ios/Client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

45 changes: 36 additions & 9 deletions firefox-ios/Client/Application/RemoteSettings/RemoteDataType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,62 @@ enum RemoteDataTypeError: Error, LocalizedError {

enum RemoteDataType: String, Codable {
case passwordRules
case contentBlockingLists

var type: any RemoteDataTypeRecord.Type {
switch self {
case .passwordRules:
return PasswordRuleRecord.self
case .contentBlockingLists:
return ContentBlockingListRecord.self
}
}

var fileName: String {
var fileNames: [String] {
switch self {
case .passwordRules:
return "RemotePasswordRules"
return ["RemotePasswordRules"]
case .contentBlockingLists:
return BlocklistFileName.allCases.map { $0.filename }
}
}

var name: String {
switch self {
case .passwordRules:
return "Password Rules"
case .contentBlockingLists:
return "Content Blocking Lists"
}
}

/// Loads the local settings for the given data type record, returning the
/// decoded objects.
/// - Returns: settings decoded to their RemoteDataTypeRecord.
func loadLocalSettingsFromJSON<T: RemoteDataTypeRecord>() async throws -> [T] {
let fileName = self.fileName
guard let fileName = self.fileNames.first else {
assertionFailure("No filename available for setting type.")
throw RemoteDataTypeError.fileNotFound(fileName: "")
}

let data = try loadLocalSettingsFileAsJSON(fileName: fileName)
do {
if let decodedArray = try? JSONDecoder().decode([T].self, from: data) {
return decodedArray
}
let singleObject = try JSONDecoder().decode(T.self, from: data)
return [singleObject]
} catch {
throw RemoteDataTypeError.decodingError(fileName: fileName, error: error)
}
}

/// Loads the local settings JSON for the given setting file.
/// - Returns: the raw JSON file data.
func loadLocalSettingsFileAsJSON(fileName: String) throws -> Data {
guard fileNames.contains(fileName) else {
throw RemoteDataTypeError.fileNotFound(fileName: fileName)
}

guard let path = Bundle.main.path(forResource: fileName, ofType: "json") else {
throw RemoteDataTypeError.fileNotFound(fileName: fileName)
Expand All @@ -53,12 +85,7 @@ enum RemoteDataType: String, Codable {

do {
let data = try Data(contentsOf: url)

if let decodedArray = try? JSONDecoder().decode([T].self, from: data) {
return decodedArray
}
let singleObject = try JSONDecoder().decode(T.self, from: data)
return [singleObject]
return data
} catch {
throw RemoteDataTypeError.decodingError(fileName: fileName, error: error)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Foundation

/// Object model to represent content blocking rules.
/// This is not used (yet) since we load the JSON directly
/// in order to modify it before injecting to WKWebView.
struct ContentBlockingListRecord: RemoteDataTypeRecord {
}
2 changes: 0 additions & 2 deletions firefox-ios/Client/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import UIKit
import CoreSpotlight
import Storage
import Shared
import Sync
import UserNotifications
import Account
import Common

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
Expand Down
1 change: 0 additions & 1 deletion firefox-ios/Client/BookmarkItemsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Foundation
import Storage
import Shared

import class MozillaAppServices.BookmarkItemData
Expand Down
21 changes: 12 additions & 9 deletions firefox-ios/Client/ContentBlocker/ContentBlocker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,14 @@ extension ContentBlocker {
let suffixLength = jsonSuffix.count
// Trim off .json suffix if needed, we only want the raw file name
let fileTrimmed = file.hasSuffix(jsonSuffix) ? String(file.dropLast(suffixLength)) : file
if let path = Bundle.main.path(forResource: fileTrimmed, ofType: "json") {
source = try String(contentsOfFile: path, encoding: .utf8)

if fileTrimmed.hasPrefix(BlocklistFileName.customBlocklistJSONFilePrefix) {
if let path = Bundle.main.path(forResource: fileTrimmed, ofType: "json") {
source = try String(contentsOfFile: path, encoding: .utf8)
}
} else {
let json = try RemoteDataType.contentBlockingLists.loadLocalSettingsFileAsJSON(fileName: fileTrimmed)
source = String(data: json, encoding: .utf8) ?? ""
}
} catch let error {
logger.log("Error loading content-blocking JSON: \(error)", level: .warning, category: .adblock)
Expand Down Expand Up @@ -288,11 +294,7 @@ extension ContentBlocker {
}
}

private func calculateHash(forFileAtPath path: String) -> String? {
guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
return nil
}

private func calculateHash(for fileData: Data) -> String? {
let hash = SHA256.hash(data: fileData)
return hash.compactMap { String(format: "%02x", $0) }.joined()
}
Expand All @@ -302,9 +304,10 @@ extension ContentBlocker {
let defaults = UserDefaults.standard
var hasChanged = false

let lists = RemoteDataType.contentBlockingLists
for list in blocklists {
guard let path = Bundle.main.path(forResource: list, ofType: "json"),
let newHash = calculateHash(forFileAtPath: path) else { continue }
guard let data = try? lists.loadLocalSettingsFileAsJSON(fileName: list) else { continue }
guard let newHash = calculateHash(for: data) else { continue }

let oldHash = defaults.string(forKey: list)
if oldHash != newHash {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,12 @@ class TPStatsBlocklists {
] {
let list: [[String: AnyObject]]
do {
guard let path = Bundle.main.path(forResource: blockListFile.filename, ofType: "json") else {
logger.log("Blocklists: bad file path.", level: .warning, category: .webview)
assertionFailure("Blocklists: bad file path.")
return
let settingsLists = RemoteDataType.contentBlockingLists
guard let json = try? settingsLists.loadLocalSettingsFileAsJSON(fileName: blockListFile.filename) else {
logger.log("Blocklists: could not load blocklist JSON file.", level: .warning, category: .webview)
assertionFailure("Blocklists: could not load file.")
continue
}

let json = try Data(contentsOf: URL(fileURLWithPath: path))
guard let data = try JSONSerialization.jsonObject(
with: json,
options: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Common
import Storage
import ComponentLibrary
import WebKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Foundation
import Storage
import Common
import MozillaAppServices

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import Common
import UIKit
import Shared
import Storage

/// Each scene has it's own scene coordinator, which is the root coordinator for a scene.
class SceneCoordinator: BaseCoordinator, LaunchCoordinatorDelegate, LaunchFinishedLoadingDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TabTrayCoordinator: BaseCoordinator,
func dismissChildTabTrayPanels() {
// [FXIOS-10482] Initial bandaid for memory leaking during tab tray open/close. Needs further investigation.
guard let childVCs = tabTrayViewController.currentPanel?.viewControllers else { return }
childVCs.forEach { ($0 as? TabDisplayPanel)?.removeTabPanel() }
childVCs.forEach { ($0 as? TabDisplayPanelViewController)?.removeTabPanel() }
}

private func initializeTabTrayViewController(selectedTab: TabTrayPanelType) {
Expand All @@ -53,8 +53,8 @@ class TabTrayCoordinator: BaseCoordinator,

private func makeChildPanels() -> [UINavigationController] {
let windowUUID = tabManager.windowUUID
let regularTabsPanel = TabDisplayPanel(isPrivateMode: false, windowUUID: windowUUID)
let privateTabsPanel = TabDisplayPanel(isPrivateMode: true, windowUUID: windowUUID)
let regularTabsPanel = TabDisplayPanelViewController(isPrivateMode: false, windowUUID: windowUUID)
let privateTabsPanel = TabDisplayPanelViewController(isPrivateMode: true, windowUUID: windowUUID)
let syncTabs = RemoteTabsPanel(windowUUID: windowUUID)
return [
ThemedNavigationController(rootViewController: regularTabsPanel, windowUUID: windowUUID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ class BrowserViewController: UIViewController,
let showWarningBadge = isActionNeeded

if isToolbarRefactorEnabled {
let shouldShowWarningBadge = store.state.screenState(
ToolbarState.self,
for: .toolbar,
window: windowUUID
)?.showMenuWarningBadge

guard showWarningBadge != shouldShowWarningBadge else { return }
let action = ToolbarAction(
showMenuWarningBadge: showWarningBadge,
windowUUID: windowUUID,
Expand Down
Loading

0 comments on commit 958b4d4

Please sign in to comment.