| LEFT | RIGHT |
| 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- |
| 2 * This Source Code Form is subject to the terms of the Mozilla Public | 2 * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | 5 |
| 6 package org.mozilla.gecko; | 6 package org.mozilla.gecko; |
| 7 | 7 |
| 8 import java.io.File; | 8 import java.io.File; |
| 9 import java.io.FileNotFoundException; | 9 import java.io.FileNotFoundException; |
| 10 import java.lang.reflect.Method; | 10 import java.lang.reflect.Method; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 Log.d(LOGTAG, "BrowserApp.onTabChanged: " + tab.getId() + ": " + msg); | 246 Log.d(LOGTAG, "BrowserApp.onTabChanged: " + tab.getId() + ": " + msg); |
| 247 switch(msg) { | 247 switch(msg) { |
| 248 case LOCATION_CHANGE: | 248 case LOCATION_CHANGE: |
| 249 if (Tabs.getInstance().isSelectedTab(tab)) { | 249 if (Tabs.getInstance().isSelectedTab(tab)) { |
| 250 maybeCancelFaviconLoad(tab); | 250 maybeCancelFaviconLoad(tab); |
| 251 } | 251 } |
| 252 // fall through | 252 // fall through |
| 253 case SELECTED: | 253 case SELECTED: |
| 254 if (Tabs.getInstance().isSelectedTab(tab)) { | 254 if (Tabs.getInstance().isSelectedTab(tab)) { |
| 255 updateHomePagerForTab(tab); | 255 updateHomePagerForTab(tab); |
| 256 if (mMenu != null) |
| 257 org.adblockplus.browser.BrowserAppUtils.updateBlockAdsMe
nuItem( |
| 258 mMenu.findItem(R.id.block_ads)); |
| 256 } | 259 } |
| 257 break; | 260 break; |
| 258 case START: | 261 case START: |
| 259 if (Tabs.getInstance().isSelectedTab(tab)) { | 262 if (Tabs.getInstance().isSelectedTab(tab)) { |
| 260 invalidateOptionsMenu(); | 263 invalidateOptionsMenu(); |
| 261 | 264 |
| 262 if (mDynamicToolbar.isEnabled()) { | 265 if (mDynamicToolbar.isEnabled()) { |
| 263 mDynamicToolbar.setVisible(true, VisibilityTransition.AN
IMATE); | 266 mDynamicToolbar.setVisible(true, VisibilityTransition.AN
IMATE); |
| 264 } | 267 } |
| 265 } | 268 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 "Feedback:MaybeLater", | 555 "Feedback:MaybeLater", |
| 553 "Feedback:OpenPlayStore", | 556 "Feedback:OpenPlayStore", |
| 554 "Menu:Add", | 557 "Menu:Add", |
| 555 "Menu:Remove", | 558 "Menu:Remove", |
| 556 "Reader:ListStatusRequest", | 559 "Reader:ListStatusRequest", |
| 557 "Reader:Removed", | 560 "Reader:Removed", |
| 558 "Reader:Share", | 561 "Reader:Share", |
| 559 "Settings:Show", | 562 "Settings:Show", |
| 560 "Telemetry:Gather", | 563 "Telemetry:Gather", |
| 561 "Updater:Launch", | 564 "Updater:Launch", |
| 562 "BrowserToolbar:Visibility", | 565 "BrowserToolbar:Visibility"); |
| 563 "BlockAds:Update"); | |
| 564 | 566 |
| 565 Distribution distribution = Distribution.init(this); | 567 Distribution distribution = Distribution.init(this); |
| 566 | 568 |
| 567 // Init suggested sites engine in BrowserDB. | 569 // Init suggested sites engine in BrowserDB. |
| 568 final SuggestedSites suggestedSites = new SuggestedSites(appContext, dis
tribution); | 570 final SuggestedSites suggestedSites = new SuggestedSites(appContext, dis
tribution); |
| 569 BrowserDB.setSuggestedSites(suggestedSites); | 571 BrowserDB.setSuggestedSites(suggestedSites); |
| 570 | 572 |
| 571 JavaAddonManager.getInstance().init(appContext); | 573 JavaAddonManager.getInstance().init(appContext); |
| 572 mSharedPreferencesHelper = new SharedPreferencesHelper(appContext); | 574 mSharedPreferencesHelper = new SharedPreferencesHelper(appContext); |
| 573 mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext); | 575 mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 "Feedback:MaybeLater", | 993 "Feedback:MaybeLater", |
| 992 "Feedback:OpenPlayStore", | 994 "Feedback:OpenPlayStore", |
| 993 "Menu:Add", | 995 "Menu:Add", |
| 994 "Menu:Remove", | 996 "Menu:Remove", |
| 995 "Reader:ListStatusRequest", | 997 "Reader:ListStatusRequest", |
| 996 "Reader:Removed", | 998 "Reader:Removed", |
| 997 "Reader:Share", | 999 "Reader:Share", |
| 998 "Settings:Show", | 1000 "Settings:Show", |
| 999 "Telemetry:Gather", | 1001 "Telemetry:Gather", |
| 1000 "Updater:Launch", | 1002 "Updater:Launch", |
| 1001 "BrowserToolbar:Visibility", | 1003 "BrowserToolbar:Visibility"); |
| 1002 "BlockAds:Update"); | |
| 1003 | 1004 |
| 1004 if (AppConstants.MOZ_ANDROID_BEAM) { | 1005 if (AppConstants.MOZ_ANDROID_BEAM) { |
| 1005 NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); | 1006 NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); |
| 1006 if (nfc != null) { | 1007 if (nfc != null) { |
| 1007 // null this out even though the docs say it's not needed, | 1008 // null this out even though the docs say it's not needed, |
| 1008 // because the source code looks like it will only do this | 1009 // because the source code looks like it will only do this |
| 1009 // automatically on API 14+ | 1010 // automatically on API 14+ |
| 1010 nfc.setNdefPushMessageCallback(null, this); | 1011 nfc.setNdefPushMessageCallback(null, this); |
| 1011 } | 1012 } |
| 1012 } | 1013 } |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 Telemetry.HistogramAdd("FENNEC_THUMBNAILS_COUNT", | 1388 Telemetry.HistogramAdd("FENNEC_THUMBNAILS_COUNT", |
| 1388 BrowserDB.getCount(getContentResolver(), "thumbnails")); | 1389 BrowserDB.getCount(getContentResolver(), "thumbnails")); |
| 1389 Telemetry.HistogramAdd("FENNEC_READING_LIST_COUNT", | 1390 Telemetry.HistogramAdd("FENNEC_READING_LIST_COUNT", |
| 1390 BrowserDB.getCount(getContentResolver(), "readinglist")); | 1391 BrowserDB.getCount(getContentResolver(), "readinglist")); |
| 1391 Telemetry.HistogramAdd("BROWSER_IS_USER_DEFAULT", (isDefaultBrowser(
) ? 1 : 0)); | 1392 Telemetry.HistogramAdd("BROWSER_IS_USER_DEFAULT", (isDefaultBrowser(
) ? 1 : 0)); |
| 1392 } else if ("Updater:Launch".equals(event)) { | 1393 } else if ("Updater:Launch".equals(event)) { |
| 1393 handleUpdaterLaunch(); | 1394 handleUpdaterLaunch(); |
| 1394 | 1395 |
| 1395 } else if ("BrowserToolbar:Visibility".equals(event)) { | 1396 } else if ("BrowserToolbar:Visibility".equals(event)) { |
| 1396 setBrowserToolbarVisible(message.getBoolean("visible")); | 1397 setBrowserToolbarVisible(message.getBoolean("visible")); |
| 1397 | |
| 1398 } else if ("BlockAds:Update".equals(event)) { | |
| 1399 final Menu menu = mMenu; | |
| 1400 final boolean enabled = message.getBoolean("canBlockAds"); | |
| 1401 final boolean checked = message.getBoolean("blockAds"); | |
| 1402 ThreadUtils.postToUiThread(new Runnable() { | |
| 1403 @Override | |
| 1404 public void run() { | |
| 1405 if (menu == null) | |
| 1406 return; | |
| 1407 final MenuItem blockAdsItem = menu.findItem(R.id.block_a
ds); | |
| 1408 blockAdsItem.setEnabled(enabled); | |
| 1409 blockAdsItem.setChecked(checked); | |
| 1410 } | |
| 1411 }); | |
| 1412 | |
| 1413 | 1398 |
| 1414 } else { | 1399 } else { |
| 1415 super.handleMessage(event, message, callback); | 1400 super.handleMessage(event, message, callback); |
| 1416 } | 1401 } |
| 1417 } | 1402 } |
| 1418 | 1403 |
| 1419 /** | 1404 /** |
| 1420 * Use a dummy Intent to do a default browser check. | 1405 * Use a dummy Intent to do a default browser check. |
| 1421 * | 1406 * |
| 1422 * @return true if this package is the default browser on this device, false
otherwise. | 1407 * @return true if this package is the default browser on this device, false
otherwise. |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2292 } | 2277 } |
| 2293 | 2278 |
| 2294 return null; | 2279 return null; |
| 2295 } | 2280 } |
| 2296 | 2281 |
| 2297 /** | 2282 /** |
| 2298 * Add the provided item to the provided menu, which should be | 2283 * Add the provided item to the provided menu, which should be |
| 2299 * the root (mMenu). | 2284 * the root (mMenu). |
| 2300 */ | 2285 */ |
| 2301 private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info
) { | 2286 private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info
) { |
| 2287 // Adblock Browser doesn't support add-ons, so the only menu item that |
| 2288 // could be added is the one for whitelisting the current domain added |
| 2289 // by ABP - Adblock Browser has its own item for that. |
| 2290 if (true) |
| 2291 return; |
| 2292 |
| 2302 info.added = true; | 2293 info.added = true; |
| 2303 | 2294 |
| 2304 final Menu destination; | 2295 final Menu destination; |
| 2305 if (info.parent == 0) { | 2296 if (info.parent == 0) { |
| 2306 destination = menu; | 2297 destination = menu; |
| 2307 } else if (info.parent == GECKO_TOOLS_MENU) { | 2298 } else if (info.parent == GECKO_TOOLS_MENU) { |
| 2308 MenuItem tools = menu.findItem(R.id.tools); | 2299 MenuItem tools = menu.findItem(R.id.tools); |
| 2309 destination = tools != null ? tools.getSubMenu() : menu; | 2300 destination = tools != null ? tools.getSubMenu() : menu; |
| 2310 } else { | 2301 } else { |
| 2311 MenuItem parent = menu.findItem(info.parent); | 2302 MenuItem parent = menu.findItem(info.parent); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2451 addAddonMenuItemToMenu(mMenu, item); | 2442 addAddonMenuItemToMenu(mMenu, item); |
| 2452 } | 2443 } |
| 2453 } | 2444 } |
| 2454 | 2445 |
| 2455 // Action providers are available only ICS+. | 2446 // Action providers are available only ICS+. |
| 2456 if (Versions.feature14Plus) { | 2447 if (Versions.feature14Plus) { |
| 2457 GeckoMenuItem share = (GeckoMenuItem) mMenu.findItem(R.id.share); | 2448 GeckoMenuItem share = (GeckoMenuItem) mMenu.findItem(R.id.share); |
| 2458 GeckoActionProvider provider = GeckoActionProvider.getForType(GeckoA
ctionProvider.DEFAULT_MIME_TYPE, this); | 2449 GeckoActionProvider provider = GeckoActionProvider.getForType(GeckoA
ctionProvider.DEFAULT_MIME_TYPE, this); |
| 2459 share.setActionProvider(provider); | 2450 share.setActionProvider(provider); |
| 2460 } | 2451 } |
| 2452 |
| 2453 org.adblockplus.browser.BrowserAppUtils.updateBlockAdsMenuItem( |
| 2454 mMenu.findItem(R.id.block_ads)); |
| 2461 | 2455 |
| 2462 return true; | 2456 return true; |
| 2463 } | 2457 } |
| 2464 | 2458 |
| 2465 @Override | 2459 @Override |
| 2466 public void openOptionsMenu() { | 2460 public void openOptionsMenu() { |
| 2467 // Disable menu access (for hardware buttons) when the software menu but
ton is inaccessible. | 2461 // Disable menu access (for hardware buttons) when the software menu but
ton is inaccessible. |
| 2468 if (mBrowserToolbar.isEditing()) { | 2462 if (mBrowserToolbar.isEditing()) { |
| 2469 return; | 2463 return; |
| 2470 } | 2464 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2795 args.put("desktopMode", !item.isChecked()); | 2789 args.put("desktopMode", !item.isChecked()); |
| 2796 args.put("tabId", selectedTab.getId()); | 2790 args.put("tabId", selectedTab.getId()); |
| 2797 } catch (JSONException e) { | 2791 } catch (JSONException e) { |
| 2798 Log.e(LOGTAG, "error building json arguments"); | 2792 Log.e(LOGTAG, "error building json arguments"); |
| 2799 } | 2793 } |
| 2800 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Desk
topMode:Change", args.toString())); | 2794 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Desk
topMode:Change", args.toString())); |
| 2801 return true; | 2795 return true; |
| 2802 } | 2796 } |
| 2803 | 2797 |
| 2804 if (itemId == R.id.block_ads) { | 2798 if (itemId == R.id.block_ads) { |
| 2805 Tab selectedTab = Tabs.getInstance().getSelectedTab(); | 2799 org.adblockplus.browser.BrowserAppUtils.updateCurrentTabWhitelisting
(item); |
| 2806 if (selectedTab == null) | |
| 2807 return true; | |
| 2808 JSONObject args = new JSONObject(); | |
| 2809 try { | |
| 2810 args.put("blockAds", !item.isChecked()); | |
| 2811 args.put("url", selectedTab.getURL()); | |
| 2812 } catch (JSONException e) { | |
| 2813 Log.e(LOGTAG, "error building json arguments"); | |
| 2814 } | |
| 2815 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Bloc
kAds:Change", args.toString())); | |
| 2816 return true; | 2800 return true; |
| 2817 } | 2801 } |
| 2818 | 2802 |
| 2819 if (itemId == R.id.new_tab) { | 2803 if (itemId == R.id.new_tab) { |
| 2820 addTab(); | 2804 addTab(); |
| 2821 return true; | 2805 return true; |
| 2822 } | 2806 } |
| 2823 | 2807 |
| 2824 if (itemId == R.id.new_private_tab) { | 2808 if (itemId == R.id.new_private_tab) { |
| 2825 addPrivateTab(); | 2809 addPrivateTab(); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3197 final SessionInformation previ
ousSession) { | 3181 final SessionInformation previ
ousSession) { |
| 3198 return new BrowserHealthRecorder(context, | 3182 return new BrowserHealthRecorder(context, |
| 3199 GeckoSharedPrefs.forApp(context), | 3183 GeckoSharedPrefs.forApp(context), |
| 3200 profilePath, | 3184 profilePath, |
| 3201 dispatcher, | 3185 dispatcher, |
| 3202 osLocale, | 3186 osLocale, |
| 3203 appLocale, | 3187 appLocale, |
| 3204 previousSession); | 3188 previousSession); |
| 3205 } | 3189 } |
| 3206 } | 3190 } |
| LEFT | RIGHT |