Bug 1369107 - 1. Remove usages of GeckoAppShell.getContext(); r=droeh

Replace usages of GeckoAppShell.getContext() with
getApplicationContext() if possible, or the current Activity if the
usage expects an Activity context.

MozReview-Commit-ID: 9GOWszgEsQu
This commit is contained in:
Jim Chen 2017-06-02 16:13:41 -04:00
Родитель 858e777c78
Коммит 5674b33e77
7 изменённых файлов: 35 добавлений и 23 удалений

Просмотреть файл

@ -1793,7 +1793,7 @@ public class BrowserApp extends GeckoApp
// Display notification for Mozilla data reporting, if data should be collected.
if (AppConstants.MOZ_DATA_REPORTING &&
Restrictions.isAllowed(this, Restrictable.DATA_CHOICES)) {
DataReportingNotification.checkAndNotifyPolicy(GeckoAppShell.getContext());
DataReportingNotification.checkAndNotifyPolicy(this);
}
break;
@ -1989,12 +1989,12 @@ public class BrowserApp extends GeckoApp
break;
case "Experiments:SetOverride":
Experiments.setOverride(getContext(), message.getString("name"),
Experiments.setOverride(this, message.getString("name"),
message.getBoolean("isEnabled"));
break;
case "Experiments:ClearOverride":
Experiments.clearOverride(getContext(), message.getString("name"));
Experiments.clearOverride(this, message.getString("name"));
break;
case "Favicon:Request":
@ -2040,7 +2040,7 @@ public class BrowserApp extends GeckoApp
break;
case "Sanitize:ClearSyncedTabs":
FennecTabsRepository.deleteNonLocalClientsAndTabs(getContext());
FennecTabsRepository.deleteNonLocalClientsAndTabs(this);
callback.sendSuccess(null);
break;
@ -2069,7 +2069,7 @@ public class BrowserApp extends GeckoApp
Telemetry.addToHistogram("FENNEC_CUSTOM_HOMEPAGE",
(Tabs.hasHomepage(this) ? 1 : 0));
final SharedPreferences prefs = GeckoSharedPrefs.forProfile(getContext());
final SharedPreferences prefs = GeckoSharedPrefs.forProfile(this);
final boolean hasCustomHomepanels =
prefs.contains(HomeConfigPrefsBackend.PREFS_CONFIG_KEY) ||
prefs.contains(HomeConfigPrefsBackend.PREFS_CONFIG_KEY_OLD);
@ -2077,7 +2077,7 @@ public class BrowserApp extends GeckoApp
Telemetry.addToHistogram("FENNEC_HOMEPANELS_CUSTOM", hasCustomHomepanels ? 1 : 0);
Telemetry.addToHistogram("FENNEC_READER_VIEW_CACHE_SIZE",
SavedReaderViewHelper.getSavedReaderViewHelper(getContext())
SavedReaderViewHelper.getSavedReaderViewHelper(this)
.getDiskSpacedUsedKB());
if (Versions.feature16Plus) {
@ -2086,7 +2086,7 @@ public class BrowserApp extends GeckoApp
}
Telemetry.addToHistogram("FENNEC_ORBOT_INSTALLED",
ContextUtils.isPackageInstalled(getContext(), "org.torproject.android") ? 1 : 0);
ContextUtils.isPackageInstalled(this, "org.torproject.android") ? 1 : 0);
break;
case "Website:AppInstalled":
@ -2094,7 +2094,7 @@ public class BrowserApp extends GeckoApp
final String startUrl = message.getString("start_url");
final String manifestPath = message.getString("manifest_path");
final LoadFaviconResult loadIconResult = FaviconDecoder
.decodeDataURI(getContext(), message.getString("icon"));
.decodeDataURI(this, message.getString("icon"));
if (loadIconResult != null) {
final Bitmap icon = loadIconResult
.getBestBitmap(GeckoAppShell.getPreferredIconSize());
@ -2831,9 +2831,9 @@ public class BrowserApp extends GeckoApp
}
private void showFirstrunPager() {
if (Experiments.isInExperimentLocal(getContext(), Experiments.ONBOARDING3_A)) {
if (Experiments.isInExperimentLocal(this, Experiments.ONBOARDING3_A)) {
Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_A);
GeckoSharedPrefs.forProfile(getContext()).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_A).apply();
GeckoSharedPrefs.forProfile(this).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_A).apply();
Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_A);
return;
}
@ -4122,7 +4122,7 @@ public class BrowserApp extends GeckoApp
// for topsites where we do not indicate that a page is an offline reader-view bookmark too.
final String pageURL;
if (!flags.contains(OnUrlOpenListener.Flags.NO_READER_VIEW)) {
pageURL = SavedReaderViewHelper.getReaderURLIfCached(getContext(), url);
pageURL = SavedReaderViewHelper.getReaderURLIfCached(this, url);
} else {
pageURL = url;
}
@ -4146,7 +4146,7 @@ public class BrowserApp extends GeckoApp
// We only use onUrlOpenInBackgroundListener for the homepanel context menus, hence
// we should always be checking whether we want the readermode version
final String pageURL = SavedReaderViewHelper.getReaderURLIfCached(getContext(), url);
final String pageURL = SavedReaderViewHelper.getReaderURLIfCached(this, url);
final boolean isPrivate = flags.contains(OnUrlOpenInBackgroundListener.Flags.PRIVATE);

Просмотреть файл

@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.content.pm.PackageManager;
@ -103,7 +104,9 @@ public class DownloadsIntegration implements BundleEventListener
int state = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
try {
state = GeckoAppShell.getContext().getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");
final PackageManager pm = GeckoAppShell.getApplicationContext()
.getPackageManager();
state = pm.getApplicationEnabledSetting("com.android.providers.downloads");
} catch (IllegalArgumentException e) {
// Download Manager package does not exist
return false;
@ -161,7 +164,9 @@ public class DownloadsIntegration implements BundleEventListener
if (useSystemDownloadManager()) {
final File f = new File(aFile);
final DownloadManager dm = (DownloadManager) GeckoAppShell.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
final DownloadManager dm = (DownloadManager)
GeckoAppShell.getApplicationContext()
.getSystemService(Context.DOWNLOAD_SERVICE);
dm.addCompletedDownload(f.getName(),
f.getName(),
true, // Media scanner should scan this
@ -170,8 +175,13 @@ public class DownloadsIntegration implements BundleEventListener
Math.max(1, f.length()), // Some versions of Android require downloads to be at least length 1
false); // Don't show a notification.
} else {
final Context context = GeckoAppShell.getContext();
final GeckoMediaScannerClient client = new GeckoMediaScannerClient(context, aFile, mimeType);
final Activity currentActivity =
GeckoActivityMonitor.getInstance().getCurrentActivity();
if (currentActivity == null) {
return;
}
final GeckoMediaScannerClient client =
new GeckoMediaScannerClient(currentActivity, aFile, mimeType);
client.connect();
}
}
@ -181,7 +191,9 @@ public class DownloadsIntegration implements BundleEventListener
return;
}
final DownloadManager dm = (DownloadManager) GeckoAppShell.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
final DownloadManager dm = (DownloadManager)
GeckoAppShell.getApplicationContext()
.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = null;
try {

Просмотреть файл

@ -67,7 +67,7 @@ public final class ThumbnailHelper {
private ByteBuffer mBuffer;
private ThumbnailHelper() {
final Resources res = GeckoAppShell.getContext().getResources();
final Resources res = GeckoAppShell.getApplicationContext().getResources();
mPendingThumbnails = new ArrayList<>();
try {

Просмотреть файл

@ -30,7 +30,7 @@ public class PromptListItem {
public Drawable mIcon;
PromptListItem(GeckoBundle aObject) {
Context context = GeckoAppShell.getContext();
final Context context = GeckoAppShell.getApplicationContext();
label = aObject.getString("label", "");
isGroup = aObject.getBoolean("isGroup");
inGroup = aObject.getBoolean("inGroup");

Просмотреть файл

@ -55,7 +55,7 @@ public class PostUpdateHandler extends BrowserAppDelegateWithReference {
final String dataDir = browserApp.getApplicationInfo().dataDir;
final SharedPreferences prefs = GeckoSharedPrefs.forApp(browserApp);
final AssetManager assetManager = browserApp.getContext().getAssets();
final AssetManager assetManager = browserApp.getAssets();
try {
final String[] assetNames = assetManager.list("features");

Просмотреть файл

@ -282,7 +282,7 @@ public class WebAppActivity extends SingleTabActivity {
return null;
}
final LoadFaviconResult loadIconResult = FaviconDecoder
.decodeDataURI(getContext(), iconStr);
.decodeDataURI(this, iconStr);
if (loadIconResult == null) {
return null;
}

Просмотреть файл

@ -24,7 +24,7 @@ Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
var geckoAppShell = JNI.LoadClass(jenv, "org.mozilla.gecko.GeckoAppShell", {
static_methods: [
{ name: "getPreferredIconSize", sig: "()I" },
{ name: "getContext", sig: "()Landroid/content/Context;" },
{ name: "getApplicationContext", sig: "()Landroid/content/Context;" },
],
});
@ -56,7 +56,7 @@ Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
{ name: "getName", sig: "()Ljava/lang/String;" },
],
});
is("org.mozilla.gecko.BrowserApp", JNI.ReadString(jenv, geckoAppShell.getContext().getClass().getName()), "class name is correct");
is("org.mozilla.gecko.GeckoApplication", JNI.ReadString(jenv, geckoAppShell.getApplicationContext().getClass().getName()), "class name is correct");
} finally {
if (jenv) {
JNI.UnloadClasses(jenv);