Closed Bug 1134222 Opened 10 years ago Closed 10 years ago

[e10s] "Save Link As..."/"Bookmark This Link" in remote browser causes unsafe CPOW usage warning

Categories

(Firefox :: Menus, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 40
Tracking Status
e10s m8+ ---
firefox40 --- fixed

People

(Reporter: Kwan, Assigned: Kwan)

References

Details

(Keywords: addon-compat)

Attachments

(2 files, 1 obsolete file)

+++ This bug was initially created as a clone of Bug #1133577 +++ STR: 1) Visit a site with some links on it in an e10s window 2) Right-click on a link, and choose "Save Link As..." This causes some "unsafe CPOW usage" warnings in the Browser Console. In browser/base/content/nsContextMenu.js: // Save URL of clicked-on link. saveLink: function() { var doc = this.target.ownerDocument; <-- Causes CPOW warning var linkText; // If selected text is found to match valid URL pattern. if (this.onPlainTextLink) linkText = this.focusedWindow.getSelection().toString().trim(); else linkText = this.linkText(); urlSecurityCheck(this.linkURL, this.principal); this.saveHelper(this.linkURL, linkText, null, true, doc); }, in browser/base/content/utilityOverlay.js: // Gather all descendent text under given document node. function gatherTextUnder ( root ) { var text = ""; var node = root.firstChild; <-- Causes CPOW warning var depth = 1; while ( node && depth > 0 ) { // See if this node is text. if ( node.nodeType == Node.TEXT_NODE ) { <-- Causes CPOW warning // Add this text to our collection. text += " " + node.data; <-- Causes CPOW warning } else if ( node instanceof HTMLImageElement) { <-- Causes CPOW warning [complex, image] // If it has an "alt" attribute, add that. var altText = node.getAttribute( "alt" ); <-- Causes CPOW warning [image] if ( altText && altText != "" ) { text += " " + altText; } } // Find next node to test. // First, see if this node has children. if ( node.hasChildNodes() ) { <-- Causes CPOW warning // Go to first child. node = node.firstChild; <-- Causes CPOW warning [complex] depth++; } else { // No children, try next sibling (or parent next sibling). while ( depth > 0 && !node.nextSibling ) { <-- Causes CPOW warning node = node.parentNode; <-- Causes CPOW warning depth--; } if ( node.nextSibling ) { <-- Causes CPOW warning node = node.nextSibling; <-- Causes CPOW warning [complex] } } } // Strip leading and tailing whitespace. text = text.trim(); // Compress remaining whitespace. text = text.replace( /\s+/g, " " ); return text; } note that the amount of warnings depends on the structure of the link, and I've marked up accordingly untagged warnings are just caused by <a>text</a> [complex] tagged warnings are caused by e.g. <a><em>text</em> text</a> [image] tagged warnings are caused by e.g. <a><img/></a> Note I might make this situation even worse in bug 850378
Changing summary to include "Bookmark This Link" since it is a strict subset of this report, hitting all the same CPOWs in utilityOverlay's gatherTextUnder()
Summary: [e10s] "Save Link As..." in remote browser causes unsafe CPOW usage warning → [e10s] "Save Link As..."/"Bookmark This Link" in remote browser causes unsafe CPOW usage warning
CPOW's I missed due to not testing with the right markup: in browser/base/content/nsContextMenu.js: // Get text of link. linkText: function() { var text = gatherTextUnder(this.link); if (!text || !text.match(/\S/)) { text = this.link.getAttribute("title"); <- Causes CPOW warning if (!text || !text.match(/\S/)) { text = this.link.getAttribute("alt"); <- Causes CPOW warning if (!text || !text.match(/\S/)) text = this.linkURL; } } return text; },
Assignee: nobody → moz-ian
Status: NEW → ASSIGNED
Depends on: 1140859
So it turns out the linkText is already being calculated when initing the menu. In the plaintext case because it needs the text to even work out if it's a link, and in the actual link case, formatSearchContextItem() does it. (I thought doing all the tree walking in gatherTextUnder() during init, instead of using messages when needed, would have been too expensive for fixing this, but since it is already being done anyway may as well keep it). This won't fix all the warnings in the save link case, bug 1140859 is for the rest. Note to self: whichever of this and bug 850378 lands second will need to be rebased on top of the other.
Attachment #8574417 - Flags: review?(mconley)
Comment on attachment 8574417 [details] [diff] [review] Store the value of linkText that is calculated during nsContextMenu init and reuse it later, rather than recalculating it Review of attachment 8574417 [details] [diff] [review]: ----------------------------------------------------------------- This makes sense to me. Glad to see even more unsafe CPOW usage warning reductions! You're on a roll, Ian! Thank so much.
Attachment #8574417 - Flags: review?(mconley) → review+
Attached file MozReview Request: bz://1134222/Kwan (obsolete) —
/r/6981 - Bug 1134222 - Save a reference to the ownerDocument during the sync contextmenu message, and use it for saveLink() Pull down this commit: hg pull -r 50793a51ef72d275171383c01fc0117f7f455567 https://reviewboard-hg.mozilla.org/gecko/
Attachment #8591205 - Flags: review?(gkrizsanits)
Comment on attachment 8591205 [details] MozReview Request: bz://1134222/Kwan https://reviewboard.mozilla.org/r/6979/#review5787 Thanks, this looks good to me.
Attachment #8591205 - Flags: review?(gkrizsanits) → review+
Cool, with this patch all the remaining work to get Save Link safe is covered by bug 1140859, which I have a patch for. https://treeherder.mozilla.org/#/jobs?repo=try&revision=67fcd4cdbffb 1 intermittent (bug 961215)
Keywords: checkin-needed
Bug 1140859 has fixed the remainder.
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Keywords: leave-open
Resolution: --- → FIXED
Target Milestone: --- → Firefox 40
This patch did a very bad thing which is change something that was a function to a string. Any add-on that used linkText now needs: + // linkText changed from a function to a string + // in Firefox 39. Check for both. + if ("getLinkText" in gContextMenu) { + title = gContextMenu.linkText; + } else { + title = gContextMenu.linkText(); + } The string should have had a new variable name, not reused the preexisting function name.
(In reply to Mike Kaply [:mkaply] from comment #14) > This patch did a very bad thing which is change something that was a > function to a string. > > Any add-on that used linkText now needs: > > + // linkText changed from a function to a string > + // in Firefox 39. Check for both. > + if ("getLinkText" in gContextMenu) { > + title = gContextMenu.linkText; > + } else { > + title = gContextMenu.linkText(); > + } > > The string should have had a new variable name, not reused the preexisting > function name. Oh damn it, sorry, I wasn't even thinking of addon compat. As 39's only in Aurora is it worth changing the variable name, or would that just cause even more problems?
Jorge: Can you do a quick search and see if any add-ons use linkText?
I see about 100 add-ons on MXR using this function, so it's definitely a compatibility issue. I think the variable name should be changed, as Mike suggested, and I would like some clarification as to whether this change is being introduced in 39 or 40.
Keywords: addon-compat
We definitely would want to back to using the function and changing the new variable name then. We'll fix our code.
Hey Ian, Feel like filing a new bug to switch the variable name?
Flags: needinfo?(moz-ian)
Thanks, guys, for keeping addon compat here!
Depends on: 1160339
(In reply to Jorge Villalobos [:jorgev] from comment #17) > I see about 100 add-ons on MXR using this function, so it's definitely a > compatibility issue. I think the variable name should be changed, as Mike > suggested, and I would like some clarification as to whether this change is > being introduced in 39 or 40. The issue is introduced in 39 from this landing: (In reply to Wes Kocher (:KWierso) from comment #7) > https://hg.mozilla.org/mozilla-central/rev/1fe96992c3b5 (In reply to Mike Conley (:mconley) - Needinfo me! from comment #19) > Hey Ian, > > Feel like filing a new bug to switch the variable name? Done, bug 1160339, and given you the r?.
No longer depends on: 1160339
Flags: needinfo?(moz-ian)
Depends on: 1160339
Attachment #8591205 - Attachment is obsolete: true
Attachment #8619510 - Flags: review+
See Also: → 1199239
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: