Closed Bug 1186732 Opened 9 years ago Closed 9 years ago

Need a way to load scripts into a blank page and give it a URL

Categories

(Firefox :: Extension Compatibility, defect)

34 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 42
Tracking Status
firefox42 --- fixed

People

(Reporter: billm, Assigned: bholley)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

The main way you load code into a Chrome extension is by specifying a "background page". This is a web page that's loaded into a hidden window. It has access to the extension APIs. The manifest file specifies either an HTML file or a list of scripts to load into the page. Right now, if the list of scripts is provided, we call docShell.createAboutBlankContentViewer and then use createElement to create a bunch of <script> tags and append them to the document. The problem with this approach is that the resulting document's URL is about:blank. Background pages often do XHRs, and the URL they provide is often a relative URL. We get an error from these XHRs. Chrome solves this by giving the background page a dummy URL (I think it's something like chrome-extension://foo/_generatedBackground.html). That way, relative URLs for XHRs are resolved relative to chrome-extension://foo/. Bobby, how do you think we could solve this?
Flags: needinfo?(bobbyholley)
How s an XHR URI relative to chrome-extension:// foo useful, exactly? Regardless, it seems like the addon code could just create a moz-extension substitution from foo/_generatedBackground.html to about:blank. Wouldn't that solve the problem?
Flags: needinfo?(bobbyholley)
(In reply to (PTO July 22 - July 26) from comment #1) > Regardless, it seems like the addon code could just create a moz-extension > substitution from foo/_generatedBackground.html to about:blank. Wouldn't > that solve the problem? This sounds like a good idea!
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
Actually, I don't think that will work. You can only substitute based on the host rather than the entire URL. I still like the idea of routing to about:blank, but I'm not sure how to do it. We could maybe use a different host for the background page, but that's pretty ugly and it might break some assumptions that extensions make. Bobby, what do you think of adding support to SubstitutingProtocolHandler so that certain paths can have different mappings? It looks like net_ResolveRelativePath would be useful for this.
Status: RESOLVED → REOPENED
Flags: needinfo?(bobbyholley)
Resolution: WORKSFORME → ---
I think generalizing this stuff to do some sort of most-exact-matching is going to make it a lot more complicated. I think we can just hack something up to solve this problem in C++. I'll attach a patch shortly.
Flags: needinfo?(bobbyholley)
Attachment #8640233 - Flags: review?(wmccloskey)
Comment on attachment 8640233 [details] [diff] [review] Implement an about:blank page inside of moz-extension. v1 Review of attachment 8640233 [details] [diff] [review]: ----------------------------------------------------------------- Yeah, this seems good. We might want to change the _blank.html name at some point, but this is fine for now.
Attachment #8640233 - Flags: review?(wmccloskey) → review+
Assignee: nobody → bobbyholley
Status: REOPENED → RESOLVED
Closed: 9 years ago9 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → Firefox 42
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: