mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1127189 - part 2 - Initialize browser API directly to get rid of nsBrowserElement observers. r=kanru
--HG-- extra : rebase_source : 84f091ace43aebdb1c71e3060aa5a8220561977d
This commit is contained in:
parent
93d58b32bd
commit
7d7f2fce93
@ -170,14 +170,12 @@ nsFrameLoader::nsFrameLoader(Element* aOwner, bool aNetworkCreated)
|
||||
, mRemoteFrame(false)
|
||||
, mClipSubdocument(true)
|
||||
, mClampScrollPosition(true)
|
||||
, mRemoteBrowserInitialized(false)
|
||||
, mObservingOwnerContent(false)
|
||||
, mVisible(true)
|
||||
, mCurrentRemoteFrame(nullptr)
|
||||
, mRemoteBrowser(nullptr)
|
||||
, mChildID(0)
|
||||
, mEventMode(EVENT_MODE_NORMAL_DISPATCH)
|
||||
, mPendingFrameSent(false)
|
||||
{
|
||||
ResetPermissionManagerStatus();
|
||||
}
|
||||
@ -365,15 +363,6 @@ nsFrameLoader::ReallyStartLoadingInternal()
|
||||
|
||||
if (mRemoteFrame) {
|
||||
if (!mRemoteBrowser) {
|
||||
if (!mPendingFrameSent) {
|
||||
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||
if (os && !mRemoteBrowserInitialized) {
|
||||
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
|
||||
"remote-browser-pending", nullptr);
|
||||
mPendingFrameSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
TryRemoteBrowser();
|
||||
|
||||
if (!mRemoteBrowser) {
|
||||
@ -916,16 +905,11 @@ nsFrameLoader::ShowRemoteFrame(const nsIntSize& size,
|
||||
|
||||
EnsureMessageManager();
|
||||
|
||||
InitializeBrowserAPI();
|
||||
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||
if (os && !mRemoteBrowserInitialized) {
|
||||
if (!mPendingFrameSent) {
|
||||
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
|
||||
"remote-browser-pending", nullptr);
|
||||
mPendingFrameSent = true;
|
||||
}
|
||||
if (os) {
|
||||
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
|
||||
"remote-browser-shown", nullptr);
|
||||
mRemoteBrowserInitialized = true;
|
||||
}
|
||||
} else {
|
||||
nsIntRect dimensions;
|
||||
@ -1794,6 +1778,7 @@ nsFrameLoader::MaybeCreateDocShell()
|
||||
mDocShell->SetIsBrowserInsideApp(containingAppId);
|
||||
}
|
||||
|
||||
InitializeBrowserAPI();
|
||||
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
|
||||
@ -2758,3 +2743,12 @@ nsFrameLoader::GetLoadContext(nsILoadContext** aLoadContext)
|
||||
loadContext.forget(aLoadContext);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsFrameLoader::InitializeBrowserAPI()
|
||||
{
|
||||
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(mOwnerContent);
|
||||
if (browserFrame) {
|
||||
browserFrame->InitializeBrowserAPI();
|
||||
}
|
||||
}
|
||||
|
@ -312,6 +312,8 @@ private:
|
||||
// own-or-containing-app.
|
||||
void ResetPermissionManagerStatus();
|
||||
|
||||
void InitializeBrowserAPI();
|
||||
|
||||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
nsCOMPtr<nsIURI> mURIToLoad;
|
||||
mozilla::dom::Element* mOwnerContent; // WEAK
|
||||
@ -351,7 +353,6 @@ private:
|
||||
bool mRemoteFrame : 1;
|
||||
bool mClipSubdocument : 1;
|
||||
bool mClampScrollPosition : 1;
|
||||
bool mRemoteBrowserInitialized : 1;
|
||||
bool mObservingOwnerContent : 1;
|
||||
|
||||
// Backs nsIFrameLoader::{Get,Set}Visible. Visibility state here relates to
|
||||
@ -369,9 +370,6 @@ private:
|
||||
// See nsIFrameLoader.idl. EVENT_MODE_NORMAL_DISPATCH automatically
|
||||
// forwards some input events to out-of-process content.
|
||||
uint32_t mEventMode;
|
||||
|
||||
// Indicate if we have sent 'remote-browser-pending'.
|
||||
bool mPendingFrameSent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,91 +19,12 @@
|
||||
#include "nsIDOMDOMRequest.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static const char kRemoteBrowserPending[] = "remote-browser-pending";
|
||||
static const char kInprocessBrowserShown[] = "inprocess-browser-shown";
|
||||
|
||||
class nsBrowserElement::BrowserShownObserver : public nsIObserver
|
||||
, public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
explicit BrowserShownObserver(nsBrowserElement* aBrowserElement);
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
void AddObserver();
|
||||
void RemoveObserver();
|
||||
private:
|
||||
virtual ~BrowserShownObserver();
|
||||
|
||||
// Weak reference to the browser element. nsBrowserElement has a
|
||||
// reference to us. nsBrowserElement's destructor is responsible to
|
||||
// null out this weak reference via RemoveObserver()
|
||||
nsBrowserElement* mBrowserElement;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsBrowserElement::BrowserShownObserver, nsIObserver, nsISupportsWeakReference)
|
||||
|
||||
nsBrowserElement::BrowserShownObserver::BrowserShownObserver(nsBrowserElement* aBrowserElement)
|
||||
: mBrowserElement(aBrowserElement)
|
||||
{
|
||||
}
|
||||
|
||||
nsBrowserElement::BrowserShownObserver::~BrowserShownObserver()
|
||||
{
|
||||
RemoveObserver();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserElement::BrowserShownObserver::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
NS_ENSURE_TRUE(mBrowserElement, NS_OK);
|
||||
|
||||
if (!strcmp(aTopic, kRemoteBrowserPending) ||
|
||||
!strcmp(aTopic, kInprocessBrowserShown)) {
|
||||
nsCOMPtr<nsIFrameLoader> frameLoader = do_QueryInterface(aSubject);
|
||||
nsCOMPtr<nsIFrameLoader> myFrameLoader = mBrowserElement->GetFrameLoader();
|
||||
// The browser element API needs the frameloader to
|
||||
// initialize. We still use the observer to get notified when the
|
||||
// frameloader is created. So we check if the frameloader created
|
||||
// is ours, then initialize the browser element API.
|
||||
if (frameLoader && frameLoader == myFrameLoader) {
|
||||
mBrowserElement->InitBrowserElementAPI();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsBrowserElement::BrowserShownObserver::AddObserver()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->AddObserver(this, kRemoteBrowserPending, true);
|
||||
obs->AddObserver(this, kInprocessBrowserShown, true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsBrowserElement::BrowserShownObserver::RemoveObserver()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->RemoveObserver(this, kRemoteBrowserPending);
|
||||
obs->RemoveObserver(this, kInprocessBrowserShown);
|
||||
}
|
||||
mBrowserElement = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
nsBrowserElement::IsBrowserElementOrThrow(ErrorResult& aRv)
|
||||
{
|
||||
@ -145,18 +66,6 @@ nsBrowserElement::InitBrowserElementAPI()
|
||||
}
|
||||
}
|
||||
|
||||
nsBrowserElement::nsBrowserElement()
|
||||
: mOwnerIsWidget(false)
|
||||
{
|
||||
mObserver = new BrowserShownObserver(this);
|
||||
mObserver->AddObserver();
|
||||
}
|
||||
|
||||
nsBrowserElement::~nsBrowserElement()
|
||||
{
|
||||
mObserver->RemoveObserver();
|
||||
}
|
||||
|
||||
void
|
||||
nsBrowserElement::SetVisible(bool aVisible, ErrorResult& aRv)
|
||||
{
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "nsIBrowserElementAPI.h"
|
||||
|
||||
class nsFrameLoader;
|
||||
class nsIObserver;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -31,8 +30,8 @@ class ErrorResult;
|
||||
class nsBrowserElement
|
||||
{
|
||||
public:
|
||||
nsBrowserElement();
|
||||
virtual ~nsBrowserElement();
|
||||
nsBrowserElement() : mOwnerIsWidget(false) {}
|
||||
virtual ~nsBrowserElement() {}
|
||||
|
||||
void SetVisible(bool aVisible, ErrorResult& aRv);
|
||||
already_AddRefed<dom::DOMRequest> GetVisible(ErrorResult& aRv);
|
||||
@ -94,17 +93,13 @@ public:
|
||||
|
||||
protected:
|
||||
NS_IMETHOD_(already_AddRefed<nsFrameLoader>) GetFrameLoader() = 0;
|
||||
void InitBrowserElementAPI();
|
||||
nsCOMPtr<nsIBrowserElementAPI> mBrowserElementAPI;
|
||||
|
||||
private:
|
||||
void InitBrowserElementAPI();
|
||||
bool IsBrowserElementOrThrow(ErrorResult& aRv);
|
||||
bool IsNotWidgetOrThrow(ErrorResult& aRv);
|
||||
bool mOwnerIsWidget;
|
||||
|
||||
class BrowserShownObserver;
|
||||
friend class BrowserShownObserver;
|
||||
nsRefPtr<BrowserShownObserver> mObserver;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -499,3 +499,11 @@ nsGenericHTMLFrameElement::AllowCreateFrameLoader()
|
||||
mFrameLoaderCreationDisallowed = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericHTMLFrameElement::InitializeBrowserAPI()
|
||||
{
|
||||
MOZ_ASSERT(mFrameLoader);
|
||||
InitBrowserElementAPI();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -85,4 +85,10 @@ interface nsIMozBrowserFrame : nsIDOMMozBrowserFrame
|
||||
* It is an error to call this method if we already have a frame loader.
|
||||
*/
|
||||
void createRemoteFrameLoader(in nsITabParent aTabParent);
|
||||
|
||||
/**
|
||||
* Initialize the API, and add frame message listener to listen to API
|
||||
* invocations.
|
||||
*/
|
||||
[noscript] void initializeBrowserAPI();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user