Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: load url from Intent, plus fixed some warnings #32160

Merged
merged 7 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
/android-toolchains
/target
/tests/wpt/reftests-report/report.html
/ports/android/bin
/ports/android/libs
/ports/android/local.properties
/ports/android/obj
/python/_virtualenv*
/python/_venv*
/python/tidy/servo_tidy.egg-info
Expand Down
3 changes: 2 additions & 1 deletion ports/jniapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub extern "C" fn Java_org_mozilla_servoview_JNIServo_init(
callbacks_obj: JObject,
surface: JObject,
) {
let (mut opts, log, log_str, _gst_debug_str) = match get_options(&env, opts, surface) {
let (opts, log, log_str, _gst_debug_str) = match get_options(&env, opts, surface) {
Ok((opts, log, log_str, gst_debug_str)) => (opts, log, log_str, gst_debug_str),
Err(err) => {
throw(&env, &err);
Expand Down Expand Up @@ -875,6 +875,7 @@ fn get_options(

let opts = InitOptions {
args: args.unwrap_or(vec![]),
url,
coordinates,
density,
xr_discovery: None,
Expand Down
4 changes: 3 additions & 1 deletion ports/jniapi/src/simpleservo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub use servo::embedder_traits::EventLoopWaker;

pub struct InitOptions {
pub args: Vec<String>,
pub url: Option<String>,
pub coordinates: Coordinates,
pub density: f32,
pub xr_discovery: Option<webxr::Discovery>,
Expand Down Expand Up @@ -253,10 +254,11 @@ pub fn init(
args.insert(0, "servo".to_string());
opts::from_cmdline_args(Options::new(), &args);

let embedder_url = init_opts.url.as_ref().and_then(|s| ServoUrl::parse(s).ok());
let pref_url = ServoUrl::parse(&pref!(shell.homepage)).ok();
let blank_url = ServoUrl::parse("about:blank").ok();

let url = pref_url.or(blank_url).unwrap();
let url = embedder_url.or(pref_url).or(blank_url).unwrap();

gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(gl::COLOR_BUFFER_BIT);
Expand Down
1 change: 1 addition & 0 deletions support/android/apk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/gen/
/libs/
/local.properties
/obj/
/proguard-project.txt
12 changes: 6 additions & 6 deletions support/android/apk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ ext.getJniLibsPath = { boolean debug, String arch ->

ext.getRustTarget = { String arch ->
switch (arch.toLowerCase()) {
case 'armv7' : return 'armv7-linux-androideabi'
case 'arm64' : return 'aarch64-linux-android'
case 'armv7': return 'armv7-linux-androideabi'
case 'arm64': return 'aarch64-linux-android'
case 'x86': return 'i686-linux-android'
case 'x64': return 'x86_64-linux-android'
default: throw new GradleException("Invalid target architecture " + arch)
Expand All @@ -35,8 +35,8 @@ ext.getRustTarget = { String arch ->

ext.getNDKAbi = { String arch ->
switch (arch.toLowerCase()) {
case 'armv7' : return 'armeabi-v7a'
case 'arm64' : return 'arm64-v8a'
case 'armv7': return 'armeabi-v7a'
case 'arm64': return 'arm64-v8a'
case 'x86': return 'x86'
case 'x64': return 'x86_64'
default: throw new GradleException("Invalid target architecture " + arch)
Expand All @@ -60,8 +60,8 @@ ext.getNdkDir = { ->

def ndkDir = ndkRoot != null ? new File(ndkRoot) : null
if (!ndkDir || !ndkDir.exists()) {
throw new GradleException("Please set a valid ANDROID_NDK_ROOT environment variable" +
"or ndk.dir path in local.properties file");
throw new GradleException("Please set a valid ANDROID_NDK_ROOT environment variable " +
"or ndk.dir path in local.properties file")
}
return ndkDir.absolutePath
}
8 changes: 4 additions & 4 deletions support/android/apk/servoapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.regex.Pattern

android {
compileSdk 33
buildToolsVersion "33.0.2"
buildToolsVersion = "33.0.2"

namespace 'org.mozilla.servo'

Expand All @@ -27,7 +27,7 @@ android {
}

// Share all of that with servoview
flavorDimensions "default"
flavorDimensions = ["default"]

productFlavors {
basic {
Expand Down Expand Up @@ -113,8 +113,8 @@ android {

// Ignore default 'debug' and 'release' build types
variantFilter { variant ->
if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
if(variant.buildType.name == 'release' || variant.buildType.name == 'debug') {
variant.setIgnore(true)
}
}

Expand Down
6 changes: 2 additions & 4 deletions support/android/apk/servoapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">

<uses-feature android:glEsVersion="0x00030000" android:required="true" />
Expand All @@ -12,8 +11,8 @@

<application android:label="Servo" android:icon="@mipmap/servo">
<activity android:name=".MainActivity"
android:label="Servo"
android:configChanges="density|keyboardHidden|navigation|orientation|screenSize|uiMode">
android:configChanges="density|keyboardHidden|navigation|orientation|screenSize|uiMode"
android:exported="true">
<meta-data android:name="android.app.lib_name" android:value="servo" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -45,4 +44,3 @@
</application>

</manifest>
<!-- END_INCLUDE(manifest) -->
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.os.Bundle;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -21,11 +22,9 @@
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.util.Log;

import org.mozilla.servo.MediaSession;
import org.mozilla.servoview.ServoView;
import org.mozilla.servoview.Servo;
import org.mozilla.servoview.ServoView;

import java.io.File;

Expand Down Expand Up @@ -65,16 +64,15 @@ protected void onCreate(Bundle savedInstanceState) {
mServoView.setClient(this);
mServoView.requestFocus();

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
File sdcard = getExternalFilesDir("");
String host = sdcard.toPath().resolve("android_hosts").toString();
try {
File sdcard = getExternalFilesDir("");
String host = sdcard.toPath().resolve("android_hosts").toString();
try {
Os.setenv("HOST_FILE", host, false);
} catch (ErrnoException e) {
} catch (ErrnoException e) {
e.printStackTrace();
}
}


Intent intent = getIntent();
String args = intent.getStringExtra("servoargs");
String log = intent.getStringExtra("servolog");
Expand Down Expand Up @@ -253,7 +251,6 @@ public void onMediaSessionPlaybackStateChange(int state) {
if (state == MediaSession.PLAYBACK_STATE_PLAYING ||
state == MediaSession.PLAYBACK_STATE_PAUSED) {
mMediaSession.showMediaSessionControls();
return;
}
}

Expand All @@ -265,6 +262,5 @@ public void onMediaSessionSetPositionState(float duration, float position, float
}

mMediaSession.setPositionState(duration, position, playbackRate);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.mozilla.servo;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand Down Expand Up @@ -124,7 +123,7 @@ public void onReceive(Context context, Intent intent) {

mContext.registerReceiver(mMediaSessionActionReceiver, filter);

Notification.Builder builder = new Notification.Builder(mContext, this.MEDIA_CHANNEL_ID);
Notification.Builder builder = new Notification.Builder(mContext, MEDIA_CHANNEL_ID);
builder
.setSmallIcon(R.drawable.media_session_icon)
.setContentTitle(mTitle)
Expand Down
22 changes: 11 additions & 11 deletions support/android/apk/servoview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.regex.Pattern

android {
compileSdk 33
buildToolsVersion "33.0.2"
Gae24 marked this conversation as resolved.
Show resolved Hide resolved
buildToolsVersion = "33.0.2"

namespace 'org.mozilla.servoview'

Expand All @@ -28,7 +28,7 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

flavorDimensions "default"
flavorDimensions = ["default"]

productFlavors {
basic {
Expand Down Expand Up @@ -115,8 +115,8 @@ android {

// Ignore default 'debug' and 'release' build types
variantFilter { variant ->
if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
if(variant.buildType.name == 'release' || variant.buildType.name == 'debug') {
variant.setIgnore(true)
}
}

Expand All @@ -140,7 +140,7 @@ android {
tasks.all {
compileTask ->
// This matches the task `mergeBasicArmv7DebugJniLibFolders`.
Pattern pattern = Pattern.compile(/^merge[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)JniLibFolders/)
Pattern pattern = Pattern.compile(/^merge[A-Z]\w+([A-Z]\w+)(Debug|Release)JniLibFolders/)
Matcher matcher = pattern.matcher(compileTask.name)
if (!matcher.find()) {
return
Expand Down Expand Up @@ -217,7 +217,7 @@ dependencies {

// folderFilter can be used to improve search performance
static String findDependencyPath(String basePath, String filename, String folderFilter) {
File path = new File(basePath);
File path = new File(basePath)
if (!path.exists()) {
return ''
}
Expand All @@ -231,7 +231,7 @@ static String findDependencyPath(String basePath, String filename, String folder
}
def result = ''
path.eachFileRecurse(FileType.FILES) {
if(it.name.equals(filename)) {
if(it.name == filename) {
result = it.absolutePath
}
}
Expand All @@ -241,9 +241,9 @@ static String findDependencyPath(String basePath, String filename, String folder

class ServoDependency {
ServoDependency(String fileName, String folderFilter = null) {
this.fileName = fileName;
this.folderFilter = folderFilter;
this.fileName = fileName
this.folderFilter = folderFilter
}
public String fileName;
public String folderFilter;
public String fileName
public String folderFilter
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
package org.mozilla.servoview;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Surface;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

import org.freedesktop.gstreamer.GStreamer;
import org.mozilla.servoview.JNIServo.ServoCoordinates;
import org.mozilla.servoview.JNIServo.ServoOptions;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class Servo {
private static final String LOGTAG = "Servo";
private JNIServo mJNI = new JNIServo();
Expand All @@ -38,9 +35,7 @@ public Servo(

mServoCallbacks = new Callbacks(client, gfxcb);

mRunCallback.inGLThread(() -> {
mJNI.init(activity, options, mServoCallbacks, surface);
});
mRunCallback.inGLThread(() -> mJNI.init(activity, options, mServoCallbacks, surface));
}

public void resetGfxCallbacks(GfxCallbacks gfxcb) {
Expand All @@ -49,7 +44,7 @@ public void resetGfxCallbacks(GfxCallbacks gfxcb) {

public void shutdown() {
mShuttingDown = true;
FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() {
FutureTask<Void> task = new FutureTask<>(new Callable<Void>() {
public Void call() throws Exception {
mJNI.requestShutdown();
// Wait until Servo gets back to us to finalize shutdown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.widget.OverScroller;

import java.util.ArrayList;
Expand Down Expand Up @@ -78,7 +79,7 @@ private void init(Context context) {
setFocusable(true);
setFocusableInTouchMode(true);
setClickable(true);
ArrayList view = new ArrayList();
ArrayList<View> view = new ArrayList<>();
view.add(this);
addTouchables(view);
setWillNotCacheDrawing(false);
Expand All @@ -89,7 +90,6 @@ private void init(Context context) {
mGLThread.start();
}


public void setClient(Client client) {
mClient = client;
}
Expand All @@ -99,7 +99,6 @@ public void setServoArgs(String args, String log) {
mServoLog = log;
}


// RunCallback
public void inGLThread(Runnable r) {
mGLLooperHandler.post(r);
Expand Down Expand Up @@ -212,18 +211,14 @@ public void stop() {
mServo.stop();
}

public void loadUri(String uri) {
public void loadUri(Uri uri) {
if (mServo != null) {
mServo.loadUri(uri);
mServo.loadUri(uri.toString());
} else {
mInitialUri = uri;
mInitialUri = uri.toString();
}
}

public void loadUri(Uri uri) {
loadUri(uri.toString());
}

public void scrollStart(int dx, int dy, int x, int y) {
mServo.scrollStart(dx, dy, x, y);
}
Expand Down Expand Up @@ -373,6 +368,7 @@ public void surfaceCreated(SurfaceHolder holder) {
Surface surface = holder.getSurface();
ServoOptions options = new ServoOptions();
options.args = mServoView.mServoArgs;
options.url = mServoView.mInitialUri;
options.coordinates = coords;
options.enableLogs = true;
options.enableSubpixelTextAntialiasing = true;
Expand Down