mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 719493 - Don't block on gecko to select a tab. r=mbrubeck
This commit is contained in:
parent
40ed5445f6
commit
e1d4fe5aa0
@ -955,7 +955,7 @@ abstract public class GeckoApp
|
||||
Tab tab = handleAddTab(message);
|
||||
Boolean selected = message.getBoolean("selected");
|
||||
if (selected)
|
||||
handleSelectTab(tab.getId());
|
||||
Tabs.getInstance().selectTab(tab.getId());
|
||||
} else if (event.equals("Tab:Close")) {
|
||||
int tabId = message.getInt("tabID");
|
||||
Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
@ -964,10 +964,9 @@ abstract public class GeckoApp
|
||||
int tabId = message.getInt("tabID");
|
||||
Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
processThumbnail(tab, null, Base64.decode(message.getString("data").substring(22), Base64.DEFAULT));
|
||||
} else if (event.equals("Tab:Selected")) {
|
||||
} else if (event.equals("Tab:Select")) {
|
||||
int tabId = message.getInt("tabID");
|
||||
Log.i(LOGTAG, "Switched to tab: " + tabId);
|
||||
handleSelectTab(tabId);
|
||||
Tabs.getInstance().selectTab(tabId);
|
||||
} else if (event.equals("Doorhanger:Add")) {
|
||||
handleDoorHanger(message);
|
||||
} else if (event.equals("Doorhanger:Remove")) {
|
||||
@ -1230,31 +1229,6 @@ abstract public class GeckoApp
|
||||
return tab;
|
||||
}
|
||||
|
||||
void handleSelectTab(int tabId) {
|
||||
final Tab tab = Tabs.getInstance().selectTab(tabId);
|
||||
if (tab == null)
|
||||
return;
|
||||
|
||||
if (tab.getURL().equals("about:home"))
|
||||
showAboutHome();
|
||||
else
|
||||
hideAboutHome();
|
||||
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
mAutoCompletePopup.hide();
|
||||
if (Tabs.getInstance().isSelectedTab(tab)) {
|
||||
mBrowserToolbar.setTitle(tab.getDisplayTitle());
|
||||
mBrowserToolbar.setFavicon(tab.getFavicon());
|
||||
mBrowserToolbar.setSecurityMode(tab.getSecurityMode());
|
||||
mBrowserToolbar.setProgressVisibility(tab.isLoading());
|
||||
mDoorHangerPopup.updatePopup();
|
||||
mBrowserToolbar.setShadowVisibility(!(tab.getURL().startsWith("about:")));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleDocumentStart(int tabId, final boolean showProgress) {
|
||||
final Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
if (tab == null)
|
||||
@ -1653,7 +1627,7 @@ abstract public class GeckoApp
|
||||
GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Tab:Added", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Tab:Close", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Tab:Selected", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Tab:Select", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Tab:ScreenshotData", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext);
|
||||
@ -1984,7 +1958,7 @@ abstract public class GeckoApp
|
||||
GeckoAppShell.unregisterGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Tab:Added", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Tab:Close", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Tab:Selected", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Tab:Select", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Tab:ScreenshotData", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
|
||||
@ -2437,7 +2411,7 @@ abstract public class GeckoApp
|
||||
JSONObject args = new JSONObject();
|
||||
try {
|
||||
args.put("url", url);
|
||||
args.put("parentId", Tabs.getInstance().getSelectedTabId());
|
||||
args.put("parentId", Tabs.getInstance().getSelectedTab().getId());
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "error building JSON arguments");
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ import android.util.Log;
|
||||
public class Tabs implements GeckoEventListener {
|
||||
private static final String LOGTAG = "GeckoTabs";
|
||||
|
||||
private static int selectedTab = -1;
|
||||
private Tab selectedTab;
|
||||
private HashMap<Integer, Tab> tabs;
|
||||
private ArrayList<Tab> order;
|
||||
private ContentResolver resolver;
|
||||
@ -97,9 +97,36 @@ public class Tabs implements GeckoEventListener {
|
||||
public Tab selectTab(int id) {
|
||||
if (!tabs.containsKey(id))
|
||||
return null;
|
||||
|
||||
selectedTab = id;
|
||||
return tabs.get(id);
|
||||
|
||||
final Tab tab = tabs.get(id);
|
||||
// This avoids a NPE below, but callers need to be careful to
|
||||
// handle this case
|
||||
if (tab == null)
|
||||
return null;
|
||||
|
||||
if (tab.getURL().equals("about:home"))
|
||||
GeckoApp.mAppContext.showAboutHome();
|
||||
else
|
||||
GeckoApp.mAppContext.hideAboutHome();
|
||||
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
GeckoApp.mAutoCompletePopup.hide();
|
||||
// Do we need to do this check?
|
||||
if (isSelectedTab(tab)) {
|
||||
GeckoApp.mBrowserToolbar.setTitle(tab.getDisplayTitle());
|
||||
GeckoApp.mBrowserToolbar.setFavicon(tab.getFavicon());
|
||||
GeckoApp.mBrowserToolbar.setSecurityMode(tab.getSecurityMode());
|
||||
GeckoApp.mBrowserToolbar.setProgressVisibility(tab.isLoading());
|
||||
GeckoApp.mDoorHangerPopup.updatePopup();
|
||||
GeckoApp.mBrowserToolbar.setShadowVisibility(!(tab.getURL().startsWith("about:")));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Pass a message to Gecko to update tab state in BrowserApp
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Selected", String.valueOf(tab.getId())));
|
||||
return selectedTab = tab;
|
||||
}
|
||||
|
||||
public int getIndexOf(Tab tab) {
|
||||
@ -114,15 +141,14 @@ public class Tabs implements GeckoEventListener {
|
||||
}
|
||||
|
||||
public Tab getSelectedTab() {
|
||||
return tabs.get(selectedTab);
|
||||
}
|
||||
|
||||
public int getSelectedTabId() {
|
||||
return selectedTab;
|
||||
}
|
||||
|
||||
public boolean isSelectedTab(Tab tab) {
|
||||
return (tab.getId() == selectedTab);
|
||||
if (selectedTab == null)
|
||||
return false;
|
||||
|
||||
return tab == selectedTab;
|
||||
}
|
||||
|
||||
public Tab getTab(int id) {
|
||||
@ -145,9 +171,7 @@ public class Tabs implements GeckoEventListener {
|
||||
if (tab == null || nextTab == null)
|
||||
return;
|
||||
|
||||
// TODO: Clean up the Tab:Select/Tab:Selected message passing so that we can
|
||||
// immediately update the Java UI here (bug 719493)
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", String.valueOf(nextTab.getId())));
|
||||
selectTab(nextTab.getId());
|
||||
|
||||
int tabId = tab.getId();
|
||||
removeTab(tabId);
|
||||
|
@ -38,19 +38,15 @@
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Build;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
@ -162,7 +158,7 @@ public class TabsTray extends Activity implements GeckoApp.OnTabsChangedListener
|
||||
|
||||
mOnInfoClickListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", v.getTag().toString()));
|
||||
Tabs.getInstance().selectTab(Integer.parseInt((String) v.getTag()));
|
||||
finishActivity();
|
||||
}
|
||||
};
|
||||
@ -182,17 +178,14 @@ public class TabsTray extends Activity implements GeckoApp.OnTabsChangedListener
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mTabs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getItem(int position) {
|
||||
return mTabs.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
@ -223,7 +216,6 @@ public class TabsTray extends Activity implements GeckoApp.OnTabsChangedListener
|
||||
title.setText(tab.getDisplayTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
convertView = mInflater.inflate(R.layout.tabs_row, null);
|
||||
|
||||
|
@ -207,7 +207,7 @@ var BrowserApp = {
|
||||
|
||||
Services.obs.addObserver(this, "Tab:Add", false);
|
||||
Services.obs.addObserver(this, "Tab:Load", false);
|
||||
Services.obs.addObserver(this, "Tab:Select", false);
|
||||
Services.obs.addObserver(this, "Tab:Selected", false);
|
||||
Services.obs.addObserver(this, "Tab:Closed", false);
|
||||
Services.obs.addObserver(this, "Tab:Screenshot", false);
|
||||
Services.obs.addObserver(this, "Session:Back", false);
|
||||
@ -512,23 +512,33 @@ var BrowserApp = {
|
||||
tab.screenshot(width, height);
|
||||
},
|
||||
|
||||
// Use this method to select a tab from JS. This method sends a message
|
||||
// to Java to select the tab in the Java UI (we'll get a Tab:Selected message
|
||||
// back from Java when that happens).
|
||||
selectTab: function selectTab(aTab) {
|
||||
if (aTab != null) {
|
||||
if (!aTab) {
|
||||
Cu.reportError("Error trying to select tab (tab doesn't exist)");
|
||||
return;
|
||||
}
|
||||
|
||||
let message = {
|
||||
gecko: {
|
||||
type: "Tab:Select",
|
||||
tabID: aTab.id
|
||||
}
|
||||
};
|
||||
sendMessageToJava(message);
|
||||
},
|
||||
|
||||
// This method updates the state in BrowserApp after a tab has been selected
|
||||
// in the Java UI.
|
||||
_handleTabSelected: function _handleTabSelected(aTab) {
|
||||
this.selectedTab = aTab;
|
||||
aTab.active = true;
|
||||
let message = {
|
||||
gecko: {
|
||||
type: "Tab:Selected",
|
||||
tabID: aTab.id
|
||||
}
|
||||
};
|
||||
|
||||
let evt = document.createEvent("UIEvents");
|
||||
evt.initUIEvent("TabSelect", true, false, window, null);
|
||||
aTab.browser.dispatchEvent(evt);
|
||||
|
||||
sendMessageToJava(message);
|
||||
}
|
||||
},
|
||||
|
||||
quit: function quit() {
|
||||
@ -859,8 +869,8 @@ var BrowserApp = {
|
||||
this.addTab(url, params);
|
||||
else
|
||||
this.loadURI(url, browser, params);
|
||||
} else if (aTopic == "Tab:Select") {
|
||||
this.selectTab(this.getTabForId(parseInt(aData)));
|
||||
} else if (aTopic == "Tab:Selected") {
|
||||
this._handleTabSelected(this.getTabForId(parseInt(aData)));
|
||||
} else if (aTopic == "Tab:Closed") {
|
||||
this._handleTabClosed(this.getTabForId(parseInt(aData)));
|
||||
} else if (aTopic == "Tab:Screenshot") {
|
||||
|
Loading…
Reference in New Issue
Block a user