Open Bug 510157 Opened 11 years ago Updated 2 years ago

nsIDOMNSRange.createContextualFragment() fails when there is applied XUL-overlay including XML namespace declarations

Categories

(Core :: DOM: Core & HTML, defect, P5)

defect

Tracking

()

People

(Reporter: yuki, Unassigned)

Details

Attachments

(1 file)

1.15 KB, application/x-xpinstall
Details
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2a2pre) Gecko/20090812 Minefield/3.6a2pre (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2a2pre) Gecko/20090812 Minefield/3.6a2pre

NSRange.createContextualFragment() creates document fragment from source, however, it raises an exception (or returns "null") unexpectedly in some cases. When I saw this problem, there is applied XUL-overlay including XML namespace declarations.

Reproducible: Always

Steps to Reproduce:
1. Install the testcase addon to Firefox.
2. Restart Firefox.
3. A button named "click!" appears bottom in the browser window.
4. Click the button.


Actual Results:  
An alert appears:
-------------------------------
fragment: (not created)
[Exception... "Component returned failure code: 0x804e03f7 [nsIDOMNSRange.createContextualFragment]"  nsresult: "0x804e03f7 (<unknown>)"  location: "JS frame :: chrome://browser/content/browser.xul :: oncommand :: line 1"  data: no]
-------------------------------

And an error appears in the Error Console:
-------------------------------
Error: duplicate attribute
Source File: 
Line: 1, Column: 174
Source Code:
<window xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-------------------------------



Expected Results:  
A visible label "hello world!" appears (created and inserted) below the button.



I found this bug when I researching about conflict of two addons, Tab Mix Plus and Tree Style Tab.
TMP: http://tmp.garyr.net/dev-builds/
TST: http://piro.sakura.ne.jp/xul/treestyletab/

TST appends "Parent:" row below "Tags:" row in the <panel> for the star button, by createContextualFragment(). However, when TMP is installed, the operation always fails.

So, I read the source codes of TMP, and I realized that TMP's overlay includes some XML namespace declarations in "tabmix.xul", like:
----------------------------------------------
<overlay id="tabmix-overlay"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
(snip)
  <window id="main-window"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    onload="TMP_TBP_Startup();" />
----------------------------------------------

This source is completely VALID as XML. Those XML namespace declarations should work only for the <window> element itself and its contents. However, when Gecko generates temporary source for createContextualFragment(), he seems to fail detecting XML namespace declarations.
Attached file testcase addon
Actual result on Firefox 3.0.13 and Firefox 3.5.3pre:

An alert appears:
-------------------------------
fragment: null
[Exception... "Parameter is not an object"  code: "1003" nsresult: "0x805303eb (NS_ERROR_DOM_NOT_OBJECT_ERR)"  location: "chrome://browser/content/browser.xul Line: 1"]
-------------------------------

And an error appears same to Trunk, in the Error Console.
source of testcase:

<?xml version="1.0"?>
<overlay id="overlay"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <window id="main-window"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <button label="click!"
            oncommand="
		var range = document.createRange();
		range.selectNodeContents(document.documentElement);
		range.collapse(false);
		var source = '&lt;label value=&quot;hello world!&quot;/&gt;';
		var fragment = '(not created)';
		try {
			fragment = range.createContextualFragment(source);
			range.insertNode(fragment);
		}
		catch(e) {
			alert('fragment: '+fragment+'\n'+e);
		}
		range.detach();
            "/>
  </window>
</overlay>
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows Vista → All
Hardware: x86 → All
Version: unspecified → Trunk
I'm going to delete xmlns namespace declarations from tabmix overlay to main-window"

the only thing that we need to overlay is the onload, actualy i'm goin g to try to check if i can overlay the onload dynamically.

but anyway this look like that this is work ok
<overlay id="tabmix-overlay"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
(snip)
  <window id="main-window"
    onload="TMP_TBP_Startup();" />
(In reply to comment #4)

> but anyway this look like that this is work ok
> <overlay id="tabmix-overlay"
>     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
> (snip)
>   <window id="main-window"
>     onload="TMP_TBP_Startup();" />

I can confirm that this change works with both TMP 0.3.8.1 and TST 0.8.2009081101 enabled in Firefox 3.5.2
Component: DOM: Traversal-Range → DOM: Core & HTML
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.