Index: mobile/android/base/BrowserApp.java |
=================================================================== |
--- a/mobile/android/base/BrowserApp.java |
+++ b/mobile/android/base/BrowserApp.java |
@@ -559,7 +559,8 @@ |
"Settings:Show", |
"Telemetry:Gather", |
"Updater:Launch", |
- "BrowserToolbar:Visibility"); |
+ "BrowserToolbar:Visibility", |
+ "BlockAds:Update"); |
Distribution distribution = Distribution.init(this); |
@@ -997,7 +998,8 @@ |
"Settings:Show", |
"Telemetry:Gather", |
"Updater:Launch", |
- "BrowserToolbar:Visibility"); |
+ "BrowserToolbar:Visibility", |
+ "BlockAds:Update"); |
if (AppConstants.MOZ_ANDROID_BEAM) { |
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); |
@@ -1393,6 +1395,22 @@ |
} else if ("BrowserToolbar:Visibility".equals(event)) { |
setBrowserToolbarVisible(message.getBoolean("visible")); |
+ } else if ("BlockAds:Update".equals(event)) { |
+ final Menu menu = mMenu; |
+ final boolean enabled = message.getBoolean("canBlockAds"); |
+ final boolean checked = message.getBoolean("blockAds"); |
+ ThreadUtils.postToUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ if (menu == null) |
+ return; |
+ final MenuItem blockAdsItem = menu.findItem(R.id.block_ads); |
+ blockAdsItem.setEnabled(enabled); |
+ blockAdsItem.setChecked(checked); |
+ } |
+ }); |
+ |
+ |
} else { |
super.handleMessage(event, message, callback); |
} |
@@ -2783,6 +2801,21 @@ |
return true; |
} |
+ if (itemId == R.id.block_ads) { |
+ Tab selectedTab = Tabs.getInstance().getSelectedTab(); |
+ if (selectedTab == null) |
+ return true; |
+ JSONObject args = new JSONObject(); |
+ try { |
+ args.put("blockAds", !item.isChecked()); |
+ args.put("url", selectedTab.getURL()); |
+ } catch (JSONException e) { |
+ Log.e(LOGTAG, "error building json arguments"); |
+ } |
+ GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("BlockAds:Change", args.toString())); |
+ return true; |
+ } |
+ |
if (itemId == R.id.new_tab) { |
addTab(); |
return true; |