Bug 1653214 - Part 1: Merge implementations of nsDocShell::Create into nsDocShell::InitWindow; r=nika
Differential Revision: https://phabricator.services.mozilla.com/D83766
This commit is contained in:
@@ -371,7 +371,7 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mInEnsureScriptEnv(false),
|
mInEnsureScriptEnv(false),
|
||||||
#endif
|
#endif
|
||||||
mCreated(false),
|
mInitialized(false),
|
||||||
mAllowSubframes(true),
|
mAllowSubframes(true),
|
||||||
mAllowJavascript(true),
|
mAllowJavascript(true),
|
||||||
mAllowMetaRedirects(true),
|
mAllowMetaRedirects(true),
|
||||||
@@ -460,6 +460,35 @@ nsDocShell::~nsDocShell() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nsDocShell::Initialize() {
|
||||||
|
if (mInitialized) {
|
||||||
|
// We've already been initialized.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ASSERTION(mItemType == typeContent || mItemType == typeChrome,
|
||||||
|
"Unexpected item type in docshell");
|
||||||
|
|
||||||
|
NS_ENSURE_TRUE(Preferences::GetRootBranch(), false);
|
||||||
|
mInitialized = true;
|
||||||
|
|
||||||
|
mDisableMetaRefreshWhenInactive =
|
||||||
|
Preferences::GetBool("browser.meta_refresh_when_inactive.disabled",
|
||||||
|
mDisableMetaRefreshWhenInactive);
|
||||||
|
|
||||||
|
mDeviceSizeIsPageSize = Preferences::GetBool(
|
||||||
|
"docshell.device_size_is_page_size", mDeviceSizeIsPageSize);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
||||||
|
if (serv) {
|
||||||
|
const char* msg = mItemType == typeContent ? NS_WEBNAVIGATION_CREATE
|
||||||
|
: NS_CHROME_WEBNAVIGATION_CREATE;
|
||||||
|
serv->NotifyObservers(GetAsSupports(this), msg, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
already_AddRefed<nsDocShell> nsDocShell::Create(
|
already_AddRefed<nsDocShell> nsDocShell::Create(
|
||||||
BrowsingContext* aBrowsingContext, uint64_t aContentWindowID) {
|
BrowsingContext* aBrowsingContext, uint64_t aContentWindowID) {
|
||||||
@@ -4077,38 +4106,16 @@ nsDocShell::InitWindow(nativeWindow aParentNativeWindow,
|
|||||||
int32_t aWidth, int32_t aHeight) {
|
int32_t aWidth, int32_t aHeight) {
|
||||||
SetParentWidget(aParentWidget);
|
SetParentWidget(aParentWidget);
|
||||||
SetPositionAndSize(aX, aY, aWidth, aHeight, 0);
|
SetPositionAndSize(aX, aY, aWidth, aHeight, 0);
|
||||||
|
NS_ENSURE_TRUE(Initialize(), NS_ERROR_FAILURE);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocShell::Create() {
|
nsDocShell::Create() {
|
||||||
if (mCreated) {
|
// Implementations have been moved to nsDocShell::Initialize
|
||||||
// We've already been created
|
MOZ_DIAGNOSTIC_ASSERT(false);
|
||||||
return NS_OK;
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
|
||||||
|
|
||||||
NS_ASSERTION(mItemType == typeContent || mItemType == typeChrome,
|
|
||||||
"Unexpected item type in docshell");
|
|
||||||
|
|
||||||
NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
|
|
||||||
mCreated = true;
|
|
||||||
|
|
||||||
mDisableMetaRefreshWhenInactive =
|
|
||||||
Preferences::GetBool("browser.meta_refresh_when_inactive.disabled",
|
|
||||||
mDisableMetaRefreshWhenInactive);
|
|
||||||
|
|
||||||
mDeviceSizeIsPageSize = Preferences::GetBool(
|
|
||||||
"docshell.device_size_is_page_size", mDeviceSizeIsPageSize);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
|
||||||
if (serv) {
|
|
||||||
const char* msg = mItemType == typeContent ? NS_WEBNAVIGATION_CREATE
|
|
||||||
: NS_CHROME_WEBNAVIGATION_CREATE;
|
|
||||||
serv->NotifyObservers(GetAsSupports(this), msg, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|||||||
@@ -194,11 +194,13 @@ class nsDocShell final : public nsDocLoader,
|
|||||||
NS_DECL_NSINETWORKINTERCEPTCONTROLLER
|
NS_DECL_NSINETWORKINTERCEPTCONTROLLER
|
||||||
NS_DECL_NSIDEPRECATIONWARNER
|
NS_DECL_NSIDEPRECATIONWARNER
|
||||||
|
|
||||||
// Create a new nsDocShell object, initializing it.
|
// Create a new nsDocShell object.
|
||||||
static already_AddRefed<nsDocShell> Create(
|
static already_AddRefed<nsDocShell> Create(
|
||||||
mozilla::dom::BrowsingContext* aBrowsingContext,
|
mozilla::dom::BrowsingContext* aBrowsingContext,
|
||||||
uint64_t aContentWindowID = 0);
|
uint64_t aContentWindowID = 0);
|
||||||
|
|
||||||
|
bool Initialize();
|
||||||
|
|
||||||
NS_IMETHOD Stop() override {
|
NS_IMETHOD Stop() override {
|
||||||
// Need this here because otherwise nsIWebNavigation::Stop
|
// Need this here because otherwise nsIWebNavigation::Stop
|
||||||
// overrides the docloader's Stop()
|
// overrides the docloader's Stop()
|
||||||
@@ -1186,7 +1188,7 @@ class nsDocShell final : public nsDocLoader,
|
|||||||
bool mInEnsureScriptEnv;
|
bool mInEnsureScriptEnv;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool mCreated : 1;
|
bool mInitialized : 1;
|
||||||
bool mAllowSubframes : 1;
|
bool mAllowSubframes : 1;
|
||||||
bool mAllowJavascript : 1;
|
bool mAllowJavascript : 1;
|
||||||
bool mAllowMetaRedirects : 1;
|
bool mAllowMetaRedirects : 1;
|
||||||
|
|||||||
@@ -978,10 +978,6 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* frame) {
|
|||||||
RefPtr<nsDocShell> baseWindow = GetDocShell();
|
RefPtr<nsDocShell> baseWindow = GetDocShell();
|
||||||
baseWindow->InitWindow(nullptr, view->GetWidget(), 0, 0, size.width,
|
baseWindow->InitWindow(nullptr, view->GetWidget(), 0, 0, size.width,
|
||||||
size.height);
|
size.height);
|
||||||
// This is kinda whacky, this "Create()" call doesn't really
|
|
||||||
// create anything, one starts to wonder why this was named
|
|
||||||
// "Create"...
|
|
||||||
baseWindow->Create();
|
|
||||||
baseWindow->SetVisibility(true);
|
baseWindow->SetVisibility(true);
|
||||||
NS_ENSURE_TRUE(GetDocShell(), false);
|
NS_ENSURE_TRUE(GetDocShell(), false);
|
||||||
|
|
||||||
@@ -2185,10 +2181,7 @@ nsresult nsFrameLoader::MaybeCreateDocShell() {
|
|||||||
nsGlobalWindowOuter::Cast(newWindow)->AllowScriptsToClose();
|
nsGlobalWindowOuter::Cast(newWindow)->AllowScriptsToClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is kinda whacky, this call doesn't really create anything,
|
if (!docShell->Initialize()) {
|
||||||
// but it must be called to make sure things are properly
|
|
||||||
// initialized.
|
|
||||||
if (NS_FAILED(docShell->Create())) {
|
|
||||||
// Do not call Destroy() here. See bug 472312.
|
// Do not call Destroy() here. See bug 472312.
|
||||||
NS_WARNING("Something wrong when creating the docshell for a frameloader!");
|
NS_WARNING("Something wrong when creating the docshell for a frameloader!");
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|||||||
@@ -138,9 +138,6 @@ already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
|
|||||||
Unused << docShell->AddProgressListener(docShellTreeOwner,
|
Unused << docShell->AddProgressListener(docShellTreeOwner,
|
||||||
nsIWebProgress::NOTIFY_ALL);
|
nsIWebProgress::NOTIFY_ALL);
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(
|
|
||||||
docShell->InitWindow(nullptr, docShellParentWidget, 0, 0, 0, 0), nullptr);
|
|
||||||
|
|
||||||
docShell->SetTreeOwner(docShellTreeOwner);
|
docShell->SetTreeOwner(docShellTreeOwner);
|
||||||
|
|
||||||
// If the webbrowser is a content docshell item then we won't hear any
|
// If the webbrowser is a content docshell item then we won't hear any
|
||||||
@@ -152,7 +149,10 @@ already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
|
|||||||
aBrowsingContext->InitSessionHistory();
|
aBrowsingContext->InitSessionHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(docShell->Create(), nullptr);
|
nsresult rv = docShell->InitWindow(nullptr, docShellParentWidget, 0, 0, 0, 0);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
docShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0)
|
docShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0)
|
||||||
docShellTreeOwner->AddChromeListeners();
|
docShellTreeOwner->AddChromeListeners();
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
|||||||
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
// Make sure to set the item type on the docshell _before_ calling
|
// Make sure to set the item type on the docshell _before_ calling
|
||||||
// Create() so it knows what type it is.
|
// InitWindow() so it knows what type it is.
|
||||||
NS_ENSURE_SUCCESS(EnsureChromeTreeOwner(), NS_ERROR_FAILURE);
|
NS_ENSURE_SUCCESS(EnsureChromeTreeOwner(), NS_ERROR_FAILURE);
|
||||||
|
|
||||||
mDocShell->SetTreeOwner(mChromeTreeOwner);
|
mDocShell->SetTreeOwner(mChromeTreeOwner);
|
||||||
@@ -249,7 +249,6 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
|||||||
NS_ENSURE_SUCCESS(mDocShell->InitWindow(nullptr, mWindow, r.X(), r.Y(),
|
NS_ENSURE_SUCCESS(mDocShell->InitWindow(nullptr, mWindow, r.X(), r.Y(),
|
||||||
r.Width(), r.Height()),
|
r.Width(), r.Height()),
|
||||||
NS_ERROR_FAILURE);
|
NS_ERROR_FAILURE);
|
||||||
NS_ENSURE_SUCCESS(mDocShell->Create(), NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
// Attach a WebProgress listener.during initialization...
|
// Attach a WebProgress listener.during initialization...
|
||||||
mDocShell->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);
|
mDocShell->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);
|
||||||
|
|||||||
Reference in New Issue
Block a user