Bug 1208622 - Separate API entry points. r=bz

This commit is contained in:
Bobby Holley 2015-09-25 14:03:51 -07:00
parent 896562fc4e
commit e91aae8249
6 changed files with 34 additions and 41 deletions

View File

@ -39,6 +39,7 @@
#include "nsIWebBrowserChrome.h"
#include "nsReadableUtils.h"
#include "nsFocusManager.h"
#include "nsGlobalWindow.h"
#ifdef MOZ_XUL
#include "nsIXULDocument.h"
@ -482,10 +483,9 @@ RootAccessible::RelationByType(RelationType aType)
if (!mDocumentNode || aType != RelationType::EMBEDS)
return DocAccessibleWrap::RelationByType(aType);
nsIDOMWindow* rootWindow = mDocumentNode->GetWindow();
nsPIDOMWindow* rootWindow = mDocumentNode->GetWindow();
if (rootWindow) {
nsCOMPtr<nsIDOMWindow> contentWindow;
rootWindow->GetContent(getter_AddRefs(contentWindow));
nsCOMPtr<nsIDOMWindow> contentWindow = nsGlobalWindow::Cast(rootWindow)->GetContent();
if (contentWindow) {
nsCOMPtr<nsIDOMDocument> contentDOMDocument;
contentWindow->GetDocument(getter_AddRefs(contentDOMDocument));

View File

@ -3942,7 +3942,7 @@ nsGlobalWindow::GetContentOuter(JSContext* aCx,
{
MOZ_RELEASE_ASSERT(IsOuterWindow());
nsCOMPtr<nsIDOMWindow> content = GetContentInternal(aError);
nsCOMPtr<nsIDOMWindow> content = GetContentInternal(aError, !nsContentUtils::IsCallerChrome());
if (aError.Failed()) {
return;
}
@ -3971,7 +3971,7 @@ nsGlobalWindow::GetContent(JSContext* aCx,
}
already_AddRefed<nsIDOMWindow>
nsGlobalWindow::GetContentInternal(ErrorResult& aError)
nsGlobalWindow::GetContentInternal(ErrorResult& aError, bool aUnprivilegedCaller)
{
MOZ_ASSERT(IsOuterWindow());
@ -3989,7 +3989,7 @@ nsGlobalWindow::GetContentInternal(ErrorResult& aError)
}
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
if (!nsContentUtils::IsCallerChrome()) {
if (aUnprivilegedCaller) {
// If we're called by non-chrome code, make sure we don't return
// the primary content window if the calling tab is hidden. In
// such a case we return the same-type root in the hidden tab,
@ -4024,17 +4024,6 @@ nsGlobalWindow::GetContentInternal(ErrorResult& aError)
return domWindow.forget();
}
NS_IMETHODIMP
nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
{
FORWARD_TO_OUTER(GetContent, (aContent), NS_ERROR_UNEXPECTED);
ErrorResult rv;
*aContent = GetContentInternal(rv).take();
return rv.StealNSResult();
}
MozSelfSupport*
nsGlobalWindow::GetMozSelfSupport(ErrorResult& aError)
{

View File

@ -40,6 +40,7 @@
#include "mozilla/dom/StorageEvent.h"
#include "mozilla/dom/StorageEventBinding.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/ErrorResult.h"
#include "nsFrameMessageManager.h"
#include "mozilla/LinkedList.h"
#include "mozilla/TimeStamp.h"
@ -338,6 +339,8 @@ public:
{ }
#endif
static nsGlobalWindow* Cast(nsPIDOMWindow* aPIWin) { return static_cast<nsGlobalWindow*>(aPIWin); }
// public methods
nsPIDOMWindow* GetPrivateParent();
@ -1116,12 +1119,22 @@ public:
const nsAString& aOptions,
const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
mozilla::ErrorResult& aError);
already_AddRefed<nsIDOMWindow>
GetContentInternal(mozilla::ErrorResult& aError, bool aUnprivilegedCaller);
void GetContentOuter(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& aError);
void GetContent(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& aError);
already_AddRefed<nsIDOMWindow> GetContent()
{
MOZ_ASSERT(IsOuterWindow());
mozilla::ErrorResult ignored;
return GetContentInternal(ignored, /* aUnprivilegedCaller = */ false);
}
void Get_content(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& aError)
@ -1617,9 +1630,6 @@ protected:
ShowModalDialog(const nsAString& aUrl, nsIVariant* aArgument,
const nsAString& aOptions, mozilla::ErrorResult& aError);
already_AddRefed<nsIDOMWindow>
GetContentInternal(mozilla::ErrorResult& aError);
// Ask the user if further dialogs should be blocked, if dialogs are currently
// being abused. This is used in the cases where we have no modifiable UI to
// show, in that case we show a separate dialog to ask this question.

View File

@ -1977,11 +1977,10 @@ EventStateManager::GetContentViewer(nsIContentViewer** aCv)
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(focusedWindow);
if(!ourWindow) return NS_ERROR_FAILURE;
nsIDOMWindow *rootWindow = ourWindow->GetPrivateRoot();
nsCOMPtr<nsPIDOMWindow> rootWindow = do_QueryInterface(ourWindow->GetPrivateRoot());
if(!rootWindow) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMWindow> contentWindow;
rootWindow->GetContent(getter_AddRefs(contentWindow));
nsCOMPtr<nsIDOMWindow> contentWindow = nsGlobalWindow::Cast(rootWindow)->GetContent();
if(!contentWindow) return NS_ERROR_FAILURE;
nsIDocument *doc = GetDocumentFromWindow(contentWindow);

View File

@ -22,7 +22,7 @@ interface nsIVariant;
* @see <http://www.whatwg.org/html/#window>
*/
[scriptable, uuid(7e26f1bd-a694-4b65-8d9d-9eead0645fe3)]
[scriptable, uuid(ab30b7cc-f7f9-4b9b-befb-7dbf6cf86d46)]
interface nsIDOMWindow : nsISupports
{
// the current browsing context
@ -368,9 +368,6 @@ interface nsIDOMWindow : nsISupports
*/
void sizeToContent();
/* [replaceable] content */
[noscript] readonly attribute nsIDOMWindow content;
/* [replaceable] prompter */
[noscript] readonly attribute nsIPrompt prompter;

View File

@ -19,6 +19,7 @@
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "nsPIDOMWindow.h"
#include "nsGlobalWindow.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIBaseWindow.h"
@ -92,8 +93,8 @@ activateWindow( nsIDOMWindow *win ) {
#endif
// Simple Win32 mutex wrapper.
struct Mutex {
Mutex( const char16_t *name )
struct Win32Mutex {
Win32Mutex( const char16_t *name )
: mName( name ),
mHandle( 0 ),
mState( -1 ) {
@ -102,7 +103,7 @@ struct Mutex {
printf( "CreateMutex error = 0x%08X\n", (int)GetLastError() );
#endif
}
~Mutex() {
~Win32Mutex() {
if ( mHandle ) {
// Make sure we release it if we own it.
Unlock();
@ -669,7 +670,7 @@ nsNativeAppSupportWin::Start( bool *aResult ) {
MOZ_MUTEX_NAMESPACE,
NS_ConvertUTF8toUTF16(gAppData->name).get(),
MOZ_STARTUP_MUTEX_NAME );
Mutex startupLock = Mutex( mMutexName );
Win32Mutex startupLock = Win32Mutex( mMutexName );
NS_ENSURE_TRUE( startupLock.Lock( MOZ_DDE_START_TIMEOUT ), NS_ERROR_FAILURE );
@ -759,7 +760,7 @@ nsNativeAppSupportWin::Stop( bool *aResult ) {
nsresult rv = NS_OK;
*aResult = true;
Mutex ddeLock( mMutexName );
Win32Mutex ddeLock( mMutexName );
if ( ddeLock.Lock( MOZ_DDE_STOP_TIMEOUT ) ) {
if ( mConversations == 0 ) {
@ -799,7 +800,7 @@ nsNativeAppSupportWin::Quit() {
// to wait to hold the lock, in which case they will not find the
// window as we will destroy ours under our lock.
// When the mutex goes off the stack, it is unlocked via destructor.
Mutex mutexLock(mMutexName);
Win32Mutex mutexLock(mMutexName);
NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE);
// If we've got a message window to receive IPC or new window requests,
@ -1007,18 +1008,15 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t
nsCOMPtr<nsIDOMWindow> navWin;
GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(),
getter_AddRefs( navWin ) );
if ( !navWin ) {
nsCOMPtr<nsPIDOMWindow> piNavWin = do_QueryInterface(navWin);
if ( !piNavWin ) {
// There is not a window open
break;
}
// Get content window.
nsCOMPtr<nsIDOMWindow> content;
navWin->GetContent( getter_AddRefs( content ) );
if ( !content ) {
break;
}
// Convert that to internal interface.
nsCOMPtr<nsPIDOMWindow> internalContent( do_QueryInterface( content ) );
nsCOMPtr<nsIDOMWindow> internalContent_ = nsGlobalWindow::Cast(piNavWin)->GetContent();
nsCOMPtr<nsPIDOMWindow> internalContent = do_QueryInterface(internalContent_);
if ( !internalContent ) {
break;
}