Commit 7bb24389 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: adds @NonNull/@Nullable to public API

I only added this to the public API as that is the important
part.

BUG=none
TEST=none

Change-Id: I2369ea07fcac9e3bb87632f6235f11e37d5283a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874587
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708402}
parent a177fe08
...@@ -44,6 +44,7 @@ template("weblayer_java") { ...@@ -44,6 +44,7 @@ template("weblayer_java") {
deps = [ deps = [
":weblayer_client_manifest", ":weblayer_client_manifest",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:com_android_support_support_fragment_java", "//third_party/android_deps:com_android_support_support_fragment_java",
"//weblayer/browser/java:client_java", "//weblayer/browser/java:client_java",
] ]
......
...@@ -8,6 +8,9 @@ import android.net.Uri; ...@@ -8,6 +8,9 @@ import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -19,6 +22,10 @@ import org.chromium.weblayer_private.aidl.IFullscreenDelegateClient; ...@@ -19,6 +22,10 @@ import org.chromium.weblayer_private.aidl.IFullscreenDelegateClient;
import org.chromium.weblayer_private.aidl.IObjectWrapper; import org.chromium.weblayer_private.aidl.IObjectWrapper;
import org.chromium.weblayer_private.aidl.ObjectWrapper; import org.chromium.weblayer_private.aidl.ObjectWrapper;
/**
* Represents a web-browser. More specifically, owns a NavigationController, and allows configuring
* state of the browser, such as delegates and observers.
*/
public final class BrowserController { public final class BrowserController {
/** The top level key of the JSON object returned by executeScript(). */ /** The top level key of the JSON object returned by executeScript(). */
public static final String SCRIPT_RESULT_KEY = "result"; public static final String SCRIPT_RESULT_KEY = "result";
...@@ -41,7 +48,7 @@ public final class BrowserController { ...@@ -41,7 +48,7 @@ public final class BrowserController {
mNavigationController = NavigationController.create(mImpl); mNavigationController = NavigationController.create(mImpl);
} }
public void setDownloadDelegate(DownloadDelegate delegate) { public void setDownloadDelegate(@Nullable DownloadDelegate delegate) {
try { try {
if (delegate != null) { if (delegate != null) {
mDownloadDelegateClient = new DownloadDelegateClientImpl(delegate); mDownloadDelegateClient = new DownloadDelegateClientImpl(delegate);
...@@ -55,7 +62,7 @@ public final class BrowserController { ...@@ -55,7 +62,7 @@ public final class BrowserController {
} }
} }
public void setFullscreenDelegate(FullscreenDelegate delegate) { public void setFullscreenDelegate(@Nullable FullscreenDelegate delegate) {
try { try {
if (delegate != null) { if (delegate != null) {
mFullscreenDelegateClient = new FullscreenDelegateClientImpl(delegate); mFullscreenDelegateClient = new FullscreenDelegateClientImpl(delegate);
...@@ -78,7 +85,8 @@ public final class BrowserController { ...@@ -78,7 +85,8 @@ public final class BrowserController {
* callback if provided. The object passed to the callback will have a single key * callback if provided. The object passed to the callback will have a single key
* SCRIPT_RESULT_KEY which will hold the result of running the script. * SCRIPT_RESULT_KEY which will hold the result of running the script.
*/ */
public void executeScript(String script, ValueCallback<JSONObject> callback) { public void executeScript(
@NonNull String script, @Nullable ValueCallback<JSONObject> callback) {
try { try {
ValueCallback<String> stringCallback = (String result) -> { ValueCallback<String> stringCallback = (String result) -> {
if (callback == null) { if (callback == null) {
...@@ -99,6 +107,7 @@ public final class BrowserController { ...@@ -99,6 +107,7 @@ public final class BrowserController {
} }
} }
@Nullable
public FullscreenDelegate getFullscreenDelegate() { public FullscreenDelegate getFullscreenDelegate() {
return mFullscreenDelegateClient != null ? mFullscreenDelegateClient.getDelegate() : null; return mFullscreenDelegateClient != null ? mFullscreenDelegateClient.getDelegate() : null;
} }
...@@ -108,15 +117,16 @@ public final class BrowserController { ...@@ -108,15 +117,16 @@ public final class BrowserController {
// TODO(sky): figure out right assertion here if mProfile is non-null. // TODO(sky): figure out right assertion here if mProfile is non-null.
} }
@NonNull
public NavigationController getNavigationController() { public NavigationController getNavigationController() {
return mNavigationController; return mNavigationController;
} }
public void addObserver(BrowserObserver observer) { public void addObserver(@Nullable BrowserObserver observer) {
mObservers.addObserver(observer); mObservers.addObserver(observer);
} }
public void removeObserver(BrowserObserver observer) { public void removeObserver(@Nullable BrowserObserver observer) {
mObservers.removeObserver(observer); mObservers.removeObserver(observer);
} }
......
...@@ -16,6 +16,8 @@ import android.view.LayoutInflater; ...@@ -16,6 +16,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull;
import org.chromium.weblayer_private.aidl.APICallException; import org.chromium.weblayer_private.aidl.APICallException;
import org.chromium.weblayer_private.aidl.IBrowserFragment; import org.chromium.weblayer_private.aidl.IBrowserFragment;
import org.chromium.weblayer_private.aidl.IObjectWrapper; import org.chromium.weblayer_private.aidl.IObjectWrapper;
...@@ -149,6 +151,7 @@ public final class BrowserFragment extends Fragment { ...@@ -149,6 +151,7 @@ public final class BrowserFragment extends Fragment {
* Returns the {@link BrowserFragmentController} associated with this fragment. * Returns the {@link BrowserFragmentController} associated with this fragment.
* The controller is available only between BrowserFragment's onCreate() and onDestroy(). * The controller is available only between BrowserFragment's onCreate() and onDestroy().
*/ */
@NonNull
public BrowserFragmentController getController() { public BrowserFragmentController getController() {
if (mBrowserFragmentController == null) { if (mBrowserFragmentController == null) {
throw new RuntimeException("BrowserFragmentController is available only between " throw new RuntimeException("BrowserFragmentController is available only between "
......
...@@ -8,6 +8,9 @@ import android.os.RemoteException; ...@@ -8,6 +8,9 @@ import android.os.RemoteException;
import android.view.View; import android.view.View;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.chromium.weblayer_private.aidl.APICallException; import org.chromium.weblayer_private.aidl.APICallException;
import org.chromium.weblayer_private.aidl.IBrowserFragmentController; import org.chromium.weblayer_private.aidl.IBrowserFragmentController;
import org.chromium.weblayer_private.aidl.ObjectWrapper; import org.chromium.weblayer_private.aidl.ObjectWrapper;
...@@ -27,6 +30,7 @@ public final class BrowserFragmentController { ...@@ -27,6 +30,7 @@ public final class BrowserFragmentController {
} }
// TODO(pshmakov): rename this to BrowserTabController. // TODO(pshmakov): rename this to BrowserTabController.
@NonNull
public BrowserController getBrowserController() { public BrowserController getBrowserController() {
if (mController == null) { if (mController == null) {
try { try {
...@@ -38,7 +42,7 @@ public final class BrowserFragmentController { ...@@ -38,7 +42,7 @@ public final class BrowserFragmentController {
return mController; return mController;
} }
public void setTopView(View view) { public void setTopView(@Nullable View view) {
try { try {
mImpl.setTopView(ObjectWrapper.wrap(view)); mImpl.setTopView(ObjectWrapper.wrap(view));
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -55,6 +59,7 @@ public final class BrowserFragmentController { ...@@ -55,6 +59,7 @@ public final class BrowserFragmentController {
* @return a ListenableResult of whether the request succeeded. A request might fail if it is * @return a ListenableResult of whether the request succeeded. A request might fail if it is
* subsumed by a subsequent request, or if this object is destroyed. * subsumed by a subsequent request, or if this object is destroyed.
*/ */
@NonNull
public ListenableResult<Boolean> setSupportsEmbedding(boolean enable) { public ListenableResult<Boolean> setSupportsEmbedding(boolean enable) {
try { try {
final ListenableResult<Boolean> listenableResult = new ListenableResult<Boolean>(); final ListenableResult<Boolean> listenableResult = new ListenableResult<Boolean>();
...@@ -75,6 +80,7 @@ public final class BrowserFragmentController { ...@@ -75,6 +80,7 @@ public final class BrowserFragmentController {
* Returns {@link Profile} associated with this Browser Fragment. Multiple fragments can share * Returns {@link Profile} associated with this Browser Fragment. Multiple fragments can share
* the same Profile. * the same Profile.
*/ */
@NonNull
public Profile getProfile() { public Profile getProfile() {
try { try {
return mProfileManager.getProfileFor(mImpl.getProfile()); return mProfileManager.getProfileFor(mImpl.getProfile());
......
...@@ -6,6 +6,8 @@ package org.chromium.weblayer; ...@@ -6,6 +6,8 @@ package org.chromium.weblayer;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.NonNull;
/** /**
* Informed of interesting events that happen during the lifetime of a BrowserController. * Informed of interesting events that happen during the lifetime of a BrowserController.
*/ */
...@@ -15,7 +17,7 @@ public abstract class BrowserObserver { ...@@ -15,7 +17,7 @@ public abstract class BrowserObserver {
* *
* @param url The new user-visible url. * @param url The new user-visible url.
*/ */
public void visibleUrlChanged(Uri url) {} public void visibleUrlChanged(@NonNull Uri url) {}
/** /**
* The load state of the document has changed. * The load state of the document has changed.
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.weblayer; package org.chromium.weblayer;
import androidx.annotation.NonNull;
/** /**
* An interface that allows clients to handle download requests originating in the browser. * An interface that allows clients to handle download requests originating in the browser.
*/ */
...@@ -17,6 +19,6 @@ public abstract class DownloadDelegate { ...@@ -17,6 +19,6 @@ public abstract class DownloadDelegate {
* @param mimetype the mimetype of the content reported by the server * @param mimetype the mimetype of the content reported by the server
* @param contentLength the file size reported by the server * @param contentLength the file size reported by the server
*/ */
public abstract void downloadRequested(String url, String userAgent, String contentDisposition, public abstract void downloadRequested(@NonNull String url, @NonNull String userAgent,
String mimetype, long contentLength); @NonNull String contentDisposition, @NonNull String mimetype, long contentLength);
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.weblayer; package org.chromium.weblayer;
import androidx.annotation.NonNull;
/** /**
* Used to configure fullscreen related state. HTML fullscreen support is only enabled if a * Used to configure fullscreen related state. HTML fullscreen support is only enabled if a
* FullscreenDelegate is set. * FullscreenDelegate is set.
...@@ -17,7 +19,7 @@ public abstract class FullscreenDelegate { ...@@ -17,7 +19,7 @@ public abstract class FullscreenDelegate {
* *
* NOTE: the Runnable must not be used synchronously. * NOTE: the Runnable must not be used synchronously.
*/ */
public abstract void enterFullscreen(Runnable exitFullscreenRunner); public abstract void enterFullscreen(@NonNull Runnable exitFullscreenRunner);
/** /**
* The page has exited fullscreen mode and the system should be moved out of fullscreen mode. * The page has exited fullscreen mode and the system should be moved out of fullscreen mode.
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.weblayer; package org.chromium.weblayer;
import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
...@@ -21,7 +23,7 @@ public class ListenableResult<V> { ...@@ -21,7 +23,7 @@ public class ListenableResult<V> {
* Call the callback with the result of computation. * Call the callback with the result of computation.
* Note callback may be called immediately. * Note callback may be called immediately.
*/ */
public void addCallback(Callback<V> callback) { public void addCallback(@NonNull Callback<V> callback) {
if (mHasResult) { if (mHasResult) {
callback.onResult(mResult); callback.onResult(mResult);
return; return;
......
...@@ -7,6 +7,8 @@ package org.chromium.weblayer; ...@@ -7,6 +7,8 @@ package org.chromium.weblayer;
import android.net.Uri; import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import androidx.annotation.NonNull;
import org.chromium.weblayer_private.aidl.APICallException; import org.chromium.weblayer_private.aidl.APICallException;
import org.chromium.weblayer_private.aidl.IClientNavigation; import org.chromium.weblayer_private.aidl.IClientNavigation;
import org.chromium.weblayer_private.aidl.INavigation; import org.chromium.weblayer_private.aidl.INavigation;
...@@ -58,6 +60,7 @@ public final class Navigation extends IClientNavigation.Stub { ...@@ -58,6 +60,7 @@ public final class Navigation extends IClientNavigation.Stub {
* The uri the main frame is navigating to. This may change during the navigation when * The uri the main frame is navigating to. This may change during the navigation when
* encountering a server redirect. * encountering a server redirect.
*/ */
@NonNull
public Uri getUri() { public Uri getUri() {
try { try {
return Uri.parse(mNavigationImpl.getUri()); return Uri.parse(mNavigationImpl.getUri());
...@@ -70,6 +73,7 @@ public final class Navigation extends IClientNavigation.Stub { ...@@ -70,6 +73,7 @@ public final class Navigation extends IClientNavigation.Stub {
* Returns the redirects that occurred on the way to the current page. The current page is the * Returns the redirects that occurred on the way to the current page. The current page is the
* last one in the list (so even when there's no redirect, there will be one entry in the list). * last one in the list (so even when there's no redirect, there will be one entry in the list).
*/ */
@NonNull
public List<Uri> getRedirectChain() { public List<Uri> getRedirectChain() {
try { try {
List<Uri> redirects = new ArrayList<Uri>(); List<Uri> redirects = new ArrayList<Uri>();
......
...@@ -7,6 +7,8 @@ package org.chromium.weblayer; ...@@ -7,6 +7,8 @@ package org.chromium.weblayer;
import android.net.Uri; import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import androidx.annotation.NonNull;
import org.chromium.weblayer_private.aidl.APICallException; import org.chromium.weblayer_private.aidl.APICallException;
import org.chromium.weblayer_private.aidl.IBrowserController; import org.chromium.weblayer_private.aidl.IBrowserController;
import org.chromium.weblayer_private.aidl.IClientNavigation; import org.chromium.weblayer_private.aidl.IClientNavigation;
...@@ -37,7 +39,7 @@ public final class NavigationController { ...@@ -37,7 +39,7 @@ public final class NavigationController {
mObservers = new ObserverList<NavigationObserver>(); mObservers = new ObserverList<NavigationObserver>();
} }
public void navigate(Uri uri) { public void navigate(@NonNull Uri uri) {
try { try {
mNavigationController.navigate(uri.toString()); mNavigationController.navigate(uri.toString());
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -109,6 +111,7 @@ public final class NavigationController { ...@@ -109,6 +111,7 @@ public final class NavigationController {
} }
} }
@NonNull
public Uri getNavigationEntryDisplayUri(int index) { public Uri getNavigationEntryDisplayUri(int index) {
try { try {
return Uri.parse(mNavigationController.getNavigationEntryDisplayUri(index)); return Uri.parse(mNavigationController.getNavigationEntryDisplayUri(index));
...@@ -117,11 +120,11 @@ public final class NavigationController { ...@@ -117,11 +120,11 @@ public final class NavigationController {
} }
} }
public void addObserver(NavigationObserver observer) { public void addObserver(@NonNull NavigationObserver observer) {
mObservers.addObserver(observer); mObservers.addObserver(observer);
} }
public void removeObserver(NavigationObserver observer) { public void removeObserver(@NonNull NavigationObserver observer) {
mObservers.removeObserver(observer); mObservers.removeObserver(observer);
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.weblayer; package org.chromium.weblayer;
import androidx.annotation.NonNull;
/** /**
* Informed of interesting events that happen during the lifetime of NavigationController. This * Informed of interesting events that happen during the lifetime of NavigationController. This
* interface is only notified of main frame navigations. * interface is only notified of main frame navigations.
...@@ -37,14 +39,14 @@ public abstract class NavigationObserver { ...@@ -37,14 +39,14 @@ public abstract class NavigationObserver {
* *
* @param navigation the unique object for this navigation. * @param navigation the unique object for this navigation.
*/ */
public void navigationStarted(Navigation navigation) {} public void navigationStarted(@NonNull Navigation navigation) {}
/** /**
* Called when a navigation encountered a server redirect. * Called when a navigation encountered a server redirect.
* *
* @param navigation the unique object for this navigation. * @param navigation the unique object for this navigation.
*/ */
public void navigationRedirected(Navigation navigation) {} public void navigationRedirected(@NonNull Navigation navigation) {}
/** /**
* Called when the navigation is ready to be committed in a renderer. A navigation is considered * Called when the navigation is ready to be committed in a renderer. A navigation is considered
...@@ -59,7 +61,7 @@ public abstract class NavigationObserver { ...@@ -59,7 +61,7 @@ public abstract class NavigationObserver {
* *
* @param navigation the unique object for this navigation. * @param navigation the unique object for this navigation.
*/ */
public void navigationCommitted(Navigation navigation) {} public void navigationCommitted(@NonNull Navigation navigation) {}
/** /**
* Called when a navigation completes successfully in the BrowserController. * Called when a navigation completes successfully in the BrowserController.
...@@ -77,7 +79,7 @@ public abstract class NavigationObserver { ...@@ -77,7 +79,7 @@ public abstract class NavigationObserver {
* *
* @param navigation the unique object for this navigation. * @param navigation the unique object for this navigation.
*/ */
public void navigationCompleted(Navigation navigation) {} public void navigationCompleted(@NonNull Navigation navigation) {}
/** /**
* Called when a navigation aborts in the BrowserController. * Called when a navigation aborts in the BrowserController.
...@@ -87,7 +89,7 @@ public abstract class NavigationObserver { ...@@ -87,7 +89,7 @@ public abstract class NavigationObserver {
* *
* @param navigation the unique object for this navigation. * @param navigation the unique object for this navigation.
*/ */
public void navigationFailed(Navigation navigation) {} public void navigationFailed(@NonNull Navigation navigation) {}
/** /**
* This is fired after each navigation has completed to indicate that the first paint after a * This is fired after each navigation has completed to indicate that the first paint after a
......
...@@ -16,6 +16,8 @@ import android.webkit.ValueCallback; ...@@ -16,6 +16,8 @@ import android.webkit.ValueCallback;
import android.webkit.WebViewDelegate; import android.webkit.WebViewDelegate;
import android.webkit.WebViewFactory; import android.webkit.WebViewFactory;
import androidx.annotation.NonNull;
import org.chromium.weblayer_private.aidl.APICallException; import org.chromium.weblayer_private.aidl.APICallException;
import org.chromium.weblayer_private.aidl.BrowserFragmentArgs; import org.chromium.weblayer_private.aidl.BrowserFragmentArgs;
import org.chromium.weblayer_private.aidl.IBrowserFragment; import org.chromium.weblayer_private.aidl.IBrowserFragment;
...@@ -104,6 +106,7 @@ public final class WebLayer { ...@@ -104,6 +106,7 @@ public final class WebLayer {
* @return a ListenableFuture whose value will contain the WebLayer once initialization * @return a ListenableFuture whose value will contain the WebLayer once initialization
* completes * completes
*/ */
@NonNull
public static ListenableFuture<WebLayer> create(Context appContext) public static ListenableFuture<WebLayer> create(Context appContext)
throws UnsupportedVersionException { throws UnsupportedVersionException {
if (sFuture == null) { if (sFuture == null) {
...@@ -182,6 +185,7 @@ public final class WebLayer { ...@@ -182,6 +185,7 @@ public final class WebLayer {
mImpl = iWebLayer; mImpl = iWebLayer;
} }
@NonNull
public static BrowserFragment createBrowserFragment(String profilePath) { public static BrowserFragment createBrowserFragment(String profilePath) {
// TODO: use a profile id instead of the path to the actual file. // TODO: use a profile id instead of the path to the actual file.
Bundle args = new Bundle(); Bundle args = new Bundle();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment