diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index e908dc4476f2..d8ca57634538 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -8532,7 +8532,7 @@ public: NS_IMETHOD Run() { if (mDoc->GetWindow()) { - mDoc->GetWindow()->SetFullScreen(mValue); + mDoc->GetWindow()->SetFullScreenInternal(mValue, false); } return NS_OK; } diff --git a/content/html/content/test/test_fullscreen-api.html b/content/html/content/test/test_fullscreen-api.html index e65da921d1de..fe84d0d4ca8e 100644 --- a/content/html/content/test/test_fullscreen-api.html +++ b/content/html/content/test/test_fullscreen-api.html @@ -70,6 +70,12 @@ function nextTest() { } } +try { + window.fullScreen = true; +} catch (e) { +} +is(window.fullScreen, false, "Shouldn't be able to set window fullscreen from content"); + addLoadEvent(nextTest); SimpleTest.waitForExplicitFinish(); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 589f9a0c893e..02592097aaf1 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -4457,6 +4457,12 @@ nsGlobalWindow::GetNearestWidget() NS_IMETHODIMP nsGlobalWindow::SetFullScreen(bool aFullScreen) +{ + return SetFullScreenInternal(aFullScreen, true); +} + +nsresult +nsGlobalWindow::SetFullScreenInternal(bool aFullScreen, bool aRequireTrust) { FORWARD_TO_OUTER(SetFullScreen, (aFullScreen), NS_ERROR_NOT_INITIALIZED); @@ -4464,11 +4470,10 @@ nsGlobalWindow::SetFullScreen(bool aFullScreen) bool rootWinFullScreen; GetFullScreen(&rootWinFullScreen); - // Only chrome can change our fullScreen mode, unless the DOM full-screen - // API is enabled. - if ((aFullScreen == rootWinFullScreen || - !nsContentUtils::IsCallerTrustedForWrite()) && - !nsContentUtils::IsFullScreenApiEnabled()) { + // Only chrome can change our fullScreen mode, unless we're running in + // untrusted mode. + if (aFullScreen == rootWinFullScreen || + (aRequireTrust && !nsContentUtils::IsCallerTrustedForWrite())) { return NS_OK; } @@ -4478,11 +4483,11 @@ nsGlobalWindow::SetFullScreen(bool aFullScreen) nsCOMPtr treeItem = do_QueryInterface(mDocShell); nsCOMPtr rootItem; treeItem->GetRootTreeItem(getter_AddRefs(rootItem)); - nsCOMPtr window = do_GetInterface(rootItem); + nsCOMPtr window = do_GetInterface(rootItem); if (!window) return NS_ERROR_FAILURE; if (rootItem != treeItem) - return window->SetFullScreen(aFullScreen); + return window->SetFullScreenInternal(aFullScreen, aRequireTrust); // make sure we don't try to set full screen on a non-chrome window, // which might happen in embedding world diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index a145c86e87c7..6b254237400d 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -398,6 +398,7 @@ public: virtual NS_HIDDEN_(void) MaybeUpdateTouchState(); virtual NS_HIDDEN_(void) UpdateTouchState(); virtual NS_HIDDEN_(bool) DispatchCustomEvent(const char *aEventName); + virtual NS_HIDDEN_(nsresult) SetFullScreenInternal(bool aIsFullScreen, bool aRequireTrust); // nsIDOMStorageIndexedDB NS_DECL_NSIDOMSTORAGEINDEXEDDB diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 18d11380719f..fdfceabc72d2 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -80,8 +80,8 @@ class nsIArray; class nsPIWindowRoot; #define NS_PIDOMWINDOW_IID \ -{ 0x1352de12, 0x7a07, 0x4610, \ - { 0x93, 0xd5, 0xb8, 0x76, 0xfe, 0x93, 0x09, 0x50 } } +{ 0x9aef58e9, 0x5225, 0x4e58, \ + { 0x9a, 0xfb, 0xe6, 0x63, 0x97, 0x1d, 0x86, 0x88 } } class nsPIDOMWindow : public nsIDOMWindowInternal { @@ -457,6 +457,13 @@ public: return mMayHaveTouchEventListener; } + /** + * Moves the top-level window into fullscreen mode if aIsFullScreen is true, + * otherwise exits fullscreen. If aRequireTrust is true, this method only + * changes window state in a context trusted for write. + */ + virtual nsresult SetFullScreenInternal(bool aIsFullScreen, bool aRequireTrust) = 0; + /** * Call this to indicate that some node (this window, its document, * or content in that document) has a "MozAudioAvailable" event listener.