Skip to content

Commit 5aa53e5

Browse files
committed
Initial Commit
0 parents  commit 5aa53e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2493
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.iml
2+
.idea
3+
.gradle
4+
/local.properties
5+
/.idea/caches
6+
/.idea/libraries
7+
/.idea/modules.xml
8+
/.idea/workspace.xml
9+
/.idea/navEditor.xml
10+
/.idea/assetWizardSettings.xml
11+
.DS_Store
12+
/build
13+
/captures
14+
.externalNativeBuild
15+
.cxx
16+
local.properties
17+
**/env
18+
OpacityCore/src/main/jniLibs
19+

OpacityCore/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

OpacityCore/build.gradle

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'maven-publish'
5+
}
6+
7+
android {
8+
namespace 'com.opacitylabs.opacitycore'
9+
compileSdk 34
10+
11+
defaultConfig {
12+
minSdk 24
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
consumerProguardFiles "consumer-rules.pro"
16+
externalNativeBuild {
17+
cmake {
18+
cppFlags ''
19+
}
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
minifyEnabled false
26+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27+
}
28+
}
29+
30+
compileOptions {
31+
sourceCompatibility JavaVersion.VERSION_1_8
32+
targetCompatibility JavaVersion.VERSION_1_8
33+
}
34+
35+
kotlinOptions {
36+
jvmTarget = '1.8'
37+
}
38+
39+
externalNativeBuild {
40+
cmake {
41+
path file('src/main/cpp/CMakeLists.txt')
42+
version '3.22.1'
43+
}
44+
}
45+
46+
publishing {
47+
singleVariant("release") {
48+
withSourcesJar()
49+
}
50+
}
51+
}
52+
53+
dependencies {
54+
implementation libs.androidx.core.ktx
55+
implementation libs.androidx.appcompat
56+
implementation libs.material
57+
implementation libs.geckoview.nightly
58+
implementation libs.androidx.security.crypto
59+
testImplementation libs.junit
60+
androidTestImplementation libs.androidx.junit
61+
androidTestImplementation libs.androidx.espresso.core
62+
}
63+
64+
publishing {
65+
publications {
66+
release(MavenPublication) {
67+
groupId = 'com.opacitylabs'
68+
artifactId = 'opacitycore'
69+
version = '3.23.13'
70+
71+
afterEvaluate {
72+
from components.release
73+
}
74+
}
75+
}
76+
}

OpacityCore/consumer-rules.pro

Whitespace-only changes.

OpacityCore/proguard-rules.pro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
22+
-keep class com.opacitylabs.opacitycore.OpacityResponse { *; }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
</manifest>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
browser.webRequest.onHeadersReceived.addListener(
2+
function (details) {
3+
let cookiesHeaders = details.responseHeaders.filter(
4+
(header) => header.name.toLowerCase() === "set-cookie"
5+
);
6+
7+
if (cookiesHeaders.length === 0) {
8+
return;
9+
}
10+
11+
let cookies = cookiesHeaders[0].value;
12+
13+
if (!cookies) {
14+
return;
15+
}
16+
17+
// cookies is a single string, e.g. "sampleCookie=sampleValue; Path=\/\nsampleCookie2=sampleValue2; Path=\/"
18+
// We need to split and parse it to a single dictionary
19+
20+
// Parse cookies
21+
let cookieDict = {};
22+
cookies.split("\n").forEach((cookie) => {
23+
let cookieParts = cookie.split(";")[0].split("=");
24+
let cookieName = cookieParts[0].trim();
25+
let cookieValue = cookieParts[1].trim();
26+
cookieDict[cookieName] = cookieValue;
27+
});
28+
29+
// Send cookies back to the app (GeckoView) via messaging
30+
browser.runtime.sendNativeMessage("gecko", {
31+
event: "cookies",
32+
cookies: cookieDict,
33+
});
34+
},
35+
{ urls: ["<all_urls>"] }, // Intercept all URLs
36+
["responseHeaders"]
37+
);
38+
39+
browser.webNavigation.onDOMContentLoaded.addListener(function (details) {
40+
if (details.frameId === 0) { // Ensure it's the top-level frame
41+
// Inject a script to fetch the outerHTML of the current document
42+
browser.tabs.executeScript(details.tabId, {
43+
code: "document.documentElement.outerHTML"
44+
}).then(result => {
45+
if (result && result.length > 0) {
46+
const htmlBody = result[0]; // The outerHTML of the page
47+
48+
// Send the HTML content and cookies to the native app
49+
browser.runtime.sendNativeMessage("gecko", {
50+
event: "html_body",
51+
html: htmlBody
52+
});
53+
54+
} else {
55+
browser.runtime.sendNativeMessage("gecko", {
56+
event: "No results when getting outerHTML",
57+
});
58+
}
59+
}).catch(err => {
60+
browser.runtime.sendNativeMessage("gecko", {
61+
event: "Execute script error: " + err.toString(),
62+
});
63+
})
64+
}
65+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Opacity Extension",
4+
"version": "1.0",
5+
"description": "Opacity extension for GeckoView",
6+
"applications": {
7+
"gecko": {
8+
9+
"strict_min_version": "68.0"
10+
}
11+
},
12+
"background": {
13+
"scripts": [
14+
"background.js"
15+
]
16+
},
17+
"permissions": [
18+
"webRequest",
19+
"activeTab",
20+
"tabs",
21+
"webRequestBlocking",
22+
"cookies",
23+
"*://*/*",
24+
"<all_urls>",
25+
"nativeMessaging",
26+
"nativeMessagingFromContent",
27+
"geckoViewAddons",
28+
"webNavigation",
29+
"scripting"
30+
]
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
cmake_minimum_required(VERSION 3.22.1)
3+
4+
project("OpacityCore")
5+
6+
set(OPACITY_CORE_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libopacity_core.a)
7+
add_library(opacity_core STATIC IMPORTED)
8+
set_target_properties(opacity_core PROPERTIES IMPORTED_LOCATION ${OPACITY_CORE_LIB})
9+
10+
add_library(${CMAKE_PROJECT_NAME} SHARED
11+
# List C/C++ source files with relative paths to this CMakeLists.txt.
12+
OpacityCore.cpp)
13+
14+
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/../jni/include)
15+
16+
target_link_libraries(${CMAKE_PROJECT_NAME}
17+
opacity_core
18+
android
19+
log)

0 commit comments

Comments
 (0)