Bug 899376: PageActions for helper apps. r=wesj

This commit is contained in:
Shilpan Bhagat 2013-08-23 16:28:00 -07:00
parent b4980a91f7
commit 3a3b0bf1f7
7 changed files with 57 additions and 0 deletions

View File

@ -668,6 +668,7 @@ RES_DRAWABLE_MDPI = \
res/drawable-mdpi/icon_most_recent_empty.png \
res/drawable-mdpi/icon_most_visited.png \
res/drawable-mdpi/icon_most_visited_empty.png \
res/drawable-mdpi/icon_openinapp.png \
res/drawable-mdpi/icon_pageaction.png \
res/drawable-mdpi/icon_reading_list_empty.png \
res/drawable-mdpi/progress_spinner.png \
@ -780,6 +781,7 @@ RES_DRAWABLE_HDPI = \
res/drawable-hdpi/icon_most_recent_empty.png \
res/drawable-hdpi/icon_most_visited.png \
res/drawable-hdpi/icon_most_visited_empty.png \
res/drawable-hdpi/icon_openinapp.png \
res/drawable-hdpi/icon_pageaction.png \
res/drawable-hdpi/icon_reading_list_empty.png \
res/drawable-hdpi/tab_indicator_divider.9.png \
@ -878,6 +880,7 @@ RES_DRAWABLE_XHDPI = \
res/drawable-xhdpi/icon_most_recent_empty.png \
res/drawable-xhdpi/icon_most_visited.png \
res/drawable-xhdpi/icon_most_visited_empty.png \
res/drawable-xhdpi/icon_openinapp.png \
res/drawable-xhdpi/icon_pageaction.png \
res/drawable-xhdpi/icon_reading_list_empty.png \
res/drawable-xhdpi/spinner_default.9.png \

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

View File

@ -69,6 +69,54 @@ var HelperApps = {
return found;
},
updatePageAction: function setPageAction(uri) {
let apps = this.getAppsForUri(uri);
if (apps.length > 0)
this._setPageActionFor(uri, apps);
else
this._removePageAction();
},
_setPageActionFor: function setPageActionFor(uri, apps) {
this._pageActionUri = uri;
// If the pageaction is already added, simply update the URI to be launched when 'onclick' is triggered.
if (this._pageActionId != undefined)
return;
this._pageActionId = NativeWindow.pageactions.add({
title: Strings.browser.GetStringFromName("openInApp.pageAction"),
icon: "drawable://icon_openinapp",
clickCallback: function() {
if (apps.length == 1)
this._launchApp(apps[0], this._pageActionUri);
else
this.openUriInApp(this._pageActionUri);
}.bind(this)
});
},
_removePageAction: function removePageAction() {
if(!this._pageActionId)
return;
NativeWindow.pageactions.remove(this._pageActionId);
delete this._pageActionId;
},
_launchApp: function launchApp(appData, uri) {
let mimeType = ContentAreaUtils.getMIMETypeForURI(uri) || "";
let msg = {
type: "Intent:Open",
mime: mimeType,
action: "android.intent.action.VIEW",
url: uri.spec,
packageName: appData.packageName,
className: appData.activityName
};
sendMessageToJava(msg);
},
openUriInApp: function openUriInApp(uri) {
let mimeType = ContentAreaUtils.getMIMETypeForURI(uri) || "";
let msg = {

View File

@ -3540,6 +3540,9 @@ Tab.prototype = {
this._linkifier.linkifyNumbers(this.browser.contentWindow.document);
}
// Show page actions for helper apps.
HelperApps.updatePageAction(this.browser.currentURI);
if (!Reader.isEnabledForParseOnLoad)
return;

View File

@ -288,3 +288,6 @@ getUserMedia.sharingCameraAndMicrophone.message2 = Camera and microphone are on
#Reader mode
readerMode.enter = Enter Reader Mode
readerMode.exit = Exit Reader Mode
#Open in App
openInApp.pageAction = Open in App