Bug 1146589 - Ensure that tab opened with "open now" action is selected and visible when fennec loads (r=mcomella)

This commit is contained in:
Martyn Haigh 2015-03-30 10:45:03 +01:00
parent 3a907f34e2
commit 5cf5532037
4 changed files with 44 additions and 7 deletions

View File

@ -912,7 +912,7 @@ public class BrowserApp extends GeckoApp
@Override
public void run() {
if (TabQueueHelper.shouldOpenTabQueueUrls(BrowserApp.this)) {
TabQueueHelper.openQueuedUrls(BrowserApp.this, mProfile, TabQueueHelper.FILE_NAME);
TabQueueHelper.openQueuedUrls(BrowserApp.this, mProfile, TabQueueHelper.FILE_NAME, false);
}
}
});
@ -3428,7 +3428,7 @@ public class BrowserApp extends GeckoApp
// If the user has clicked the tab queue notification then load the tabs.
if(AppConstants.NIGHTLY_BUILD && AppConstants.MOZ_ANDROID_TAB_QUEUE && mInitialized && isTabQueueAction) {
int queuedTabCount = TabQueueHelper.getTabQueueLength(this);
TabQueueHelper.openQueuedUrls(this, mProfile, TabQueueHelper.FILE_NAME);
TabQueueHelper.openQueuedUrls(this, mProfile, TabQueueHelper.FILE_NAME, false);
// If there's more than one tab then also show the tabs panel.
if (queuedTabCount > 1) {

View File

@ -46,6 +46,7 @@ import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.preferences.ClearOnShutdownPref;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.prompts.PromptService;
import org.mozilla.gecko.tabqueue.TabQueueHelper;
import org.mozilla.gecko.updater.UpdateServiceHelper;
import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.util.ActivityUtils;
@ -1827,10 +1828,38 @@ public abstract class GeckoApp
String uri = intent.getDataString();
Tabs.getInstance().loadUrl(uri);
} else if (Intent.ACTION_VIEW.equals(action)) {
String uri = intent.getDataString();
Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB |
Tabs.LOADURL_USER_ENTERED |
Tabs.LOADURL_EXTERNAL);
// We need to ensure that if we receive a VIEW action and there are tabs queued then the
// site loaded from the intent is op top (last loaded) and selected with all other tabs
// being opened behind it. We process the tab queue first and request a callback from the JS - the
// listener will open the url from the intent as normal when the tab queue has been processed.
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (AppConstants.NIGHTLY_BUILD && AppConstants.MOZ_ANDROID_TAB_QUEUE
&& TabQueueHelper.shouldOpenTabQueueUrls(GeckoApp.this)) {
EventDispatcher.getInstance().registerGeckoThreadListener(new NativeEventListener() {
@Override
public void handleMessage(String event, NativeJSObject message, EventCallback callback) {
if ("Tabs:TabsOpened".equals(event)) {
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Tabs:TabsOpened");
String uri = intent.getDataString();
Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB |
Tabs.LOADURL_USER_ENTERED |
Tabs.LOADURL_EXTERNAL);
}
}
}, "Tabs:TabsOpened");
TabQueueHelper.openQueuedUrls(GeckoApp.this, mProfile, TabQueueHelper.FILE_NAME, true);
} else {
String uri = intent.getDataString();
Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB |
Tabs.LOADURL_USER_ENTERED |
Tabs.LOADURL_EXTERNAL);
}
}
});
} else if (ACTION_HOMESCREEN_SHORTCUT.equals(action)) {
String uri = getURIFromIntent(intent);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBookmarkLoadEvent(uri));

View File

@ -111,7 +111,7 @@ public class TabQueueHelper {
return prefs.getInt(PREF_TAB_QUEUE_COUNT, 0);
}
public static void openQueuedUrls(final Context context, final GeckoProfile profile, final String filename) {
public static void openQueuedUrls(final Context context, final GeckoProfile profile, final String filename, boolean shouldPerformJavaScriptCallback) {
ThreadUtils.assertNotOnUiThread();
// Remove the notification.
@ -129,6 +129,7 @@ public class TabQueueHelper {
JSONObject data = new JSONObject();
try {
data.put("urls", jsonArray);
data.put("shouldNotifyTabsOpenedToJava", shouldPerformJavaScriptCallback);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tabs:OpenMultiple", data.toString()));
} catch (JSONException e) {
// Don't exit early as we perform cleanup at the end of this function.

View File

@ -160,7 +160,14 @@ SessionStore.prototype = {
}
case "Tabs:OpenMultiple": {
let data = JSON.parse(aData);
this._openTabs(data);
if (data.shouldNotifyTabsOpenedToJava) {
Messaging.sendRequest({
type: "Tabs:TabsOpened"
});
}
break;
}
case "application-background":