Last Comment Bug 264308 - Implement DOM Level 3 UserData API
: Implement DOM Level 3 UserData API
Status: RESOLVED FIXED
: dev-doc-complete
Product: Core
Classification: Components
Component: DOM: Core & HTML (show other bugs)
: Trunk
: All All
: -- normal (vote)
: ---
Assigned To: Peter Van der Beken [:peterv]
:
: Andrew Overholt [:overholt]
Mentors:
Depends on: 251025 264309 314075 324871
Blocks:
  Show dependency treegraph
 
Reported: 2004-10-14 01:02 PDT by Peter Van der Beken [:peterv]
Modified: 2012-05-03 13:29 PDT (History)
15 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
WIP (66.45 KB, patch)
2004-11-16 12:55 PST, Peter Van der Beken [:peterv]
no flags Details | Diff | Splinter Review
v1 (71.32 KB, patch)
2005-01-27 08:07 PST, Peter Van der Beken [:peterv]
no flags Details | Diff | Splinter Review
v2 (102.94 KB, patch)
2005-02-09 15:49 PST, Peter Van der Beken [:peterv]
no flags Details | Diff | Splinter Review
v2.1 (56.82 KB, patch)
2005-09-12 07:47 PDT, Peter Van der Beken [:peterv]
no flags Details | Diff | Splinter Review
v2.2 (62.23 KB, patch)
2005-10-11 07:30 PDT, Peter Van der Beken [:peterv]
jst: review+
jst: superreview+
Details | Diff | Splinter Review

Description Peter Van der Beken [:peterv] 2004-10-14 01:02:45 PDT
 
Comment 1 Peter Van der Beken [:peterv] 2004-11-16 12:55:56 PST
Created attachment 166151 [details] [diff] [review]
WIP

May still crash and leak.
Comment 2 Peter Van der Beken [:peterv] 2005-01-27 08:07:05 PST
Created attachment 172568 [details] [diff] [review]
v1

This doesn't leak. Last remaining problem: we call the handler twice on
importNode (because it does a cloneNode internally). Not sure how to fix it
yet.
Comment 3 Peter Van der Beken [:peterv] 2005-02-09 15:49:25 PST
Created attachment 173906 [details] [diff] [review]
v2
Comment 4 Jonas Sicking (:sicking) No longer reading bugmail consistently 2005-02-18 20:45:42 PST
I'll try to start looking at this this weekend
Comment 5 Peter Van der Beken [:peterv] 2005-09-12 07:47:07 PDT
Created attachment 195743 [details] [diff] [review]
v2.1
Comment 6 Olli Pettay [:smaug] 2005-09-15 12:16:19 PDT
Comment on attachment 195743 [details] [diff] [review]
v2.1

> #define NS_IDOCUMENT_IID      \
>@@ -778,6 +780,39 @@ public:
>    */
>   virtual void NotifyURIVisitednessChanged(nsIURI* aURI) = 0;
> 
>+  nsresult SetUserData(const nsISupports *aObject, const nsAString &aKey,
>+                       nsIVariant *aData, nsIDOMUserDataHandler *aHandler,
>+                       nsIVariant **aResult)
>+  {
>+    nsCOMPtr<nsIAtom> key = do_GetAtom(aKey);
>+    if (!key) {
>+      return NS_ERROR_OUT_OF_MEMORY;
>+    }
>+
>+    return SetUserData(aObject, key, aData, aHandler, aResult);
>+  }
>+  virtual nsresult SetUserData(const nsISupports *aObject, nsIAtom *aKey,
>+                               nsIVariant *aData,
>+                               nsIDOMUserDataHandler *aHandler,
>+                               nsIVariant **aResult) = 0;
>+  nsresult GetUserData(nsISupports *aObject, const nsAString &aKey,
>+                       nsIVariant **aResult)
>+  {
>+    nsCOMPtr<nsIAtom> key = do_GetAtom(aKey);
>+    if (!key) {
>+      return NS_ERROR_OUT_OF_MEMORY;
>+    }
>+
>+    return GetUserData(aObject, key, aResult);
>+  }
>+  virtual nsresult GetUserData(const nsISupports *aObject, nsIAtom *aKey,
>+                               nsIVariant **aResult) = 0;
>+  virtual void CallUserDataHandler(PRUint16 aOperation,
>+                                   const nsISupports *aObject,
>+                                   nsIDOMNode *aSource, nsIDOMNode *aDest) = 0;
>+  virtual void TransferUserData(const nsISupports *aObject,
>+                                nsIDocument *aDestination) = 0;
>+

Could you add some documentation about these methods.
Comment 8 Olli Pettay [:smaug] 2005-09-16 06:47:57 PDT
(In reply to comment #7)
> (In reply to comment #6)
> 
> > Could you add some documentation about these methods.
> 
>
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-getUserData
>
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-setUserData
> http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#UserDataHandler
> 

Those links applies to the methods in
http://lxr.mozilla.org/seamonkey/source/dom/public/idl/core/nsIDOM3Node.idl#82
etc. But I'd like to see comments what the methods in nsIDocument are doing
(not nsIDOM3Document, not nsIDOM3Node, but nsIDocument) ;)
Comment 9 Peter Van der Beken [:peterv] 2005-10-11 07:30:08 PDT
Created attachment 199167 [details] [diff] [review]
v2.2
Comment 10 Johnny Stenback (:jst, jst@mozilla.com) 2005-10-26 17:10:35 PDT
Comment on attachment 199167 [details] [diff] [review]
v2.2

- In CallHandler() (in nsDocument.cpp):

+  nsresult rv = handlerData->mDocument->GetUserData(object, aKey,
+                                                    getter_AddRefs(data));
+  if (NS_SUCCEEDED(rv)) {
+    nsAutoString key;
+    aKey->ToString(key);
+    handler->Handle(handlerData->mOperation, key, data, handlerData->mSource,
+                    handlerData->mDest);

Shouldn't the condition for getting in here be if (data), or if (NS_SUCCEEDED(rv) && data)? Seems like GetUserData() always returns NS_OK, even if there is no data (as it IMO should)...

r+sr=jst
Comment 11 Peter Van der Beken [:peterv] 2005-10-27 08:03:10 PDT
(In reply to comment #10)
> (From update of attachment 199167 [details] [diff] [review] [edit])
> - In CallHandler() (in nsDocument.cpp):
> 
> +  nsresult rv = handlerData->mDocument->GetUserData(object, aKey,
> +                                                    getter_AddRefs(data));
> +  if (NS_SUCCEEDED(rv)) {
> +    nsAutoString key;
> +    aKey->ToString(key);
> +    handler->Handle(handlerData->mOperation, key, data, handlerData->mSource,
> +                    handlerData->mDest);
> 
> Shouldn't the condition for getting in here be if (data), or if
> (NS_SUCCEEDED(rv) && data)? Seems like GetUserData() always returns NS_OK, even
> if there is no data (as it IMO should)...

I made sure that we only set a handler if we've set data, so I added an assertion here instead.
I also changed the IIDs for nsIContent, nsIDocument and nsIDOMUserDataHandler.
Comment 12 Mark Mentovai 2005-10-27 19:16:57 PDT
Caused a crash [@ nsPropertyTable::DeleteAllPropertiesFor] in bug 314075?
Comment 13 Alex Vincent [:WeirdAl] 2006-12-01 10:22:19 PST
I'd like to have tests written for this.  Examples of setUserData() and getUserData() are not easy to find, even on codesearch.google.com.  A search on lxr shows only glazou's composer code is using it, and he's not setting any UserDataHandler objects in his calls.
Comment 14 Peter Van der Beken [:peterv] 2006-12-02 01:50:36 PST
There are at least some tests in the W3C DOM testsuite.
Comment 15 Eric Shepherd [:sheppy] 2007-10-02 10:40:07 PDT
I'm not sure how or where to document these; there's very, very little information available about them.  Can someone point me in the direction of where to actually find those tests in the testsuite?  I don't happen to know where it is.
Comment 16 Peter Van der Beken [:peterv] 2007-10-02 10:48:14 PDT
http://dev.w3.org/cvsweb/2001/DOM-Test-Suite/tests/level3/core/ contains some of the raw tests (look for files that contain userdata). I personally don't have the html versions of the tests anymore and we haven't imported the DOM Level 3 Core tests into our testsuite yet. I'll see if I can generate just the UserData ones.

Some spec links:

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-getUserData
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-setUserData
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#UserDataHandler
Comment 17 Eric Shepherd [:sheppy] 2007-10-02 10:50:42 PDT
Yeah, I'm looking at that Java code now.  I guess I'll sit down and do some HTML/JS code myself for this.
Comment 18 Nickolay_Ponomarev 2009-10-11 23:01:16 PDT
FWIW:
https://developer.mozilla.org/en/DOM/Node.setUserData
https://developer.mozilla.org/en/DOM/Node.getUserData

Didn't proof-read those pages though.
Comment 19 Florian Scholz [:fscholz] (MDN) 2012-03-24 10:54:23 PDT
The following pages are in a good shape with at least some little examples:
https://developer.mozilla.org/en/DOM/UserDataHandler
https://developer.mozilla.org/en/DOM/DOMUserData
https://developer.mozilla.org/en/DOM/Node.getUserData
https://developer.mozilla.org/en/DOM/Node.setUserData

Marking this as completed finally.

Note You need to log in before you can comment on or make changes to this bug.