On 12/2/14, 8:17 AM, Kevin Grandon wrote:
> We currently use location.origin quite frequently in gaia, and we also use it in workers.
So the difference between location.origin and document.origin is that
the latter is the origin of the document and the former is the origin of
the document's URI.
For example, if you have an about:blank iframe, or an <iframe srcdoc>
then location.origin will be "null" but document.origin will be the
origin of the document involved (which is the same as the origin of the
parent document).
location.origin in workers has the same problem: it's the origin of the
URI the worker was loaded from, not the origin of the worker. For example:
var w =
new Worker('data:text/javascript,postMessage(location.origin)');
w.onmessage = function(e) { alert(e.data); }
will alert "null".
> My vote would be to keep it around, especially if we have no way of getting document.origin from a worker.
Are you trying to get the origin of the worker, the origin of the
document that started the worker (at the moment, more or less the same
thing, but maybe not into the future), the origin of the URI the worker
was loaded from (what location.origin does right now) or something else?
> The naming is a bit confusing to me as a web developer.
Yes. I suspect that location.origin is mostly a footgun both in workers
and in Window contexts...
> Not sure if it's possible, but at first glance something like `location.documentOrigin` would make more sense to me
It's possible, but I don't think it's a good idea. First of all, for
which document? The one the location is from or the current document in
the browsing context (like most location stuff)?
>- then we could use it in workers I assume?
We can add an API to workers to get origins, if we know which origins
we're interested in. We should not be putting it on Location, in my
opinion.
But I agree there is value in doing this in a way that acts the same in
windows and workers. Perhaps what we should really do is put .origin on
Window and on WorkerGlobalScope instead of (or in addition to?) putting
it on Document? Then "self.origin" would do the right thing in both a
Window and a worker... But it does involve adding "origin" in the global
scope.
-Boris