Permalink
Browse files

Make the Share extension support the latest version of the data payload

  • Loading branch information...
1 parent 46ae3e7 commit 0789bf024172424527797c0d63ca28cba1a18f4f @PaulKinlan committed Aug 23, 2012
Showing with 39 additions and 13 deletions.
  1. +39 −13 tools/chrome/extensions/share/background.js
@@ -1,24 +1,50 @@
function clickHandler(info, tab) {
- if(info.mediaType == "image" ||
- info.mediaType == "video" ||
- info.mediaType == "audio") {
-
- var i = new WebKitIntent({"action": "http://webintents.org/share", "type": info.mediaType + "/*", "data": info.srcUrl});
- window.navigator.webkitStartActivity(i);
- }
- else if(!!info.linkUrl) {
- var i = new WebKitIntent({"action": "http://webintents.org/share", "type": "text/uri-list", "data": info.linkUrl });
- window.navigator.webkitStartActivity(i, function() {}, function() {});
- }
+ var type = (info.mediaType) ? info.mediaType + "/*" : "text/uri-list" ;
+ var data = {
+ "via": "Chrome Share extension",
+ "url": info.linkUrl,
+ };
+
+ var i = new WebKitIntent({"action": "http://webintents.org/share", "type": type, "data": data });
+ window.navigator.webkitStartActivity(i, function() {}, function() {});
};
chrome.browserAction.onClicked.addListener(function(tab) {
clickHandler({linkUrl: tab.url}, tab);
});
+
+chrome.contextMenus.create({
+ "title" : "Share Link",
+ "type" : "normal",
+ "contexts" : ["link"],
+ "onclick" : clickHandler
+});
+
+chrome.contextMenus.create({
+ "title" : "Share Image",
+ "type" : "normal",
+ "contexts" : ["image"],
+ "onclick" : clickHandler
+});
+
+chrome.contextMenus.create({
+ "title" : "Share Page",
+ "type" : "normal",
+ "contexts" : ["page"],
+ "onclick" : clickHandler
+});
+
+chrome.contextMenus.create({
+ "title" : "Share Video",
+ "type" : "normal",
+ "contexts" : ["video"],
+ "onclick" : clickHandler
+});
+
chrome.contextMenus.create({
- "title" : "Share",
+ "title" : "Share Audio",
"type" : "normal",
- "contexts" : ["link", "image", "page", "video", "audio"],
+ "contexts" : ["audio"],
"onclick" : clickHandler
});

0 comments on commit 0789bf0

Please sign in to comment.