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
|
||||
mInEnsureScriptEnv(false),
|
||||
#endif
|
||||
mCreated(false),
|
||||
mInitialized(false),
|
||||
mAllowSubframes(true),
|
||||
mAllowJavascript(true),
|
||||
mAllowMetaRedirects(true),
|
||||
@@ -460,6 +460,35 @@ nsDocShell::~nsDocShell() {
|
||||
#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 */
|
||||
already_AddRefed<nsDocShell> nsDocShell::Create(
|
||||
BrowsingContext* aBrowsingContext, uint64_t aContentWindowID) {
|
||||
@@ -4077,38 +4106,16 @@ nsDocShell::InitWindow(nativeWindow aParentNativeWindow,
|
||||
int32_t aWidth, int32_t aHeight) {
|
||||
SetParentWidget(aParentWidget);
|
||||
SetPositionAndSize(aX, aY, aWidth, aHeight, 0);
|
||||
NS_ENSURE_TRUE(Initialize(), NS_ERROR_FAILURE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::Create() {
|
||||
if (mCreated) {
|
||||
// We've already been created
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
// Implementations have been moved to nsDocShell::Initialize
|
||||
MOZ_DIAGNOSTIC_ASSERT(false);
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -194,11 +194,13 @@ class nsDocShell final : public nsDocLoader,
|
||||
NS_DECL_NSINETWORKINTERCEPTCONTROLLER
|
||||
NS_DECL_NSIDEPRECATIONWARNER
|
||||
|
||||
// Create a new nsDocShell object, initializing it.
|
||||
// Create a new nsDocShell object.
|
||||
static already_AddRefed<nsDocShell> Create(
|
||||
mozilla::dom::BrowsingContext* aBrowsingContext,
|
||||
uint64_t aContentWindowID = 0);
|
||||
|
||||
bool Initialize();
|
||||
|
||||
NS_IMETHOD Stop() override {
|
||||
// Need this here because otherwise nsIWebNavigation::Stop
|
||||
// overrides the docloader's Stop()
|
||||
@@ -1186,7 +1188,7 @@ class nsDocShell final : public nsDocLoader,
|
||||
bool mInEnsureScriptEnv;
|
||||
#endif
|
||||
|
||||
bool mCreated : 1;
|
||||
bool mInitialized : 1;
|
||||
bool mAllowSubframes : 1;
|
||||
bool mAllowJavascript : 1;
|
||||
bool mAllowMetaRedirects : 1;
|
||||
|
||||
@@ -978,10 +978,6 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* frame) {
|
||||
RefPtr<nsDocShell> baseWindow = GetDocShell();
|
||||
baseWindow->InitWindow(nullptr, view->GetWidget(), 0, 0, size.width,
|
||||
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);
|
||||
NS_ENSURE_TRUE(GetDocShell(), false);
|
||||
|
||||
@@ -2185,10 +2181,7 @@ nsresult nsFrameLoader::MaybeCreateDocShell() {
|
||||
nsGlobalWindowOuter::Cast(newWindow)->AllowScriptsToClose();
|
||||
}
|
||||
|
||||
// This is kinda whacky, this call doesn't really create anything,
|
||||
// but it must be called to make sure things are properly
|
||||
// initialized.
|
||||
if (NS_FAILED(docShell->Create())) {
|
||||
if (!docShell->Initialize()) {
|
||||
// Do not call Destroy() here. See bug 472312.
|
||||
NS_WARNING("Something wrong when creating the docshell for a frameloader!");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@@ -138,9 +138,6 @@ already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
|
||||
Unused << docShell->AddProgressListener(docShellTreeOwner,
|
||||
nsIWebProgress::NOTIFY_ALL);
|
||||
|
||||
NS_ENSURE_SUCCESS(
|
||||
docShell->InitWindow(nullptr, docShellParentWidget, 0, 0, 0, 0), nullptr);
|
||||
|
||||
docShell->SetTreeOwner(docShellTreeOwner);
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
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->AddChromeListeners();
|
||||
|
||||
@@ -240,7 +240,7 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
||||
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
||||
|
||||
// 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);
|
||||
|
||||
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(),
|
||||
r.Width(), r.Height()),
|
||||
NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(mDocShell->Create(), NS_ERROR_FAILURE);
|
||||
|
||||
// Attach a WebProgress listener.during initialization...
|
||||
mDocShell->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);
|
||||
|
||||
Reference in New Issue
Block a user