MouseLock – DOM Validation

I’ve been trying to implement the validation on MouseLock to check if the element being locked belonged to the “right” DOM.
What happens is that if the parent document tries to lock an element that belongs to a different document, for example: the document of an iframe, the mouse shouldn’t lock. So it’s only possible to lock an element if he belongs to the same DOM as the one the MouseLockable object has access to.

The Fix

 nsCOMPtr<nsIDOMDocument> targetDoc;
  parentNode->GetOwnerDocument(getter_AddRefs(targetDoc));
  if (targetDoc != domDoc) {
    return false;
  }

Code

While testing, I came across some interesting data:

All the objects from the parent window have a different memory address from the ones on the iframe.
I always knew that the iframe had a different scope from the parent page, but I never realized that having a different scope literally meant creating all the objects needed in a page, pretty much loading a page inside a page.
It’s amazing how many things we take for granted when using a browser, when in fact, a simple mousemove generates a call stack of more than 100 calls.

**I would assume that the iDoc would have the same memory address as the iWindow.document, but apparently they don’t

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s