зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1782751 - Make desktop viewport mode a synced BrowsingContext field. r=twisniewski
So that it's preserved properly across replacements (bug 1781936). Differential Revision: https://phabricator.services.mozilla.com/D155274
This commit is contained in:
Родитель
e32b8c70e9
Коммит
c20ec755c9
|
@ -161,6 +161,7 @@ enum class ExplicitActiveStatus : uint8_t {
|
|||
FIELD(UseGlobalHistory, bool) \
|
||||
FIELD(TargetTopLevelLinkClicksToBlankInternal, bool) \
|
||||
FIELD(FullscreenAllowedByOwner, bool) \
|
||||
FIELD(ForceDesktopViewport, bool) \
|
||||
/* \
|
||||
* "is popup" in the spec. \
|
||||
* Set only on top browsing contexts. \
|
||||
|
@ -587,6 +588,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
|
|||
aRv);
|
||||
}
|
||||
|
||||
bool ForceDesktopViewport() const { return GetForceDesktopViewport(); }
|
||||
|
||||
bool AuthorStyleDisabledDefault() const {
|
||||
return GetAuthorStyleDisabledDefault();
|
||||
}
|
||||
|
@ -1180,6 +1183,16 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
|
|||
ContentParent* aSource);
|
||||
void DidSet(FieldIndex<IDX_AllowJavascript>, bool aOldValue);
|
||||
|
||||
bool CanSet(FieldIndex<IDX_ForceDesktopViewport>, bool aValue,
|
||||
ContentParent* aSource) {
|
||||
return IsTop() && XRE_IsParentProcess();
|
||||
}
|
||||
|
||||
// TODO(emilio): Maybe handle the flag being set dynamically without
|
||||
// navigating? The previous code didn't do it tho, and a reload is probably
|
||||
// worth it regardless.
|
||||
// void DidSet(FieldIndex<IDX_ForceDesktopViewport>, bool aOldValue);
|
||||
|
||||
bool CanSet(FieldIndex<IDX_HasRestoreData>, bool aNewValue,
|
||||
ContentParent* aSource);
|
||||
|
||||
|
|
|
@ -323,6 +323,7 @@ void CanonicalBrowsingContext::ReplacedBy(
|
|||
txn.SetUserAgentOverride(GetUserAgentOverride());
|
||||
txn.SetSuspendMediaWhenInactive(GetSuspendMediaWhenInactive());
|
||||
txn.SetDisplayMode(GetDisplayMode());
|
||||
txn.SetForceDesktopViewport(GetForceDesktopViewport());
|
||||
|
||||
// As this is a different BrowsingContext, set InitialSandboxFlags to the
|
||||
// current flags in the new context so that they also apply to any initial
|
||||
|
|
|
@ -10230,7 +10230,7 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
|
|||
nsPresContext* context = mPresShell->GetPresContext();
|
||||
// When querying the full zoom, get it from the device context rather than
|
||||
// directly from the pres context, because the device context's value can
|
||||
// include an adjustment necessay to keep the number of app units per device
|
||||
// include an adjustment necessary to keep the number of app units per device
|
||||
// pixel an integer, and we want the adjusted value.
|
||||
float fullZoom = context ? context->DeviceContext()->GetFullZoom() : 1.0;
|
||||
fullZoom = (fullZoom == 0.0) ? 1.0 : fullZoom;
|
||||
|
@ -10243,8 +10243,8 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
|
|||
// Special behaviour for desktop mode, provided we are not on an about: page,
|
||||
// or fullscreen.
|
||||
const bool fullscreen = Fullscreen();
|
||||
nsPIDOMWindowOuter* win = GetWindow();
|
||||
if (win && win->IsDesktopModeViewport() && !IsAboutPage() && !fullscreen) {
|
||||
auto* bc = GetBrowsingContext();
|
||||
if (bc && bc->ForceDesktopViewport() && !IsAboutPage() && !fullscreen) {
|
||||
CSSCoord viewportWidth =
|
||||
StaticPrefs::browser_viewport_desktopWidth() / fullZoom;
|
||||
CSSToScreenScale scaleToFit(aDisplaySize.width / viewportWidth);
|
||||
|
@ -10401,11 +10401,10 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
|
|||
// default size has a complicated calculation, we fixup the maxWidth
|
||||
// value after setting it, above.
|
||||
if (maxWidth == nsViewportInfo::Auto && !mValidScaleFloat) {
|
||||
BrowsingContext* bc = GetBrowsingContext();
|
||||
if (bc && bc->TouchEventsOverride() == TouchEventsOverride::Enabled &&
|
||||
bc->InRDMPane()) {
|
||||
// If RDM and touch simulation are active, then use the simulated
|
||||
// screen width to accomodate for cases where the screen width is
|
||||
// screen width to accommodate for cases where the screen width is
|
||||
// larger than the desktop viewport default.
|
||||
maxWidth = nsViewportInfo::Max(
|
||||
displaySize.width, StaticPrefs::browser_viewport_desktopWidth());
|
||||
|
|
|
@ -2601,22 +2601,6 @@ nsDOMWindowUtils::IsInModalState(bool* retval) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetDesktopModeViewport(bool* retval) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
*retval = window && window->IsDesktopModeViewport();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SetDesktopModeViewport(bool aDesktopMode) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(window);
|
||||
|
||||
window->SetDesktopModeViewport(aDesktopMode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SuspendTimeouts() {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
|
||||
|
|
|
@ -7579,7 +7579,6 @@ nsPIDOMWindowOuter::nsPIDOMWindowOuter(uint64_t aWindowID)
|
|||
mModalStateDepth(0),
|
||||
mSuppressEventHandlingDepth(0),
|
||||
mIsBackground(false),
|
||||
mDesktopModeViewport(false),
|
||||
mIsRootOuterWindow(false),
|
||||
mInnerWindow(nullptr),
|
||||
mWindowID(aWindowID),
|
||||
|
|
|
@ -803,10 +803,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
|
|||
mozilla::dom::Element* GetFrameElementInternal() const;
|
||||
void SetFrameElementInternal(mozilla::dom::Element* aFrameElement);
|
||||
|
||||
void SetDesktopModeViewport(bool aDesktopModeViewport) {
|
||||
mDesktopModeViewport = aDesktopModeViewport;
|
||||
}
|
||||
bool IsDesktopModeViewport() const { return mDesktopModeViewport; }
|
||||
bool IsBackground() { return mIsBackground; }
|
||||
|
||||
// Audio API
|
||||
|
@ -1166,9 +1162,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
|
|||
// "active".
|
||||
bool mIsBackground;
|
||||
|
||||
// current desktop mode flag.
|
||||
bool mDesktopModeViewport;
|
||||
|
||||
bool mIsRootOuterWindow;
|
||||
|
||||
// And these are the references between inner and outer windows.
|
||||
|
|
|
@ -220,6 +220,12 @@ interface BrowsingContext {
|
|||
*/
|
||||
[SetterThrows] attribute boolean allowJavascript;
|
||||
|
||||
/**
|
||||
* Determines whether we're forcing a desktop-mode viewport. Only settable in
|
||||
* the top browsing context from the parent process.
|
||||
*/
|
||||
[SetterThrows] attribute boolean forceDesktopViewport;
|
||||
|
||||
/*
|
||||
* Default load flags (as defined in nsIRequest) that will be set on all
|
||||
* requests made by this BrowsingContext.
|
||||
|
|
|
@ -1502,11 +1502,6 @@ interface nsIDOMWindowUtils : nsISupports {
|
|||
*/
|
||||
boolean isInModalState();
|
||||
|
||||
/**
|
||||
* Internal desktopMode flag.
|
||||
*/
|
||||
attribute boolean desktopModeViewport;
|
||||
|
||||
/**
|
||||
* Suspend/resume timeouts on this window and its descendant windows.
|
||||
*/
|
||||
|
|
|
@ -12,10 +12,6 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
|
|||
|
||||
const EXPORTED_SYMBOLS = ["GeckoViewSettingsChild"];
|
||||
|
||||
// This needs to match GeckoSessionSettings.java
|
||||
const VIEWPORT_MODE_MOBILE = 0;
|
||||
const VIEWPORT_MODE_DESKTOP = 1;
|
||||
|
||||
// Handles GeckoView content settings
|
||||
class GeckoViewSettingsChild extends GeckoViewActorChild {
|
||||
receiveMessage(message) {
|
||||
|
@ -26,7 +22,6 @@ class GeckoViewSettingsChild extends GeckoViewActorChild {
|
|||
case "SettingsUpdate": {
|
||||
const settings = message.data;
|
||||
|
||||
this.viewportMode = settings.viewportMode;
|
||||
if (settings.isPopup) {
|
||||
// Allow web extensions to close their own action popups (bz1612363)
|
||||
this.contentWindow.windowUtils.allowScriptsToClose();
|
||||
|
@ -34,14 +29,6 @@ class GeckoViewSettingsChild extends GeckoViewActorChild {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
set viewportMode(aMode) {
|
||||
const { windowUtils } = this.contentWindow;
|
||||
if (aMode === windowUtils.desktopModeViewport) {
|
||||
return;
|
||||
}
|
||||
windowUtils.desktopModeViewport = aMode === VIEWPORT_MODE_DESKTOP;
|
||||
}
|
||||
}
|
||||
|
||||
const { debug, warn } = GeckoViewSettingsChild.initLogging("GeckoViewSettings");
|
||||
|
|
|
@ -1187,6 +1187,20 @@ class NavigationDelegateTest : BaseSessionTest() {
|
|||
assertThat("innerWidth should be equal to $desktopInnerWidth", innerWidth,
|
||||
closeTo(desktopInnerWidth, 0.1))
|
||||
|
||||
mainSession.loadTestPath(HELLO_HTML_PATH)
|
||||
mainSession.waitForPageStop()
|
||||
|
||||
innerWidth = mainSession.evaluateJS(innerWidthJs) as Double
|
||||
assertThat("after navigation innerWidth should be equal to $desktopInnerWidth",
|
||||
innerWidth, closeTo(desktopInnerWidth, 0.1))
|
||||
|
||||
mainSession.loadTestPath(VIEWPORT_PATH)
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
innerWidth = mainSession.evaluateJS(innerWidthJs) as Double
|
||||
assertThat("after navigting back innerWidth should be equal to $desktopInnerWidth",
|
||||
innerWidth, closeTo(desktopInnerWidth, 0.1))
|
||||
|
||||
mainSession.settings.viewportMode = GeckoSessionSettings.VIEWPORT_MODE_MOBILE
|
||||
|
||||
mainSession.reload()
|
||||
|
|
|
@ -44,6 +44,10 @@ const DISPLAY_MODE_MINIMAL_UI = 1;
|
|||
const DISPLAY_MODE_STANDALONE = 2;
|
||||
const DISPLAY_MODE_FULLSCREEN = 3;
|
||||
|
||||
// This needs to match GeckoSessionSettings.java
|
||||
const VIEWPORT_MODE_MOBILE = 0;
|
||||
const VIEWPORT_MODE_DESKTOP = 1;
|
||||
|
||||
// Handles GeckoSession settings.
|
||||
class GeckoViewSettings extends GeckoViewModule {
|
||||
onInit() {
|
||||
|
@ -76,6 +80,7 @@ class GeckoViewSettings extends GeckoViewModule {
|
|||
this.sessionContextId = settings.sessionContextId;
|
||||
this.suspendMediaWhenInactive = settings.suspendMediaWhenInactive;
|
||||
this.allowJavascript = settings.allowJavascript;
|
||||
this.viewportMode = settings.viewportMode;
|
||||
this.useTrackingProtection = !!settings.useTrackingProtection;
|
||||
|
||||
// When the page is loading from the main process (e.g. from an extension
|
||||
|
@ -111,6 +116,11 @@ class GeckoViewSettings extends GeckoViewModule {
|
|||
this.browsingContext.useTrackingProtection = aUse;
|
||||
}
|
||||
|
||||
set viewportMode(aViewportMode) {
|
||||
this.browsingContext.forceDesktopViewport =
|
||||
aViewportMode == VIEWPORT_MODE_DESKTOP;
|
||||
}
|
||||
|
||||
get userAgentMode() {
|
||||
return this._userAgentMode;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче