b=311290, add redraw() method to windowutils for performance testing and expose windowutils to content, r=roc,sr=jst

This commit is contained in:
vladimir%pobox.com 2005-10-21 22:30:36 +00:00
parent 04153159a6
commit ab0a7304ab
4 changed files with 64 additions and 8 deletions

View File

@ -38,12 +38,14 @@
#include "nsISupports.idl"
/**
* nsIDOMWindowUtils is intended for giving privileged script access to
* additional properties and methods of nsIDOMWindow unavailable to
* content script. Access this interface by calling getInterface on a DOMWindow.
* nsIDOMWindowUtils is intended for infrequently-used methods related
* to the current nsIDOMWindow. Some of the methods may require
* elevated privileges; the method implementations should contain the
* necessary security checks. Access this interface by calling
* getInterface on a DOMWindow.
*/
[scriptable, uuid(8a157a4f-a81e-489f-baf2-bc8970d60472)]
[scriptable, uuid(cc7f4216-ad89-4687-a793-980662bd10bd)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -69,6 +71,14 @@ interface nsIDOMWindowUtils : nsISupports {
* Function to get metadata associated with the window's current document
* @param aName the name of the metadata. This should be all lowercase.
* @return the value of the metadata, or the empty string if it's not set
*
* Will throw a DOM security error if called without UniversalXPConnect
* privileges.
*/
AString getDocumentMetadata(in AString aName);
/**
* Force an immediate redraw of this window.
*/
void redraw();
};

View File

@ -352,6 +352,9 @@ enum nsDOMClassInfoID {
// PageTransition Events
eDOMClassInfo_PageTransitionEvent_id,
// WindowUtils
eDOMClassInfo_WindowUtils_id,
// Define this near the end so that enabling/disabling foreignobject doesn't
// break binary compatibility
#if defined(MOZ_SVG) && defined(MOZ_SVG_FOREIGNOBJECT)

View File

@ -76,6 +76,7 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMEventListener.h"
#include "nsContentUtils.h"
#include "nsDOMWindowUtils.h"
// Window scriptable helper includes
#include "nsIDocShell.h"
@ -1049,10 +1050,12 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif // MOZ_ENABLE_CANVAS
NS_DEFINE_CLASSINFO_DATA(SmartCardEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(PageTransitionEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SmartCardEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(PageTransitionEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WindowUtils, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
// Define MOZ_SVG_FOREIGNOBJECT here so that when it gets switched on,
// we preserve binary compatibility. New classes should be added
@ -1674,6 +1677,10 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WindowUtils, nsIDOMWindowUtils)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowUtils)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Location, nsIDOMLocation)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLocation)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSLocation)

View File

@ -37,15 +37,22 @@
#include "nsIDocShell.h"
#include "nsPresContext.h"
#include "nsDOMClassInfo.h"
#include "nsDOMError.h"
#include "nsDOMWindowUtils.h"
#include "nsGlobalWindow.h"
#include "nsIDocument.h"
#include "nsContentUtils.h"
#include "nsIFrame.h"
NS_INTERFACE_MAP_BEGIN(nsDOMWindowUtils)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWindowUtils)
NS_INTERFACE_MAP_ENTRY(nsIDOMWindowUtils)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WindowUtils)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMWindowUtils)
@ -100,6 +107,11 @@ NS_IMETHODIMP
nsDOMWindowUtils::GetDocumentMetadata(const nsAString& aName,
nsAString& aValue)
{
PRBool hasCap = PR_FALSE;
if (NS_FAILED(nsContentUtils::SecurityManager()->IsCapabilityEnabled("UniversalXPConnect", &hasCap))
|| !hasCap)
return NS_ERROR_DOM_SECURITY_ERR;
if (mWindow) {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
if (doc) {
@ -112,3 +124,27 @@ nsDOMWindowUtils::GetDocumentMetadata(const nsAString& aName,
aValue.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::Redraw()
{
nsresult rv;
nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
if (docShell) {
nsCOMPtr<nsIPresShell> presShell;
rv = docShell->GetPresShell(getter_AddRefs(presShell));
if (NS_SUCCEEDED(rv) && presShell) {
nsIFrame *rootFrame = presShell->GetRootFrame();
if (rootFrame) {
nsRect r(nsPoint(0, 0), rootFrame->GetSize());
rootFrame->Invalidate(r, PR_TRUE);
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}