mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 728782 - Add support for Bookmark Link context menu r=wesj r=gbrown
This commit is contained in:
parent
43a881a014
commit
ce305c7eae
@ -1120,6 +1120,19 @@ abstract public class GeckoApp
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (event.equals("Bookmark:Insert")) {
|
||||
final String url = message.getString("url");
|
||||
final String title = message.getString("title");
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(GeckoApp.mAppContext, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
|
||||
GeckoAppShell.getHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
BrowserDB.addBookmark(GeckoApp.mAppContext.getContentResolver(), title, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
||||
@ -1846,6 +1859,7 @@ abstract public class GeckoApp
|
||||
GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
|
||||
GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);
|
||||
|
||||
IntentFilter batteryFilter = new IntentFilter();
|
||||
batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
@ -2202,6 +2216,7 @@ abstract public class GeckoApp
|
||||
GeckoAppShell.unregisterGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
|
||||
GeckoAppShell.unregisterGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);
|
||||
|
||||
mFavicons.close();
|
||||
|
||||
|
12
mobile/android/base/tests/robocop_big_mailto.html
Normal file
12
mobile/android/base/tests/robocop_big_mailto.html
Normal file
@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Big Mailto</title>
|
||||
<link rel="shortcut icon" href="data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==" />
|
||||
<meta name="viewport" content="initial-scale=1.0"/>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0">
|
||||
<div style="text-align: center; margin: 0; padding: 0">
|
||||
<a style="font-size: 60px" href="mailto:foo.bar@example.com">Email Foo.Bar</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -3,7 +3,6 @@ package @ANDROID_PACKAGE_NAME@.tests;
|
||||
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public class testWebContentContextMenu extends BaseTest {
|
||||
@ -11,16 +10,17 @@ public class testWebContentContextMenu extends BaseTest {
|
||||
setTestType("mochitest");
|
||||
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
|
||||
|
||||
// Load the about: page
|
||||
String url = getAbsoluteUrl("/robocop/robocop_big_link.html");
|
||||
loadUrl(url);
|
||||
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
|
||||
// The link has a 60px height, so let's try to hit the middle
|
||||
float top = mDriver.getGeckoTop() + 30 * dm.density;
|
||||
float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2;
|
||||
|
||||
// Load the test page and check for 'Open Link'
|
||||
String url = getAbsoluteUrl("/robocop/robocop_big_link.html");
|
||||
loadUrl(url);
|
||||
|
||||
mSolo.clickLongOnScreen(left, top);
|
||||
|
||||
mAsserter.ok(mSolo.waitForText("Open"), "looking for context menu action", "found 'Open Link'");
|
||||
@ -36,5 +36,40 @@ public class testWebContentContextMenu extends BaseTest {
|
||||
// See tab count
|
||||
Element tabCount = mDriver.findElement(getActivity(), "tabs_count");
|
||||
mAsserter.is(tabCount.getText(), "2", "Number of tabs has increased");
|
||||
|
||||
// Load the test page again and test for 'Share Link' and 'Bookmark Link'
|
||||
loadUrl(url);
|
||||
|
||||
mSolo.clickLongOnScreen(left, top);
|
||||
|
||||
mAsserter.ok(mSolo.waitForText("Share"), "looking for context menu action", "found 'Share Link'");
|
||||
mAsserter.ok(mSolo.waitForText("Bookmark"), "looking for context menu action", "found 'Bookmark Link'");
|
||||
mSolo.clickOnText("Bookmark");
|
||||
mAsserter.is(mSolo.waitForText("Bookmark added"), true, "Bookmark added verified");
|
||||
|
||||
// We know that the link test page points to robocop_blank_01.html, so lets
|
||||
// load it and see if the page is bookmarked
|
||||
url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
|
||||
loadUrl(url);
|
||||
|
||||
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
||||
mSolo.waitForText("Bookmark");
|
||||
|
||||
// TODO: This doesn't work for some reason. We got a 'Bookmark added' and
|
||||
// will check for 'Bookmark removed'
|
||||
mAsserter.todo_is(mSolo.isTextChecked("Bookmark"), true, "Page is bookmarked");
|
||||
|
||||
mSolo.clickOnText("Bookmark");
|
||||
mAsserter.is(mSolo.waitForText("Bookmark removed"), true, "Bookmark removal verified");
|
||||
|
||||
// Load the mailto test page again and test for allowed menu actions
|
||||
url = getAbsoluteUrl("/robocop/robocop_big_mailto.html");
|
||||
loadUrl(url);
|
||||
|
||||
mSolo.clickLongOnScreen(left, top);
|
||||
|
||||
mAsserter.ok(mSolo.waitForText("Share"), "looking for context menu action", "found 'Share Link'");
|
||||
mAsserter.ok(!mSolo.waitForText("Open", 0, 1000, false), "looking for context menu action", "did not find 'Open Link'");
|
||||
mAsserter.ok(!mSolo.waitForText("Bookmark", 0, 1000, false), "looking for context menu action", "did not find 'Bookmark Link'");
|
||||
}
|
||||
}
|
||||
|
@ -1121,6 +1121,20 @@ var NativeWindow = {
|
||||
sharing.shareWithDefault(url, "text/plain", title);
|
||||
});
|
||||
|
||||
this.add(Strings.browser.GetStringFromName("contextmenu.bookmarkLink"),
|
||||
this.linkBookmarkableContext,
|
||||
function(aTarget) {
|
||||
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
|
||||
let title = aTarget.textContent || aTarget.title || url;
|
||||
sendMessageToJava({
|
||||
gecko: {
|
||||
type: "Bookmark:Insert",
|
||||
url: url,
|
||||
title: title
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.add(Strings.browser.GetStringFromName("contextmenu.fullScreen"),
|
||||
this.SelectorContext("video:not(:-moz-full-screen)"),
|
||||
function(aTarget) {
|
||||
@ -1186,23 +1200,9 @@ var NativeWindow = {
|
||||
|
||||
linkOpenableContext: {
|
||||
matches: function linkOpenableContextMatches(aElement) {
|
||||
if (aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||
((aElement instanceof Ci.nsIDOMHTMLAnchorElement && aElement.href) ||
|
||||
(aElement instanceof Ci.nsIDOMHTMLAreaElement && aElement.href) ||
|
||||
aElement instanceof Ci.nsIDOMHTMLLinkElement ||
|
||||
aElement.getAttributeNS(kXLinkNamespace, "type") == "simple")) {
|
||||
let uri;
|
||||
try {
|
||||
let url = NativeWindow.contextmenus._getLinkURL(aElement);
|
||||
uri = Services.io.newURI(url, null, null);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let uri = NativeWindow.contextmenus._getLink(aElement);
|
||||
if (uri) {
|
||||
let scheme = uri.scheme;
|
||||
if (!scheme)
|
||||
return false;
|
||||
|
||||
let dontOpen = /^(mailto|javascript|news|snews)$/;
|
||||
return (scheme && !dontOpen.test(scheme));
|
||||
}
|
||||
@ -1212,23 +1212,9 @@ var NativeWindow = {
|
||||
|
||||
linkShareableContext: {
|
||||
matches: function linkShareableContextMatches(aElement) {
|
||||
if (aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||
((aElement instanceof Ci.nsIDOMHTMLAnchorElement && aElement.href) ||
|
||||
(aElement instanceof Ci.nsIDOMHTMLAreaElement && aElement.href) ||
|
||||
aElement instanceof Ci.nsIDOMHTMLLinkElement ||
|
||||
aElement.getAttributeNS(kXLinkNamespace, "type") == "simple")) {
|
||||
let uri;
|
||||
try {
|
||||
let url = NativeWindow.contextmenus._getLinkURL(aElement);
|
||||
uri = Services.io.newURI(url, null, null);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let uri = NativeWindow.contextmenus._getLink(aElement);
|
||||
if (uri) {
|
||||
let scheme = uri.scheme;
|
||||
if (!scheme)
|
||||
return false;
|
||||
|
||||
let dontShare = /^(chrome|about|file|javascript|resource)$/;
|
||||
return (scheme && !dontShare.test(scheme));
|
||||
}
|
||||
@ -1236,6 +1222,18 @@ var NativeWindow = {
|
||||
}
|
||||
},
|
||||
|
||||
linkBookmarkableContext: {
|
||||
matches: function linkBookmarkableContextMatches(aElement) {
|
||||
let uri = NativeWindow.contextmenus._getLink(aElement);
|
||||
if (uri) {
|
||||
let scheme = uri.scheme;
|
||||
let dontBookmark = /^(mailto)$/;
|
||||
return (scheme && !dontBookmark.test(scheme));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
textContext: {
|
||||
matches: function textContext(aElement) {
|
||||
return ((aElement instanceof Ci.nsIDOMHTMLInputElement && aElement.mozIsTextField(false))
|
||||
@ -1348,6 +1346,20 @@ var NativeWindow = {
|
||||
return Services.io.newURI(aURL, aOriginCharset, aBaseURI);
|
||||
},
|
||||
|
||||
_getLink: function(aElement) {
|
||||
if (aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||
((aElement instanceof Ci.nsIDOMHTMLAnchorElement && aElement.href) ||
|
||||
(aElement instanceof Ci.nsIDOMHTMLAreaElement && aElement.href) ||
|
||||
aElement instanceof Ci.nsIDOMHTMLLinkElement ||
|
||||
aElement.getAttributeNS(kXLinkNamespace, "type") == "simple")) {
|
||||
try {
|
||||
let url = NativeWindow.contextmenus._getLinkURL(aElement);
|
||||
return Services.io.newURI(url, null, null);
|
||||
} catch (e) {}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
_getLinkURL: function ch_getLinkURL(aLink) {
|
||||
let href = aLink.href;
|
||||
if (href)
|
||||
|
@ -199,6 +199,7 @@ selectionHelper.textCopied=Text copied to clipboard
|
||||
# Context menu
|
||||
contextmenu.openInNewTab=Open Link in New Tab
|
||||
contextmenu.shareLink=Share Link
|
||||
contextmenu.bookmarkLink=Bookmark Link
|
||||
contextmenu.changeInputMethod=Select Input Method
|
||||
contextmenu.fullScreen=Full Screen
|
||||
contextmenu.saveImage=Save Image
|
||||
|
Loading…
Reference in New Issue
Block a user