diff --git a/embedding/browser/build/nsWebBrowserModule.cpp b/embedding/browser/build/nsWebBrowserModule.cpp index 084bcade4c2..efa9b5592f7 100644 --- a/embedding/browser/build/nsWebBrowserModule.cpp +++ b/embedding/browser/build/nsWebBrowserModule.cpp @@ -25,32 +25,29 @@ NS_DEFINE_NAMED_CID(NS_COMMANDHANDLER_CID); NS_DEFINE_NAMED_CID(NS_WEBBROWSERCONTENTPOLICY_CID); static const mozilla::Module::CIDEntry kWebBrowserCIDs[] = { - { &kNS_WEBBROWSER_CID, false, nullptr, nsWebBrowserConstructor }, - { &kNS_COMMANDHANDLER_CID, false, nullptr, nsCommandHandlerConstructor }, - { &kNS_WEBBROWSERCONTENTPOLICY_CID, false, nullptr, nsWebBrowserContentPolicyConstructor }, - { nullptr } + { &kNS_WEBBROWSER_CID, false, nullptr, nsWebBrowserConstructor }, + { &kNS_COMMANDHANDLER_CID, false, nullptr, nsCommandHandlerConstructor }, + { &kNS_WEBBROWSERCONTENTPOLICY_CID, false, nullptr, nsWebBrowserContentPolicyConstructor }, + { nullptr } }; static const mozilla::Module::ContractIDEntry kWebBrowserContracts[] = { - { NS_WEBBROWSER_CONTRACTID, &kNS_WEBBROWSER_CID }, - { NS_COMMANDHANDLER_CONTRACTID, &kNS_COMMANDHANDLER_CID }, - { NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, &kNS_WEBBROWSERCONTENTPOLICY_CID }, - { nullptr } + { NS_WEBBROWSER_CONTRACTID, &kNS_WEBBROWSER_CID }, + { NS_COMMANDHANDLER_CONTRACTID, &kNS_COMMANDHANDLER_CID }, + { NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, &kNS_WEBBROWSERCONTENTPOLICY_CID }, + { nullptr } }; static const mozilla::Module::CategoryEntry kWebBrowserCategories[] = { - { "content-policy", NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, NS_WEBBROWSERCONTENTPOLICY_CONTRACTID }, - { nullptr } + { "content-policy", NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, NS_WEBBROWSERCONTENTPOLICY_CONTRACTID }, + { nullptr } }; static const mozilla::Module kWebBrowserModule = { - mozilla::Module::kVersion, - kWebBrowserCIDs, - kWebBrowserContracts, - kWebBrowserCategories + mozilla::Module::kVersion, + kWebBrowserCIDs, + kWebBrowserContracts, + kWebBrowserCategories }; NSMODULE_DEFN(Browser_Embedding_Module) = &kWebBrowserModule; - - - diff --git a/embedding/browser/nsCTooltipTextProvider.h b/embedding/browser/nsCTooltipTextProvider.h index 993f7bb048c..4829cdf0ba1 100644 --- a/embedding/browser/nsCTooltipTextProvider.h +++ b/embedding/browser/nsCTooltipTextProvider.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */ @@ -9,6 +9,6 @@ #include "nsITooltipTextProvider.h" #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID \ - "@mozilla.org/embedcomp/tooltiptextprovider;1" + "@mozilla.org/embedcomp/tooltiptextprovider;1" #endif diff --git a/embedding/browser/nsCommandHandler.cpp b/embedding/browser/nsCommandHandler.cpp index db5ada47a30..dedb32ad6ec 100644 --- a/embedding/browser/nsCommandHandler.cpp +++ b/embedding/browser/nsCommandHandler.cpp @@ -11,8 +11,8 @@ #include "nsMemory.h" #include "nsPIDOMWindow.h" -nsCommandHandler::nsCommandHandler() : - mWindow(nullptr) +nsCommandHandler::nsCommandHandler() + : mWindow(nullptr) { } @@ -20,128 +20,125 @@ nsCommandHandler::~nsCommandHandler() { } -nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler) +nsresult +nsCommandHandler::GetCommandHandler(nsICommandHandler** aCommandHandler) { - NS_ENSURE_ARG_POINTER(aCommandHandler); + NS_ENSURE_ARG_POINTER(aCommandHandler); - *aCommandHandler = nullptr; - if (mWindow == nullptr) - { - return NS_ERROR_FAILURE; + *aCommandHandler = nullptr; + if (!mWindow) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr window(do_QueryInterface(mWindow)); + if (!window) { + return NS_ERROR_FAILURE; + } + + // Get the document tree owner + + nsCOMPtr docShellAsTreeItem = + do_QueryInterface(window->GetDocShell()); + nsIDocShellTreeOwner* treeOwner = nullptr; + docShellAsTreeItem->GetTreeOwner(&treeOwner); + + // Make sure the tree owner is an an nsDocShellTreeOwner object + // by QI'ing for a hidden interface. If it doesn't have the interface + // then it's not safe to do the casting. + + nsCOMPtr realTreeOwner(do_QueryInterface(treeOwner)); + if (realTreeOwner) { + nsDocShellTreeOwner* tree = static_cast(treeOwner); + if (tree->mTreeOwner) { + nsresult rv; + rv = tree->mTreeOwner->QueryInterface(NS_GET_IID(nsICommandHandler), + (void**)aCommandHandler); + NS_RELEASE(treeOwner); + return rv; } - nsCOMPtr window(do_QueryInterface(mWindow)); - if (!window) - { - return NS_ERROR_FAILURE; - } + NS_RELEASE(treeOwner); + } - // Get the document tree owner + *aCommandHandler = nullptr; - nsCOMPtr docShellAsTreeItem = - do_QueryInterface(window->GetDocShell()); - nsIDocShellTreeOwner *treeOwner = nullptr; - docShellAsTreeItem->GetTreeOwner(&treeOwner); - - // Make sure the tree owner is an an nsDocShellTreeOwner object - // by QI'ing for a hidden interface. If it doesn't have the interface - // then it's not safe to do the casting. - - nsCOMPtr realTreeOwner(do_QueryInterface(treeOwner)); - if (realTreeOwner) - { - nsDocShellTreeOwner *tree = static_cast(treeOwner); - if (tree->mTreeOwner) - { - nsresult rv; - rv = tree->mTreeOwner->QueryInterface(NS_GET_IID(nsICommandHandler), (void **)aCommandHandler); - NS_RELEASE(treeOwner); - return rv; - } - - NS_RELEASE(treeOwner); - } - - *aCommandHandler = nullptr; - - return NS_OK; + return NS_OK; } - NS_IMPL_ADDREF(nsCommandHandler) NS_IMPL_RELEASE(nsCommandHandler) NS_INTERFACE_MAP_BEGIN(nsCommandHandler) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandHandler) - NS_INTERFACE_MAP_ENTRY(nsICommandHandlerInit) - NS_INTERFACE_MAP_ENTRY(nsICommandHandler) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandHandler) + NS_INTERFACE_MAP_ENTRY(nsICommandHandlerInit) + NS_INTERFACE_MAP_ENTRY(nsICommandHandler) NS_INTERFACE_MAP_END /////////////////////////////////////////////////////////////////////////////// // nsICommandHandlerInit implementation -/* attribute nsIDocShell docShell; */ -NS_IMETHODIMP nsCommandHandler::GetWindow(nsIDOMWindow * *aWindow) +NS_IMETHODIMP +nsCommandHandler::GetWindow(nsIDOMWindow** aWindow) { - *aWindow = nullptr; - return NS_OK; + *aWindow = nullptr; + return NS_OK; } -NS_IMETHODIMP nsCommandHandler::SetWindow(nsIDOMWindow * aWindow) +NS_IMETHODIMP +nsCommandHandler::SetWindow(nsIDOMWindow* aWindow) { - if (aWindow == nullptr) - { - return NS_ERROR_FAILURE; - } - mWindow = aWindow; - return NS_OK; + if (!aWindow) { + return NS_ERROR_FAILURE; + } + mWindow = aWindow; + return NS_OK; } /////////////////////////////////////////////////////////////////////////////// // nsICommandHandler implementation -/* string exec (in string aCommand, in string aStatus); */ -NS_IMETHODIMP nsCommandHandler::Exec(const char *aCommand, const char *aStatus, char **aResult) +NS_IMETHODIMP +nsCommandHandler::Exec(const char* aCommand, const char* aStatus, + char** aResult) { - NS_ENSURE_ARG_POINTER(aCommand); - NS_ENSURE_ARG_POINTER(aResult); + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); - nsCOMPtr commandHandler; - GetCommandHandler(getter_AddRefs(commandHandler)); + nsCOMPtr commandHandler; + GetCommandHandler(getter_AddRefs(commandHandler)); - // Call the client's command handler to deal with this command - if (commandHandler) - { - *aResult = nullptr; - return commandHandler->Exec(aCommand, aStatus, aResult); - } + // Call the client's command handler to deal with this command + if (commandHandler) { + *aResult = nullptr; + return commandHandler->Exec(aCommand, aStatus, aResult); + } - // Return an empty string - const char szEmpty[] = ""; - *aResult = (char *) nsMemory::Clone(szEmpty, sizeof(szEmpty)); + // Return an empty string + const char szEmpty[] = ""; + *aResult = (char*)nsMemory::Clone(szEmpty, sizeof(szEmpty)); - return NS_OK; + return NS_OK; } -/* string query (in string aCommand, in string aStatus); */ -NS_IMETHODIMP nsCommandHandler::Query(const char *aCommand, const char *aStatus, char **aResult) +NS_IMETHODIMP +nsCommandHandler::Query(const char* aCommand, const char* aStatus, + char** aResult) { - NS_ENSURE_ARG_POINTER(aCommand); - NS_ENSURE_ARG_POINTER(aResult); + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); - nsCOMPtr commandHandler; - GetCommandHandler(getter_AddRefs(commandHandler)); + nsCOMPtr commandHandler; + GetCommandHandler(getter_AddRefs(commandHandler)); - // Call the client's command handler to deal with this command - if (commandHandler) - { - *aResult = nullptr; - return commandHandler->Query(aCommand, aStatus, aResult); - } + // Call the client's command handler to deal with this command + if (commandHandler) { + *aResult = nullptr; + return commandHandler->Query(aCommand, aStatus, aResult); + } - // Return an empty string - const char szEmpty[] = ""; - *aResult = (char *) nsMemory::Clone(szEmpty, sizeof(szEmpty)); + // Return an empty string + const char szEmpty[] = ""; + *aResult = (char*)nsMemory::Clone(szEmpty, sizeof(szEmpty)); - return NS_OK; + return NS_OK; } diff --git a/embedding/browser/nsCommandHandler.h b/embedding/browser/nsCommandHandler.h index 29f2127a001..778362dadbd 100644 --- a/embedding/browser/nsCommandHandler.h +++ b/embedding/browser/nsCommandHandler.h @@ -11,24 +11,24 @@ #include "nsICommandHandler.h" #include "nsIDOMWindow.h" -class nsCommandHandler : - public nsICommandHandlerInit, - public nsICommandHandler +class nsCommandHandler + : public nsICommandHandlerInit + , public nsICommandHandler { - nsIDOMWindow *mWindow; - - nsresult GetCommandHandler(nsICommandHandler **aCommandHandler); - public: - nsCommandHandler(); + nsCommandHandler(); - NS_DECL_ISUPPORTS - NS_DECL_NSICOMMANDHANDLERINIT - NS_DECL_NSICOMMANDHANDLER + NS_DECL_ISUPPORTS + NS_DECL_NSICOMMANDHANDLERINIT + NS_DECL_NSICOMMANDHANDLER protected: - virtual ~nsCommandHandler(); + virtual ~nsCommandHandler(); + +private: + nsresult GetCommandHandler(nsICommandHandler** aCommandHandler); + + nsIDOMWindow* mWindow; }; #endif - diff --git a/embedding/browser/nsContextMenuInfo.cpp b/embedding/browser/nsContextMenuInfo.cpp index bd2edfe018f..bcae91a52c8 100644 --- a/embedding/browser/nsContextMenuInfo.cpp +++ b/embedding/browser/nsContextMenuInfo.cpp @@ -28,11 +28,6 @@ #include "nsAutoPtr.h" #include "imgRequestProxy.h" - -//***************************************************************************** -// class nsContextMenuInfo -//***************************************************************************** - NS_IMPL_ISUPPORTS(nsContextMenuInfo, nsIContextMenuInfo) nsContextMenuInfo::nsContextMenuInfo() @@ -43,35 +38,33 @@ nsContextMenuInfo::~nsContextMenuInfo() { } -/* readonly attribute nsIDOMEvent mouseEvent; */ NS_IMETHODIMP -nsContextMenuInfo::GetMouseEvent(nsIDOMEvent **aEvent) +nsContextMenuInfo::GetMouseEvent(nsIDOMEvent** aEvent) { NS_ENSURE_ARG_POINTER(aEvent); NS_IF_ADDREF(*aEvent = mMouseEvent); return NS_OK; } -/* readonly attribute nsIDOMNode targetNode; */ NS_IMETHODIMP -nsContextMenuInfo::GetTargetNode(nsIDOMNode **aNode) +nsContextMenuInfo::GetTargetNode(nsIDOMNode** aNode) { NS_ENSURE_ARG_POINTER(aNode); NS_IF_ADDREF(*aNode = mDOMNode); return NS_OK; } -/* readonly attribute AString associatedLink; */ NS_IMETHODIMP nsContextMenuInfo::GetAssociatedLink(nsAString& aHRef) { NS_ENSURE_STATE(mAssociatedLink); aHRef.Truncate(0); - + nsCOMPtr content(do_QueryInterface(mAssociatedLink)); nsAutoString localName; - if (content) + if (content) { content->GetLocalName(localName); + } nsCOMPtr linkContent; ToLowerCase(localName); @@ -83,27 +76,28 @@ nsContextMenuInfo::GetAssociatedLink(nsAString& aHRef) if (hasAttr) { linkContent = content; nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) + if (anchor) { anchor->GetHref(aHRef); - else { + } else { nsCOMPtr area(do_QueryInterface(linkContent)); - if (area) + if (area) { area->GetHref(aHRef); - else { + } else { nsCOMPtr link(do_QueryInterface(linkContent)); - if (link) + if (link) { link->GetHref(aHRef); + } } } } - } - else { + } else { nsCOMPtr curr; mAssociatedLink->GetParentNode(getter_AddRefs(curr)); while (curr) { content = do_QueryInterface(curr); - if (!content) + if (!content) { break; + } content->GetLocalName(localName); ToLowerCase(localName); if (localName.EqualsLiteral("a")) { @@ -111,12 +105,14 @@ nsContextMenuInfo::GetAssociatedLink(nsAString& aHRef) content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); if (hasAttr) { linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) + nsCOMPtr anchor( + do_QueryInterface(linkContent)); + if (anchor) { anchor->GetHref(aHRef); - } - else + } + } else { linkContent = nullptr; // Links can't be nested. + } break; } @@ -128,67 +124,64 @@ nsContextMenuInfo::GetAssociatedLink(nsAString& aHRef) return NS_OK; } -/* readonly attribute imgIContainer imageContainer; */ NS_IMETHODIMP -nsContextMenuInfo::GetImageContainer(imgIContainer **aImageContainer) +nsContextMenuInfo::GetImageContainer(imgIContainer** aImageContainer) { NS_ENSURE_ARG_POINTER(aImageContainer); NS_ENSURE_STATE(mDOMNode); - + nsCOMPtr request; GetImageRequest(mDOMNode, getter_AddRefs(request)); - if (request) + if (request) { return request->GetImage(aImageContainer); + } return NS_ERROR_FAILURE; } -/* readonly attribute nsIURI imageSrc; */ NS_IMETHODIMP -nsContextMenuInfo::GetImageSrc(nsIURI **aURI) +nsContextMenuInfo::GetImageSrc(nsIURI** aURI) { NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_STATE(mDOMNode); - + nsCOMPtr content(do_QueryInterface(mDOMNode)); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); return content->GetCurrentURI(aURI); } -/* readonly attribute imgIContainer backgroundImageContainer; */ NS_IMETHODIMP -nsContextMenuInfo::GetBackgroundImageContainer(imgIContainer **aImageContainer) +nsContextMenuInfo::GetBackgroundImageContainer(imgIContainer** aImageContainer) { NS_ENSURE_ARG_POINTER(aImageContainer); NS_ENSURE_STATE(mDOMNode); - + nsRefPtr request; GetBackgroundImageRequest(mDOMNode, getter_AddRefs(request)); - if (request) + if (request) { return request->GetImage(aImageContainer); + } return NS_ERROR_FAILURE; } -/* readonly attribute nsIURI backgroundImageSrc; */ NS_IMETHODIMP -nsContextMenuInfo::GetBackgroundImageSrc(nsIURI **aURI) +nsContextMenuInfo::GetBackgroundImageSrc(nsIURI** aURI) { NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_STATE(mDOMNode); - + nsRefPtr request; GetBackgroundImageRequest(mDOMNode, getter_AddRefs(request)); - if (request) + if (request) { return request->GetURI(aURI); + } return NS_ERROR_FAILURE; } -//***************************************************************************** - nsresult -nsContextMenuInfo::GetImageRequest(nsIDOMNode *aDOMNode, imgIRequest **aRequest) +nsContextMenuInfo::GetImageRequest(nsIDOMNode* aDOMNode, imgIRequest** aRequest) { NS_ENSURE_ARG(aDOMNode); NS_ENSURE_ARG_POINTER(aRequest); @@ -197,23 +190,23 @@ nsContextMenuInfo::GetImageRequest(nsIDOMNode *aDOMNode, imgIRequest **aRequest) nsCOMPtr content(do_QueryInterface(aDOMNode)); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - return content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, - aRequest); + return content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, aRequest); } bool -nsContextMenuInfo::HasBackgroundImage(nsIDOMNode * aDOMNode) +nsContextMenuInfo::HasBackgroundImage(nsIDOMNode* aDOMNode) { NS_ENSURE_TRUE(aDOMNode, false); nsRefPtr request; GetBackgroundImageRequest(aDOMNode, getter_AddRefs(request)); - + return (request != nullptr); } nsresult -nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode *aDOMNode, imgRequestProxy **aRequest) +nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode* aDOMNode, + imgRequestProxy** aRequest) { NS_ENSURE_ARG(aDOMNode); @@ -230,8 +223,9 @@ nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode *aDOMNode, imgRequestPro element->GetNamespaceURI(nameSpace); if (nameSpace.IsEmpty()) { nsresult rv = GetBackgroundImageRequestInternal(domNode, aRequest); - if (NS_SUCCEEDED(rv) && *aRequest) + if (NS_SUCCEEDED(rv) && *aRequest) { return NS_OK; + } // no background-image found nsCOMPtr document; @@ -249,7 +243,8 @@ nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode *aDOMNode, imgRequestPro } nsresult -nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode *aDOMNode, imgRequestProxy **aRequest) +nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, + imgRequestProxy** aRequest) { NS_ENSURE_ARG_POINTER(aDOMNode); @@ -273,8 +268,9 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode *aDOMNode, imgRe while (true) { nsCOMPtr domElement(do_QueryInterface(domNode)); // bail for the parent node of the root element or null argument - if (!domElement) + if (!domElement) { break; + } nsCOMPtr computedStyle; window->GetComputedStyle(domElement, EmptyString(), @@ -308,8 +304,9 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode *aDOMNode, imgRe primitiveValue = do_QueryInterface(cssValue); if (primitiveValue) { primitiveValue->GetStringValue(bgStringValue); - if (!bgStringValue.EqualsLiteral("transparent")) + if (!bgStringValue.EqualsLiteral("transparent")) { return NS_ERROR_FAILURE; + } } } diff --git a/embedding/browser/nsContextMenuInfo.h b/embedding/browser/nsContextMenuInfo.h index b35c53d083d..5f29373b727 100644 --- a/embedding/browser/nsContextMenuInfo.h +++ b/embedding/browser/nsContextMenuInfo.h @@ -17,51 +17,38 @@ class ChromeContextMenuListener; class imgRequestProxy; -//***************************************************************************** -// class nsContextMenuInfo -// // Helper class for implementors of nsIContextMenuListener2 -//***************************************************************************** - class nsContextMenuInfo : public nsIContextMenuInfo { friend class ChromeContextMenuListener; - -public: - nsContextMenuInfo(); + +public: + nsContextMenuInfo(); NS_DECL_ISUPPORTS NS_DECL_NSICONTEXTMENUINFO - + private: - virtual ~nsContextMenuInfo(); + virtual ~nsContextMenuInfo(); - void SetMouseEvent(nsIDOMEvent *aEvent) - { mMouseEvent = aEvent; } + void SetMouseEvent(nsIDOMEvent* aEvent) { mMouseEvent = aEvent; } + void SetDOMNode(nsIDOMNode* aNode) { mDOMNode = aNode; } + void SetAssociatedLink(nsIDOMNode* aLink) { mAssociatedLink = aLink; } - void SetDOMNode(nsIDOMNode *aNode) - { mDOMNode = aNode; } - - void SetAssociatedLink(nsIDOMNode *aLink) - { mAssociatedLink = aLink; } + nsresult GetImageRequest(nsIDOMNode* aDOMNode, imgIRequest** aRequest); - nsresult GetImageRequest(nsIDOMNode *aDOMNode, - imgIRequest **aRequest); + bool HasBackgroundImage(nsIDOMNode* aDOMNode); - bool HasBackgroundImage(nsIDOMNode *aDOMNode); + nsresult GetBackgroundImageRequest(nsIDOMNode* aDOMNode, + imgRequestProxy** aRequest); - nsresult GetBackgroundImageRequest(nsIDOMNode *aDOMNode, - imgRequestProxy **aRequest); + nsresult GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, + imgRequestProxy** aRequest); - nsresult GetBackgroundImageRequestInternal(nsIDOMNode *aDOMNode, - imgRequestProxy **aRequest); - private: - nsCOMPtr mMouseEvent; - nsCOMPtr mDOMNode; - nsCOMPtr mAssociatedLink; - -}; // class nsContextMenuInfo - + nsCOMPtr mMouseEvent; + nsCOMPtr mDOMNode; + nsCOMPtr mAssociatedLink; +}; #endif // nsContextMenuInfo_h__ diff --git a/embedding/browser/nsDocShellTreeOwner.cpp b/embedding/browser/nsDocShellTreeOwner.cpp index 2dc54edbe02..7d38e5b635d 100644 --- a/embedding/browser/nsDocShellTreeOwner.cpp +++ b/embedding/browser/nsDocShellTreeOwner.cpp @@ -70,45 +70,35 @@ using namespace mozilla; using namespace mozilla::dom; -// -// GetEventReceiver -// // A helper routine that navigates the tricky path from a |nsWebBrowser| to // a |EventTarget| via the window root and chrome event handler. -// static nsresult -GetDOMEventTarget(nsWebBrowser* inBrowser, EventTarget** aTarget) +GetDOMEventTarget(nsWebBrowser* aInBrowser, EventTarget** aTarget) { - NS_ENSURE_ARG_POINTER(inBrowser); + NS_ENSURE_ARG_POINTER(aInBrowser); nsCOMPtr domWindow; - inBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + aInBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE); nsCOMPtr domWindowPrivate = do_QueryInterface(domWindow); NS_ENSURE_TRUE(domWindowPrivate, NS_ERROR_FAILURE); - nsPIDOMWindow *rootWindow = domWindowPrivate->GetPrivateRoot(); + nsPIDOMWindow* rootWindow = domWindowPrivate->GetPrivateRoot(); NS_ENSURE_TRUE(rootWindow, NS_ERROR_FAILURE); - nsCOMPtr target = - rootWindow->GetChromeEventHandler(); + nsCOMPtr target = rootWindow->GetChromeEventHandler(); NS_ENSURE_TRUE(target, NS_ERROR_FAILURE); target.forget(aTarget); return NS_OK; } - -//***************************************************************************** -//*** nsDocShellTreeOwner: Object Management -//***************************************************************************** - -nsDocShellTreeOwner::nsDocShellTreeOwner() : - mWebBrowser(nullptr), - mTreeOwner(nullptr), - mPrimaryContentShell(nullptr), - mWebBrowserChrome(nullptr), - mOwnerWin(nullptr), - mOwnerRequestor(nullptr) +nsDocShellTreeOwner::nsDocShellTreeOwner() + : mWebBrowser(nullptr) + , mTreeOwner(nullptr) + , mPrimaryContentShell(nullptr) + , mWebBrowserChrome(nullptr) + , mOwnerWin(nullptr) + , mOwnerRequestor(nullptr) { } @@ -117,22 +107,18 @@ nsDocShellTreeOwner::~nsDocShellTreeOwner() RemoveChromeListeners(); } -//***************************************************************************** -// nsDocShellTreeOwner::nsISupports -//***************************************************************************** - NS_IMPL_ADDREF(nsDocShellTreeOwner) NS_IMPL_RELEASE(nsDocShellTreeOwner) NS_INTERFACE_MAP_BEGIN(nsDocShellTreeOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner) - NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner) - NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) - NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) - NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) - NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) - NS_INTERFACE_MAP_ENTRY(nsICDocShellTreeOwner) - NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner) + NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner) + NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) + NS_INTERFACE_MAP_ENTRY(nsICDocShellTreeOwner) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_END //***************************************************************************** @@ -144,12 +130,14 @@ nsDocShellTreeOwner::GetInterface(const nsIID& aIID, void** aSink) { NS_ENSURE_ARG_POINTER(aSink); - if (NS_SUCCEEDED(QueryInterface(aIID, aSink))) + if (NS_SUCCEEDED(QueryInterface(aIID, aSink))) { return NS_OK; + } if (aIID.Equals(NS_GET_IID(nsIWebBrowserChromeFocus))) { - if (mWebBrowserChromeWeak != nullptr) + if (mWebBrowserChromeWeak != nullptr) { return mWebBrowserChromeWeak->QueryReferent(aIID, aSink); + } return mOwnerWin->QueryInterface(aIID, aSink); } @@ -176,8 +164,9 @@ nsDocShellTreeOwner::GetInterface(const nsIID& aIID, void** aSink) } nsCOMPtr req = GetOwnerRequestor(); - if (req) + if (req) { return req->GetInterface(aIID, aSink); + } return NS_NOINTERFACE; } @@ -194,19 +183,24 @@ nsDocShellTreeOwner::FindItemWithName(const char16_t* aName, { NS_ENSURE_ARG(aName); NS_ENSURE_ARG_POINTER(aFoundItem); - *aFoundItem = nullptr; // if we don't find one, we return NS_OK and a null result + + // if we don't find one, we return NS_OK and a null result + *aFoundItem = nullptr; nsresult rv; nsAutoString name(aName); - if (!mWebBrowser) + if (!mWebBrowser) { return NS_OK; // stymied + } /* special cases */ - if (name.IsEmpty()) + if (name.IsEmpty()) { return NS_OK; - if (name.LowerCaseEqualsLiteral("_blank")) + } + if (name.LowerCaseEqualsLiteral("_blank")) { return NS_OK; + } // _main is an IE target which should be case-insensitive but isn't // see bug 217886 for details // XXXbz what if our browser isn't targetable? We need to handle that somehow. @@ -241,15 +235,17 @@ nsDocShellTreeOwner::FindItemWithName(const char16_t* aName, } nsresult -nsDocShellTreeOwner::FindItemWithNameAcrossWindows(const char16_t* aName, - nsIDocShellTreeItem* aRequestor, - nsIDocShellTreeItem* aOriginalRequestor, - nsIDocShellTreeItem** aFoundItem) +nsDocShellTreeOwner::FindItemWithNameAcrossWindows( + const char16_t* aName, + nsIDocShellTreeItem* aRequestor, + nsIDocShellTreeItem* aOriginalRequestor, + nsIDocShellTreeItem** aFoundItem) { // search for the item across the list of top-level windows nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); - if (!wwatch) + if (!wwatch) { return NS_OK; + } return wwatch->FindItemWithName(aName, aRequestor, aOriginalRequestor, aFoundItem); @@ -258,30 +254,34 @@ nsDocShellTreeOwner::FindItemWithNameAcrossWindows(const char16_t* aName, void nsDocShellTreeOwner::EnsurePrompter() { - if (mPrompter) + if (mPrompter) { return; + } nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (wwatch && mWebBrowser) { nsCOMPtr domWindow; mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (domWindow) + if (domWindow) { wwatch->GetNewPrompter(domWindow, getter_AddRefs(mPrompter)); + } } } void nsDocShellTreeOwner::EnsureAuthPrompter() { - if (mAuthPrompter) + if (mAuthPrompter) { return; + } nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (wwatch && mWebBrowser) { nsCOMPtr domWindow; mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (domWindow) + if (domWindow) { wwatch->GetNewAuthPrompter(domWindow, getter_AddRefs(mAuthPrompter)); + } } } @@ -292,11 +292,13 @@ nsDocShellTreeOwner::AddToWatcher() nsCOMPtr domWindow; mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); if (domWindow) { - nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + nsCOMPtr wwatch( + do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (wwatch) { nsCOMPtr webBrowserChrome = GetWebBrowserChrome(); - if (webBrowserChrome) + if (webBrowserChrome) { wwatch->AddWindow(domWindow, webBrowserChrome); + } } } } @@ -309,36 +311,40 @@ nsDocShellTreeOwner::RemoveFromWatcher() nsCOMPtr domWindow; mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); if (domWindow) { - nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); - if (wwatch) + nsCOMPtr wwatch( + do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + if (wwatch) { wwatch->RemoveWindow(domWindow); + } } } } - NS_IMETHODIMP nsDocShellTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell, bool aPrimary, bool aTargetable, const nsAString& aID) { - if (mTreeOwner) - return mTreeOwner->ContentShellAdded(aContentShell, aPrimary, - aTargetable, aID); + if (mTreeOwner) + return mTreeOwner->ContentShellAdded(aContentShell, aPrimary, aTargetable, + aID); - if (aPrimary) - mPrimaryContentShell = aContentShell; - return NS_OK; + if (aPrimary) { + mPrimaryContentShell = aContentShell; + } + return NS_OK; } NS_IMETHODIMP nsDocShellTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell) { - if (mTreeOwner) + if (mTreeOwner) { return mTreeOwner->ContentShellRemoved(aContentShell); + } - if (mPrimaryContentShell == aContentShell) + if (mPrimaryContentShell == aContentShell) { mPrimaryContentShell = nullptr; + } return NS_OK; } @@ -346,66 +352,70 @@ nsDocShellTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell) NS_IMETHODIMP nsDocShellTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell) { - NS_ENSURE_ARG_POINTER(aShell); + NS_ENSURE_ARG_POINTER(aShell); - if (mTreeOwner) - return mTreeOwner->GetPrimaryContentShell(aShell); + if (mTreeOwner) { + return mTreeOwner->GetPrimaryContentShell(aShell); + } - nsCOMPtr shell; - shell = (mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShell); - shell.forget(aShell); + nsCOMPtr shell; + shell = mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShell; + shell.forget(aShell); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, int32_t aCX, int32_t aCY) { - nsCOMPtr webBrowserChrome = GetWebBrowserChrome(); + nsCOMPtr webBrowserChrome = GetWebBrowserChrome(); - NS_ENSURE_STATE(mTreeOwner || webBrowserChrome); + NS_ENSURE_STATE(mTreeOwner || webBrowserChrome); - if (mTreeOwner) - return mTreeOwner->SizeShellTo(aShellItem, aCX, aCY); + if (mTreeOwner) { + return mTreeOwner->SizeShellTo(aShellItem, aCX, aCY); + } - if (aShellItem == mWebBrowser->mDocShell) - return webBrowserChrome->SizeBrowserTo(aCX, aCY); + if (aShellItem == mWebBrowser->mDocShell) { + return webBrowserChrome->SizeBrowserTo(aCX, aCY); + } - nsCOMPtr webNav(do_QueryInterface(aShellItem)); - NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); + nsCOMPtr webNav(do_QueryInterface(aShellItem)); + NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); - nsCOMPtr domDocument; - webNav->GetDocument(getter_AddRefs(domDocument)); - NS_ENSURE_TRUE(domDocument, NS_ERROR_FAILURE); + nsCOMPtr domDocument; + webNav->GetDocument(getter_AddRefs(domDocument)); + NS_ENSURE_TRUE(domDocument, NS_ERROR_FAILURE); - nsCOMPtr domElement; - domDocument->GetDocumentElement(getter_AddRefs(domElement)); - NS_ENSURE_TRUE(domElement, NS_ERROR_FAILURE); + nsCOMPtr domElement; + domDocument->GetDocumentElement(getter_AddRefs(domElement)); + NS_ENSURE_TRUE(domElement, NS_ERROR_FAILURE); - // Set the preferred Size - //XXX - NS_ERROR("Implement this"); - /* - Set the preferred size on the aShellItem. - */ + // Set the preferred Size + //XXX + NS_ERROR("Implement this"); + /* + Set the preferred size on the aShellItem. + */ - nsRefPtr presContext; - mWebBrowser->mDocShell->GetPresContext(getter_AddRefs(presContext)); - NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); + nsRefPtr presContext; + mWebBrowser->mDocShell->GetPresContext(getter_AddRefs(presContext)); + NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); - nsIPresShell *presShell = presContext->GetPresShell(); - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + nsIPresShell* presShell = presContext->GetPresShell(); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, - NS_UNCONSTRAINEDSIZE), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS( + presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE), + NS_ERROR_FAILURE); - nsRect shellArea = presContext->GetVisibleArea(); + nsRect shellArea = presContext->GetVisibleArea(); - int32_t browserCX = presContext->AppUnitsToDevPixels(shellArea.width); - int32_t browserCY = presContext->AppUnitsToDevPixels(shellArea.height); + int32_t browserCX = presContext->AppUnitsToDevPixels(shellArea.width); + int32_t browserCY = presContext->AppUnitsToDevPixels(shellArea.height); - return webBrowserChrome->SizeBrowserTo(browserCX, browserCY); + return webBrowserChrome->SizeBrowserTo(browserCX, browserCY); } NS_IMETHODIMP @@ -440,7 +450,6 @@ nsDocShellTreeOwner::GetTargetableShellCount(uint32_t* aResult) // nsDocShellTreeOwner::nsIBaseWindow //***************************************************************************** - NS_IMETHODIMP nsDocShellTreeOwner::InitWindow(nativeWindow aParentNativeWindow, nsIWidget* aParentWidget, int32_t aX, @@ -459,8 +468,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::Destroy() { nsCOMPtr webBrowserChrome = GetWebBrowserChrome(); - if (webBrowserChrome) - { + if (webBrowserChrome) { return webBrowserChrome->DestroyBrowserWindow(); } @@ -468,7 +476,7 @@ nsDocShellTreeOwner::Destroy() } NS_IMETHODIMP -nsDocShellTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double *aScale) +nsDocShellTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) { if (mWebBrowser) { return mWebBrowser->GetUnscaledDevicePixelsPerCSSPixel(aScale); @@ -482,8 +490,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::SetPosition(int32_t aX, int32_t aY) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION, aX, aY, 0, 0); } @@ -494,8 +501,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::GetPosition(int32_t* aX, int32_t* aY) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->GetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION, aX, aY, nullptr, nullptr); } @@ -506,8 +512,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER, 0, 0, aCX, aCY); } @@ -518,8 +523,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::GetSize(int32_t* aCX, int32_t* aCY) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->GetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER, nullptr, nullptr, aCX, aCY); } @@ -531,11 +535,11 @@ nsDocShellTreeOwner::SetPositionAndSize(int32_t aX, int32_t aY, int32_t aCX, int32_t aCY, bool aRepaint) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { - return ownerWin->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER | - nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION, - aX, aY, aCX, aCY); + if (ownerWin) { + return ownerWin->SetDimensions( + nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER | + nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION, + aX, aY, aCX, aCY); } return NS_ERROR_NULL_POINTER; } @@ -545,11 +549,11 @@ nsDocShellTreeOwner::GetPositionAndSize(int32_t* aX, int32_t* aY, int32_t* aCX, int32_t* aCY) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { - return ownerWin->GetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER | - nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION, - aX, aY, aCX, aCY); + if (ownerWin) { + return ownerWin->GetDimensions( + nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER | + nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION, + aX, aY, aCX, aCY); } return NS_ERROR_NULL_POINTER; } @@ -576,8 +580,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->GetSiteWindow(aParentNativeWindow); } return NS_ERROR_NULL_POINTER; @@ -600,8 +603,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::GetVisibility(bool* aVisibility) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->GetVisibility(aVisibility); } return NS_ERROR_NULL_POINTER; @@ -611,15 +613,14 @@ NS_IMETHODIMP nsDocShellTreeOwner::SetVisibility(bool aVisibility) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->SetVisibility(aVisibility); } return NS_ERROR_NULL_POINTER; } NS_IMETHODIMP -nsDocShellTreeOwner::GetEnabled(bool *aEnabled) +nsDocShellTreeOwner::GetEnabled(bool* aEnabled) { NS_ENSURE_ARG_POINTER(aEnabled); *aEnabled = true; @@ -635,15 +636,14 @@ nsDocShellTreeOwner::SetEnabled(bool aEnabled) NS_IMETHODIMP nsDocShellTreeOwner::GetMainWidget(nsIWidget** aMainWidget) { - return NS_ERROR_NULL_POINTER; + return NS_ERROR_NULL_POINTER; } NS_IMETHODIMP nsDocShellTreeOwner::SetFocus() { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->SetFocus(); } return NS_ERROR_NULL_POINTER; @@ -653,8 +653,7 @@ NS_IMETHODIMP nsDocShellTreeOwner::GetTitle(char16_t** aTitle) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->GetTitle(aTitle); } return NS_ERROR_NULL_POINTER; @@ -664,19 +663,16 @@ NS_IMETHODIMP nsDocShellTreeOwner::SetTitle(const char16_t* aTitle) { nsCOMPtr ownerWin = GetOwnerWin(); - if (ownerWin) - { + if (ownerWin) { return ownerWin->SetTitle(aTitle); } return NS_ERROR_NULL_POINTER; } - //***************************************************************************** // nsDocShellTreeOwner::nsIWebProgressListener //***************************************************************************** - NS_IMETHODIMP nsDocShellTreeOwner::OnProgressChange(nsIWebProgress* aProgress, nsIRequest* aRequest, @@ -685,10 +681,10 @@ nsDocShellTreeOwner::OnProgressChange(nsIWebProgress* aProgress, int32_t aCurTotalProgress, int32_t aMaxTotalProgress) { - // In the absence of DOM document creation event, this method is the - // most convenient place to install the mouse listener on the - // DOM document. - return AddChromeListeners(); + // In the absence of DOM document creation event, this method is the + // most convenient place to install the mouse listener on the + // DOM document. + return AddChromeListeners(); } NS_IMETHODIMP @@ -697,7 +693,7 @@ nsDocShellTreeOwner::OnStateChange(nsIWebProgress* aProgress, uint32_t aProgressStateFlags, nsresult aStatus) { - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -706,7 +702,7 @@ nsDocShellTreeOwner::OnLocationChange(nsIWebProgress* aWebProgress, nsIURI* aURI, uint32_t aFlags) { - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -715,22 +711,17 @@ nsDocShellTreeOwner::OnStatusChange(nsIWebProgress* aWebProgress, nsresult aStatus, const char16_t* aMessage) { - return NS_OK; + return NS_OK; } NS_IMETHODIMP -nsDocShellTreeOwner::OnSecurityChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - uint32_t state) +nsDocShellTreeOwner::OnSecurityChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + uint32_t aState) { - return NS_OK; + return NS_OK; } - -//***************************************************************************** -// nsDocShellTreeOwner: Helpers -//***************************************************************************** - //***************************************************************************** // nsDocShellTreeOwner: Accessors //***************************************************************************** @@ -738,8 +729,9 @@ nsDocShellTreeOwner::OnSecurityChange(nsIWebProgress *aWebProgress, void nsDocShellTreeOwner::WebBrowser(nsWebBrowser* aWebBrowser) { - if (!aWebBrowser) + if (!aWebBrowser) { RemoveChromeListeners(); + } if (aWebBrowser != mWebBrowser) { mPrompter = nullptr; mAuthPrompter = nullptr; @@ -748,10 +740,10 @@ nsDocShellTreeOwner::WebBrowser(nsWebBrowser* aWebBrowser) mWebBrowser = aWebBrowser; } -nsWebBrowser * +nsWebBrowser* nsDocShellTreeOwner::WebBrowser() { - return mWebBrowser; + return mWebBrowser; } NS_IMETHODIMP @@ -760,13 +752,15 @@ nsDocShellTreeOwner::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) if (aTreeOwner) { nsCOMPtr webBrowserChrome(do_GetInterface(aTreeOwner)); NS_ENSURE_TRUE(webBrowserChrome, NS_ERROR_INVALID_ARG); - NS_ENSURE_SUCCESS(SetWebBrowserChrome(webBrowserChrome), NS_ERROR_INVALID_ARG); + NS_ENSURE_SUCCESS(SetWebBrowserChrome(webBrowserChrome), + NS_ERROR_INVALID_ARG); mTreeOwner = aTreeOwner; } else { mTreeOwner = nullptr; nsCOMPtr webBrowserChrome = GetWebBrowserChrome(); - if (!webBrowserChrome) + if (!webBrowserChrome) { NS_ENSURE_SUCCESS(SetWebBrowserChrome(nullptr), NS_ERROR_FAILURE); + } } return NS_OK; @@ -782,12 +776,14 @@ nsDocShellTreeOwner::SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome) mWebBrowserChromeWeak = nullptr; } else { nsCOMPtr supportsweak = - do_QueryInterface(aWebBrowserChrome); + do_QueryInterface(aWebBrowserChrome); if (supportsweak) { supportsweak->GetWeakReference(getter_AddRefs(mWebBrowserChromeWeak)); } else { - nsCOMPtr ownerWin(do_QueryInterface(aWebBrowserChrome)); - nsCOMPtr requestor(do_QueryInterface(aWebBrowserChrome)); + nsCOMPtr ownerWin( + do_QueryInterface(aWebBrowserChrome)); + nsCOMPtr requestor( + do_QueryInterface(aWebBrowserChrome)); // it's ok for ownerWin or requestor to be null. mWebBrowserChrome = aWebBrowserChrome; @@ -798,26 +794,22 @@ nsDocShellTreeOwner::SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome) return NS_OK; } - -// -// AddChromeListeners -// // Hook up things to the chrome like context menus and tooltips, if the chrome // has implemented the right interfaces. -// NS_IMETHODIMP nsDocShellTreeOwner::AddChromeListeners() { nsresult rv = NS_OK; nsCOMPtr webBrowserChrome = GetWebBrowserChrome(); - if (!webBrowserChrome) + if (!webBrowserChrome) { return NS_ERROR_FAILURE; + } // install tooltips if (!mChromeTooltipListener) { - nsCOMPtr - tooltipListener(do_QueryInterface(webBrowserChrome)); + nsCOMPtr tooltipListener( + do_QueryInterface(webBrowserChrome)); if (tooltipListener) { mChromeTooltipListener = new ChromeTooltipListener(mWebBrowser, webBrowserChrome); @@ -827,13 +819,13 @@ nsDocShellTreeOwner::AddChromeListeners() // install context menus if (!mChromeContextMenuListener) { - nsCOMPtr - contextListener2(do_QueryInterface(webBrowserChrome)); - nsCOMPtr - contextListener(do_QueryInterface(webBrowserChrome)); + nsCOMPtr contextListener2( + do_QueryInterface(webBrowserChrome)); + nsCOMPtr contextListener( + do_QueryInterface(webBrowserChrome)); if (contextListener2 || contextListener) { mChromeContextMenuListener = - new ChromeContextMenuListener(mWebBrowser, webBrowserChrome); + new ChromeContextMenuListener(mWebBrowser, webBrowserChrome); rv = mChromeContextMenuListener->AddChromeListeners(); } } @@ -851,9 +843,7 @@ nsDocShellTreeOwner::AddChromeListeners() } return rv; - -} // AddChromeListeners - +} NS_IMETHODIMP nsDocShellTreeOwner::RemoveChromeListeners() @@ -869,12 +859,12 @@ nsDocShellTreeOwner::RemoveChromeListeners() nsCOMPtr piTarget; GetDOMEventTarget(mWebBrowser, getter_AddRefs(piTarget)); - if (!piTarget) + if (!piTarget) { return NS_OK; + } EventListenerManager* elmP = piTarget->GetOrCreateListenerManager(); - if (elmP) - { + if (elmP) { elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("dragover"), TrustedEventsAtSystemGroupBubble()); elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("drop"), @@ -896,21 +886,23 @@ nsDocShellTreeOwner::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } - nsCOMPtr handler = do_GetService("@mozilla.org/content/dropped-link-handler;1"); + nsCOMPtr handler = + do_GetService("@mozilla.org/content/dropped-link-handler;1"); if (handler) { nsAutoString eventType; aEvent->GetType(eventType); if (eventType.EqualsLiteral("dragover")) { bool canDropLink; handler->CanDropLink(dragEvent, false, &canDropLink); - if (canDropLink) + if (canDropLink) { aEvent->PreventDefault(); - } - else if (eventType.EqualsLiteral("drop")) { - nsIWebNavigation* webnav = static_cast(mWebBrowser); + } + } else if (eventType.EqualsLiteral("drop")) { + nsIWebNavigation* webnav = static_cast(mWebBrowser); nsAutoString link, name; - if (webnav && NS_SUCCEEDED(handler->DropLink(dragEvent, name, true, link))) { + if (webnav && + NS_SUCCEEDED(handler->DropLink(dragEvent, name, true, link))) { if (!link.IsEmpty()) { webnav->LoadURI(link.get(), 0, nullptr, nullptr, nullptr); } @@ -960,58 +952,50 @@ nsDocShellTreeOwner::GetOwnerRequestor() return req.forget(); } - -/////////////////////////////////////////////////////////////////////////////// -// DefaultTooltipTextProvider - class DefaultTooltipTextProvider final : public nsITooltipTextProvider { public: - DefaultTooltipTextProvider(); + DefaultTooltipTextProvider(); - NS_DECL_ISUPPORTS - NS_DECL_NSITOOLTIPTEXTPROVIDER + NS_DECL_ISUPPORTS + NS_DECL_NSITOOLTIPTEXTPROVIDER protected: - ~DefaultTooltipTextProvider() {} + ~DefaultTooltipTextProvider() {} - nsCOMPtr mTag_dialog; - nsCOMPtr mTag_dialogheader; - nsCOMPtr mTag_window; + nsCOMPtr mTag_dialog; + nsCOMPtr mTag_dialogheader; + nsCOMPtr mTag_window; }; NS_IMPL_ISUPPORTS(DefaultTooltipTextProvider, nsITooltipTextProvider) DefaultTooltipTextProvider::DefaultTooltipTextProvider() { - // There are certain element types which we don't want to use - // as tool tip text. - mTag_dialog = do_GetAtom("dialog"); - mTag_dialogheader = do_GetAtom("dialogheader"); - mTag_window = do_GetAtom("window"); + // There are certain element types which we don't want to use + // as tool tip text. + mTag_dialog = do_GetAtom("dialog"); + mTag_dialogheader = do_GetAtom("dialogheader"); + mTag_window = do_GetAtom("window"); } -// -// UseSVGTitle -// -// A helper routine that determines whether we're still interested -// in SVG titles. We need to stop at the SVG root element that -// has a document node parent -// +// A helper routine that determines whether we're still interested in SVG +// titles. We need to stop at the SVG root element that has a document node +// parent. static bool -UseSVGTitle(nsIDOMElement *currElement) +UseSVGTitle(nsIDOMElement* aCurrElement) { - nsCOMPtr element(do_QueryInterface(currElement)); - if (!element || !element->IsSVGElement() || !element->GetParentNode()) + nsCOMPtr element(do_QueryInterface(aCurrElement)); + if (!element || !element->IsSVGElement() || !element->GetParentNode()) { return false; + } return element->GetParentNode()->NodeType() != nsIDOMNode::DOCUMENT_NODE; } -/* void getNodeText(in nsIDOMNode aNode, out wstring aText); */ NS_IMETHODIMP -DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, char16_t **aText, - bool *_retval) +DefaultTooltipTextProvider::GetNodeText(nsIDOMNode* aNode, char16_t** aText, + bool* aResult) { NS_ENSURE_ARG_POINTER(aNode); NS_ENSURE_ARG_POINTER(aText); @@ -1039,8 +1023,7 @@ DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, char16_t **aText, formHasNoValidate = form->HasAttr(kNameSpaceID_None, noValidateAtom); } - if (!content->HasAttr(kNameSpaceID_None, titleAtom) && - !formHasNoValidate) { + if (!content->HasAttr(kNameSpaceID_None, titleAtom) && !formHasNoValidate) { cvElement->GetValidationMessage(outText); found = !outText.IsEmpty(); } @@ -1061,13 +1044,17 @@ DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, char16_t **aText, } else { // ...ok, that didn't work, try it in the XLink namespace NS_NAMED_LITERAL_STRING(xlinkNS, "http://www.w3.org/1999/xlink"); - nsCOMPtr linkContent(do_QueryInterface(currElement)); + nsCOMPtr linkContent( + do_QueryInterface(currElement)); if (linkContent) { nsCOMPtr uri(linkContent->GetURIExternal()); if (uri) { - currElement->GetAttributeNS(NS_LITERAL_STRING("http://www.w3.org/1999/xlink"), NS_LITERAL_STRING("title"), outText); - if (outText.Length()) + currElement->GetAttributeNS( + NS_LITERAL_STRING("http://www.w3.org/1999/xlink"), + NS_LITERAL_STRING("title"), outText); + if (outText.Length()) { found = true; + } } } else { if (lookingForSVGTitle) { @@ -1080,8 +1067,9 @@ DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, char16_t **aText, nsIContent* child = childNodes->Item(i); if (child->IsSVGElement(nsGkAtoms::title)) { static_cast(child)->GetTextContent(outText); - if (outText.Length()) + if (outText.Length()) { found = true; + } break; } } @@ -1097,94 +1085,80 @@ DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, char16_t **aText, nsCOMPtr temp(current); temp->GetParentNode(getter_AddRefs(current)); } - } // while not found + } - *_retval = found; + *aResult = found; *aText = (found) ? ToNewUnicode(outText) : nullptr; return NS_OK; } -/////////////////////////////////////////////////////////////////////////////// - NS_IMPL_ISUPPORTS(ChromeTooltipListener, nsIDOMEventListener) -// -// ChromeTooltipListener ctor -// - -ChromeTooltipListener::ChromeTooltipListener(nsWebBrowser* inBrowser, - nsIWebBrowserChrome* inChrome) - : mWebBrowser(inBrowser), mWebBrowserChrome(inChrome), - mTooltipListenerInstalled(false), - mMouseClientX(0), mMouseClientY(0), - mShowingTooltip(false), mTooltipShownOnce(false) +ChromeTooltipListener::ChromeTooltipListener(nsWebBrowser* aInBrowser, + nsIWebBrowserChrome* aInChrome) + : mWebBrowser(aInBrowser) + , mWebBrowserChrome(aInChrome) + , mTooltipListenerInstalled(false) + , mMouseClientX(0) + , mMouseClientY(0) + , mShowingTooltip(false) + , mTooltipShownOnce(false) { mTooltipTextProvider = do_GetService(NS_TOOLTIPTEXTPROVIDER_CONTRACTID); if (!mTooltipTextProvider) { mTooltipTextProvider = new DefaultTooltipTextProvider(); } -} // ctor +} - -// -// ChromeTooltipListener dtor -// ChromeTooltipListener::~ChromeTooltipListener() { +} -} // dtor - - -// -// AddChromeListeners -// // Hook up things to the chrome like context menus and tooltips, if the chrome // has implemented the right interfaces. -// NS_IMETHODIMP ChromeTooltipListener::AddChromeListeners() { - if (!mEventTarget) + if (!mEventTarget) { GetDOMEventTarget(mWebBrowser, getter_AddRefs(mEventTarget)); + } // Register the appropriate events for tooltips, but only if // the embedding chrome cares. nsresult rv = NS_OK; - nsCOMPtr tooltipListener(do_QueryInterface(mWebBrowserChrome)); + nsCOMPtr tooltipListener( + do_QueryInterface(mWebBrowserChrome)); if (tooltipListener && !mTooltipListenerInstalled) { rv = AddTooltipListener(); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { return rv; + } } return rv; +} -} // AddChromeListeners - - -// -// AddTooltipListener -// -// Subscribe to the events that will allow us to track tooltips. We need "mouse" for mouseExit, -// "mouse motion" for mouseMove, and "key" for keyDown. As we add the listeners, keep track -// of how many succeed so we can clean up correctly in Release(). -// +// Subscribe to the events that will allow us to track tooltips. We need "mouse" +// for mouseExit, "mouse motion" for mouseMove, and "key" for keyDown. As we +// add the listeners, keep track of how many succeed so we can clean up +// correctly in Release(). NS_IMETHODIMP ChromeTooltipListener::AddTooltipListener() { if (mEventTarget) { - nsresult rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("keydown"), - this, false, false); + nsresult rv = NS_OK; + rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("keydown"), + this, false, false); NS_ENSURE_SUCCESS(rv, rv); - rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("mousedown"), this, - false, false); + rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("mousedown"), + this, false, false); NS_ENSURE_SUCCESS(rv, rv); - rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("mouseout"), this, - false, false); + rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("mouseout"), + this, false, false); NS_ENSURE_SUCCESS(rv, rv); - rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("mousemove"), this, - false, false); + rv = mEventTarget->AddSystemEventListener(NS_LITERAL_STRING("mousemove"), + this, false, false); NS_ENSURE_SUCCESS(rv, rv); mTooltipListenerInstalled = true; @@ -1193,47 +1167,36 @@ ChromeTooltipListener::AddTooltipListener() return NS_OK; } - -// -// RemoveChromeListeners -// // Unsubscribe from the various things we've hooked up to the window root. -// NS_IMETHODIMP ChromeTooltipListener::RemoveChromeListeners() { HideTooltip(); - if (mTooltipListenerInstalled) + if (mTooltipListenerInstalled) { RemoveTooltipListener(); + } mEventTarget = nullptr; // it really doesn't matter if these fail... return NS_OK; +} -} // RemoveChromeTooltipListeners - - - -// -// RemoveTooltipListener -// -// Unsubscribe from all the various tooltip events that we were listening to -// +// Unsubscribe from all the various tooltip events that we were listening to. NS_IMETHODIMP ChromeTooltipListener::RemoveTooltipListener() { if (mEventTarget) { - nsresult rv = - mEventTarget->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"), this, - false); + nsresult rv = NS_OK; + rv = mEventTarget->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"), + this, false); NS_ENSURE_SUCCESS(rv, rv); rv = mEventTarget->RemoveSystemEventListener(NS_LITERAL_STRING("mousedown"), this, false); NS_ENSURE_SUCCESS(rv, rv); - rv = mEventTarget->RemoveSystemEventListener(NS_LITERAL_STRING("mouseout"), this, - false); + rv = mEventTarget->RemoveSystemEventListener(NS_LITERAL_STRING("mouseout"), + this, false); NS_ENSURE_SUCCESS(rv, rv); rv = mEventTarget->RemoveSystemEventListener(NS_LITERAL_STRING("mousemove"), this, false); @@ -1266,36 +1229,36 @@ ChromeTooltipListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -// -// MouseMove -// -// If we're a tooltip, fire off a timer to see if a tooltip should be shown. If the -// timer fires, we cache the node in |mPossibleTooltipNode|. -// +// If we're a tooltip, fire off a timer to see if a tooltip should be shown. If +// the timer fires, we cache the node in |mPossibleTooltipNode|. nsresult ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent) { nsCOMPtr mouseEvent(do_QueryInterface(aMouseEvent)); - if (!mouseEvent) + if (!mouseEvent) { return NS_OK; + } - // stash the coordinates of the event so that we can still get back to it from within the - // timer callback. On win32, we'll get a MouseMove event even when a popup goes away -- - // even when the mouse doesn't change position! To get around this, we make sure the - // mouse has really moved before proceeding. + // stash the coordinates of the event so that we can still get back to it from + // within the timer callback. On win32, we'll get a MouseMove event even when + // a popup goes away -- even when the mouse doesn't change position! To get + // around this, we make sure the mouse has really moved before proceeding. int32_t newMouseX, newMouseY; mouseEvent->GetClientX(&newMouseX); mouseEvent->GetClientY(&newMouseY); - if (mMouseClientX == newMouseX && mMouseClientY == newMouseY) + if (mMouseClientX == newMouseX && mMouseClientY == newMouseY) { return NS_OK; + } // Filter out minor mouse movements. if (mShowingTooltip && (abs(mMouseClientX - newMouseX) <= kTooltipMouseMoveTolerance) && - (abs(mMouseClientY - newMouseY) <= kTooltipMouseMoveTolerance)) + (abs(mMouseClientY - newMouseY) <= kTooltipMouseMoveTolerance)) { return NS_OK; + } - mMouseClientX = newMouseX; mMouseClientY = newMouseY; + mMouseClientX = newMouseX; + mMouseClientY = newMouseY; mouseEvent->GetScreenX(&mMouseScreenX); mouseEvent->GetScreenY(&mMouseScreenY); @@ -1306,19 +1269,21 @@ ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent) if (!mShowingTooltip && !mTooltipShownOnce) { mTooltipTimer = do_CreateInstance("@mozilla.org/timer;1"); if (mTooltipTimer) { - nsCOMPtr eventTarget = aMouseEvent->InternalDOMEvent()->GetTarget(); - if (eventTarget) + nsCOMPtr eventTarget = + aMouseEvent->InternalDOMEvent()->GetTarget(); + if (eventTarget) { mPossibleTooltipNode = do_QueryInterface(eventTarget); - if (mPossibleTooltipNode) { - nsresult rv = - mTooltipTimer->InitWithFuncCallback(sTooltipCallback, this, - LookAndFeel::GetInt(LookAndFeel::eIntID_TooltipDelay, 500), - nsITimer::TYPE_ONE_SHOT); - if (NS_FAILED(rv)) - mPossibleTooltipNode = nullptr; } - } - else { + if (mPossibleTooltipNode) { + nsresult rv = mTooltipTimer->InitWithFuncCallback( + sTooltipCallback, this, + LookAndFeel::GetInt(LookAndFeel::eIntID_TooltipDelay, 500), + nsITimer::TYPE_ONE_SHOT); + if (NS_FAILED(rv)) { + mPossibleTooltipNode = nullptr; + } + } + } else { NS_WARNING("Could not create a timer for tooltip tracking"); } } else { @@ -1327,40 +1292,31 @@ ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent) } return NS_OK; +} -} // MouseMove - - -// -// ShowTooltip -// -// Tell the registered chrome that they should show the tooltip -// +// Tell the registered chrome that they should show the tooltip. NS_IMETHODIMP -ChromeTooltipListener::ShowTooltip(int32_t inXCoords, int32_t inYCoords, - const nsAString & inTipText) +ChromeTooltipListener::ShowTooltip(int32_t aInXCoords, int32_t aInYCoords, + const nsAString& aInTipText) { nsresult rv = NS_OK; // do the work to call the client - nsCOMPtr tooltipListener(do_QueryInterface(mWebBrowserChrome)); + nsCOMPtr tooltipListener( + do_QueryInterface(mWebBrowserChrome)); if (tooltipListener) { - rv = tooltipListener->OnShowTooltip(inXCoords, inYCoords, PromiseFlatString(inTipText).get()); - if (NS_SUCCEEDED(rv)) + rv = tooltipListener->OnShowTooltip(aInXCoords, aInYCoords, + PromiseFlatString(aInTipText).get()); + if (NS_SUCCEEDED(rv)) { mShowingTooltip = true; + } } return rv; +} -} // ShowTooltip - - -// -// HideTooltip -// // Tell the registered chrome that they should rollup the tooltip // NOTE: This routine is safe to call even if the popup is already closed. -// NS_IMETHODIMP ChromeTooltipListener::HideTooltip() { @@ -1376,37 +1332,33 @@ ChromeTooltipListener::HideTooltip() // if we're showing the tip, tell the chrome to hide it if (mShowingTooltip) { - nsCOMPtr tooltipListener(do_QueryInterface(mWebBrowserChrome)); + nsCOMPtr tooltipListener( + do_QueryInterface(mWebBrowserChrome)); if (tooltipListener) { rv = tooltipListener->OnHideTooltip(); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) { mShowingTooltip = false; + } } } return rv; +} -} // HideTooltip - - -// -// sTooltipCallback -// // A timer callback, fired when the mouse has hovered inside of a frame for the -// appropriate amount of time. Getting to this point means that we should show the -// tooltip, but only after we determine there is an appropriate TITLE element. +// appropriate amount of time. Getting to this point means that we should show +// the tooltip, but only after we determine there is an appropriate TITLE +// element. // -// This relies on certain things being cached into the |aChromeTooltipListener| object passed to -// us by the timer: +// This relies on certain things being cached into the |aChromeTooltipListener| +// object passed to us by the timer: // -- the x/y coordinates of the mouse (mMouseClientY, mMouseClientX) // -- the dom node the user hovered over (mPossibleTooltipNode) -// void -ChromeTooltipListener::sTooltipCallback(nsITimer *aTimer, - void *aChromeTooltipListener) +ChromeTooltipListener::sTooltipCallback(nsITimer* aTimer, + void* aChromeTooltipListener) { - ChromeTooltipListener* self = static_cast - (aChromeTooltipListener); + auto self = static_cast(aChromeTooltipListener); if (self && self->mPossibleTooltipNode) { // The actual coordinates we want to put the tooltip at are relative to the // toplevel docshell of our mWebBrowser. We know what the screen @@ -1447,65 +1399,52 @@ ChromeTooltipListener::sTooltipCallback(nsITimer *aTimer, bool textFound = false; self->mTooltipTextProvider->GetNodeText( - self->mPossibleTooltipNode, getter_Copies(tooltipText), &textFound); + self->mPossibleTooltipNode, getter_Copies(tooltipText), &textFound); if (textFound) { nsString tipText(tooltipText); LayoutDeviceIntPoint screenDot = widget->WidgetToScreenOffset(); double scaleFactor = 1.0; if (shell->GetPresContext()) { - scaleFactor = double(nsPresContext::AppUnitsPerCSSPixel())/ - shell->GetPresContext()->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom(); + nsDeviceContext* dc = shell->GetPresContext()->DeviceContext(); + scaleFactor = double(nsPresContext::AppUnitsPerCSSPixel()) / + dc->AppUnitsPerDevPixelAtUnitFullZoom(); } // ShowTooltip expects widget-relative position. self->ShowTooltip(self->mMouseScreenX - screenDot.x / scaleFactor, - self->mMouseScreenY - screenDot.y / scaleFactor, - tipText); + self->mMouseScreenY - screenDot.y / scaleFactor, + tipText); } } // release tooltip target if there is one, NO MATTER WHAT self->mPossibleTooltipNode = nullptr; - } // if "self" data valid - -} // sTooltipCallback - + } +} NS_IMPL_ISUPPORTS(ChromeContextMenuListener, nsIDOMEventListener) - -// -// ChromeTooltipListener ctor -// -ChromeContextMenuListener::ChromeContextMenuListener(nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome) - : mContextMenuListenerInstalled(false), - mWebBrowser(inBrowser), - mWebBrowserChrome(inChrome) +ChromeContextMenuListener::ChromeContextMenuListener( + nsWebBrowser* aInBrowser, + nsIWebBrowserChrome* aInChrome) + : mContextMenuListenerInstalled(false) + , mWebBrowser(aInBrowser) + , mWebBrowserChrome(aInChrome) { -} // ctor +} - -// -// ChromeTooltipListener dtor -// ChromeContextMenuListener::~ChromeContextMenuListener() { -} // dtor +} - -// -// AddContextMenuListener -// -// Subscribe to the events that will allow us to track context menus. Bascially, this -// is just the context-menu DOM event. -// +// Subscribe to the events that will allow us to track context menus. Bascially, +// this is just the context-menu DOM event. NS_IMETHODIMP ChromeContextMenuListener::AddContextMenuListener() { if (mEventTarget) { - nsresult rv = - mEventTarget->AddEventListener(NS_LITERAL_STRING("contextmenu"), this, - false, false); + nsresult rv = mEventTarget->AddEventListener( + NS_LITERAL_STRING("contextmenu"), this, false, false); NS_ENSURE_SUCCESS(rv, rv); mContextMenuListenerInstalled = true; @@ -1514,19 +1453,14 @@ ChromeContextMenuListener::AddContextMenuListener() return NS_OK; } - -// -// RemoveContextMenuListener -// -// Unsubscribe from all the various context menu events that we were listening to. -// +// Unsubscribe from all the various context menu events that we were listening +// to. NS_IMETHODIMP ChromeContextMenuListener::RemoveContextMenuListener() { if (mEventTarget) { - nsresult rv = - mEventTarget->RemoveEventListener(NS_LITERAL_STRING("contextmenu"), this, - false); + nsresult rv = mEventTarget->RemoveEventListener( + NS_LITERAL_STRING("contextmenu"), this, false); NS_ENSURE_SUCCESS(rv, rv); mContextMenuListenerInstalled = false; @@ -1535,60 +1469,46 @@ ChromeContextMenuListener::RemoveContextMenuListener() return NS_OK; } - -// -// AddChromeListeners -// // Hook up things to the chrome like context menus and tooltips, if the chrome // has implemented the right interfaces. -// NS_IMETHODIMP ChromeContextMenuListener::AddChromeListeners() { - if (!mEventTarget) + if (!mEventTarget) { GetDOMEventTarget(mWebBrowser, getter_AddRefs(mEventTarget)); + } // Register the appropriate events for context menus, but only if // the embedding chrome cares. nsresult rv = NS_OK; - nsCOMPtr contextListener2(do_QueryInterface(mWebBrowserChrome)); - nsCOMPtr contextListener(do_QueryInterface(mWebBrowserChrome)); - if ((contextListener || contextListener2) && !mContextMenuListenerInstalled) + nsCOMPtr contextListener2( + do_QueryInterface(mWebBrowserChrome)); + nsCOMPtr contextListener( + do_QueryInterface(mWebBrowserChrome)); + if ((contextListener || contextListener2) && !mContextMenuListenerInstalled) { rv = AddContextMenuListener(); + } return rv; +} -} // AddChromeListeners - - -// -// RemoveChromeListeners -// // Unsubscribe from the various things we've hooked up to the window root. -// NS_IMETHODIMP ChromeContextMenuListener::RemoveChromeListeners() { - if (mContextMenuListenerInstalled) + if (mContextMenuListenerInstalled) { RemoveContextMenuListener(); + } mEventTarget = nullptr; // it really doesn't matter if these fail... return NS_OK; +} -} // RemoveChromeTooltipListeners - - - -// -// ContextMenu -// -// We're on call to show the context menu. Dig around in the DOM to -// find the type of object we're dealing with and notify the front -// end chrome. -// +// We're on call to show the context menu. Dig around in the DOM to find the +// type of object we're dealing with and notify the front end chrome. NS_IMETHODIMP ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) { @@ -1601,21 +1521,25 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) return NS_OK; } - nsCOMPtr targetNode = aMouseEvent->InternalDOMEvent()->GetTarget(); - if (!targetNode) + nsCOMPtr targetNode = + aMouseEvent->InternalDOMEvent()->GetTarget(); + if (!targetNode) { return NS_ERROR_NULL_POINTER; + } nsCOMPtr targetDOMnode; nsCOMPtr node = do_QueryInterface(targetNode); - if (!node) + if (!node) { return NS_OK; + } // Stop the context menu event going to other windows (bug 78396) aMouseEvent->PreventDefault(); // If the listener is a nsIContextMenuListener2, create the info object - nsCOMPtr menuListener2(do_QueryInterface(mWebBrowserChrome)); - nsContextMenuInfo *menuInfoImpl = nullptr; + nsCOMPtr menuListener2( + do_QueryInterface(mWebBrowserChrome)); + nsContextMenuInfo* menuInfoImpl = nullptr; nsCOMPtr menuInfo; if (menuListener2) { menuInfoImpl = new nsContextMenuInfo; @@ -1651,7 +1575,8 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) flags2 |= nsIContextMenuListener2::CONTEXT_TEXT; targetDOMnode = node; } else { - nsCOMPtr inputElement(do_QueryInterface(formControl)); + nsCOMPtr inputElement( + do_QueryInterface(formControl)); if (inputElement) { flags |= nsIContextMenuListener::CONTEXT_INPUT; flags2 |= nsIContextMenuListener2::CONTEXT_INPUT; @@ -1671,13 +1596,15 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) // own context menus but not for image objects. Document objects // will never be targets or ancestors of targets, so that's OK. nsCOMPtr objectElement; - if (!(flags & nsIContextMenuListener::CONTEXT_IMAGE)) + if (!(flags & nsIContextMenuListener::CONTEXT_IMAGE)) { objectElement = do_QueryInterface(node); + } nsCOMPtr embedElement(do_QueryInterface(node)); nsCOMPtr appletElement(do_QueryInterface(node)); - if (objectElement || embedElement || appletElement) + if (objectElement || embedElement || appletElement) { return NS_OK; + } } // Bubble out, looking for items of interest @@ -1694,14 +1621,15 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) bool hasAttr = false; res = element->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (NS_SUCCEEDED(res) && hasAttr) - { + if (NS_SUCCEEDED(res) && hasAttr) { flags |= nsIContextMenuListener::CONTEXT_LINK; flags2 |= nsIContextMenuListener2::CONTEXT_LINK; - if (!targetDOMnode) + if (!targetDOMnode) { targetDOMnode = node; - if (menuInfoImpl) + } + if (menuInfoImpl) { menuInfoImpl->SetAssociatedLink(node); + } break; // exit do-while } } @@ -1724,8 +1652,9 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) flags2 |= nsIContextMenuListener2::CONTEXT_DOCUMENT; targetDOMnode = node; if (!(flags & nsIContextMenuListener::CONTEXT_IMAGE)) { - // check if this is a background image that the user was trying to click on - // and if the listener is ready for that (only nsIContextMenuListener2 and up) + // check if this is a background image that the user was trying to click + // on and if the listener is ready for that (only + // nsIContextMenuListener2 and up) if (menuInfoImpl && menuInfoImpl->HasBackgroundImage(targetDOMnode)) { flags2 |= nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE; // For the embedder to get the correct background image @@ -1760,11 +1689,12 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) menuInfoImpl->SetDOMNode(targetDOMnode); menuListener2->OnShowContextMenu(flags2, menuInfo); } else { - nsCOMPtr menuListener(do_QueryInterface(mWebBrowserChrome)); - if (menuListener) + nsCOMPtr menuListener( + do_QueryInterface(mWebBrowserChrome)); + if (menuListener) { menuListener->OnShowContextMenu(flags, aMouseEvent, targetDOMnode); + } } return NS_OK; - -} // MouseDown +} diff --git a/embedding/browser/nsDocShellTreeOwner.h b/embedding/browser/nsDocShellTreeOwner.h index fc87bd8e92d..2e060e80056 100644 --- a/embedding/browser/nsDocShellTreeOwner.h +++ b/embedding/browser/nsDocShellTreeOwner.h @@ -43,22 +43,19 @@ class ChromeContextMenuListener; // {6D10C180-6888-11d4-952B-0020183BF181} #define NS_ICDOCSHELLTREEOWNER_IID \ -{ 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } } + { 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } } -/* - * This is a fake 'hidden' interface that nsDocShellTreeOwner implements. - * Classes such as nsCommandHandler can QI for this interface to be - * sure that they're dealing with a valid nsDocShellTreeOwner and not some - * other object that implements nsIDocShellTreeOwner. - */ +// This is a fake 'hidden' interface that nsDocShellTreeOwner implements. +// Classes such as nsCommandHandler can QI for this interface to be sure that +// they're dealing with a valid nsDocShellTreeOwner and not some other object +// that implements nsIDocShellTreeOwner. class nsICDocShellTreeOwner : public nsISupports { public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID) + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID) }; -NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner, - NS_ICDOCSHELLTREEOWNER_IID) +NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner, NS_ICDOCSHELLTREEOWNER_IID) class nsDocShellTreeOwner final : public nsIDocShellTreeOwner, public nsIBaseWindow, @@ -68,83 +65,77 @@ class nsDocShellTreeOwner final : public nsIDocShellTreeOwner, public nsICDocShellTreeOwner, public nsSupportsWeakReference { -friend class nsWebBrowser; -friend class nsCommandHandler; + friend class nsWebBrowser; + friend class nsCommandHandler; public: - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS - NS_DECL_NSIBASEWINDOW - NS_DECL_NSIDOCSHELLTREEOWNER - NS_DECL_NSIDOMEVENTLISTENER - NS_DECL_NSIINTERFACEREQUESTOR - NS_DECL_NSIWEBPROGRESSLISTENER + NS_DECL_NSIBASEWINDOW + NS_DECL_NSIDOCSHELLTREEOWNER + NS_DECL_NSIDOMEVENTLISTENER + NS_DECL_NSIINTERFACEREQUESTOR + NS_DECL_NSIWEBPROGRESSLISTENER protected: - nsDocShellTreeOwner(); - virtual ~nsDocShellTreeOwner(); + nsDocShellTreeOwner(); + virtual ~nsDocShellTreeOwner(); - void WebBrowser(nsWebBrowser* aWebBrowser); + void WebBrowser(nsWebBrowser* aWebBrowser); - nsWebBrowser* WebBrowser(); - NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner); - NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome); + nsWebBrowser* WebBrowser(); + NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner); + NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome); - NS_IMETHOD AddChromeListeners(); - NS_IMETHOD RemoveChromeListeners(); + NS_IMETHOD AddChromeListeners(); + NS_IMETHOD RemoveChromeListeners(); - nsresult FindItemWithNameAcrossWindows(const char16_t* aName, - nsIDocShellTreeItem* aRequestor, - nsIDocShellTreeItem* aOriginalRequestor, - nsIDocShellTreeItem **aFoundItem); + nsresult FindItemWithNameAcrossWindows( + const char16_t* aName, + nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem* aOriginalRequestor, + nsIDocShellTreeItem** aFoundItem); - void EnsurePrompter(); - void EnsureAuthPrompter(); + void EnsurePrompter(); + void EnsureAuthPrompter(); - void AddToWatcher(); - void RemoveFromWatcher(); + void AddToWatcher(); + void RemoveFromWatcher(); - // These helper functions return the correct instances of the requested - // interfaces. If the object passed to SetWebBrowserChrome() implements - // nsISupportsWeakReference, then these functions call QueryReferent on - // that object. Otherwise, they return an addrefed pointer. If the - // WebBrowserChrome object doesn't exist, they return nullptr. - already_AddRefed GetWebBrowserChrome(); - already_AddRefed GetOwnerWin(); - already_AddRefed GetOwnerRequestor(); + // These helper functions return the correct instances of the requested + // interfaces. If the object passed to SetWebBrowserChrome() implements + // nsISupportsWeakReference, then these functions call QueryReferent on + // that object. Otherwise, they return an addrefed pointer. If the + // WebBrowserChrome object doesn't exist, they return nullptr. + already_AddRefed GetWebBrowserChrome(); + already_AddRefed GetOwnerWin(); + already_AddRefed GetOwnerRequestor(); protected: + // Weak References + nsWebBrowser* mWebBrowser; + nsIDocShellTreeOwner* mTreeOwner; + nsIDocShellTreeItem* mPrimaryContentShell; - // Weak References - nsWebBrowser* mWebBrowser; - nsIDocShellTreeOwner* mTreeOwner; - nsIDocShellTreeItem* mPrimaryContentShell; + nsIWebBrowserChrome* mWebBrowserChrome; + nsIEmbeddingSiteWindow* mOwnerWin; + nsIInterfaceRequestor* mOwnerRequestor; - nsIWebBrowserChrome* mWebBrowserChrome; - nsIEmbeddingSiteWindow* mOwnerWin; - nsIInterfaceRequestor* mOwnerRequestor; + nsWeakPtr mWebBrowserChromeWeak; // nsIWebBrowserChrome - nsWeakPtr mWebBrowserChromeWeak; // nsIWebBrowserChrome + // the objects that listen for chrome events like context menus and tooltips. + // They are separate objects to avoid circular references between |this| + // and the DOM. + nsRefPtr mChromeTooltipListener; + nsRefPtr mChromeContextMenuListener; - // the objects that listen for chrome events like context menus and tooltips. - // They are separate objects to avoid circular references between |this| - // and the DOM. - nsRefPtr mChromeTooltipListener; - nsRefPtr mChromeContextMenuListener; - - nsCOMPtr mPrompter; - nsCOMPtr mAuthPrompter; + nsCOMPtr mPrompter; + nsCOMPtr mAuthPrompter; }; -// -// class ChromeTooltipListener -// -// The class that listens to the chrome events and tells the embedding -// chrome to show tooltips, as appropriate. Handles registering itself -// with the DOM with AddChromeListeners() and removing itself with -// RemoveChromeListeners(). -// +// The class that listens to the chrome events and tells the embedding chrome to +// show tooltips, as appropriate. Handles registering itself with the DOM with +// AddChromeListeners() and removing itself with RemoveChromeListeners(). class ChromeTooltipListener final : public nsIDOMEventListener { protected: @@ -153,69 +144,70 @@ protected: public: NS_DECL_ISUPPORTS - ChromeTooltipListener(nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome); + ChromeTooltipListener(nsWebBrowser* aInBrowser, nsIWebBrowserChrome* aInChrome); NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override; NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent); - // Add/remove the relevant listeners, based on what interfaces - // the embedding chrome implements. + // Add/remove the relevant listeners, based on what interfaces the embedding + // chrome implements. NS_IMETHOD AddChromeListeners(); NS_IMETHOD RemoveChromeListeners(); private: - - // various delays for tooltips - enum { - kTooltipAutoHideTime = 5000, // 5000ms = 5 seconds - kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event + // various delays for tooltips + enum + { + kTooltipAutoHideTime = 5000, // ms + kTooltipMouseMoveTolerance = 7 // pixel tolerance for mousemove event }; NS_IMETHOD AddTooltipListener(); NS_IMETHOD RemoveTooltipListener(); - NS_IMETHOD ShowTooltip(int32_t inXCoords, int32_t inYCoords, const nsAString & inTipText); + NS_IMETHOD ShowTooltip(int32_t aInXCoords, int32_t aInYCoords, + const nsAString& aInTipText); NS_IMETHOD HideTooltip(); nsWebBrowser* mWebBrowser; nsCOMPtr mEventTarget; nsCOMPtr mTooltipTextProvider; - // This must be a strong ref in order to make sure we can hide the tooltip - // if the window goes away while we're displaying one. If we don't hold - // a strong ref, the chrome might have been disposed of before we get a chance - // to tell it, and no one would ever tell us of that fact. + // This must be a strong ref in order to make sure we can hide the tooltip if + // the window goes away while we're displaying one. If we don't hold a strong + // ref, the chrome might have been disposed of before we get a chance to tell + // it, and no one would ever tell us of that fact. nsCOMPtr mWebBrowserChrome; bool mTooltipListenerInstalled; nsCOMPtr mTooltipTimer; static void sTooltipCallback(nsITimer* aTimer, void* aListener); - int32_t mMouseClientX, mMouseClientY; // mouse coordinates for last mousemove event we saw - int32_t mMouseScreenX, mMouseScreenY; // mouse coordinates for tooltip event + + // Mouse coordinates for last mousemove event we saw + int32_t mMouseClientX; + int32_t mMouseClientY; + + // Mouse coordinates for tooltip event + int32_t mMouseScreenX; + int32_t mMouseScreenY; + bool mShowingTooltip; bool mTooltipShownOnce; - // The node hovered over that fired the timer. This may turn into the node that - // triggered the tooltip, but only if the timer ever gets around to firing. - // This is a strong reference, because the tooltip content can be destroyed while we're - // waiting for the tooltip to pup up, and we need to detect that. - // It's set only when the tooltip timer is created and launched. The timer must - // either fire or be cancelled (or possibly released?), and we release this - // reference in each of those cases. So we don't leak. + // The node hovered over that fired the timer. This may turn into the node + // that triggered the tooltip, but only if the timer ever gets around to + // firing. This is a strong reference, because the tooltip content can be + // destroyed while we're waiting for the tooltip to pup up, and we need to + // detect that. It's set only when the tooltip timer is created and launched. + // The timer must either fire or be cancelled (or possibly released?), and we + // release this reference in each of those cases. So we don't leak. nsCOMPtr mPossibleTooltipNode; +}; -}; // ChromeTooltipListener - - -// -// class ChromeContextMenuListener -// -// The class that listens to the chrome events and tells the embedding -// chrome to show context menus, as appropriate. Handles registering itself -// with the DOM with AddChromeListeners() and removing itself with -// RemoveChromeListeners(). -// +// The class that listens to the chrome events and tells the embedding chrome to +// show context menus, as appropriate. Handles registering itself with the DOM +// with AddChromeListeners() and removing itself with RemoveChromeListeners(). class ChromeContextMenuListener : public nsIDOMEventListener { protected: @@ -224,7 +216,8 @@ protected: public: NS_DECL_ISUPPORTS - ChromeContextMenuListener(nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome); + ChromeContextMenuListener(nsWebBrowser* aInBrowser, + nsIWebBrowserChrome* aInChrome); // nsIDOMContextMenuListener NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override; @@ -235,7 +228,6 @@ public: NS_IMETHOD RemoveChromeListeners(); private: - NS_IMETHOD AddContextMenuListener(); NS_IMETHOD RemoveContextMenuListener(); @@ -244,9 +236,6 @@ private: nsWebBrowser* mWebBrowser; nsCOMPtr mEventTarget; nsCOMPtr mWebBrowserChrome; - -}; // class ChromeContextMenuListener - - +}; #endif /* nsDocShellTreeOwner_h__ */ diff --git a/embedding/browser/nsEmbedStream.cpp b/embedding/browser/nsEmbedStream.cpp index df44a0d4b6b..78ebd18f19f 100644 --- a/embedding/browser/nsEmbedStream.cpp +++ b/embedding/browser/nsEmbedStream.cpp @@ -25,7 +25,7 @@ nsEmbedStream::~nsEmbedStream() } void -nsEmbedStream::InitOwner(nsIWebBrowser *aOwner) +nsEmbedStream::InitOwner(nsIWebBrowser* aOwner) { mOwner = aOwner; } @@ -37,36 +37,38 @@ nsEmbedStream::Init(void) } NS_METHOD -nsEmbedStream::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType) +nsEmbedStream::OpenStream(nsIURI* aBaseURI, const nsACString& aContentType) { nsresult rv; NS_ENSURE_ARG_POINTER(aBaseURI); NS_ENSURE_TRUE(IsASCII(aContentType), NS_ERROR_INVALID_ARG); // if we're already doing a stream, return an error - if (mOutputStream) + if (mOutputStream) { return NS_ERROR_IN_PROGRESS; + } nsCOMPtr inputStream; nsCOMPtr outputStream; - rv = NS_NewPipe2(getter_AddRefs(inputStream), - getter_AddRefs(outputStream), + rv = NS_NewPipe2(getter_AddRefs(inputStream), getter_AddRefs(outputStream), true, false, 0, UINT32_MAX); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { return rv; + } nsCOMPtr docShell = do_GetInterface(mOwner); rv = docShell->LoadStream(inputStream, aBaseURI, aContentType, EmptyCString(), nullptr); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { return rv; + } mOutputStream = outputStream; return rv; } NS_METHOD -nsEmbedStream::AppendToStream(const uint8_t *aData, uint32_t aLen) +nsEmbedStream::AppendToStream(const uint8_t* aData, uint32_t aLen) { nsresult rv; NS_ENSURE_STATE(mOutputStream); @@ -74,8 +76,9 @@ nsEmbedStream::AppendToStream(const uint8_t *aData, uint32_t aLen) uint32_t bytesWritten = 0; rv = mOutputStream->Write(reinterpret_cast(aData), aLen, &bytesWritten); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { return rv; + } NS_ASSERTION(bytesWritten == aLen, "underlying buffer couldn't handle the write"); diff --git a/embedding/browser/nsEmbedStream.h b/embedding/browser/nsEmbedStream.h index 29183617830..1ecac1f00be 100644 --- a/embedding/browser/nsEmbedStream.h +++ b/embedding/browser/nsEmbedStream.h @@ -13,24 +13,23 @@ class nsEmbedStream : public nsISupports { - public: - +public: nsEmbedStream(); - void InitOwner (nsIWebBrowser *aOwner); - NS_METHOD Init (void); + void InitOwner(nsIWebBrowser* aOwner); + NS_METHOD Init(void); - NS_METHOD OpenStream (nsIURI *aBaseURI, const nsACString& aContentType); - NS_METHOD AppendToStream (const uint8_t *aData, uint32_t aLen); - NS_METHOD CloseStream (void); + NS_METHOD OpenStream(nsIURI* aBaseURI, const nsACString& aContentType); + NS_METHOD AppendToStream(const uint8_t* aData, uint32_t aLen); + NS_METHOD CloseStream(void); NS_DECL_ISUPPORTS - protected: +protected: virtual ~nsEmbedStream(); - private: - nsIWebBrowser *mOwner; +private: + nsIWebBrowser* mOwner; nsCOMPtr mOutputStream; }; diff --git a/embedding/browser/nsWebBrowser.cpp b/embedding/browser/nsWebBrowser.cpp index 769c481f543..33ed9fdd988 100644 --- a/embedding/browser/nsWebBrowser.cpp +++ b/embedding/browser/nsWebBrowser.cpp @@ -14,7 +14,7 @@ #include "gfxUtils.h" #include "mozilla/gfx/2D.h" -//Interfaces Needed +// Interfaces Needed #include "nsReadableUtils.h" #include "nsIComponentManager.h" #include "nsIDOMDocument.h" @@ -60,24 +60,19 @@ using namespace mozilla::layers; static NS_DEFINE_CID(kChildCID, NS_CHILD_CID); - -//***************************************************************************** -//*** nsWebBrowser: Object Management -//***************************************************************************** - -nsWebBrowser::nsWebBrowser() : - mInitInfo(new nsWebBrowserInitInfo()), - mContentType(typeContentWrapper), - mActivating(false), - mShouldEnableHistory(true), - mIsActive(true), - mParentNativeWindow(nullptr), - mProgressListener(nullptr), - mBackgroundColor(0), - mPersistCurrentState(nsIWebBrowserPersist::PERSIST_STATE_READY), - mPersistResult(NS_OK), - mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE), - mParentWidget(nullptr) +nsWebBrowser::nsWebBrowser() + : mInitInfo(new nsWebBrowserInitInfo()) + , mContentType(typeContentWrapper) + , mActivating(false) + , mShouldEnableHistory(true) + , mIsActive(true) + , mParentNativeWindow(nullptr) + , mProgressListener(nullptr) + , mBackgroundColor(0) + , mPersistCurrentState(nsIWebBrowserPersist::PERSIST_STATE_READY) + , mPersistResult(NS_OK) + , mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE) + , mParentWidget(nullptr) { mWWatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID); NS_ASSERTION(mWWatch, "failed to get WindowWatcher"); @@ -88,7 +83,8 @@ nsWebBrowser::~nsWebBrowser() InternalDestroy(); } -NS_IMETHODIMP nsWebBrowser::InternalDestroy() +NS_IMETHODIMP +nsWebBrowser::InternalDestroy() { if (mInternalWidget) { mInternalWidget->SetWidgetListener(nullptr); @@ -110,11 +106,6 @@ NS_IMETHODIMP nsWebBrowser::InternalDestroy() return NS_OK; } - -//***************************************************************************** -// nsWebBrowser::nsISupports -//***************************************************************************** - NS_IMPL_ADDREF(nsWebBrowser) NS_IMPL_RELEASE(nsWebBrowser) @@ -140,7 +131,8 @@ NS_INTERFACE_MAP_END // nsWebBrowser::nsIInterfaceRequestor //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink) +NS_IMETHODIMP +nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink) { NS_ENSURE_ARG_POINTER(aSink); @@ -177,7 +169,9 @@ NS_IMETHODIMP nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink) // listeners that currently support registration through AddWebBrowserListener: // - nsIWebProgressListener -NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID) +NS_IMETHODIMP +nsWebBrowser::AddWebBrowserListener(nsIWeakReference* aListener, + const nsIID& aIID) { NS_ENSURE_ARG_POINTER(aListener); @@ -194,43 +188,59 @@ NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener(nsIWeakReference *aListener, c state->mID = aIID; } else { nsCOMPtr supports(do_QueryReferent(aListener)); - if (!supports) return NS_ERROR_INVALID_ARG; + if (!supports) { + return NS_ERROR_INVALID_ARG; + } rv = BindListener(supports, aIID); } return rv; } -NS_IMETHODIMP nsWebBrowser::BindListener(nsISupports *aListener, const nsIID& aIID) { +NS_IMETHODIMP +nsWebBrowser::BindListener(nsISupports* aListener, const nsIID& aIID) +{ NS_ENSURE_ARG_POINTER(aListener); - NS_ASSERTION(mWebProgress, "this should only be called after we've retrieved a progress iface"); + NS_ASSERTION(mWebProgress, + "this should only be called after we've retrieved a progress iface"); nsresult rv = NS_OK; // register this listener for the specified interface id if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) { nsCOMPtr listener = do_QueryInterface(aListener, &rv); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } NS_ENSURE_STATE(mWebProgress); rv = mWebProgress->AddProgressListener(listener, nsIWebProgress::NOTIFY_ALL); } else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { nsCOMPtr shistory(do_GetInterface(mDocShell, &rv)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } nsCOMPtr listener(do_QueryInterface(aListener, &rv)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } rv = shistory->AddSHistoryListener(listener); } return rv; } -NS_IMETHODIMP nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID) +NS_IMETHODIMP +nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference* aListener, + const nsIID& aIID) { NS_ENSURE_ARG_POINTER(aListener); nsresult rv = NS_OK; if (!mWebProgress) { - // if there's no-one to register the listener w/, and we don't have a queue going, - // the the called is calling Remove before an Add which doesn't make sense. - if (!mListenerArray) return NS_ERROR_FAILURE; + // if there's no-one to register the listener w/, and we don't have a queue + // going, the the called is calling Remove before an Add which doesn't make + // sense. + if (!mListenerArray) { + return NS_ERROR_FAILURE; + } // iterate the array and remove the queued listener int32_t count = mListenerArray->Length(); @@ -249,42 +259,55 @@ NS_IMETHODIMP nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference *aListener } else { nsCOMPtr supports(do_QueryReferent(aListener)); - if (!supports) return NS_ERROR_INVALID_ARG; + if (!supports) { + return NS_ERROR_INVALID_ARG; + } rv = UnBindListener(supports, aIID); } return rv; } -NS_IMETHODIMP nsWebBrowser::UnBindListener(nsISupports *aListener, const nsIID& aIID) { +NS_IMETHODIMP +nsWebBrowser::UnBindListener(nsISupports* aListener, const nsIID& aIID) +{ NS_ENSURE_ARG_POINTER(aListener); - NS_ASSERTION(mWebProgress, "this should only be called after we've retrieved a progress iface"); + NS_ASSERTION(mWebProgress, + "this should only be called after we've retrieved a progress iface"); nsresult rv = NS_OK; // remove the listener for the specified interface id if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) { nsCOMPtr listener = do_QueryInterface(aListener, &rv); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } NS_ENSURE_STATE(mWebProgress); rv = mWebProgress->RemoveProgressListener(listener); } else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { nsCOMPtr shistory(do_GetInterface(mDocShell, &rv)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } nsCOMPtr listener(do_QueryInterface(aListener, &rv)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } rv = shistory->RemoveSHistoryListener(listener); } return rv; } -NS_IMETHODIMP nsWebBrowser::EnableGlobalHistory(bool aEnable) +NS_IMETHODIMP +nsWebBrowser::EnableGlobalHistory(bool aEnable) { NS_ENSURE_STATE(mDocShell); return mDocShell->SetUseGlobalHistory(aEnable); } -NS_IMETHODIMP nsWebBrowser::GetContainerWindow(nsIWebBrowserChrome** aTopWindow) +NS_IMETHODIMP +nsWebBrowser::GetContainerWindow(nsIWebBrowserChrome** aTopWindow) { NS_ENSURE_ARG_POINTER(aTopWindow); @@ -298,13 +321,16 @@ NS_IMETHODIMP nsWebBrowser::GetContainerWindow(nsIWebBrowserChrome** aTopWindow) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetContainerWindow(nsIWebBrowserChrome* aTopWindow) +NS_IMETHODIMP +nsWebBrowser::SetContainerWindow(nsIWebBrowserChrome* aTopWindow) { NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); return mDocShellTreeOwner->SetWebBrowserChrome(aTopWindow); } -NS_IMETHODIMP nsWebBrowser::GetParentURIContentListener(nsIURIContentListener** aParentContentListener) +NS_IMETHODIMP +nsWebBrowser::GetParentURIContentListener( + nsIURIContentListener** aParentContentListener) { NS_ENSURE_ARG_POINTER(aParentContentListener); *aParentContentListener = nullptr; @@ -312,43 +338,51 @@ NS_IMETHODIMP nsWebBrowser::GetParentURIContentListener(nsIURIContentListener** // get the interface from the docshell nsCOMPtr listener(do_GetInterface(mDocShell)); - if (listener) + if (listener) { return listener->GetParentContentListener(aParentContentListener); + } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetParentURIContentListener(nsIURIContentListener* aParentContentListener) +NS_IMETHODIMP +nsWebBrowser::SetParentURIContentListener( + nsIURIContentListener* aParentContentListener) { // get the interface from the docshell nsCOMPtr listener(do_GetInterface(mDocShell)); - if (listener) + if (listener) { return listener->SetParentContentListener(aParentContentListener); + } return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsWebBrowser::GetContentDOMWindow(nsIDOMWindow **_retval) +NS_IMETHODIMP +nsWebBrowser::GetContentDOMWindow(nsIDOMWindow** aResult) { NS_ENSURE_STATE(mDocShell); nsCOMPtr retval = mDocShell->GetWindow(); - retval.forget(_retval); - return *_retval ? NS_OK : NS_ERROR_FAILURE; + retval.forget(aResult); + return *aResult ? NS_OK : NS_ERROR_FAILURE; } -NS_IMETHODIMP nsWebBrowser::GetIsActive(bool *rv) +NS_IMETHODIMP +nsWebBrowser::GetIsActive(bool* aResult) { - *rv = mIsActive; + *aResult = mIsActive; return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetIsActive(bool aIsActive) +NS_IMETHODIMP +nsWebBrowser::SetIsActive(bool aIsActive) { // Set our copy of the value mIsActive = aIsActive; // If we have a docshell, pass on the request - if (mDocShell) + if (mDocShell) { return mDocShell->SetIsActive(aIsActive); + } return NS_OK; } @@ -356,17 +390,20 @@ NS_IMETHODIMP nsWebBrowser::SetIsActive(bool aIsActive) // nsWebBrowser::nsIDocShellTreeItem //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::GetName(nsAString& aName) +NS_IMETHODIMP +nsWebBrowser::GetName(nsAString& aName) { - if (mDocShell) + if (mDocShell) { mDocShell->GetName(aName); - else + } else { aName = mInitInfo->name; + } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetName(const nsAString& aName) +NS_IMETHODIMP +nsWebBrowser::SetName(const nsAString& aName) { if (mDocShell) { return mDocShell->SetName(aName); @@ -377,14 +414,15 @@ NS_IMETHODIMP nsWebBrowser::SetName(const nsAString& aName) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::NameEquals(const char16_t *aName, bool *_retval) +NS_IMETHODIMP +nsWebBrowser::NameEquals(const char16_t* aName, bool* aResult) { NS_ENSURE_ARG_POINTER(aName); - NS_ENSURE_ARG_POINTER(_retval); + NS_ENSURE_ARG_POINTER(aResult); if (mDocShell) { - return mDocShell->NameEquals(aName, _retval); + return mDocShell->NameEquals(aName, aResult); } else { - *_retval = mInitInfo->name.Equals(aName); + *aResult = mInitInfo->name.Equals(aName); } return NS_OK; @@ -396,7 +434,8 @@ nsWebBrowser::ItemType() return mContentType; } -NS_IMETHODIMP nsWebBrowser::GetItemType(int32_t* aItemType) +NS_IMETHODIMP +nsWebBrowser::GetItemType(int32_t* aItemType) { NS_ENSURE_ARG_POINTER(aItemType); @@ -404,55 +443,64 @@ NS_IMETHODIMP nsWebBrowser::GetItemType(int32_t* aItemType) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetItemType(int32_t aItemType) +NS_IMETHODIMP +nsWebBrowser::SetItemType(int32_t aItemType) { - NS_ENSURE_TRUE((aItemType == typeContentWrapper || aItemType == typeChromeWrapper), NS_ERROR_FAILURE); + NS_ENSURE_TRUE( + aItemType == typeContentWrapper || aItemType == typeChromeWrapper, + NS_ERROR_FAILURE); mContentType = aItemType; if (mDocShell) { - mDocShell->SetItemType(mContentType == typeChromeWrapper - ? static_cast(typeChrome) - : static_cast(typeContent)); + mDocShell->SetItemType(mContentType == typeChromeWrapper ? + static_cast(typeChrome) : + static_cast(typeContent)); } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetParent(nsIDocShellTreeItem** aParent) +NS_IMETHODIMP +nsWebBrowser::GetParent(nsIDocShellTreeItem** aParent) { *aParent = nullptr; return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetSameTypeParent(nsIDocShellTreeItem** aParent) +NS_IMETHODIMP +nsWebBrowser::GetSameTypeParent(nsIDocShellTreeItem** aParent) { *aParent = nullptr; return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) +NS_IMETHODIMP +nsWebBrowser::GetRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) { NS_ENSURE_ARG_POINTER(aRootTreeItem); *aRootTreeItem = static_cast(this); nsCOMPtr parent; NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); - while(parent) { + while (parent) { *aRootTreeItem = parent; - NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)), + NS_ERROR_FAILURE); } NS_ADDREF(*aRootTreeItem); return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetSameTypeRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) +NS_IMETHODIMP +nsWebBrowser::GetSameTypeRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) { NS_ENSURE_ARG_POINTER(aRootTreeItem); *aRootTreeItem = static_cast(this); nsCOMPtr parent; - NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); - while(parent) { + NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)), + NS_ERROR_FAILURE); + while (parent) { *aRootTreeItem = parent; NS_ENSURE_SUCCESS((*aRootTreeItem)->GetSameTypeParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); @@ -461,17 +509,19 @@ NS_IMETHODIMP nsWebBrowser::GetSameTypeRootTreeItem(nsIDocShellTreeItem** aRootT return NS_OK; } -NS_IMETHODIMP nsWebBrowser::FindItemWithName(const char16_t *aName, - nsISupports* aRequestor, - nsIDocShellTreeItem* aOriginalRequestor, - nsIDocShellTreeItem **_retval) +NS_IMETHODIMP +nsWebBrowser::FindItemWithName(const char16_t* aName, + nsISupports* aRequestor, + nsIDocShellTreeItem* aOriginalRequestor, + nsIDocShellTreeItem** aResult) { NS_ENSURE_STATE(mDocShell); - NS_ASSERTION(mDocShellTreeOwner, "This should always be set when in this situation"); + NS_ASSERTION(mDocShellTreeOwner, + "This should always be set when in this situation"); - return mDocShell->FindItemWithName(aName, - static_cast(mDocShellTreeOwner), - aOriginalRequestor, _retval); + return mDocShell->FindItemWithName( + aName, static_cast(mDocShellTreeOwner), + aOriginalRequestor, aResult); } nsIDocument* @@ -486,7 +536,8 @@ nsWebBrowser::GetWindow() return mDocShell ? mDocShell->GetWindow() : nullptr; } -NS_IMETHODIMP nsWebBrowser::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner) +NS_IMETHODIMP +nsWebBrowser::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner) { NS_ENSURE_ARG_POINTER(aTreeOwner); *aTreeOwner = nullptr; @@ -501,7 +552,8 @@ NS_IMETHODIMP nsWebBrowser::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) +NS_IMETHODIMP +nsWebBrowser::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) { NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); return mDocShellTreeOwner->SetTreeOwner(aTreeOwner); @@ -511,38 +563,43 @@ NS_IMETHODIMP nsWebBrowser::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) // nsWebBrowser::nsIDocShellTreeItem //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::GetChildCount(int32_t * aChildCount) +NS_IMETHODIMP +nsWebBrowser::GetChildCount(int32_t* aChildCount) { NS_ENSURE_ARG_POINTER(aChildCount); *aChildCount = 0; return NS_OK; } -NS_IMETHODIMP nsWebBrowser::AddChild(nsIDocShellTreeItem * aChild) +NS_IMETHODIMP +nsWebBrowser::AddChild(nsIDocShellTreeItem* aChild) { return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP nsWebBrowser::RemoveChild(nsIDocShellTreeItem * aChild) +NS_IMETHODIMP +nsWebBrowser::RemoveChild(nsIDocShellTreeItem* aChild) { return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP nsWebBrowser::GetChildAt(int32_t aIndex, - nsIDocShellTreeItem ** aChild) +NS_IMETHODIMP +nsWebBrowser::GetChildAt(int32_t aIndex, nsIDocShellTreeItem** aChild) { return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP nsWebBrowser::FindChildWithName(const char16_t * aName, - bool aRecurse, bool aSameType, - nsIDocShellTreeItem * aRequestor, - nsIDocShellTreeItem * aOriginalRequestor, - nsIDocShellTreeItem ** _retval) +NS_IMETHODIMP +nsWebBrowser::FindChildWithName(const char16_t* aName, + bool aRecurse, + bool aSameType, + nsIDocShellTreeItem* aRequestor, + nsIDocShellTreeItem* aOriginalRequestor, + nsIDocShellTreeItem** aResult) { - NS_ENSURE_ARG_POINTER(_retval); + NS_ENSURE_ARG_POINTER(aResult); - *_retval = nullptr; + *aResult = nullptr; return NS_OK; } @@ -550,147 +607,151 @@ NS_IMETHODIMP nsWebBrowser::FindChildWithName(const char16_t * aName, // nsWebBrowser::nsIWebNavigation //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::GetCanGoBack(bool* aCanGoBack) +NS_IMETHODIMP +nsWebBrowser::GetCanGoBack(bool* aCanGoBack) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GetCanGoBack(aCanGoBack); } -NS_IMETHODIMP nsWebBrowser::GetCanGoForward(bool* aCanGoForward) +NS_IMETHODIMP +nsWebBrowser::GetCanGoForward(bool* aCanGoForward) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GetCanGoForward(aCanGoForward); } -NS_IMETHODIMP nsWebBrowser::GoBack() +NS_IMETHODIMP +nsWebBrowser::GoBack() { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GoBack(); } -NS_IMETHODIMP nsWebBrowser::GoForward() +NS_IMETHODIMP +nsWebBrowser::GoForward() { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GoForward(); } -NS_IMETHODIMP nsWebBrowser::LoadURIWithOptions(const char16_t* aURI, - uint32_t aLoadFlags, - nsIURI* aReferringURI, - uint32_t aReferrerPolicy, - nsIInputStream* aPostDataStream, - nsIInputStream* aExtraHeaderStream, - nsIURI* aBaseURI) +NS_IMETHODIMP +nsWebBrowser::LoadURIWithOptions(const char16_t* aURI, uint32_t aLoadFlags, + nsIURI* aReferringURI, + uint32_t aReferrerPolicy, + nsIInputStream* aPostDataStream, + nsIInputStream* aExtraHeaderStream, + nsIURI* aBaseURI) { NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->LoadURIWithOptions(aURI, - aLoadFlags, - aReferringURI, - aReferrerPolicy, - aPostDataStream, - aExtraHeaderStream, - aBaseURI); + return mDocShellAsNav->LoadURIWithOptions( + aURI, aLoadFlags, aReferringURI, aReferrerPolicy, aPostDataStream, + aExtraHeaderStream, aBaseURI); } -NS_IMETHODIMP nsWebBrowser::LoadURI(const char16_t* aURI, - uint32_t aLoadFlags, - nsIURI* aReferringURI, - nsIInputStream* aPostDataStream, - nsIInputStream* aExtraHeaderStream) +NS_IMETHODIMP +nsWebBrowser::LoadURI(const char16_t* aURI, uint32_t aLoadFlags, + nsIURI* aReferringURI, + nsIInputStream* aPostDataStream, + nsIInputStream* aExtraHeaderStream) { NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->LoadURI(aURI, - aLoadFlags, - aReferringURI, - aPostDataStream, - aExtraHeaderStream); + return mDocShellAsNav->LoadURI( + aURI, aLoadFlags, aReferringURI, aPostDataStream, aExtraHeaderStream); } -NS_IMETHODIMP nsWebBrowser::Reload(uint32_t aReloadFlags) +NS_IMETHODIMP +nsWebBrowser::Reload(uint32_t aReloadFlags) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->Reload(aReloadFlags); } -NS_IMETHODIMP nsWebBrowser::GotoIndex(int32_t aIndex) +NS_IMETHODIMP +nsWebBrowser::GotoIndex(int32_t aIndex) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GotoIndex(aIndex); } -NS_IMETHODIMP nsWebBrowser::Stop(uint32_t aStopFlags) +NS_IMETHODIMP +nsWebBrowser::Stop(uint32_t aStopFlags) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->Stop(aStopFlags); } -NS_IMETHODIMP nsWebBrowser::GetCurrentURI(nsIURI** aURI) +NS_IMETHODIMP +nsWebBrowser::GetCurrentURI(nsIURI** aURI) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GetCurrentURI(aURI); } -NS_IMETHODIMP nsWebBrowser::GetReferringURI(nsIURI** aURI) +NS_IMETHODIMP +nsWebBrowser::GetReferringURI(nsIURI** aURI) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GetReferringURI(aURI); } -NS_IMETHODIMP nsWebBrowser::SetSessionHistory(nsISHistory* aSessionHistory) +NS_IMETHODIMP +nsWebBrowser::SetSessionHistory(nsISHistory* aSessionHistory) { - if (mDocShell) + if (mDocShell) { return mDocShellAsNav->SetSessionHistory(aSessionHistory); - else + } else { mInitInfo->sessionHistory = aSessionHistory; + } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetSessionHistory(nsISHistory** aSessionHistory) +NS_IMETHODIMP +nsWebBrowser::GetSessionHistory(nsISHistory** aSessionHistory) { NS_ENSURE_ARG_POINTER(aSessionHistory); - if (mDocShell) + if (mDocShell) { return mDocShellAsNav->GetSessionHistory(aSessionHistory); - else + } else { *aSessionHistory = mInitInfo->sessionHistory; + } NS_IF_ADDREF(*aSessionHistory); return NS_OK; } - -NS_IMETHODIMP nsWebBrowser::GetDocument(nsIDOMDocument** aDocument) +NS_IMETHODIMP +nsWebBrowser::GetDocument(nsIDOMDocument** aDocument) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->GetDocument(aDocument); } - //***************************************************************************** // nsWebBrowser::nsIWebBrowserSetup //***************************************************************************** -/* void setProperty (in unsigned long aId, in unsigned long aValue); */ -NS_IMETHODIMP nsWebBrowser::SetProperty(uint32_t aId, uint32_t aValue) +NS_IMETHODIMP +nsWebBrowser::SetProperty(uint32_t aId, uint32_t aValue) { nsresult rv = NS_OK; switch (aId) { - case nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS: - { + case nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS: { NS_ENSURE_STATE(mDocShell); NS_ENSURE_TRUE((aValue == static_cast(true) || aValue == static_cast(false)), @@ -698,8 +759,7 @@ NS_IMETHODIMP nsWebBrowser::SetProperty(uint32_t aId, uint32_t aValue) mDocShell->SetAllowPlugins(!!aValue); break; } - case nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT: - { + case nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT: { NS_ENSURE_STATE(mDocShell); NS_ENSURE_TRUE((aValue == static_cast(true) || aValue == static_cast(false)), @@ -707,8 +767,7 @@ NS_IMETHODIMP nsWebBrowser::SetProperty(uint32_t aId, uint32_t aValue) mDocShell->SetAllowJavascript(!!aValue); break; } - case nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS: - { + case nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS: { NS_ENSURE_STATE(mDocShell); NS_ENSURE_TRUE((aValue == static_cast(true) || aValue == static_cast(false)), @@ -716,74 +775,66 @@ NS_IMETHODIMP nsWebBrowser::SetProperty(uint32_t aId, uint32_t aValue) mDocShell->SetAllowMetaRedirects(!!aValue); break; } - case nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES: - { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == static_cast(true) || - aValue == static_cast(false)), - NS_ERROR_INVALID_ARG); - mDocShell->SetAllowSubframes(!!aValue); - break; - } - case nsIWebBrowserSetup::SETUP_ALLOW_IMAGES: - { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == static_cast(true) || - aValue == static_cast(false)), - NS_ERROR_INVALID_ARG); - mDocShell->SetAllowImages(!!aValue); - break; - } - case nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH: - { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == static_cast(true) || - aValue == static_cast(false)), - NS_ERROR_INVALID_ARG); - mDocShell->SetAllowDNSPrefetch(!!aValue); - break; - } - case nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY: - { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == static_cast(true) || - aValue == static_cast(false)), - NS_ERROR_INVALID_ARG); - rv = EnableGlobalHistory(!!aValue); - mShouldEnableHistory = aValue; - break; - } - case nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT: - { - // obsolete - break; - } - case nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER: - { - NS_ENSURE_TRUE((aValue == static_cast(true) || - aValue == static_cast(false)), - NS_ERROR_INVALID_ARG); - SetItemType(aValue ? static_cast(typeChromeWrapper) - : static_cast(typeContentWrapper)); - break; - } - default: - rv = NS_ERROR_INVALID_ARG; - + case nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES: { + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == static_cast(true) || + aValue == static_cast(false)), + NS_ERROR_INVALID_ARG); + mDocShell->SetAllowSubframes(!!aValue); + break; + } + case nsIWebBrowserSetup::SETUP_ALLOW_IMAGES: { + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == static_cast(true) || + aValue == static_cast(false)), + NS_ERROR_INVALID_ARG); + mDocShell->SetAllowImages(!!aValue); + break; + } + case nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH: { + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == static_cast(true) || + aValue == static_cast(false)), + NS_ERROR_INVALID_ARG); + mDocShell->SetAllowDNSPrefetch(!!aValue); + break; + } + case nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY: { + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == static_cast(true) || + aValue == static_cast(false)), + NS_ERROR_INVALID_ARG); + rv = EnableGlobalHistory(!!aValue); + mShouldEnableHistory = aValue; + break; + } + case nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT: { + // obsolete + break; + } + case nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER: { + NS_ENSURE_TRUE((aValue == static_cast(true) || + aValue == static_cast(false)), + NS_ERROR_INVALID_ARG); + SetItemType(aValue ? static_cast(typeChromeWrapper) : + static_cast(typeContentWrapper)); + break; + } + default: + rv = NS_ERROR_INVALID_ARG; } return rv; } - //***************************************************************************** // nsWebBrowser::nsIWebProgressListener //***************************************************************************** -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ -NS_IMETHODIMP nsWebBrowser::OnStateChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - uint32_t aStateFlags, - nsresult aStatus) +NS_IMETHODIMP +nsWebBrowser::OnStateChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + uint32_t aStateFlags, + nsresult aStatus) { if (mPersist) { mPersist->GetCurrentState(&mPersistCurrentState); @@ -792,59 +843,64 @@ NS_IMETHODIMP nsWebBrowser::OnStateChange(nsIWebProgress *aWebProgress, mPersist = nullptr; } if (mProgressListener) { - return mProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus); + return mProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, + aStatus); } return NS_OK; } -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP nsWebBrowser::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - int32_t aCurSelfProgress, - int32_t aMaxSelfProgress, - int32_t aCurTotalProgress, - int32_t aMaxTotalProgress) +NS_IMETHODIMP +nsWebBrowser::OnProgressChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + int32_t aCurSelfProgress, + int32_t aMaxSelfProgress, + int32_t aCurTotalProgress, + int32_t aMaxTotalProgress) { if (mPersist) { mPersist->GetCurrentState(&mPersistCurrentState); } if (mProgressListener) { - return mProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); + return mProgressListener->OnProgressChange( + aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, + aCurTotalProgress, aMaxTotalProgress); } return NS_OK; } -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location, in unsigned long aFlags); */ -NS_IMETHODIMP nsWebBrowser::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location, - uint32_t aFlags) +NS_IMETHODIMP +nsWebBrowser::OnLocationChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsIURI* aLocation, + uint32_t aFlags) { if (mProgressListener) { - return mProgressListener->OnLocationChange(aWebProgress, aRequest, location, aFlags); + return mProgressListener->OnLocationChange(aWebProgress, aRequest, aLocation, + aFlags); } return NS_OK; } -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP nsWebBrowser::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const char16_t *aMessage) +NS_IMETHODIMP +nsWebBrowser::OnStatusChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsresult aStatus, + const char16_t* aMessage) { if (mProgressListener) { - return mProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage); + return mProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, + aMessage); } return NS_OK; } -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP nsWebBrowser::OnSecurityChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - uint32_t state) +NS_IMETHODIMP +nsWebBrowser::OnSecurityChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + uint32_t aState) { if (mProgressListener) { - return mProgressListener->OnSecurityChange(aWebProgress, aRequest, state); + return mProgressListener->OnSecurityChange(aWebProgress, aRequest, aState); } return NS_OK; } @@ -853,8 +909,8 @@ NS_IMETHODIMP nsWebBrowser::OnSecurityChange(nsIWebProgress *aWebProgress, // nsWebBrowser::nsIWebBrowserPersist //***************************************************************************** -/* attribute unsigned long persistFlags; */ -NS_IMETHODIMP nsWebBrowser::GetPersistFlags(uint32_t *aPersistFlags) +NS_IMETHODIMP +nsWebBrowser::GetPersistFlags(uint32_t* aPersistFlags) { NS_ENSURE_ARG_POINTER(aPersistFlags); nsresult rv = NS_OK; @@ -865,7 +921,8 @@ NS_IMETHODIMP nsWebBrowser::GetPersistFlags(uint32_t *aPersistFlags) return rv; } -NS_IMETHODIMP nsWebBrowser::SetPersistFlags(uint32_t aPersistFlags) +NS_IMETHODIMP +nsWebBrowser::SetPersistFlags(uint32_t aPersistFlags) { nsresult rv = NS_OK; mPersistFlags = aPersistFlags; @@ -876,9 +933,8 @@ NS_IMETHODIMP nsWebBrowser::SetPersistFlags(uint32_t aPersistFlags) return rv; } - -/* readonly attribute unsigned long currentState; */ -NS_IMETHODIMP nsWebBrowser::GetCurrentState(uint32_t *aCurrentState) +NS_IMETHODIMP +nsWebBrowser::GetCurrentState(uint32_t* aCurrentState) { NS_ENSURE_ARG_POINTER(aCurrentState); if (mPersist) { @@ -888,8 +944,8 @@ NS_IMETHODIMP nsWebBrowser::GetCurrentState(uint32_t *aCurrentState) return NS_OK; } -/* readonly attribute nsresult result; */ -NS_IMETHODIMP nsWebBrowser::GetResult(nsresult *aResult) +NS_IMETHODIMP +nsWebBrowser::GetResult(nsresult* aResult) { NS_ENSURE_ARG_POINTER(aResult); if (mPersist) { @@ -899,8 +955,8 @@ NS_IMETHODIMP nsWebBrowser::GetResult(nsresult *aResult) return NS_OK; } -/* attribute nsIWebBrowserPersistProgress progressListener; */ -NS_IMETHODIMP nsWebBrowser::GetProgressListener(nsIWebProgressListener * *aProgressListener) +NS_IMETHODIMP +nsWebBrowser::GetProgressListener(nsIWebProgressListener** aProgressListener) { NS_ENSURE_ARG_POINTER(aProgressListener); *aProgressListener = mProgressListener; @@ -908,37 +964,37 @@ NS_IMETHODIMP nsWebBrowser::GetProgressListener(nsIWebProgressListener * *aProgr return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetProgressListener(nsIWebProgressListener * aProgressListener) +NS_IMETHODIMP +nsWebBrowser::SetProgressListener(nsIWebProgressListener* aProgressListener) { mProgressListener = aProgressListener; return NS_OK; } -/* void saveURI (in nsIURI aURI, in nsIURI aReferrer, in unsigned long aReferrerPolicy - in nsISupports aCacheKey, in nsIInputStream aPostData, in wstring aExtraHeaders, - in nsISupports aFile, in nsILoadContext aPrivacyContext); */ -NS_IMETHODIMP nsWebBrowser::SaveURI(nsIURI *aURI, - nsISupports *aCacheKey, - nsIURI *aReferrer, - uint32_t aReferrerPolicy, - nsIInputStream *aPostData, - const char *aExtraHeaders, - nsISupports *aFile, - nsILoadContext* aPrivacyContext) +NS_IMETHODIMP +nsWebBrowser::SaveURI(nsIURI* aURI, + nsISupports* aCacheKey, + nsIURI* aReferrer, + uint32_t aReferrerPolicy, + nsIInputStream* aPostData, + const char* aExtraHeaders, + nsISupports* aFile, + nsILoadContext* aPrivacyContext) { - return SavePrivacyAwareURI(aURI, aCacheKey, aReferrer, aReferrerPolicy, - aPostData, aExtraHeaders, - aFile, aPrivacyContext && aPrivacyContext->UsePrivateBrowsing()); + return SavePrivacyAwareURI( + aURI, aCacheKey, aReferrer, aReferrerPolicy, aPostData, aExtraHeaders, + aFile, aPrivacyContext && aPrivacyContext->UsePrivateBrowsing()); } -NS_IMETHODIMP nsWebBrowser::SavePrivacyAwareURI(nsIURI *aURI, - nsISupports *aCacheKey, - nsIURI *aReferrer, - uint32_t aReferrerPolicy, - nsIInputStream *aPostData, - const char *aExtraHeaders, - nsISupports *aFile, - bool aIsPrivate) +NS_IMETHODIMP +nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI, + nsISupports* aCacheKey, + nsIURI* aReferrer, + uint32_t aReferrerPolicy, + nsIInputStream* aPostData, + const char* aExtraHeaders, + nsISupports* aFile, + bool aIsPrivate) { if (mPersist) { uint32_t currentState; @@ -977,8 +1033,8 @@ NS_IMETHODIMP nsWebBrowser::SavePrivacyAwareURI(nsIURI *aURI, return rv; } -/* void saveChannel (in nsIChannel aChannel, in nsISupports aFile); */ -NS_IMETHODIMP nsWebBrowser::SaveChannel(nsIChannel* aChannel, nsISupports *aFile) +NS_IMETHODIMP +nsWebBrowser::SaveChannel(nsIChannel* aChannel, nsISupports* aFile) { if (mPersist) { uint32_t currentState; @@ -1005,13 +1061,13 @@ NS_IMETHODIMP nsWebBrowser::SaveChannel(nsIChannel* aChannel, nsISupports *aFile return rv; } -/* void saveDocument (in nsIDOMDocument document, in nsISupports aFile, in nsISupports aDataPath); */ -NS_IMETHODIMP nsWebBrowser::SaveDocument(nsIDOMDocument *aDocument, - nsISupports *aFile, - nsISupports *aDataPath, - const char *aOutputContentType, - uint32_t aEncodingFlags, - uint32_t aWrapColumn) +NS_IMETHODIMP +nsWebBrowser::SaveDocument(nsIDOMDocument* aDocument, + nsISupports* aFile, + nsISupports* aDataPath, + const char* aOutputContentType, + uint32_t aEncodingFlags, + uint32_t aWrapColumn) { if (mPersist) { uint32_t currentState; @@ -1044,24 +1100,25 @@ NS_IMETHODIMP nsWebBrowser::SaveDocument(nsIDOMDocument *aDocument, mPersist->SetProgressListener(this); mPersist->SetPersistFlags(mPersistFlags); mPersist->GetCurrentState(&mPersistCurrentState); - rv = mPersist->SaveDocument(doc, aFile, aDataPath, aOutputContentType, aEncodingFlags, aWrapColumn); + rv = mPersist->SaveDocument(doc, aFile, aDataPath, aOutputContentType, + aEncodingFlags, aWrapColumn); if (NS_FAILED(rv)) { mPersist = nullptr; } return rv; } -/* void cancelSave(); */ -NS_IMETHODIMP nsWebBrowser::CancelSave() +NS_IMETHODIMP +nsWebBrowser::CancelSave() { if (mPersist) { return mPersist->CancelSave(); } - return NS_OK; + return NS_OK; } -/* void cancel(nsresult aReason); */ -NS_IMETHODIMP nsWebBrowser::Cancel(nsresult aReason) +NS_IMETHODIMP +nsWebBrowser::Cancel(nsresult aReason) { if (mPersist) { return mPersist->Cancel(aReason); @@ -1069,20 +1126,22 @@ NS_IMETHODIMP nsWebBrowser::Cancel(nsresult aReason) return NS_OK; } - //***************************************************************************** // nsWebBrowser::nsIBaseWindow //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::InitWindow(nativeWindow aParentNativeWindow, - nsIWidget* aParentWidget, int32_t aX, int32_t aY, int32_t aCX, int32_t aCY) +NS_IMETHODIMP +nsWebBrowser::InitWindow(nativeWindow aParentNativeWindow, + nsIWidget* aParentWidget, + int32_t aX, int32_t aY, + int32_t aCX, int32_t aCY) { NS_ENSURE_ARG(aParentNativeWindow || aParentWidget); NS_ENSURE_STATE(!mDocShell || mInitInfo); - if (aParentWidget) + if (aParentWidget) { NS_ENSURE_SUCCESS(SetParentWidget(aParentWidget), NS_ERROR_FAILURE); - else + } else NS_ENSURE_SUCCESS(SetParentNativeWindow(aParentNativeWindow), NS_ERROR_FAILURE); @@ -1092,7 +1151,8 @@ NS_IMETHODIMP nsWebBrowser::InitWindow(nativeWindow aParentNativeWindow, return NS_OK; } -NS_IMETHODIMP nsWebBrowser::Create() +NS_IMETHODIMP +nsWebBrowser::Create() { NS_ENSURE_STATE(!mDocShell && (mParentNativeWindow || mParentWidget)); @@ -1106,7 +1166,7 @@ NS_IMETHODIMP nsWebBrowser::Create() NS_ENSURE_SUCCESS(rv, rv); docShellParentWidget = mInternalWidget; - nsWidgetInitData widgetInit; + nsWidgetInitData widgetInit; widgetInit.clipChildren = true; @@ -1117,7 +1177,8 @@ NS_IMETHODIMP nsWebBrowser::Create() mInternalWidget->Create(nullptr, mParentNativeWindow, bounds, &widgetInit); } - nsCOMPtr docShell(do_CreateInstance("@mozilla.org/docshell;1", &rv)); + nsCOMPtr docShell( + do_CreateInstance("@mozilla.org/docshell;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); rv = SetDocShell(docShell); NS_ENSURE_SUCCESS(rv, rv); @@ -1148,13 +1209,15 @@ NS_IMETHODIMP nsWebBrowser::Create() // registration can go away, and nsDocShellTreeOwner can stop implementing // nsIWebProgressListener. nsCOMPtr supports = nullptr; - (void)mDocShellTreeOwner->QueryInterface(NS_GET_IID(nsIWebProgressListener), - static_cast(getter_AddRefs(supports))); + (void)mDocShellTreeOwner->QueryInterface( + NS_GET_IID(nsIWebProgressListener), + static_cast(getter_AddRefs(supports))); (void)BindListener(supports, NS_GET_IID(nsIWebProgressListener)); - NS_ENSURE_SUCCESS(mDocShellAsWin->InitWindow(nullptr, - docShellParentWidget, mInitInfo->x, mInitInfo->y, mInitInfo->cx, - mInitInfo->cy), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mDocShellAsWin->InitWindow(nullptr, docShellParentWidget, + mInitInfo->x, mInitInfo->y, + mInitInfo->cx, mInitInfo->cy), + NS_ERROR_FAILURE); mDocShell->SetName(mInitInfo->name); if (mContentType == typeChromeWrapper) { @@ -1165,8 +1228,9 @@ NS_IMETHODIMP nsWebBrowser::Create() mDocShell->SetTreeOwner(mDocShellTreeOwner); // If the webbrowser is a content docshell item then we won't hear any - // events from subframes. To solve that we install our own chrome event handler - // that always gets called (even for subframes) for any bubbling event. + // events from subframes. To solve that we install our own chrome event + // handler that always gets called (even for subframes) for any bubbling + // event. if (!mInitInfo->sessionHistory) { mInitInfo->sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID, &rv); @@ -1192,8 +1256,9 @@ NS_IMETHODIMP nsWebBrowser::Create() // and calls docShell->SetSecurityUI(this); nsCOMPtr securityUI = do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) { securityUI->Init(domWindow); + } } mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0) @@ -1204,7 +1269,8 @@ NS_IMETHODIMP nsWebBrowser::Create() return NS_OK; } -NS_IMETHODIMP nsWebBrowser::Destroy() +NS_IMETHODIMP +nsWebBrowser::Destroy() { InternalDestroy(); @@ -1215,13 +1281,15 @@ NS_IMETHODIMP nsWebBrowser::Destroy() return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetUnscaledDevicePixelsPerCSSPixel(double *aScale) +NS_IMETHODIMP +nsWebBrowser::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) { *aScale = mParentWidget ? mParentWidget->GetDefaultScale().scale : 1.0; return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetPosition(int32_t aX, int32_t aY) +NS_IMETHODIMP +nsWebBrowser::SetPosition(int32_t aX, int32_t aY) { int32_t cx = 0; int32_t cy = 0; @@ -1231,12 +1299,14 @@ NS_IMETHODIMP nsWebBrowser::SetPosition(int32_t aX, int32_t aY) return SetPositionAndSize(aX, aY, cx, cy, false); } -NS_IMETHODIMP nsWebBrowser::GetPosition(int32_t* aX, int32_t* aY) +NS_IMETHODIMP +nsWebBrowser::GetPosition(int32_t* aX, int32_t* aY) { return GetPositionAndSize(aX, aY, nullptr, nullptr); } -NS_IMETHODIMP nsWebBrowser::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) +NS_IMETHODIMP +nsWebBrowser::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) { int32_t x = 0; int32_t y = 0; @@ -1246,14 +1316,15 @@ NS_IMETHODIMP nsWebBrowser::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) return SetPositionAndSize(x, y, aCX, aCY, aRepaint); } -NS_IMETHODIMP nsWebBrowser::GetSize(int32_t* aCX, int32_t* aCY) +NS_IMETHODIMP +nsWebBrowser::GetSize(int32_t* aCX, int32_t* aCY) { return GetPositionAndSize(nullptr, nullptr, aCX, aCY); } -NS_IMETHODIMP nsWebBrowser::SetPositionAndSize(int32_t aX, int32_t aY, - int32_t aCX, int32_t aCY, - bool aRepaint) +NS_IMETHODIMP +nsWebBrowser::SetPositionAndSize(int32_t aX, int32_t aY, + int32_t aCX, int32_t aCY, bool aRepaint) { if (!mDocShell) { mInitInfo->x = aX; @@ -1273,15 +1344,17 @@ NS_IMETHODIMP nsWebBrowser::SetPositionAndSize(int32_t aX, int32_t aY, NS_ERROR_FAILURE); } // Now reposition/ resize the doc - NS_ENSURE_SUCCESS(mDocShellAsWin->SetPositionAndSize(doc_x, doc_y, aCX, aCY, - aRepaint), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS( + mDocShellAsWin->SetPositionAndSize(doc_x, doc_y, aCX, aCY, aRepaint), + NS_ERROR_FAILURE); } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetPositionAndSize(int32_t* aX, int32_t* aY, - int32_t* aCX, int32_t* aCY) +NS_IMETHODIMP +nsWebBrowser::GetPositionAndSize(int32_t* aX, int32_t* aY, + int32_t* aCX, int32_t* aCY) { if (!mDocShell) { if (aX) { @@ -1321,7 +1394,8 @@ NS_IMETHODIMP nsWebBrowser::GetPositionAndSize(int32_t* aX, int32_t* aY, return NS_OK; } -NS_IMETHODIMP nsWebBrowser::Repaint(bool aForce) +NS_IMETHODIMP +nsWebBrowser::Repaint(bool aForce) { NS_ENSURE_STATE(mDocShell); // Can directly return this as it is the @@ -1329,7 +1403,8 @@ NS_IMETHODIMP nsWebBrowser::Repaint(bool aForce) return mDocShellAsWin->Repaint(aForce); } -NS_IMETHODIMP nsWebBrowser::GetParentWidget(nsIWidget** aParentWidget) +NS_IMETHODIMP +nsWebBrowser::GetParentWidget(nsIWidget** aParentWidget) { NS_ENSURE_ARG_POINTER(aParentWidget); @@ -1340,20 +1415,23 @@ NS_IMETHODIMP nsWebBrowser::GetParentWidget(nsIWidget** aParentWidget) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetParentWidget(nsIWidget* aParentWidget) +NS_IMETHODIMP +nsWebBrowser::SetParentWidget(nsIWidget* aParentWidget) { NS_ENSURE_STATE(!mDocShell); mParentWidget = aParentWidget; - if (mParentWidget) + if (mParentWidget) { mParentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET); - else + } else { mParentNativeWindow = nullptr; + } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetParentNativeWindow(nativeWindow* aParentNativeWindow) +NS_IMETHODIMP +nsWebBrowser::GetParentNativeWindow(nativeWindow* aParentNativeWindow) { NS_ENSURE_ARG_POINTER(aParentNativeWindow); @@ -1362,7 +1440,8 @@ NS_IMETHODIMP nsWebBrowser::GetParentNativeWindow(nativeWindow* aParentNativeWin return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWindow) +NS_IMETHODIMP +nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWindow) { NS_ENSURE_STATE(!mDocShell); @@ -1371,30 +1450,36 @@ NS_IMETHODIMP nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWind return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetNativeHandle(nsAString& aNativeHandle) +NS_IMETHODIMP +nsWebBrowser::GetNativeHandle(nsAString& aNativeHandle) { // the nativeHandle should be accessed from nsIXULWindow return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsWebBrowser::GetVisibility(bool* visibility) +NS_IMETHODIMP +nsWebBrowser::GetVisibility(bool* aVisibility) { - NS_ENSURE_ARG_POINTER(visibility); + NS_ENSURE_ARG_POINTER(aVisibility); - if (!mDocShell) - *visibility = mInitInfo->visible; - else - NS_ENSURE_SUCCESS(mDocShellAsWin->GetVisibility(visibility), NS_ERROR_FAILURE); + if (!mDocShell) { + *aVisibility = mInitInfo->visible; + } else { + NS_ENSURE_SUCCESS(mDocShellAsWin->GetVisibility(aVisibility), + NS_ERROR_FAILURE); + } return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetVisibility(bool aVisibility) +NS_IMETHODIMP +nsWebBrowser::SetVisibility(bool aVisibility) { if (!mDocShell) { mInitInfo->visible = aVisibility; } else { - NS_ENSURE_SUCCESS(mDocShellAsWin->SetVisibility(aVisibility), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mDocShellAsWin->SetVisibility(aVisibility), + NS_ERROR_FAILURE); if (mInternalWidget) { mInternalWidget->Show(aVisibility); } @@ -1403,7 +1488,8 @@ NS_IMETHODIMP nsWebBrowser::SetVisibility(bool aVisibility) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetEnabled(bool* aEnabled) +NS_IMETHODIMP +nsWebBrowser::GetEnabled(bool* aEnabled) { if (mInternalWidget) { *aEnabled = mInternalWidget->IsEnabled(); @@ -1413,28 +1499,33 @@ NS_IMETHODIMP nsWebBrowser::GetEnabled(bool* aEnabled) return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsWebBrowser::SetEnabled(bool aEnabled) +NS_IMETHODIMP +nsWebBrowser::SetEnabled(bool aEnabled) { - if (mInternalWidget) + if (mInternalWidget) { return mInternalWidget->Enable(aEnabled); + } return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsWebBrowser::GetMainWidget(nsIWidget** mainWidget) +NS_IMETHODIMP +nsWebBrowser::GetMainWidget(nsIWidget** aMainWidget) { - NS_ENSURE_ARG_POINTER(mainWidget); + NS_ENSURE_ARG_POINTER(aMainWidget); - if (mInternalWidget) - *mainWidget = mInternalWidget; - else - *mainWidget = mParentWidget; + if (mInternalWidget) { + *aMainWidget = mInternalWidget; + } else { + *aMainWidget = mParentWidget; + } - NS_IF_ADDREF(*mainWidget); + NS_IF_ADDREF(*aMainWidget); return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetFocus() +NS_IMETHODIMP +nsWebBrowser::SetFocus() { nsCOMPtr window = GetWindow(); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); @@ -1443,7 +1534,8 @@ NS_IMETHODIMP nsWebBrowser::SetFocus() return fm ? fm->SetFocusedWindow(window) : NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetTitle(char16_t** aTitle) +NS_IMETHODIMP +nsWebBrowser::GetTitle(char16_t** aTitle) { NS_ENSURE_ARG_POINTER(aTitle); NS_ENSURE_STATE(mDocShell); @@ -1453,7 +1545,8 @@ NS_IMETHODIMP nsWebBrowser::GetTitle(char16_t** aTitle) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetTitle(const char16_t* aTitle) +NS_IMETHODIMP +nsWebBrowser::SetTitle(const char16_t* aTitle) { NS_ENSURE_STATE(mDocShell); @@ -1466,26 +1559,29 @@ NS_IMETHODIMP nsWebBrowser::SetTitle(const char16_t* aTitle) // nsWebBrowser::nsIScrollable //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::GetDefaultScrollbarPreferences(int32_t aScrollOrientation, - int32_t* aScrollbarPref) +NS_IMETHODIMP +nsWebBrowser::GetDefaultScrollbarPreferences(int32_t aScrollOrientation, + int32_t* aScrollbarPref) { NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->GetDefaultScrollbarPreferences(aScrollOrientation, - aScrollbarPref); + return mDocShellAsScrollable->GetDefaultScrollbarPreferences( + aScrollOrientation, aScrollbarPref); } -NS_IMETHODIMP nsWebBrowser::SetDefaultScrollbarPreferences(int32_t aScrollOrientation, - int32_t aScrollbarPref) +NS_IMETHODIMP +nsWebBrowser::SetDefaultScrollbarPreferences(int32_t aScrollOrientation, + int32_t aScrollbarPref) { NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->SetDefaultScrollbarPreferences(aScrollOrientation, - aScrollbarPref); + return mDocShellAsScrollable->SetDefaultScrollbarPreferences( + aScrollOrientation, aScrollbarPref); } -NS_IMETHODIMP nsWebBrowser::GetScrollbarVisibility(bool* aVerticalVisible, - bool* aHorizontalVisible) +NS_IMETHODIMP +nsWebBrowser::GetScrollbarVisibility(bool* aVerticalVisible, + bool* aHorizontalVisible) { NS_ENSURE_STATE(mDocShell); @@ -1497,26 +1593,28 @@ NS_IMETHODIMP nsWebBrowser::GetScrollbarVisibility(bool* aVerticalVisible, // nsWebBrowser::nsITextScroll //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::ScrollByLines(int32_t aNumLines) +NS_IMETHODIMP +nsWebBrowser::ScrollByLines(int32_t aNumLines) { NS_ENSURE_STATE(mDocShell); return mDocShellAsTextScroll->ScrollByLines(aNumLines); } -NS_IMETHODIMP nsWebBrowser::ScrollByPages(int32_t aNumPages) +NS_IMETHODIMP +nsWebBrowser::ScrollByPages(int32_t aNumPages) { NS_ENSURE_STATE(mDocShell); return mDocShellAsTextScroll->ScrollByPages(aNumPages); } - //***************************************************************************** // nsWebBrowser: Listener Helpers //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::SetDocShell(nsIDocShell* aDocShell) +NS_IMETHODIMP +nsWebBrowser::SetDocShell(nsIDocShell* aDocShell) { nsCOMPtr kungFuDeathGrip(mDocShell); if (aDocShell) { @@ -1549,10 +1647,12 @@ NS_IMETHODIMP nsWebBrowser::SetDocShell(nsIDocShell* aDocShell) // a no-op unless setIsActive(false) has been called on us. mDocShell->SetIsActive(mIsActive); } else { - if (mDocShellTreeOwner) + if (mDocShellTreeOwner) { mDocShellTreeOwner->RemoveFromWatcher(); // evil twin of Add in Create() - if (mDocShellAsWin) + } + if (mDocShellAsWin) { mDocShellAsWin->Destroy(); + } mDocShell = nullptr; mDocShellAsReq = nullptr; @@ -1566,10 +1666,12 @@ NS_IMETHODIMP nsWebBrowser::SetDocShell(nsIDocShell* aDocShell) return NS_OK; } -NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner() +NS_IMETHODIMP +nsWebBrowser::EnsureDocShellTreeOwner() { - if (mDocShellTreeOwner) + if (mDocShellTreeOwner) { return NS_OK; + } mDocShellTreeOwner = new nsDocShellTreeOwner(); mDocShellTreeOwner->WebBrowser(this); @@ -1577,23 +1679,24 @@ NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner() return NS_OK; } -static void DrawPaintedLayer(PaintedLayer* aLayer, - gfxContext* aContext, - const nsIntRegion& aRegionToDraw, - DrawRegionClip aClip, - const nsIntRegion& aRegionToInvalidate, - void* aCallbackData) +static void +DrawPaintedLayer(PaintedLayer* aLayer, + gfxContext* aContext, + const nsIntRegion& aRegionToDraw, + DrawRegionClip aClip, + const nsIntRegion& aRegionToInvalidate, + void* aCallbackData) { DrawTarget& aDrawTarget = *aContext->GetDrawTarget(); ColorPattern color(ToDeviceColor(*static_cast(aCallbackData))); nsIntRect dirtyRect = aRegionToDraw.GetBounds(); - aDrawTarget.FillRect(Rect(dirtyRect.x, dirtyRect.y, - dirtyRect.width, dirtyRect.height), - color); + aDrawTarget.FillRect( + Rect(dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height), color); } -void nsWebBrowser::WindowRaised(nsIWidget* aWidget) +void +nsWebBrowser::WindowRaised(nsIWidget* aWidget) { #if defined(DEBUG_smaug) nsCOMPtr document = mDocShell->GetDocument(); @@ -1605,7 +1708,8 @@ void nsWebBrowser::WindowRaised(nsIWidget* aWidget) Activate(); } -void nsWebBrowser::WindowLowered(nsIWidget* aWidget) +void +nsWebBrowser::WindowLowered(nsIWidget* aWidget) { #if defined(DEBUG_smaug) nsCOMPtr document = mDocShell->GetDocument(); @@ -1617,7 +1721,8 @@ void nsWebBrowser::WindowLowered(nsIWidget* aWidget) Deactivate(); } -bool nsWebBrowser::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) +bool +nsWebBrowser::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) { LayerManager* layerManager = aWidget->GetLayerManager(); NS_ASSERTION(layerManager, "Must be in paint event"); @@ -1634,7 +1739,8 @@ bool nsWebBrowser::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) return true; } -NS_IMETHODIMP nsWebBrowser::GetPrimaryContentWindow(nsIDOMWindow** aDOMWindow) +NS_IMETHODIMP +nsWebBrowser::GetPrimaryContentWindow(nsIDOMWindow** aDOMWindow) { *aDOMWindow = nullptr; @@ -1659,40 +1765,42 @@ NS_IMETHODIMP nsWebBrowser::GetPrimaryContentWindow(nsIDOMWindow** aDOMWindow) // nsWebBrowser::nsIWebBrowserFocus //***************************************************************************** -/* void activate (); */ -NS_IMETHODIMP nsWebBrowser::Activate(void) +NS_IMETHODIMP +nsWebBrowser::Activate(void) { nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); nsCOMPtr window = GetWindow(); - if (fm && window) + if (fm && window) { return fm->WindowRaised(window); + } return NS_OK; } -/* void deactivate (); */ -NS_IMETHODIMP nsWebBrowser::Deactivate(void) +NS_IMETHODIMP +nsWebBrowser::Deactivate(void) { nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); nsCOMPtr window = GetWindow(); - if (fm && window) + if (fm && window) { return fm->WindowLowered(window); + } return NS_OK; } -/* void setFocusAtFirstElement (); */ -NS_IMETHODIMP nsWebBrowser::SetFocusAtFirstElement(void) +NS_IMETHODIMP +nsWebBrowser::SetFocusAtFirstElement(void) { return NS_OK; } -/* void setFocusAtLastElement (); */ -NS_IMETHODIMP nsWebBrowser::SetFocusAtLastElement(void) +NS_IMETHODIMP +nsWebBrowser::SetFocusAtLastElement(void) { return NS_OK; } -/* attribute nsIDOMWindow focusedWindow; */ -NS_IMETHODIMP nsWebBrowser::GetFocusedWindow(nsIDOMWindow * *aFocusedWindow) +NS_IMETHODIMP +nsWebBrowser::GetFocusedWindow(nsIDOMWindow** aFocusedWindow) { NS_ENSURE_ARG_POINTER(aFocusedWindow); *aFocusedWindow = nullptr; @@ -1705,17 +1813,19 @@ NS_IMETHODIMP nsWebBrowser::GetFocusedWindow(nsIDOMWindow * *aFocusedWindow) nsCOMPtr focusedElement; nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); return fm ? fm->GetFocusedElementForWindow(window, true, aFocusedWindow, - getter_AddRefs(focusedElement)) : NS_OK; + getter_AddRefs(focusedElement)) : + NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetFocusedWindow(nsIDOMWindow * aFocusedWindow) +NS_IMETHODIMP +nsWebBrowser::SetFocusedWindow(nsIDOMWindow* aFocusedWindow) { nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); return fm ? fm->SetFocusedWindow(aFocusedWindow) : NS_OK; } -/* attribute nsIDOMElement focusedElement; */ -NS_IMETHODIMP nsWebBrowser::GetFocusedElement(nsIDOMElement * *aFocusedElement) +NS_IMETHODIMP +nsWebBrowser::GetFocusedElement(nsIDOMElement** aFocusedElement) { NS_ENSURE_ARG_POINTER(aFocusedElement); NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); @@ -1724,10 +1834,13 @@ NS_IMETHODIMP nsWebBrowser::GetFocusedElement(nsIDOMElement * *aFocusedElement) NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - return fm ? fm->GetFocusedElementForWindow(window, true, nullptr, aFocusedElement) : NS_OK; + return + fm ? fm->GetFocusedElementForWindow(window, true, nullptr, aFocusedElement) : + NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement) +NS_IMETHODIMP +nsWebBrowser::SetFocusedElement(nsIDOMElement* aFocusedElement) { nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); return fm ? fm->SetFocus(aFocusedElement, 0) : NS_OK; @@ -1737,8 +1850,8 @@ NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement) // nsWebBrowser::nsIWebBrowserStream //***************************************************************************** -/* void openStream(in nsIURI aBaseURI, in ACString aContentType); */ -NS_IMETHODIMP nsWebBrowser::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType) +NS_IMETHODIMP +nsWebBrowser::OpenStream(nsIURI* aBaseURI, const nsACString& aContentType) { nsresult rv; @@ -1746,30 +1859,33 @@ NS_IMETHODIMP nsWebBrowser::OpenStream(nsIURI *aBaseURI, const nsACString& aCont mStream = new nsEmbedStream(); mStream->InitOwner(this); rv = mStream->Init(); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { return rv; + } } return mStream->OpenStream(aBaseURI, aContentType); } -/* void appendToStream([const, array, size_is(aLen)] in octet aData, - * in unsigned long aLen); */ -NS_IMETHODIMP nsWebBrowser::AppendToStream(const uint8_t *aData, uint32_t aLen) + +NS_IMETHODIMP +nsWebBrowser::AppendToStream(const uint8_t* aData, uint32_t aLen) { - if (!mStream) + if (!mStream) { return NS_ERROR_FAILURE; + } return mStream->AppendToStream(aData, aLen); } -/* void closeStream (); */ -NS_IMETHODIMP nsWebBrowser::CloseStream() +NS_IMETHODIMP +nsWebBrowser::CloseStream() { nsresult rv; - if (!mStream) + if (!mStream) { return NS_ERROR_FAILURE; + } rv = mStream->CloseStream(); mStream = nullptr; diff --git a/embedding/browser/nsWebBrowser.h b/embedding/browser/nsWebBrowser.h index 08dbcbb51ca..26267d4ca9f 100644 --- a/embedding/browser/nsWebBrowser.h +++ b/embedding/browser/nsWebBrowser.h @@ -44,20 +44,21 @@ class nsWebBrowserInitInfo { public: - //nsIBaseWindow Stuff - int32_t x; - int32_t y; - int32_t cx; - int32_t cy; - bool visible; - nsCOMPtr sessionHistory; - nsString name; + // nsIBaseWindow Stuff + int32_t x; + int32_t y; + int32_t cx; + int32_t cy; + bool visible; + nsCOMPtr sessionHistory; + nsString name; }; class nsWebBrowserListenerState { public: - bool Equals(nsIWeakReference *aListener, const nsIID& aID) { + bool Equals(nsIWeakReference* aListener, const nsIID& aID) + { return mWeakPtr.get() == aListener && mID.Equals(aID); } @@ -67,7 +68,7 @@ public: // {cda5863a-aa9c-411e-be49-ea0d525ab4b5} - #define NS_WEBBROWSER_CID \ -{0xcda5863a, 0xaa9c, 0x411e, { 0xbe, 0x49, 0xea, 0x0d, 0x52, 0x5a, 0xb4, 0xb5 }} + { 0xcda5863a, 0xaa9c, 0x411e, { 0xbe, 0x49, 0xea, 0x0d, 0x52, 0x5a, 0xb4, 0xb5 } } class nsWebBrowser final : public nsIWebBrowser, @@ -86,6 +87,7 @@ class nsWebBrowser final : public nsIWebBrowser, public nsSupportsWeakReference { friend class nsDocShellTreeOwner; + public: nsWebBrowser(); @@ -112,9 +114,9 @@ protected: // XXXbz why are these NS_IMETHOD? They're not interface methods! NS_IMETHOD SetDocShell(nsIDocShell* aDocShell); NS_IMETHOD EnsureDocShellTreeOwner(); - NS_IMETHOD GetPrimaryContentWindow(nsIDOMWindow **aDomWindow); - NS_IMETHOD BindListener(nsISupports *aListener, const nsIID& aIID); - NS_IMETHOD UnBindListener(nsISupports *aListener, const nsIID& aIID); + NS_IMETHOD GetPrimaryContentWindow(nsIDOMWindow** aDomWindow); + NS_IMETHOD BindListener(nsISupports* aListener, const nsIID& aIID); + NS_IMETHOD UnBindListener(nsISupports* aListener, const nsIID& aIID); NS_IMETHOD EnableGlobalHistory(bool aEnable); // nsIWidgetListener @@ -124,40 +126,41 @@ protected: protected: nsRefPtr mDocShellTreeOwner; - nsCOMPtr mDocShell; + nsCOMPtr mDocShell; nsCOMPtr mDocShellAsReq; - nsCOMPtr mDocShellAsWin; + nsCOMPtr mDocShellAsWin; nsCOMPtr mDocShellAsNav; - nsCOMPtr mDocShellAsScrollable; - nsCOMPtr mDocShellAsTextScroll; - nsCOMPtr mInternalWidget; + nsCOMPtr mDocShellAsScrollable; + nsCOMPtr mDocShellAsTextScroll; + + nsCOMPtr mInternalWidget; nsCOMPtr mWWatch; nsAutoPtr mInitInfo; - uint32_t mContentType; - bool mActivating; - bool mShouldEnableHistory; - bool mIsActive; - nativeWindow mParentNativeWindow; - nsIWebProgressListener *mProgressListener; - nsCOMPtr mWebProgress; + uint32_t mContentType; + bool mActivating; + bool mShouldEnableHistory; + bool mIsActive; + nativeWindow mParentNativeWindow; + nsIWebProgressListener* mProgressListener; + nsCOMPtr mWebProgress; nsCOMPtr mPrintSettings; // cached background color - nscolor mBackgroundColor; + nscolor mBackgroundColor; // persistence object nsCOMPtr mPersist; - uint32_t mPersistCurrentState; - nsresult mPersistResult; - uint32_t mPersistFlags; + uint32_t mPersistCurrentState; + nsresult mPersistResult; + uint32_t mPersistFlags; // stream - nsRefPtr mStream; + nsRefPtr mStream; - //Weak Reference interfaces... - nsIWidget* mParentWidget; - nsAutoPtr> mListenerArray; + // Weak Reference interfaces... + nsIWidget* mParentWidget; + nsAutoPtr > mListenerArray; }; #endif /* nsWebBrowser_h__ */ diff --git a/embedding/browser/nsWebBrowserContentPolicy.cpp b/embedding/browser/nsWebBrowserContentPolicy.cpp index 6d2f741b36d..71b1651a143 100644 --- a/embedding/browser/nsWebBrowserContentPolicy.cpp +++ b/embedding/browser/nsWebBrowserContentPolicy.cpp @@ -13,91 +13,91 @@ nsWebBrowserContentPolicy::nsWebBrowserContentPolicy() { - MOZ_COUNT_CTOR(nsWebBrowserContentPolicy); + MOZ_COUNT_CTOR(nsWebBrowserContentPolicy); } nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy() { - MOZ_COUNT_DTOR(nsWebBrowserContentPolicy); + MOZ_COUNT_DTOR(nsWebBrowserContentPolicy); } NS_IMPL_ISUPPORTS(nsWebBrowserContentPolicy, nsIContentPolicy) NS_IMETHODIMP -nsWebBrowserContentPolicy::ShouldLoad(uint32_t contentType, - nsIURI *contentLocation, - nsIURI *requestingLocation, - nsISupports *requestingContext, - const nsACString &mimeGuess, - nsISupports *extra, - nsIPrincipal *requestPrincipal, - int16_t *shouldLoad) +nsWebBrowserContentPolicy::ShouldLoad(uint32_t aContentType, + nsIURI* aContentLocation, + nsIURI* aRequestingLocation, + nsISupports* aRequestingContext, + const nsACString& aMimeGuess, + nsISupports* aExtra, + nsIPrincipal* aRequestPrincipal, + int16_t* aShouldLoad) { - NS_PRECONDITION(shouldLoad, "Null out param"); + NS_PRECONDITION(aShouldLoad, "Null out param"); - *shouldLoad = nsIContentPolicy::ACCEPT; + *aShouldLoad = nsIContentPolicy::ACCEPT; - nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext); - /* We're going to dereference shell, so make sure it isn't null */ - if (!shell) { - return NS_OK; - } + nsIDocShell* shell = NS_CP_GetDocShellFromContext(aRequestingContext); + /* We're going to dereference shell, so make sure it isn't null */ + if (!shell) { + return NS_OK; + } - nsresult rv; - bool allowed = true; + nsresult rv; + bool allowed = true; - switch (contentType) { - case nsIContentPolicy::TYPE_SCRIPT: - rv = shell->GetAllowJavascript(&allowed); - break; - case nsIContentPolicy::TYPE_SUBDOCUMENT: - rv = shell->GetAllowSubframes(&allowed); - break; + switch (aContentType) { + case nsIContentPolicy::TYPE_SCRIPT: + rv = shell->GetAllowJavascript(&allowed); + break; + case nsIContentPolicy::TYPE_SUBDOCUMENT: + rv = shell->GetAllowSubframes(&allowed); + break; #if 0 - /* XXXtw: commented out in old code; add during conpol phase 2 */ - case nsIContentPolicy::TYPE_REFRESH: - rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */ - break; + /* XXXtw: commented out in old code; add during conpol phase 2 */ + case nsIContentPolicy::TYPE_REFRESH: + rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */ + break; #endif - case nsIContentPolicy::TYPE_IMAGE: - case nsIContentPolicy::TYPE_IMAGESET: - rv = shell->GetAllowImages(&allowed); - break; - default: - return NS_OK; - } + case nsIContentPolicy::TYPE_IMAGE: + case nsIContentPolicy::TYPE_IMAGESET: + rv = shell->GetAllowImages(&allowed); + break; + default: + return NS_OK; + } - if (NS_SUCCEEDED(rv) && !allowed) { - *shouldLoad = nsIContentPolicy::REJECT_TYPE; - } - return rv; + if (NS_SUCCEEDED(rv) && !allowed) { + *aShouldLoad = nsIContentPolicy::REJECT_TYPE; + } + return rv; } NS_IMETHODIMP -nsWebBrowserContentPolicy::ShouldProcess(uint32_t contentType, - nsIURI *contentLocation, - nsIURI *requestingLocation, - nsISupports *requestingContext, - const nsACString &mimeGuess, - nsISupports *extra, - nsIPrincipal *requestPrincipal, - int16_t *shouldProcess) +nsWebBrowserContentPolicy::ShouldProcess(uint32_t aContentType, + nsIURI* aContentLocation, + nsIURI* aRequestingLocation, + nsISupports* aRequestingContext, + const nsACString& aMimeGuess, + nsISupports* aExtra, + nsIPrincipal* aRequestPrincipal, + int16_t* aShouldProcess) { - NS_PRECONDITION(shouldProcess, "Null out param"); + NS_PRECONDITION(aShouldProcess, "Null out param"); - *shouldProcess = nsIContentPolicy::ACCEPT; - - // Object tags will always open channels with TYPE_OBJECT, but may end up - // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block - // actual-plugins at the process stage - if (contentType != nsIContentPolicy::TYPE_OBJECT) { - return NS_OK; - } - - nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext); - if (shell && (!shell->PluginsAllowedInCurrentDoc())) { - *shouldProcess = nsIContentPolicy::REJECT_TYPE; - } + *aShouldProcess = nsIContentPolicy::ACCEPT; + // Object tags will always open channels with TYPE_OBJECT, but may end up + // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block + // actual-plugins at the process stage + if (aContentType != nsIContentPolicy::TYPE_OBJECT) { return NS_OK; + } + + nsIDocShell* shell = NS_CP_GetDocShellFromContext(aRequestingContext); + if (shell && (!shell->PluginsAllowedInCurrentDoc())) { + *aShouldProcess = nsIContentPolicy::REJECT_TYPE; + } + + return NS_OK; } diff --git a/embedding/browser/nsWebBrowserContentPolicy.h b/embedding/browser/nsWebBrowserContentPolicy.h index 7958bc70308..9da59098052 100644 --- a/embedding/browser/nsWebBrowserContentPolicy.h +++ b/embedding/browser/nsWebBrowserContentPolicy.h @@ -8,19 +8,19 @@ /* f66bc334-1dd1-11b2-bab2-90e04fe15c19 */ #define NS_WEBBROWSERCONTENTPOLICY_CID \ -{ 0xf66bc334, 0x1dd1, 0x11b2, { 0xba, 0xb2, 0x90, 0xe0, 0x4f, 0xe1, 0x5c, 0x19 } } + { 0xf66bc334, 0x1dd1, 0x11b2, { 0xba, 0xb2, 0x90, 0xe0, 0x4f, 0xe1, 0x5c, 0x19 } } -#define NS_WEBBROWSERCONTENTPOLICY_CONTRACTID "@mozilla.org/embedding/browser/content-policy;1" +#define NS_WEBBROWSERCONTENTPOLICY_CONTRACTID \ + "@mozilla.org/embedding/browser/content-policy;1" class nsWebBrowserContentPolicy : public nsIContentPolicy { protected: - virtual ~nsWebBrowserContentPolicy(); + virtual ~nsWebBrowserContentPolicy(); public: - nsWebBrowserContentPolicy(); + nsWebBrowserContentPolicy(); - NS_DECL_ISUPPORTS - NS_DECL_NSICONTENTPOLICY + NS_DECL_ISUPPORTS + NS_DECL_NSICONTENTPOLICY }; -