Skip to content

Commit

Permalink
Merge branch 'main' into sparaipan/fxios-8029-Firefox-Suggest-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PARAIPAN9 committed Feb 16, 2024
2 parents 0292b43 + 89f1b05 commit 599324a
Show file tree
Hide file tree
Showing 126 changed files with 2,451 additions and 372 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ bitrise.yml @mozilla-mobile/fxios-automation-1
.taskcluster.yml @mozilla-mobile/fxios-automation-1
/taskcluster @mozilla-mobile/fxios-automation-1
.github/workflows @mozilla-mobile/fxios-automation-1
/test-fixtures @mozilla-mobile/fxios-automation-1
/test-fixtures @mozilla-mobile/fxios-automation-1
/test-fixtures/generate-metrics.sh @mozilla-mobile/fxios-eng
33 changes: 27 additions & 6 deletions .github/workflows/firefox-check-rust-component-dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,64 @@ jobs:
with:
persist-credentials: false
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./test-fixtures/requirements.txt
- name: Modifing Swift Package dependencies
run: |
python ./test-fixtures/update-rust-component-version.py
- name: Get new A-S tag to be used in the PR info
run: |
cd test-fixtures/
chmod u+x read-rust-component-tag.sh
echo "version=$(./read-rust-component-tag.sh)" >> $GITHUB_ENV
echo "rust_version=$(./read-rust-component-tag.sh)" >> $GITHUB_ENV
- name: Remove temp file created to store the tag info
run: |
cd test-fixtures/
[ ! -e newest_tag.txt ] || rm newest_tag.txt
- name: Script to check if branch exists to not commit again
run: |-
branch=$(curl -X GET -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/mozilla-mobile/firefox-ios/branches?per_page=100 | jq -r '.[].name | select(contains("update-spm-new-rust-component-tag-${{ env.version }}"))')
branch=$(curl -X GET -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/mozilla-mobile/firefox-ios/branches?per_page=100 | jq -r '.[].name | select(contains("update-spm-new-rust-component-tag-${{ env.rust_version }}"))')
echo $branch
if [ -z "$branch" ]; then echo "BRANCH_CREATED=false" >> $GITHUB_ENV; else echo "BRANCH_CREATED=true" >> $GITHUB_ENV;fi
- name: Determine PR Version Number
id: versioning
run: |
# This step is used to determine the next version number for the PR title
# The output includes debugging for the piped commands that generate
# the version number and the last line is the version number itself
output=$(bash test-fixtures/ci/get-next-pr-version)
echo "$output"
next_version=$(echo "$output" | tail -n 1) # get the last line of the output
echo "Next Firefox iOS version is: v${next_version}"
echo "next_app_version=${next_version}" >> $GITHUB_ENV
- name: Update rust-component version
if: env.BRANCH_CREATED == 'false'
run: |-
git diff
git diff --quiet || (git add firefox-ios/Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved firefox-ios/Client.xcodeproj/project.pbxproj)
git diff --quiet || (git add firefox-ios/Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved firefox-ios/Client.xcodeproj/project.pbxproj)
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
if: env.BRANCH_CREATED == 'false'
with:
commit-message: Auto update SPM with latest rust-component release ${{ env.version }}
commit-message: Auto update SPM with latest rust-component release ${{ env.rust_version }}
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
committer: GitHub <[email protected]>
title: Refactor [vXXX] Auto update SPM with latest rust-component ${{ env.version }}
branch: update-spm-new-rust-component-tag-${{ env.version }}
title: Refactor [v${{ env.next_app_version }}] Auto update SPM with latest rust-component ${{ env.rust_version }}
branch: update-spm-new-rust-component-tag-${{ env.rust_version }}
token: ${{ secrets.GITHUB_TOKEN }}
23 changes: 21 additions & 2 deletions .github/workflows/firefox-ios-import-strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,28 @@ jobs:
persist-credentials: false
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.inputs.branchName }}

- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Determine PR Version Number
id: versioning
run: |
# This step is used to determine the next version number for the PR title
# The output includes debugging for the piped commands that generate
# the version number and the last line is the version number itself
output=$(bash test-fixtures/ci/get-next-pr-version)
echo "$output"
next_version=$(echo "$output" | tail -n 1) # get the last line of the output
echo "Next version is: v${next_version}"
echo "next_version=${next_version}" >> $GITHUB_ENV
- name: Get PR info
run: |
current_date=$(date +"%Y-%m-%d")
Expand All @@ -36,7 +52,7 @@ jobs:
echo "current_date=$current_date" >> $GITHUB_ENV
if [[ $current_branch == 'main' ]]; then
echo "branch_name=string-import-$current_date" >> $GITHUB_ENV
echo "pr_title=Localize [ver] String import $current_date" >> $GITHUB_ENV
echo "pr_title=Localize [v${{ env.next_version }}] String import $current_date" >> $GITHUB_ENV
echo "pr_body=This automated PR imports string changes" >> $GITHUB_ENV
else
# version: v105.0 -> v105
Expand All @@ -45,19 +61,22 @@ jobs:
echo "pr_title=Localize [$version] String import $current_date" >> $GITHUB_ENV
echo "pr_body=This automated PR imports string changes into branch '$current_branch'" >> $GITHUB_ENV
fi
- name: Run script to import strings
run: sh ./bootstrap.sh --importLocales

- name: Update new strings
run: |-
git diff || (git add firefox-ios/Shared/*/*.lproj/* firefox-ios/Shared/*.lproj/* firefox-ios/WidgetKit/*.lproj/* firefox-ios/Client/*/*.lproj/* firefox-ios/Client/*.lproj/*)
git restore firefox-ios/Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
committer: GitHub <[email protected]>
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: ${{ env.pr_title }}
title: ${{ env.pr_title }}
title: "Localize [v${{ env.next_version }}] String import ${{ env.current_date }}"
branch: ${{ env.branch_name }}
body: ${{ env.pr_body }}
18 changes: 16 additions & 2 deletions .github/workflows/firefox-ios-update-effective-tld-names-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,28 @@ jobs:
echo "create_pr=true" >> $GITHUB_ENV
cp tmp.dat firefox-ios/Shared/effective_tld_names.dat
echo "branch_name=refactor-update-effective-tld-names" >> $GITHUB_ENV
echo "pr_title=Refactor [vXXX] Update effective_tld_names file $current_date" >> $GITHUB_ENV
echo "pr_body=This automated PR updates the effective_tld_names file" >> $GITHUB_ENV
rm tmp.dat
fi
- name: Determine PR Version Number
id: versioning
run: |
# This step is used to determine the next version number for the PR title
# The output includes debugging for the piped commands that generate
# the version number and the last line is the version number itself
output=$(bash test-fixtures/ci/get-next-pr-version)
echo "$output"
next_version=$(echo "$output" | tail -n 1) # get the last line of the output
echo "Next version is: v${next_version}"
echo "next_version=${next_version}" >> $GITHUB_ENV
- name: Add Modified File to PR
if: ${{ env.create_pr }}
run: |-
git diff || (git add firefox-ios/Shared/effective_tld_names.dat)
- name: Create Pull Request
if: ${{ env.create_pr }}
uses: peter-evans/create-pull-request@v3
Expand All @@ -59,6 +73,6 @@ jobs:
committer: GitHub <[email protected]>
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: ${{ env.pr_title }}
title: ${{ env.pr_title }}
title: "Refactor [v${{ env.next_version }}] Update effective_tld_names file ${{ env.current_date }}"
branch: ${{ env.branch_name }}
body: ${{ env.pr_body }}
76 changes: 76 additions & 0 deletions .github/workflows/firefox-ios-update-uri.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Update URIs and Create PR
on:
schedule:
- cron: '0 0 1 * *' # Runs at 00:00 on the first day of every month
workflow_dispatch:
inputs:
branchName:
description: 'Branch used as target for automation'
required: true
default: 'main'
jobs:
build:
runs-on: ubuntu-latest # using ubuntu as a lightweight environment
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.inputs.branchName }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
# include pyarrow for pandas 3.0 compatibility
pip install pandas pyarrow requests
- name: Run URI update script
run: python test-fixtures/ci/uri_update.py

- name: Check for changes
id: git-check
run: |
if git diff --quiet; then
echo "No changes detected, skipping PR creation."
echo "changes_detected=false" >> $GITHUB_ENV
else
echo "Changes detected, proceeding to create PR."
git diff
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit --allow-empty -m "empty commit" # add empty commit so when squashed the history will show PR title
git add firefox-ios/Shared/Extensions/URLExtensions.swift
echo "changes_detected=true" >> $GITHUB_ENV
datetime=$(date +%Y%m%d%H%M%S)
echo "date=$datetime" >> $GITHUB_ENV
fi
- name: Determine PR Version Number
id: versioning
run: |
# This step is used to determine the next version number for the PR title
# The output includes debugging for the piped commands that generate
# the version number and the last line is the version number itself
output=$(bash test-fixtures/ci/get-next-pr-version)
echo "$output"
next_version=$(echo "$output" | tail -n 1) # get the last line of the output
echo "Next version is: v${next_version}"
echo "next_version=${next_version}" >> $GITHUB_ENV
- name: Create Pull Request
if: env.changes_detected == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Automated URI update on ${{ github.event.inputs.branchName || 'main' }} ${{ env.date }}
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
committer: GitHub <[email protected]>
title: Refactor [v${{ env.next_version }}] Automated URI update on ${{ github.event.inputs.branchName || 'main' }} ${{ env.date }}
branch: update-uri-schemes-${{ env.date }}
body: This automated PR updates the URIs.
12 changes: 11 additions & 1 deletion BrowserKit/Sources/WebEngine/EngineSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Foundation
/// Protocol representing a single engine session. In browsers usually a session corresponds to a tab.
public protocol EngineSession {
var delegate: EngineSessionDelegate? { get set }
var findInPageDelegate: FindInPageHelperDelegate? { get set }

/// The engine received a request to load a URL.
/// - Parameter url: The URL string that is requested
Expand All @@ -24,9 +25,18 @@ public protocol EngineSession {
/// Navigates forward in the history of this session.
func goForward()

/// Scroll the session to the top
/// Scroll the session to the top.
func scrollToTop()

/// Find a text selection in this session.
/// - Parameters:
/// - text: The text to search
/// - function: The functionality the find in page should search with
func findInPage(text: String, function: FindInPageFunction)

/// Called whenever the find in page session should be ended.
func findInPageDone()

/// Navigates to the specified index in the history of this session. The current index of
/// this session's history will be updated but the items within it will be unchanged.
/// Invalid index values are ignored.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 Common
import Foundation
import WebKit

public enum FindInPageFunction: String {
/// Find all the occurences of this text in the page
case find

/// Find the next occurence of this text in the page
case findNext

/// Find the previous occurence of this text in the page
case findPrevious
}

public protocol FindInPageHelperDelegate: AnyObject {
func findInPageHelper(didUpdateCurrentResult currentResult: Int)
func findInPageHelper(didUpdateTotalResults totalResults: Int)
}

class FindInPageContentScript: WKContentScript {
weak var delegate: FindInPageHelperDelegate?
private var logger: Logger

init(logger: Logger = DefaultLogger.shared) {
self.logger = logger
}

class func name() -> String {
return "FindInPage"
}

func scriptMessageHandlerNames() -> [String] {
return ["findInPageHandler"]
}

func userContentController(
didReceiveMessage message: Any
) {
guard let parameters = message as? [String: Int] else {
// TODO: FXIOS-6463 - Integrate message handler check
logger.log("FindInPage.js sent wrong type of message",
level: .warning,
category: .webview)
return
}

if let currentResult = parameters["currentResult"] {
delegate?.findInPageHelper(didUpdateCurrentResult: currentResult)
}

if let totalResults = parameters["totalResults"] {
delegate?.findInPageHelper(didUpdateTotalResults: totalResults)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ protocol WKContentScript {

func scriptMessageHandlerNames() -> [String]

func userContentController(
_ userContentController: WKUserContentController,
didReceiveScriptMessage message: WKScriptMessage
)
func userContentController(didReceiveMessage message: Any)

func prepareForDeinit()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import WebKit

/// Manager used to add and remove scripts inside a WKEngineSession
protocol WKContentScriptManager: WKScriptMessageHandler {
var scripts: [String: WKContentScript] { get }

func addContentScript(_ script: WKContentScript,
name: String,
forSession session: WKEngineSession)
Expand All @@ -19,12 +21,12 @@ protocol WKContentScriptManager: WKScriptMessageHandler {
}

class DefaultContentScriptManager: NSObject, WKContentScriptManager {
var scripts = [String: WKContentScript]()
private(set) var scripts = [String: WKContentScript]()

func addContentScript(_ script: WKContentScript,
name: String,
forSession session: WKEngineSession) {
// If a script already exists on a tab, skip adding this duplicate.
// If a script already exists on a session, skip adding this duplicate.
guard scripts[name] == nil else { return }

scripts[name] = script
Expand Down Expand Up @@ -58,7 +60,7 @@ class DefaultContentScriptManager: NSObject, WKContentScriptManager {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
for script in scripts.values where script.scriptMessageHandlerNames().contains(message.name) {
script.userContentController(userContentController, didReceiveScriptMessage: message)
script.userContentController(didReceiveMessage: message.body)
return
}
}
Expand Down
Loading

0 comments on commit 599324a

Please sign in to comment.