mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-12 06:52:25 +00:00
Bug 852608 - Part 3: Add UI for adding a search engine. r=lucasr
This commit is contained in:
parent
773ca272ed
commit
c4eedb156d
@ -712,7 +712,7 @@ abstract public class BrowserApp extends GeckoApp
|
||||
|
||||
if (itemId == R.id.subscribe) {
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null && tab.getFeedsEnabled()) {
|
||||
if (tab != null && tab.hasFeeds()) {
|
||||
JSONObject args = new JSONObject();
|
||||
try {
|
||||
args.put("tabId", tab.getId());
|
||||
@ -724,6 +724,21 @@ abstract public class BrowserApp extends GeckoApp
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemId == R.id.add_search_engine) {
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null && tab.hasOpenSearch()) {
|
||||
JSONObject args = new JSONObject();
|
||||
try {
|
||||
args.put("tabId", tab.getId());
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "error building json arguments");
|
||||
return true;
|
||||
}
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Add", args.toString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemId == R.id.copyurl) {
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
|
@ -377,15 +377,19 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
||||
menu.findItem(R.id.share).setVisible(false);
|
||||
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
||||
}
|
||||
if (!tab.getFeedsEnabled()) {
|
||||
|
||||
if (!tab.hasFeeds()) {
|
||||
menu.findItem(R.id.subscribe).setVisible(false);
|
||||
}
|
||||
|
||||
menu.findItem(R.id.add_search_engine).setVisible(tab.hasOpenSearch());
|
||||
} else {
|
||||
// if there is no tab, remove anything tab dependent
|
||||
menu.findItem(R.id.copyurl).setVisible(false);
|
||||
menu.findItem(R.id.share).setVisible(false);
|
||||
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
||||
menu.findItem(R.id.subscribe).setVisible(false);
|
||||
menu.findItem(R.id.add_search_engine).setVisible(false);
|
||||
}
|
||||
|
||||
menu.findItem(R.id.share).setVisible(!GeckoProfile.get(getContext()).inGuestMode());
|
||||
|
@ -43,7 +43,8 @@ public class Tab {
|
||||
private Bitmap mFavicon;
|
||||
private String mFaviconUrl;
|
||||
private int mFaviconSize;
|
||||
private boolean mFeedsEnabled;
|
||||
private boolean mHasFeeds;
|
||||
private boolean mHasOpenSearch;
|
||||
private JSONObject mIdentityData;
|
||||
private boolean mReaderEnabled;
|
||||
private BitmapDrawable mThumbnail;
|
||||
@ -98,7 +99,8 @@ public class Tab {
|
||||
mFavicon = null;
|
||||
mFaviconUrl = null;
|
||||
mFaviconSize = 0;
|
||||
mFeedsEnabled = false;
|
||||
mHasFeeds = false;
|
||||
mHasOpenSearch = false;
|
||||
mIdentityData = null;
|
||||
mReaderEnabled = false;
|
||||
mEnteringReaderMode = false;
|
||||
@ -236,8 +238,12 @@ public class Tab {
|
||||
return mFaviconUrl;
|
||||
}
|
||||
|
||||
public boolean getFeedsEnabled() {
|
||||
return mFeedsEnabled;
|
||||
public boolean hasFeeds() {
|
||||
return mHasFeeds;
|
||||
}
|
||||
|
||||
public boolean hasOpenSearch() {
|
||||
return mHasOpenSearch;
|
||||
}
|
||||
|
||||
public String getSecurityMode() {
|
||||
@ -393,8 +399,12 @@ public class Tab {
|
||||
mFaviconSize = 0;
|
||||
}
|
||||
|
||||
public void setFeedsEnabled(boolean feedsEnabled) {
|
||||
mFeedsEnabled = feedsEnabled;
|
||||
public void setHasFeeds(boolean hasFeeds) {
|
||||
mHasFeeds = hasFeeds;
|
||||
}
|
||||
|
||||
public void setHasOpenSearch(boolean hasOpenSearch) {
|
||||
mHasOpenSearch = hasOpenSearch;
|
||||
}
|
||||
|
||||
public void updateIdentityData(JSONObject identityData) {
|
||||
@ -622,7 +632,7 @@ public class Tab {
|
||||
|
||||
setContentType(message.getString("contentType"));
|
||||
clearFavicon();
|
||||
setFeedsEnabled(false);
|
||||
setHasFeeds(false);
|
||||
updateTitle(null);
|
||||
updateIdentityData(null);
|
||||
setReaderEnabled(false);
|
||||
|
@ -102,6 +102,7 @@ public class Tabs implements GeckoEventListener {
|
||||
registerEventListener("DOMTitleChanged");
|
||||
registerEventListener("Link:Favicon");
|
||||
registerEventListener("Link:Feed");
|
||||
registerEventListener("Link:OpenSearch");
|
||||
registerEventListener("DesktopMode:Changed");
|
||||
registerEventListener("Tab:ViewportMetadata");
|
||||
}
|
||||
@ -467,8 +468,11 @@ public class Tabs implements GeckoEventListener {
|
||||
tab.updateFaviconURL(message.getString("href"), message.getInt("size"));
|
||||
notifyListeners(tab, TabEvents.LINK_FAVICON);
|
||||
} else if (event.equals("Link:Feed")) {
|
||||
tab.setFeedsEnabled(true);
|
||||
tab.setHasFeeds(true);
|
||||
notifyListeners(tab, TabEvents.LINK_FEED);
|
||||
} else if (event.equals("Link:OpenSearch")) {
|
||||
boolean visible = message.getBoolean("visible");
|
||||
tab.setHasOpenSearch(visible);
|
||||
} else if (event.equals("DesktopMode:Changed")) {
|
||||
tab.setDesktopMode(message.getBoolean("desktopMode"));
|
||||
notifyListeners(tab, TabEvents.DESKTOP_MODE_CHANGE);
|
||||
|
@ -228,6 +228,7 @@ size. -->
|
||||
<!ENTITY contextmenu_top_sites_edit "Edit">
|
||||
<!ENTITY contextmenu_top_sites_pin "Pin Site">
|
||||
<!ENTITY contextmenu_top_sites_unpin "Unpin Site">
|
||||
<!ENTITY contextmenu_add_search_engine "Add a Search Engine">
|
||||
|
||||
<!ENTITY pref_titlebar_mode "Title bar">
|
||||
<!ENTITY pref_titlebar_mode_title "Show page title">
|
||||
|
@ -17,6 +17,10 @@
|
||||
<item android:id="@+id/subscribe"
|
||||
android:title="@string/contextmenu_subscribe"/>
|
||||
|
||||
<item android:id="@+id/add_search_engine"
|
||||
android:title="@string/contextmenu_add_search_engine"
|
||||
android:visible="false"/>
|
||||
|
||||
<item android:id="@+id/copyurl"
|
||||
android:title="@string/contextmenu_copyurl"/>
|
||||
|
||||
|
@ -228,6 +228,7 @@
|
||||
<string name="contextmenu_top_sites_edit">&contextmenu_top_sites_edit;</string>
|
||||
<string name="contextmenu_top_sites_pin">&contextmenu_top_sites_pin;</string>
|
||||
<string name="contextmenu_top_sites_unpin">&contextmenu_top_sites_unpin;</string>
|
||||
<string name="contextmenu_add_search_engine">&contextmenu_add_search_engine;</string>
|
||||
|
||||
<string name="pref_titlebar_mode">&pref_titlebar_mode;</string>
|
||||
<string name="pref_titlebar_mode_title">&pref_titlebar_mode_title;</string>
|
||||
|
@ -3702,6 +3702,22 @@ Tab.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear page-specific opensearch engines and feeds for a new request.
|
||||
if (aStateFlags & Ci.nsIWebProgressListener.STATE_START && aRequest && aWebProgress.isTopLevel) {
|
||||
this.browser.engines = null;
|
||||
|
||||
// Send message to clear search engine option in context menu.
|
||||
let newEngineMessage = {
|
||||
type: "Link:OpenSearch",
|
||||
tabID: this.id,
|
||||
visible: false
|
||||
};
|
||||
|
||||
sendMessageToJava(newEngineMessage);
|
||||
|
||||
this.browser.feeds = null;
|
||||
}
|
||||
|
||||
// Check to see if we restoring the content from a previous presentation (session)
|
||||
// since there should be no real network activity
|
||||
let restoring = aStateFlags & Ci.nsIWebProgressListener.STATE_RESTORING;
|
||||
|
Loading…
x
Reference in New Issue
Block a user