1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
14 # The Original Code is mozilla.org code.
16 # The Initial Developer of the Original Code is
17 # Netscape Communications Corporation.
18 # Portions created by the Initial Developer are Copyright (C) 1998
19 # the Initial Developer. All Rights Reserved.
22 # Blake Ross <blake@cs.stanford.edu>
23 # David Hyatt <hyatt@mozilla.org>
24 # Peter Annema <disttsc@bart.nl>
25 # Dean Tessman <dean_tessman@hotmail.com>
26 # Kevin Puetz <puetzk@iastate.edu>
27 # Ben Goodger <ben@netscape.com>
28 # Pierre Chanial <chanial@noos.fr>
29 # Jason Eager <jce2@po.cwru.edu>
30 # Joe Hewitt <hewitt@netscape.com>
31 # Alec Flett <alecf@netscape.com>
32 # Asaf Romano <mozilla.mano@sent.com>
33 # Jason Barnabe <jason_barnabe@fastmail.fm>
34 # Peter Parente <parente@cs.unc.edu>
35 # Giorgio Maone <g.maone@informaction.com>
36 # Tom Germeau <tom.germeau@epigoon.com>
37 # Jesse Ruderman <jruderman@gmail.com>
38 # Joe Hughes <joe@retrovirus.com>
39 # Pamela Greene <pamg.bugs@gmail.com>
40 # Michael Ventnor <ventnors_dogs234@yahoo.com.au>
41 # Simon Bünzli <zeniko@gmail.com>
42 # Gijs Kruitbosch <gijskruitbosch@gmail.com>
43 # Ehsan Akhgari <ehsan.akhgari@gmail.com>
44 # Dan Mosedale <dmose@mozilla.org>
45 # Justin Dolske <dolske@mozilla.com>
46 # Kathleen Brade <brade@pearlcrescent.com>
47 # Mark Smith <mcs@pearlcrescent.com>
49 # Alternatively, the contents of this file may be used under the terms of
50 # either the GNU General Public License Version 2 or later (the "GPL"), or
51 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
52 # in which case the provisions of the GPL or the LGPL are applicable instead
53 # of those above. If you wish to allow use of your version of this file only
54 # under the terms of either the GPL or the LGPL, and not to allow others to
55 # use your version of this file under the terms of the MPL, indicate your
56 # decision by deleting the provisions above and replace them with the notice
57 # and other provisions required by the GPL or the LGPL. If you do not delete
58 # the provisions above, a recipient may use your version of this file under
59 # the terms of any one of the MPL, the GPL or the LGPL.
61 # ***** END LICENSE BLOCK *****
67 this.isFrameImage =
false;
68 this.onTextInput =
false;
69 this.onKeywordField =
false;
71 this.onLoadedImage =
false;
72 this.onCompletedImage =
false;
73 this.onCanvas =
false;
77 this.onMailtoLink =
false;
78 this.onSaveableLink =
false;
79 this.onMathML =
false;
83 this.linkProtocol =
null;
85 this.hasBGImage =
false;
86 this.isTextSelected =
false;
87 this.isContentSelected =
false;
88 this.shouldDisplay =
true;
89 this.isDesignMode =
false;
90 this.possibleSpellChecking =
false;
91 this.ellipsis =
"\u2026";
93 this.ellipsis =
gPrefService.getComplexValue(
"intl.ellipsis",
94 Ci.nsIPrefLocalizedString).data;
104 onDestroy:
function () {
108 initMenu:
function CM_initMenu(aPopup,
aBrowser) {
112 this.isFrameImage = document.getElementById(
"isFrameImage");
115 this.setTarget(document.popupNode, document.popupRangeParent,
116 document.popupRangeOffset);
118 this.isTextSelected = this.isTextSelection();
119 this.isContentSelected = this.isContentSelection();
125 initItems:
function CM_initItems() {
126 this.initOpenItems();
127 this.initNavigationItems();
128 this.initViewItems();
129 this.initMiscItems();
130 this.initSpellingItems();
131 this.initSaveItems();
132 this.initClipboardItems();
133 this.initMediaPlayerItems();
136 initOpenItems:
function CM_initOpenItems() {
137 var isMailtoInternal =
false;
138 if (this.onMailtoLink) {
139 var mailtoHandler =
Cc[
"@mozilla.org/uriloader/external-protocol-service;1"].
141 getProtocolHandlerInfo(
"mailto");
142 isMailtoInternal = (!mailtoHandler.alwaysAskBeforeHandling &&
143 mailtoHandler.preferredAction ==
Ci.nsIHandlerInfo.useHelperApp &&
144 (mailtoHandler.preferredApplicationHandler instanceof
Ci.nsIWebHandlerApp));
146 var shouldShow = this.onSaveableLink || isMailtoInternal;
147 this.showItem(
"context-openlink", shouldShow);
148 this.showItem(
"context-openlinkintab", shouldShow);
149 this.showItem(
"context-sep-open", shouldShow);
152 initNavigationItems:
function CM_initNavigationItems() {
153 var shouldShow = !(this.isContentSelected || this.onLink || this.onImage ||
154 this.onCanvas || this.onVideo || this.onAudio ||
156 this.showItem(
"context-back", shouldShow);
157 this.showItem(
"context-forward", shouldShow);
158 this.showItem(
"context-reload", shouldShow);
159 this.showItem(
"context-stop", shouldShow);
160 this.showItem(
"context-sep-stop", shouldShow);
166 initSaveItems:
function CM_initSaveItems() {
167 var shouldShow = !(this.onTextInput || this.onLink ||
168 this.isContentSelected || this.onImage ||
169 this.onCanvas || this.onVideo || this.onAudio);
170 this.showItem(
"context-savepage", shouldShow);
171 this.showItem(
"context-sendpage", shouldShow);
174 this.showItem(
"context-savelink", this.onSaveableLink);
175 this.showItem(
"context-sendlink", this.onSaveableLink);
178 this.showItem(
"context-saveimage", this.onLoadedImage || this.onCanvas);
179 this.showItem(
"context-savevideo", this.onVideo);
180 this.showItem(
"context-saveaudio", this.onAudio);
181 this.setItemAttr(
"context-savevideo",
"disabled", !this.mediaURL);
182 this.setItemAttr(
"context-saveaudio",
"disabled", !this.mediaURL);
184 this.showItem(
"context-sendimage", this.onImage);
185 this.showItem(
"context-sendvideo", this.onVideo);
186 this.showItem(
"context-sendaudio", this.onAudio);
187 this.setItemAttr(
"context-sendvideo",
"disabled", !this.mediaURL);
188 this.setItemAttr(
"context-sendaudio",
"disabled", !this.mediaURL);
191 initViewItems:
function CM_initViewItems() {
193 this.showItem(
"context-viewpartialsource-selection",
194 this.isContentSelected);
195 this.showItem(
"context-viewpartialsource-mathml",
196 this.onMathML && !this.isContentSelected);
198 var shouldShow = !(this.isContentSelected ||
199 this.onImage || this.onCanvas ||
200 this.onVideo || this.onAudio ||
201 this.onLink || this.onTextInput);
202 this.showItem(
"context-viewsource", shouldShow);
203 this.showItem(
"context-viewinfo", shouldShow);
205 this.showItem(
"context-sep-viewsource", shouldShow);
209 var haveSetDesktopBackground =
false;
210 #ifdef HAVE_SHELL_SERVICE
214 haveSetDesktopBackground =
true;
216 this.showItem(
"context-setDesktopBackground",
217 haveSetDesktopBackground && this.onLoadedImage);
219 if (haveSetDesktopBackground && this.onLoadedImage) {
220 document.getElementById(
"context-setDesktopBackground")
221 .disabled = this.disableSetDesktopBackground();
225 this.showItem(
"context-reloadimage", (this.onImage && !this.onCompletedImage));
229 this.showItem(
"context-viewimage", (this.onImage &&
230 (!this.onStandaloneImage || this.inFrame)) || this.onCanvas);
232 this.showItem(
"context-viewvideo", this.onVideo);
233 this.setItemAttr(
"context-viewvideo",
"disabled", !this.mediaURL);
236 this.showItem(
"context-viewbgimage", shouldShow && !this._hasMultipleBGImages);
237 this.showItem(
"context-sep-viewbgimage", shouldShow && !this._hasMultipleBGImages);
238 document.getElementById(
"context-viewbgimage")
239 .disabled = !this.hasBGImage;
241 this.showItem(
"context-viewimageinfo", this.onImage);
244 initMiscItems:
function CM_initMiscItems() {
245 var isTextSelected = this.isTextSelected;
248 this.showItem(
"context-bookmarkpage",
249 !(this.isContentSelected || this.onTextInput || this.onLink ||
250 this.onImage || this.onVideo || this.onAudio));
251 this.showItem(
"context-bookmarklink", this.onLink && !this.onMailtoLink);
252 this.showItem(
"context-searchselect", isTextSelected);
253 this.showItem(
"context-keywordfield",
254 this.onTextInput && this.onKeywordField);
255 this.showItem(
"frame", this.inFrame);
256 this.showItem(
"frame-sep", this.inFrame && isTextSelected);
261 this.isFrameImage.removeAttribute(
'hidden');
263 this.isFrameImage.setAttribute(
'hidden',
'true');
267 this.showItem(
"context-sep-bidi",
top.gBidiUI);
268 this.showItem(
"context-bidi-text-direction-toggle",
269 this.onTextInput &&
top.gBidiUI);
270 this.showItem(
"context-bidi-page-direction-toggle",
271 !this.onTextInput &&
top.gBidiUI);
274 var blockImage = document.getElementById(
"context-blockimage");
277 .QueryInterface(
Ci.nsIImageLoadingContent)
284 hostLabel = uri.host;
288 var shortenedUriHost = hostLabel.replace(/^www\./
i,
"");
289 if (shortenedUriHost.length > 15)
290 shortenedUriHost = shortenedUriHost.substr(0,15) + this.ellipsis;
291 blockImage.label =
gNavigatorBundle.getFormattedString(
"blockImages", [shortenedUriHost]);
293 if (this.isImageBlocked())
294 blockImage.setAttribute(
"checked",
"true");
296 blockImage.removeAttribute(
"checked");
301 this.showItem(
"context-blockimage", this.onImage && hostLabel &&
305 initSpellingItems:
function() {
306 var canSpell = InlineSpellCheckerUI.canSpellCheck;
307 var onMisspelling = InlineSpellCheckerUI.overMisspelling;
308 this.showItem(
"spell-check-enabled", canSpell);
309 this.showItem(
"spell-separator", canSpell || this.possibleSpellChecking);
311 document.getElementById(
"spell-check-enabled")
312 .setAttribute(
"checked", InlineSpellCheckerUI.enabled);
315 this.showItem(
"spell-add-to-dictionary", onMisspelling);
318 this.showItem(
"spell-suggestions-separator", onMisspelling);
320 var
menu = document.getElementById(
"contentAreaContextMenu");
321 var suggestionsSeparator =
322 document.getElementById(
"spell-add-to-dictionary");
323 var numsug = InlineSpellCheckerUI.addSuggestionsToMenu(menu, suggestionsSeparator, 5);
324 this.showItem(
"spell-no-suggestions", numsug == 0);
327 this.showItem(
"spell-no-suggestions",
false);
330 this.showItem(
"spell-dictionaries", InlineSpellCheckerUI.enabled);
332 var dictMenu = document.getElementById(
"spell-dictionaries-menu");
333 var dictSep = document.getElementById(
"spell-language-separator");
334 InlineSpellCheckerUI.addDictionaryListToMenu(dictMenu, dictSep);
335 this.showItem(
"spell-add-dictionaries-main",
false);
337 else if (this.possibleSpellChecking) {
341 this.showItem(
"spell-add-dictionaries-main",
true);
344 this.showItem(
"spell-add-dictionaries-main",
false);
347 initClipboardItems:
function() {
352 goUpdateGlobalEditMenuItems();
354 this.showItem(
"context-undo", this.onTextInput);
355 this.showItem(
"context-sep-undo", this.onTextInput);
356 this.showItem(
"context-cut", this.onTextInput);
357 this.showItem(
"context-copy",
358 this.isContentSelected || this.onTextInput);
359 this.showItem(
"context-paste", this.onTextInput);
360 this.showItem(
"context-delete", this.onTextInput);
361 this.showItem(
"context-sep-paste", this.onTextInput);
362 this.showItem(
"context-selectall", !(this.onLink || this.onImage ||
363 this.onVideo || this.onAudio) || this.isDesignMode);
364 this.showItem(
"context-sep-selectall", this.isContentSelected );
372 this.showItem(
"context-copyemail", this.onMailtoLink);
375 this.showItem(
"context-copylink", this.onLink && !this.onMailtoLink);
376 this.showItem(
"context-sep-copylink", this.onLink &&
377 (this.onImage || this.onVideo || this.onAudio));
379 #ifdef CONTEXT_COPY_IMAGE_CONTENTS
381 this.showItem(
"context-copyimage-contents", this.onImage);
384 this.showItem(
"context-copyimage", this.onImage);
385 this.showItem(
"context-copyvideourl", this.onVideo);
386 this.showItem(
"context-copyaudiourl", this.onAudio);
387 this.setItemAttr(
"context-copyvideourl",
"disabled", !this.mediaURL);
388 this.setItemAttr(
"context-copyaudiourl",
"disabled", !this.mediaURL);
389 this.showItem(
"context-sep-copyimage", this.onImage ||
390 this.onVideo || this.onAudio);
393 initMediaPlayerItems:
function() {
394 var onMedia = (this.onVideo || this.onAudio);
396 this.showItem(
"context-media-play", onMedia && (this.
target.paused ||
this.target.ended));
397 this.showItem(
"context-media-pause", onMedia && !this.
target.paused && !
this.target.ended);
398 this.showItem(
"context-media-mute", onMedia && !this.
target.muted);
399 this.showItem(
"context-media-unmute", onMedia && this.
target.muted);
400 this.showItem(
"context-media-showcontrols", onMedia && !this.
target.controls);
401 this.showItem(
"context-media-hidecontrols", onMedia && this.
target.controls);
402 this.showItem(
"context-video-fullscreen", this.onVideo);
406 this.setItemAttr(
"context-media-play",
"disabled", hasError);
407 this.setItemAttr(
"context-media-pause",
"disabled", hasError);
408 this.setItemAttr(
"context-media-mute",
"disabled", hasError);
409 this.setItemAttr(
"context-media-unmute",
"disabled", hasError);
410 this.setItemAttr(
"context-media-showcontrols",
"disabled", hasError);
411 this.setItemAttr(
"context-media-hidecontrols",
"disabled", hasError);
413 this.setItemAttr(
"context-video-fullscreen",
"disabled", hasError);
415 this.showItem(
"context-media-sep-commands", onMedia);
419 setTarget:
function (aNode, aRangeParent, aRangeOffset) {
420 const xulNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
421 if (aNode.namespaceURI == xulNS ||
422 this.isTargetAFormControl(aNode)) {
423 this.shouldDisplay =
false;
427 this.onImage =
false;
428 this.onLoadedImage =
false;
429 this.onCompletedImage =
false;
430 this.onStandaloneImage =
false;
431 this.onCanvas =
false;
432 this.onVideo =
false;
433 this.onAudio =
false;
434 this.onTextInput =
false;
435 this.onKeywordField =
false;
440 this.linkProtocol =
"";
441 this.onMathML =
false;
442 this.inFrame =
false;
443 this.hasBGImage =
false;
444 this.bgImageURL =
"";
445 this.possibleSpellChecking =
false;
452 InlineSpellCheckerUI.clearSuggestionsFromMenu();
453 InlineSpellCheckerUI.clearDictionaryListFromMenu();
455 InlineSpellCheckerUI.uninit();
461 if (this.
target.nodeType == Node.ELEMENT_NODE) {
463 if (this.
target instanceof
Ci.nsIImageLoadingContent &&
464 this.target.currentURI) {
468 this.
target.getRequest(
Ci.nsIImageLoadingContent.CURRENT_REQUEST);
469 if (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE))
470 this.onLoadedImage =
true;
471 if (request && (request.imageStatus & request.STATUS_LOAD_COMPLETE))
472 this.onCompletedImage =
true;
474 this.mediaURL = this.
target.currentURI.spec;
475 if (this.
target.ownerDocument instanceof ImageDocument)
476 this.onStandaloneImage =
true;
478 else if (this.
target instanceof HTMLCanvasElement) {
479 this.onCanvas =
true;
481 else if (this.
target instanceof HTMLVideoElement) {
483 this.mediaURL = this.
target.currentSrc || this.
target.src;
485 else if (this.
target instanceof HTMLAudioElement) {
487 this.mediaURL = this.
target.currentSrc || this.
target.src;
489 else if (this.
target instanceof HTMLInputElement ) {
490 this.onTextInput = this.isTargetATextBox(this.
target);
492 if (this.onTextInput && ! this.
target.readOnly &&
493 this.target.type !=
"password") {
494 this.possibleSpellChecking =
true;
495 InlineSpellCheckerUI.init(this.
target.QueryInterface(
Ci.nsIDOMNSEditableElement).editor);
496 InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
498 this.onKeywordField = this.isTargetAKeywordField(this.
target);
500 else if (this.
target instanceof HTMLTextAreaElement) {
501 this.onTextInput =
true;
502 if (!this.
target.readOnly) {
503 this.possibleSpellChecking =
true;
504 InlineSpellCheckerUI.init(this.
target.QueryInterface(
Ci.nsIDOMNSEditableElement).editor);
505 InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
508 else if (this.
target instanceof HTMLHtmlElement) {
509 var bodyElt = this.
target.ownerDocument.body;
513 computedURL = this.getComputedURL(bodyElt,
"background-image");
514 this._hasMultipleBGImages =
false;
516 this._hasMultipleBGImages =
true;
519 this.hasBGImage =
true;
529 const XMLNS =
"http://www.w3.org/XML/1998/namespace";
532 if (elem.nodeType == Node.ELEMENT_NODE) {
535 ((elem instanceof HTMLAnchorElement && elem.href) ||
536 (elem instanceof HTMLAreaElement && elem.href) ||
537 elem instanceof HTMLLinkElement ||
538 elem.getAttributeNS(
"http://www.w3.org/1999/xlink",
"type") ==
"simple")) {
548 while ((parent = parent.parentNode) &&
549 (parent.nodeType == Node.ELEMENT_NODE)) {
551 if ((parent instanceof HTMLAnchorElement && parent.href) ||
552 (parent instanceof HTMLAreaElement && parent.href) ||
553 parent instanceof HTMLLinkElement ||
554 parent.getAttributeNS(
"http://www.w3.org/1999/xlink",
"type") ==
"simple")
560 this.link = realLink;
561 this.linkURL = this.getLinkURL();
562 this.linkURI = this.getLinkURI();
563 this.linkProtocol = this.getLinkProtocol();
564 this.onMailtoLink = (this.linkProtocol ==
"mailto");
565 this.onSaveableLink = this.isLinkSaveable( this.link );
571 if (!this.hasBGImage &&
572 !this._hasMultipleBGImages) {
575 bgImgUrl = this.getComputedURL(elem,
"background-image");
576 this._hasMultipleBGImages =
false;
578 this._hasMultipleBGImages =
true;
581 this.hasBGImage =
true;
588 elem = elem.parentNode;
592 const NS_MathML =
"http://www.w3.org/1998/Math/MathML";
593 if ((this.
target.nodeType == Node.TEXT_NODE &&
594 this.target.parentNode.namespaceURI == NS_MathML)
595 || (
this.target.namespaceURI == NS_MathML))
596 this.onMathML =
true;
599 var docDefaultView = this.
target.ownerDocument.defaultView;
600 if (docDefaultView != docDefaultView.top)
604 var
win = this.
target.ownerDocument.defaultView;
606 var isEditable =
false;
608 var editingSession = win.QueryInterface(
Ci.nsIInterfaceRequestor)
609 .getInterface(
Ci.nsIWebNavigation)
610 .QueryInterface(
Ci.nsIInterfaceRequestor)
611 .getInterface(
Ci.nsIEditingSession);
612 if (editingSession.windowIsEditable(win) &&
613 this.getComputedStyle(this.
target,
"-moz-user-modify") ==
"read-write") {
622 this.onTextInput =
true;
623 this.onKeywordField =
false;
624 this.onImage =
false;
625 this.onLoadedImage =
false;
626 this.onCompletedImage =
false;
627 this.onMathML =
false;
628 this.inFrame =
false;
629 this.hasBGImage =
false;
630 this.isDesignMode =
true;
631 this.possibleSpellChecking =
true;
632 InlineSpellCheckerUI.init(editingSession.getEditorForWindow(win));
633 var canSpell = InlineSpellCheckerUI.canSpellCheck;
634 InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
635 this.showItem(
"spell-check-enabled", canSpell);
636 this.showItem(
"spell-separator", canSpell);
642 getComputedStyle:
function(aElem, aProp) {
643 return aElem.ownerDocument
645 .getComputedStyle(aElem,
"").getPropertyValue(aProp);
649 getComputedURL:
function(aElem, aProp) {
650 var
url = aElem.ownerDocument
651 .defaultView.getComputedStyle(aElem,
"")
652 .getPropertyCSSValue(aProp);
653 if (url instanceof CSSValueList) {
655 throw "found multiple URLs";
658 return url.primitiveType == CSSPrimitiveValue.CSS_URI ?
659 url.getStringValue() :
null;
663 isLinkSaveable:
function(aLink) {
666 return this.linkProtocol && !(
667 this.linkProtocol ==
"mailto" ||
668 this.linkProtocol ==
"javascript" ||
669 this.linkProtocol ==
"news" ||
670 this.linkProtocol ==
"snews" );
674 openLink :
function () {
679 openLinkInTab:
function() {
684 openFrameInTab:
function() {
686 var frameURL = doc.location.href;
687 var referrer = doc.referrer;
694 reloadFrame:
function() {
695 this.
target.ownerDocument.location.reload();
699 openFrame:
function() {
701 var frameURL = doc.location.href;
702 var referrer = doc.referrer;
709 showOnlyThisFrame:
function() {
711 var frameURL = doc.location.href;
713 urlSecurityCheck(frameURL, this.
browser.contentPrincipal,
714 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
715 var referrer = doc.referrer;
720 viewPartialSource:
function(aContext) {
721 var focusedWindow = document.commandDispatcher.focusedWindow;
722 if (focusedWindow ==
window)
723 focusedWindow = content;
725 var docCharset =
null;
727 docCharset =
"charset=" + focusedWindow.document.characterSet;
732 var reference =
null;
733 if (aContext ==
"selection")
734 reference = focusedWindow.getSelection();
735 else if (aContext ==
"mathml")
742 window.openDialog(
"chrome://global/content/viewPartialSource.xul",
743 "_blank",
"scrollbars,resizable,chrome,dialog=no",
744 docUrl, docCharset, reference, aContext);
748 viewFrameSource:
function() {
752 viewInfo:
function() {
756 viewImageInfo:
function() {
758 "mediaTab",
this.target);
761 viewFrameInfo:
function() {
765 reloadImage:
function(e) {
766 urlSecurityCheck(this.mediaURL,
768 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
770 if (this.
target instanceof
Ci.nsIImageLoadingContent)
771 this.
target.forceReload();
775 viewMedia:
function(e) {
779 viewURL = this.
target.toDataURL();
781 viewURL = this.mediaURL;
782 urlSecurityCheck(viewURL,
784 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
791 fullScreenVideo:
function () {
794 openDialog(
"chrome://browser/content/fullscreen-video.xhtml",
795 "",
"chrome,dialog=no", this.
target);
799 viewBGImage:
function(e) {
800 urlSecurityCheck(this.bgImageURL,
802 Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
807 disableSetDesktopBackground:
function() {
810 if (!(this.
target instanceof
Ci.nsIImageLoadingContent))
813 if ((
"complete" in this.
target) && !this.target.complete)
816 if (this.target.currentURI.schemeIs(
"javascript"))
819 var request = this.target
820 .QueryInterface(
Ci.nsIImageLoadingContent)
821 .getRequest(
Ci.nsIImageLoadingContent.CURRENT_REQUEST);
828 setDesktopBackground:
function() {
831 if (this.disableSetDesktopBackground())
834 urlSecurityCheck(this.
target.currentURI.spec,
835 this.target.ownerDocument.nodePrincipal);
838 const kDesktopBackgroundURL =
839 "chrome://browser/content/setDesktopBackground.xul";
843 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
844 .getService(Components.interfaces.nsIWindowMediator);
845 var dbWin = wm.getMostRecentWindow(
"Shell:SetDesktopBackground");
847 dbWin.gSetBackground.init(this.
target);
851 openDialog(kDesktopBackgroundURL,
"",
852 "centerscreen,chrome,dialog=no,dependent,resizable=no",
857 openDialog(kDesktopBackgroundURL,
"",
858 "centerscreen,chrome,dialog,modal,dependent",
864 saveFrame:
function () {
865 saveDocument(this.
target.ownerDocument);
869 saveLink:
function() {
871 const NS_ERROR_SAVE_LINK_AS_TIMEOUT = 0x805d0020;
874 urlSecurityCheck(this.linkURL, doc.nodePrincipal);
875 var linkText = this.linkText();
876 var linkURL = this.linkURL;
883 function saveAsListener() {}
884 saveAsListener.prototype = {
887 onStartRequest:
function saveLinkAs_onStartRequest(aRequest, aContext) {
892 if (aRequest.status == NS_ERROR_SAVE_LINK_AS_TIMEOUT)
898 if (!Components.isSuccessCode(aRequest.status)) {
900 const sbs =
Cc[
"@mozilla.org/intl/stringbundle;1"].
902 const bundle = sbs.createBundle(
903 "chrome://mozapps/locale/downloads/downloads.properties");
905 const title =
bundle.GetStringFromName(
"downloadErrorAlertTitle");
906 const msg =
bundle.GetStringFromName(
"downloadErrorGeneric");
908 const promptSvc =
Cc[
"@mozilla.org/embedcomp/prompt-service;1"].
910 promptSvc.alert(doc.defaultView, title,
msg);
915 var extHelperAppSvc =
916 Cc[
"@mozilla.org/uriloader/external-helper-app-service;1"].
918 var channel = aRequest.QueryInterface(
Ci.nsIChannel);
920 extHelperAppSvc.doContent(channel.contentType, aRequest,
921 doc.defaultView,
true);
922 this.extListener.onStartRequest(aRequest, aContext);
925 onStopRequest:
function saveLinkAs_onStopRequest(aRequest, aContext,
927 if (aStatusCode == NS_ERROR_SAVE_LINK_AS_TIMEOUT) {
930 saveURL(linkURL, linkText,
null,
true,
false, doc.documentURIObject);
932 if (this.extListener)
933 this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
936 onDataAvailable:
function saveLinkAs_onDataAvailable(aRequest, aContext,
939 this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
945 function callbacks() {}
946 callbacks.prototype = {
947 getInterface:
function sLA_callbacks_getInterface(aIID) {
948 if (aIID.equals(
Ci.nsIAuthPrompt) || aIID.equals(
Ci.nsIAuthPrompt2)) {
949 var
ww =
Cc[
"@mozilla.org/embedcomp/window-watcher;1"].
951 return ww.getPrompt(doc.defaultView, aIID);
953 throw Cr.NS_ERROR_NO_INTERFACE;
960 function timerCallback() {}
961 timerCallback.prototype = {
962 notify:
function sLA_timer_notify(aTimer) {
963 channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT);
969 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"].
971 var channel = ioService.newChannelFromURI(this.getLinkURI());
972 channel.notificationCallbacks =
new callbacks();
973 channel.loadFlags |=
Ci.nsIRequest.LOAD_BYPASS_CACHE |
974 Ci.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS;
975 if (channel instanceof
Ci.nsIHttpChannel) {
976 channel.referrer = doc.documentURIObject;
977 if (channel instanceof
Ci.nsIHttpChannelInternal)
978 channel.forceAllowThirdPartyCookie =
true;
983 gPrefService.getIntPref(
"browser.download.saveLinkAsFilenameTimeout");
984 var timer =
Cc[
"@mozilla.org/timer;1"].createInstance(
Ci.nsITimer);
985 timer.initWithCallback(
new timerCallback(), timeToWait,
986 timer.TYPE_ONE_SHOT);
989 channel.asyncOpen(
new saveAsListener(),
null);
992 sendLink:
function() {
998 saveImage :
function() {
999 if (this.onCanvas || this.onImage)
1006 if (this.onCanvas) {
1008 saveImageURL(this.
target.toDataURL(),
"canvas.png",
"SaveImageTitle",
1009 true,
false, doc.documentURIObject);
1011 else if (this.onImage) {
1012 urlSecurityCheck(this.mediaURL, doc.nodePrincipal);
1013 saveImageURL(this.mediaURL,
null,
"SaveImageTitle",
false,
1014 false, doc.documentURIObject);
1016 else if (this.onVideo || this.onAudio) {
1017 urlSecurityCheck(this.mediaURL, doc.nodePrincipal);
1018 var dialogTitle = this.onVideo ?
"SaveVideoTitle" :
"SaveAudioTitle";
1019 saveURL(this.mediaURL,
null, dialogTitle,
false,
1020 false, doc.documentURIObject);
1025 sendImage :
function() {
1026 if (this.onCanvas || this.onImage)
1030 sendMedia:
function() {
1034 toggleImageBlocking:
function(aBlock) {
1035 var permissionmanager =
Cc[
"@mozilla.org/permissionmanager;1"].
1038 var
uri = this.
target.QueryInterface(
Ci.nsIImageLoadingContent).currentURI;
1041 permissionmanager.add(uri,
"image",
Ci.nsIPermissionManager.DENY_ACTION);
1043 permissionmanager.remove(uri.host,
"image");
1045 var
brandBundle = document.getElementById(
"bundle_brand");
1046 var app = brandBundle.getString(
"brandShortName");
1048 "imageBlockedWarning" :
"imageAllowedWarning", [app, uri.host]);
1050 var notificationBox = this.
browser.getNotificationBox();
1051 var notification = notificationBox.getNotificationWithValue(
"images-blocked");
1060 callback:
function() {
self.toggleImageBlocking(!aBlock); }
1062 const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
1063 notificationBox.appendNotification(message,
"images-blocked",
1064 "chrome://browser/skin/Info.png",
1072 isImageBlocked:
function() {
1073 var permissionmanager =
Cc[
"@mozilla.org/permissionmanager;1"].
1076 var
uri = this.
target.QueryInterface(
Ci.nsIImageLoadingContent).currentURI;
1078 return permissionmanager.testPermission(uri,
"image") ==
Ci.nsIPermissionManager.DENY_ACTION;
1082 copyEmail:
function() {
1086 var
url = this.linkURL;
1087 var qmark = url.indexOf(
"?");
1091 addresses = qmark > 7 ? url.substring(7, qmark) : url.substr(7);
1096 var characterSet = this.
target.ownerDocument.characterSet;
1097 const textToSubURI =
Cc[
"@mozilla.org/intl/texttosuburi;1"].
1099 addresses = textToSubURI.unEscapeURIForUI(characterSet, addresses);
1105 var clipboard =
Cc[
"@mozilla.org/widget/clipboardhelper;1"].
1107 clipboard.copyString(addresses);
1115 showItem:
function(aItemOrId, aShow) {
1116 var item = aItemOrId.constructor ==
String ?
1117 document.getElementById(aItemOrId) : aItemOrId;
1119 item.hidden = !aShow;
1125 setItemAttr:
function(aID, aAttr, aVal ) {
1126 var
elem = document.getElementById(aID);
1130 elem.removeAttribute(aAttr);
1134 elem.setAttribute(aAttr, aVal);
1141 setItemAttrFromNode:
function(aItem_id, aAttr, aOther_id) {
1142 var
elem = document.getElementById(aOther_id);
1143 if (elem && elem.getAttribute(aAttr) ==
"true")
1144 this.setItemAttr(aItem_id, aAttr,
"true");
1146 this.setItemAttr(aItem_id, aAttr,
null);
1150 cloneNode:
function(aItem) {
1152 var
node = document.createElement(aItem.tagName);
1155 var attrs = aItem.attributes;
1156 for (var
i = 0;
i < attrs.length;
i++) {
1157 var attr = attrs.item(
i);
1158 node.setAttribute(attr.nodeName, attr.nodeValue);
1166 getLinkURL:
function() {
1167 var
href = this.link.href;
1171 href = this.link.getAttributeNS(
"http://www.w3.org/1999/xlink",
1174 if (!href || !href.match(/\S/)) {
1183 getLinkURI:
function() {
1194 getLinkProtocol:
function() {
1196 return this.linkURI.scheme;
1202 linkText:
function() {
1204 if (!text || !text.match(/\S/)) {
1205 text = this.link.getAttribute(
"title");
1206 if (!text || !text.match(/\S/)) {
1207 text = this.link.getAttribute(
"alt");
1208 if (!text || !text.match(/\S/))
1209 text = this.linkURL;
1217 isTextSelection:
function() {
1225 if (selectedText.length > 15)
1226 selectedText = selectedText.substr(0,15) + this.ellipsis;
1230 var engineName =
"";
1231 var ss =
Cc[
"@mozilla.org/browser/search-service;1"].
1234 engineName = ss.currentEngine.name;
1236 engineName = ss.defaultEngine.name;
1239 var menuLabel =
gNavigatorBundle.getFormattedString(
"contextMenuSearchText",
1242 document.getElementById(
"context-searchselect").label = menuLabel;
1243 document.getElementById(
"context-searchselect").accessKey =
1250 isContentSelection:
function() {
1251 return !document.commandDispatcher.focusedWindow.getSelection().isCollapsed;
1254 toString:
function () {
1255 return "contextMenu.target = " + this.
target +
"\n" +
1256 "contextMenu.onImage = " + this.onImage +
"\n" +
1257 "contextMenu.onLink = " + this.onLink +
"\n" +
1258 "contextMenu.link = " + this.link +
"\n" +
1259 "contextMenu.inFrame = " + this.inFrame +
"\n" +
1260 "contextMenu.hasBGImage = " + this.hasBGImage +
"\n";
1265 isTargetAFormControl:
function(aNode) {
1266 if (aNode instanceof HTMLInputElement)
1267 return (aNode.type !=
"text" && aNode.type !=
"password" &&
1268 aNode.type !=
"image");
1270 return (aNode instanceof HTMLButtonElement) ||
1271 (aNode instanceof HTMLSelectElement) ||
1272 (aNode instanceof HTMLOptionElement) ||
1273 (aNode instanceof HTMLOptGroupElement);
1276 isTargetATextBox:
function(
node) {
1277 if (
node instanceof HTMLInputElement)
1278 return (
node.type ==
"text" ||
node.type ==
"password")
1280 return (
node instanceof HTMLTextAreaElement);
1283 isTargetAKeywordField:
function(aNode) {
1284 if (!(aNode instanceof HTMLInputElement))
1287 var form = aNode.form;
1288 if (!form || aNode.type ==
"password")
1291 var method = form.method.toUpperCase();
1303 return (method ==
"GET" || method ==
"") ||
1304 (form.enctype !=
"text/plain") && (form.enctype !=
"multipart/form-data");
1310 shouldShowSeparator:
function (aSeparatorID) {
1311 var separator = document.getElementById(aSeparatorID);
1313 var sibling = separator.previousSibling;
1314 while (sibling && sibling.localName !=
"menuseparator") {
1315 if (!sibling.hidden)
1317 sibling = sibling.previousSibling;
1323 addDictionaries:
function() {
1324 var
uri =
formatURL(
"browser.dictionaries.download.url",
true);
1328 locale =
gPrefService.getComplexValue(
"intl.accept_languages",
1329 Ci.nsIPrefLocalizedString).data;
1335 version =
Cc[
"@mozilla.org/xre/app-info;1"].
1340 uri = uri.replace(/%LOCALE%/, escape(locale)).replace(/%VERSION%/, version);
1342 var newWindowPref =
gPrefService.getIntPref(
"browser.link.open_newwindow");
1343 var where = newWindowPref == 3 ?
"tab" :
"window";
1348 bookmarkThisPage:
function CM_bookmarkThisPage() {
1349 window.top.PlacesCommandHook.bookmarkPage(this.
browser, PlacesUtils.bookmarksMenuFolderId,
true);
1352 bookmarkLink:
function CM_bookmarkLink() {
1353 window.top.PlacesCommandHook.bookmarkLink(PlacesUtils.bookmarksMenuFolderId,
this.linkURL,
1357 addBookmarkForFrame:
function CM_addBookmarkForFrame() {
1359 var
uri = doc.documentURIObject;
1361 var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
1363 var title = doc.title;
1364 var description =
PlacesUIUtils.getDescriptionFromDocument(doc);
1368 PlacesUtils.bookmarksMenuFolderId,
1369 -1, title,
null, [descAnno]);
1371 itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
1375 window.top.StarUI.showEditBookmarkPopup(itemId, this.
browser,
"overlap");
1378 savePageAs:
function CM_savePageAs() {
1379 saveDocument(this.
browser.contentDocument);
1382 sendPage:
function CM_sendPage() {
1386 printFrame:
function CM_printFrame() {
1387 PrintUtils.print(this.
target.ownerDocument.defaultView);
1390 switchPageDirection:
function CM_switchPageDirection() {
1394 mediaCommand :
function CM_mediaCommand(command) {
1408 media.muted =
false;
1410 case "hidecontrols":
1411 media.removeAttribute(
"controls");
1413 case "showcontrols":
1414 media.setAttribute(
"controls",
"true");
1419 copyMediaLocation :
function () {
1420 var clipboard =
Cc[
"@mozilla.org/widget/clipboardhelper;1"].
1422 clipboard.copyString(this.mediaURL);
1427 return this.mediaURL;
function openNewTabWith(aURL, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aReferrer)
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)
function BrowserPageInfo(doc, initialTab, imageElement)
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
function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer)
function getShellService()
restoreHistoryPrecursor aCount
function SwitchDocumentDirection(aWindow)
_getSelectedPageStyle s i