forked from youtube/cobalt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Java impls for Cobalt's Mojo interfaces (youtube#4909)
A Java implementation for the CrashAnnotator interface is added as an example. It is still stubbed, but now in Java; a quick follow-up will implement it using StarboardBridge.setCrashContext. The Mojo Java Bindings API doc was used as a reference. b/383301493
- Loading branch information
1 parent
ab26b08
commit dc0f4c3
Showing
14 changed files
with
276 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
cobalt/android/apk/app/src/main/java/dev/cobalt/browser/CobaltInterfaceRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dev.cobalt.browser; | ||
|
||
import dev.cobalt.browser.crashannotator.CrashAnnotatorImplFactory; | ||
import org.chromium.base.annotations.CalledByNative; | ||
import org.chromium.content_public.browser.InterfaceRegistrar; | ||
import org.chromium.content_public.browser.RenderFrameHost; | ||
import org.chromium.crashannotator.mojom.CrashAnnotator; | ||
import org.chromium.services.service_manager.InterfaceRegistry; | ||
|
||
/** Registers Mojo interface implementations exposed to C++ code at the Cobalt layer. */ | ||
class CobaltInterfaceRegistrar { | ||
@CalledByNative | ||
private static void registerMojoInterfaces() { | ||
InterfaceRegistrar.Registry.addRenderFrameHostRegistrar( | ||
new CobaltRenderFrameHostInterfaceRegistrar()); | ||
} | ||
|
||
private static class CobaltRenderFrameHostInterfaceRegistrar | ||
implements InterfaceRegistrar<RenderFrameHost> { | ||
@Override | ||
public void registerInterfaces( | ||
InterfaceRegistry registry, | ||
final RenderFrameHost renderFrameHost) { | ||
registry.addInterface( | ||
CrashAnnotator.MANAGER, | ||
new CrashAnnotatorImplFactory(renderFrameHost)); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...t/android/apk/app/src/main/java/dev/cobalt/browser/crashannotator/CrashAnnotatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dev.cobalt.browser.crashannotator; | ||
|
||
import static dev.cobalt.util.Log.TAG; | ||
|
||
import dev.cobalt.util.Log; | ||
import org.chromium.content_public.browser.RenderFrameHost; | ||
import org.chromium.crashannotator.mojom.CrashAnnotator; | ||
import org.chromium.mojo.system.MojoException; | ||
|
||
/** Implements the CrashAnnotator Mojo interface in Java. */ | ||
public class CrashAnnotatorImpl implements CrashAnnotator { | ||
// TODO(cobalt, b/383301493): confirm that this member is needed for proper | ||
// lifetime management. | ||
private final RenderFrameHost mRenderFrameHost; | ||
|
||
public CrashAnnotatorImpl(RenderFrameHost renderFrameHost) { | ||
mRenderFrameHost = renderFrameHost; | ||
} | ||
|
||
@Override | ||
public void setString(String key, | ||
String value, | ||
SetString_Response callback) { | ||
// TODO(cobalt, b/383301493): actually implement this by calling | ||
// StarboardBridge.setCrashContext(). | ||
Log.i(TAG, "Java CrashAnnotator impl key=%s value=%s", key, value); | ||
callback.call(false); | ||
} | ||
|
||
/** This abstract method must be overridden. */ | ||
@Override | ||
public void close() {} | ||
|
||
/** This abstract method must be overridden. */ | ||
@Override | ||
public void onConnectionError(MojoException e) {} | ||
} |
33 changes: 33 additions & 0 deletions
33
...id/apk/app/src/main/java/dev/cobalt/browser/crashannotator/CrashAnnotatorImplFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dev.cobalt.browser.crashannotator; | ||
|
||
import org.chromium.content_public.browser.RenderFrameHost; | ||
import org.chromium.crashannotator.mojom.CrashAnnotator; | ||
import org.chromium.services.service_manager.InterfaceFactory; | ||
|
||
/** Creates instances of CrashAnnotator Mojo interface implementations. */ | ||
public class CrashAnnotatorImplFactory implements InterfaceFactory { | ||
private final RenderFrameHost mRenderFrameHost; | ||
|
||
public CrashAnnotatorImplFactory(RenderFrameHost renderFrameHost) { | ||
mRenderFrameHost = renderFrameHost; | ||
} | ||
|
||
@Override | ||
public CrashAnnotator createImpl() { | ||
return new CrashAnnotatorImpl(mRenderFrameHost); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
cobalt/browser/android/mojo/cobalt_interface_registrar_android.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "cobalt/browser/android/mojo/cobalt_interface_registrar_android.h" | ||
|
||
#include <jni.h> | ||
|
||
#include "base/android/jni_android.h" | ||
|
||
// Must come after all headers that specialize FromJniType() / ToJniType(). | ||
#include "cobalt/android/jni_headers/CobaltInterfaceRegistrar_jni.h" | ||
|
||
namespace cobalt { | ||
|
||
void RegisterCobaltJavaMojoInterfaces() { | ||
Java_CobaltInterfaceRegistrar_registerMojoInterfaces( | ||
base::android::AttachCurrentThread()); | ||
} | ||
|
||
} // namespace cobalt |
25 changes: 25 additions & 0 deletions
25
cobalt/browser/android/mojo/cobalt_interface_registrar_android.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2025 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef COBALT_BROWSER_ANDROID_MOJO_COBALT_INTERFACE_REGISTRAR_ANDROID_H_ | ||
#define COBALT_BROWSER_ANDROID_MOJO_COBALT_INTERFACE_REGISTRAR_ANDROID_H_ | ||
|
||
namespace cobalt { | ||
|
||
// Registers Cobalt's Java Mojo interfaces with its independent registrar. | ||
void RegisterCobaltJavaMojoInterfaces(); | ||
|
||
} // namespace cobalt | ||
|
||
#endif // COBALT_BROWSER_ANDROID_MOJO_COBALT_INTERFACE_REGISTRAR_ANDROID_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters