Closed Bug 1262813 Opened 8 years ago Closed 8 years ago

Listing indexedDB from a javascript: iframe fails with TypeError

Categories

(DevTools :: Storage Inspector, defect, P1)

defect

Tracking

(firefox48 fixed)

RESOLVED FIXED
Firefox 48
Tracking Status
firefox48 --- fixed

People

(Reporter: jsnajdr, Assigned: timhuang)

References

Details

(Whiteboard: [OA])

Attachments

(1 file, 1 obsolete file)

Steps to reproduce:
1. Load the patch from bug 1262766 and run the devtools/client/storage/test/browser_storage_cache_error.js mochitest.

Expected result:
It passes.

Actual result:
After bug 1237915 has landed, initializing the Storage Inspector fails on this test's test page (storage-cache-error.html) with a TypeError:

Full message: TypeError: win is null
Full stack: .populateStoresForHost<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/server/actors/storage.js:1615:9

This is caused by the iframe with the "javascript:parent.frameContent" URL. The getWindowFromHost method searches for the right window by comparing the host to:

win.document.nodePrincipal.originNoSuffix

The origin however is "http://test.example.org", not the javascript: URL, so nothing is found and null is returned. The calling code doesn't expect the return value to be null.

On the other hand, the win.location.href contains the right javascript: URL (and win.location.origin is null).

I have no idea now all that principal magic work and I'm unable to fix this myself.
Blocks: 1262766
See Also: → 1237915
When a new window has been created, the storage actor is going to know this new window through the observer event 'content-document-global-created' [1]. Then, the getWindowFromHost can acquire this window correctly.

However, it seems like that this observer event does not happen after the creation of the iframe in storage-cache-error.html. I think it causes this problem. But I really don't know why this event does not occur. 

[1] https://dxr.mozilla.org/mozilla-central/source/devtools/server/actors/storage.js#2208
(In reply to Tim Huang[:timhuang] from comment #1)
> However, it seems like that this observer event does not happen after the
> creation of the iframe in storage-cache-error.html. I think it causes this
> problem. But I really don't know why this event does not occur. 

This is true only for windows created after the Storage Inspector is initialized and running. When the storage inspector is starting up, it fetches the windows in the fetchChildWindows method [1]. This is what happens in the cache-error test.

When the getWindowFromHost method can't find the window, it's not because it's missing from this.childWindowPool. It's there. It's not found because the comparison in [2] doesn't find it. "host" is the javascript: URL, but the "origin" (fetched from the principal) is the URL of the site, http://test1.example.org.

[1] https://dxr.mozilla.org/mozilla-central/source/devtools/server/actors/storage.js#2147-2165
[2] https://dxr.mozilla.org/mozilla-central/source/devtools/server/actors/storage.js#2189
I think the window of the site 'http://test1.example.org' belongs to the tab window. The function fetchChildWindows will add tab window into the childWindowPool as well as other child windows. So, if it works correctly, the window pool should contain two windows, one for 'http://test1.example.org' and another for 'javascript: URL' for this test case. But now, it only has the tab window, the site of 'http://test1.example.org'.
(In reply to Tim Huang[:timhuang] from comment #3)
> But now, it only has the tab window, the site of 'http://test1.example.org'.

When I run the test locally, both windows are there, but the javascript: one fails to be found. If I add the following log statement before line [1]:

console.log(`Searching for window ${host}, checking origin=${origin}`, win.location);

and run the cache-error test, I get this:

console.log: Searching for window javascript:parent.frameContent, checking origin=http://test1.example.org Location {
  "href":"http://test1.example.org/browser/devtools/client/storage/test/storage-cache-error.html",
  "origin":"http://test1.example.org",
  "protocol":"http:",
  "host":"test1.example.org",
  "hostname":"test1.example.org",
  "port":"",
  "pathname":"/browser/devtools/client/storage/test/storage-cache-error.html",
  "search":"",
  "hash":""
}
console.log: Searching for window javascript:parent.frameContent, checking origin=http://test1.example.org Location {
  "href":"javascript:parent.frameContent",
  "origin":"null",
  "protocol":"javascript:",
  "host":"",
  "hostname":"",
  "port":"",
  "pathname":"",
  "search":"",
  "hash":""
}

Both windows are there, origin from principal is the same, the javascript: URL is only in the win.location.href.

[1] https://dxr.mozilla.org/mozilla-central/source/devtools/server/actors/storage.js#2189
Whiteboard: [OA]
Assignee: nobody → tihuang
Status: NEW → ASSIGNED
A very similar issue happens in bug 1215349, on the about:home page. On this page, indexedDBs are not shown, although the page has an "abouthome" database. This happens because the getWindowFromHost fails to find the window. The origin from the principal is "moz-safe-about:home", the "host" is just "about:home".
See Also: → 1215349
This patch makes the getWindowFromHost not only checks the origin, but also checks the url of the document with the host.
Attachment #8740955 - Flags: review?(mratcliffe)
Attachment #8740955 - Flags: review?(mratcliffe) → review+
Rebase mozilla-central.
Attachment #8742005 - Flags: review+
Attachment #8740955 - Attachment is obsolete: true
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/8997f9366f6b
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 48
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.