Commit deca77f1 authored by Tiger Oakes's avatar Tiger Oakes Committed by Commit Bot

Remove getApplicationContext calls from /content/public/

Continuation of work in bug 646094.

Preparing to activate an errorprone check to flag
context#getApplicationContext calls. The goal is to prevent storing the
resulting context as a class property, and instead use ContextUtils.

Bug: 846456
Change-Id: I059c13769179010146530e75b554acc29260abaa
Reviewed-on: https://chromium-review.googlesource.com/1140511Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Tiger Oakes <tigero@google.com>
Cr-Commit-Position: refs/heads/master@{#575752}
parent 1071f368
......@@ -18,6 +18,7 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.content_public.browser.WebContents;
......@@ -159,7 +160,7 @@ public class LollipopWebContentsAccessibility extends KitKatWebContentsAccessibi
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (!isNativeInitialized()) return;
mContext.getApplicationContext().unregisterReceiver(mBroadcastReceiver);
ContextUtils.getApplicationContext().unregisterReceiver(mBroadcastReceiver);
}
@Override
......@@ -172,7 +173,7 @@ public class LollipopWebContentsAccessibility extends KitKatWebContentsAccessibi
if (!isNativeInitialized()) return;
try {
IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
mContext.getApplicationContext().registerReceiver(mBroadcastReceiver, filter);
ContextUtils.getApplicationContext().registerReceiver(mBroadcastReceiver, filter);
} catch (ReceiverCallNotAllowedException e) {
// WebView may be running inside a BroadcastReceiver, in which case registerReceiver is
// not allowed.
......
......@@ -163,7 +163,7 @@ public class WebContentsAccessibilityImpl extends AccessibilityNodeProvider
mProductVersion = productVersion;
mAccessibilityManager =
(AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
mCaptioningController = new CaptioningController(mWebContents, mContext);
mCaptioningController = new CaptioningController(mWebContents);
WindowEventObserverManager.from(mWebContents).addObserver(this);
mInitialized = true;
......
......@@ -4,7 +4,6 @@
package org.chromium.content.browser.accessibility.captioning;
import android.content.Context;
import android.os.Build;
/**
......@@ -15,12 +14,11 @@ public class CaptioningBridgeFactory {
/**
* Create and return the best SystemCaptioningBridge available.
*
* @param context Context associated with the activity.
* @return the best SystemCaptioningBridge available.
*/
public static SystemCaptioningBridge getSystemCaptioningBridge(Context context) {
public static SystemCaptioningBridge getSystemCaptioningBridge() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return KitKatCaptioningBridge.getInstance(context);
return KitKatCaptioningBridge.getInstance();
}
// On older systems, return a CaptioningBridge that does nothing.
return new EmptyCaptioningBridge();
......
......@@ -5,7 +5,6 @@
package org.chromium.content.browser.accessibility.captioning;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import org.chromium.base.annotations.CalledByNative;
......@@ -20,8 +19,8 @@ public class CaptioningController implements SystemCaptioningBridge.SystemCaptio
private SystemCaptioningBridge mSystemCaptioningBridge;
private long mNativeCaptioningController;
public CaptioningController(WebContents webContents, Context context) {
mSystemCaptioningBridge = CaptioningBridgeFactory.getSystemCaptioningBridge(context);
public CaptioningController(WebContents webContents) {
mSystemCaptioningBridge = CaptioningBridgeFactory.getSystemCaptioningBridge();
mNativeCaptioningController = nativeInit(webContents);
}
......
......@@ -9,6 +9,8 @@ import android.content.Context;
import android.os.Build;
import android.view.accessibility.CaptioningManager;
import org.chromium.base.ContextUtils;
import java.util.Locale;
/**
......@@ -58,22 +60,20 @@ public class KitKatCaptioningBridge implements SystemCaptioningBridge {
* @param context the Context to associate with this bridge.
* @return the singleton instance of KitKatCaptioningBridge.
*/
public static KitKatCaptioningBridge getInstance(Context context) {
public static KitKatCaptioningBridge getInstance() {
if (sKitKatCaptioningBridge == null) {
sKitKatCaptioningBridge = new KitKatCaptioningBridge(context);
sKitKatCaptioningBridge = new KitKatCaptioningBridge();
}
return sKitKatCaptioningBridge;
}
/**
* Construct a new KitKat+ captioning bridge
*
* @param context the Context to associate with this bridge.
*/
private KitKatCaptioningBridge(Context context) {
private KitKatCaptioningBridge() {
mCaptioningChangeDelegate = new CaptioningChangeDelegate();
mCaptioningManager =
(CaptioningManager) context.getApplicationContext().getSystemService(
(CaptioningManager) ContextUtils.getApplicationContext().getSystemService(
Context.CAPTIONING_SERVICE);
}
......
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