Bug 774633 - Factor nsWindowWatcher call to SetOpenerScriptPrincipal into a method on nsGlobalWindow. r=jst

This doesn't change any functionality in the code. Note that the name is currently
a bit of a misnomer, but we change that in the next patch when we rip out the
arguments.
Bug 774633 - Wean SetInitialPrincipalToSubject off some parameters and clean it up. r=jst

We can remove the fallback to the principal of aParent because we already push the
cx for aParent (callerContextGuard) whenever we're concerned about using its principal.
Bug 774633 - Remove dead mOpenerScriptPrincipal. r=jst

This value is initialized to null and never set, so we can get rid of it.
Bug 774633 - Fold SetOpenerScriptPrincipal into SetInitialPrincipalToSubject, and make it indempotent and callable without an existing document. r=jst

There's no reason it has to fail if there's no mDoc, since any document is promptly
blown away with the new about:blank document.

The indempotence is important because we want to be able to call this method
unconditionally in OpenJSWindowInternal (since we may not have gone through
RegisterTopLevelWindow) without worrying about whether we've called it already.
Bug 774633 - Move the call to SetInitialPrincipalToSubject into nsAppShellService::RegisterTopLevelWindow. r=jst

This means that we get the correct principal on the window before sending notifying
any consumers about the window's creation.
Bug 774633 - Remove "is chrome window" condition for inner window reuse. r=jst

WouldReuseInnerWindow also returns true if the new window is same-origin with
the old one about:blank document.

This condition exists in order to handle some sloppiness with respect to the
principals on initial about:blank documents. Chrome callers sometimes parent
chrome windows (with XUL document) to content windows. But this parenting causes
us to push the cx of the content window during window creation, meaning that
the subsequent load of chrome://foo.xul blows away the old inner window and any
expandos on it. We can handle this case more precisely by skipping the cx push
for type="chrome" windows.

Furthermore, this was also necessary to prevent the inner window from being
blown away in the call to SetOpenerScriptPrincipal once nsWindowWatcher gets
the window back from the window creator (and after it's already told consumers
about the window via "domwindowcreated"). But we fixed this nastiness in the
previous patches.

So we can remove this case. By doing so, we can prevent inner windows from ever
changing origins, which is very important for compartment security invariants.
Bug 774633 - Assert against switching origins on a compartment. r=jst
Bug 774633 - Fix TestAppShellSteadyState to load a system principal URI so that we don't discard the inner window. r=bent
Bug 774607 - Remove use of JS_{Is,Make}SystemObject from Gecko. r=bz

We currently set this for system globals and anything whose parent
chain leads to a system global. Maybe this was relevant before, but
with CPG this is just equivalent to asking whether the object is in
a system compartment. And the only place where we _check_ this bit
is immediately after checking for a system compartment, in
WrapperFactory. So AFAICT this can go away entirely.
Bug 774607 - Remove JS_{Is,Make}SystemObject API. r=luke
Bug 771354 - Don't special-case principal assignment for chrome windows in nsGlobalWindow.cpp. r=bz a=akeybl