mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 797075 - Part 1: loadUrl() cleanup. r=mfinkle
--HG-- extra : rebase_source : 05466908b2148224b2ff45c6eebd08bcf6dc5f18
This commit is contained in:
parent
08b68c64f8
commit
747dcba812
@ -561,7 +561,7 @@ public class AboutHomeContent extends ScrollView
|
||||
|
||||
container.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mActivity.loadUrlInTab(url);
|
||||
Tabs.getInstance().loadUrlInTab(url);
|
||||
}
|
||||
});
|
||||
|
||||
@ -578,7 +578,7 @@ public class AboutHomeContent extends ScrollView
|
||||
mLastTabs.setOnMoreTextClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
for (String url : lastTabUrlsList)
|
||||
mActivity.loadUrlInTab(url);
|
||||
Tabs.getInstance().loadUrlInTab(url);
|
||||
}
|
||||
});
|
||||
mLastTabs.show();
|
||||
|
@ -519,7 +519,7 @@ public class AwesomeBar extends GeckoActivity {
|
||||
break;
|
||||
}
|
||||
|
||||
GeckoApp.mAppContext.loadUrl(url, AwesomeBar.Target.NEW_TAB);
|
||||
Tabs.getInstance().loadUrl(url, Tabs.LOADURL_NEW_TAB);
|
||||
Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
|
@ -16,9 +16,16 @@ class AwesomebarResultHandler implements ActivityResultHandler {
|
||||
String url = data.getStringExtra(AwesomeBar.URL_KEY);
|
||||
AwesomeBar.Target target = AwesomeBar.Target.valueOf(data.getStringExtra(AwesomeBar.TARGET_KEY));
|
||||
String searchEngine = data.getStringExtra(AwesomeBar.SEARCH_KEY);
|
||||
boolean userEntered = data.getBooleanExtra(AwesomeBar.USER_ENTERED_KEY, false);
|
||||
if (url != null && url.length() > 0)
|
||||
GeckoApp.mAppContext.loadRequest(url, target, searchEngine, userEntered);
|
||||
if (url != null && url.length() > 0) {
|
||||
int flags = Tabs.LOADURL_NONE;
|
||||
if (target == AwesomeBar.Target.NEW_TAB) {
|
||||
flags |= Tabs.LOADURL_NEW_TAB;
|
||||
}
|
||||
if (data.getBooleanExtra(AwesomeBar.USER_ENTERED_KEY, false)) {
|
||||
flags |= Tabs.LOADURL_USER_ENTERED;
|
||||
}
|
||||
Tabs.getInstance().loadUrl(url, searchEngine, -1, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,12 +190,6 @@ abstract public class BrowserApp extends GeckoApp
|
||||
super.onStatePurged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRequest(String url, AwesomeBar.Target target, String searchEngine, boolean userEntered) {
|
||||
mBrowserToolbar.setTitle(url);
|
||||
super.loadRequest(url, target, searchEngine, userEntered);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -636,7 +630,7 @@ abstract public class BrowserApp extends GeckoApp
|
||||
mAboutHomeContent.setUriLoadCallback(new AboutHomeContent.UriLoadCallback() {
|
||||
public void callback(String url) {
|
||||
mBrowserToolbar.setProgressVisibility(true);
|
||||
loadUrl(url, AwesomeBar.Target.CURRENT_TAB);
|
||||
Tabs.getInstance().loadUrl(url);
|
||||
}
|
||||
});
|
||||
mAboutHomeContent.setLoadCompleteCallback(new AboutHomeContent.VoidCallback() {
|
||||
@ -874,13 +868,13 @@ abstract public class BrowserApp extends GeckoApp
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.addons:
|
||||
loadUrlInTab("about:addons");
|
||||
Tabs.getInstance().loadUrlInTab("about:addons");
|
||||
return true;
|
||||
case R.id.downloads:
|
||||
loadUrlInTab("about:downloads");
|
||||
Tabs.getInstance().loadUrlInTab("about:downloads");
|
||||
return true;
|
||||
case R.id.apps:
|
||||
loadUrlInTab("about:apps");
|
||||
Tabs.getInstance().loadUrlInTab("about:apps");
|
||||
return true;
|
||||
case R.id.char_encoding:
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
|
||||
@ -938,7 +932,7 @@ abstract public class BrowserApp extends GeckoApp
|
||||
@Override
|
||||
public void onPostExecute(Boolean shouldShowFeedbackPage) {
|
||||
if (shouldShowFeedbackPage)
|
||||
loadUrlInTab("about:feedback");
|
||||
Tabs.getInstance().loadUrlInTab("about:feedback");
|
||||
}
|
||||
}).execute();
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
|
||||
URLSpan linkSpan = new URLSpan(linkUrl) {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mActivity.loadUrlInTab(this.getURL());
|
||||
Tabs.getInstance().loadUrlInTab(this.getURL());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1930,7 +1930,7 @@ abstract public class GeckoApp
|
||||
}
|
||||
else if (ACTION_LOAD.equals(action)) {
|
||||
String uri = intent.getDataString();
|
||||
loadUrl(uri, AwesomeBar.Target.CURRENT_TAB);
|
||||
Tabs.getInstance().loadUrl(uri);
|
||||
}
|
||||
else if (Intent.ACTION_VIEW.equals(action)) {
|
||||
String uri = intent.getDataString();
|
||||
@ -2458,62 +2458,6 @@ abstract public class GeckoApp
|
||||
}
|
||||
}
|
||||
|
||||
// If searchEngine is provided, url will be used as the search query.
|
||||
// Otherwise, the url is loaded.
|
||||
protected void loadRequest(String url, AwesomeBar.Target target, String searchEngine, boolean userEntered) {
|
||||
Log.d(LOGTAG, target.name());
|
||||
JSONObject args = new JSONObject();
|
||||
try {
|
||||
args.put("url", url);
|
||||
args.put("engine", searchEngine);
|
||||
args.put("userEntered", userEntered);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "error building JSON arguments");
|
||||
}
|
||||
|
||||
if (target == AwesomeBar.Target.NEW_TAB) {
|
||||
Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
|
||||
} else {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Load", args.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUrl(String url) {
|
||||
loadRequest(url, AwesomeBar.Target.CURRENT_TAB, null, false);
|
||||
}
|
||||
|
||||
public void loadUrl(String url, AwesomeBar.Target target) {
|
||||
loadRequest(url, target, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the url as a new tab, and mark the selected tab as its "parent".
|
||||
* If the url is already open in a tab, the existing tab is selected.
|
||||
* Use this for tabs opened by the browser chrome, so users can press the
|
||||
* "Back" button to return to the previous tab.
|
||||
*/
|
||||
public void loadUrlInTab(String url) {
|
||||
Tabs tabsInstance = Tabs.getInstance();
|
||||
Iterable<Tab> tabs = tabsInstance.getTabsInOrder();
|
||||
for (Tab tab : tabs) {
|
||||
if (url.equals(tab.getURL())) {
|
||||
tabsInstance.selectTab(tab.getId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject args = new JSONObject();
|
||||
try {
|
||||
args.put("url", url);
|
||||
args.put("parentId", tabsInstance.getSelectedTab().getId());
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "error building JSON arguments");
|
||||
}
|
||||
Log.i(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
|
||||
}
|
||||
|
||||
public LayerView getLayerView() {
|
||||
return mLayerView;
|
||||
}
|
||||
@ -2701,7 +2645,7 @@ abstract public class GeckoApp
|
||||
case R.id.pasteandgo: {
|
||||
String text = GeckoAppShell.getClipboardText();
|
||||
if (text != null && !TextUtils.isEmpty(text)) {
|
||||
loadUrl(text, AwesomeBar.Target.CURRENT_TAB);
|
||||
Tabs.getInstance().loadUrl(text);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class LinkPreference extends Preference {
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
GeckoApp.mAppContext.loadUrlInTab(mUrl);
|
||||
Tabs.getInstance().loadUrlInTab(mUrl);
|
||||
callChangeListener(mUrl);
|
||||
}
|
||||
}
|
||||
|
@ -454,7 +454,7 @@ public final class Tab {
|
||||
return;
|
||||
|
||||
mEnteringReaderMode = true;
|
||||
GeckoApp.mAppContext.loadUrl(ReaderModeUtils.getAboutReaderForUrl(getURL(), mId, mReadingListItem));
|
||||
Tabs.getInstance().loadUrl(ReaderModeUtils.getAboutReaderForUrl(getURL(), mId, mReadingListItem));
|
||||
}
|
||||
|
||||
public boolean isEnteringReaderMode() {
|
||||
|
@ -33,6 +33,10 @@ public class Tabs implements GeckoEventListener {
|
||||
// Keeps track of how much has happened since we last updated our persistent tab store.
|
||||
private volatile int mScore = 0;
|
||||
|
||||
public static final int LOADURL_NONE = 0;
|
||||
public static final int LOADURL_NEW_TAB = 1;
|
||||
public static final int LOADURL_USER_ENTERED = 2;
|
||||
|
||||
private static final int SCORE_INCREMENT_TAB_LOCATION_CHANGE = 5;
|
||||
private static final int SCORE_INCREMENT_TAB_SELECTED = 10;
|
||||
private static final int SCORE_THRESHOLD = 30;
|
||||
@ -40,7 +44,6 @@ public class Tabs implements GeckoEventListener {
|
||||
private GeckoApp mActivity;
|
||||
|
||||
private Tabs() {
|
||||
|
||||
registerEventListener("SessionHistory:New");
|
||||
registerEventListener("SessionHistory:Back");
|
||||
registerEventListener("SessionHistory:Forward");
|
||||
@ -65,7 +68,7 @@ public class Tabs implements GeckoEventListener {
|
||||
return mTabs.size();
|
||||
}
|
||||
|
||||
public Tab addTab(JSONObject params) throws JSONException {
|
||||
private Tab addTab(JSONObject params) throws JSONException {
|
||||
int id = params.getInt("tabID");
|
||||
if (mTabs.containsKey(id))
|
||||
return mTabs.get(id);
|
||||
@ -412,4 +415,69 @@ public class Tabs implements GeckoEventListener {
|
||||
private void registerEventListener(String event) {
|
||||
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a tab with the given URL in the currently selected tab.
|
||||
*
|
||||
* @param url URL of page to load, or search term used if searchEngine is given
|
||||
*/
|
||||
public void loadUrl(String url) {
|
||||
loadUrl(url, LOADURL_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a tab with the given URL.
|
||||
*
|
||||
* @param url URL of page to load, or search term used if searchEngine is given
|
||||
* @param flags flags used to load tab
|
||||
*/
|
||||
public void loadUrl(String url, int flags) {
|
||||
loadUrl(url, null, -1, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a tab with the given URL.
|
||||
*
|
||||
* @param url URL of page to load, or search term used if searchEngine is given
|
||||
* @param searchEngine if given, the search engine with this name is used
|
||||
* to search for the url string; if null, the URL is loaded directly
|
||||
* @param parentId ID of this tab's parent, or -1 if it has no parent
|
||||
* @param flags flags used to load tab
|
||||
*/
|
||||
public void loadUrl(String url, String searchEngine, int parentId, int flags) {
|
||||
JSONObject args = new JSONObject();
|
||||
try {
|
||||
args.put("url", url);
|
||||
args.put("engine", searchEngine);
|
||||
args.put("parentId", parentId);
|
||||
args.put("userEntered", (flags & LOADURL_USER_ENTERED) != 0);
|
||||
args.put("newTab", (flags & LOADURL_NEW_TAB) != 0);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "error building JSON arguments");
|
||||
}
|
||||
|
||||
Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Load");
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Load", args.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the url as a new tab, and mark the selected tab as its "parent".
|
||||
*
|
||||
* If the url is already open in a tab, the existing tab is selected.
|
||||
* Use this for tabs opened by the browser chrome, so users can press the
|
||||
* "Back" button to return to the previous tab.
|
||||
*
|
||||
* @param url URL of page to load
|
||||
*/
|
||||
public void loadUrlInTab(String url) {
|
||||
Iterable<Tab> tabs = getTabsInOrder();
|
||||
for (Tab tab : tabs) {
|
||||
if (url.equals(tab.getURL())) {
|
||||
selectTab(tab.getId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
loadUrl(url, null, getSelectedTab().getId(), LOADURL_NEW_TAB);
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,6 @@ var BrowserApp = {
|
||||
|
||||
getBridge().browserApp = this;
|
||||
|
||||
Services.obs.addObserver(this, "Tab:Add", false);
|
||||
Services.obs.addObserver(this, "Tab:Load", false);
|
||||
Services.obs.addObserver(this, "Tab:Selected", false);
|
||||
Services.obs.addObserver(this, "Tab:Closed", false);
|
||||
@ -1076,7 +1075,7 @@ var BrowserApp = {
|
||||
browser.reload();
|
||||
} else if (aTopic == "Session:Stop") {
|
||||
browser.stop();
|
||||
} else if (aTopic == "Tab:Add" || aTopic == "Tab:Load") {
|
||||
} else if (aTopic == "Tab:Load") {
|
||||
let data = JSON.parse(aData);
|
||||
|
||||
// Pass LOAD_FLAGS_DISALLOW_INHERIT_OWNER to prevent any loads from
|
||||
@ -1105,7 +1104,7 @@ var BrowserApp = {
|
||||
if (!shouldShowProgress(url))
|
||||
params.showProgress = false;
|
||||
|
||||
if (aTopic == "Tab:Add")
|
||||
if (data.newTab)
|
||||
this.addTab(url, params);
|
||||
else
|
||||
this.loadURI(url, browser, params);
|
||||
|
Loading…
Reference in New Issue
Block a user