Bug 727303 - Add nsPIDOMWindow::SetFullScreenInteral. r=roc

This commit is contained in:
Chris Pearce
2012-02-20 10:02:08 +13:00
parent 5352c8ded2
commit fe02b726c5
5 changed files with 29 additions and 10 deletions

View File

@@ -8532,7 +8532,7 @@ public:
NS_IMETHOD Run()
{
if (mDoc->GetWindow()) {
mDoc->GetWindow()->SetFullScreen(mValue);
mDoc->GetWindow()->SetFullScreenInternal(mValue, false);
}
return NS_OK;
}

View File

@@ -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();

View File

@@ -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<nsIDocShellTreeItem> treeItem = do_QueryInterface(mDocShell);
nsCOMPtr<nsIDocShellTreeItem> rootItem;
treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
nsCOMPtr<nsIDOMWindow> window = do_GetInterface(rootItem);
nsCOMPtr<nsPIDOMWindow> 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

View File

@@ -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

View File

@@ -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.