mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 755245 - Implement System Message Handler : Part 2, Add a getApp() method to nsGlobalWindow [r=mounir]
This commit is contained in:
parent
98fe91c4f9
commit
c5aa869164
@ -64,6 +64,7 @@
|
||||
#include "sampler.h"
|
||||
#include "nsDOMBlobBuilder.h"
|
||||
#include "nsIDOMFileHandle.h"
|
||||
#include "nsIDOMApplicationRegistry.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@ -2569,3 +2570,16 @@ nsDOMWindowUtils::SetApp(const nsAString& aManifestURL)
|
||||
|
||||
return static_cast<nsGlobalWindow*>(window.get())->SetApp(aManifestURL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetApp(mozIDOMApplication** aApplication)
|
||||
{
|
||||
if (!IsUniversalXPConnectCapable()) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
return static_cast<nsGlobalWindow*>(window.get())->GetApp(aApplication);
|
||||
}
|
||||
|
@ -10678,22 +10678,14 @@ nsGlobalWindow::SetIsApp(bool aValue)
|
||||
bool
|
||||
nsGlobalWindow::IsPartOfApp()
|
||||
{
|
||||
FORWARD_TO_OUTER(IsPartOfApp, (), TriState_False);
|
||||
mozIDOMApplication* app;
|
||||
nsresult rv = GetApp(&app);
|
||||
|
||||
// We go trough all window parents until we find one with |mIsApp| set to
|
||||
// something. If none is found, we are not part of an application.
|
||||
for (nsGlobalWindow* w = this; w;
|
||||
w = static_cast<nsGlobalWindow*>(w->GetParentInternal())) {
|
||||
if (w->mIsApp == TriState_True) {
|
||||
// The window should be part of an application.
|
||||
MOZ_ASSERT(w->mApp);
|
||||
return true;
|
||||
} else if (w->mIsApp == TriState_False) {
|
||||
return false;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return app != nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -10723,6 +10715,30 @@ nsGlobalWindow::SetApp(const nsAString& aManifestURL)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::GetApp(mozIDOMApplication** aApplication)
|
||||
{
|
||||
*aApplication = nsnull;
|
||||
|
||||
FORWARD_TO_OUTER(GetApp, (aApplication), NS_OK);
|
||||
|
||||
// We go trough all window parents until we find one with |mIsApp| set to
|
||||
// something. If none is found, we are not part of an application.
|
||||
for (nsGlobalWindow* w = this; w;
|
||||
w = static_cast<nsGlobalWindow*>(w->GetParentInternal())) {
|
||||
if (w->mIsApp == TriState_True) {
|
||||
// The window should be part of an application.
|
||||
MOZ_ASSERT(w->mApp);
|
||||
NS_IF_ADDREF(*aApplication = w->mApp);
|
||||
return NS_OK;
|
||||
} else if (w->mIsApp == TriState_False) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsGlobalChromeWindow implementation
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow)
|
||||
|
@ -894,6 +894,7 @@ protected:
|
||||
|
||||
void SetIsApp(bool aValue);
|
||||
nsresult SetApp(const nsAString& aManifestURL);
|
||||
nsresult GetApp(mozIDOMApplication** aApplication);
|
||||
|
||||
// Implements Get{Real,Scriptable}Top.
|
||||
nsresult GetTopImpl(nsIDOMWindow **aWindow, bool aScriptable);
|
||||
|
@ -38,6 +38,7 @@ interface nsIDOMFile;
|
||||
interface nsIFile;
|
||||
interface nsIDOMTouch;
|
||||
interface nsIDOMClientRect;
|
||||
interface mozIDOMApplication;
|
||||
|
||||
[scriptable, uuid(858578f1-9653-4d5c-821a-07479bf2d9b2)]
|
||||
interface nsIDOMWindowUtils : nsISupports {
|
||||
@ -1165,4 +1166,9 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
* or isn't the manifest URL of an installed application.
|
||||
*/
|
||||
void setApp(in DOMString manifestURL);
|
||||
/**
|
||||
* Retrieves the Application object associated to this window.
|
||||
* Can be null if |setApp()| has not been called.
|
||||
*/
|
||||
mozIDOMApplication getApp();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user