зеркало из https://github.com/mozilla/gecko-dev.git
Fix for Bug #57985 r=hyatt,ddrinan a=hyat
Have HandleDOMEvent gather some information about mouse left button down events and pass it on to the entropy collector.
This commit is contained in:
Родитель
54d0ebc2f9
Коммит
8c42fb78d0
|
@ -1,3 +1,4 @@
|
|||
domstubs.idl
|
||||
nsIScriptContextOwner.idl
|
||||
nsIScriptGlobalObjectOwner.idl
|
||||
nsIEntropyCollector.idl
|
||||
|
|
|
@ -27,6 +27,7 @@ DIRS=base coreDom coreEvents range events html css
|
|||
XPIDLSRCS = .\domstubs.idl \
|
||||
.\nsIScriptContextOwner.idl \
|
||||
.\nsIScriptGlobalObjectOwner.idl \
|
||||
.\nsIEntropyCollector.idl \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla code.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Javier Delgadillo <javi@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* Interface for an object that wants to gather "random"
|
||||
* data to be used for entropy purposes.
|
||||
*/
|
||||
%{C++
|
||||
|
||||
// Define CID {29a1d8b6-ac5a-11d4-9978-00b0d02354a0}
|
||||
#define NS_ENTROPYCOLLECTOR_CID \
|
||||
{ 0x29a1d8b6, 0xac5a, 0x11d4, \
|
||||
{ 0x00, 0xb0, 0xd0, 0x23, 0x54, 0xa0 } }
|
||||
|
||||
/*
|
||||
* If anyone wants to collect the entropy distributed by the
|
||||
* event handler, they'll have to implement this CONTRACTID
|
||||
*/
|
||||
#define NS_ENTROPYCOLLECTOR_CONTRACTID "@mozilla.org/security/entropy;1"
|
||||
%}
|
||||
/* Buffer type - for passing random data to the entropy
|
||||
* collector.
|
||||
*/
|
||||
[ptr] native buffer(void);
|
||||
|
||||
[uuid(6f883680-ab9d-11d4-9978-00b0d02354a0)]
|
||||
interface nsIEntropyCollector : nsISupports
|
||||
{
|
||||
|
||||
/**
|
||||
* Add the following bytes to the pool of data to be used
|
||||
* in gathering entropy.
|
||||
*/
|
||||
void randomUpdate(in buffer entropy, in long bufLen);
|
||||
|
||||
};
|
|
@ -98,6 +98,7 @@
|
|||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIComputedDOMStyle.h"
|
||||
#include "nsIEntropyCollector.h"
|
||||
#include "nsDOMCID.h"
|
||||
#include "nsDOMError.h"
|
||||
|
||||
|
@ -109,6 +110,9 @@
|
|||
#include "nsIXBLService.h"
|
||||
|
||||
|
||||
nsIEntropyCollector* gEntropyCollector = nsnull;
|
||||
PRInt32 gRefCnt = 0;
|
||||
|
||||
// CIDs
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
@ -138,6 +142,13 @@ GlobalWindowImpl::GlobalWindowImpl() :
|
|||
mChromeEventHandler(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
if (gRefCnt++ == 0) {
|
||||
nsCOMPtr<nsIEntropyCollector> enCol(do_GetService(NS_ENTROPYCOLLECTOR_CONTRACTID));
|
||||
if (enCol) {
|
||||
gEntropyCollector = enCol;
|
||||
NS_ADDREF(gEntropyCollector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlobalWindowImpl::~GlobalWindowImpl()
|
||||
|
@ -163,6 +174,9 @@ void GlobalWindowImpl::CleanUp()
|
|||
NS_IF_RELEASE(mLocation);
|
||||
NS_IF_RELEASE(mFrames);
|
||||
mOpener = nsnull; // Forces Release
|
||||
if (--gRefCnt == 0) {
|
||||
NS_IF_RELEASE(gEntropyCollector);
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
|
@ -473,6 +487,24 @@ NS_IMETHODIMP GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
|
|||
nsCOMPtr<nsIChromeEventHandler> kungFuDeathGrip1(mChromeEventHandler);
|
||||
nsCOMPtr<nsIScriptContext> kungFuDeathGrip2(mContext);
|
||||
|
||||
/* If this is a mouse event, use the struct to provide entropy for
|
||||
* the system.
|
||||
*/
|
||||
if (gEntropyCollector && !mChromeEventHandler &&
|
||||
(NS_EVENT_FLAG_BUBBLE != aFlags) &&
|
||||
(aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN)) {
|
||||
//Since the high bits seem to be zero's most of the time,
|
||||
//let's only take the lowest half of the point structure.
|
||||
PRInt16 myCoord[4];
|
||||
|
||||
myCoord[0] = aEvent->point.x;
|
||||
myCoord[1] = aEvent->point.y;
|
||||
myCoord[2] = aEvent->refPoint.x;
|
||||
myCoord[3] = aEvent->refPoint.y;
|
||||
gEntropyCollector->RandomUpdate((void*)myCoord, sizeof(myCoord));
|
||||
gEntropyCollector->RandomUpdate((void*)&aEvent->time, sizeof(PRUint32));
|
||||
}
|
||||
|
||||
if (NS_EVENT_FLAG_INIT & aFlags) {
|
||||
if (!aDOMEvent) {
|
||||
aDOMEvent = &domEvent;
|
||||
|
|
Загрузка…
Ссылка в новой задаче