Bug 885289 - Improve context menu behaviour for srcdoc iframes. r=mconley, r=bz

This commit is contained in:
James Kitchener 2013-07-25 09:32:50 -04:00
parent 100b814fc3
commit d60ef2c22d
5 changed files with 52 additions and 8 deletions

View File

@ -311,7 +311,7 @@
label="&openFrameCmd.label;"
accesskey="&openFrameCmd.accesskey;"
oncommand="gContextMenu.openFrame();"/>
<menuseparator/>
<menuseparator id="open-frame-sep"/>
<menuitem id="context-reloadframe"
label="&reloadFrameCmd.label;"
accesskey="&reloadFrameCmd.accesskey;"

View File

@ -277,6 +277,18 @@ nsContextMenu.prototype = {
this.showItem("context-keywordfield",
this.onTextInput && this.onKeywordField);
this.showItem("frame", this.inFrame);
// srcdoc cannot be opened separately due to concerns about web
// content with about:srcdoc in location bar masquerading as trusted
// chrome/addon content.
// No need to also test for this.inFrame as this is checked in the parent
// submenu.
this.showItem("context-showonlythisframe", !this.inSrcdocFrame);
this.showItem("context-openframeintab", !this.inSrcdocFrame);
this.showItem("context-openframe", !this.inSrcdocFrame);
this.showItem("context-bookmarkframe", !this.inSrcdocFrame);
this.showItem("open-frame-sep", !this.inSrcdocFrame);
this.showItem("frame-sep", this.inFrame && isTextSelected);
// Hide menu entries for images, show otherwise
@ -516,6 +528,7 @@ nsContextMenu.prototype = {
this.linkProtocol = "";
this.onMathML = false;
this.inFrame = false;
this.inSrcdocFrame = false;
this.inSyntheticDoc = false;
this.hasBGImage = false;
this.bgImageURL = "";
@ -679,11 +692,11 @@ nsContextMenu.prototype = {
// See if the user clicked in a frame.
var docDefaultView = this.target.ownerDocument.defaultView;
if (docDefaultView != docDefaultView.top) {
// srcdoc iframes are not considered frames for concerns about web
// content with about:srcdoc in location bar masqurading as trusted
// chrome/addon content.
if (!this.target.ownerDocument.isSrcdocDocument)
this.inFrame = true;
this.inFrame = true;
if (this.target.ownerDocument.isSrcdocDocument) {
this.inSrcdocFrame = true;
}
}
// if the document is editable, show context menu like in text inputs
@ -713,6 +726,7 @@ nsContextMenu.prototype = {
this.onCompletedImage = false;
this.onMathML = false;
this.inFrame = false;
this.inSrcdocFrame = false;
this.hasBGImage = false;
this.isDesignMode = true;
this.onEditableArea = true;

View File

@ -67,5 +67,6 @@ Browser context menu subtest.
<input id="test-select-input-text-type-password" type="password" value="password">
<embed id="test-plugin" style="width: 200px; height: 200px;" type="application/x-test"></embed>
<img id="test-longdesc" src="ctxmenu-image.png" longdesc="http://www.mozilla.org"></embed>
<iframe id="test-srcdoc" width="98" height="98" srcdoc="Hello World" style="border: 1px solid black"></iframe>
</body>
</html>

View File

@ -955,6 +955,33 @@ function runTest(testNum) {
"context-viewimagedesc", true
].concat(inspectItems));
closeContextMenu();
openContextMenuFor(srcdoc);
return;
case 31:
// Context menu for an iframe with srcdoc attribute set
checkContextMenu(["context-back", false,
"context-forward", false,
"context-reload", true,
"---", null,
"context-bookmarkpage", true,
"context-savepage", true,
"---", null,
"context-viewbgimage", false,
"context-selectall", true,
"frame", null,
["context-reloadframe", true,
"---", null,
"context-saveframe", true,
"---", null,
"context-printframe", true,
"---", null,
"context-viewframesource", true,
"context-viewframeinfo", true], null,
"---", null,
"context-viewsource", true,
"context-viewinfo", true
].concat(inspectItems));
// finish test
subwindow.close();
@ -984,7 +1011,7 @@ var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
iframe, video_in_iframe, image_in_iframe, textarea, contenteditable,
inputspell, pagemenu, dom_full_screen, plainTextItems, audio_in_video,
selecttext, selecttextlink, imagelink, select_inputtext, select_inputtext_password,
plugin, longdesc;
plugin, longdesc, iframe;
function startTest() {
chromeWin = SpecialPowers.wrap(subwindow)
@ -1034,6 +1061,7 @@ function startTest() {
select_inputtext_password = subwindow.document.getElementById("test-select-input-text-type-password");
plugin = subwindow.document.getElementById("test-plugin");
longdesc = subwindow.document.getElementById("test-longdesc");
srcdoc = subwindow.document.getElementById("test-srcdoc");
contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
runTest(1);

View File

@ -6105,7 +6105,8 @@ nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
if (aForceOwner) {
nsAutoCString uriStr;
aURI->GetSpec(uriStr);
if(!uriStr.EqualsLiteral("about:srcdoc")) {
if(!uriStr.EqualsLiteral("about:srcdoc") &&
!uriStr.EqualsLiteral("view-source:about:srcdoc")) {
nsCOMPtr<nsIURI> ownerURI;
nsresult rv = aLoadingPrincipal->GetURI(getter_AddRefs(ownerURI));
MOZ_ASSERT(NS_SUCCEEDED(rv) && SchemeIs(ownerURI, NS_NULLPRINCIPAL_SCHEME));