Bug 1130096 - Convert embedding/components/windowwatcher/ to Gecko style. r=mccr8

This commit is contained in:
Birunthan Mohanathas 2015-05-11 12:35:14 -07:00
parent 68403abab7
commit a38a033c5f
7 changed files with 682 additions and 577 deletions

View File

@ -19,9 +19,9 @@ using namespace mozilla::dom;
****************** nsAutoWindowStateHelper *********************
****************************************************************/
nsAutoWindowStateHelper::nsAutoWindowStateHelper(nsPIDOMWindow *aWindow)
: mWindow(aWindow),
mDefaultEnabled(DispatchEventToChrome("DOMWillOpenModalDialog"))
nsAutoWindowStateHelper::nsAutoWindowStateHelper(nsPIDOMWindow* aWindow)
: mWindow(aWindow)
, mDefaultEnabled(DispatchEventToChrome("DOMWillOpenModalDialog"))
{
if (mWindow) {
mWindow->EnterModalState();
@ -40,7 +40,7 @@ nsAutoWindowStateHelper::~nsAutoWindowStateHelper()
}
bool
nsAutoWindowStateHelper::DispatchEventToChrome(const char *aEventName)
nsAutoWindowStateHelper::DispatchEventToChrome(const char* aEventName)
{
// XXXbz should we skip dispatching the event if the inner changed?
// That is, should we store both the inner and the outer?
@ -60,7 +60,9 @@ nsAutoWindowStateHelper::DispatchEventToChrome(const char *aEventName)
if (rv.Failed()) {
return false;
}
NS_ENSURE_TRUE(NS_SUCCEEDED(event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true)), false);
NS_ENSURE_TRUE(NS_SUCCEEDED(event->InitEvent(
NS_ConvertASCIItoUTF16(aEventName), true, true)),
false);
event->SetTrusted(true);
event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;

View File

@ -19,20 +19,16 @@ class nsPIDOMWindow;
class nsAutoWindowStateHelper
{
public:
explicit nsAutoWindowStateHelper(nsPIDOMWindow *aWindow);
explicit nsAutoWindowStateHelper(nsPIDOMWindow* aWindow);
~nsAutoWindowStateHelper();
bool DefaultEnabled()
{
return mDefaultEnabled;
}
bool DefaultEnabled() { return mDefaultEnabled; }
protected:
bool DispatchEventToChrome(const char *aEventName);
bool DispatchEventToChrome(const char* aEventName);
nsCOMPtr<nsPIDOMWindow> mWindow;
bool mDefaultEnabled;
};
#endif

View File

@ -2,76 +2,90 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDialogParamBlock.h"
#include "nsString.h"
#include "nsReadableUtils.h"
NS_IMPL_ISUPPORTS(nsDialogParamBlock, nsIDialogParamBlock)
nsDialogParamBlock::nsDialogParamBlock() : mNumStrings(0), mString(nullptr)
nsDialogParamBlock::nsDialogParamBlock()
: mNumStrings(0)
, mString(nullptr)
{
for(int32_t i = 0; i < kNumInts; i++)
for (int32_t i = 0; i < kNumInts; i++) {
mInt[i] = 0;
}
}
nsDialogParamBlock::~nsDialogParamBlock()
{
delete [] mString;
delete[] mString;
}
NS_IMETHODIMP nsDialogParamBlock::SetNumberStrings(int32_t inNumStrings)
NS_IMETHODIMP
nsDialogParamBlock::SetNumberStrings(int32_t aNumStrings)
{
if (mString != nullptr)
if (mString) {
return NS_ERROR_ALREADY_INITIALIZED;
}
mString = new nsString[inNumStrings];
if (!mString)
mString = new nsString[aNumStrings];
if (!mString) {
return NS_ERROR_OUT_OF_MEMORY;
mNumStrings = inNumStrings;
}
mNumStrings = aNumStrings;
return NS_OK;
}
NS_IMETHODIMP nsDialogParamBlock::GetInt(int32_t inIndex, int32_t *_retval)
NS_IMETHODIMP
nsDialogParamBlock::GetInt(int32_t aIndex, int32_t* aResult)
{
nsresult rv = InBounds(inIndex, kNumInts);
if (rv == NS_OK)
*_retval = mInt[inIndex];
return rv;
}
NS_IMETHODIMP nsDialogParamBlock::SetInt(int32_t inIndex, int32_t inInt)
{
nsresult rv = InBounds(inIndex, kNumInts);
if (rv == NS_OK)
mInt[inIndex]= inInt;
return rv;
}
NS_IMETHODIMP nsDialogParamBlock::GetString(int32_t inIndex, char16_t **_retval)
{
if (mNumStrings == 0)
SetNumberStrings(kNumStrings);
nsresult rv = InBounds(inIndex, mNumStrings);
if (rv == NS_OK)
*_retval = ToNewUnicode(mString[inIndex]);
return rv;
}
NS_IMETHODIMP nsDialogParamBlock::SetString(int32_t inIndex, const char16_t *inString)
{
if (mNumStrings == 0)
SetNumberStrings(kNumStrings);
nsresult rv = InBounds(inIndex, mNumStrings);
if (rv == NS_OK)
mString[inIndex]= inString;
nsresult rv = InBounds(aIndex, kNumInts);
if (rv == NS_OK) {
*aResult = mInt[aIndex];
}
return rv;
}
NS_IMETHODIMP
nsDialogParamBlock::GetObjects(nsIMutableArray * *aObjects)
nsDialogParamBlock::SetInt(int32_t aIndex, int32_t aInt)
{
nsresult rv = InBounds(aIndex, kNumInts);
if (rv == NS_OK) {
mInt[aIndex] = aInt;
}
return rv;
}
NS_IMETHODIMP
nsDialogParamBlock::GetString(int32_t aIndex, char16_t** aResult)
{
if (mNumStrings == 0) {
SetNumberStrings(kNumStrings);
}
nsresult rv = InBounds(aIndex, mNumStrings);
if (rv == NS_OK) {
*aResult = ToNewUnicode(mString[aIndex]);
}
return rv;
}
NS_IMETHODIMP
nsDialogParamBlock::SetString(int32_t aIndex, const char16_t* aString)
{
if (mNumStrings == 0) {
SetNumberStrings(kNumStrings);
}
nsresult rv = InBounds(aIndex, mNumStrings);
if (rv == NS_OK) {
mString[aIndex] = aString;
}
return rv;
}
NS_IMETHODIMP
nsDialogParamBlock::GetObjects(nsIMutableArray** aObjects)
{
NS_ENSURE_ARG_POINTER(aObjects);
NS_IF_ADDREF(*aObjects = mObjects);
@ -79,10 +93,8 @@ nsDialogParamBlock::GetObjects(nsIMutableArray * *aObjects)
}
NS_IMETHODIMP
nsDialogParamBlock::SetObjects(nsIMutableArray * aObjects)
nsDialogParamBlock::SetObjects(nsIMutableArray* aObjects)
{
mObjects = aObjects;
return NS_OK;
}

View File

@ -2,7 +2,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsDialogParamBlock_h
#define __nsDialogParamBlock_h
@ -12,34 +12,33 @@
// {4E4AAE11-8901-46cc-8217-DAD7C5415873}
#define NS_DIALOGPARAMBLOCK_CID \
{0x4e4aae11, 0x8901, 0x46cc, {0x82, 0x17, 0xda, 0xd7, 0xc5, 0x41, 0x58, 0x73}}
{0x4e4aae11, 0x8901, 0x46cc, {0x82, 0x17, 0xda, 0xd7, 0xc5, 0x41, 0x58, 0x73}}
class nsString;
class nsDialogParamBlock: public nsIDialogParamBlock
class nsDialogParamBlock : public nsIDialogParamBlock
{
public:
public:
nsDialogParamBlock();
NS_DECL_NSIDIALOGPARAMBLOCK
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
protected:
virtual ~nsDialogParamBlock();
private:
enum { kNumInts = 8, kNumStrings = 16 };
enum {kNumInts = 8, kNumStrings = 16};
nsresult InBounds(int32_t inIndex, int32_t inMax) {
return inIndex >= 0 && inIndex < inMax ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
nsresult InBounds(int32_t aIndex, int32_t aMax)
{
return aIndex >= 0 && aIndex < aMax ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
}
int32_t mInt[kNumInts];
int32_t mNumStrings;
nsString* mString;
nsCOMPtr<nsIMutableArray> mObjects;
nsCOMPtr<nsIMutableArray> mObjects;
};
#endif

View File

@ -19,24 +19,24 @@
* password on the auth information object.
*/
inline void
NS_SetAuthInfo(nsIAuthInformation* aAuthInfo, const nsString& user,
const nsString& password)
NS_SetAuthInfo(nsIAuthInformation* aAuthInfo, const nsString& aUser,
const nsString& aPassword)
{
uint32_t flags;
aAuthInfo->GetFlags(&flags);
if (flags & nsIAuthInformation::NEED_DOMAIN) {
// Domain is separated from username by a backslash
int32_t idx = user.FindChar(char16_t('\\'));
int32_t idx = aUser.FindChar(char16_t('\\'));
if (idx == kNotFound) {
aAuthInfo->SetUsername(user);
aAuthInfo->SetUsername(aUser);
} else {
aAuthInfo->SetDomain(Substring(user, 0, idx));
aAuthInfo->SetUsername(Substring(user, idx + 1));
aAuthInfo->SetDomain(Substring(aUser, 0, idx));
aAuthInfo->SetUsername(Substring(aUser, idx + 1));
}
} else {
aAuthInfo->SetUsername(user);
aAuthInfo->SetUsername(aUser);
}
aAuthInfo->SetPassword(password);
aAuthInfo->SetPassword(aPassword);
}
/**
@ -54,12 +54,13 @@ NS_SetAuthInfo(nsIAuthInformation* aAuthInfo, const nsString& user,
*/
inline void
NS_GetAuthHostPort(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
bool machineProcessing, nsCString& host, int32_t* port)
bool aMachineProcessing, nsCString& aHost, int32_t* aPort)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
return;
}
// Have to distinguish proxy auth and host auth here...
uint32_t flags;
@ -74,27 +75,27 @@ NS_GetAuthHostPort(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
nsAutoCString idnhost;
info->GetHost(idnhost);
info->GetPort(port);
info->GetPort(aPort);
if (machineProcessing) {
if (aMachineProcessing) {
nsCOMPtr<nsIIDNService> idnService =
do_GetService(NS_IDNSERVICE_CONTRACTID);
if (idnService) {
idnService->ConvertUTF8toACE(idnhost, host);
idnService->ConvertUTF8toACE(idnhost, aHost);
} else {
// Not much we can do here...
host = idnhost;
aHost = idnhost;
}
} else {
host = idnhost;
aHost = idnhost;
}
} else {
if (machineProcessing) {
uri->GetAsciiHost(host);
*port = NS_GetRealPort(uri);
if (aMachineProcessing) {
uri->GetAsciiHost(aHost);
*aPort = NS_GetRealPort(uri);
} else {
uri->GetHost(host);
uri->GetPort(port);
uri->GetHost(aHost);
uri->GetPort(aPort);
}
}
}
@ -106,14 +107,14 @@ NS_GetAuthHostPort(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
*/
inline void
NS_GetAuthKey(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
nsCString& key)
nsCString& aKey)
{
// HTTP does this differently from other protocols
nsCOMPtr<nsIHttpChannel> http(do_QueryInterface(aChannel));
if (!http) {
nsCOMPtr<nsIURI> uri;
aChannel->GetURI(getter_AddRefs(uri));
uri->GetPrePath(key);
uri->GetPrePath(aKey);
return;
}
@ -125,15 +126,14 @@ NS_GetAuthKey(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
nsAutoString realm;
aAuthInfo->GetRealm(realm);
// Now assemble the key: host:port (realm)
key.Append(host);
key.Append(':');
key.AppendInt(port);
key.AppendLiteral(" (");
AppendUTF16toUTF8(realm, key);
key.Append(')');
aKey.Append(host);
aKey.Append(':');
aKey.AppendInt(port);
aKey.AppendLiteral(" (");
AppendUTF16toUTF8(realm, aKey);
aKey.Append(')');
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
// {a21bfa01-f349-4394-a84c-8de5cf0737d0}
#define NS_WINDOWWATCHER_CID \
{0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}}
{0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}}
#include "nsCOMPtr.h"
#include "mozilla/Mutex.h"
@ -19,21 +19,21 @@
#include "nsPIWindowWatcher.h"
#include "nsTArray.h"
class nsIURI;
class nsIDocShellTreeItem;
class nsIDocShellTreeOwner;
class nsIURI;
class nsIDocShellTreeItem;
class nsIDocShellTreeOwner;
class nsPIDOMWindow;
class nsWatcherWindowEnumerator;
class nsPromptService;
class nsWatcherWindowEnumerator;
class nsPromptService;
struct nsWatcherWindowEntry;
struct SizeSpec;
class nsWindowWatcher :
public nsIWindowWatcher,
public nsPIWindowWatcher,
public nsIPromptFactory
class nsWindowWatcher
: public nsIWindowWatcher
, public nsPIWindowWatcher
, public nsIPromptFactory
{
friend class nsWatcherWindowEnumerator;
friend class nsWatcherWindowEnumerator;
public:
nsWindowWatcher();
@ -46,79 +46,78 @@ public:
NS_DECL_NSPIWINDOWWATCHER
NS_DECL_NSIPROMPTFACTORY
static int32_t GetWindowOpenLocation(nsIDOMWindow *aParent,
uint32_t aChromeFlags,
bool aCalledFromJS,
bool aPositionSpecified,
bool aSizeSpecified);
static int32_t GetWindowOpenLocation(nsIDOMWindow* aParent,
uint32_t aChromeFlags,
bool aCalledFromJS,
bool aPositionSpecified,
bool aSizeSpecified);
protected:
virtual ~nsWindowWatcher();
friend class nsPromptService;
bool AddEnumerator(nsWatcherWindowEnumerator* inEnumerator);
bool RemoveEnumerator(nsWatcherWindowEnumerator* inEnumerator);
bool AddEnumerator(nsWatcherWindowEnumerator* aEnumerator);
bool RemoveEnumerator(nsWatcherWindowEnumerator* aEnumerator);
nsWatcherWindowEntry *FindWindowEntry(nsIDOMWindow *aWindow);
nsresult RemoveWindow(nsWatcherWindowEntry *inInfo);
nsWatcherWindowEntry* FindWindowEntry(nsIDOMWindow* aWindow);
nsresult RemoveWindow(nsWatcherWindowEntry* aInfo);
// Get the caller tree item. Look on the JS stack, then fall back
// to the parent if there's nothing there.
already_AddRefed<nsIDocShellTreeItem>
GetCallerTreeItem(nsIDocShellTreeItem* aParentItem);
already_AddRefed<nsIDocShellTreeItem> GetCallerTreeItem(
nsIDocShellTreeItem* aParentItem);
// Unlike GetWindowByName this will look for a caller on the JS
// stack, and then fall back on aCurrentWindow if it can't find one.
nsPIDOMWindow*
SafeGetWindowByName(const nsAString& aName, nsIDOMWindow* aCurrentWindow);
nsPIDOMWindow* SafeGetWindowByName(const nsAString& aName,
nsIDOMWindow* aCurrentWindow);
// Just like OpenWindowJS, but knows whether it got called via OpenWindowJS
// (which means called from script) or called via OpenWindow.
nsresult OpenWindowInternal(nsIDOMWindow *aParent,
const char *aUrl,
const char *aName,
const char *aFeatures,
nsresult OpenWindowInternal(nsIDOMWindow* aParent,
const char* aUrl,
const char* aName,
const char* aFeatures,
bool aCalledFromJS,
bool aDialog,
bool aNavigate,
nsITabParent *aOpeningTab,
nsIArray *argv,
nsIDOMWindow **_retval);
nsITabParent* aOpeningTab,
nsIArray* aArgv,
nsIDOMWindow** aResult);
static nsresult URIfromURL(const char *aURL,
nsIDOMWindow *aParent,
nsIURI **aURI);
static uint32_t CalculateChromeFlags(nsIDOMWindow *aParent,
const char *aFeatures,
bool aFeaturesSpecified,
bool aDialog,
bool aChromeURL,
bool aHasChromeParent,
bool aOpenedFromRemoteTab);
static int32_t WinHasOption(const char *aOptions, const char *aName,
int32_t aDefault, bool *aPresenceFlag);
static nsresult URIfromURL(const char* aURL,
nsIDOMWindow* aParent,
nsIURI** aURI);
static uint32_t CalculateChromeFlags(nsIDOMWindow* aParent,
const char* aFeatures,
bool aFeaturesSpecified,
bool aDialog,
bool aChromeURL,
bool aHasChromeParent,
bool aOpenedFromRemoteTab);
static int32_t WinHasOption(const char* aOptions, const char* aName,
int32_t aDefault, bool* aPresenceFlag);
/* Compute the right SizeSpec based on aFeatures */
static void CalcSizeSpec(const char* aFeatures, SizeSpec& aResult);
static nsresult ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem,
nsIDOMWindow *aParent,
bool aWindowIsNew,
nsIDOMWindow **aOpenedWindow);
static void SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem,
nsIDOMWindow *aParent,
bool aIsCallerChrome,
const SizeSpec & aSizeSpec);
static void GetWindowTreeItem(nsIDOMWindow *inWindow,
nsIDocShellTreeItem **outTreeItem);
static void GetWindowTreeOwner(nsIDOMWindow *inWindow,
nsIDocShellTreeOwner **outTreeOwner);
static void CalcSizeSpec(const char* aFeatures, SizeSpec& aResult);
static nsresult ReadyOpenedDocShellItem(nsIDocShellTreeItem* aOpenedItem,
nsIDOMWindow* aParent,
bool aWindowIsNew,
nsIDOMWindow** aOpenedWindow);
static void SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
nsIDOMWindow* aParent,
bool aIsCallerChrome,
const SizeSpec& aSizeSpec);
static void GetWindowTreeItem(nsIDOMWindow* aWindow,
nsIDocShellTreeItem** aResult);
static void GetWindowTreeOwner(nsIDOMWindow* aWindow,
nsIDocShellTreeOwner** aResult);
nsTArray<nsWatcherWindowEnumerator*> mEnumeratorList;
nsWatcherWindowEntry *mOldestWindow;
mozilla::Mutex mListLock;
nsWatcherWindowEntry* mOldestWindow;
mozilla::Mutex mListLock;
nsCOMPtr<nsIWindowCreator> mWindowCreator;
};
#endif