Merge mozilla-central to autoland on a CLOSED TREE

This commit is contained in:
Cristian Tuns 2024-03-18 13:08:43 -04:00
commit 8e6b718036
10842 changed files with 1297878 additions and 97 deletions

View file

@ -388,3 +388,22 @@ jobs:
- mozilla-central
when:
- {hour: 0, minute: 0}
- name: nightly-android
job:
type: decision-task
treeherder-symbol: Na
target-tasks-method: nightly-android
include-push-tasks: true
run-on-projects:
- mozilla-central
- oak
when: [] # hook only
- name: android-l10n-import
job:
type: decision-task
treeherder-symbol: android-l10n-import
target-tasks-method: android-l10n-import
run-on-projects: [oak]
when: [] # hook only

View file

@ -189,6 +189,34 @@ mobile/android/app/geckoview-prefs.js
mobile/android/installer/
mobile/android/locales/
# TODO - Bug 1881094: temporarily ignored for firefox-android migration
mobile/android/android-components/components/browser/engine-system/src/main/res/raw/domain_blocklist.json
mobile/android/android-components/components/browser/engine-system/src/main/res/raw/domain_safelist.json
mobile/android/android-components/components/browser/errorpages/src/main/assets/errorPageScripts.js
mobile/android/android-components/components/browser/errorpages/src/main/assets/error_page_js.html
mobile/android/android-components/components/browser/icons/src/main/assets/extensions/browser-icons/icons.js
mobile/android/android-components/components/browser/session-storage/src/androidTest/assets/index.html
mobile/android/android-components/components/concept/engine/src/test/resources/manifests/example_mdn.json
mobile/android/android-components/components/concept/engine/src/test/resources/manifests/invalid_json.json
mobile/android/android-components/components/concept/engine/src/test/resources/manifests/spec_typical.json
mobile/android/android-components/components/concept/engine/src/test/resources/manifests/twitter_mobile.json
mobile/android/android-components/components/feature/accounts/src/main/assets/extensions/fxawebchannel/background.js
mobile/android/android-components/components/feature/accounts/src/main/assets/extensions/fxawebchannel/fxawebchannel.js
mobile/android/android-components/components/feature/addons/src/test/resources/collection.json
mobile/android/android-components/components/feature/addons/src/test/resources/collection_with_empty_values.json
mobile/android/android-components/components/feature/addons/src/test/resources/localized_collection.json
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/
mobile/android/android-components/components/feature/search/src/main/assets/extensions/ads/adsTelemetry.js
mobile/android/android-components/components/feature/search/src/main/assets/extensions/search/searchTelemetry.js
mobile/android/android-components/components/feature/webcompat-reporter/src/main/assets/
mobile/android/android-components/components/feature/webcompat/src/main/assets/extensions/webcompat/
mobile/android/android-components/samples/browser/src/main/assets/extensions/test/background.js
mobile/android/fenix/app/src/androidTest/assets/
mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/syncintegration/
mobile/android/fenix/app/src/main/assets/
mobile/android/focus-android/app/src/androidTest/assets/
mobile/android/android-components/docs/assets/js/icon-js.js
# Pre-processed/pref files
modules/libpref/greprefs.js
modules/libpref/init/all.js

View file

@ -285,3 +285,5 @@ fc01df84fa6d91b9dabb4b608eb947cef3230871 FIREFOX_NIGHTLY_120_END
4ef3a0b2e8cd48a60eed95f8ba15e13ee48432af FIREFOX_NIGHTLY_123_END
2af34b4c9adf8c8defd3251b569af9c38cc0a429 FIREFOX_BETA_124_BASE
3a789882861bf458a92ed529bdbe4ddc39bd9671 FIREFOX_NIGHTLY_124_END
488c57bb8ceed6da3f0be935156a480cdb92bc32 FIREFOX_BETA_125_BASE
3c5105fce0360bb6708a9ac3f09d06527b316119 FIREFOX_NIGHTLY_125_END

View file

@ -1150,6 +1150,14 @@ mobile/android/docs/geckoview/assets/js/search-data.json
# Uses `#filter substitution`
mobile/android/app/geckoview-prefs.js
# TODO - Bug 1881094: temporarily ignored for firefox-android migration
mobile/android/android-components/
mobile/android/fenix/
mobile/android/focus-android/
mobile/android/docs/_includes/
mobile/android/docs/_layouts/
mobile/android/docs/assets/js/icon-js.js
# Not much JS to lint and non-standard at that
mobile/android/installer/
mobile/android/locales/

View file

@ -76,6 +76,12 @@ layout/style/test/gtest/example.css
layout/style/test/mapped2.css
layout/style/test/unstyled-frame.css
# TODO - Bug 1881094: temporarily ignored for firefox-android migration
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readerview.css
mobile/android/android-components/components/feature/webcompat/src/main/assets/extensions/webcompat/about-compat/aboutCompat.css
mobile/android/android-components/docs/assets/main.scss
mobile/android/fenix/app/src/main/assets/shared_error_style.css
# Empty test files:
netwerk/test/mochitests/test1.css
netwerk/test/mochitests/test2.css

View file

@ -22,4 +22,4 @@
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.
Removed proxying objects - Bug 1878638: Remove handle duplication rules for Windows process sandboxes
Merge day clobber 2024-03-18

View file

@ -1 +1 @@
125.0a1
126.0a1

View file

@ -1 +1 @@
125.0a1
126.0a1

View file

@ -14,7 +14,15 @@ buildscript {
}
}
ext.kotlin_version = '1.9.22'
ext {
kotlin_version = Versions.kotlin
detekt_plugin = Versions.detekt
python_envs_plugin = Versions.python_envs_plugin
ksp_plugin = Versions.ksp_plugin
// Used in mobile/android/fenix/app/build.gradle
protobuf_plugin = FenixVersions.protobuf_plugin
}
dependencies {
classpath 'org.mozilla.apilint:apilint:0.5.2'
@ -23,9 +31,21 @@ buildscript {
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
classpath 'org.tomlj:tomlj:1.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Used in mobile/android/fenix/app/build.gradle
classpath FenixDependencies.androidx_safeargs
classpath FenixDependencies.osslicenses_plugin
classpath FenixDependencies.tools_benchmarkgradle
classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
}
}
plugins {
id("io.gitlab.arturbosch.detekt").version("$detekt_plugin")
id("com.google.devtools.ksp").version("$ksp_plugin")
}
def tryInt = { string ->
if (string == null) {
return string
@ -347,12 +367,25 @@ afterEvaluate {
"-Xlint:-serial",
// Classfile, because javac has a bug with MethodParameters attributes
// with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
"-Xlint:-classfile",
// Turn all remaining warnings into errors,
// unless marked by @SuppressWarnings.
"-Werror"]
"-Xlint:-classfile"]
// In GeckoView java projects only, turn all remaining warnings
// into errors unless marked by @SuppressWarnings.
def projectName = project.getName()
if (projectName.startsWith('geckoview')
|| projectName == 'annotations'
|| projectName == 'exoplayer2'
|| projectName == 'messaging_example'
|| projectName == 'port_messaging_example'
|| projectName == 'test_runner'
) {
options.compilerArgs += [
"-Werror"
]
}
}
}
}
apply plugin: 'idea'
@ -385,7 +418,16 @@ idea {
}
}
subprojects {
subprojects { project ->
// Perform spotless lint in GeckoView projects only.
def projectName = project.getName()
if (projectName.startsWith('geckoview')
|| projectName == 'annotations'
|| projectName == 'exoplayer2'
|| projectName == 'messaging_example'
|| projectName == 'port_messaging_example'
|| projectName == 'test_runner'
) {
apply plugin: "com.diffplug.spotless"
spotless {
@ -404,4 +446,29 @@ subprojects {
ktlint('0.49.1')
}
}
} else {
afterEvaluate {
// Set the source and target compatibility for non-GeckoView projects only.
if (it.hasProperty('android')) {
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
}
}
}
project.configurations.configureEach {
resolutionStrategy.capabilitiesResolution.withCapability("org.mozilla.telemetry:glean-native") {
def toBeSelected = candidates.find {
it.id instanceof ProjectComponentIdentifier && it.id.projectName.contains('geckoview')
}
if (toBeSelected != null) {
select(toBeSelected)
}
because 'use GeckoView Glean instead of standalone Glean'
}
}
}

View file

@ -92,3 +92,16 @@ path:tools/browsertime/package-lock.json
path:testing/geckodriver
path:testing/mozbase/rust
path:testing/webdriver
# for firefox-android
path:mobile/android/android-components/.buildconfig.yml
path:mobile/android/focus-android/.buildconfig.yml
path:mobile/android/fenix/.buildconfig.yml
path:mobile/android/android-components/gradle/wrapper/gradle-wrapper.properties
path:mobile/android/focus-android/gradle/wrapper/gradle-wrapper.properties
path:mobile/android/fenix/gradle/wrapper/gradle-wrapper.properties
path:mobile/android/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt
path:mobile/android/android-components/plugins/dependencies/src/main/java/ApplicationServices.kt
path:mobile/android/focus-android/plugins/focusdependencies/src/main/java/FocusDependenciesPlugin.kt
path:mobile/android/fenix/plugins/fenixdependencies/src/main/java/FenixDependenciesPlugin.kt
path:mobile/android/version.txt

View file

@ -10,4 +10,4 @@
# hardcoded milestones in the tree from these two files.
#--------------------------------------------------------
125.0a1
126.0a1

View file

@ -25,6 +25,8 @@ categories:
- toolkit
- js
- mobile/android/geckoview
- mobile/android/fenix
- mobile/android/focus-android
- dom/bindings/webidl
- modules/libpref
- networking

30
mobile/android/.cron.yml Normal file
View file

@ -0,0 +1,30 @@
# Definitions for jobs that run periodically. For details on the format, see
# `taskcluster/taskgraph/cron/schema.py`. For documentation, see
# `taskcluster/docs/cron.rst`.
---
jobs:
- name: nightly
job:
type: decision-task
treeherder-symbol: nightly-D
target-tasks-method: nightly
when: []
- name: nightly-test
job:
type: decision-task
treeherder-symbol: Nt
target-tasks-method: nightly-test
when: []
- name: screenshots
job:
type: decision-task
treeherder-symbol: screenshots-D
target-tasks-method: screenshots
when: [] # unscheduled
- name: legacy-api-ui-tests
job:
type: decision-task
treeherder-symbol: legacy-api-ui
target-tasks-method: legacy_api_ui_tests
when: [] # unscheduled

View file

@ -0,0 +1,12 @@
# [components] Issue mozilla-mobile/android-components#12939: Address all ktlint issues
a7eb0fe9d057982cb5eb1ad670e8195afe7fba1a
# [components] For mozilla-mobile/android-components#12930 - Fix old but now blocking ktlint issues
44988dca372d00d8e523176b23d22348558dd5ab
# [components] For mozilla-mobile/android-components#12500: Fix ktlint issues.
2998899e7929ce99f920d4dd6bc13f86c426003b
# [components] For mozilla-mobile/android-components#12151 - Fix ktlint issues for GeckoPromptDelegate.kt
5d28c56cfa19c65c48bd50e3f622130a7f5435e4
# [fenix] For mozilla-mobile/fenix#27667 - Remove import-ordering from the list of disabled ktlint rules
e3b88788dbe03cf41ac015a848fa1ee0b40d39e2
# [fenix] For mozilla-mobile/fenix#26844: Fix ktlint issues and remove them from baseline.
1a2ecb6374198c2bc5266a70a19700de0b294b6f

View file

@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: We are now using Bugzilla for issue tracking!
url: https://bugzilla.mozilla.org/enter_bug.cgi?product=Fenix
about: Please file your ticket there, and select the corresponding component from the list. If the component is not in the list, select "General". In commit messages, please reference the ticket using "Bug 1234567 - " as prefix.

5
mobile/android/.github/SECURITY.md vendored Normal file
View file

@ -0,0 +1,5 @@
# Mozilla Security #
- Mozilla cares about privacy and security. For more information please see: https://www.mozilla.org/security/
- If you believe that you've found a security vulnerability, please report it by sending email to the addresses: android-components-security@mozilla.com and security@mozilla.org.

View file

@ -0,0 +1,23 @@
### Pull Request checklist
<!-- Before submitting the PR, please address each item -->
- [ ] **Quality**: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
- [ ] **Tests**: This PR includes thorough tests or an explanation of why it does not
- [ ] **Changelog**: This PR includes [a changelog entry](https://github.com/mozilla-mobile/firefox-android/blob/main/docs/changelog.md) or does not need one
- [ ] **Accessibility**: The code in this PR follows [accessibility best practices](https://github.com/mozilla-mobile/firefox-android/blob/main/docs/shared/android/accessibility_guide.md) or does not include any user facing features
### After merge
- **Breaking Changes**: If this is a breaking Android Components change, please push a draft PR on [Reference Browser](https://github.com/mozilla-mobile/reference-browser) to address the breaking issues.
### To download an APK when reviewing a PR (after all CI tasks finished running):
1. Click on `Checks` at the top of the PR page.
2. Click on the `firefoxci-taskcluster` group on the left to expand all tasks.
3. Click on the `build-apk-{fenix,focus,klar}-debug` task you're interested in.
4. Click on `View task in Taskcluster` in the new `DETAILS` section.
5. The APK links should be on the right side of the screen, named for each CPU architecture.
### GitHub Automation
<!-- Do not add anything below this line -->
Used by GitHub Actions.

View file

@ -0,0 +1,46 @@
# 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/
#
# This workflow periodically calls the relbot action to update GeckoView
# Beta.
#
# The relbot action will look at Maven and compare the latest GV Beta
# release available to what is currently configured in GeckoView.kt on
# a hard coded A-C release branch. If the branch is outdated then
# a new PR will be created to update the GV version and increment the
# A-C version.
#
name: "AC - Update GeckoView"
permissions:
contents: write
pull-requests: write
on:
schedule:
- cron: '*/15 * * * *'
jobs:
main:
name: "Update GeckoView"
runs-on: ubuntu-20.04
steps:
- name: "Update GV (On Main)"
uses: mozilla-mobile/relbot@6.1.0
if: github.repository == 'mozilla-mobile/firefox-android'
with:
project: android-components
command: update-main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update GV (On Releases)"
uses: mozilla-mobile/relbot@6.1.0
if: github.repository == 'mozilla-mobile/firefox-android'
with:
project: android-components
command: update-releases
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -0,0 +1,22 @@
# 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/
name: Bugzilla Format
on:
pull_request_target:
types: [opened, synchronize, reopened, edited, ready_for_review]
branches:
- main
jobs:
bugzilla_format:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]' && github.actor != 'dependabot[bot]' && github.actor != 'MickeyMoz'
steps:
- name: Bugzilla Format
uses: gabrielluong/bugzilla-format@1.0.1
if: github.repository == 'mozilla-mobile/firefox-android'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

View file

@ -0,0 +1,22 @@
# 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/
name: Bugzilla Issue Linker
on:
pull_request_target:
types: [opened, synchronize, reopened, edited, ready_for_review]
branches:
- main
jobs:
bugzilla_linker:
runs-on: ubuntu-latest
steps:
- name: Bugzilla Linker
uses: gabrielluong/bugzilla-linker@1.0.0
if: github.repository == 'mozilla-mobile/firefox-android'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
section: "### GitHub Automation"

View file

@ -0,0 +1,40 @@
# 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/
name: "Fenix - Update Nimbus Experiments"
on:
workflow_dispatch: {}
jobs:
fenix-update-nimbus-experiments:
name: "Update Nimbus Experiments"
runs-on: ubuntu-latest
steps:
- name: "Checkout Main Branch"
uses: actions/checkout@v3
with:
path: fenix
ref: main
fetch-depth: 0
- name: "Update Experiments JSON"
id: update-experiments-json
uses: mozilla-mobile/update-experiments@v3
with:
repo-path: fenix
output-path: fenix/app/src/main/res/raw/initial_experiments.json
experimenter-url: https://experimenter.services.mozilla.com/api/v6/experiments-first-run/
app-name: fenix
branch: automation/update-fenix-nimbus-experiments
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
if: steps.update-experiments-json.outputs.changed == 1 && steps.update-experiments-json.outputs.changed-branch >= 1
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: fenix
branch: automation/update-fenix-nimbus-experiments
commit-message: "Update Fenix initial_experiments.json based on the current first-run experiments in experimenter"
title: "Update Fenix initial experiments JSON for Nimbus"
body: "This (automated) PR updates the initial_experiments.json on the `main` branch"
delete-branch: true

View file

@ -0,0 +1,40 @@
# 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/
name: "Focus - Update Nimbus Experiments"
on:
workflow_dispatch: {}
jobs:
focus-update-nimbus-experiments:
name: "Update Nimbus Experiments"
runs-on: ubuntu-latest
steps:
- name: "Checkout Main Branch"
uses: actions/checkout@v3
with:
path: focus-android
ref: main
fetch-depth: 0
- name: "Update Experiments JSON"
id: update-experiments-json
uses: mozilla-mobile/update-experiments@v3
with:
repo-path: focus-android
output-path: focus-android/app/src/main/res/raw/initial_experiments.json
experimenter-url: https://experimenter.services.mozilla.com/api/v6/experiments-first-run/
app-name: focus_android
branch: automation/update-focus-nimbus-experiments
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
if: steps.update-experiments-json.outputs.changed == 1 && steps.update-experiments-json.outputs.changed-branch >= 1
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: focus-android
branch: automation/update-focus-nimbus-experiments
commit-message: "Update Focus initial_experiments.json based on the current first-run experiments in experimenter"
title: "Update Focus initial experiments JSON for Nimbus"
body: "This (automated) PR updates the initial_experiments.json on the `main` branch"
delete-branch: true

View file

@ -0,0 +1,10 @@
---
name: Glean probe-scraper
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
glean-probe-scraper:
uses: mozilla/probe-scraper/.github/workflows/glean.yaml@main

View file

@ -0,0 +1,86 @@
# 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/
name: Import l10n translations
permissions:
contents: write
pull-requests: write
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
copy:
name: Import strings
runs-on: ubuntu-latest
steps:
- name: Discover A-C beta version
id: discover-beta-version
uses: mozilla-mobile/fenix-beta-version@4.2.3
- name: Checkout Beta Branch
uses: actions/checkout@v3
with:
path: "source"
ref: releases_v${{ steps.discover-beta-version.outputs.beta_version }}
- name: Clone android-l10n repository
uses: actions/checkout@v3
with:
repository: "mozilla-l10n/android-l10n"
path: "l10n"
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Python dependencies
run: |
pip install -r l10n/.github/requirements.txt
- name: Copy translated files for android-components
run: >
python l10n/.github/scripts/import_strings.py l10n
--toml l10n/mozilla-mobile/android-components/l10n.toml
--dest source/android-components
- name: Copy translated files for fenix
run: >
python l10n/.github/scripts/import_strings.py l10n
--toml l10n/mozilla-mobile/fenix/l10n.toml
--dest source/fenix
- name: Copy translated files for focus-android
run: >
python l10n/.github/scripts/import_strings.py l10n
--toml l10n/mozilla-mobile/focus-android/l10n.toml
--dest source/focus-android
- name: Commit changes and open pull request
run: |
# Only try to commit if there are pending changes
cd source
if [[ $(git diff --exit-code) || $(git ls-files --other --exclude-standard) ]]
then
branch="automation/import-l10n"
git config user.name "github-actions"
git config user.email "github-actions@users.noreply.github.com"
git checkout -B "$branch"
git add .
git commit -m "Import translations from android-l10n"
git push -f origin "$branch"
# Create pull request if there isn't one open yet, use the last
# commit message as title.
open_prs=$(gh pr list --repo "$GITHUB_REPOSITORY" --json headRefName | jq --arg BRANCH "$branch" 'map(select(.headRefName==$BRANCH)) | length')
if (( $open_prs > 0 )); then
echo "Existing pull request updated."
pr_link=$(gh pr list --repo "$GITHUB_REPOSITORY" --json headRefName,url | jq -r --arg BRANCH "$branch" 'map(select(.headRefName==$BRANCH)) | .[].url')
echo "Link: $pr_link"
else
echo "Opening new pull request."
gh pr create --fill --base releases_v${{ steps.discover-beta-version.outputs.beta_version }}
fi
else
echo "No changes found."
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -0,0 +1,26 @@
# 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/
name: Pull Request Labeler
on:
pull_request_target:
types: [opened, reopened, synchronize, converted_to_draft, ready_for_review, review_requested]
branches:
- main
pull_request_review:
types: [submitted]
branches:
- main
jobs:
pull_request_labeler:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]' && github.actor != 'dependabot[bot]' && github.actor != 'MickeyMoz'
steps:
- name: Pull Request Labeler
uses: gabrielluong/pull-request-labeler@1.0.6
if: github.repository == 'mozilla-mobile/firefox-android'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

103
mobile/android/.gitignore vendored Normal file
View file

@ -0,0 +1,103 @@
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
!taskcluster/ci/build/
.build-cache/
# Local configuration file (sdk path, etc)
local.properties
.lastAutoPublishContentsHash
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Intellij
*.iml
.idea/
# Vim swap files
*.sw[op]
# Keystore files
*.jks
# OS X
.DS_Store
# jacoco.exec
jacoco.exec
#Gihub Bot Token
.github_token
# UI test artifacts
.firebase_token*
results/
test_artifacts/
/build/test-tools/google-cloud-sdk/
/build/test-tools/*.jar
/build/test-tools/*.gz
# Screenshots
fastlane/
# Secrets files, e.g. tokens
.adjust_token
.sentry_token
.mls_token
.nimbus
.wallpaper_url
.pocket_consumer_key
fenix/app/src/**/res/values/fenix_firebase_push_credentials.xml
# Python Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
venv/
# Web extensions: manifest.json files are generated
manifest.json
# Xcode
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
*.xcscmblueprint
.build

View file

@ -0,0 +1,86 @@
queue_rules:
- name: default
conditions:
- status-success=complete-pr
- or:
- current-datetime<2024-03-15T00:00:00Z
- base!=main
allow_checks_interruption: false
priority_rules:
- name: high priority
conditions:
- label=urgent
priority: high
pull_request_rules:
- name: Resolve conflict
conditions:
- conflict
actions:
comment:
message: This pull request has conflicts when rebasing. Could you fix it @{{author}}? 🙏
- name: MickeyMoz - Auto Merge
conditions:
- author=MickeyMoz
- status-success=complete-pr
- files~=^android-components/(Gecko\.kt|components/lib/publicsuffixlist/src/main/assets/publicsuffixes)
- -files~=^(?!android-components/(Gecko\.kt|components/lib/publicsuffixlist/src/main/assets/publicsuffixes)).+$
actions:
review:
type: APPROVE
message: MickeyMoz 💪
queue:
method: rebase
name: default
- name: L10N - Auto Merge
conditions:
- author=github-actions[bot]
- status-success=complete-pr
- files~=^(android-components|fenix|focus-android)/(.+/strings\.xml|l10n\.toml)
- -files~=^(?!(android-components|fenix|focus-android)/(.+/strings\.xml|l10n\.toml)).+$
actions:
review:
type: APPROVE
message: LGTM 😎
queue:
method: rebase
name: default
- name: Release automation
conditions:
- author=github-actions[bot]
- status-success=complete-pr
- status-success=complete-push
- files~=^android-components/(\.buildconfig\.yml|plugins/dependencies/src/main/java/(ApplicationServices|DependenciesPlugin|Gecko)\.kt)
- -files~=^(?!android-components/(\.buildconfig\.yml|plugins/dependencies/src/main/java/(ApplicationServices|DependenciesPlugin|Gecko)\.kt)).+$
actions:
review:
type: APPROVE
message: 🚢
queue:
method: rebase
name: default
delete_head_branch:
force: false
- name: Needs landing - Rebase
conditions:
- status-success=complete-pr
- label=🛬 needs landing
- "#approved-reviews-by>=1"
- -draft
- label!=work in progress
- label!=do not land
actions:
queue:
method: rebase
name: default
- name: Needs landing - Squash
conditions:
- status-success=complete-pr
- label=🛬 needs landing (squash)
- "#approved-reviews-by>=1"
- -draft
- label!=work in progress
- label!=do not land
actions:
queue:
method: squash
name: default

View file

@ -0,0 +1,350 @@
---
version: 1
reporting: checks-v1
policy:
pullRequests: public_restricted
tasks:
- $let:
trustDomain: mobile
canonicalRepo: https://github.com/mozilla-mobile/firefox-android
isPullRequest:
# We now support both github-pull-request and github-pull-request-untrusted
$eval: 'tasks_for[:19] == "github-pull-request"'
ownTaskId:
$if: '"github" in tasks_for'
then: {$eval: as_slugid("decision_task")}
else:
$if: 'tasks_for == "cron"'
then: '${ownTaskId}'
in:
$let:
# Github events have this stuff in different places...
ownerEmail:
$if: 'tasks_for in ["cron", "action"]'
then: '${tasks_for}@noreply.mozilla.org'
else:
# GitHub adds "[bot]" to bot usernames and that doesn't validate as email.
$if: 'event.sender.login == "bors[bot]"'
then: 'skaspari+mozlando@mozilla.com' # It must match what's in bors.toml
else:
$if: 'tasks_for == "github-push"'
then:
$if: 'event.pusher.email'
then: '${event.pusher.email}'
else: '${event.pusher.name}@users.noreply.github.com'
else:
$if: 'isPullRequest'
then: '${event.pull_request.user.login}@users.noreply.github.com'
repoFullName:
$if: 'tasks_for in "github-push"'
then: '${event.repository.full_name}'
else:
$if: 'isPullRequest'
then: '${event.pull_request.base.repo.full_name}'
else:
$if: 'tasks_for in ["cron", "action"]'
# Trim https://github.com/
then: '${repository.url[19:]}'
baseRepoUrl:
$if: 'tasks_for == "github-push"'
then: '${event.repository.html_url}'
else:
$if: 'isPullRequest'
then: '${event.pull_request.base.repo.html_url}'
else:
$if: 'tasks_for in ["cron", "action"]'
then: '${repository.url}'
repoUrl:
$if: 'tasks_for == "github-push"'
then: '${event.repository.html_url}'
else:
$if: 'isPullRequest'
then: '${event.pull_request.head.repo.html_url}'
else:
$if: 'tasks_for in ["cron", "action"]'
then: '${repository.url}'
project:
$if: 'tasks_for == "github-push"'
then: '${event.repository.name}'
else:
$if: 'isPullRequest'
then: '${event.pull_request.head.repo.name}'
else:
$if: 'tasks_for in ["cron", "action"]'
then: '${repository.project}'
base_ref:
$if: 'isPullRequest'
then: ${event.pull_request.base.ref}
else:
# event.base_ref is barely documented[1]. Testing showed it's only
# defined when creating a new branch. It's null when pushing to an
# existing branch
#
# [1] https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
$if: 'tasks_for == "github-push" && event.base_ref'
then: ${event.base_ref}
else:
$if: 'tasks_for == "github-push"'
then: ${event.ref}
else:
$if: 'tasks_for in ["cron", "action"]'
then:
$if: 'push.branch[:11] == "refs/heads/"'
then: {$eval: 'push.branch[11:]'}
else: ${push.branch}
head_ref:
$if: 'isPullRequest'
then: ${event.pull_request.head.ref}
else:
$if: 'tasks_for == "github-push"'
then: ${event.ref}
else:
$if: 'tasks_for in ["cron", "action"]'
then: '${push.branch}'
base_sha:
$if: 'tasks_for == "github-push"'
then: '${event.before}'
else:
$if: 'isPullRequest'
then: '${event.pull_request.base.sha}'
else:
$if: 'tasks_for in ["cron", "action"]'
then: '${push.revision}'
head_sha:
$if: 'tasks_for == "github-push"'
then: '${event.after}'
else:
$if: 'isPullRequest'
then: '${event.pull_request.head.sha}'
else:
$if: 'tasks_for in ["cron", "action"]'
then: '${push.revision}'
pullRequestAction:
$if: 'isPullRequest'
then: ${event.action}
else: 'UNDEFINED'
in:
$let:
level:
$if: >
tasks_for in ["github-push", "action", "cron"] && repoUrl == canonicalRepo
then: '3'
else: '1'
short_base_ref:
$if: 'base_ref[:11] == "refs/heads/"'
then: {$eval: 'base_ref[11:]'}
else: ${base_ref}
short_head_ref:
$if: 'head_ref[:11] == "refs/heads/"'
then: {$eval: 'head_ref[11:]'}
else: ${head_ref}
in:
$if: >
tasks_for in ["action", "cron"]
|| (isPullRequest && pullRequestAction in ["opened", "reopened", "synchronize"])
|| (tasks_for == "github-push" && head_ref[:10] != "refs/tags/" && short_head_ref != "staging.tmp" && short_head_ref != "trying.tmp" && short_head_ref[:8] != "mergify/")
then:
$mergeDeep:
- $if: 'tasks_for != "action"'
then:
taskId: '${ownTaskId}'
- taskGroupId:
$if: 'tasks_for == "action"'
then:
'${action.taskGroupId}'
else:
'${ownTaskId}' # same as taskId; this is how automation identifies a decision task
schedulerId: '${trustDomain}-level-${level}'
created: {$fromNow: ''}
deadline: {$fromNow: '1 day'}
expires: {$fromNow: '1 year 1 second'} # 1 second so artifacts expire first, despite rounding errors
metadata:
$merge:
- owner: "${ownerEmail}"
source: '${repoUrl}/raw/${head_sha}/.taskcluster.yml'
- $if: 'isPullRequest || tasks_for == "github-push"'
then:
name: "Decision Task"
description: 'The task that creates all of the other tasks in the task graph'
else:
$if: 'tasks_for == "action"'
then:
name: "Action: ${action.title}"
description: |
${action.description}
Action triggered by clientID `${clientId}`
else:
name: "Decision Task for cron job ${cron.job_name}"
description: 'Created by a [cron task](https://firefox-ci-tc.services.mozilla.com/tasks/${cron.task_id})'
provisionerId: "mobile-${level}"
workerType: "decision-gcp"
tags:
$if: 'isPullRequest || tasks_for == "github-push"'
then:
kind: decision-task
else:
$if: 'tasks_for == "action"'
then:
kind: 'action-callback'
else:
$if: 'tasks_for == "cron"'
then:
kind: cron-task
routes:
$flattenDeep:
- checks
- $if: 'level == "3" || repoUrl == "https://github.com/mozilla-releng/staging-firefox-android"'
then:
- tc-treeherder.v2.${project}.${head_sha}
- $if: 'tasks_for == "github-push"'
then:
- index.mobile.v2.${project}.branch.${short_head_ref}.latest.taskgraph.decision
- index.mobile.v2.${project}.branch.${short_head_ref}.revision.${head_sha}.taskgraph.decision
- index.mobile.v2.${project}.revision.${head_sha}.taskgraph.decision
- $if: 'tasks_for == "cron"'
then:
# cron context provides ${head_ref} as a short one
- index.mobile.v2.${project}.branch.${head_ref}.latest.taskgraph.decision-${cron.job_name}
- index.mobile.v2.${project}.branch.${head_ref}.revision.${head_sha}.taskgraph.decision-${cron.job_name}
- index.mobile.v2.${project}.branch.${head_ref}.revision.${head_sha}.taskgraph.cron.${ownTaskId}
scopes:
$if: 'tasks_for == "github-push"'
then:
- 'assume:repo:github.com/${repoFullName}:branch:${short_head_ref}'
else:
$if: 'isPullRequest'
then:
- 'assume:repo:github.com/${repoFullName}:${tasks_for[7:]}'
else:
$if: 'tasks_for == "action"'
then:
# when all actions are hooks, we can calculate this directly rather than using a variable
- '${action.repo_scope}'
else:
- 'assume:repo:github.com/${repoFullName}:cron:${cron.job_name}'
requires: all-completed
priority: lowest
retries: 5
payload:
env:
# run-task uses these to check out the source; the inputs
# to `mach taskgraph decision` are all on the command line.
$merge:
- MOBILE_BASE_REPOSITORY: '${baseRepoUrl}'
MOBILE_BASE_REF: '${short_base_ref}'
MOBILE_BASE_REV: '${base_sha}'
MOBILE_HEAD_REPOSITORY: '${repoUrl}'
MOBILE_HEAD_REF: '${short_head_ref}'
MOBILE_HEAD_REV: '${head_sha}'
MOBILE_PIP_REQUIREMENTS: taskcluster/requirements.txt
MOBILE_REPOSITORY_TYPE: git
MOZ_AUTOMATION: "1"
REPOSITORIES: {$json: {mobile: "firefox-android"}}
- $if: 'isPullRequest'
then:
MOBILE_PULL_REQUEST_NUMBER: '${event.pull_request.number}'
- $if: 'tasks_for == "action"'
then:
ACTION_TASK_GROUP_ID: '${action.taskGroupId}' # taskGroupId of the target task
ACTION_TASK_ID: {$json: {$eval: 'taskId'}} # taskId of the target task (JSON-encoded)
ACTION_INPUT: {$json: {$eval: 'input'}}
ACTION_CALLBACK: '${action.cb_name}'
features:
taskclusterProxy: true
chainOfTrust: true
# Note: This task is built server side without the context or tooling that
# exist in tree so we must hard code the hash
image:
mozillareleases/taskgraph:decision-10068f116a3800a829ddba367136a95bef5634e06f77e051859586202c93b18a@sha256:a74ed430fd80ebb647bb4a5b019523cf5f69246ed2c2603386dbc8f7200c8140
maxRunTime: 1800
command:
- /usr/local/bin/run-task
- '--mobile-checkout=/builds/worker/checkouts/vcs'
- '--task-cwd=/builds/worker/checkouts/vcs'
- '--'
- bash
- -cx
- $let:
extraArgs: {$if: 'tasks_for == "cron"', then: '${cron.quoted_args}', else: ''}
in:
$if: 'tasks_for == "action"'
then: >
cd /builds/worker/checkouts/vcs &&
ln -s /builds/worker/artifacts artifacts &&
~/.local/bin/taskgraph action-callback
else: >
cd /builds/worker/checkouts/vcs &&
ln -s /builds/worker/artifacts artifacts &&
~/.local/bin/taskgraph decision
--pushlog-id='0'
--pushdate='0'
--project='${project}'
--message=""
--owner='${ownerEmail}'
--level='${level}'
--base-repository="$MOBILE_BASE_REPOSITORY"
--base-ref="$MOBILE_BASE_REF"
--base-rev="$MOBILE_BASE_REV"
--head-repository="$MOBILE_HEAD_REPOSITORY"
--head-ref="$MOBILE_HEAD_REF"
--head-rev="$MOBILE_HEAD_REV"
--repository-type="$MOBILE_REPOSITORY_TYPE"
--tasks-for='${tasks_for}'
${extraArgs}
artifacts:
'public':
type: 'directory'
path: '/builds/worker/artifacts'
expires: {$fromNow: '1 year'}
'public/docker-contexts':
type: 'directory'
path: '/builds/worker/checkouts/vcs/docker-contexts'
# This needs to be at least the deadline of the
# decision task + the docker-image task deadlines.
# It is set to a week to allow for some time for
# debugging, but they are not useful long-term.
expires: {$fromNow: '7 day'}
extra:
$merge:
- treeherder:
$merge:
- machine:
platform: gecko-decision
- $if: 'isPullRequest || tasks_for == "github-push"'
then:
symbol: D
else:
$if: 'tasks_for == "action"'
then:
groupName: 'action-callback'
groupSymbol: AC
symbol: "${action.symbol}"
else:
groupSymbol: cron
symbol: "${cron.job_symbol}"
- $if: 'tasks_for == "action"'
then:
parent: '${action.taskGroupId}'
action:
name: '${action.name}'
context:
taskGroupId: '${action.taskGroupId}'
taskId: {$eval: 'taskId'}
input: {$eval: 'input'}
clientId: {$eval: 'clientId'}
- $if: 'tasks_for == "cron"'
then:
cron: {$json: {$eval: 'cron'}}
- tasks_for: '${tasks_for}'

30
mobile/android/CODEOWNERS Normal file
View file

@ -0,0 +1,30 @@
# 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/.
# This CODEOWNERS file defines individuals or teams that are responsible
# for code in this repository. Code owners are automatically requested
# for review when someone opens a pull request that modifies code that
# they own. Order is important; the last matching pattern takes the most
# precedence.
# A CODEOWNERS file uses a pattern that follows the same rules used in
# gitignore files. The pattern is followed by one or more GitHub usernames
# or team names using the standard @username or @org/team-name format.
# You can also refer to a user by an email address that has been added
# to their GitHub account, for example user@example.com.
# https://help.github.com/articles/about-codeowners/
# Release Engineering pipeline
/.cron.yml @mozilla-mobile/releng
/.taskcluster.yml @mozilla-mobile/releng
/android-components/automation/ @mozilla-mobile/aet @mozilla-mobile/QA
/fenix/automation/ @mozilla-mobile/aet @mozilla-mobile/QA
/focus-android/automation/ @mozilla-mobile/aet @mozilla-mobile/QA
/taskcluster/ @mozilla-mobile/releng @mozilla-mobile/aet
# Any android components that may need specific people to be notified
/android-components/components/feature/accounts-push/ @jonalmeida
/android-components/components/feature/push/ @jonalmeida
/android-components/components/lib/push-firebase/ @jonalmeida
/android-components/components/lib/state/ @csadilek @jonalmeida

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
# Maven group ID used for all components
componentsGroupId: "org.mozilla.components"
# Synchronized build configuration for all modules
jvmTargetCompatibility: 17
compileSdkVersion: 34
minSdkVersion: 21
targetSdkVersion: 34

View file

@ -0,0 +1,15 @@
# This is an .editorconfig that ktlint will "stop" at.
# If an .editorconfig file exists in any parent directory of the checkout
# directory, ktlint will fail because it uses those settings to determine what
# the indentation should be.
root = True
[*.kt]
indent_size = 4
indent_style = space
ij_kotlin_allow_trailing_comma_on_call_site=true
ij_kotlin_allow_trailing_comma=true

View file

@ -0,0 +1,12 @@
# 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/.
# Treat generated API docs as binary. We do not want them to pollute
# our diffs.
docs/api/**/* -text -diff linguist-generated=true
# Treat the public suffix list file as text
**/publicsuffixes diff

View file

@ -0,0 +1,2 @@
The changelog is now hosted here:
https://mozilla-mobile.github.io/android-components/changelog/

View file

@ -0,0 +1,325 @@
# Android components
[![Task Status](https://firefox-ci-tc.services.mozilla.com/api/github/v1/repository/mozilla-mobile/android-components/main/badge.svg)](https://firefox-ci-tc.services.mozilla.com/api/github/v1/repository/mozilla-mobile/android-components/main/latest)
[![Mergify Status](https://img.shields.io/endpoint.svg?url=https://gh.mergify.io/badges/mozilla-mobile/android-components&style=flat)](https://mergify.io)
[![chat.mozilla.org](https://img.shields.io/badge/chat-on%20matrix-51bb9c)](https://chat.mozilla.org/#/room/#android-components:mozilla.org)
_A collection of Android libraries to build browsers or browser-like applications._
For more information **[see the website](https://mozilla-mobile.github.io/android-components/)**.
A fully-featured reference browser implementation based on the components can be found in the [reference-browser repository](https://github.com/mozilla-mobile/reference-browser).
# Getting Involved
We encourage you to participate in this open source project. We love pull requests, bug reports, ideas, (security) code reviews or any kind of positive contribution.
Before you attempt to make a contribution please read the [Community Participation Guidelines](https://www.mozilla.org/en-US/about/governance/policies/participation/).
* Matrix: [android-components:mozilla.org chat room](https://chat.mozilla.org/#/room/#android-components:mozilla.org) ([How to connect](https://wiki.mozilla.org/Matrix#Connect_to_Matrix)).
* Localization happens on [Pontoon](https://pontoon.mozilla.org/projects/android-l10n/). Please get in touch with delphine (at) mozilla (dot) com directly for more information.
# Maven repository
All components are getting published on [maven.mozilla.org](https://maven.mozilla.org/).
To use them, you need to add the following to your project's top-level build file, in the `allprojects` block (see e.g. the [reference-browser](https://github.com/mozilla-mobile/reference-browser/blob/main/build.gradle)):
```groovy
repositories {
maven {
url "https://maven.mozilla.org/maven2"
}
}
```
Each module that uses a component needs to specify it in its build file, in the `dependencies` block. For example, to use the `Base` component (in the `support`) collection, you need:
```groovy
dependencies {
implementation 'org.mozilla.components:support-base:+'
}
```
## Nightly builds
Nightly builds are created every day from the `main` branch and published on [nightly.maven.mozilla.org](https://nightly.maven.mozilla.org).
# Components
* 🔴 **In Development** - Not ready to be used in shipping products.
* ⚪ **Preview** - This component is almost/partially ready and can be tested in products.
* 🔵 **Production ready** - Used by shipping products.
## Browser
High-level components for building browser(-like) apps.
* 🔵 [**Awesomebar**](components/browser/awesomebar/README.md) - A customizable [Awesome Bar](https://support.mozilla.org/en-US/kb/awesome-bar-search-firefox-bookmarks-history-tabs) implementation for browsers.
* 🔵 [**Domains**](components/browser/domains/README.md) Localized and customizable domain lists for auto-completion in browsers.
* 🔵 [**Engine-Gecko**](components/browser/engine-gecko/README.md) - *Engine* implementation based on [GeckoView](https://wiki.mozilla.org/Mobile/GeckoView).
* 🔵 [**Engine-System**](components/browser/engine-system/README.md) - *Engine* implementation based on the system's WebView.
* 🔵 [**Errorpages**](components/browser/errorpages/README.md) - Responsive browser error pages for Android apps.
* 🔵 [**Icons**](components/browser/icons/README.md) - A component for loading and storing website icons (like [Favicons](https://en.wikipedia.org/wiki/Favicon)).
* 🔵 [**Menu**](components/browser/menu/README.md) - A generic menu with customizable items primarily for browser toolbars.
* ⚪ [**Menu 2**](components/browser/menu2/README.md) - A generic menu with customizable items primarily for browser toolbars.
* 🔵 [**Session-Storage**](components/browser/session-storage/README.md) - Component for saving and restoring the browser state.
* 🔵 [**State**](components/browser/state/README.md) - Component for maintaining the centralized state of the browser and its components.
* 🔵 [**Storage-Sync**](components/browser/storage-sync/README.md) - A syncable implementation of browser storage backed by [application-services' Places lib](https://github.com/mozilla/application-services).
* 🔵 [**Tabstray**](components/browser/tabstray/README.md) - A customizable tabs tray for browsers.
* 🔵 [**Thumbnails**](components/browser/thumbnails/README.md) - A component for loading and storing website thumbnails (screenshot of the website).
* 🔵 [**Toolbar**](components/browser/toolbar/README.md) - A customizable toolbar for browsers.
## Concept
_API contracts and abstraction layers for browser components._
* 🔵 [**Awesomebar**](components/concept/awesomebar/README.md) - An abstract definition of an awesome bar component.
* 🔵 [**Engine**](components/concept/engine/README.md) - Abstraction layer that allows hiding the actual browser engine implementation.
* 🔵 [**Fetch**](components/concept/fetch/README.md) - An abstract definition of an HTTP client for fetching resources.
* 🔵 [**Push**](components/concept/push/README.md) - An abstract definition of a push service component.
* 🔵 [**Storage**](components/concept/storage/README.md) - Abstract definition of a browser storage component.
* 🔵 [**Tabstray**](components/concept/tabstray/README.md) - Abstract definition of a tabs tray component.
* 🔵 [**Toolbar**](components/concept/toolbar/README.md) - Abstract definition of a browser toolbar component.
## Feature
_Combined components to implement feature-specific use cases._
* 🔵 [**Accounts**](components/feature/accounts/README.md) - A component that connects an FxaAccountManager from [service-firefox-accounts](components/service/firefox-accounts/README.md) with [feature-tabs](components/feature/tabs/README.md) in order to facilitate authentication flows.
* 🔵 [**Accounts Push**](components/feature/accounts-push/README.md) - Feature of use cases for FxA Account that work with push support.
* 🔵 [**Autofill**](components/feature/autofill/README.md) - A component that provides support for Android's Autofill framework.
* 🔵 [**Awesomebar**](components/feature/awesomebar/README.md) - A component that connects a [concept-awesomebar](components/concept/awesomebar/README.md) implementation to a [concept-toolbar](components/concept/toolbar/README.md) implementation and provides implementations of various suggestion providers.
* 🔴 [**Containers**](components/feature/containers/README.md) - A component for working with contextual identities also known as containers.
* 🔵 [**Context Menu**](components/feature/contextmenu/README.md) - A component for displaying context menus when *long-pressing* web content.
* 🔵 [**Custom Tabs**](components/feature/customtabs/README.md) - A component for providing [Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs) functionality in browsers.
* 🔵 [**Downloads**](components/feature/downloads/README.md) - A component to perform downloads using the [Android downloads manager](https://developer.android.com/reference/android/app/DownloadManager).
* 🔵 [**Intent**](components/feature/intent/README.md) - A component that provides intent processing functionality by combining various other feature modules.
* ⚪ [**Progressive Web Apps (PWA)**](components/feature/pwa/README.md) - A component that provides functionality for supporting Progressive Web Apps (PWA).
* 🔵 [**Reader View**](components/feature/readerview/README.md) - A component that provides Reader View functionality.
* 🔵 [**QR**](components/feature/qr/README.md) - A component that provides functionality for scanning QR codes.
* 🔵 [**Search**](components/feature/search/README.md) - A component that connects an (concept) engine implementation with the browser search module.
* 🔵 [**Session**](components/feature/session/README.md) - A component that connects an (concept) engine implementation with the browser session and storage modules.
* 🔵 [**Share**](components/feature/share/README.md) - Feature implementation for saving and sorting recent apps used for sharing.
* 🔵 [**Sync**](components/feature/sync/README.md) -A component that provides synchronization orchestration for groups of (concept) SyncableStore objects.
* 🔵 [**Tabs**](components/feature/tabs/README.md) - A component that connects a tabs tray implementation with the session and toolbar modules.
* 🔵 [**Tab Collections**](components/feature/tab-collections/README.md) - Feature implementation for saving, restoring and organizing collections of tabs.
* 🔵 [**Toolbar**](components/feature/toolbar/README.md) - A component that connects a (concept) toolbar implementation with the browser session module.
* 🔵 [**Top Sites**](components/feature/top-sites/README.md) - Feature implementation for saving and removing top sites.
* 🔵 [**Prompts**](components/feature/prompts/README.md) - A component that will handle all the common prompt dialogs from web content.
* 🔵 [**Push**](components/feature/push/README.md) - A component that provides Autopush messages with help from a supported push service.
* 🔵 [**Find In Page**](components/feature/findinpage/README.md) - A component that provides an UI widget for [find in page functionality](https://support.mozilla.org/en-US/kb/search-contents-current-page-text-or-links).
* 🔵 [**Remote Tabs**](components/feature/remotetabs/README.md) - Feature that provides access to other device's tabs in the same account.
* 🔵 [**Site Permissions**](components/feature/sitepermissions/README.md) - A feature for showing site permission request prompts.
* 🔵 [**WebAuthn**](components/feature/webauthn/README.md) - A feature that provides WebAuthn functionality for supported engines.
* 🔵 [**Web Notifications**](components/feature/webnotifications/README.md) - A component for displaying web notifications.
* 🔵 [**WebCompat**](components/feature/webcompat/README.md) - A feature to enable website-hotfixing via the Web Compatibility System-Addon.
* 🔵 [**WebCompat Reporter**](components/feature/webcompat-reporter/README.md) - A feature that enables users to report site issues to Mozilla's Web Compatibility team for further diagnosis.
* 🔵 [**Web Add-ons**](components/feature/addons/README.md) - A feature that provides functionality for managing add-ons.
## UI
_Generic low-level UI components for building apps._
* 🔵 [**Autocomplete**](components/ui/autocomplete/README.md) - A set of components to provide autocomplete functionality.
* 🔵 [**Colors**](components/ui/colors/README.md) - The standard set of [Photon](https://design.firefox.com/photon/) colors.
* 🔵 [**Fonts**](components/ui/fonts/README.md) - The standard set of fonts used by Mozilla Android products.
* 🔵 [**Icons**](components/ui/icons/README.md) - A collection of often used browser icons.
* 🔵 [**Tabcounter**](components/ui/tabcounter/README.md) - A button that shows the current tab count and can animate state changes.
## Service
_Components and libraries to interact with backend services._
* 🔵 [**Firefox Accounts (FxA)**](components/service/firefox-accounts/README.md) - A library for integrating with Firefox Accounts.
* 🔵 [**Firefox Sync - Logins**](components/service/sync-logins/README.md) - A library for integrating with Firefox Sync - Logins.
* 🔵 [**Firefox Sync - Autofill**](components/service/sync-autofill/README.md) - A library for integrating with Firefox Sync - Autofill.
* 🔵 [**Glean**](components/service/glean/README.md) - A client-side telemetry SDK for collecting metrics and sending them to Mozilla's telemetry service (eventually replacing [service-telemetry](components/service/telemetry/README.md)).
* 🔵 [**Location**](components/service/location/README.md) - A library for accessing Mozilla's and other location services.
* 🔴 [**Nimbus**](components/service/nimbus/README.md) - A wrapper for the Nimbus SDK.
* 🔵 [**Pocket**](components/service/pocket/README.md) - A library for communicating with the Pocket API.
* 🔵 [**Contile**](components/service/contile/README.md) - A library for communicating with the Contile services API.
## Support
_Supporting components with generic helper code._
* 🔵 [**Android Test**](components/support/android-test/README.md) - A collection of helpers for testing components in instrumented (on device) tests (`src/androidTest`).
* 🔵 [**Base**](components/support/base/README.md) - Base component containing building blocks for components.
* 🔵 [**Ktx**](components/support/ktx/README.md) - A set of Kotlin extensions on top of the Android framework and Kotlin standard library.
* 🔵 [**Test**](components/support/test/README.md) - A collection of helpers for testing components in local unit tests (`src/test`).
* 🔵 [**Test Appservices**](components/support/test-appservices/README.md) - A component for synchronizing Application Services' unit testing dependencies used in Android Components.
* 🔵 [**Test LibState**](components/support/test-libstate/README.md) - A collection of helpers for testing functionality that relies on the lib-state component in local unit tests (`src/test`).
* 🔵 [**Utils**](components/support/utils/README.md) - Generic utility classes to be shared between projects.
* 🔵 [**Webextensions**](components/support/webextensions/README.md) - A component containing building blocks for features implemented as web extensions.
## Standalone libraries
* 🔵 [**Crash**](components/lib/crash/README.md) - A generic crash reporter component that can report crashes to multiple services.
* 🔵 [**Dataprotect**](components/lib/dataprotect/README.md) - A component using AndroidKeyStore to protect user data.
* 🔵 [**Fetch-HttpURLConnection**](components/lib/fetch-httpurlconnection/README.md) - A [concept-fetch](concept/fetch/README.md) implementation using [HttpURLConnection](https://developer.android.com/reference/java/net/HttpURLConnection.html).
* 🔵 [**Fetch-OkHttp**](components/lib/fetch-okhttp/README.md) - A [concept-fetch](concept/fetch/README.md) implementation using [OkHttp](https://github.com/square/okhttp).
* ⚪ [**JEXL**](components/lib/jexl/README.md) - Javascript Expression Language: Context-based expression parser and evaluator.
* 🔵 [**Public Suffix List**](components/lib/publicsuffixlist/README.md) - A library for reading and using the [public suffix list](https://publicsuffix.org/).
* 🔵 [**Push-Firebase**](components/lib/push-firebase/README.md) - A [concept-push](concept/push/README.md) implementation using [Firebase Cloud Messaging](https://firebase.google.com/products/cloud-messaging/).
* 🔵 [**State**](components/lib/state/README.md) - A library for maintaining application state.
## Tooling
* 🔵 [**Fetch-Tests**](components/tooling/fetch-tests/README.md) - A generic test suite for components that implement [concept-fetch](concept/fetch/README.md).
* 🔵 [**Lint**](components/tooling/lint/README.md) - Custom Lint rules for the components repository.
# Sample apps
_Sample apps using various components._
* [**Browser**](samples/browser) - A simple browser composed from browser components. This sample application is only a very basic browser. For a full-featured reference browser implementation see the **[reference-browser repository](https://github.com/mozilla-mobile/reference-browser)**.
* [**Crash**](samples/crash) - An app showing the integration of the `lib-crash` component.
* [**Firefox Accounts (FxA)**](samples/firefox-accounts) - A simple app demoing Firefox Accounts integration.
* [**Firefox Sync**](samples/sync) - A simple app demoing general Firefox Sync integration, with bookmarks and history.
* [**Firefox Sync - Logins**](samples/sync-logins) - A simple app demoing Firefox Sync (Logins) integration.
* [**DataProtect**](samples/dataprotect) - An app demoing how to use the [**Dataprotect**](components/lib/dataprotect/README.md) component to load and store encrypted data in `SharedPreferences`.
* [**Glean**](samples/glean) - An app demoing how to use the [**Glean**](components/service/glean/README.md) library to collect and send telemetry data.
* [**Toolbar**](samples/toolbar) - An app demoing multiple customized toolbars using the [**browser-toolbar**](components/browser/toolbar/README.md) component.
# Building #
## Command line ##
```
$ git clone https://github.com/mozilla-mobile/android-components.git
$ cd android-components
$ ./gradlew assemble
```
## Android Studio ##
If the environment variable `JAVA_HOME` is not defined, you will need to set it. If you would like to use the JDK installed by Android Studio, here's how to find it:
1. Open Android Studio.
2. Select "Configure".
3. Select "Default Project Structure". You should now see the Android JDK location.
4. Set the environment variable `JAVA_HOME` to the location. (How you set an environment variable depends on your OS.)
5. Restart Android Studio.
Once the environment variable is set, you can import the project into Android Studio with the default wizard options.
If your build fails, you may find you get more instructive error messages by attempting the build at the command line.
# Coding Standards #
## Style ##
We follow the style enforced by [ktlint](https://ktlint.github.io/) and [detekt](https://github.com/detekt/detekt). See [how to configure Android Studio appropriately](https://github.com/pinterest/ktlint#option-1-recommended).
To check your style, run:
```
./gradlew ktlint
./gradlew detekt
```
## Documentation ##
We use `README.md` files for each component.
If you fix a bug or change an API, you should update [docs/changelog.md](https://github.com/mozilla-mobile/android-components/blob/main/docs/changelog.md).
## Testing ##
You are expected to both add tests for code that you write and make sure that your changes do not
cause existing tests to fail. You may find these command lines helpful:
```
./gradlew test # Run all tests
./gradlew :support-ktx:testdebugunittest # Run unit tests for a specified module
```
See also [how to measure code coverage](https://mozac.org/contributing/code-coverage).
## Accessibility ##
If your code has user-facing changes, follow [Android accessibility best practices](https://github.com/mozilla-mobile/shared-docs/blob/main/android/accessibility_guide.md).
# License
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/

View file

@ -0,0 +1,19 @@
android {
lint {
warningsAsErrors true
abortOnError (project.name != "support-test")
// With our L10N process its totally possible to have missing or (temporarily) extra translations.
disable 'MissingTranslation',
'ExtraTranslation',
// We do not want to enforce this as a generic rule for all languages (see #6117, #6056, #6118)
'TypographyEllipsis',
// https://github.com/mozilla-mobile/android-components/issues/10641
'UnspecifiedImmutableFlag',
// https://github.com/mozilla-mobile/android-components/issues/10643
'UnusedResources',
// "We do not impose rules on locales"
// https://github.com/mozilla-mobile/android-components/pull/11069
'TypographyDashes'
}
}

View file

@ -0,0 +1,133 @@
#!/usr/bin/env python3
# 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/.
# Purpose: Publish android packages to local maven repo, but only if changed since last publish.
# Dependencies: None
# Usage: ./automation/publish_to_maven_local_if_modified.py
import argparse
import hashlib
import os
import subprocess
import sys
import time
from pathlib import Path
def fatal_err(msg):
print(f"\033[31mError: {msg}\033[0m")
exit(1)
def run_cmd_checked(*args, **kwargs):
"""Run a command, throwing an exception if it exits with non-zero status."""
kwargs["check"] = True
return subprocess.run(*args, **kwargs)
def find_project_root():
"""Find the absolute path of the project repository root."""
# As a convention, we expect this file in [project-root]/automation/.
automation_dir = Path(__file__).parent
# Therefore the automation dir's parent is the project root we're looking for.
return automation_dir.parent
LAST_CONTENTS_HASH_FILE = ".lastAutoPublishContentsHash"
GITIGNORED_FILES_THAT_AFFECT_THE_BUILD = ["local.properties"]
parser = argparse.ArgumentParser(
description="Publish android packages to local maven repo, but only if changed since last publish"
)
parser.parse_args()
root_dir = find_project_root()
if str(root_dir) != os.path.abspath(os.curdir):
fatal_err(
f"This only works if run from the repo root ({root_dir!r} != {os.path.abspath(os.curdir)!r})"
)
# Calculate a hash reflecting the current state of the repo.
contents_hash = hashlib.sha256()
contents_hash.update(
run_cmd_checked(["git", "rev-parse", "HEAD"], capture_output=True).stdout
)
contents_hash.update(b"\x00")
# Get a diff of all tracked (staged and unstaged) files.
changes = run_cmd_checked(["git", "diff", "HEAD", "."], capture_output=True).stdout
contents_hash.update(changes)
contents_hash.update(b"\x00")
# But unfortunately it can only tell us the names of untracked
# files, and it won't tell us anything about files that are in
# .gitignore but can still affect the build.
untracked_files = []
# Get a list of all untracked files sans standard exclusions.
# -o is for getting other (i.e. untracked) files
# --exclude-standard is to handle standard Git exclusions: .git/info/exclude, .gitignore in each directory,
# and the user's global exclusion file.
changes_others = run_cmd_checked(
["git", "ls-files", "-o", "--exclude-standard"], capture_output=True
).stdout
changes_lines = iter(ln.strip() for ln in changes_others.split(b"\n"))
try:
ln = next(changes_lines)
while ln:
untracked_files.append(ln)
ln = next(changes_lines)
except StopIteration:
pass
# Then, account for some excluded files that we care about.
untracked_files.extend(GITIGNORED_FILES_THAT_AFFECT_THE_BUILD)
# Finally, get hashes of everything.
# Skip files that don't exist, e.g. missing GITIGNORED_FILES_THAT_AFFECT_THE_BUILD. `hash-object` errors out if it gets
# a non-existent file, so we hope that disk won't change between this filter and the cmd run just below.
filtered_untracked = [nm for nm in untracked_files if os.path.isfile(nm)]
# Reading contents of the files is quite slow when there are lots of them, so delegate to `git hash-object`.
git_hash_object_cmd = ["git", "hash-object"]
git_hash_object_cmd.extend(filtered_untracked)
changes_untracked = run_cmd_checked(git_hash_object_cmd, capture_output=True).stdout
contents_hash.update(changes_untracked)
contents_hash.update(b"\x00")
contents_hash = contents_hash.hexdigest()
# If the contents hash has changed since last publish, re-publish.
last_contents_hash = ""
try:
with open(LAST_CONTENTS_HASH_FILE) as f:
last_contents_hash = f.read().strip()
except FileNotFoundError:
pass
if contents_hash == last_contents_hash:
print("Contents have not changed, no need to publish")
else:
print("Contents have changed, publishing")
if sys.platform.startswith("win"):
run_cmd_checked(
["gradlew.bat", "publishToMavenLocal", f"-Plocal={time.time_ns()}"],
shell=True,
)
else:
run_cmd_checked(
["./gradlew", "publishToMavenLocal", f"-Plocal={time.time_ns()}"]
)
with open(LAST_CONTENTS_HASH_FILE, "w") as f:
f.write(contents_hash)
f.write("\n")

View file

@ -0,0 +1,31 @@
# Google Cloud Documentation: https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run
# Flank Documentation: https://flank.github.io/flank/
gcloud:
results-bucket: android-components_test_artifacts
record-video: true
timeout: 30m
async: false
num-flaky-test-attempts: 2
app: /APP/PATH
test: /TEST/PATH
auto-google-login: false
use-orchestrator: true
environment-variables:
clearPackageData: true
directories-to-pull:
- /sdcard/screenshots
performance-metrics: true
device:
- model: Pixel2.arm
version: 28
locale: en_US
flank:
project: GOOGLE_PROJECT
max-test-shards: -1
num-test-runs: 1
output-style: compact
full-junit-result: true

View file

@ -0,0 +1,31 @@
# Google Cloud Documentation: https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run
# Flank Documentation: https://flank.github.io/flank/
gcloud:
results-bucket: android-components_test_artifacts
record-video: true
timeout: 30m
async: false
num-flaky-test-attempts: 1
app: /app/path
test: /test/path
auto-google-login: false
use-orchestrator: true
environment-variables:
clearPackageData: true
directories-to-pull:
- /sdcard/screenshots
performance-metrics: true
device:
- model: Pixel2
version: 28
flank:
project: GOOGLE_PROJECT
max-test-shards: -1
num-test-runs: 1
output-style: compact
full-junit-result: true
repeat-tests: 1

View file

@ -0,0 +1,82 @@
#!/usr/bin/python3
from __future__ import print_function
import argparse
import json
import sys
from pathlib import Path
import yaml
def parse_args(cmdln_args):
parser = argparse.ArgumentParser(description="Parse UI test logs an results")
parser.add_argument(
"--output-md",
type=argparse.FileType("w", encoding="utf-8"),
help="Output markdown file.",
required=True,
)
parser.add_argument(
"--log",
type=argparse.FileType("r", encoding="utf-8"),
help="Log output of flank.",
required=True,
)
parser.add_argument(
"--results", type=Path, help="Directory containing flank results", required=True
)
parser.add_argument(
"--exit-code", type=int, help="Exit code of flank.", required=True
)
parser.add_argument("--device-type", help="Type of device ", required=True)
return parser.parse_args(args=cmdln_args)
def extract_android_args(log):
return yaml.safe_load(log.split("AndroidArgs\n")[1].split("RunTests\n")[0])
def main():
args = parse_args(sys.argv[1:])
log = args.log.read()
matrix_ids = json.loads(args.results.joinpath("matrix_ids.json").read_text())
# with args.results.joinpath("flank.yml") as f:
# flank_config = yaml.safe_load(f)
android_args = extract_android_args(log)
print = args.output_md.write
print("# Devices\n")
print(yaml.safe_dump(android_args["gcloud"]["device"]))
print("# Results\n")
print("| matrix | result | logs | details \n")
print("| --- | --- | --- | --- |\n")
for matrix, matrix_result in matrix_ids.items():
print(
"| {matrixId} | {outcome} | [logs]({webLink}) | {axes[0][details]}\n".format(
**matrix_result
)
)
if matrix_result["outcome"] != "success":
# write failures to test log in format known to treeherder logviewer
sys.stdout.write(
f"TEST-UNEXPECTED-FAIL | {matrix_result['outcome']} | {matrix_result['webLink']} | {matrix_result['axes'][0]['details']}\n"
)
print("---\n")
print("# References & Documentation\n")
print(
"* [Automated UI Testing Documentation](https://github.com/mozilla-mobile/shared-docs/blob/main/android/ui-testing.md)\n"
)
print(
"* Mobile Test Engineering on [Confluence](https://mozilla-hub.atlassian.net/wiki/spaces/MTE/overview) | [Slack](https://mozilla.slack.com/archives/C02KDDS9QM9) | [Alerts](https://mozilla.slack.com/archives/C0134KJ4JHL)\n"
)
if __name__ == "__main__":
main()

View file

@ -0,0 +1,151 @@
#!/usr/bin/env bash
# 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/.
# This script does the following:
# 1. Retrieves glcoud service account token
# 2. Activates gcloud service account
# 3. Connects to google Firebase (using TestArmada's Flank tool)
# 4. Executes UI tests
# 5. Puts test artifacts into the test_artifacts folder
# NOTE:
# Flank supports sharding across multiple devices at a time, but gcloud API
# only supports 1 defined APK per test run.
# If a command fails then do not proceed and fail this script too.
set -e
#########################
# The command line help #
#########################
display_help() {
echo "Usage: $0 Component_Name Build_Variant [Number_Shards...]"
echo
echo "Examples:"
echo "To run component/browser tests on ARM device shard (1 test / shard)"
echo "$ execute-firebase-test.sh component arm"
echo
echo "To run component/feature tests on X86 device (on 3 shards)"
echo "$ execute-firebase-test.sh feature x86 3"
echo
echo "To run UI samples/sampleName tests"
echo "$ execute-firebase-test.sh sample-sampleName arm 1"
echo
}
# Basic parameter check
if [[ $# -lt 2 ]]; then
echo "Your command line contains $# arguments"
display_help
exit 1
fi
component="$1" # browser, concept, feature
device_type="$2" # arm | x86
if [[ ! -z "$3" ]]; then
num_shards=$3
fi
JAVA_BIN="/usr/bin/java"
PATH_TEST="./automation/taskcluster/androidTest"
FLANK_BIN="/builds/worker/test-tools/flank.jar"
FLANK_CONF_ARM="${PATH_TEST}/flank-arm.yml"
FLANK_CONF_X86="${PATH_TEST}/flank-x86.yml"
ARTIFACT_DIR="/builds/worker/artifacts"
RESULTS_DIR="${ARTIFACT_DIR}/results"
echo
echo "ACTIVATE SERVICE ACCT"
echo
# this is where the Google Testcloud project ID is set
gcloud config set project "$GOOGLE_PROJECT"
echo
gcloud auth activate-service-account --key-file "$GOOGLE_APPLICATION_CREDENTIALS"
echo
echo
# From now on disable exiting on error. If the tests fail we want to continue
# and try to download the artifacts. We will exit with the actual error code later.
set +e
if [[ "${device_type,,}" == "x86" ]]
then
flank_template="$FLANK_CONF_X86"
else
flank_template="$FLANK_CONF_ARM"
fi
# Remove samples- from the component for each APK path
samples=${component//samples-}
# If tests are for components, the path is different than for samples
if [[ "${component}" != samples-* ]]
then
# Case 1: tests for any component (but NOT samples, NOT real UI tests)
APK_APP="./samples/browser/build/outputs/apk/gecko/debug/samples-browser-gecko-debug.apk"
if [[ "${component}" == *"-"* ]]
then
regex='([a-z]*)-(.*)'
[[ "$component" =~ $regex ]]
APK_TEST="./components/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/build/outputs/apk/androidTest/debug/${component}-debug-androidTest.apk"
else
APK_TEST="./components/${component}/engine-gecko/build/outputs/apk/androidTest/debug/browser-engine-gecko-debug-androidTest.apk"
fi
elif [[ "${component}" == "samples-browser" ]]
then
# Case 2: tests for browser sample (gecko sample only)
APK_APP="./samples/${samples}/build/outputs/apk/gecko/debug/samples-${samples}-gecko-debug.apk"
APK_TEST="./samples/${samples}/build/outputs/apk/androidTest/gecko/debug/samples-{$samples}-gecko-debug-androidTest.apk"
else
# Case 3: tests for non-browser samples (i.e. samples-glean)
APK_APP="./samples/${samples}/build/outputs/apk/debug/samples-${samples}-debug.apk"
APK_TEST="./samples/${samples}/build/outputs/apk/androidTest/debug/samples-${samples}-debug-androidTest.apk"
fi
# function to exit script with exit code from test run.
# (Only 0 if all test executions passed)
function failure_check() {
echo
echo
if [[ $exitcode -ne 0 ]]; then
echo "ERROR: UI test run failed, please check above URL"
else
echo "All UI test(s) have passed!"
fi
echo
echo "RESULTS"
echo
mkdir -p ${ARTIFACT_DIR}/github
chmod +x ${PATH_TEST}/parse-ui-test.py
${PATH_TEST}/parse-ui-test.py \
--exit-code "${exitcode}" \
--log flank.log \
--results "${RESULTS_DIR}" \
--output-md "${ARTIFACT_DIR}/github/customCheckRunText.md" \
--device-type "${device_type}"
echo
echo
}
echo
echo "EXECUTE TEST(S)"
echo
set -o pipefail && $JAVA_BIN -jar $FLANK_BIN android run \
--config=$flank_template \
--max-test-shards=$num_shards \
--app=$APK_APP --test=$APK_TEST \
--local-result-dir="${RESULTS_DIR}" \
--project=$GOOGLE_PROJECT \
--client-details=commit=${MOBILE_HEAD_REV:-None},pullRequest=${PULL_REQUEST_NUMBER:-None} \
| tee flank.log
exitcode=$?
failure_check
exit $exitcode

View file

@ -0,0 +1,384 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import static org.gradle.api.tasks.testing.TestResult.ResultType
buildscript {
repositories {
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
maven {
url repository
if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
allowInsecureProtocol = true
}
}
}
}
dependencies {
classpath ComponentsDependencies.tools_androidgradle
classpath ComponentsDependencies.tools_kotlingradle
}
// Variables in plugins {} aren't directly supported. Hack around it by setting an
// intermediate variable which can pull from FenixDependencies.kt and be used later.
ext {
detekt_plugin = Versions.detekt
python_envs_plugin = Versions.python_envs_plugin
ksp_plugin = Versions.ksp_plugin
}
}
plugins {
id("io.gitlab.arturbosch.detekt").version("$detekt_plugin")
id("com.google.devtools.ksp").version("$ksp_plugin")
}
allprojects {
repositories {
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
maven {
url repository
if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
allowInsecureProtocol = true
}
}
}
maven {
url "${gradle.mozconfig.topobjdir}/gradle/maven"
}
}
}
subprojects {
apply plugin: 'jacoco'
// Enable Kotlin warnings as errors for all modules
tasks.withType(KotlinCompile).configureEach {
kotlinOptions.allWarningsAsErrors = true
}
project.configurations.configureEach {
// Dependencies can't depend on a different major version of Glean than A-C itself.
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'org.mozilla.telemetry'
&& details.requested.name.contains('glean') ) {
def requested = details.requested.version.tokenize(".")
def defined = Versions.mozilla_glean.tokenize(".")
// Check the major version
if (requested[0] != defined[0]) {
throw new AssertionError("Cannot resolve to a single Glean version. Requested: ${details.requested.version}, A-C uses: ${Versions.mozilla_glean}")
} else {
// Enforce that all (transitive) dependencies are using the defined Glean version
details.useVersion Versions.mozilla_glean
}
}
}
resolutionStrategy.capabilitiesResolution.withCapability("org.mozilla.telemetry:glean-native") {
def toBeSelected = candidates.find { it.id instanceof ModuleComponentIdentifier && it.id.module.contains('geckoview') }
if (toBeSelected != null) {
select(toBeSelected)
}
because 'use GeckoView Glean instead of standalone Glean'
}
}
// Allow local appservices substitution in each subproject.
def appServicesSrcDir = null
if (gradle.hasProperty('localProperties.autoPublish.application-services.dir')) {
appServicesSrcDir = gradle.getProperty('localProperties.autoPublish.application-services.dir')
} else if (gradle.hasProperty('localProperties.branchBuild.application-services.dir')) {
appServicesSrcDir = gradle.getProperty('localProperties.branchBuild.application-services.dir')
}
if (appServicesSrcDir) {
if (appServicesSrcDir.startsWith("/")) {
apply from: "${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
} else {
apply from: "${rootProject.projectDir}/${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
}
}
// Allow local Glean substitution in each subproject.
if (gradle.hasProperty('localProperties.autoPublish.glean.dir')) {
ext.gleanSrcDir = gradle."localProperties.autoPublish.glean.dir"
apply from: "${rootProject.projectDir}/${gleanSrcDir}/build-scripts/substitute-local-glean.gradle"
}
if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopsrcdir')) {
if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopobjdir')) {
ext.topobjdir = gradle."localProperties.dependencySubstitutions.geckoviewTopobjdir"
}
ext.topsrcdir = gradle."localProperties.dependencySubstitutions.geckoviewTopsrcdir"
apply from: "${topsrcdir}/substitute-local-geckoview.gradle"
}
afterEvaluate {
if (it.hasProperty('android')) {
jacoco {
toolVersion = Versions.jacoco
}
// Format test output
tasks.matching {it instanceof Test}.configureEach() {
systemProperty "robolectric.logging", "stdout"
systemProperty "logging.test-mode", "true"
systemProperty "javax.net.ssl.trustStoreType", "JKS"
testLogging.events = []
def out = services.get(StyledTextOutputFactory).create("an-ouput")
beforeSuite { descriptor ->
if (descriptor.getClassName() != null) {
out.style(Style.Header).println("\nSUITE: " + descriptor.getClassName())
}
}
beforeTest { descriptor ->
out.style(Style.Description).println(" TEST: " + descriptor.getName())
}
onOutput { descriptor, event ->
logger.lifecycle(" " + event.message.trim())
}
afterTest { descriptor, result ->
switch (result.getResultType()) {
case ResultType.SUCCESS:
out.style(Style.Success).println(" SUCCESS")
break
case ResultType.FAILURE:
def testId = descriptor.getClassName() + "." + descriptor.getName()
out.style(Style.Failure).println(" TEST-UNEXPECTED-FAIL | " + testId + " | " + result.getException())
break
case ResultType.SKIPPED:
out.style(Style.Info).println(" SKIPPED")
break
}
logger.lifecycle("")
}
}
dependencies {
lintChecks project(':tooling-lint')
}
kotlin {
jvmToolchain(config.jvmTargetCompatibility)
}
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
packagingOptions {
resources {
excludes += ['META-INF/atomicfu.kotlin_module', 'META-INF/AL2.0', 'META-INF/LGPL2.1']
// Required dependencies using byte-buddy; remove after this is
// fixed by: https://issuetracker.google.com/issues/170131605
excludes.add("META-INF/licenses/ASM")
pickFirsts += ['win32-x86-64/attach_hotspot_windows.dll', 'win32-x86/attach_hotspot_windows.dll']
}
}
androidResources {
ignoreAssetsPattern "manifest.template.json"
}
tasks.withType(KotlinCompile).configureEach {
kotlinOptions.freeCompilerArgs += ["-opt-in=kotlin.RequiresOptIn"]
}
}
if (project.hasProperty("coverage") && project.name != "support-test") {
android.buildTypes.all { buildType ->
tasks.withType(Test).configureEach() {
jacoco {
includeNoLocationClasses = true
excludes = ['jdk.internal.*']
}
finalizedBy { "jacoco${buildType.name.capitalize()}TestReport" }
}
tasks.register("jacoco${buildType.name.capitalize()}TestReport", JacocoReport) {
reports {
xml.required = true
html.required = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
'**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
def kotlinDebugTree = fileTree(dir: "$project.layout.buildDirectory/tmp/kotlin-classes/${buildType.name}", excludes: fileFilter)
def javaDebugTree = fileTree(dir: "$project.layout.buildDirectory/intermediates/classes/${buildType.name}", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([kotlinDebugTree, javaDebugTree]))
getExecutionData().setFrom(fileTree(project.layout.buildDirectory).include([
"jacoco/test${buildType.name.capitalize()}UnitTest.exec"
]))
}
}
android {
buildTypes {
debug {
testCoverageEnabled true
}
}
}
}
}
}
tasks.withType(KotlinCompile).configureEach {
// Translate Kotlin messages like "w: ..." and "e: ..." into
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
def listener = {
if (it.startsWith("e: warnings found")) {
return
}
if (it.startsWith('w: ') || it.startsWith('e: ')) {
def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
if (!matches) {
logger.quiet "kotlinc message format has changed!"
if (it.startsWith('w: ')) {
// For warnings, don't continue because we don't want to throw an
// exception. For errors, we want the exception so that the new error
// message format gets translated properly.
return
}
}
def (_, type, file, line, column, message) = matches[0]
type = (type == 'w') ? 'warning' : 'error'
// Use logger.lifecycle, which does not go through stderr again.
logger.lifecycle "$file:$line:$column: $type: $message"
}
} as StandardOutputListener
doFirst {
logging.addStandardErrorListener(listener)
}
doLast {
logging.removeStandardErrorListener(listener)
}
}
}
if (findProject(":geckoview") == null) {
// Avoid adding this task if it already exists in a different root project.
tasks.register("clean", Delete) {
delete rootProject.layout.buildDirectory
}
}
detekt {
input = files("$projectDir/components", "$projectDir/buildSrc", "$projectDir/samples")
config = files("$projectDir/config/detekt.yml")
baseline = file("$projectDir/config/detekt-baseline.xml")
reports {
html {
enabled = true
destination = file("$projectDir/build/reports/detekt.html")
}
xml {
enabled = false
}
txt {
enabled = false
}
}
}
tasks.withType(Detekt).configureEach() {
// Custom detekt rules should be build before
// See https://arturbosch.github.io/detekt/extensions.html#pitfalls
dependsOn(":tooling-detekt:assemble")
autoCorrect = true
exclude "**/build.gradle.kts"
exclude "**/src/androidTest/**"
exclude "**/src/iosTest/**"
exclude "**/src/test/**"
exclude "**/test/src/**"
exclude "**/build/**"
exclude "**/resources/**"
exclude "**/tmp/**"
exclude "**/tooling/fetch/tests/**"
exclude "**/tooling/fetch-tests/**"
exclude "**/src/main/assets/extensions/**"
exclude "**/docs/**"
}
// Apply same path exclusions as for the main task
tasks.withType(DetektCreateBaselineTask).configureEach() {
exclude "**/src/androidTest/**"
exclude "**/src/test/**"
exclude "**/test/src/**"
exclude "**/build/**"
exclude "**/resources/**"
exclude "**/tmp/**"
exclude "**/tooling/fetch/tests/**"
exclude "**/tooling/fetch-tests/**"
}
configurations {
ktlint
}
dependencies {
ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
}
detektPlugins project(":tooling-detekt")
}
tasks.register("ktlint", JavaExec) {
group = "verification"
description = "Check Kotlin code style."
classpath = configurations.ktlint
mainClass.set("com.pinterest.ktlint.Main")
args "components/**/*.kt" , "samples/**/*.kt", "!**/build/**/*.kt", "buildSrc/**/*.kt", "--baseline=ktlint-baseline.xml"
}
tasks.register("ktlintFormat", JavaExec) {
group = "formatting"
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
mainClass.set("com.pinterest.ktlint.Main")
args "-F", "components/**/*.kt" , "samples/**/*.kt", "!**/build/**/*.kt", "buildSrc/**/*.kt", "--baseline=ktlint-baseline.xml"
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
tasks.register("listRepositories") {
doLast {
println "Repositories:"
project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
}
}
tasks.register("testToolsDir", Exec) {
group = "verification"
description = "Run tests in the tools/ directory."
workingDir = "tools"
commandLine = ["python3", "test_list_compatible_dependency_versions.py"]
}

View file

@ -0,0 +1,67 @@
# [Android Components](../../../README.md) > Browser > Domains
This component provides APIs for managing localized and customizable domain lists (see [Domains](#domains) and [CustomDomains](#customdomains)). It also contains auto-complete functionality for these lists (see [DomainAutoCompleteProvider](#domainautocompleteprovider)) which can be used in conjuction with our [UI autocomplete component](../../ui/autocomplete/README.md).
## Usage
### Setting up the dependency
Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):
```Groovy
implementation "org.mozilla.components:browser-domains:{latest-version}"
```
### Domains
The `Domains` object is used to load the built-in localized domain lists which are shipped as part of this component. These lists are grouped by country and can be found [in our repository](src/main/assets/domains).
```Kotlin
// Load the domain lists for all countries in the default locale (fallback is US)
val domains = Domains.load(context)
```
### CustomDomains
The `CustomDomains` object can be used to manage a custom domain list which will be stored in `SharedPreferences`.
```Kotlin
// Load the custom domain list
val domains = CustomDomains.load(context)
// Save custom domains
CustomDomains.save(context, listOf("mozilla.org", "getpocket.com"))
// Remove custom domains
CustomDomains.remove(context, listOf("nolongerexists.org"))
```
### DomainAutoCompleteProvider
The class provides auto-complete functionality for both `Domains` and `CustomDomains`.
```Kotlin
// Initialize the provider
val provider = DomainAutocompleteProvider()
provider.initialize(
context,
useShippedDomains = true,
useCustomDomains = true,
loadDomainsFromDisk = true
)
```
Note that when `loadDomainsFromDisk` is set to true there is no need to manually call `load` on either `Domains` or `CustomDomains`.
```Kotlin
// Autocomplete domain lists
val result = provider.autocomplete("moz")
```
The result will contain the autocompleted text (`result.text`), the URL (`result.url`), and the source of the match (`result.source`), which is either `DEFAULT_LIST` if a result was found in the shipped domain list or `CUSTOM_LIST` otherwise. The custom domain list takes precendece over the built-in shipped domain list and the API will only return the first match.
## License
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/

View file

@ -0,0 +1,40 @@
/* 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/. */
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
defaultConfig {
minSdkVersion config.minSdkVersion
compileSdk config.compileSdkVersion
targetSdkVersion config.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
namespace 'mozilla.components.browser.domains'
}
dependencies {
implementation project(':concept-toolbar')
implementation ComponentsDependencies.kotlin_coroutines
testImplementation project(':support-test')
testImplementation ComponentsDependencies.androidx_test_junit
testImplementation ComponentsDependencies.testing_robolectric
testImplementation ComponentsDependencies.testing_coroutines
}
apply from: '../../../android-lint.gradle'
apply from: '../../../publish.gradle'
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description)

View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,4 @@
<!-- 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/. -->
<manifest />

View file

@ -0,0 +1,50 @@
google.com.br
youtube.com
google.com
facebook.com
globo.com
uol.com.br
blastingnews.com
live.com
mercadolivre.com.br
yahoo.com
blogspot.com.br
wikipedia.org
whatsapp.com
netflix.com
olx.com.br
instagram.com
msn.com
metropoles.com
fatosdesconhecidos.com.br
twitter.com
caixa.gov.br
uptodown.com
aliexpress.com
curapelanatureza.com.br
wordpress.com
abril.com.br
americanas.com.br
correios.com.br
reclameaqui.com.br
bet365.com
onclkds.com
bol.uol.com.br
techtudo.com.br
fazenda.gov.br
microsoft.com
folha.uol.com.br
linkedin.com
tumblr.com
sp.gov.br
reddit.com
bb.com.br
pinterest.com
itau.com.br
letras.mus.br
otvfoco.com.br
vagalume.com.br
portalinteressante.com
myappolicious.com.br
thewhizmarketing.com
twitch.tv

View file

@ -0,0 +1,49 @@
google.com
youtube.com
facebook.com
reddit.com
amazon.com
wikipedia.org
yahoo.com
twitter.com
netflix.com
ebay.com
imgur.com
linkedin.com
instagram.com
diply.com
craigslist.org
live.com
office.com
twitch.tv
tumblr.com
pinterest.com
espn.com
cnn.com
bing.com
wikia.com
chase.com
imdb.com
nytimes.com
paypal.com
blogspot.com
apple.com
yelp.com
stackoverflow.com
bankofamerica.com
wordpress.com
github.com
microsoft.com
wellsfargo.com
zillow.com
salesforce.com
msn.com
walmart.com
weather.com
dropbox.com
buzzfeed.com
intuit.com
washingtonpost.com
soundcloud.com
huffingtonpost.com
indeed.com

View file

@ -0,0 +1,50 @@
google.de
youtube.com
google.com
facebook.com
amazon.de
ebay.de
wikipedia.org
ebay-kleinanzeigen.de
web.de
yahoo.com
ok.ru
gmx.net
reddit.com
vk.com
t-online.de
twitter.com
spiegel.de
mail.ru
instagram.com
live.com
chip.de
bild.de
paypal.com
bing.com
twitch.tv
whatsapp.com
yandex.ru
gutefrage.net
mobile.de
google.ru
blogspot.de
tumblr.com
bs.to
focus.de
linkedin.com
netflix.com
wordpress.com
imgur.com
postbank.de
welt.de
streamcloud.eu
microsoft.com
immobilienscout24.de
msn.com
dict.cc
otto.de
xing.com
amazon.com
heise.de
github.com

View file

@ -0,0 +1,50 @@
google.fr
youtube.com
google.com
facebook.com
wikipedia.org
amazon.fr
leboncoin.fr
yahoo.com
live.com
twitter.com
orange.fr
free.fr
linkedin.com
lemonde.fr
instagram.com
reddit.com
lefigaro.fr
ebay.fr
cdiscount.com
jeuxvideo.com
zone-telechargement.ws
labanquepostale.fr
blogspot.fr
allocine.fr
msn.com
commentcamarche.net
pole-emploi.fr
vk.com
sfr.fr
lequipe.fr
twitch.tv
francetvinfo.fr
20minutes.fr
pinterest.com
netflix.com
programme-tv.net
credit-agricole.fr
linternaute.com
github.com
wordpress.com
caf.fr
aliexpress.com
dailymotion.com
tumblr.com
t411.ai
stackoverflow.com
microsoft.com
meteofrance.com
onclkds.com
bfmtv.com

View file

@ -0,0 +1,49 @@
google.co.uk
youtube.com
google.com
facebook.com
reddit.com
bbc.co.uk
amazon.co.uk
wikipedia.org
ebay.co.uk
twitter.com
live.com
yahoo.com
instagram.com
diply.com
linkedin.com
imgur.com
netflix.com
theguardian.com
dailymail.co.uk
twitch.tv
imdb.com
paypal.com
office.com
tumblr.com
www.gov.uk
wikia.com
givemesport.com
amazon.com
bing.com
wordpress.com
telegraph.co.uk
rightmove.co.uk
pinterest.com
gumtree.com
msn.com
microsoft.com
stackoverflow.com
booking.com
vk.com
tripadvisor.co.uk
lloydsbank.co.uk
apple.com
service.gov.uk
onclkds.com
github.com
independent.co.uk
bt.com
vice.com
hsbc.co.uk

View file

@ -0,0 +1,444 @@
google.com
facebook.com
amazon.com
youtube.com
yahoo.com
ebay.com
wikipedia.org
twitter.com
reddit.com
go.com
craigslist.org
live.com
netflix.com
pinterest.com
bing.com
linkedin.com
imgur.com
espn.go.com
walmart.com
tumblr.com
target.com
paypal.com
cnn.com
chase.com
instagram.com
bestbuy.com
blogspot.com
nytimes.com
msn.com
imdb.com
apple.com
bankofamerica.com
diply.com
huffingtonpost.com
yelp.com
wellsfargo.com
etsy.com
weather.com
wordpress.com
buzzfeed.com
zillow.com
kohls.com
aol.com
homedepot.com
foxnews.com
microsoft.com
comcast.net
wikia.com
groupon.com
macys.com
washingtonpost.com
outbrain.com
xfinity.com
usps.com
hulu.com
americanexpress.com
slickdeals.net
pandora.com
office.com
cnet.com
indeed.com
capitalone.com
nfl.com
ups.com
ask.com
verizonwireless.com
newegg.com
usatoday.com
forbes.com
dailymail.co.uk
dropbox.com
att.com
costco.com
gfycat.com
lowes.com
gap.com
about.com
tripadvisor.com
fedex.com
baidu.com
vice.com
nordstrom.com
adobe.com
bbc.com
twitch.tv
allrecipes.com
retailmenot.com
stackoverflow.com
citi.com
sears.com
jcpenney.com
webmd.com
nih.gov
answers.com
foodnetwork.com
discovercard.com
cbssports.com
overstock.com
businessinsider.com
office365.com
theguardian.com
staples.com
bleacherreport.com
verizon.com
github.com
wayfair.com
salesforce.com
zulily.com
wsj.com
flickr.com
goodreads.com
realtor.com
nbcnews.com
ebates.com
ancestry.com
wunderground.com
instructure.com
people.com
stackexchange.com
drudgereport.com
fidelity.com
southwest.com
deviantart.com
thesaurus.com
intuit.com
woot.com
pch.com
soundcloud.com
force.com
samsclub.com
ign.com
qvc.com
npr.org
patch.com
dell.com
accuweather.com
vimeo.com
expedia.com
trulia.com
ca.gov
swagbucks.com
spotify.com
bedbathandbeyond.com
nypost.com
aliexpress.com
blackboard.com
ticketmaster.com
ikea.com
feedly.com
usaa.com
tmz.com
quora.com
lifehacker.com
kayak.com
reference.com
zappos.com
gizmodo.com
slate.com
faithtap.com
adp.com
abcnews.go.com
sephora.com
cbs.com
latimes.com
shutterfly.com
t-mobile.com
littlethings.com
glassdoor.com
bloomberg.com
cbsnews.com
wikihow.com
walgreens.com
usbank.com
blogger.com
weebly.com
gamestop.com
food.com
time.com
kickstarter.com
okcupid.com
aa.com
weather.gov
nametests.com
fandango.com
engadget.com
steamcommunity.com
thekitchn.com
nba.com
mashable.com
hp.com
gamefaqs.com
delta.com
coupons.com
eonline.com
surveymonkey.com
kmart.com
barnesandnoble.com
meetup.com
bhphotovideo.com
fanduel.com
quizlet.com
nydailynews.com
sbnation.com
nbcsports.com
bbc.co.uk
ew.com
nike.com
rottentomatoes.com
steampowered.com
reuters.com
qq.com
today.com
mapquest.com
audible.com
priceline.com
whitepages.com
united.com
myfitnesspal.com
icloud.com
forever21.com
theatlantic.com
microsoftstore.com
theverge.com
gawker.com
houzz.com
mayoclinic.org
rei.com
sfgate.com
lifebuzz.com
discover.com
pnc.com
pof.com
iflscience.com
popsugar.com
creditkarma.com
telegraph.co.uk
airbnb.com
buzzlie.com
cnbc.com
deadspin.com
sina.com.cn
legacy.com
thedailybeast.com
samsung.com
nextdoor.com
evite.com
shopify.com
yellowpages.com
pcmag.com
redfin.com
weibo.com
alibaba.com
cabelas.com
battle.net
foxsports.com
taobao.com
eventbrite.com
victoriassecret.com
theblaze.com
dealnews.com
cbslocal.com
cvs.com
dailymotion.com
ecollege.com
gofundme.com
fitbit.com
instructables.com
godaddy.com
babycenter.com
squarespace.com
llbean.com
dickssportinggoods.com
6pm.com
myway.com
hsn.com
wired.com
officedepot.com
ozztube.com
usmagazine.com
match.com
cracked.com
evernote.com
box.com
starbucks.com
kbb.com
mlb.com
marriott.com
si.com
jezebel.com
pbs.org
consumerreports.org
roblox.com
urbandictionary.com
kotaku.com
xbox.com
marketwatch.com
refinery29.com
wikimedia.org
tvguide.com
politico.com
barclaycardus.com
abc.go.com
mint.com
topix.com
theblackfriday.com
aarp.org
hotnewhiphop.com
yourdailydish.com
sprint.com
vox.com
cafemom.com
nbc.com
dailykos.com
azlyrics.com
autotrader.com
hilton.com
irs.gov
monster.com
mailchimp.com
webex.com
landsend.com
wix.com
usnews.com
jcrew.com
jet.com
capitalone360.com
sharepoint.com
schwab.com
ulta.com
vistaprint.com
rollingstone.com
biblegateway.com
gamespot.com
io9.com
opentable.com
hm.com
duckduckgo.com
chron.com
photobucket.com
shareasale.com
directv.com
avg.com
oracle.com
hotels.com
timewarnercable.com
chicagotribune.com
ehow.com
primewire.ag
abs-cbnnews.com
salon.com
greatergood.com
epicurious.com
fool.com
patheos.com
custhelp.com
purdue.edu
tickld.com
frys.com
indiatimes.com
amazon.co.uk
zendesk.com
tigerdirect.com
stubhub.com
healthcare.gov
archive.org
qualtrics.com
ravelry.com
cars.com
redbox.com
jalopnik.com
speedtest.net
harvard.edu
slideshare.net
kinja.com
nesn.com
michaels.com
mit.edu
bodybuilding.com
edmunds.com
nhl.com
zergnet.com
techcrunch.com
pogo.com
mozilla.org
naver.com
giphy.com
bankrate.com
msnbc.com
digitaltrends.com
fanfiction.net
skype.com
disney.go.com
norton.com
androidcentral.com
tomshardware.com
thefreedictionary.com
liveleak.com
247sports.com
merriam-webster.com
wnd.com
earthlink.net
independent.co.uk
drugs.com
rotoworld.com
nationalgeographic.com
ae.com
noaa.gov
arstechnica.com
thinkgeek.com
stanford.edu
bizjournals.com
hootsuite.com
genius.com
goodhousekeeping.com
vanguard.com
ny.gov
citibankonline.com
booking.com
mic.com
orbitz.com
dominos.com
medium.com
wow.com
urbanoutfitters.com
douban.com
timeanddate.com
draftkings.com
livestrong.com
livingsocial.com
cox.net
theonion.com
marthastewart.com
comenity.net
worldlifestyle.com
disney.com
realsimple.com
vrbo.com
playstation.com
potterybarn.com
zazzle.com
ksl.com
tdbank.com
sourceforge.net
careerbuilder.com

View file

@ -0,0 +1,50 @@
google.com.hk
youtube.com
google.com
facebook.com
yahoo.com
discuss.com.hk
aastocks.com
wikipedia.org
baidu.com
taobao.com
pixnet.net
bastillepost.com
nextmedia.com
whatsapp.com
instagram.com
price.com.hk
ettoday.net
qq.com
hsbc.com.hk
tmall.com
live.com
hkgolden.com
reddit.com
beautyexchange.com.hk
etnet.com.hk
on.cc
amazon.com
twitter.com
uwants.com
presslogic.com
unwire.hk
gamer.com.tw
hangseng.com
hk01.com
twitch.tv
linkedin.com
teepr.com
hkjc.com
apple.com
bomb01.com
sina.com.cn
weibo.com
dcfever.com
thestandnews.com
office.com
openrice.com
tumblr.com
tvb.com
alipay.com
stackoverflow.com

View file

@ -0,0 +1,50 @@
google.com
google.co.id
youtube.com
detik.com
tribunnews.com
facebook.com
yahoo.com
tokopedia.com
liputan6.com
kompas.com
bukalapak.com
kaskus.co.id
kapanlagi.com
wordpress.com
merdeka.com
okezone.com
elevenia.co.id
lazada.co.id
uzone.id
bintang.com
brilio.net
popads.net
instagram.com
bola.net
wikipedia.org
blogspot.com
onclkds.com
dream.co.id
viva.co.id
alodokter.com
tempo.co
suara.com
wowkeren.com
idntimes.com
bola.com
sindonews.com
republika.co.id
kompasiana.com
vemale.com
blanja.com
cnnindonesia.com
olx.co.id
lk21.org
popcash.net
blibli.com
poptm.com
nonton.movie
indexmovie.me
adexchangeprediction.com
subscene.com

View file

@ -0,0 +1,50 @@
google.pl
youtube.com
facebook.com
google.com
allegro.pl
onet.pl
wp.pl
wikipedia.org
olx.pl
vk.com
interia.pl
wykop.pl
gazeta.pl
filmweb.pl
instagram.com
wiocha.pl
cda.pl
aliexpress.com
otomoto.pl
mbank.pl
reddit.com
ceneo.pl
tvn24.pl
twitter.com
gumtree.pl
blogspot.com
kwejk.pl
wyborcza.pl
joemonster.org
stackoverflow.com
twitch.tv
o2.pl
ipko.pl
steamcommunity.com
github.com
chomikuj.pl
centrum24.pl
linkedin.com
money.pl
librus.pl
demotywatory.pl
sport.pl
microsoft.com
zalukaj.com
wikia.com
jbzdy.pl
imgur.com
flashscore.pl
gry-online.pl
pudelek.pl

View file

@ -0,0 +1,50 @@
vk.com
google.ru
yandex.ru
youtube.com
mail.ru
ok.ru
google.com
avito.ru
aliexpress.com
wikipedia.org
instagram.com
sberbank.ru
gismeteo.ru
rambler.ru
kinogo.club
kinopoisk.ru
drom.ru
facebook.com
pikabu.ru
drive2.ru
rutracker.org
twitch.tv
rbc.ru
hh.ru
gosuslugi.ru
lenta.ru
pochta.ru
wildberries.ru
wikia.com
4pda.ru
fb.ru
seasonvar.ru
kp.ru
znanija.com
ucoz.ru
narod.ru
mts.ru
infourok.ru
ebay.com
ozon.ru
worldoftanks.ru
mos.ru
vesti.ru
nnmclub.to
microsoft.com
rp5.ru
2gis.ru
consultant.ru
fotostrana.ru
dnevnik.ru

View file

@ -0,0 +1,49 @@
google.com.sg
youtube.com
google.com
facebook.com
yahoo.com
wikipedia.org
reddit.com
blogspot.sg
live.com
instagram.com
qoo10.sg
whatsapp.com
linkedin.com
dbs.com.sg
amazon.com
twitter.com
wordpress.com
onclkds.com
office.com
allsingaporestuff.com
baidu.com
lazada.sg
straitstimes.com
singpass.gov.sg
google.co.id
taobao.com
tumblr.com
gomovies.to
wikia.com
hardwarezone.com.sg
nus.edu.sg
msn.com
microsoft.com
carousell.com
kissanime.ru
ocbc.com
stackoverflow.com
ntu.edu.sg
thepiratebay.org
aliexpress.com
imgur.com
dropbox.com
apple.com
channelnewsasia.com
imdb.com
twitch.tv
abs-cbn.com
jobstreet.com.sg
uob.com.sg

View file

@ -0,0 +1,50 @@
google.com.tw
pixnet.net
youtube.com
facebook.com
ettoday.net
google.com
yahoo.com
ltn.com.tw
nownews.com
setn.com
momoshop.com.tw
wikipedia.org
ck101.com
ptt.cc
tvbs.com.tw
104.com.tw
gamer.com.tw
appledaily.com.tw
pchome.com.tw
ruten.com.tw
ctitv.com.tw
teepr.com
life.tw
blogspot.tw
dcard.tw
baidu.com
udn.com
mobile01.com
eyny.com
epochtimes.com
qoolquiz.com
bomb01.com
talk.tw
ipetgroup.com
storm.mg
123kubo.com
cmoney.tw
taobao.com
twitch.tv
instagram.com
xuite.net
sina.com.tw
1111.com.tw
businessweekly.com.tw
elle.com.tw
twitter.com
books.com.tw
591.com.tw
everydayhealth.com.tw
techbang.com

View file

@ -0,0 +1,49 @@
google.com
youtube.com
facebook.com
reddit.com
amazon.com
wikipedia.org
yahoo.com
twitter.com
netflix.com
ebay.com
imgur.com
linkedin.com
instagram.com
diply.com
craigslist.org
live.com
office.com
twitch.tv
tumblr.com
pinterest.com
espn.com
cnn.com
bing.com
wikia.com
chase.com
imdb.com
nytimes.com
paypal.com
blogspot.com
apple.com
yelp.com
stackoverflow.com
bankofamerica.com
wordpress.com
github.com
microsoft.com
wellsfargo.com
zillow.com
salesforce.com
msn.com
walmart.com
weather.com
dropbox.com
buzzfeed.com
intuit.com
washingtonpost.com
soundcloud.com
huffingtonpost.com
indeed.com

View file

@ -0,0 +1,68 @@
/* 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/. */
package mozilla.components.browser.domains
import android.content.Context
import android.content.SharedPreferences
/**
* Contains functionality to manage custom domains for auto-completion.
*/
object CustomDomains {
private const val PREFERENCE_NAME = "custom_autocomplete"
private const val KEY_DOMAINS = "custom_domains"
private const val SEPARATOR = "@<;>@"
/**
* Loads the previously added/saved custom domains from preferences.
*
* @param context the application context
* @return list of custom domains
*/
fun load(context: Context): List<String> =
preferences(context).getString(KEY_DOMAINS, "")!!
.split(SEPARATOR)
.filter { !it.isEmpty() }
/**
* Saves the provided domains to preferences.
*
* @param context the application context
* @param domains list of domains
*/
fun save(context: Context, domains: List<String>) {
preferences(context)
.edit()
.putString(KEY_DOMAINS, domains.joinToString(separator = SEPARATOR))
.apply()
}
/**
* Adds the provided domain to preferences.
*
* @param context the application context
* @param domain the domain to add
*/
fun add(context: Context, domain: String) {
val domains = mutableListOf<String>()
domains.addAll(load(context))
domains.add(domain)
save(context, domains)
}
/**
* Removes the provided domain from preferences.
*
* @param context the application context
* @param domains the domain to remove
*/
fun remove(context: Context, domains: List<String>) {
save(context, load(context) - domains)
}
private fun preferences(context: Context): SharedPreferences =
context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
}

View file

@ -0,0 +1,39 @@
/* 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/. */
package mozilla.components.browser.domains
/**
* Class intended for internal use which encapsulates meta data about a domain.
*/
data class Domain(val protocol: String, val hasWww: Boolean, val host: String) {
internal val url: String
get() = "$protocol${if (hasWww) "www." else "" }$host"
companion object {
private const val PROTOCOL_INDEX = 1
private const val WWW_INDEX = 2
private const val HOST_INDEX = 3
private const val DEFAULT_PROTOCOL = "http://"
private val urlMatcher = Regex("""(https?://)?(www.)?(.+)?""")
fun create(url: String): Domain {
val result = urlMatcher.find(url)
return result?.let {
val protocol = it.groups[PROTOCOL_INDEX]?.value ?: DEFAULT_PROTOCOL
val hasWww = it.groups[WWW_INDEX]?.value == "www."
val host = it.groups[HOST_INDEX]?.value ?: throw IllegalStateException()
return Domain(protocol, hasWww, host)
} ?: throw IllegalStateException()
}
}
}
internal fun Iterable<String>.into(): List<Domain> {
return this.map { Domain.create(it) }
}

View file

@ -0,0 +1,151 @@
/* 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/. */
package mozilla.components.browser.domains
import android.content.Context
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import java.util.Locale
/**
* Provides autocomplete functionality for domains, based on a provided list
* of assets (see [Domains]) and/or a custom domain list managed by
* [CustomDomains].
*/
// FIXME delete this https://github.com/mozilla-mobile/android-components/issues/1358
@Deprecated(
"Use `ShippedDomainsProvider` or `CustomDomainsProvider`",
ReplaceWith(
"ShippedDomainsProvider()/CustomDomainsProvider()",
"mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider",
"mozilla.components.browser.domains.autocomplete.CustomDomainsProvider",
),
)
class DomainAutoCompleteProvider {
object AutocompleteSource {
const val DEFAULT_LIST = "default"
const val CUSTOM_LIST = "custom"
}
/**
* Represents a result of auto-completion.
*
* @property text the result text starting with the raw search text as passed
* to [autocomplete] followed by the completion text (e.g. moz => mozilla.org)
* @property url the complete url (containing the protocol) as provided
* when the domain was saved. (e.g. https://mozilla.org)
* @property source the source identifier of the autocomplete source
* @property size total number of available autocomplete domains
* in this source
*/
data class Result(val text: String, val url: String, val source: String, val size: Int)
// We compute these on worker threads; make sure results are immediately visible on the UI thread.
@Volatile
internal var customDomains = emptyList<Domain>()
@Volatile
internal var shippedDomains = emptyList<Domain>()
private var useCustomDomains = false
private var useShippedDomains = true
/**
* Computes an autocomplete suggestion for the given text, and invokes the
* provided callback, passing the result.
*
* @param rawText text to be auto completed
* @return the result of auto-completion. If no match is found an empty
* result object is returned.
*/
@Suppress("ReturnCount")
fun autocomplete(rawText: String): Result {
if (useCustomDomains) {
val result = tryToAutocomplete(rawText, customDomains, AutocompleteSource.CUSTOM_LIST)
if (result != null) {
return result
}
}
if (useShippedDomains) {
val result = tryToAutocomplete(rawText, shippedDomains, AutocompleteSource.DEFAULT_LIST)
if (result != null) {
return result
}
}
return Result("", "", "", 0)
}
/**
* Initializes this provider instance by making sure the shipped and/or custom
* domains are loaded.
*
* @param context the application context
* @param useShippedDomains true (default) if the domains provided by this
* module should be used, otherwise false.
* @param useCustomDomains true if the custom domains provided by
* [CustomDomains] should be used, otherwise false (default).
* @param loadDomainsFromDisk true (default) if domains should be loaded,
* otherwise false. This parameter is for testing purposes only.
*/
fun initialize(
context: Context,
useShippedDomains: Boolean = true,
useCustomDomains: Boolean = false,
loadDomainsFromDisk: Boolean = true,
) {
this.useCustomDomains = useCustomDomains
this.useShippedDomains = useShippedDomains
if (!loadDomainsFromDisk) {
return
}
if (!useCustomDomains && !useShippedDomains) {
return
}
CoroutineScope(Dispatchers.IO).launch {
if (useCustomDomains) {
customDomains = async { CustomDomains.load(context).into() }.await()
}
if (useShippedDomains) {
shippedDomains = async { Domains.load(context).into() }.await()
}
}
}
@Suppress("ReturnCount")
private fun tryToAutocomplete(rawText: String, domains: List<Domain>, source: String): Result? {
// Search terms are all lowercase already, we just need to lowercase the search text
val searchText = rawText.lowercase(Locale.US)
domains.forEach {
val wwwDomain = "www.${it.host}"
if (wwwDomain.startsWith(searchText)) {
return Result(getResultText(rawText, wwwDomain), it.url, source, domains.size)
}
if (it.host.startsWith(searchText)) {
return Result(getResultText(rawText, it.host), it.url, source, domains.size)
}
}
return null
}
/**
* Our autocomplete list is all lower case, however the search text might
* be mixed case. Our autocomplete EditText code does more string comparison,
* which fails if the suggestion doesn't exactly match searchText (ie.
* if casing differs). It's simplest to just build a suggestion
* that exactly matches the search text - which is what this method is for:
*/
private fun getResultText(rawSearchText: String, autocomplete: String) =
rawSearchText + autocomplete.substring(rawSearchText.length)
}

View file

@ -0,0 +1,84 @@
/* 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/. */
package mozilla.components.browser.domains
import android.content.Context
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES
import android.os.LocaleList
import android.text.TextUtils
import java.io.IOException
import java.util.Locale
/**
* Contains functionality to access domain lists shipped as part of this
* module's assets.
*/
object Domains {
/**
* Loads the domains applicable to the app's locale, plus the domains
* in the 'global' list.
*
* @param context the application context
* @return list of domains
*/
fun load(context: Context): List<String> {
return load(context, getCountriesInDefaultLocaleList())
}
internal fun load(context: Context, countries: Set<String>): List<String> {
val domains = LinkedHashSet<String>()
val availableLists = getAvailableDomainLists(context)
// First initialize the country specific lists following the default locale order
countries
.filter { availableLists.contains(it) }
.forEach { loadDomainsForLanguage(context, domains, it) }
// And then add domains from the global list
loadDomainsForLanguage(context, domains, "global")
return domains.toList()
}
private fun getAvailableDomainLists(context: Context): Set<String> {
val availableDomains = LinkedHashSet<String>()
val assetManager = context.assets
val domains = try {
assetManager.list("domains") ?: emptyArray<String>()
} catch (e: IOException) {
emptyArray<String>()
}
availableDomains.addAll(domains)
return availableDomains
}
private fun loadDomainsForLanguage(context: Context, domains: MutableSet<String>, country: String) {
val assetManager = context.assets
val languageDomains = try {
assetManager.open("domains/$country").bufferedReader().readLines()
} catch (e: IOException) {
emptyList<String>()
}
domains.addAll(languageDomains)
}
private fun getCountriesInDefaultLocaleList(): Set<String> {
val countries = java.util.LinkedHashSet<String>()
val addIfNotEmpty = { c: String -> if (!TextUtils.isEmpty(c)) countries.add(c.lowercase(Locale.US)) }
if (SDK_INT >= VERSION_CODES.N) {
val list = LocaleList.getDefault()
for (i in 0 until list.size()) {
addIfNotEmpty(list.get(i).country)
}
} else {
addIfNotEmpty(Locale.getDefault().country)
}
return countries
}
}

View file

@ -0,0 +1,110 @@
/* 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/. */
package mozilla.components.browser.domains.autocomplete
import android.content.Context
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import mozilla.components.browser.domains.CustomDomains
import mozilla.components.browser.domains.Domain
import mozilla.components.browser.domains.Domains
import mozilla.components.browser.domains.into
import mozilla.components.concept.toolbar.AutocompleteProvider
import mozilla.components.concept.toolbar.AutocompleteResult
import java.util.Locale
enum class DomainList(val listName: String) {
DEFAULT("default"),
CUSTOM("custom"),
}
/**
* Provides autocomplete functionality for domains based on provided list of assets (see [Domains]).
*/
class ShippedDomainsProvider(override val autocompletePriority: Int = 0) :
BaseDomainAutocompleteProvider(DomainList.DEFAULT, Domains.asLoader())
/**
* Provides autocomplete functionality for domains based on a list managed by [CustomDomains].
*/
class CustomDomainsProvider(override val autocompletePriority: Int = 0) :
BaseDomainAutocompleteProvider(DomainList.CUSTOM, CustomDomains.asLoader())
typealias DomainsLoader = (Context) -> List<Domain>
private fun Domains.asLoader(): DomainsLoader = { context: Context -> load(context).into() }
private fun CustomDomains.asLoader(): DomainsLoader = { context: Context -> load(context).into() }
/**
* Provides common autocomplete functionality powered by domain lists.
*
* @param list source of domains
* @param domainsLoader provider for all available domains
*/
open class BaseDomainAutocompleteProvider(
private val list: DomainList,
private val domainsLoader: DomainsLoader,
override val autocompletePriority: Int = 0,
) : AutocompleteProvider, CoroutineScope by CoroutineScope(Dispatchers.IO) {
// We compute 'domains' on the worker thread; make sure it's immediately visible on the UI thread.
@Volatile
var domains: List<Domain> = emptyList()
fun initialize(context: Context) {
launch {
domains = async { domainsLoader(context) }.await()
}
}
/**
* Computes an autocomplete suggestion for the given text, and invokes the
* provided callback, passing the result.
*
* @param query text to be auto completed
* @return the result of auto-completion, or null if no match is found.
*/
override suspend fun getAutocompleteSuggestion(query: String): AutocompleteResult? {
// Search terms are all lowercase already, we just need to lowercase the search text
val searchText = query.lowercase(Locale.US)
domains.forEach {
val wwwDomain = "www.${it.host}"
if (wwwDomain.startsWith(searchText)) {
return AutocompleteResult(
input = searchText,
text = getResultText(query, wwwDomain),
url = it.url,
source = list.listName,
totalItems = domains.size,
)
}
if (it.host.startsWith(searchText)) {
return AutocompleteResult(
input = searchText,
text = getResultText(query, it.host),
url = it.url,
source = list.listName,
totalItems = domains.size,
)
}
}
return null
}
/**
* Our autocomplete list is all lower case, however the search text might
* be mixed case. Our autocomplete EditText code does more string comparison,
* which fails if the suggestion doesn't exactly match searchText (ie.
* if casing differs). It's simplest to just build a suggestion
* that exactly matches the search text - which is what this method is for:
*/
private fun getResultText(rawSearchText: String, autocomplete: String) =
rawSearchText + autocomplete.substring(rawSearchText.length)
}

View file

@ -0,0 +1,140 @@
/* 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/. */
package mozilla.components.browser.domains
import android.content.Context
import android.os.Looper.getMainLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import mozilla.components.browser.domains.autocomplete.BaseDomainAutocompleteProvider
import mozilla.components.browser.domains.autocomplete.DomainList
import mozilla.components.browser.domains.autocomplete.DomainsLoader
import mozilla.components.concept.toolbar.AutocompleteProvider
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
@RunWith(AndroidJUnit4::class)
class BaseDomainAutocompleteProviderTest {
@Test
fun `empty provider with DEFAULT list returns nothing`() {
val provider = createAndInitProvider(testContext, DomainList.DEFAULT) {
emptyList()
}
assertNoCompletion(provider, "m")
assertNoCompletion(provider, "mo")
assertNoCompletion(provider, "moz")
assertNoCompletion(provider, "g")
assertNoCompletion(provider, "go")
assertNoCompletion(provider, "goo")
assertNoCompletion(provider, "w")
assertNoCompletion(provider, "www")
}
@Test
fun `empty provider with CUSTOM list returns nothing`() {
val provider = createAndInitProvider(testContext, DomainList.CUSTOM) {
emptyList()
}
assertNoCompletion(provider, "m")
assertNoCompletion(provider, "mo")
assertNoCompletion(provider, "moz")
assertNoCompletion(provider, "g")
assertNoCompletion(provider, "go")
assertNoCompletion(provider, "goo")
assertNoCompletion(provider, "w")
assertNoCompletion(provider, "www")
}
@Test
fun `non-empty provider with DEFAULT list returns completion`() {
val domains = listOf("mozilla.org", "google.com", "facebook.com").into()
val list = DomainList.DEFAULT
val domainsCount = domains.size
val provider = createAndInitProvider(testContext, list) { domains }
shadowOf(getMainLooper()).idle()
assertCompletion(provider, list, domainsCount, "m", "m", "mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "moz", "moz", "mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "www", "www", "www.mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "www.face", "www.face", "www.facebook.com", "http://facebook.com")
assertCompletion(provider, list, domainsCount, "M", "m", "Mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "MOZ", "moz", "MOZilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "www.GOO", "www.goo", "www.GOOgle.com", "http://google.com")
assertCompletion(provider, list, domainsCount, "WWW.GOOGLE.", "www.google.", "WWW.GOOGLE.com", "http://google.com")
assertCompletion(provider, list, domainsCount, "www.facebook.com", "www.facebook.com", "www.facebook.com", "http://facebook.com")
assertCompletion(provider, list, domainsCount, "facebook.com", "facebook.com", "facebook.com", "http://facebook.com")
assertNoCompletion(provider, "wwww")
assertNoCompletion(provider, "yahoo")
}
@Test
fun `non-empty provider with CUSTOM list returns completion`() {
val domains = listOf("mozilla.org", "google.com", "facebook.com").into()
val list = DomainList.CUSTOM
val domainsCount = domains.size
val provider = createAndInitProvider(testContext, list) { domains }
shadowOf(getMainLooper()).idle()
assertCompletion(provider, list, domainsCount, "m", "m", "mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "moz", "moz", "mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "www", "www", "www.mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "www.face", "www.face", "www.facebook.com", "http://facebook.com")
assertCompletion(provider, list, domainsCount, "M", "m", "Mozilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "MOZ", "moz", "MOZilla.org", "http://mozilla.org")
assertCompletion(provider, list, domainsCount, "www.GOO", "www.goo", "www.GOOgle.com", "http://google.com")
assertCompletion(provider, list, domainsCount, "WWW.GOOGLE.", "www.google.", "WWW.GOOGLE.com", "http://google.com")
assertCompletion(provider, list, domainsCount, "www.facebook.com", "www.facebook.com", "www.facebook.com", "http://facebook.com")
assertCompletion(provider, list, domainsCount, "facebook.com", "facebook.com", "facebook.com", "http://facebook.com")
assertNoCompletion(provider, "wwww")
assertNoCompletion(provider, "yahoo")
}
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun assertCompletion(
provider: AutocompleteProvider,
domainSource: DomainList,
sourceSize: Int,
input: String,
expectedInput: String,
completion: String,
expectedUrl: String,
) = runTest {
val result = provider.getAutocompleteSuggestion(input)!!
assertTrue("Autocompletion shouldn't be empty", result.text.isNotEmpty())
assertEquals("Autocompletion input", expectedInput, result.input)
assertEquals("Autocompletion completion", completion, result.text)
assertEquals("Autocompletion source list", domainSource.listName, result.source)
assertEquals("Autocompletion url", expectedUrl, result.url)
assertEquals("Autocompletion source list size", sourceSize, result.totalItems)
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun assertNoCompletion(provider: AutocompleteProvider, input: String) = runTest {
val result = provider.getAutocompleteSuggestion(input)
assertNull("Result should be null", result)
}
private fun createAndInitProvider(context: Context, list: DomainList, loader: DomainsLoader): AutocompleteProvider =
object : BaseDomainAutocompleteProvider(list, loader) {
override val coroutineContext = super.coroutineContext + Dispatchers.Main
}.apply { initialize(context) }

View file

@ -0,0 +1,81 @@
/* 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/. */
package mozilla.components.browser.domains
import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class CustomDomainsTest {
@Before
fun setUp() {
testContext.getSharedPreferences("custom_autocomplete", Context.MODE_PRIVATE)
.edit()
.clear()
.apply()
}
@ExperimentalCoroutinesApi
@Test
fun customListIsEmptyByDefault() {
val domains = CustomDomains.load(testContext)
assertEquals(0, domains.size)
}
@Test
fun saveAndRemoveDomains() {
CustomDomains.save(
testContext,
listOf(
"mozilla.org",
"example.org",
"example.com",
),
)
var domains = CustomDomains.load(testContext)
assertEquals(3, domains.size)
CustomDomains.remove(testContext, listOf("example.org", "example.com"))
domains = CustomDomains.load(testContext)
assertEquals(1, domains.size)
assertEquals("mozilla.org", domains.elementAt(0))
}
@Test
fun addAndLoadDomains() {
CustomDomains.add(testContext, "mozilla.org")
val domains = CustomDomains.load(testContext)
assertEquals(1, domains.size)
assertEquals("mozilla.org", domains.elementAt(0))
}
@Test
fun saveAndLoadDomains() {
CustomDomains.save(
testContext,
listOf(
"mozilla.org",
"example.org",
"example.com",
),
)
val domains = CustomDomains.load(testContext)
assertEquals(3, domains.size)
assertEquals("mozilla.org", domains.elementAt(0))
assertEquals("example.org", domains.elementAt(1))
assertEquals("example.com", domains.elementAt(2))
}
}

View file

@ -0,0 +1,116 @@
/* 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/. */
@file:Suppress("DEPRECATION")
package mozilla.components.browser.domains
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.browser.domains.DomainAutoCompleteProvider.AutocompleteSource.CUSTOM_LIST
import mozilla.components.browser.domains.DomainAutoCompleteProvider.AutocompleteSource.DEFAULT_LIST
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
/**
* While [DomainAutoCompleteProvider] exists (even if it's deprecated) we need to test it.
*/
@RunWith(AndroidJUnit4::class)
class DomainAutoCompleteProviderTest {
@Test
fun autocompletionWithShippedDomains() {
val provider = DomainAutoCompleteProvider().also {
it.initialize(
testContext,
useShippedDomains = true,
useCustomDomains = false,
loadDomainsFromDisk = false,
)
it.shippedDomains = listOf("mozilla.org", "google.com", "facebook.com").into()
it.customDomains = emptyList()
}
val size = provider.shippedDomains.size
assertCompletion(provider, "m", DEFAULT_LIST, size, "mozilla.org", "http://mozilla.org")
assertCompletion(provider, "www", DEFAULT_LIST, size, "www.mozilla.org", "http://mozilla.org")
assertCompletion(provider, "www.face", DEFAULT_LIST, size, "www.facebook.com", "http://facebook.com")
assertCompletion(provider, "MOZ", DEFAULT_LIST, size, "MOZilla.org", "http://mozilla.org")
assertCompletion(provider, "www.GOO", DEFAULT_LIST, size, "www.GOOgle.com", "http://google.com")
assertCompletion(provider, "WWW.GOOGLE.", DEFAULT_LIST, size, "WWW.GOOGLE.com", "http://google.com")
assertCompletion(provider, "www.facebook.com", DEFAULT_LIST, size, "www.facebook.com", "http://facebook.com")
assertCompletion(provider, "facebook.com", DEFAULT_LIST, size, "facebook.com", "http://facebook.com")
assertNoCompletion(provider, "wwww")
assertNoCompletion(provider, "yahoo")
}
@Test
fun autocompletionWithCustomDomains() {
val domains = listOf("facebook.com", "google.com", "mozilla.org")
val customDomains = listOf("gap.com", "www.fanfiction.com", "https://mobile.de")
val provider = DomainAutoCompleteProvider().also {
it.initialize(
testContext,
useShippedDomains = true,
useCustomDomains = true,
loadDomainsFromDisk = false,
)
it.shippedDomains = domains.into()
it.customDomains = customDomains.into()
}
assertCompletion(provider, "f", CUSTOM_LIST, customDomains.size, "fanfiction.com", "http://www.fanfiction.com")
assertCompletion(provider, "fa", CUSTOM_LIST, customDomains.size, "fanfiction.com", "http://www.fanfiction.com")
assertCompletion(provider, "fac", DEFAULT_LIST, domains.size, "facebook.com", "http://facebook.com")
assertCompletion(provider, "g", CUSTOM_LIST, customDomains.size, "gap.com", "http://gap.com")
assertCompletion(provider, "go", DEFAULT_LIST, domains.size, "google.com", "http://google.com")
assertCompletion(provider, "ga", CUSTOM_LIST, customDomains.size, "gap.com", "http://gap.com")
assertCompletion(provider, "m", CUSTOM_LIST, customDomains.size, "mobile.de", "https://mobile.de")
assertCompletion(provider, "mo", CUSTOM_LIST, customDomains.size, "mobile.de", "https://mobile.de")
assertCompletion(provider, "mob", CUSTOM_LIST, customDomains.size, "mobile.de", "https://mobile.de")
assertCompletion(provider, "moz", DEFAULT_LIST, domains.size, "mozilla.org", "http://mozilla.org")
}
@Test
fun autocompletionWithoutDomains() {
val filter = DomainAutoCompleteProvider()
assertNoCompletion(filter, "mozilla")
}
private fun assertCompletion(
provider: DomainAutoCompleteProvider,
text: String,
domainSource: String,
sourceSize: Int,
completion: String,
expectedUrl: String,
) {
val result = provider.autocomplete(text)
assertFalse(result.text.isEmpty())
assertEquals(completion, result.text)
assertEquals(domainSource, result.source)
assertEquals(expectedUrl, result.url)
assertEquals(sourceSize, result.size)
}
private fun assertNoCompletion(provider: DomainAutoCompleteProvider, text: String) {
val result = provider.autocomplete(text)
assertTrue(result.text.isEmpty())
assertTrue(result.url.isEmpty())
assertTrue(result.source.isEmpty())
assertEquals(0, result.size)
}
}

View file

@ -0,0 +1,39 @@
/* 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/. */
package mozilla.components.browser.domains
import org.junit.Assert
import org.junit.Test
class DomainTest {
@Test
fun domainCreation() {
val firstItem = Domain.create("https://mozilla.com")
Assert.assertTrue(firstItem.protocol == "https://")
Assert.assertFalse(firstItem.hasWww)
Assert.assertTrue(firstItem.host == "mozilla.com")
val secondItem = Domain.create("www.mozilla.com")
Assert.assertTrue(secondItem.protocol == "http://")
Assert.assertTrue(secondItem.hasWww)
Assert.assertTrue(secondItem.host == "mozilla.com")
}
@Test
fun domainCanCreateUrl() {
val firstItem = Domain.create("https://mozilla.com")
Assert.assertEquals("https://mozilla.com", firstItem.url)
val secondItem = Domain.create("www.mozilla.com")
Assert.assertEquals("http://www.mozilla.com", secondItem.url)
}
@Test(expected = IllegalStateException::class)
fun domainCreationWithBadURLThrowsException() {
Domain.create("http://www.")
}
}

View file

@ -0,0 +1,30 @@
/* 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/. */
package mozilla.components.browser.domains
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class DomainsTest {
@Test
fun loadDomains() {
val domains = Domains.load(testContext, setOf("us"))
Assert.assertFalse(domains.isEmpty())
Assert.assertTrue(domains.contains("reddit.com"))
}
@Test
fun loadDomainsWithDefaultCountries() {
val domains = Domains.load(testContext)
Assert.assertFalse(domains.isEmpty())
// From the global list
Assert.assertTrue(domains.contains("mozilla.org"))
}
}

View file

@ -0,0 +1,85 @@
/* 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/. */
package mozilla.components.browser.domains
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import mozilla.components.browser.domains.autocomplete.BaseDomainAutocompleteProvider
import mozilla.components.browser.domains.autocomplete.CustomDomainsProvider
import mozilla.components.browser.domains.autocomplete.DomainList
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Test
class ProvidersTest {
@Test
fun autocompletionWithShippedDomains() {
val provider = ShippedDomainsProvider()
provider.domains = listOf("mozilla.org", "google.com", "facebook.com").into()
val size = provider.domains.size
assertCompletion(provider, "m", DomainList.DEFAULT, size, "mozilla.org", "http://mozilla.org")
assertCompletion(provider, "www", DomainList.DEFAULT, size, "www.mozilla.org", "http://mozilla.org")
assertCompletion(provider, "www.face", DomainList.DEFAULT, size, "www.facebook.com", "http://facebook.com")
assertCompletion(provider, "MOZ", DomainList.DEFAULT, size, "MOZilla.org", "http://mozilla.org")
assertCompletion(provider, "www.GOO", DomainList.DEFAULT, size, "www.GOOgle.com", "http://google.com")
assertCompletion(provider, "WWW.GOOGLE.", DomainList.DEFAULT, size, "WWW.GOOGLE.com", "http://google.com")
assertCompletion(provider, "www.facebook.com", DomainList.DEFAULT, size, "www.facebook.com", "http://facebook.com")
assertCompletion(provider, "facebook.com", DomainList.DEFAULT, size, "facebook.com", "http://facebook.com")
assertNoCompletion(provider, "wwww")
assertNoCompletion(provider, "yahoo")
}
@Test
fun autocompletionWithCustomDomains() {
val customDomains = listOf("gap.com", "www.fanfiction.com", "https://mobile.de")
val provider = CustomDomainsProvider()
provider.domains = customDomains.into()
assertCompletion(provider, "f", DomainList.CUSTOM, customDomains.size, "fanfiction.com", "http://www.fanfiction.com")
assertCompletion(provider, "fa", DomainList.CUSTOM, customDomains.size, "fanfiction.com", "http://www.fanfiction.com")
assertCompletion(provider, "g", DomainList.CUSTOM, customDomains.size, "gap.com", "http://gap.com")
assertCompletion(provider, "ga", DomainList.CUSTOM, customDomains.size, "gap.com", "http://gap.com")
assertCompletion(provider, "m", DomainList.CUSTOM, customDomains.size, "mobile.de", "https://mobile.de")
assertCompletion(provider, "mo", DomainList.CUSTOM, customDomains.size, "mobile.de", "https://mobile.de")
assertCompletion(provider, "mob", DomainList.CUSTOM, customDomains.size, "mobile.de", "https://mobile.de")
}
@Test
fun autocompletionWithoutDomains() {
val filter = CustomDomainsProvider()
assertNoCompletion(filter, "mozilla")
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun assertCompletion(
provider: BaseDomainAutocompleteProvider,
text: String,
domainSource: DomainList,
sourceSize: Int,
completion: String,
expectedUrl: String,
) = runTest {
val result = provider.getAutocompleteSuggestion(text)!!
assertFalse(result.text.isEmpty())
assertEquals(completion, result.text)
assertEquals(domainSource.listName, result.source)
assertEquals(expectedUrl, result.url)
assertEquals(sourceSize, result.totalItems)
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun assertNoCompletion(provider: BaseDomainAutocompleteProvider, text: String) = runTest {
assertNull(provider.getAutocompleteSuggestion(text))
}
}

View file

@ -0,0 +1,41 @@
# [Android Components](../../../README.md) > Browser > Engine-Gecko
[*Engine*](../../concept/engine/README.md) implementation based on [GeckoView](https://wiki.mozilla.org/Mobile/GeckoView).
## Usage
### Setting up the dependency
Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):
```Groovy
implementation "org.mozilla.components:browser-engine-gecko:{latest-version}"
```
### Integration with the Glean SDK
#### Before using this component
Products sending telemetry and using this component *must request* a data-review following [this process](https://wiki.mozilla.org/Firefox/Data_Collection).
The [Glean SDK](../../../components/service/glean/README.md) can be used to collect [Gecko Telemetry](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/index.html).
Applications using both this component and the Glean SDK should setup the Gecko Telemetry delegate
as shown below:
```Kotlin
val builder = GeckoRuntimeSettings.Builder()
val runtimeSettings = builder
.telemetryDelegate(GeckoGleanAdapter()) // Sets up the delegate!
.build()
// Create the Gecko runtime.
GeckoRuntime.create(context, runtimeSettings)
```
#### Adding new metrics
New Gecko metrics can be added as described [in the Firefox Telemetry docs](https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/start/adding-a-new-probe.html).
## License
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/

View file

@ -0,0 +1,193 @@
/* 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/. */
buildscript {
repositories {
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
maven {
url repository
if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
allowInsecureProtocol = true
}
}
}
}
dependencies {
classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
}
}
plugins {
id "com.jetbrains.python.envs" version "$python_envs_plugin"
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
defaultConfig {
minSdkVersion config.minSdkVersion
compileSdk config.compileSdkVersion
targetSdkVersion config.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
resources {
excludes += ['META-INF/proguard/androidx-annotations.pro']
}
}
buildFeatures {
buildConfig true
}
namespace 'mozilla.components.browser.engine.gecko'
}
// Set configuration for the Glean parser to extract metrics.yaml
// file from AAR dependencies of this project rather than look
// for it into the project directory.
ext.allowMetricsFromAAR = true
dependencies {
implementation project(':concept-engine')
implementation project(':concept-fetch')
implementation project(':support-ktx')
implementation project(':support-utils')
implementation(project(':service-nimbus')) {
exclude group: 'org.mozilla.telemetry', module: 'glean-native'
}
implementation ComponentsDependencies.kotlin_coroutines
if (findProject(":geckoview") != null) {
api project(':geckoview')
} else {
api getGeckoViewDependency()
}
implementation ComponentsDependencies.androidx_paging
implementation ComponentsDependencies.androidx_data_store_preferences
implementation ComponentsDependencies.androidx_lifecycle_livedata
testImplementation ComponentsDependencies.androidx_test_core
testImplementation ComponentsDependencies.androidx_test_junit
testImplementation ComponentsDependencies.testing_robolectric
testImplementation ComponentsDependencies.testing_coroutines
testImplementation ComponentsDependencies.testing_mockwebserver
testImplementation project(':support-test')
testImplementation project(':tooling-fetch-tests')
// We only compile against Glean. It's up to the app to add those dependencies
// if it wants to collect GeckoView telemetry through the Glean SDK.
compileOnly project(":service-glean")
testImplementation project(":service-glean")
testImplementation ComponentsDependencies.androidx_work_testing
androidTestImplementation ComponentsDependencies.androidx_test_core
androidTestImplementation ComponentsDependencies.androidx_test_runner
androidTestImplementation ComponentsDependencies.androidx_test_rules
androidTestImplementation project(':tooling-fetch-tests')
}
apply plugin: "org.mozilla.telemetry.glean-gradle-plugin"
apply from: '../../../android-lint.gradle'
apply from: '../../../publish.gradle'
apply plugin: "org.mozilla.appservices.nimbus-gradle-plugin"
nimbus {
// The path to the Nimbus feature manifest file
manifestFile = "geckoview.fml.yaml"
channels = [
debug: "debug",
release: "release",
]
// This is an optional value, and updates the plugin to use a copy of application
// services. The path should be relative to the root project directory.
// *NOTE*: This example will not work for all projects, but should work for Fenix, Focus, and Android Components
applicationServicesDir = gradle.hasProperty('localProperties.autoPublish.application-services.dir')
? gradle.getProperty('localProperties.autoPublish.application-services.dir') : null
}
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description)
// Non-official versions are like "61.0a1", where "a1" is the milestone.
// This simply strips that off, leaving "61.0" in this example.
def getAppVersionWithoutMilestone() {
return gradle.mozconfig.substs.MOZ_APP_VERSION.replaceFirst(/a[0-9]/, "")
}
// Mimic Python: open(os.path.join(buildconfig.topobjdir, 'buildid.h')).readline().split()[2]
def getBuildId() {
if (System.env.MOZ_BUILD_DATE) {
if (System.env.MOZ_BUILD_DATE.length() == 14) {
return System.env.MOZ_BUILD_DATE
}
logger.warn("Ignoring invalid MOZ_BUILD_DATE: ${System.env.MOZ_BUILD_DATE}")
}
return file("${gradle.mozconfig.topobjdir}/buildid.h").getText('utf-8').split()[2]
}
def getVersionNumber() {
def appVersion = getAppVersionWithoutMilestone()
def parts = appVersion.split('\\.')
def version = parts[0] + "." + parts[1] + "." + getBuildId()
if (!gradle.mozconfig.substs.MOZILLA_OFFICIAL && !gradle.mozconfig.substs.MOZ_ANDROID_FAT_AAR_ARCHITECTURES) {
// Use -SNAPSHOT versions locally to enable the local GeckoView substitution flow.
version += "-SNAPSHOT"
}
return version
}
def getArtifactSuffix() {
def suffix = ""
// Release artifacts don't specify the channel, for the sake of simplicity.
if (gradle.mozconfig.substs.MOZ_UPDATE_CHANNEL != 'release') {
suffix += "-${gradle.mozconfig.substs.MOZ_UPDATE_CHANNEL}"
}
return suffix
}
def getArtifactId() {
def id = "geckoview" + getArtifactSuffix()
if (!gradle.mozconfig.substs.MOZ_ANDROID_GECKOVIEW_LITE) {
id += "-omni"
}
if (gradle.mozconfig.substs.MOZILLA_OFFICIAL && !gradle.mozconfig.substs.MOZ_ANDROID_FAT_AAR_ARCHITECTURES) {
// In automation, per-architecture artifacts identify
// the architecture; multi-architecture artifacts don't.
// When building locally, we produce a "skinny AAR" with
// one target architecture masquerading as a "fat AAR"
// to enable Gradle composite builds to substitute this
// project into consumers easily.
id += "-${gradle.mozconfig.substs.ANDROID_CPU_ARCH}"
}
return id
}
def getGeckoViewDependency() {
// on try, relax geckoview version pin to allow for --use-existing-task
if ('https://hg.mozilla.org/try' == System.env.GECKO_HEAD_REPOSITORY) {
rootProject.logger.lifecycle("Getting geckoview on try: ${getArtifactId()}:+")
return "org.mozilla.geckoview:${getArtifactId()}:+"
}
rootProject.logger.lifecycle("Getting geckoview: ${getArtifactId()}:${getVersionNumber()}")
return "org.mozilla.geckoview:${getArtifactId()}:${getVersionNumber()}"
}

View file

@ -0,0 +1,8 @@
# Metrics definitions have moved
Metrics definitions for projects using `engine-gecko` moved to the Glean Dictionary.
For Firefox for Android those definitions can be found at:
[https://dictionary.telemetry.mozilla.org/apps/fenix](https://dictionary.telemetry.mozilla.org/apps/fenix)
This file is kept only for historical reference.

View file

@ -0,0 +1,24 @@
# 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/.
about:
description: GeckoView features configurable via Nimbus
android:
package: mozilla.components.browser.engine.gecko
class: .GeckoNimbus
channels:
- debug
- release
features:
pdfjs:
description: "PDF.js features"
variables:
download-button:
description: "Download button"
type: Boolean
default: true
open-in-app-button:
description: "Open in app button"
type: Boolean
default: true

View file

@ -0,0 +1,30 @@
# 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/.
# IMPORTANT NOTE: this file is here only as a safety measure, to make
# sure the correct code is generated even though the GeckoView AAR file
# reports an empty metrics.yaml file. The metric in this file is currently
# disabled and not supposed to collect any data.
---
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
test.glean.geckoview:
streaming:
type: timing_distribution
gecko_datapoint: TELEMETRY_TEST_STREAMING
disabled: true
description: |
A test-only, disabled metric. This is required to guarantee
that a `GleanGeckoHistogramMapping` is always generated, even
though the GeckoView AAR exports no metric. Please note that
the data-review field below contains no review, since this
metric is disabled and not allowed to collect any data.
bugs:
- https://bugzilla.mozilla.org/1566374
data_reviews:
- https://bugzilla.mozilla.org/1566374
notification_emails:
- glean-team@mozilla.com
expires: never

View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,126 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.fetch.geckoview
import androidx.test.annotation.UiThreadTest
import androidx.test.core.app.ApplicationProvider
import androidx.test.filters.MediumTest
import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient
import mozilla.components.concept.fetch.Client
import org.junit.Assert.assertTrue
import org.junit.Test
@MediumTest
class GeckoViewFetchTestCases : mozilla.components.tooling.fetch.tests.FetchTestCases() {
override fun createNewClient(): Client = GeckoViewFetchClient(ApplicationProvider.getApplicationContext())
@Test
@UiThreadTest
fun clientInstance() {
assertTrue(createNewClient() is GeckoViewFetchClient)
}
@Test
@UiThreadTest
override fun get200WithGzippedBody() {
super.get200WithGzippedBody()
}
@Test
@UiThreadTest
override fun get200OverridingDefaultHeaders() {
super.get200OverridingDefaultHeaders()
}
@Test
@UiThreadTest
override fun get200WithDuplicatedCacheControlRequestHeaders() {
super.get200WithDuplicatedCacheControlRequestHeaders()
}
@Test
@UiThreadTest
override fun get200WithDuplicatedCacheControlResponseHeaders() {
super.get200WithDuplicatedCacheControlResponseHeaders()
}
@Test
@UiThreadTest
override fun get200WithHeaders() {
super.get200WithHeaders()
}
@Test
@UiThreadTest
override fun get200WithReadTimeout() {
super.get200WithReadTimeout()
}
@Test
@UiThreadTest
override fun get200WithStringBody() {
super.get200WithStringBody()
}
@Test
@UiThreadTest
override fun get302FollowRedirects() {
super.get302FollowRedirects()
}
@Test
@UiThreadTest
override fun get302FollowRedirectsDisabled() {
super.get302FollowRedirectsDisabled()
}
@Test
@UiThreadTest
override fun get404WithBody() {
super.get404WithBody()
}
@Test
@UiThreadTest
override fun post200WithBody() {
super.post200WithBody()
}
@Test
@UiThreadTest
override fun put201FileUpload() {
super.put201FileUpload()
}
@Test
@UiThreadTest
override fun get200WithCookiePolicy() {
super.get200WithCookiePolicy()
}
@Test
@UiThreadTest
override fun get200WithContentTypeCharset() {
super.get200WithContentTypeCharset()
}
@Test
@UiThreadTest
override fun get200WithCacheControl() {
super.get200WithCacheControl()
}
@Test
@UiThreadTest
override fun getThrowsIOExceptionWhenHostNotReachable() {
super.getThrowsIOExceptionWhenHostNotReachable()
}
@Test
@UiThreadTest
override fun getDataUri() {
super.getDataUri()
}
}

View file

@ -0,0 +1,4 @@
<!-- 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/. -->
<manifest />

View file

@ -0,0 +1,73 @@
/* 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/. */
package mozilla.components.browser.engine.gecko
import android.util.JsonReader
import android.util.JsonWriter
import mozilla.components.concept.engine.EngineSessionState
import org.json.JSONException
import org.json.JSONObject
import org.mozilla.geckoview.GeckoSession
import java.io.IOException
private const val GECKO_STATE_KEY = "GECKO_STATE"
class GeckoEngineSessionState internal constructor(
internal val actualState: GeckoSession.SessionState?,
) : EngineSessionState {
override fun writeTo(writer: JsonWriter) {
with(writer) {
beginObject()
name(GECKO_STATE_KEY)
value(actualState.toString())
endObject()
flush()
}
}
companion object {
fun fromJSON(json: JSONObject): GeckoEngineSessionState = try {
val state = json.getString(GECKO_STATE_KEY)
GeckoEngineSessionState(
GeckoSession.SessionState.fromString(state),
)
} catch (e: JSONException) {
GeckoEngineSessionState(null)
}
/**
* Creates a [GeckoEngineSessionState] from the given [JsonReader].
*/
fun from(reader: JsonReader): GeckoEngineSessionState = try {
reader.beginObject()
val rawState = if (reader.hasNext()) {
val key = reader.nextName()
if (key != GECKO_STATE_KEY) {
throw AssertionError("Unknown state key: $key")
}
reader.nextString()
} else {
null
}
reader.endObject()
GeckoEngineSessionState(
rawState?.let { GeckoSession.SessionState.fromString(it) },
)
} catch (e: IOException) {
GeckoEngineSessionState(null)
} catch (e: JSONException) {
// Internally GeckoView uses org.json and currently may throw JSONException in certain cases
// https://github.com/mozilla-mobile/android-components/issues/9332
GeckoEngineSessionState(null)
}
}
}

View file

@ -0,0 +1,249 @@
/* 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/. */
package mozilla.components.browser.engine.gecko
import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Color
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.core.view.ViewCompat
import mozilla.components.browser.engine.gecko.activity.GeckoViewActivityContextDelegate
import mozilla.components.browser.engine.gecko.selection.GeckoSelectionActionDelegate
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
import mozilla.components.concept.engine.selection.SelectionActionDelegate
import org.mozilla.geckoview.BasicSelectionActionDelegate
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import java.lang.ref.WeakReference
/**
* Gecko-based EngineView implementation.
*/
class GeckoEngineView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr), EngineView {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal var geckoView = object : NestedGeckoView(context) {
override fun onAttachedToWindow() {
try {
super.onAttachedToWindow()
} catch (e: IllegalStateException) {
// This is to debug "display already acquired" crashes
val otherActivityClassName =
this.session?.accessibility?.view?.context?.javaClass?.simpleName
val otherActivityClassHashcode =
this.session?.accessibility?.view?.context?.hashCode()
val activityClassName = context.javaClass.simpleName
val activityClassHashCode = context.hashCode()
val msg = "ATTACH VIEW: Current activity: $activityClassName hashcode " +
"$activityClassHashCode Other activity: $otherActivityClassName " +
"hashcode $otherActivityClassHashcode"
throw IllegalStateException(msg, e)
}
}
override fun onDetachedFromWindow() {
// We are releasing the session before GeckoView gets detached from the window. Otherwise
// GeckoView will close the session automatically and we do not want that.
releaseSession()
super.onDetachedFromWindow()
}
}.apply {
// Explicitly mark this view as important for autofill. The default "auto" doesn't seem to trigger any
// autofill behavior for us here.
@Suppress("WrongConstant")
ViewCompat.setImportantForAutofill(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES)
}
internal fun setColorScheme(preferredColorScheme: PreferredColorScheme) {
var colorScheme = preferredColorScheme
if (preferredColorScheme == PreferredColorScheme.System) {
colorScheme =
if (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
== Configuration.UI_MODE_NIGHT_YES
) {
PreferredColorScheme.Dark
} else {
PreferredColorScheme.Light
}
}
if (colorScheme == PreferredColorScheme.Dark) {
geckoView.coverUntilFirstPaint(DARK_COVER)
} else {
geckoView.coverUntilFirstPaint(Color.WHITE)
}
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal var currentSession: GeckoEngineSession? = null
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal var currentSelection: BasicSelectionActionDelegate? = null
override var selectionActionDelegate: SelectionActionDelegate? = null
init {
addView(geckoView)
/**
* With the current design, we have a [NestedGeckoView] inside this
* [GeckoEngineView]. In our supported embedders, we wrap this with the
* AndroidX `SwipeRefreshLayout` to enable features like Pull-To-Refresh:
*
* ```
* SwipeRefreshLayout
* GeckoEngineView
* NestedGeckoView
* ```
*
* `SwipeRefreshLayout` only looks at the direct child to see if it has nested scrolling
* enabled. As we embed [NestedGeckoView] inside [GeckoEngineView], we change the hierarchy
* so that [NestedGeckoView] is no longer the direct child of `SwipeRefreshLayout`.
*
* To fix this we enable nested scrolling on the GeckoEngineView to emulate this
* information. This is required information for `View.requestDisallowInterceptTouchEvent`
* to work correctly in the [NestedGeckoView].
*/
isNestedScrollingEnabled = true
}
/**
* Render the content of the given session.
*/
@Synchronized
override fun render(session: EngineSession) {
val internalSession = session as GeckoEngineSession
currentSession = session
if (geckoView.session != internalSession.geckoSession) {
geckoView.session?.let {
// Release a previously assigned session. Otherwise GeckoView will close it
// automatically.
detachSelectionActionDelegate(it)
geckoView.releaseSession()
}
try {
geckoView.setSession(internalSession.geckoSession)
attachSelectionActionDelegate(internalSession.geckoSession)
} catch (e: IllegalStateException) {
// This is to debug "display already acquired" crashes
val otherActivityClassName =
internalSession.geckoSession.accessibility.view?.context?.javaClass?.simpleName
val otherActivityClassHashcode =
internalSession.geckoSession.accessibility.view?.context?.hashCode()
val activityClassName = context.javaClass.simpleName
val activityClassHashCode = context.hashCode()
val msg = "SET SESSION: Current activity: $activityClassName hashcode " +
"$activityClassHashCode Other activity: $otherActivityClassName " +
"hashcode $otherActivityClassHashcode"
throw IllegalStateException(msg, e)
}
}
}
private fun attachSelectionActionDelegate(session: GeckoSession) {
val delegate = GeckoSelectionActionDelegate.maybeCreate(context, selectionActionDelegate)
if (delegate != null) {
session.selectionActionDelegate = delegate
currentSelection = delegate
}
}
private fun detachSelectionActionDelegate(session: GeckoSession?) {
if (currentSelection != null) {
session?.selectionActionDelegate = null
currentSelection = null
}
}
@Synchronized
override fun release() {
detachSelectionActionDelegate(currentSession?.geckoSession)
currentSession = null
geckoView.releaseSession()
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
release()
}
override fun canClearSelection() = !currentSelection?.selection?.text.isNullOrEmpty()
override fun canScrollVerticallyUp() = currentSession?.let { it.scrollY > 0 } != false
override fun canScrollVerticallyDown() =
true // waiting for this issue https://bugzilla.mozilla.org/show_bug.cgi?id=1507569
override fun getInputResultDetail() = geckoView.inputResultDetail
override fun setVerticalClipping(clippingHeight: Int) {
geckoView.setVerticalClipping(clippingHeight)
}
override fun setDynamicToolbarMaxHeight(height: Int) {
geckoView.setDynamicToolbarMaxHeight(height)
}
override fun setActivityContext(context: Context?) {
geckoView.activityContextDelegate = GeckoViewActivityContextDelegate(WeakReference(context))
}
@Suppress("TooGenericExceptionCaught")
override fun captureThumbnail(onFinish: (Bitmap?) -> Unit) {
try {
val geckoResult = geckoView.capturePixels()
geckoResult.then(
{ bitmap ->
onFinish(bitmap)
GeckoResult<Void>()
},
{
onFinish(null)
GeckoResult<Void>()
},
)
} catch (e: Exception) {
// There's currently no reliable way for consumers of GeckoView to
// know whether or not the compositor is ready. So we have to add
// a catch-all here. In the future, GeckoView will invoke our error
// callback instead and this block can be removed:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1645114
// https://github.com/mozilla-mobile/android-components/issues/6680
onFinish(null)
}
}
override fun clearSelection() {
currentSelection?.clearSelection()
}
override fun setVisibility(visibility: Int) {
// GeckoView doesn't react to onVisibilityChanged so we need to propagate ourselves for now:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1630775
// We do this to prevent the content from resizing when the view is not visible:
// https://github.com/mozilla-mobile/android-components/issues/6664
geckoView.visibility = visibility
super.setVisibility(visibility)
}
companion object {
internal const val DARK_COVER = 0xFF2A2A2E.toInt()
}
}

View file

@ -0,0 +1,76 @@
/* 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/. */
package mozilla.components.browser.engine.gecko
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.launch
import mozilla.components.concept.engine.CancellableOperation
import org.mozilla.geckoview.GeckoResult
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
/**
* Wait for a GeckoResult to be complete in a co-routine.
*/
suspend fun <T> GeckoResult<T>.await() = suspendCoroutine<T?> { continuation ->
then(
{
continuation.resume(it)
GeckoResult<Void>()
},
{
continuation.resumeWithException(it)
GeckoResult<Void>()
},
)
}
/**
* Converts a [GeckoResult] to a [CancellableOperation].
*/
fun <T> GeckoResult<T>.asCancellableOperation(): CancellableOperation {
val geckoResult = this
return object : CancellableOperation {
override fun cancel(): Deferred<Boolean> {
val result = CompletableDeferred<Boolean>()
geckoResult.cancel().then(
{
result.complete(it ?: false)
GeckoResult<Void>()
},
{ throwable ->
result.completeExceptionally(throwable)
GeckoResult<Void>()
},
)
return result
}
}
}
/**
* Create a GeckoResult from a co-routine.
*/
@Suppress("TooGenericExceptionCaught")
fun <T> CoroutineScope.launchGeckoResult(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> T,
) = GeckoResult<T>().apply {
launch(context, start) {
try {
val value = block()
complete(value)
} catch (exception: Throwable) {
completeExceptionally(exception)
}
}
}

View file

@ -0,0 +1,146 @@
/* 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/. */
package mozilla.components.browser.engine.gecko
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import mozilla.components.browser.engine.gecko.content.blocking.GeckoTrackingProtectionException
import mozilla.components.browser.engine.gecko.ext.geckoTrackingProtectionPermission
import mozilla.components.browser.engine.gecko.ext.isExcludedForTrackingProtection
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import mozilla.components.concept.engine.content.blocking.TrackingProtectionExceptionStorage
import mozilla.components.support.ktx.kotlin.getOrigin
import mozilla.components.support.ktx.kotlin.stripDefaultPort
import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY
/**
* A [TrackingProtectionExceptionStorage] implementation to store tracking protection exceptions.
*/
internal class GeckoTrackingProtectionExceptionStorage(
private val runtime: GeckoRuntime,
) : TrackingProtectionExceptionStorage {
internal var scope = CoroutineScope(Dispatchers.IO)
override fun contains(session: EngineSession, onResult: (Boolean) -> Unit) {
val url = (session as GeckoEngineSession).currentUrl
if (!url.isNullOrEmpty()) {
getPermissions(url) { permissions ->
val contains = permissions.isNotEmpty()
onResult(contains)
}
} else {
onResult(false)
}
}
override fun fetchAll(onResult: (List<TrackingProtectionException>) -> Unit) {
runtime.storageController.allPermissions.accept { permissions ->
val trackingExceptions = permissions.filterTrackingProtectionExceptions()
onResult(trackingExceptions.map { exceptions -> exceptions.toTrackingProtectionException() })
}
}
private fun List<ContentPermission>?.filterTrackingProtectionExceptions() =
this.orEmpty().filter { it.isExcludedForTrackingProtection }
private fun List<ContentPermission>?.filterTrackingProtectionExceptions(url: String) =
this.orEmpty()
.filter {
it.isExcludedForTrackingProtection && it.uri.getOrigin().orEmpty()
.stripDefaultPort() == url
}
override fun add(session: EngineSession, persistInPrivateMode: Boolean) {
val geckoEngineSession = (session as GeckoEngineSession)
if (persistInPrivateMode) {
addPersistentPrivateException(geckoEngineSession)
} else {
geckoEngineSession.geckoTrackingProtectionPermission?.let {
runtime.storageController.setPermission(it, VALUE_ALLOW)
}
}
geckoEngineSession.notifyObservers {
onExcludedOnTrackingProtectionChange(true)
}
}
internal fun addPersistentPrivateException(geckoEngineSession: GeckoEngineSession) {
val permission = geckoEngineSession.geckoTrackingProtectionPermission
permission?.let {
runtime.storageController.setPrivateBrowsingPermanentPermission(it, VALUE_ALLOW)
}
}
override fun remove(session: EngineSession) {
val geckoEngineSession = (session as GeckoEngineSession)
val url = geckoEngineSession.currentUrl ?: return
geckoEngineSession.notifyObservers {
onExcludedOnTrackingProtectionChange(false)
}
remove(url)
}
override fun remove(exception: TrackingProtectionException) {
if (exception is GeckoTrackingProtectionException) {
remove(exception.contentPermission)
} else {
remove(exception.url)
}
}
@VisibleForTesting
internal fun remove(url: String) {
val storage = runtime.storageController
getPermissions(url) { permissions ->
permissions.forEach { geckoPermissions ->
storage.setPermission(geckoPermissions, VALUE_DENY)
}
}
}
// This is a workaround until https://bugzilla.mozilla.org/show_bug.cgi?id=1723280 gets addressed
private fun getPermissions(url: String, onFinish: (List<ContentPermission>) -> Unit) {
val localUrl = url.getOrigin().orEmpty().stripDefaultPort()
val storage = runtime.storageController
if (localUrl.isNotEmpty()) {
storage.allPermissions.accept { permissions ->
onFinish(permissions.filterTrackingProtectionExceptions(localUrl))
}
} else {
onFinish(emptyList())
}
}
@VisibleForTesting
internal fun remove(contentPermission: ContentPermission) {
runtime.storageController.setPermission(contentPermission, VALUE_DENY)
}
override fun removeAll(activeSessions: List<EngineSession>?, onRemove: () -> Unit) {
val storage = runtime.storageController
activeSessions?.forEach { engineSession ->
engineSession.notifyObservers {
onExcludedOnTrackingProtectionChange(false)
}
}
storage.allPermissions.accept { permissions ->
val trackingExceptions = permissions.filterTrackingProtectionExceptions()
trackingExceptions.forEach {
storage.setPermission(it, VALUE_DENY)
}
onRemove.invoke()
}
}
}
private fun ContentPermission.toTrackingProtectionException(): GeckoTrackingProtectionException {
return GeckoTrackingProtectionException(uri, privateMode, this)
}

View file

@ -0,0 +1,258 @@
/* 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/. */
package mozilla.components.browser.engine.gecko
import android.annotation.SuppressLint
import android.content.Context
import android.view.MotionEvent
import androidx.annotation.VisibleForTesting
import androidx.core.view.NestedScrollingChild
import androidx.core.view.NestedScrollingChildHelper
import androidx.core.view.ViewCompat
import mozilla.components.concept.engine.InputResultDetail
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoView
import org.mozilla.geckoview.PanZoomController
/**
* geckoView that supports nested scrolls (for using in a CoordinatorLayout).
*
* This code is a simplified version of the NestedScrollView implementation
* which can be found in the support library:
* [android.support.v4.widget.NestedScrollView]
*
* Based on:
* https://github.com/takahirom/webview-in-coordinatorlayout
*/
@Suppress("ClickableViewAccessibility")
open class NestedGeckoView(context: Context) : GeckoView(context), NestedScrollingChild {
@VisibleForTesting
internal var lastY: Int = 0
@VisibleForTesting
internal val scrollOffset = IntArray(2)
private val scrollConsumed = IntArray(2)
private var gestureCanReachParent = true
private var initialDownY: Float = 0f
@VisibleForTesting
internal var nestedOffsetY: Int = 0
@VisibleForTesting
internal var childHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this)
/**
* How user's MotionEvent will be handled.
*
* @see InputResultDetail
*/
internal var inputResultDetail = InputResultDetail.newInstance(true)
init {
isNestedScrollingEnabled = true
}
@Suppress("ComplexMethod")
override fun onTouchEvent(ev: MotionEvent): Boolean {
val event = MotionEvent.obtain(ev)
val action = ev.actionMasked
val eventY = event.y.toInt()
when (action) {
MotionEvent.ACTION_MOVE -> {
val allowScroll = !shouldPinOnScreen() && inputResultDetail.isTouchHandledByBrowser()
var deltaY = lastY - eventY
if (allowScroll && dispatchNestedPreScroll(0, deltaY, scrollConsumed, scrollOffset)) {
deltaY -= scrollConsumed[1]
event.offsetLocation(0f, (-scrollOffset[1]).toFloat())
nestedOffsetY += scrollOffset[1]
}
lastY = eventY - scrollOffset[1]
if (allowScroll && dispatchNestedScroll(0, scrollOffset[1], 0, deltaY, scrollOffset)) {
lastY -= scrollOffset[1]
event.offsetLocation(0f, scrollOffset[1].toFloat())
nestedOffsetY += scrollOffset[1]
}
// If this event is the first touch move event, there are two possible cases
// where we still need to wait for the response for this first touch move event.
// a) we haven't yet received the response from GeckoView because of active touch
// event listeners etc.
// b) we have received the response for the touch down event that GeckoView
// consumed the event
// In the case of a) it's possible a touch move event listener does preventDefault()
// for this touch move event, then any subsequent touch events need to be directly
// routed to GeckoView rather than being intercepted.
// In the case of b) if GeckoView consumed this touch move event to scroll down the
// web content, any touch event interception should not be allowed since, for example
// SwipeRefreshLayout is supposed to trigger a refresh after the user started scroll
// down if the user restored the scroll position at the top.
val hasDragGestureStarted = event.y != initialDownY
if (gestureCanReachParent && hasDragGestureStarted) {
updateInputResult(event)
event.recycle()
return true
}
}
MotionEvent.ACTION_DOWN -> {
// A new gesture started. Ask GV if it can handle this.
parent?.requestDisallowInterceptTouchEvent(true)
updateInputResult(event)
nestedOffsetY = 0
lastY = eventY
initialDownY = event.y
// The event should be handled either by onTouchEvent,
// either by onTouchEventForResult, never by both.
// Early return if we sent it to updateInputResult(..) which calls onTouchEventForResult.
event.recycle()
return true
}
// We don't care about other touch events
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
// inputResultDetail needs to be reset here and not in the next ACTION_DOWN, because
// its value is used by other features that poll for the value via
// `EngineView.getInputResultDetail`. Not resetting this in ACTION_CANCEL/ACTION_UP
// would then mean we send stale information to those features from a previous
// gesture's result.
inputResultDetail = InputResultDetail.newInstance(true)
stopNestedScroll()
// Allow touch event interception here so that the next ACTION_DOWN event can be properly
// intercepted by the parent.
parent?.requestDisallowInterceptTouchEvent(false)
gestureCanReachParent = true
}
}
// Execute event handler from parent class in all cases
val eventHandled = callSuperOnTouchEvent(event)
// Recycle previously obtained event
event.recycle()
return eventHandled
}
@VisibleForTesting
internal fun callSuperOnTouchEvent(event: MotionEvent): Boolean {
return super.onTouchEvent(event)
}
@SuppressLint("WrongThread") // Lint complains startNestedScroll() needs to be called on the main thread
@VisibleForTesting
internal fun updateInputResult(event: MotionEvent) {
val eventAction = event.actionMasked
val eventY = event.y
superOnTouchEventForDetailResult(event)
.accept {
// Since the response from APZ is async, we could theoretically have a response
// which is out of time when we get the ACTION_MOVE events, and we do not want
// to forward this to the parent pre-emptively.
if (!gestureCanReachParent) {
return@accept
}
inputResultDetail = inputResultDetail.copy(
it?.handledResult(),
it?.scrollableDirections(),
it?.overscrollDirections(),
)
when (eventAction) {
MotionEvent.ACTION_DOWN -> {
// Gesture can reach the parent only if the content is already at the top
gestureCanReachParent = inputResultDetail.canOverscrollTop()
if (gestureCanReachParent && inputResultDetail.isTouchUnhandled()) {
// If the event wasn't used in GeckoView, allow touch event interception.
parent?.requestDisallowInterceptTouchEvent(false)
}
}
MotionEvent.ACTION_MOVE -> {
if (initialDownY < eventY) {
// In the case of scroll upwards gestures, allow touch event interception
// only if the event wasn't consumed by the web site. I.e. even if
// the event was consumed by the browser to scroll up the content.
if (!inputResultDetail.isTouchHandledByWebsite()) {
parent?.requestDisallowInterceptTouchEvent(false)
}
} else if (initialDownY > eventY) {
// Once after the content started scroll down, touch event interception
// is never allowed.
parent?.requestDisallowInterceptTouchEvent(true)
gestureCanReachParent = false
} else {
// Normally ACTION_MOVE should happen with moving the event position,
// but if it happened allow touch event interception just in case.
parent?.requestDisallowInterceptTouchEvent(false)
}
}
}
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL)
}
}
@VisibleForTesting
internal open fun superOnTouchEventForDetailResult(
event: MotionEvent,
): GeckoResult<PanZoomController.InputResultDetail> =
super.onTouchEventForDetailResult(event)
override fun setNestedScrollingEnabled(enabled: Boolean) {
childHelper.isNestedScrollingEnabled = enabled
}
override fun isNestedScrollingEnabled(): Boolean {
return childHelper.isNestedScrollingEnabled
}
override fun startNestedScroll(axes: Int): Boolean {
return childHelper.startNestedScroll(axes)
}
override fun stopNestedScroll() {
childHelper.stopNestedScroll()
}
override fun hasNestedScrollingParent(): Boolean {
return childHelper.hasNestedScrollingParent()
}
override fun dispatchNestedScroll(
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
offsetInWindow: IntArray?,
): Boolean {
return childHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow)
}
override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?): Boolean {
return childHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
}
override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean {
return childHelper.dispatchNestedFling(velocityX, velocityY, consumed)
}
override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float): Boolean {
return childHelper.dispatchNestedPreFling(velocityX, velocityY)
}
}

View file

@ -0,0 +1,45 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.activity
import android.app.PendingIntent
import android.content.Intent
import mozilla.components.concept.engine.activity.ActivityDelegate
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoRuntime
import java.lang.ref.WeakReference
/**
* A wrapper for the [ActivityDelegate] to communicate with the Gecko-based delegate.
*/
internal class GeckoActivityDelegate(
private val delegateRef: WeakReference<ActivityDelegate>,
) : GeckoRuntime.ActivityDelegate {
private val logger = Logger(GeckoActivityDelegate::javaClass.name)
override fun onStartActivityForResult(intent: PendingIntent): GeckoResult<Intent> {
val result: GeckoResult<Intent> = GeckoResult()
val delegate = delegateRef.get()
if (delegate == null) {
logger.warn("No activity delegate attached. Cannot request FIDO auth.")
result.completeExceptionally(RuntimeException("Activity for result failed; no delegate attached."))
return result
}
delegate.startIntentSenderForResult(intent.intentSender) { data ->
if (data != null) {
result.complete(data)
} else {
result.completeExceptionally(RuntimeException("Activity for result failed."))
}
}
return result
}
}

View file

@ -0,0 +1,35 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.activity
import mozilla.components.concept.engine.activity.OrientationDelegate
import org.mozilla.geckoview.AllowOrDeny
import org.mozilla.geckoview.AllowOrDeny.ALLOW
import org.mozilla.geckoview.AllowOrDeny.DENY
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.OrientationController
/**
* Default [OrientationController.OrientationDelegate] implementation that delegates both the behavior
* and the returned value to a [OrientationDelegate].
*/
internal class GeckoScreenOrientationDelegate(
private val delegate: OrientationDelegate,
) : OrientationController.OrientationDelegate {
override fun onOrientationLock(requestedOrientation: Int): GeckoResult<AllowOrDeny> {
val result = GeckoResult<AllowOrDeny>()
when (delegate.onOrientationLock(requestedOrientation)) {
true -> result.complete(ALLOW)
false -> result.complete(DENY)
}
return result
}
override fun onOrientationUnlock() {
delegate.onOrientationUnlock()
}
}

View file

@ -0,0 +1,43 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.activity
import android.app.Activity
import android.content.Context
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.geckoview.GeckoView
import java.lang.ref.WeakReference
/**
* GeckoViewActivityContextDelegate provides an active Activity to GeckoView or null. Not to be confused
* with the runtime delegate of [GeckoActivityDelegate], which is tightly coupled to webauthn.
* See bug 1806191 for more information on delegate differences.
*
* @param contextRef A reference to an active Activity context or null for GeckoView to use.
*/
class GeckoViewActivityContextDelegate(
private val contextRef: WeakReference<Context?>,
) : GeckoView.ActivityContextDelegate {
private val logger = Logger("GeckoViewActivityContextDelegate")
init {
if (contextRef.get() == null) {
logger.warn("Activity context is null.")
} else if (contextRef.get() !is Activity) {
logger.warn("A non-activity context was set.")
}
}
/**
* Used by GeckoView to get an Activity context for operations such as printing.
* @return An active Activity context or null.
*/
override fun getActivityContext(): Context? {
val context = contextRef.get()
if ((context == null)) {
return null
}
return context
}
}

View file

@ -0,0 +1,110 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.autofill
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mozilla.components.browser.engine.gecko.ext.toAutocompleteAddress
import mozilla.components.browser.engine.gecko.ext.toCreditCardEntry
import mozilla.components.browser.engine.gecko.ext.toLoginEntry
import mozilla.components.concept.storage.CreditCard
import mozilla.components.concept.storage.CreditCardsAddressesStorageDelegate
import mozilla.components.concept.storage.Login
import mozilla.components.concept.storage.LoginStorageDelegate
import org.mozilla.geckoview.Autocomplete
import org.mozilla.geckoview.GeckoResult
/**
* Gecko credit card and login storage delegate that handles runtime storage requests. This allows
* the Gecko runtime to call the underlying storage to handle requests for fetching, saving and
* updating of autocomplete items in the storage.
*
* @param creditCardsAddressesStorageDelegate An instance of [CreditCardsAddressesStorageDelegate].
* Provides methods for retrieving [CreditCard]s from the underlying storage.
* @param loginStorageDelegate An instance of [LoginStorageDelegate].
* Provides read/write methods for the [Login] storage.
*/
class GeckoAutocompleteStorageDelegate(
private val creditCardsAddressesStorageDelegate: CreditCardsAddressesStorageDelegate,
private val loginStorageDelegate: LoginStorageDelegate,
) : Autocomplete.StorageDelegate {
override fun onAddressFetch(): GeckoResult<Array<Autocomplete.Address>>? {
val result = GeckoResult<Array<Autocomplete.Address>>()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(IO) {
val addresses = creditCardsAddressesStorageDelegate.onAddressesFetch()
.map { it.toAutocompleteAddress() }
.toTypedArray()
result.complete(addresses)
}
return result
}
override fun onCreditCardFetch(): GeckoResult<Array<Autocomplete.CreditCard>> {
val result = GeckoResult<Array<Autocomplete.CreditCard>>()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(IO) {
val key = creditCardsAddressesStorageDelegate.getOrGenerateKey()
val creditCards = creditCardsAddressesStorageDelegate.onCreditCardsFetch()
.mapNotNull {
val plaintextCardNumber =
creditCardsAddressesStorageDelegate.decrypt(key, it.encryptedCardNumber)?.number
if (plaintextCardNumber == null) {
null
} else {
Autocomplete.CreditCard.Builder()
.guid(it.guid)
.name(it.billingName)
.number(plaintextCardNumber)
.expirationMonth(it.expiryMonth.toString())
.expirationYear(it.expiryYear.toString())
.build()
}
}
.toTypedArray()
result.complete(creditCards)
}
return result
}
override fun onCreditCardSave(creditCard: Autocomplete.CreditCard) {
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(IO) {
creditCardsAddressesStorageDelegate.onCreditCardSave(creditCard.toCreditCardEntry())
}
}
override fun onLoginSave(login: Autocomplete.LoginEntry) {
loginStorageDelegate.onLoginSave(login.toLoginEntry())
}
override fun onLoginFetch(domain: String): GeckoResult<Array<Autocomplete.LoginEntry>> {
val result = GeckoResult<Array<Autocomplete.LoginEntry>>()
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(IO) {
val storedLogins = loginStorageDelegate.onLoginFetch(domain)
val logins = storedLogins.await()
.map { it.toLoginEntry() }
.toTypedArray()
result.complete(logins)
}
return result
}
}

View file

@ -0,0 +1,20 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.content.blocking
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission
/**
* Represents a site that will be ignored by the tracking protection policies.
* @property url The url of the site to be ignored.
* @property privateMode Indicates if this exception should persisted in private mode.
* @property contentPermission The associated gecko content permission of this exception.
*/
data class GeckoTrackingProtectionException(
override val url: String,
val privateMode: Boolean = false,
val contentPermission: ContentPermission,
) : TrackingProtectionException

View file

@ -0,0 +1,128 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.cookiebanners
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import mozilla.components.browser.engine.gecko.await
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.DISABLED
import mozilla.components.concept.engine.cookiehandling.CookieBannersStorage
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.StorageController
/**
* A storage to store [CookieBannerHandlingMode] using GeckoView APIs.
*/
class GeckoCookieBannersStorage(
runtime: GeckoRuntime,
private val reportSiteDomainsRepository: ReportSiteDomainsRepository,
) : CookieBannersStorage {
private val geckoStorage: StorageController = runtime.storageController
private val mainScope = CoroutineScope(Dispatchers.Main)
override suspend fun addException(
uri: String,
privateBrowsing: Boolean,
) {
setGeckoException(uri, DISABLED, privateBrowsing)
}
override suspend fun isSiteDomainReported(siteDomain: String): Boolean {
return reportSiteDomainsRepository.isSiteDomainReported(siteDomain)
}
override suspend fun saveSiteDomain(siteDomain: String) {
reportSiteDomainsRepository.saveSiteDomain(siteDomain)
}
override suspend fun addPersistentExceptionInPrivateMode(uri: String) {
setPersistentPrivateGeckoException(uri, DISABLED)
}
override suspend fun findExceptionFor(
uri: String,
privateBrowsing: Boolean,
): CookieBannerHandlingMode? {
return queryExceptionInGecko(uri, privateBrowsing)
}
override suspend fun hasException(uri: String, privateBrowsing: Boolean): Boolean? {
val result = findExceptionFor(uri, privateBrowsing)
return if (result != null) {
result == DISABLED
} else {
null
}
}
override suspend fun removeException(uri: String, privateBrowsing: Boolean) {
removeGeckoException(uri, privateBrowsing)
}
@VisibleForTesting
internal fun removeGeckoException(uri: String, privateBrowsing: Boolean) {
geckoStorage.removeCookieBannerModeForDomain(uri, privateBrowsing)
}
@VisibleForTesting
internal fun setGeckoException(
uri: String,
mode: CookieBannerHandlingMode,
privateBrowsing: Boolean,
) {
geckoStorage.setCookieBannerModeForDomain(
uri,
mode.mode,
privateBrowsing,
)
}
@VisibleForTesting
internal fun setPersistentPrivateGeckoException(
uri: String,
mode: CookieBannerHandlingMode,
) {
geckoStorage.setCookieBannerModeAndPersistInPrivateBrowsingForDomain(
uri,
mode.mode,
)
}
@VisibleForTesting
@Suppress("TooGenericExceptionCaught")
internal suspend fun queryExceptionInGecko(
uri: String,
privateBrowsing: Boolean,
): CookieBannerHandlingMode? {
return try {
withContext(mainScope.coroutineContext) {
geckoStorage.getCookieBannerModeForDomain(uri, privateBrowsing).await()
?.toCookieBannerHandlingMode() ?: throw IllegalArgumentException(
"An error happened trying to find cookie banners mode for the " +
"uri $uri and private browsing mode $privateBrowsing",
)
}
} catch (e: Exception) {
// This normally happen on internal sites like about:config or ip sites.
val disabledErrors = listOf("NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS", "NS_ERROR_HOST_IS_IP_ADDRESS")
if (disabledErrors.any { (e.message ?: "").contains(it) }) {
Logger("GeckoCookieBannersStorage").error("Unable to query cookie banners exception", e)
null
} else {
throw e
}
}
}
}
@VisibleForTesting
internal fun Int.toCookieBannerHandlingMode(): CookieBannerHandlingMode {
return CookieBannerHandlingMode.values().first { it.mode == this }
}

View file

@ -0,0 +1,75 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.cookiebanners
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.stringPreferencesKey
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import mozilla.components.browser.engine.gecko.cookiebanners.ReportSiteDomainsRepository.PreferencesKeys.REPORT_SITE_DOMAINS
import mozilla.components.support.base.log.logger.Logger
import java.io.IOException
/**
* A repository to save reported site domains with the datastore API.
*/
class ReportSiteDomainsRepository(
private val dataStore: DataStore<Preferences>,
) {
companion object {
const val SEPARATOR = "@<;>@"
const val REPORT_SITE_DOMAINS_REPOSITORY_NAME = "report_site_domains_preferences"
const val PREFERENCE_KEY_NAME = "report_site_domains"
}
private object PreferencesKeys {
val REPORT_SITE_DOMAINS = stringPreferencesKey(PREFERENCE_KEY_NAME)
}
/**
* Check if the given site's domain url is saved locally.
* @param siteDomain the [siteDomain] that will be checked.
*/
suspend fun isSiteDomainReported(siteDomain: String): Boolean {
return dataStore.data
.catch { exception ->
if (exception is IOException) {
Logger.error("Error reading preferences.", exception)
emit(emptyPreferences())
} else {
throw exception
}
}.map { preferences ->
val reportSiteDomainsString = preferences[REPORT_SITE_DOMAINS] ?: ""
val reportSiteDomainsList =
reportSiteDomainsString.split(SEPARATOR).filter { it.isNotEmpty() }
reportSiteDomainsList.contains(siteDomain)
}.first()
}
/**
* Save the given site's domain url in datastore to keep it persistent locally.
* This method gets called after the site domain was reported with Nimbus.
* @param siteDomain the [siteDomain] that will be saved.
*/
suspend fun saveSiteDomain(siteDomain: String) {
dataStore.edit { preferences ->
val siteDomainsPreferences = preferences[REPORT_SITE_DOMAINS] ?: ""
val siteDomainsList = siteDomainsPreferences.split(SEPARATOR).filter { it.isNotEmpty() }
if (siteDomainsList.contains(siteDomain)) {
return@edit
}
val domains = mutableListOf<String>()
domains.addAll(siteDomainsList)
domains.add(siteDomain)
preferences[REPORT_SITE_DOMAINS] = domains.joinToString(SEPARATOR)
}
}
}

View file

@ -0,0 +1,42 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.ext
import mozilla.components.concept.storage.Address
import org.mozilla.geckoview.Autocomplete
/**
* Converts a GeckoView [Autocomplete.Address] to an Android Components [Address].
*/
fun Autocomplete.Address.toAddress() = Address(
guid = guid ?: "",
name = name,
organization = organization,
streetAddress = streetAddress,
addressLevel3 = addressLevel3,
addressLevel2 = addressLevel2,
addressLevel1 = addressLevel1,
postalCode = postalCode,
country = country,
tel = tel,
email = email,
)
/**
* Converts an Android Components [Address] to a GeckoView [Autocomplete.Address].
*/
fun Address.toAutocompleteAddress() = Autocomplete.Address.Builder()
.guid(guid)
.name(name)
.organization(organization)
.streetAddress(streetAddress)
.addressLevel3(addressLevel3)
.addressLevel2(addressLevel2)
.addressLevel1(addressLevel1)
.postalCode(postalCode)
.country(country)
.tel(tel)
.email(email)
.build()

View file

@ -0,0 +1,32 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.ext
import mozilla.components.concept.storage.CreditCardEntry
import mozilla.components.support.utils.creditCardIIN
import org.mozilla.geckoview.Autocomplete
/**
* Converts a GeckoView [Autocomplete.CreditCard] to an Android Components [CreditCardEntry].
*/
fun Autocomplete.CreditCard.toCreditCardEntry() = CreditCardEntry(
guid = guid,
name = name,
number = number,
expiryMonth = expirationMonth,
expiryYear = expirationYear,
cardType = number.creditCardIIN()?.creditCardIssuerNetwork?.name ?: "",
)
/**
* Converts an Android Components [CreditCardEntry] to a GeckoView [Autocomplete.CreditCard].
*/
fun CreditCardEntry.toAutocompleteCreditCard() = Autocomplete.CreditCard.Builder()
.guid(guid)
.name(name)
.number(number)
.expirationMonth(expiryMonth)
.expirationYear(expiryYear)
.build()

View file

@ -0,0 +1,31 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.ext
import mozilla.components.browser.engine.gecko.prompt.GeckoChoice
import mozilla.components.concept.engine.prompt.Choice
/**
* Converts a GeckoView [GeckoChoice] to an Android Components [Choice].
*/
private fun GeckoChoice.toChoice(): Choice {
val choiceChildren = items?.map { it.toChoice() }?.toTypedArray()
// On the GeckoView docs states that label is a @NonNull, but on run-time
// we are getting null values
// https://bugzilla.mozilla.org/show_bug.cgi?id=1771149
@Suppress("USELESS_ELVIS")
return Choice(id, !disabled, label ?: "", selected, separator, choiceChildren)
}
/**
* Convert an array of [GeckoChoice] to Choice array.
* @return array of Choice
*/
fun convertToChoices(
geckoChoices: Array<out GeckoChoice>,
): Array<Choice> = geckoChoices.map { geckoChoice ->
val choice = geckoChoice.toChoice()
choice
}.toTypedArray()

View file

@ -0,0 +1,25 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.ext
import mozilla.components.browser.engine.gecko.GeckoEngineSession
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_TRACKING
/**
* Indicates if this Gecko permission is a tracking protection permission and it is excluded
* from the tracking protection policies.
*/
val ContentPermission.isExcludedForTrackingProtection: Boolean
get() = this.permission == PERMISSION_TRACKING &&
value == VALUE_ALLOW
/**
* Provides the tracking protection permission for the given [GeckoEngineSession].
* This is available after every onLocationChange call.
*/
val GeckoEngineSession.geckoTrackingProtectionPermission: ContentPermission?
get() = this.geckoPermissions.find { it.permission == PERMISSION_TRACKING }

View file

@ -0,0 +1,43 @@
/* 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/. */
package mozilla.components.browser.engine.gecko.ext
import mozilla.components.concept.storage.Login
import mozilla.components.concept.storage.LoginEntry
import org.mozilla.geckoview.Autocomplete
/**
* Converts a GeckoView [Autocomplete.LoginEntry] to an Android Components [LoginEntry].
*/
fun Autocomplete.LoginEntry.toLoginEntry() = LoginEntry(
origin = origin,
formActionOrigin = formActionOrigin,
httpRealm = httpRealm,
username = username,
password = password,
)
/**
* Converts an Android Components [Login] to a GeckoView [Autocomplete.LoginEntry].
*/
fun Login.toLoginEntry() = Autocomplete.LoginEntry.Builder()
.guid(guid)
.origin(origin)
.formActionOrigin(formActionOrigin)
.httpRealm(httpRealm)
.username(username)
.password(password)
.build()
/**
* Converts an Android Components [LoginEntry] to a GeckoView [Autocomplete.LoginEntry].
*/
fun LoginEntry.toLoginEntry() = Autocomplete.LoginEntry.Builder()
.origin(origin)
.formActionOrigin(formActionOrigin)
.httpRealm(httpRealm)
.username(username)
.password(password)
.build()

Some files were not shown because too many files have changed in this diff Show more