71 Components.utils.import(
"resource://app/jsmodules/DropHelper.jsm");
73 Components.utils.import(
"resource://app/jsmodules/LibraryUtils.jsm");
79 this.isFrameImage =
false;
80 this.onTextInput =
false;
81 this.onKeywordField =
false;
83 this.onLoadedImage =
false;
84 this.onCompletedImage =
false;
85 this.onCanvas =
false;
87 this.onMailtoLink =
false;
88 this.onSaveableLink =
false;
89 this.onMetaDataItem =
false;
90 this.onMathML =
false;
95 this.linkProtocol =
null;
97 this.hasBGImage =
false;
98 this.isTextSelected =
false;
99 this.isContentSelected =
false;
100 this.inDirList =
false;
101 this.shouldDisplay =
true;
102 this.isDesignMode =
false;
103 this.possibleSpellChecking =
false;
104 this.ellipsis =
"\u2026";
106 this.ellipsis =
gPrefService.getComplexValue(
"intl.ellipsis",
107 Ci.nsIPrefLocalizedString).data;
117 onDestroy:
function () {
121 initMenu:
function CM_initMenu(aPopup,
aBrowser) {
125 this.isFrameImage = document.getElementById(
"isFrameImage");
128 this.setTarget(document.popupNode, document.popupRangeParent,
129 document.popupRangeOffset);
131 this.isTextSelected = this.isTextSelection();
132 this.isContentSelected = this.isContentSelection();
138 initItems:
function CM_initItems() {
139 this.initOpenItems();
140 this.initOpenExternalItems();
141 this.initNavigationItems();
142 this.initViewItems();
143 this.initMiscItems();
144 this.initSpellingItems();
145 this.initSaveItems();
146 this.initClipboardItems();
147 this.initMediaItems();
150 initOpenItems:
function CM_initOpenItems() {
151 var shouldShow = this.onSaveableLink ||
152 (this.inDirList && this.onLink);
153 this.showItem(
"context-openlinkintab", shouldShow);
154 this.showItem(
"context-sep-open", shouldShow);
157 initOpenExternalItems:
function CM_initOpenExternalItems() {
158 var showLink = this.onSaveableLink ||
159 (this.inDirList && this.onLink);
160 var showPage = !showLink && !showImage && !InlineSpellCheckerUI.canSpellCheck;
161 var showImage = this.onImage;
163 this.showItem(
"context-openlinkexternal", showLink);
164 this.showItem(
"context-openpageexternal", showPage);
165 this.showItem(
"context-sep-openexternal", showLink || showPage);
167 this.showItem(
"context-openimageexternal", showImage);
168 this.showItem(
"context-sep-openimageexternal", showImage);
171 initNavigationItems:
function CM_initNavigationItems() {
172 var shouldShow = !(this.onLink || this.onImage ||
173 this.onCanvas || this.onTextInput);
174 this.showItem(
"context-back", shouldShow);
175 this.showItem(
"context-forward", shouldShow);
176 this.showItem(
"context-reload", shouldShow);
177 this.showItem(
"context-stop", shouldShow);
178 this.showItem(
"context-sep-stop", shouldShow);
181 initSaveItems:
function CM_initSaveItems() {
182 var shouldShow = !(this.inDirList || this.onTextInput || this.onLink ||
183 this.onImage || this.onCanvas);
184 this.showItem(
"context-savepage", shouldShow);
185 this.showItem(
"context-sep-savepage", shouldShow);
188 this.showItem(
"context-savelink", this.onSaveableLink);
191 this.showItem(
"context-saveimage", this.onLoadedImage || this.onCanvas);
194 initViewItems:
function CM_initViewItems() {
196 var shouldShow = !(this.inDirList || this.onImage ||
197 this.onLink || this.onTextInput);
198 this.showItem(
"context-viewsource", shouldShow);
200 this.showItem(
"context-sep-properties",
false);
204 var haveSetDesktopBackground =
false;
207 this.showItem(
"context-showimage", (this.onImage && !this.onCompletedImage));
211 this.showItem(
"context-viewimage", (this.onImage &&
212 (!this.onStandaloneImage || this.inFrame)) || this.onCanvas);
214 this.showItem(
"context-sep-viewbgimage",
false);
217 initMiscItems:
function CM_initMiscItems() {
218 this.showItem(
"context-searchselect", this.isTextSelected);
228 var showFrame = this.inFrame && !this.onImage && !this.onLink;
229 this.showItem(
"frame", showFrame);
230 this.showItem(
"frame-sep",
false);
231 this.showItem(
"frame-sep-after", showFrame);
236 this.isFrameImage.removeAttribute(
'hidden');
238 this.isFrameImage.setAttribute(
'hidden',
'true');
242 this.showItem(
"context-sep-bidi",
top.gBidiUI);
243 this.showItem(
"context-bidi-text-direction-toggle",
244 this.onTextInput &&
top.gBidiUI);
245 this.showItem(
"context-bidi-page-direction-toggle",
246 !this.onTextInput &&
top.gBidiUI);
249 var blockImage = document.getElementById(
"context-blockimage");
252 .QueryInterface(
Ci.nsIImageLoadingContent)
259 hostLabel = uri.host;
263 var shortenedUriHost = hostLabel.replace(/^www\./
i,
"");
264 if (shortenedUriHost.length > 15)
265 shortenedUriHost = shortenedUriHost.substr(0,15) + this.ellipsis;
266 blockImage.label =
gNavigatorBundle.getFormattedString(
"blockImages", [shortenedUriHost]);
268 if (this.isImageBlocked())
269 blockImage.setAttribute(
"checked",
"true");
271 blockImage.removeAttribute(
"checked");
276 this.showItem(
"context-blockimage", this.onImage && hostLabel);
279 initSpellingItems:
function() {
280 var canSpell = InlineSpellCheckerUI.canSpellCheck;
281 var onMisspelling = InlineSpellCheckerUI.overMisspelling;
282 this.showItem(
"spell-check-enabled", canSpell);
283 this.showItem(
"spell-separator",
false);
285 document.getElementById(
"spell-check-enabled")
286 .setAttribute(
"checked", InlineSpellCheckerUI.enabled);
289 this.showItem(
"spell-add-to-dictionary", onMisspelling);
292 this.showItem(
"spell-suggestions-separator", onMisspelling);
294 var
menu = document.getElementById(
"contentAreaContextMenu");
295 var suggestionsSeparator =
296 document.getElementById(
"spell-add-to-dictionary");
297 var numsug = InlineSpellCheckerUI.addSuggestionsToMenu(menu, suggestionsSeparator, 5);
298 this.showItem(
"spell-no-suggestions", numsug == 0);
301 this.showItem(
"spell-no-suggestions",
false);
304 this.showItem(
"spell-dictionaries", InlineSpellCheckerUI.enabled);
306 var dictMenu = document.getElementById(
"spell-dictionaries-menu");
307 var dictSep = document.getElementById(
"spell-language-separator");
308 InlineSpellCheckerUI.addDictionaryListToMenu(dictMenu, dictSep);
309 this.showItem(
"spell-add-dictionaries-main",
false);
311 else if (this.possibleSpellChecking) {
315 this.showItem(
"spell-add-dictionaries-main",
true);
318 this.showItem(
"spell-add-dictionaries-main",
false);
321 initClipboardItems:
function() {
326 goUpdateGlobalEditMenuItems();
328 this.showItem(
"context-undo", this.onTextInput);
329 this.showItem(
"context-sep-undo", this.onTextInput);
330 this.showItem(
"context-cut", this.onTextInput);
331 this.showItem(
"context-copyselected", this.isContentSelected);
332 this.showItem(
"context-sep-selected", this.isContentSelected);
333 this.showItem(
"context-copy", this.onTextInput);
334 this.showItem(
"context-paste", this.onTextInput);
335 this.showItem(
"context-delete", this.onTextInput);
336 this.showItem(
"context-sep-paste", this.onTextInput);
337 var showSelectAll = !(this.onLink || this.onImage) || this.isDesignMode;
338 this.showItem(
"context-selectall", showSelectAll);
339 this.showItem(
"context-sep-selectall", showSelectAll);
347 this.showItem(
"context-copylink", this.onLink && !this.onMailtoLink);
348 this.showItem(
"context-sep-copylink", this.onLink && this.onImage);
351 this.showItem(
"context-copyimage-contents", this.onImage);
354 this.showItem(
"context-copyimage", this.onImage);
355 this.showItem(
"context-sep-copyimage", this.onImage);
358 initMediaItems:
function () {
359 this.showItem(
"context-playmedia", this.onMedia);
360 this.showItem(
"context-downloadmedia", this.onMedia);
361 this.showItem(
"context-addmediatoplaylist", this.onMedia);
362 this.showItem(
"context-sep-media", this.onMedia);
365 this.updateAddToPlaylist();
379 setTarget:
function (aNode, aRangeParent, aRangeOffset) {
380 const xulNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
381 if (aNode.namespaceURI == xulNS ||
382 this.isTargetAFormControl(aNode)) {
383 this.shouldDisplay =
false;
387 this.onImage =
false;
388 this.onLoadedImage =
false;
389 this.onCompletedImage =
false;
390 this.onStandaloneImage =
false;
391 this.onCanvas =
false;
392 this.onMetaDataItem =
false;
393 this.onTextInput =
false;
394 this.onKeywordField =
false;
399 this.linkProtocol =
"";
400 this.onMathML =
false;
401 this.onMedia =
false;
402 this.inFrame =
false;
403 this.hasBGImage =
false;
404 this.bgImageURL =
"";
405 this.possibleSpellChecking =
false;
412 InlineSpellCheckerUI.clearSuggestionsFromMenu();
413 InlineSpellCheckerUI.clearDictionaryListFromMenu();
415 InlineSpellCheckerUI.uninit();
421 if (this.
target.nodeType == Node.ELEMENT_NODE) {
423 if (this.
target instanceof
Ci.nsIImageLoadingContent &&
424 this.target.currentURI) {
426 this.onMetaDataItem =
true;
429 this.
target.getRequest(
Ci.nsIImageLoadingContent.CURRENT_REQUEST);
430 if (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE))
431 this.onLoadedImage =
true;
432 if (request && (request.imageStatus & request.STATUS_LOAD_COMPLETE))
433 this.onCompletedImage =
true;
435 this.imageURL = this.
target.currentURI.spec;
436 if (this.
target.ownerDocument instanceof ImageDocument)
437 this.onStandaloneImage =
true;
439 else if (this.
target instanceof HTMLCanvasElement) {
440 this.onCanvas =
true;
442 else if (this.
target instanceof HTMLInputElement ) {
443 this.onTextInput = this.isTargetATextBox(this.
target);
445 if (this.onTextInput && ! this.
target.readOnly &&
446 this.target.type !=
"password") {
447 this.possibleSpellChecking =
true;
448 InlineSpellCheckerUI.init(this.
target.QueryInterface(
Ci.nsIDOMNSEditableElement).editor);
449 InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
451 this.onKeywordField = this.isTargetAKeywordField(this.
target);
453 else if (this.
target instanceof HTMLTextAreaElement) {
454 this.onTextInput =
true;
455 if (!this.
target.readOnly) {
456 this.possibleSpellChecking =
true;
457 InlineSpellCheckerUI.init(this.
target.QueryInterface(
Ci.nsIDOMNSEditableElement).editor);
458 InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
461 else if (this.
target instanceof HTMLHtmlElement) {
462 var bodyElt = this.
target.ownerDocument.body;
464 var computedURL = this.getComputedURL(bodyElt,
"background-image");
466 this.hasBGImage =
true;
472 else if (
"HTTPIndex" in content &&
473 content.HTTPIndex instanceof
Ci.nsIHTTPIndex) {
474 this.inDirList =
true;
478 while (root && !this.link) {
479 if (root.tagName ==
"tree") {
485 if (root.getAttribute(
"URL")) {
488 this.link = {
href : root.getAttribute(
"URL"),
490 if (aAttr ==
"title") {
491 return root.firstChild.firstChild
492 .getAttribute(
"label");
500 this.onSaveableLink = root.getAttribute(
"container") !=
"true";
503 root = root.parentNode;
510 const XMLNS =
"http://www.w3.org/XML/1998/namespace";
513 if (elem.nodeType == Node.ELEMENT_NODE) {
516 ((elem instanceof HTMLAnchorElement && elem.href) ||
517 (elem instanceof HTMLAreaElement && elem.href) ||
518 elem instanceof HTMLLinkElement ||
519 elem.getAttributeNS(
"http://www.w3.org/1999/xlink",
"type") ==
"simple")) {
523 this.onMetaDataItem =
true;
529 var parent = elem.parentNode;
532 if ((parent instanceof HTMLAnchorElement && parent.href) ||
533 (parent instanceof HTMLAreaElement && parent.href) ||
534 parent instanceof HTMLLinkElement ||
535 parent.getAttributeNS(
"http://www.w3.org/1999/xlink",
"type") ==
"simple")
538 parent = parent.parentNode;
542 this.link = realLink;
543 this.linkURL = this.getLinkURL();
544 this.linkURI = this.getLinkURI();
545 this.linkProtocol = this.getLinkProtocol();
546 this.onMailtoLink = (this.linkProtocol ==
"mailto");
547 this.onSaveableLink = this.isLinkSaveable( this.link );
551 if (!this.onMetaDataItem) {
555 if ((elem instanceof HTMLQuoteElement && elem.cite) ||
556 (elem instanceof HTMLTableElement && elem.summary) ||
557 (elem instanceof HTMLModElement &&
558 (elem.cite || elem.dateTime)) ||
559 (elem instanceof HTMLElement &&
560 (elem.title || elem.lang)) ||
561 elem.getAttributeNS(
XMLNS,
"lang")) {
562 this.onMetaDataItem =
true;
569 if (!this.hasBGImage) {
570 var bgImgUrl = this.getComputedURL( elem,
"background-image" );
572 this.hasBGImage =
true;
579 elem = elem.parentNode;
583 const NS_MathML =
"http://www.w3.org/1998/Math/MathML";
584 if ((this.
target.nodeType == Node.TEXT_NODE &&
585 this.target.parentNode.namespaceURI == NS_MathML)
586 || (
this.target.namespaceURI == NS_MathML))
587 this.onMathML =
true;
590 var docDefaultView = this.
target.ownerDocument.defaultView;
591 if (docDefaultView != docDefaultView.top)
595 var
win = this.
target.ownerDocument.defaultView;
597 var isEditable =
false;
599 var editingSession = win.QueryInterface(
Ci.nsIInterfaceRequestor)
600 .getInterface(
Ci.nsIWebNavigation)
601 .QueryInterface(
Ci.nsIInterfaceRequestor)
602 .getInterface(
Ci.nsIEditingSession);
603 if (editingSession.windowIsEditable(win) &&
604 this.getComputedStyle(this.
target,
"-moz-user-modify") ==
"read-write") {
613 this.onMedia = this.linkURL &&
617 this.onTextInput =
true;
618 this.onKeywordField =
false;
619 this.onImage =
false;
620 this.onLoadedImage =
false;
621 this.onCompletedImage =
false;
622 this.onMetaDataItem =
false;
623 this.onMathML =
false;
624 this.onMedia =
false;
625 this.inFrame =
false;
626 this.hasBGImage =
false;
627 this.isDesignMode =
true;
628 this.possibleSpellChecking =
true;
629 InlineSpellCheckerUI.init(editingSession.getEditorForWindow(win));
630 var canSpell = InlineSpellCheckerUI.canSpellCheck;
631 InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
632 this.showItem(
"spell-check-enabled", canSpell);
633 this.showItem(
"spell-separator",
false);
639 getComputedStyle:
function(aElem, aProp) {
640 return aElem.ownerDocument
642 .getComputedStyle(aElem,
"").getPropertyValue(aProp);
646 getComputedURL:
function(aElem, aProp) {
647 var
url = aElem.ownerDocument
648 .defaultView.getComputedStyle(aElem,
"")
649 .getPropertyCSSValue(aProp);
650 return url.primitiveType == CSSPrimitiveValue.CSS_URI ?
651 url.getStringValue() :
null;
655 isLinkSaveable:
function(aLink) {
658 return this.linkProtocol && !(
659 this.linkProtocol ==
"mailto" ||
660 this.linkProtocol ==
"javascript" ||
661 this.linkProtocol ==
"news" ||
662 this.linkProtocol ==
"snews" );
665 openLinkInDefaultBrowser:
function() {
666 SBOpenURLInDefaultBrowser(this.linkURL);
669 openPageInDefaultBrowser:
function() {
670 SBOpenURLInDefaultBrowser(gBrowser.currentURI.spec);
673 openFrameInDefaultBrowser:
function() {
675 var frameURL = doc.documentURIObject.spec;
676 SBOpenURLInDefaultBrowser(frameURL);
678 openImageInDefaultBrowser:
function() {
679 SBOpenURLInDefaultBrowser(this.imageURL);
683 openLinkInTab:
function() {
685 if (!gBrowser.handleMediaURL(
this.linkURL,
false,
false))
690 openFrameInTab:
function() {
692 var frameURL = doc.documentURIObject.spec;
693 var referrer = doc.referrer;
700 reloadFrame:
function() {
701 this.
target.ownerDocument.location.reload();
705 showOnlyThisFrame:
function() {
707 var frameURL = doc.documentURIObject.spec;
709 urlSecurityCheck(frameURL, this.
tabbrowser.selectedBrowser.contentPrincipal,
710 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
711 var referrer = doc.referrer;
716 viewFrameSource:
function() {
720 showImage:
function(e) {
721 urlSecurityCheck(this.imageURL,
722 this.
tabbrowser.selectedBrowser.contentPrincipal,
723 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
725 if (this.
target instanceof
Ci.nsIImageLoadingContent)
726 this.
target.forceReload();
730 viewImage:
function(e) {
734 viewURL = this.
target.toDataURL();
736 viewURL = this.imageURL;
737 urlSecurityCheck(viewURL,
738 this.
tabbrowser.selectedBrowser.contentPrincipal,
739 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
747 saveFrame:
function () {
748 saveDocument(this.
target.ownerDocument);
752 saveLink:
function() {
754 const NS_ERROR_SAVE_LINK_AS_TIMEOUT = 0x805d0020;
757 urlSecurityCheck(this.linkURL, doc.nodePrincipal);
758 var linkText = this.linkText();
759 var linkURL = this.linkURL;
766 function saveAsListener() {}
767 saveAsListener.prototype = {
770 onStartRequest:
function saveLinkAs_onStartRequest(aRequest, aContext) {
775 if (aRequest.status == NS_ERROR_SAVE_LINK_AS_TIMEOUT)
781 if (!Components.isSuccessCode(aRequest.status)) {
783 const sbs =
Cc[
"@mozilla.org/intl/stringbundle;1"].
785 const bundle = sbs.createBundle(
786 "chrome://mozapps/locale/downloads/downloads.properties");
788 const title =
bundle.GetStringFromName(
"downloadErrorAlertTitle");
789 const msg =
bundle.GetStringFromName(
"downloadErrorGeneric");
791 const promptSvc =
Cc[
"@mozilla.org/embedcomp/prompt-service;1"].
793 promptSvc.alert(doc.defaultView, title,
msg);
798 var extHelperAppSvc =
799 Cc[
"@mozilla.org/uriloader/external-helper-app-service;1"].
801 var channel = aRequest.QueryInterface(
Ci.nsIChannel);
803 extHelperAppSvc.doContent(channel.contentType, aRequest,
804 doc.defaultView,
true);
805 this.extListener.onStartRequest(aRequest, aContext);
808 onStopRequest:
function saveLinkAs_onStopRequest(aRequest, aContext,
810 if (aStatusCode == NS_ERROR_SAVE_LINK_AS_TIMEOUT) {
813 saveURL(linkURL, linkText,
null,
true,
false, doc.documentURIObject);
815 if (this.extListener)
816 this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
819 onDataAvailable:
function saveLinkAs_onDataAvailable(aRequest, aContext,
822 this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
828 function callbacks() {}
829 callbacks.prototype = {
830 getInterface:
function sLA_callbacks_getInterface(aIID) {
831 if (aIID.equals(
Ci.nsIAuthPrompt) || aIID.equals(
Ci.nsIAuthPrompt2)) {
832 var
ww =
Cc[
"@mozilla.org/embedcomp/window-watcher;1"].
834 return ww.getPrompt(doc.defaultView, aIID);
836 throw Cr.NS_ERROR_NO_INTERFACE;
843 function timerCallback() {}
844 timerCallback.prototype = {
845 notify:
function sLA_timer_notify(aTimer) {
846 channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT);
852 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"].
854 var channel = ioService.newChannelFromURI(this.getLinkURI());
855 channel.notificationCallbacks =
new callbacks();
856 channel.loadFlags |=
Ci.nsIRequest.LOAD_BYPASS_CACHE |
857 Ci.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS;
858 if (channel instanceof
Ci.nsIHttpChannel)
859 channel.referrer = doc.documentURIObject;
865 gPrefService.getIntPref(
"browser.download.saveLinkAsFilenameTimeout");
868 var timer =
Cc[
"@mozilla.org/timer;1"].createInstance(
Ci.nsITimer);
869 timer.initWithCallback(
new timerCallback(), timeToWait,
870 timer.TYPE_ONE_SHOT);
873 channel.asyncOpen(
new saveAsListener(),
null);
877 saveImage:
function() {
881 saveImageURL(this.
target.toDataURL(),
"canvas.png",
"SaveImageTitle",
882 true,
false, doc.documentURIObject);
885 urlSecurityCheck(this.imageURL, doc.nodePrincipal);
886 saveImageURL(this.imageURL,
null,
"SaveImageTitle",
false,
887 false, doc.documentURIObject);
891 toggleImageBlocking:
function(aBlock) {
892 var permissionmanager =
Cc[
"@mozilla.org/permissionmanager;1"].
895 var
uri = this.
target.QueryInterface(
Ci.nsIImageLoadingContent).currentURI;
898 permissionmanager.add(uri,
"image",
Ci.nsIPermissionManager.DENY_ACTION);
900 permissionmanager.remove(uri.host,
"image");
902 var
brandBundle = document.getElementById(
"bundle_brand");
903 var app = brandBundle.getString(
"brandShortName");
904 var bundle_browser = document.getElementById(
"bundle_browser");
905 var
message = bundle_browser.getFormattedString(aBlock ?
906 "imageBlockedWarning" :
"imageAllowedWarning", [app, uri.host]);
908 var notificationBox = this.
tabbrowser.getNotificationBox();
909 var notification = notificationBox.getNotificationWithValue(
"images-blocked");
916 label: bundle_browser.getString(
"undo"),
917 accessKey: bundle_browser.getString(
"undo.accessKey"),
918 callback:
function() {
self.toggleImageBlocking(!aBlock); }
920 const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
921 notificationBox.appendNotification(message,
"images-blocked",
922 "chrome://browser/skin/Info.png",
930 isImageBlocked:
function() {
931 var permissionmanager =
Cc[
"@mozilla.org/permissionmanager;1"].
934 var
uri = this.
target.QueryInterface(
Ci.nsIImageLoadingContent).currentURI;
936 return permissionmanager.testPermission(uri,
"image") ==
Ci.nsIPermissionManager.DENY_ACTION;
944 showItem:
function(aItemOrId, aShow) {
945 var item = aItemOrId.constructor ==
String ?
946 document.getElementById(aItemOrId) : aItemOrId;
948 item.hidden = !aShow;
954 setItemAttr:
function(aID, aAttr, aVal ) {
955 var
elem = document.getElementById(aID);
959 elem.removeAttribute(aAttr);
963 elem.setAttribute(aAttr, aVal);
970 setItemAttrFromNode:
function(aItem_id, aAttr, aOther_id) {
971 var
elem = document.getElementById(aOther_id);
972 if (elem && elem.getAttribute(aAttr) ==
"true")
973 this.setItemAttr(aItem_id, aAttr,
"true");
975 this.setItemAttr(aItem_id, aAttr,
null);
979 cloneNode:
function(aItem) {
981 var
node = document.createElement(aItem.tagName);
984 var attrs = aItem.attributes;
985 for (var
i = 0;
i < attrs.length;
i++) {
986 var attr = attrs.item(
i);
987 node.setAttribute(attr.nodeName, attr.nodeValue);
995 getLinkURL:
function() {
996 var
href = this.link.href;
1000 href = this.link.getAttributeNS(
"http://www.w3.org/1999/xlink",
1003 if (!href || !href.match(/\S/)) {
1012 getLinkURI:
function() {
1013 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"].
1016 return ioService.newURI(this.linkURL,
null,
null);
1025 getLinkProtocol:
function() {
1027 return this.linkURI.scheme;
1033 linkText:
function() {
1035 if (!text || !text.match(/\S/)) {
1036 text = this.link.getAttribute(
"title");
1037 if (!text || !text.match(/\S/)) {
1038 text = this.link.getAttribute(
"alt");
1039 if (!text || !text.match(/\S/))
1040 text = this.linkURL;
1048 isTextSelection:
function() {
1056 if (selectedText.length > 15)
1057 selectedText = selectedText.substr(0,15) + this.ellipsis;
1061 var engineName =
"";
1062 var ss =
Cc[
"@mozilla.org/browser/search-service;1"].
1065 engineName = ss.currentEngine.name;
1067 engineName = ss.defaultEngine.name;
1070 var menuLabel =
gNavigatorBundle.getFormattedString(
"contextMenuSearchText",
1073 document.getElementById(
"context-searchselect").label = menuLabel;
1079 isContentSelection:
function() {
1080 return !document.commandDispatcher.focusedWindow.getSelection().isCollapsed;
1083 toString:
function () {
1084 return "contextMenu.target = " + this.
target +
"\n" +
1085 "contextMenu.onImage = " + this.onImage +
"\n" +
1086 "contextMenu.onLink = " + this.onLink +
"\n" +
1087 "contextMenu.link = " + this.link +
"\n" +
1088 "contextMenu.inFrame = " + this.inFrame +
"\n" +
1089 "contextMenu.hasBGImage = " + this.hasBGImage +
"\n";
1094 isTargetAFormControl:
function(aNode) {
1095 if (aNode instanceof HTMLInputElement)
1096 return (aNode.type !=
"text" && aNode.type !=
"password");
1098 return (aNode instanceof HTMLButtonElement) ||
1099 (aNode instanceof HTMLSelectElement) ||
1100 (aNode instanceof HTMLOptionElement) ||
1101 (aNode instanceof HTMLOptGroupElement);
1104 isTargetATextBox:
function(
node) {
1105 if (
node instanceof HTMLInputElement)
1106 return (
node.type ==
"text" ||
node.type ==
"password")
1108 return (
node instanceof HTMLTextAreaElement);
1111 isTargetAKeywordField:
function(aNode) {
1112 var form = aNode.form;
1116 var method = form.method.toUpperCase();
1128 return (method ==
"GET" || method ==
"") ||
1129 (form.enctype !=
"text/plain") && (form.enctype !=
"multipart/form-data");
1135 shouldShowSeparator:
function (aSeparatorID) {
1136 var separator = document.getElementById(aSeparatorID);
1138 var sibling = separator.previousSibling;
1139 while (sibling && sibling.localName !=
"menuseparator") {
1140 if (!sibling.hidden)
1142 sibling = sibling.previousSibling;
1148 addDictionaries:
function() {
1151 uri =
formatURL(
"browser.dictionaries.download.url",
true);
1153 Components.utils.reportError(
"Dictionnary URL not found in prefs");
1158 locale =
gPrefService.getComplexValue(
"intl.accept_languages",
1159 Ci.nsIPrefLocalizedString).data;
1165 version =
Cc[
"@mozilla.org/xre/app-info;1"].
1170 uri = uri.replace(/%LOCALE%/, escape(locale)).replace(/%VERSION%/, version);
1180 savePageAs:
function CM_savePageAs() {
1181 saveDocument(this.
tabbrowser.selectedBrowser.contentDocument);
1184 switchPageDirection:
function CM_switchPageDirection() {
1189 updateAddToPlaylist:
function CM_updateAddToPlaylist() {
1190 var sep = document.getElementById(
"context-sep-playlists");
1191 var popup = sep.parentNode;
1192 var elements = document.getElementsByAttribute(
"type",
"addtoplaylist");
1193 while (elements.length > 0) {
1194 popup.removeChild(elements[0]);
1196 var
libraryManager = Components.classes[
"@songbirdnest.com/Songbird/library/Manager;1"]
1197 .getService(Components.interfaces.sbILibraryManager);
1198 var libs = libraryManager.getLibraries();
1200 while (libs.hasMoreElements()) {
1201 var library = libs.getNext();
1202 nadded += this.updateAddToPlaylistForLibrary(library);
1206 this.showItem(
"context-addmediatoplaylist-noplaylist", (nadded == 0));
1210 updateAddToPlaylistForLibrary:
function CM_addToPlayListForLibrary(aLibrary) {
1212 var sep = document.getElementById(
"context-sep-playlists");
1213 var popup = sep.parentNode;
1219 _downloadListGUID:
null,
1220 _libraryServicePane:
null,
1221 onEnumerationBegin:
function() {
1222 var ddh = Components.classes[
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1"]
1223 .getService(Components.interfaces.sbIDownloadDeviceHelper);
1224 var downloadMediaList = ddh.getDownloadMediaList();
1225 if (downloadMediaList)
1226 this._downloadListGUID = downloadMediaList.guid;
1228 this._libraryServicePane =
1229 Components.classes[
'@songbirdnest.com/servicepane/library;1']
1230 .getService(Components.interfaces.sbILibraryServicePaneService);
1232 onEnumerationEnd:
function() { },
1233 onEnumeratedItem:
function(list, item) {
1235 var
hidden = item.getProperty(
"http://songbirdnest.com/data/1.0#hidden");
1236 if (hidden ==
"1" ||
1237 item.type !=
"simple") {
1238 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
1244 if (item.guid ==
this._downloadListGUID) {
1245 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
1249 function isHidden(
node) {
1251 if (
node.hidden)
return true;
1256 var
node = this._libraryServicePane.getNodeForLibraryResource(item);
1257 if (!node || isHidden(node)) {
1258 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
1262 var menuitem = document.createElement(
"menuitem");
1263 menuitem.setAttribute(
"type",
"addtoplaylist");
1264 menuitem.setAttribute(
"library", aLibrary.guid);
1265 menuitem.setAttribute(
"playlist", item.guid);
1268 songbird_bundle = document.getElementById(
"songbird_strings");
1269 menuitem.setAttribute(
"label", songbird_bundle.getString(
"addMediaToPlaylistCmd.unnamedPlaylist"));
1271 menuitem.setAttribute(
"label", item.name);
1273 menuitem.setAttribute(
"oncommand",
"gContextMenu.addMediaToPlaylist(event);");
1274 popup.insertBefore(menuitem, sep);
1280 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
1285 aLibrary.enumerateItemsByProperty(
"http://songbirdnest.com/data/1.0#isList",
"1",
1293 addMediaToPlaylist:
function CM_addMediaToPlaylist(aEvent) {
1295 var libraryguid = aEvent.target.getAttribute(
"library");
1296 var playlistguid = aEvent.target.getAttribute(
"playlist");
1298 var
libraryManager = Components.classes[
"@songbirdnest.com/Songbird/library/Manager;1"]
1299 .getService(Components.interfaces.sbILibraryManager);
1300 var library = libraryManager.getLibrary(libraryguid);
1302 var playlist = library.getMediaItem(playlistguid);
1305 this._addMediaToPlaylist(playlist);
1310 throw new Error(
"addMediaToPlaylist invoked with invalid playlist");
1314 addMediaToNewPlaylist:
function CM_addMediaToNewPlaylist() {
1318 var newMediaList =
window.makeNewPlaylist(
"simple");
1319 this._addMediaToPlaylist(newMediaList);
1323 _addMediaToPlaylist:
function CM__addMediaToPlaylist(
aPlaylist) {
1330 downloadMedia:
function CM_downloadMedia() {
1336 "http://songbirdnest.com/data/1.0#contentURL",
1341 "http://songbirdnest.com/data/1.0#originURL",
1350 var dropHandlerListener = {
1351 onDropComplete:
function(aTargetList,
1354 aInsertedInMediaList,
1355 aOtherDropsHandled) {
1359 onFirstMediaItem:
function(aTargetList, aFirstMediaItem) { },
1361 ExternalDropHandler.dropUrlsOnList(
window, [this.linkURL],
LibraryUtils.webLibrary, -1, dropHandlerListener);
1365 "http://songbirdnest.com/data/1.0#contentURL",
1368 throw new Error(
"Failed to find media item after dropping it in the web library");
1373 var ddh = Components.classes[
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1"]
1374 .getService(Components.interfaces.sbIDownloadDeviceHelper);
1375 ddh.downloadItem(item);
1378 playMedia:
function CM_playMedia() {
1379 gBrowser.handleMediaURL(this.linkURL,
true,
false);
1382 subscribeMediaPage:
function CM_subscribeToPage() {
1383 this._subscribeMedia(gBrowser.currentURI);
1386 subscribeMediaFrame:
function CM_subscribeToFrame() {
1388 this._subscribeMedia(doc.documentURIObject);
1391 _subscribeMedia:
function CM_subscribeToURL(aURI) {
1392 SBSubscribe(
null, aURI);
function openNewTabWith(aURL, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aReferrer)
function getFirstItemByProperty(aMediaList, aProperty, aValue)
function mimeTypeIsTextBased(aMimeType)
function gatherTextUnder(root)
function openUILinkIn(url, where, allowThirdPartyFixup, postData, referrerUrl)
function doc() browser.contentDocument
function makeURLAbsolute(aBase, aUrl)
function formatURL(aFormat, aIsPref)
function getBrowserSelection(aCharLen)
getService(Ci.sbIFaceplateManager)
function BrowserViewSourceOfDocument(aDocument)
TimerLoop prototype notify
this _contentSandbox label
function makeURI(aURLSpec, aCharset)
function isElementVisible(aElement)
function openUILink(url, e, ignoreButton, ignoreAlt, allowKeywordFixup, postData, referrerUrl)
_updateTextAndScrollDataForTab aBrowser
return aWindow document documentElement getAttribute(aAttribute)||dimension
Javascript wrappers for common library tasks.
restoreHistoryPrecursor aCount
function SwitchDocumentDirection(aWindow)
_getSelectedPageStyle s i