Commit c727f5d1 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Add thread checks

Add thread check to all embedder to implementation calls.

Change-Id: Ifac0c0de5b2ea365313d151451cbff8ade7ab818
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879428Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709129}
parent 0d1d7a9a
...@@ -23,23 +23,24 @@ template("weblayer_java") { ...@@ -23,23 +23,24 @@ template("weblayer_java") {
android_library(target_name) { android_library(target_name) {
java_files = [ java_files = [
"org/chromium/weblayer/BrowserController.java", "org/chromium/weblayer/BrowserController.java",
"org/chromium/weblayer/BrowserFragment.java",
"org/chromium/weblayer/BrowserFragmentController.java", "org/chromium/weblayer/BrowserFragmentController.java",
"org/chromium/weblayer/BrowserFragment.java",
"org/chromium/weblayer/BrowserObserver.java", "org/chromium/weblayer/BrowserObserver.java",
"org/chromium/weblayer/Callback.java", "org/chromium/weblayer/Callback.java",
"org/chromium/weblayer/ChildProcessService.java",
"org/chromium/weblayer/DownloadDelegate.java", "org/chromium/weblayer/DownloadDelegate.java",
"org/chromium/weblayer/FullscreenDelegate.java", "org/chromium/weblayer/FullscreenDelegate.java",
"org/chromium/weblayer/ListenableFuture.java", "org/chromium/weblayer/ListenableFuture.java",
"org/chromium/weblayer/ListenableResult.java", "org/chromium/weblayer/ListenableResult.java",
"org/chromium/weblayer/Navigation.java",
"org/chromium/weblayer/NavigationController.java", "org/chromium/weblayer/NavigationController.java",
"org/chromium/weblayer/Navigation.java",
"org/chromium/weblayer/NavigationObserver.java", "org/chromium/weblayer/NavigationObserver.java",
"org/chromium/weblayer/ObserverList.java", "org/chromium/weblayer/ObserverList.java",
"org/chromium/weblayer/Profile.java", "org/chromium/weblayer/Profile.java",
"org/chromium/weblayer/ProfileManager.java", "org/chromium/weblayer/ProfileManager.java",
"org/chromium/weblayer/WebLayer.java", "org/chromium/weblayer/ThreadCheck.java",
"org/chromium/weblayer/ChildProcessService.java",
"org/chromium/weblayer/UnsupportedVersionException.java", "org/chromium/weblayer/UnsupportedVersionException.java",
"org/chromium/weblayer/WebLayer.java",
] ]
deps = [ deps = [
......
...@@ -49,6 +49,7 @@ public final class BrowserController { ...@@ -49,6 +49,7 @@ public final class BrowserController {
} }
public void setDownloadDelegate(@Nullable DownloadDelegate delegate) { public void setDownloadDelegate(@Nullable DownloadDelegate delegate) {
ThreadCheck.ensureOnUiThread();
try { try {
if (delegate != null) { if (delegate != null) {
mDownloadDelegateClient = new DownloadDelegateClientImpl(delegate); mDownloadDelegateClient = new DownloadDelegateClientImpl(delegate);
...@@ -63,6 +64,7 @@ public final class BrowserController { ...@@ -63,6 +64,7 @@ public final class BrowserController {
} }
public void setFullscreenDelegate(@Nullable FullscreenDelegate delegate) { public void setFullscreenDelegate(@Nullable FullscreenDelegate delegate) {
ThreadCheck.ensureOnUiThread();
try { try {
if (delegate != null) { if (delegate != null) {
mFullscreenDelegateClient = new FullscreenDelegateClientImpl(delegate); mFullscreenDelegateClient = new FullscreenDelegateClientImpl(delegate);
...@@ -77,6 +79,7 @@ public final class BrowserController { ...@@ -77,6 +79,7 @@ public final class BrowserController {
} }
public DownloadDelegate getDownloadDelegate() { public DownloadDelegate getDownloadDelegate() {
ThreadCheck.ensureOnUiThread();
return mDownloadDelegateClient != null ? mDownloadDelegateClient.getDelegate() : null; return mDownloadDelegateClient != null ? mDownloadDelegateClient.getDelegate() : null;
} }
...@@ -87,6 +90,7 @@ public final class BrowserController { ...@@ -87,6 +90,7 @@ public final class BrowserController {
*/ */
public void executeScript( public void executeScript(
@NonNull String script, @Nullable ValueCallback<JSONObject> callback) { @NonNull String script, @Nullable ValueCallback<JSONObject> callback) {
ThreadCheck.ensureOnUiThread();
try { try {
ValueCallback<String> stringCallback = (String result) -> { ValueCallback<String> stringCallback = (String result) -> {
if (callback == null) { if (callback == null) {
...@@ -109,6 +113,7 @@ public final class BrowserController { ...@@ -109,6 +113,7 @@ public final class BrowserController {
@Nullable @Nullable
public FullscreenDelegate getFullscreenDelegate() { public FullscreenDelegate getFullscreenDelegate() {
ThreadCheck.ensureOnUiThread();
return mFullscreenDelegateClient != null ? mFullscreenDelegateClient.getDelegate() : null; return mFullscreenDelegateClient != null ? mFullscreenDelegateClient.getDelegate() : null;
} }
...@@ -119,14 +124,17 @@ public final class BrowserController { ...@@ -119,14 +124,17 @@ public final class BrowserController {
@NonNull @NonNull
public NavigationController getNavigationController() { public NavigationController getNavigationController() {
ThreadCheck.ensureOnUiThread();
return mNavigationController; return mNavigationController;
} }
public void addObserver(@Nullable BrowserObserver observer) { public void addObserver(@Nullable BrowserObserver observer) {
ThreadCheck.ensureOnUiThread();
mObservers.addObserver(observer); mObservers.addObserver(observer);
} }
public void removeObserver(@Nullable BrowserObserver observer) { public void removeObserver(@Nullable BrowserObserver observer) {
ThreadCheck.ensureOnUiThread();
mObservers.removeObserver(observer); mObservers.removeObserver(observer);
} }
......
...@@ -145,6 +145,7 @@ public final class BrowserFragment extends Fragment { ...@@ -145,6 +145,7 @@ public final class BrowserFragment extends Fragment {
*/ */
public BrowserFragment() { public BrowserFragment() {
super(); super();
ThreadCheck.ensureOnUiThread();
} }
/** /**
...@@ -153,6 +154,7 @@ public final class BrowserFragment extends Fragment { ...@@ -153,6 +154,7 @@ public final class BrowserFragment extends Fragment {
*/ */
@NonNull @NonNull
public BrowserFragmentController getController() { public BrowserFragmentController getController() {
ThreadCheck.ensureOnUiThread();
if (mBrowserFragmentController == null) { if (mBrowserFragmentController == null) {
throw new RuntimeException("BrowserFragmentController is available only between " throw new RuntimeException("BrowserFragmentController is available only between "
+ "BrowserFragment's onCreate() and onDestroy()."); + "BrowserFragment's onCreate() and onDestroy().");
...@@ -162,6 +164,7 @@ public final class BrowserFragment extends Fragment { ...@@ -162,6 +164,7 @@ public final class BrowserFragment extends Fragment {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnActivityResult( mImpl.asRemoteFragment().handleOnActivityResult(
requestCode, resultCode, ObjectWrapper.wrap(data)); requestCode, resultCode, ObjectWrapper.wrap(data));
...@@ -173,6 +176,7 @@ public final class BrowserFragment extends Fragment { ...@@ -173,6 +176,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
ThreadCheck.ensureOnUiThread();
// This is the first lifecycle event and also the first time we can get app context (unless // This is the first lifecycle event and also the first time we can get app context (unless
// the embedder has already called getController). So it's the latest and at the same time // the embedder has already called getController). So it's the latest and at the same time
// the earliest moment when we can initialize WebLayer without missing any lifecycle events. // the earliest moment when we can initialize WebLayer without missing any lifecycle events.
...@@ -206,6 +210,7 @@ public final class BrowserFragment extends Fragment { ...@@ -206,6 +210,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnCreate(ObjectWrapper.wrap(savedInstanceState)); mImpl.asRemoteFragment().handleOnCreate(ObjectWrapper.wrap(savedInstanceState));
mBrowserFragmentController = new BrowserFragmentController(mImpl.getController(), mBrowserFragmentController = new BrowserFragmentController(mImpl.getController(),
...@@ -218,6 +223,7 @@ public final class BrowserFragment extends Fragment { ...@@ -218,6 +223,7 @@ public final class BrowserFragment extends Fragment {
@Override @Override
public View onCreateView( public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ThreadCheck.ensureOnUiThread();
try { try {
return ObjectWrapper.unwrap(mImpl.asRemoteFragment().handleOnCreateView(), View.class); return ObjectWrapper.unwrap(mImpl.asRemoteFragment().handleOnCreateView(), View.class);
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -228,6 +234,7 @@ public final class BrowserFragment extends Fragment { ...@@ -228,6 +234,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnActivityCreated( mImpl.asRemoteFragment().handleOnActivityCreated(
ObjectWrapper.wrap(savedInstanceState)); ObjectWrapper.wrap(savedInstanceState));
...@@ -239,6 +246,7 @@ public final class BrowserFragment extends Fragment { ...@@ -239,6 +246,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onStart() { public void onStart() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnStart(); mImpl.asRemoteFragment().handleOnStart();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -249,6 +257,7 @@ public final class BrowserFragment extends Fragment { ...@@ -249,6 +257,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onResume() { public void onResume() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnResume(); mImpl.asRemoteFragment().handleOnResume();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -259,6 +268,7 @@ public final class BrowserFragment extends Fragment { ...@@ -259,6 +268,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnSaveInstanceState(ObjectWrapper.wrap(outState)); mImpl.asRemoteFragment().handleOnSaveInstanceState(ObjectWrapper.wrap(outState));
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -269,6 +279,7 @@ public final class BrowserFragment extends Fragment { ...@@ -269,6 +279,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onPause() { public void onPause() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnPause(); mImpl.asRemoteFragment().handleOnPause();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -279,6 +290,7 @@ public final class BrowserFragment extends Fragment { ...@@ -279,6 +290,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onStop() { public void onStop() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnStop(); mImpl.asRemoteFragment().handleOnStop();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -289,6 +301,7 @@ public final class BrowserFragment extends Fragment { ...@@ -289,6 +301,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onDestroyView() { public void onDestroyView() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnDestroyView(); mImpl.asRemoteFragment().handleOnDestroyView();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -299,6 +312,7 @@ public final class BrowserFragment extends Fragment { ...@@ -299,6 +312,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onDestroy() { public void onDestroy() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnDestroy(); mImpl.asRemoteFragment().handleOnDestroy();
// The other side does the clean up automatically in handleOnDestroy() // The other side does the clean up automatically in handleOnDestroy()
...@@ -311,6 +325,7 @@ public final class BrowserFragment extends Fragment { ...@@ -311,6 +325,7 @@ public final class BrowserFragment extends Fragment {
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
@Override @Override
public void onDetach() { public void onDetach() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.asRemoteFragment().handleOnDetach(); mImpl.asRemoteFragment().handleOnDetach();
} catch (RemoteException e) { } catch (RemoteException e) {
......
...@@ -32,6 +32,7 @@ public final class BrowserFragmentController { ...@@ -32,6 +32,7 @@ public final class BrowserFragmentController {
// TODO(pshmakov): rename this to BrowserTabController. // TODO(pshmakov): rename this to BrowserTabController.
@NonNull @NonNull
public BrowserController getBrowserController() { public BrowserController getBrowserController() {
ThreadCheck.ensureOnUiThread();
if (mController == null) { if (mController == null) {
try { try {
mController = new BrowserController(mImpl.getBrowserController()); mController = new BrowserController(mImpl.getBrowserController());
...@@ -43,6 +44,7 @@ public final class BrowserFragmentController { ...@@ -43,6 +44,7 @@ public final class BrowserFragmentController {
} }
public void setTopView(@Nullable View view) { public void setTopView(@Nullable View view) {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.setTopView(ObjectWrapper.wrap(view)); mImpl.setTopView(ObjectWrapper.wrap(view));
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -61,6 +63,7 @@ public final class BrowserFragmentController { ...@@ -61,6 +63,7 @@ public final class BrowserFragmentController {
*/ */
@NonNull @NonNull
public ListenableResult<Boolean> setSupportsEmbedding(boolean enable) { public ListenableResult<Boolean> setSupportsEmbedding(boolean enable) {
ThreadCheck.ensureOnUiThread();
try { try {
final ListenableResult<Boolean> listenableResult = new ListenableResult<Boolean>(); final ListenableResult<Boolean> listenableResult = new ListenableResult<Boolean>();
mImpl.setSupportsEmbedding( mImpl.setSupportsEmbedding(
...@@ -82,6 +85,7 @@ public final class BrowserFragmentController { ...@@ -82,6 +85,7 @@ public final class BrowserFragmentController {
*/ */
@NonNull @NonNull
public Profile getProfile() { public Profile getProfile() {
ThreadCheck.ensureOnUiThread();
try { try {
return mProfileManager.getProfileFor(mImpl.getProfile()); return mProfileManager.getProfileFor(mImpl.getProfile());
} catch (RemoteException e) { } catch (RemoteException e) {
......
...@@ -49,6 +49,7 @@ public final class Navigation extends IClientNavigation.Stub { ...@@ -49,6 +49,7 @@ public final class Navigation extends IClientNavigation.Stub {
} }
public State getState() { public State getState() {
ThreadCheck.ensureOnUiThread();
try { try {
return ipcStateToState(mNavigationImpl.getState()); return ipcStateToState(mNavigationImpl.getState());
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -62,6 +63,7 @@ public final class Navigation extends IClientNavigation.Stub { ...@@ -62,6 +63,7 @@ public final class Navigation extends IClientNavigation.Stub {
*/ */
@NonNull @NonNull
public Uri getUri() { public Uri getUri() {
ThreadCheck.ensureOnUiThread();
try { try {
return Uri.parse(mNavigationImpl.getUri()); return Uri.parse(mNavigationImpl.getUri());
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -75,6 +77,7 @@ public final class Navigation extends IClientNavigation.Stub { ...@@ -75,6 +77,7 @@ public final class Navigation extends IClientNavigation.Stub {
*/ */
@NonNull @NonNull
public List<Uri> getRedirectChain() { public List<Uri> getRedirectChain() {
ThreadCheck.ensureOnUiThread();
try { try {
List<Uri> redirects = new ArrayList<Uri>(); List<Uri> redirects = new ArrayList<Uri>();
for (String r : mNavigationImpl.getRedirectChain()) redirects.add(Uri.parse(r)); for (String r : mNavigationImpl.getRedirectChain()) redirects.add(Uri.parse(r));
......
...@@ -40,6 +40,7 @@ public final class NavigationController { ...@@ -40,6 +40,7 @@ public final class NavigationController {
} }
public void navigate(@NonNull Uri uri) { public void navigate(@NonNull Uri uri) {
ThreadCheck.ensureOnUiThread();
try { try {
mNavigationController.navigate(uri.toString()); mNavigationController.navigate(uri.toString());
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -48,6 +49,7 @@ public final class NavigationController { ...@@ -48,6 +49,7 @@ public final class NavigationController {
} }
public void goBack() { public void goBack() {
ThreadCheck.ensureOnUiThread();
try { try {
mNavigationController.goBack(); mNavigationController.goBack();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -56,6 +58,7 @@ public final class NavigationController { ...@@ -56,6 +58,7 @@ public final class NavigationController {
} }
public void goForward() { public void goForward() {
ThreadCheck.ensureOnUiThread();
try { try {
mNavigationController.goForward(); mNavigationController.goForward();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -64,6 +67,7 @@ public final class NavigationController { ...@@ -64,6 +67,7 @@ public final class NavigationController {
} }
public boolean canGoBack() { public boolean canGoBack() {
ThreadCheck.ensureOnUiThread();
try { try {
return mNavigationController.canGoBack(); return mNavigationController.canGoBack();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -72,6 +76,7 @@ public final class NavigationController { ...@@ -72,6 +76,7 @@ public final class NavigationController {
} }
public boolean canGoForward() { public boolean canGoForward() {
ThreadCheck.ensureOnUiThread();
try { try {
return mNavigationController.canGoForward(); return mNavigationController.canGoForward();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -80,6 +85,7 @@ public final class NavigationController { ...@@ -80,6 +85,7 @@ public final class NavigationController {
} }
public void reload() { public void reload() {
ThreadCheck.ensureOnUiThread();
try { try {
mNavigationController.reload(); mNavigationController.reload();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -88,6 +94,7 @@ public final class NavigationController { ...@@ -88,6 +94,7 @@ public final class NavigationController {
} }
public void stop() { public void stop() {
ThreadCheck.ensureOnUiThread();
try { try {
mNavigationController.stop(); mNavigationController.stop();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -96,6 +103,7 @@ public final class NavigationController { ...@@ -96,6 +103,7 @@ public final class NavigationController {
} }
public int getNavigationListSize() { public int getNavigationListSize() {
ThreadCheck.ensureOnUiThread();
try { try {
return mNavigationController.getNavigationListSize(); return mNavigationController.getNavigationListSize();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -104,6 +112,7 @@ public final class NavigationController { ...@@ -104,6 +112,7 @@ public final class NavigationController {
} }
public int getNavigationListCurrentIndex() { public int getNavigationListCurrentIndex() {
ThreadCheck.ensureOnUiThread();
try { try {
return mNavigationController.getNavigationListCurrentIndex(); return mNavigationController.getNavigationListCurrentIndex();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -113,6 +122,7 @@ public final class NavigationController { ...@@ -113,6 +122,7 @@ public final class NavigationController {
@NonNull @NonNull
public Uri getNavigationEntryDisplayUri(int index) { public Uri getNavigationEntryDisplayUri(int index) {
ThreadCheck.ensureOnUiThread();
try { try {
return Uri.parse(mNavigationController.getNavigationEntryDisplayUri(index)); return Uri.parse(mNavigationController.getNavigationEntryDisplayUri(index));
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -121,10 +131,12 @@ public final class NavigationController { ...@@ -121,10 +131,12 @@ public final class NavigationController {
} }
public void addObserver(@NonNull NavigationObserver observer) { public void addObserver(@NonNull NavigationObserver observer) {
ThreadCheck.ensureOnUiThread();
mObservers.addObserver(observer); mObservers.addObserver(observer);
} }
public void removeObserver(@NonNull NavigationObserver observer) { public void removeObserver(@NonNull NavigationObserver observer) {
ThreadCheck.ensureOnUiThread();
mObservers.removeObserver(observer); mObservers.removeObserver(observer);
} }
......
...@@ -29,6 +29,7 @@ public final class Profile { ...@@ -29,6 +29,7 @@ public final class Profile {
} }
public void clearBrowsingData() { public void clearBrowsingData() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.clearBrowsingData(); mImpl.clearBrowsingData();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -37,6 +38,7 @@ public final class Profile { ...@@ -37,6 +38,7 @@ public final class Profile {
} }
public void destroy() { public void destroy() {
ThreadCheck.ensureOnUiThread();
try { try {
mImpl.destroy(); mImpl.destroy();
} catch (RemoteException e) { } catch (RemoteException e) {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer; package org.chromium.weblayer;
import org.chromium.weblayer_private.aidl.IProfile; import org.chromium.weblayer_private.aidl.IProfile;
...@@ -23,6 +27,7 @@ import java.util.Map; ...@@ -23,6 +27,7 @@ import java.util.Map;
/** Destroys all the Profiles. */ /** Destroys all the Profiles. */
void destroy() { void destroy() {
ThreadCheck.ensureOnUiThread();
for (Profile profile : mProfiles.values()) { for (Profile profile : mProfiles.values()) {
profile.destroy(); profile.destroy();
} }
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer;
import android.os.Looper;
import android.util.AndroidRuntimeException;
/* package */ class ThreadCheck {
/* package */ static void ensureOnUiThread() {
if (Looper.getMainLooper() != Looper.myLooper()) {
throw new AndroidRuntimeException("This method needs to be called on the main thread");
}
}
}
...@@ -109,6 +109,7 @@ public final class WebLayer { ...@@ -109,6 +109,7 @@ public final class WebLayer {
@NonNull @NonNull
public static ListenableFuture<WebLayer> create(Context appContext) public static ListenableFuture<WebLayer> create(Context appContext)
throws UnsupportedVersionException { throws UnsupportedVersionException {
ThreadCheck.ensureOnUiThread();
if (sFuture == null) { if (sFuture == null) {
// Just in case the app passed an Activity context. // Just in case the app passed an Activity context.
appContext = appContext.getApplicationContext(); appContext = appContext.getApplicationContext();
...@@ -157,7 +158,8 @@ public final class WebLayer { ...@@ -157,7 +158,8 @@ public final class WebLayer {
} }
@Override @Override
public void onLoad() { /* package */ void onLoad() {
ThreadCheck.ensureOnUiThread();
try { try {
mIWebLayer.loadSync(); mIWebLayer.loadSync();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -177,6 +179,7 @@ public final class WebLayer { ...@@ -177,6 +179,7 @@ public final class WebLayer {
} }
public void destroy() { public void destroy() {
ThreadCheck.ensureOnUiThread();
// TODO: implement me. // TODO: implement me.
mProfileManager.destroy(); mProfileManager.destroy();
} }
...@@ -187,6 +190,7 @@ public final class WebLayer { ...@@ -187,6 +190,7 @@ public final class WebLayer {
@NonNull @NonNull
public static BrowserFragment createBrowserFragment(String profilePath) { public static BrowserFragment createBrowserFragment(String profilePath) {
ThreadCheck.ensureOnUiThread();
// 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();
args.putString(BrowserFragmentArgs.PROFILE_PATH, profilePath == null ? "" : profilePath); args.putString(BrowserFragmentArgs.PROFILE_PATH, profilePath == null ? "" : profilePath);
......
...@@ -191,8 +191,8 @@ public class NavigationTest { ...@@ -191,8 +191,8 @@ public class NavigationTest {
mActivityTestRule.navigateAndWait(URL2); mActivityTestRule.navigateAndWait(URL2);
mActivityTestRule.navigateAndWait(URL3); mActivityTestRule.navigateAndWait(URL3);
NavigationController navigationController = NavigationController navigationController = runOnUiThreadBlocking(
activity.getBrowserController().getNavigationController(); () -> activity.getBrowserController().getNavigationController());
navigateAndWaitForCompletion(URL2, () -> { navigateAndWaitForCompletion(URL2, () -> {
assertTrue(navigationController.canGoBack()); assertTrue(navigationController.canGoBack());
......
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