Commit 00e24aa2 authored by Arthur Sonzogni's avatar Arthur Sonzogni Committed by Commit Bot

Revert "weblayer: fixes strict mode issues for weblayer"

This reverts commit e245bb7a.

Reason for revert: several tests are failing: See:
https://crbug.com/1062561
https://crbug.com/1062554

Original change's description:
> weblayer: fixes strict mode issues for weblayer
> 
> This fixs a number of cases and enables strict mode in tests. Hopefully
> that helps prevent any other access from being added.
> 
> The trickier cases are jacoco injects code that accesses the disk, and
> LayoutInflater may trigger loading classes, which triggers disk
> access.
> 
> BUG=1059770
> TEST=covered by tests now
> 
> Change-Id: I50f81836f838b023fe09fd5f760cb7484edd8d26
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2100589
> Commit-Queue: Scott Violet <sky@chromium.org>
> Reviewed-by: Bo <boliu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#751028}

TBR=sky@chromium.org,boliu@chromium.org

Change-Id: I3405b415b69cbb3cb0e417ac38caae608356101b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1059770, 1062561, 1062554
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107586Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751267}
parent 9808dd47
...@@ -13,7 +13,6 @@ import android.view.WindowManager; ...@@ -13,7 +13,6 @@ import android.view.WindowManager;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.StrictModeContext;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties; import org.chromium.ui.modaldialog.ModalDialogProperties;
...@@ -47,14 +46,6 @@ public class AppModalPresenter extends ModalDialogManager.Presenter { ...@@ -47,14 +46,6 @@ public class AppModalPresenter extends ModalDialogManager.Presenter {
mContext = context; mContext = context;
} }
private ModalDialogView loadDialogView() {
// LayoutInflater may access the disk.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
return (ModalDialogView) LayoutInflater.from(mDialog.getContext())
.inflate(R.layout.modal_dialog_view, null);
}
}
@Override @Override
protected void addDialogView(PropertyModel model) { protected void addDialogView(PropertyModel model) {
int style = model.get(ModalDialogProperties.PRIMARY_BUTTON_FILLED) int style = model.get(ModalDialogProperties.PRIMARY_BUTTON_FILLED)
...@@ -66,13 +57,11 @@ public class AppModalPresenter extends ModalDialogManager.Presenter { ...@@ -66,13 +57,11 @@ public class AppModalPresenter extends ModalDialogManager.Presenter {
// Cancel on touch outside should be disabled by default. The ModelChangeProcessor wouldn't // Cancel on touch outside should be disabled by default. The ModelChangeProcessor wouldn't
// notify change if the property is not set during initialization. // notify change if the property is not set during initialization.
mDialog.setCanceledOnTouchOutside(false); mDialog.setCanceledOnTouchOutside(false);
ModalDialogView dialogView = loadDialogView(); ModalDialogView dialogView = (ModalDialogView) LayoutInflater.from(mDialog.getContext())
.inflate(R.layout.modal_dialog_view, null);
mModelChangeProcessor = mModelChangeProcessor =
PropertyModelChangeProcessor.create(model, dialogView, new ViewBinder()); PropertyModelChangeProcessor.create(model, dialogView, new ViewBinder());
// setContentView() can trigger using LayoutInflater, which may read from disk. mDialog.setContentView(dialogView);
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
mDialog.setContentView(dialogView);
}
try { try {
mDialog.show(); mDialog.show();
......
...@@ -18,7 +18,6 @@ import androidx.annotation.NonNull; ...@@ -18,7 +18,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import org.chromium.base.StrictModeContext;
import org.chromium.content_public.browser.SelectionPopupController; import org.chromium.content_public.browser.SelectionPopupController;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.interpolators.BakedBezierInterpolator; import org.chromium.ui.interpolators.BakedBezierInterpolator;
...@@ -106,14 +105,6 @@ public abstract class TabModalPresenter extends ModalDialogManager.Presenter { ...@@ -106,14 +105,6 @@ public abstract class TabModalPresenter extends ModalDialogManager.Presenter {
return mDialogContainer; return mDialogContainer;
} }
private ModalDialogView loadDialogView(int style) {
// LayoutInflater may access the disk.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
return (ModalDialogView) LayoutInflater.from(new ContextThemeWrapper(mContext, style))
.inflate(R.layout.modal_dialog_view, null);
}
}
@Override @Override
protected void addDialogView(PropertyModel model) { protected void addDialogView(PropertyModel model) {
if (mDialogContainer == null) mDialogContainer = createDialogContainer(); if (mDialogContainer == null) mDialogContainer = createDialogContainer();
...@@ -121,7 +112,9 @@ public abstract class TabModalPresenter extends ModalDialogManager.Presenter { ...@@ -121,7 +112,9 @@ public abstract class TabModalPresenter extends ModalDialogManager.Presenter {
int style = model.get(ModalDialogProperties.PRIMARY_BUTTON_FILLED) int style = model.get(ModalDialogProperties.PRIMARY_BUTTON_FILLED)
? R.style.Theme_Chromium_ModalDialog_FilledPrimaryButton ? R.style.Theme_Chromium_ModalDialog_FilledPrimaryButton
: R.style.Theme_Chromium_ModalDialog_TextPrimaryButton; : R.style.Theme_Chromium_ModalDialog_TextPrimaryButton;
mDialogView = loadDialogView(style); mDialogView =
(ModalDialogView) LayoutInflater.from(new ContextThemeWrapper(mContext, style))
.inflate(R.layout.modal_dialog_view, null);
mModelChangeProcessor = mModelChangeProcessor =
PropertyModelChangeProcessor.create(model, mDialogView, new ViewBinder()); PropertyModelChangeProcessor.create(model, mDialogView, new ViewBinder());
......
...@@ -7,7 +7,6 @@ package org.chromium.components.embedder_support.delegate; ...@@ -7,7 +7,6 @@ package org.chromium.components.embedder_support.delegate;
import android.content.Context; import android.content.Context;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
...@@ -38,10 +37,7 @@ public class ColorChooserAndroid { ...@@ -38,10 +37,7 @@ public class ColorChooserAndroid {
} }
private void openColorChooser() { private void openColorChooser() {
// This triggers LayoutInflater, which may access the disk. mDialog.show();
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
mDialog.show();
}
} }
@CalledByNative @CalledByNative
......
...@@ -13,8 +13,6 @@ import android.view.View; ...@@ -13,8 +13,6 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.StrictModeContext;
/** /**
* UI for the color chooser that shows on the Android platform as a result of * UI for the color chooser that shows on the Android platform as a result of
* &lt;input type=color &gt; form element. * &lt;input type=color &gt; form element.
...@@ -35,15 +33,6 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList ...@@ -35,15 +33,6 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList
private int mCurrentColor; private int mCurrentColor;
View inflateView(Context context, int id) {
// LayoutInflater may trigger accessing the disk.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return inflater.inflate(id, null);
}
}
/** /**
* @param context The context the dialog is to run in. * @param context The context the dialog is to run in.
* @param listener The object to notify when the color is set. * @param listener The object to notify when the color is set.
...@@ -59,7 +48,9 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList ...@@ -59,7 +48,9 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList
mCurrentColor = mInitialColor; mCurrentColor = mInitialColor;
// Initialize title // Initialize title
View title = inflateView(context, R.layout.color_picker_dialog_title); LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View title = inflater.inflate(R.layout.color_picker_dialog_title, null);
setCustomTitle(title); setCustomTitle(title);
mCurrentColorView = title.findViewById(R.id.selected_color_view); mCurrentColorView = title.findViewById(R.id.selected_color_view);
...@@ -99,7 +90,7 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList ...@@ -99,7 +90,7 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList
}); });
// Initialize main content view // Initialize main content view
View content = inflateView(context, R.layout.color_picker_dialog_content); View content = inflater.inflate(R.layout.color_picker_dialog_content, null);
setView(content); setView(content);
// Initialize More button. // Initialize More button.
......
...@@ -11,7 +11,6 @@ import android.view.LayoutInflater; ...@@ -11,7 +11,6 @@ import android.view.LayoutInflater;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.StrictModeContext;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties; import org.chromium.ui.modaldialog.ModalDialogProperties;
...@@ -53,11 +52,8 @@ public abstract class JavascriptModalDialog implements ModalDialogProperties.Con ...@@ -53,11 +52,8 @@ public abstract class JavascriptModalDialog implements ModalDialogProperties.Con
protected void show(Context context, ModalDialogManager manager, protected void show(Context context, ModalDialogManager manager,
@ModalDialogManager.ModalDialogType int dialogType) { @ModalDialogManager.ModalDialogType int dialogType) {
assert manager != null; assert manager != null;
// LayoutInflater may trigger accessing the disk. mDialogCustomView = (JavascriptDialogCustomView) LayoutInflater.from(context).inflate(
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { R.layout.js_modal_dialog, null);
mDialogCustomView = (JavascriptDialogCustomView) LayoutInflater.from(context).inflate(
R.layout.js_modal_dialog, null);
}
mDialogCustomView.setPromptText(mDefaultPromptText); mDialogCustomView.setPromptText(mDefaultPromptText);
mDialogCustomView.setSuppressCheckBoxVisibility(mShouldShowSuppressCheckBox); mDialogCustomView.setSuppressCheckBoxVisibility(mShouldShowSuppressCheckBox);
......
...@@ -405,20 +405,17 @@ public final class WebLayerImpl extends IWebLayer.Stub { ...@@ -405,20 +405,17 @@ public final class WebLayerImpl extends IWebLayer.Stub {
} }
private void loadNativeLibrary(String packageName) { private void loadNativeLibrary(String packageName) {
// Loading the library triggers disk access. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { WebViewFactory.loadWebViewNativeLibraryFromPackage(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { packageName, getClass().getClassLoader());
WebViewFactory.loadWebViewNativeLibraryFromPackage( } else {
packageName, getClass().getClassLoader()); try {
} else { Method loadNativeLibrary =
try { WebViewFactory.class.getDeclaredMethod("loadNativeLibrary");
Method loadNativeLibrary = loadNativeLibrary.setAccessible(true);
WebViewFactory.class.getDeclaredMethod("loadNativeLibrary"); loadNativeLibrary.invoke(null);
loadNativeLibrary.setAccessible(true); } catch (ReflectiveOperationException e) {
loadNativeLibrary.invoke(null); Log.e(TAG, "Failed to load native library.", e);
} catch (ReflectiveOperationException e) {
Log.e(TAG, "Failed to load native library.", e);
}
} }
} }
} }
......
...@@ -10,7 +10,6 @@ import android.view.View; ...@@ -10,7 +10,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.chromium.base.StrictModeContext;
import org.chromium.components.browser_ui.modaldialog.R; import org.chromium.components.browser_ui.modaldialog.R;
import org.chromium.components.browser_ui.modaldialog.TabModalPresenter; import org.chromium.components.browser_ui.modaldialog.TabModalPresenter;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -44,17 +43,10 @@ public class WebLayerTabModalPresenter extends TabModalPresenter { ...@@ -44,17 +43,10 @@ public class WebLayerTabModalPresenter extends TabModalPresenter {
runEnterAnimation(); runEnterAnimation();
} }
private FrameLayout loadDialogContainer() {
// LayoutInflater may trigger accessing the disk.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
return (FrameLayout) LayoutInflater.from(mContext).inflate(
R.layout.modal_dialog_container, null);
}
}
@Override @Override
protected ViewGroup createDialogContainer() { protected ViewGroup createDialogContainer() {
FrameLayout dialogContainer = loadDialogContainer(); FrameLayout dialogContainer = (FrameLayout) LayoutInflater.from(mContext).inflate(
R.layout.modal_dialog_container, null);
dialogContainer.setVisibility(View.GONE); dialogContainer.setVisibility(View.GONE);
dialogContainer.setClickable(true); dialogContainer.setClickable(true);
......
...@@ -8,9 +8,6 @@ import android.content.Context; ...@@ -8,9 +8,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import android.os.StrictMode.VmPolicy;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
...@@ -61,17 +58,6 @@ public class InstrumentationActivity extends FragmentActivity { ...@@ -61,17 +58,6 @@ public class InstrumentationActivity extends FragmentActivity {
private Bundle mSavedInstanceState; private Bundle mSavedInstanceState;
private TabCallback mTabCallback; private TabCallback mTabCallback;
private static boolean isJaCoCoEnabled() {
// Nothing is set at runtime indicating jacoco is being used. This looks for the existence
// of a javacoco class to determine if jacoco is enabled.
try {
Class.forName("org.jacoco.agent.rt.RT");
return true;
} catch (LinkageError | ClassNotFoundException e) {
}
return false;
}
public Tab getTab() { public Tab getTab() {
return mTab; return mTab;
} }
...@@ -109,19 +95,6 @@ public class InstrumentationActivity extends FragmentActivity { ...@@ -109,19 +95,6 @@ public class InstrumentationActivity extends FragmentActivity {
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
// JaCoCo injects code that does file access, which doesn't work well with strict mode.
if (!isJaCoCoEnabled()) {
StrictMode.setThreadPolicy(
new ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDeath().build());
// This doesn't use detectAll() as the untagged sockets policy is encountered in tests
// using TestServer.
StrictMode.setVmPolicy(new VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mSavedInstanceState = savedInstanceState; mSavedInstanceState = savedInstanceState;
LinearLayout mainView = new LinearLayout(this); LinearLayout mainView = new LinearLayout(this);
......
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