merging from cvs-trunk-mirror

--HG--
rename : js/src/js.c => js/src/js.cpp
rename : js/src/jsapi.c => js/src/jsapi.cpp
rename : js/src/jsatom.c => js/src/jsatom.cpp
rename : js/src/jsbool.c => js/src/jsbool.cpp
rename : js/src/jscntxt.c => js/src/jscntxt.cpp
rename : js/src/jsemit.c => js/src/jsemit.cpp
rename : js/src/jsgc.c => js/src/jsgc.cpp
rename : js/src/jsinterp.c => js/src/jsinterp.cpp
rename : js/src/jsobj.c => js/src/jsobj.cpp
rename : js/src/jsopcode.c => js/src/jsopcode.cpp
rename : js/src/jsxml.c => js/src/jsxml.cpp
This commit is contained in:
edward.lee@engineering.uiuc.edu 2007-08-10 15:25:15 -07:00
commit 610500d38e
714 changed files with 10431 additions and 158845 deletions

View File

@ -134,7 +134,7 @@ endif # WINNT
ifeq ($(OS_ARCH),WINNT)
# we want to copy PDB files on Windows
MAKE_SYM_STORE_ARGS := -c
DUMP_SYMS_BIN := $(topsrcdir)/toolkit/airbag/tools/win32/dump_syms.exe
DUMP_SYMS_BIN := $(topsrcdir)/toolkit/crashreporter/tools/win32/dump_syms.exe
# PDB files don't get moved to dist, so we need to scan the whole objdir
MAKE_SYM_STORE_PATH := .
endif
@ -160,10 +160,10 @@ EXTRA_BUILDID := -$(MOZ_SYMBOLS_EXTRA_BUILDID)
endif
buildsymbols:
ifdef MOZ_AIRBAG
ifdef MOZ_CRASHREPORTER
echo building symbol store
mkdir -p $(DIST)/crashreporter-symbols/$(BUILDID)
$(PYTHON) $(topsrcdir)/toolkit/airbag/tools/symbolstore.py \
$(PYTHON) $(topsrcdir)/toolkit/crashreporter/tools/symbolstore.py \
$(MAKE_SYM_STORE_ARGS) -s $(topsrcdir) $(DUMP_SYMS_BIN) \
$(DIST)/crashreporter-symbols/$(BUILDID) \
$(MAKE_SYM_STORE_PATH) > \
@ -174,11 +174,11 @@ ifdef MOZ_AIRBAG
zip -r9D ../crashreporter-symbols-$(BUILDID).zip .
mv $(DIST)/crashreporter-symbols/crashreporter-symbols-$(BUILDID).zip \
$(topsrcdir)/../$(BUILDID)
endif # MOZ_AIRBAG
endif # MOZ_CRASHREPORTER
uploadsymbols:
ifdef MOZ_AIRBAG
$(topsrcdir)/toolkit/airbag/tools/upload_symbols.sh $(topsrcdir)/../$(BUILDID)/crashreporter-symbols-$(BUILDID).zip
ifdef MOZ_CRASHREPORTER
$(topsrcdir)/toolkit/crashreporter/tools/upload_symbols.sh $(topsrcdir)/../$(BUILDID)/crashreporter-symbols-$(BUILDID).zip
endif
ifeq ($(OS_ARCH),WINNT)

View File

@ -425,9 +425,6 @@ nsAccessibleWrap::CreateMaiInterfaces(void)
interfacesBits |= 1 << MAI_INTERFACE_ACTION;
}
PRUint32 accRole;
GetRole(&accRole);
//nsIAccessibleText
nsCOMPtr<nsIAccessibleText> accessInterfaceText;
QueryInterface(NS_GET_IID(nsIAccessibleText),
@ -478,15 +475,11 @@ nsAccessibleWrap::CreateMaiInterfaces(void)
if (!MustPrune(this)) { // These interfaces require children
//nsIAccessibleHypertext
PRInt32 linkCount = 0;
nsCOMPtr<nsIAccessibleHyperText> accessInterfaceHypertext;
QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
getter_AddRefs(accessInterfaceHypertext));
if (accessInterfaceHypertext) {
nsresult rv = accessInterfaceHypertext->GetLinks(&linkCount);
if (NS_SUCCEEDED(rv) && (linkCount > 0)) {
interfacesBits |= 1 << MAI_INTERFACE_HYPERTEXT;
}
interfacesBits |= 1 << MAI_INTERFACE_HYPERTEXT;
}
//nsIAccessibleTable
@ -912,25 +905,24 @@ refChildCB(AtkObject *aAtkObj, gint aChildIndex)
return nsnull;
}
nsresult rv;
nsCOMPtr<nsIAccessible> accChild;
nsCOMPtr<nsIAccessibleHyperText> hyperText;
accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
if (hyperText) {
// If HyperText, then number of links matches number of children
nsCOMPtr<nsIAccessibleHyperLink> hyperLink;
rv = hyperText->GetLink(aChildIndex, getter_AddRefs(hyperLink));
hyperText->GetLink(aChildIndex, getter_AddRefs(hyperLink));
accChild = do_QueryInterface(hyperLink);
}
else {
nsCOMPtr<nsIAccessibleText> accText;
accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText), getter_AddRefs(accText));
if (!accText) { // Accessible Text that is not HyperText has no children
rv = accWrap->GetChildAt(aChildIndex, getter_AddRefs(accChild));
accWrap->GetChildAt(aChildIndex, getter_AddRefs(accChild));
}
}
if (NS_FAILED(rv) || !accChild)
if (!accChild)
return nsnull;
AtkObject* childAtkObj = nsAccessibleWrap::GetAtkObject(accChild);

View File

@ -55,43 +55,3 @@ nsDocAccessibleWrap::~nsDocAccessibleWrap()
{
}
void nsDocAccessibleWrap::SetEditor(nsIEditor* aEditor)
{
// Recreate atkobject if editable interface is changing
PRBool needRecreate = mAtkObject && (mEditor != aEditor)
&& (!mEditor || !aEditor);
nsDocAccessible::SetEditor(aEditor);
if (needRecreate) {
// Get parent atkobject and index in parent
AtkObject* oldAtkObj = mAtkObject;
// getParentCB
AtkObject* parentAtkObj = atk_object_get_parent(oldAtkObj);
// getIndexInParentCB
PRInt32 index = atk_object_get_index_in_parent(oldAtkObj);
// Clear old atkobject
ShutdownAtkObject();
// Get new atkobject
GetAtkObject();
// Emit children_changed events
if (parentAtkObj && (index >= 0)) {
g_signal_emit_by_name(parentAtkObj, "children_changed::remove", index,
oldAtkObj, NULL);
g_signal_emit_by_name(parentAtkObj, "children_changed::add", index,
mAtkObject, NULL);
}
// Set every child's parent to new created atkobject
nsCOMPtr<nsIAccessible> accChild;
while (NextChild(accChild)) {
if (IsEmbeddedObject(accChild)) {
AtkObject* childAtkObj = nsAccessibleWrap::GetAtkObject(accChild);
atk_object_set_parent(childAtkObj, mAtkObject);
}
}
}
}

View File

@ -54,10 +54,6 @@ public:
nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell);
virtual ~nsDocAccessibleWrap();
// Override SetEditor because we need to recreate atkobject
// when editable interface is added/removed
void SetEditor(nsIEditor* aEditor);
PRBool mActivated;
};

View File

@ -97,10 +97,7 @@ setTextContentsCB(AtkEditableText *aText, const gchar *aString)
MAI_LOG_DEBUG(("EditableText: setTextContentsCB, aString=%s", aString));
NS_ConvertUTF8toUTF16 strContent(aString);
nsresult rv = accText->SetTextContents(strContent);
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceEditableText::SetTextContents, failed\n");
accText->SetTextContents(strContent);
}
void
@ -125,9 +122,7 @@ insertTextCB(AtkEditableText *aText,
// nsresult rv = accText->InsertText(strContent, aLength, &pos);
// *aPosition = pos;
nsresult rv = accText->InsertText(strContent, *aPosition);
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceEditableText::InsertText, failed\n");
accText->InsertText(strContent, *aPosition);
MAI_LOG_DEBUG(("EditableText: insert aString=%s, aLength=%d, aPosition=%d",
aString, aLength, *aPosition));
@ -148,9 +143,7 @@ copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
MAI_LOG_DEBUG(("EditableText: copyTextCB, aStartPos=%d, aEndPos=%d",
aStartPos, aEndPos));
nsresult rv = accText->CopyText(aStartPos, aEndPos);
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceEditableText::CopyText, failed\n");
accText->CopyText(aStartPos, aEndPos);
}
void
@ -167,9 +160,7 @@ cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
return;
MAI_LOG_DEBUG(("EditableText: cutTextCB, aStartPos=%d, aEndPos=%d",
aStartPos, aEndPos));
nsresult rv = accText->CutText(aStartPos, aEndPos);
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceEditableText::CutText, failed\n");
accText->CutText(aStartPos, aEndPos);
}
void
@ -187,9 +178,7 @@ deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
MAI_LOG_DEBUG(("EditableText: deleteTextCB, aStartPos=%d, aEndPos=%d",
aStartPos, aEndPos));
nsresult rv = accText->DeleteText(aStartPos, aEndPos);
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceEditableText::DeleteText, failed\n");
accText->DeleteText(aStartPos, aEndPos);
}
void
@ -206,7 +195,5 @@ pasteTextCB(AtkEditableText *aText, gint aPosition)
return;
MAI_LOG_DEBUG(("EditableText: pasteTextCB, aPosition=%d", aPosition));
nsresult rv = accText->PasteText(aPosition);
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceEditableText::PasteText, failed\n");
accText->PasteText(aPosition);
}

View File

@ -86,13 +86,13 @@ getLinkCountCB(AtkHypertext *aText)
if (!accWrap)
return -1;
nsCOMPtr<nsIAccessibleHyperText> accHyperlink;
nsCOMPtr<nsIAccessibleHyperText> hyperText;
accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
getter_AddRefs(accHyperlink));
NS_ENSURE_TRUE(accHyperlink, -1);
getter_AddRefs(hyperText));
NS_ENSURE_TRUE(hyperText, -1);
PRInt32 count = -1;
nsresult rv = accHyperlink->GetLinks(&count);
nsresult rv = hyperText->GetLinks(&count);
NS_ENSURE_SUCCESS(rv, -1);
return count;
@ -105,13 +105,13 @@ getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
if (!accWrap)
return -1;
nsCOMPtr<nsIAccessibleHyperText> accHyperlink;
nsCOMPtr<nsIAccessibleHyperText> hyperText;
accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
getter_AddRefs(accHyperlink));
NS_ENSURE_TRUE(accHyperlink, -1);
getter_AddRefs(hyperText));
NS_ENSURE_TRUE(hyperText, -1);
PRInt32 index = -1;
nsresult rv = accHyperlink->GetLinkIndex(aCharIndex, &index);
nsresult rv = hyperText->GetLinkIndex(aCharIndex, &index);
NS_ENSURE_SUCCESS(rv, -1);
return index;

View File

@ -256,12 +256,13 @@ getRunAttributesCB(AtkText *aText, gint aOffset,
nsCOMPtr<nsIAccessible> accessibleWithAttrs;
PRInt32 startOffset = 0, endOffset = 0;
nsresult rv = accText->GetAttributeRange(aOffset,
&startOffset, &endOffset,
getter_AddRefs(accessibleWithAttrs));
nsresult rv =
accText->GetAttributeRange(aOffset, &startOffset, &endOffset,
getter_AddRefs(accessibleWithAttrs));
*aStartOffset = startOffset;
*aEndOffset = endOffset;
NS_ENSURE_SUCCESS(rv, nsnull);
if (NS_FAILED(rv))
return nsnull;
return GetAttributeSet(accessibleWithAttrs);
}
@ -396,6 +397,7 @@ getTextSelectionCountCB(AtkText *aText)
nsCOMPtr<nsIAccessibleText> accText;
accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
getter_AddRefs(accText));
NS_ENSURE_TRUE(accText, nsnull);
PRInt32 selectionCount;
nsresult rv = accText->GetSelectionCount(&selectionCount);

View File

@ -77,9 +77,9 @@ ACCESSIBILITY_ATOM(deckFrame, "DeckFrame")
ACCESSIBILITY_ATOM(inlineBlockFrame, "InlineBlockFrame")
ACCESSIBILITY_ATOM(inlineFrame, "InlineFrame")
ACCESSIBILITY_ATOM(objectFrame, "ObjectFrame")
ACCESSIBILITY_ATOM(placeholderFrame, "PlaceholderFrame")
ACCESSIBILITY_ATOM(scrollFrame, "ScrollFrame")
ACCESSIBILITY_ATOM(textFrame, "TextFrame")
ACCESSIBILITY_ATOM(tableCaptionFrame, "TableCaptionFrame")
ACCESSIBILITY_ATOM(tableCellFrame, "TableCellFrame")
ACCESSIBILITY_ATOM(tableOuterFrame, "TableOuterFrame")

View File

@ -1385,8 +1385,14 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessible(nsIDOMNode *aNode,
}
if (tryFrame) {
if (frame->GetType() != nsAccessibilityAtoms::placeholderFrame &&
frame->GetRect().IsEmpty()) {
// Do not create accessible object subtrees for non-rendered table captions.
// This could not be done in nsTableCaptionFrame::GetAccessible() because the
// descendants of the table caption would still be created.
// By setting *aIsHidden = PR_TRUE we ensure that no descendant accessibles are created
if (frame->GetType() == nsAccessibilityAtoms::tableCaptionFrame &&
frame->GetRect().IsEmpty()) {
// XXX This is not the ideal place for this code, but right now there is
// no better place:
*aIsHidden = PR_TRUE;
return NS_OK;
}

View File

@ -39,64 +39,53 @@
#include "nsAccessible.h"
#include "nsAccessibleRelation.h"
#include "nsIAccessibleDocument.h"
#include "nsIDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMNSHTMLElement.h"
#include "nsIImageDocument.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIScrollableView.h"
#include "nsIViewManager.h"
#include "nsIWidget.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOM3Node.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMElement.h"
#include "nsHTMLLinkAccessible.h"
#include "nsISelection.h"
#include "nsISelectionController.h"
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsUnicharUtils.h"
#include "prdtoa.h"
#include "nsIDOMComment.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLBRElement.h"
#include "nsIAtom.h"
#include "nsGUIEvent.h"
#include "nsIDocShellTreeItem.h"
#include "nsHyperTextAccessibleWrap.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIDOMHTMLObjectElement.h"
#include "nsIDOMXULButtonElement.h"
#include "nsIDOMXULCheckboxElement.h"
#include "nsIAccessibleDocument.h"
#include "nsIAccessibleHyperText.h"
#include "nsAccessibleTreeWalker.h"
#include "nsIDOM3Node.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentXBL.h"
#include "nsIDOMDocumentTraversal.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMNodeFilter.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMNSHTMLElement.h"
#include "nsIDOMTreeWalker.h"
#include "nsIDOMXULButtonElement.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMXULElement.h"
#include "nsIDOMXULLabelElement.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsPIDOMWindow.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIForm.h"
#include "nsIFormControl.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsIFrame.h"
#include "nsIViewManager.h"
#include "nsIDocShellTreeItem.h"
#include "nsXPIDLString.h"
#include "nsUnicharUtils.h"
#include "prdtoa.h"
#include "nsIAtom.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIFocusController.h"
#include "nsAccessibleTreeWalker.h"
#include "nsIURI.h"
#include "nsIImageLoadingContent.h"
#include "nsITimer.h"
#include "nsIMutableArray.h"
#include "nsIDOMTreeWalker.h"
#include "nsIDOMDocumentTraversal.h"
#include "nsIDOMNodeFilter.h"
#include "nsIObserverService.h"
#include "nsIServiceManager.h"
#ifdef NS_DEBUG
#include "nsIFrameDebug.h"
@ -244,7 +233,7 @@ nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_ERROR_NO_INTERFACE;
}
return nsAccessNode::QueryInterface(aIID, aInstancePtr);
return nsAccessNodeWrap::QueryInterface(aIID, aInstancePtr);
}
nsAccessible::nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsAccessNodeWrap(aNode, aShell),
@ -2179,7 +2168,7 @@ nsAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
if (role == nsIAccessibleRole::ROLE_OUTLINE)
break;
if (role == nsIAccessibleRole::ROLE_OUTLINEITEM)
if (role == nsIAccessibleRole::ROLE_GROUPING)
++ groupLevel;
parent->GetParent(getter_AddRefs(nextParent));
@ -2289,6 +2278,10 @@ nsAccessible::GetFinalState(PRUint32 *aState, PRUint32 *aExtraState)
nsresult rv = GetState(aState, aExtraState);
NS_ENSURE_SUCCESS(rv, rv);
// Apply ARIA states to be sure accessible states will be overriden.
rv = GetARIAState(aState);
NS_ENSURE_SUCCESS(rv, rv);
// Set additional states which presence depends on another states.
if (aExtraState) {
if (!(*aState & nsIAccessibleStates::STATE_UNAVAILABLE)) {
@ -2311,8 +2304,7 @@ nsAccessible::GetFinalState(PRUint32 *aState, PRUint32 *aExtraState)
}
}
// Apply ARIA states to be sure accessible states will be overriden.
return GetARIAState(aState);
return NS_OK;
}
nsresult
@ -2678,11 +2670,13 @@ NS_IMETHODIMP nsAccessible::GetAccessibleRelated(PRUint32 aRelationType, nsIAcce
case nsIAccessibleRelation::RELATION_DEFAULT_BUTTON:
{
if (content->IsNodeOfType(nsINode::eHTML)) {
nsCOMPtr<nsIForm> form;
while ((form = do_QueryInterface(content)) == nsnull &&
(content = content->GetParent()) != nsnull) /* nothing */ ;
if (form) {
// HTML form controls implements nsIFormControl interface.
nsCOMPtr<nsIFormControl> control(do_QueryInterface(content));
if (control) {
nsCOMPtr<nsIDOMHTMLFormElement> htmlform;
control->GetForm(getter_AddRefs(htmlform));
nsCOMPtr<nsIForm> form(do_QueryInterface(htmlform));
if (form)
relatedNode = do_QueryInterface(form->GetDefaultSubmitElement());
}
}

View File

@ -1205,7 +1205,9 @@ nsDocAccessible::FireTextChangedEventOnDOMCharacterDataModified(nsIContent *aCon
nsCOMPtr<nsIAccessible> accessible;
nsresult rv = GetAccessibleInParentChain(node, getter_AddRefs(accessible));
if (NS_FAILED(rv) || !accessible)
nsCOMPtr<nsIAccessibleHyperText> hyperTextIface =
do_QueryInterface(accessible);
if (NS_FAILED(rv) || !hyperTextIface)
return;
nsRefPtr<nsHyperTextAccessible> textAccessible;
@ -1254,7 +1256,9 @@ nsDocAccessible::FireTextChangedEventOnDOMNodeInserted(nsIContent *aChild,
nsCOMPtr<nsIAccessible> accessible;
nsresult rv = GetAccessibleInParentChain(node, getter_AddRefs(accessible));
if (NS_FAILED(rv) || !accessible)
nsCOMPtr<nsIAccessibleHyperText> hyperTextIface =
do_QueryInterface(accessible);
if (NS_FAILED(rv) || !hyperTextIface)
return;
nsRefPtr<nsHyperTextAccessible> textAccessible;
@ -1312,7 +1316,9 @@ nsDocAccessible::FireTextChangedEventOnDOMNodeRemoved(nsIContent *aChild,
nsCOMPtr<nsIAccessible> accessible;
nsresult rv = GetAccessibleInParentChain(node, getter_AddRefs(accessible));
if (NS_FAILED(rv) || !accessible)
nsCOMPtr<nsIAccessibleHyperText> hyperTextIface =
do_QueryInterface(accessible);
if (NS_FAILED(rv) || !hyperTextIface)
return;
nsRefPtr<nsHyperTextAccessible> textAccessible;

View File

@ -79,42 +79,40 @@ nsresult nsHyperTextAccessible::QueryInterface(REFNSIID aIID, void** aInstancePt
nsCOMPtr<nsIDOMXULDocument> xulDoc(do_QueryInterface(mDOMNode));
if (mDOMNode && !xulDoc) {
// We need XUL doc check for now because for now nsDocAccessible must inherit from nsHyperTextAccessible
// in order for HTML document accessibles to get support for these interfaces
// We need XUL doc check for now because for now nsDocAccessible must
// inherit from nsHyperTextAccessible in order for HTML document accessibles
// to get support for these interfaces.
// However at some point we may push <body> to implement the interfaces and
// return nsDocAccessible to inherit from nsAccessibleWrap
// return nsDocAccessible to inherit from nsAccessibleWrap.
PRUint32 role = Role(this);
if (aIID.Equals(NS_GET_IID(nsIAccessibleText))) {
// If |this| contains any children
PRInt32 numChildren;
GetChildCount(&numChildren);
if (numChildren > 0) {
*aInstancePtr = static_cast<nsIAccessibleText*>(this);
NS_ADDREF_THIS();
return NS_OK;
if (role == nsIAccessibleRole::ROLE_TEXT_LEAF) {
return NS_ERROR_NO_INTERFACE;
}
return NS_ERROR_NO_INTERFACE;
*aInstancePtr = static_cast<nsIAccessibleText*>(this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperText))) {
if (IsHyperText()) {
// If |this| contains text and embedded objects
*aInstancePtr = static_cast<nsIAccessibleHyperText*>(this);
NS_ADDREF_THIS();
return NS_OK;
if (role == nsIAccessibleRole::ROLE_ENTRY ||
role == nsIAccessibleRole::ROLE_PASSWORD_TEXT ||
role == nsIAccessibleRole::ROLE_TEXT_LEAF) {
return NS_ERROR_NO_INTERFACE;
}
return NS_ERROR_NO_INTERFACE;
*aInstancePtr = static_cast<nsIAccessibleHyperText*>(this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIAccessibleEditableText))) {
// If this contains editable text
PRUint32 state, extState;
GetState(&state, &extState);
if (extState & nsIAccessibleStates::EXT_STATE_EDITABLE) {
*aInstancePtr = static_cast<nsIAccessibleEditableText*>(this);
NS_ADDREF_THIS();
return NS_OK;
if (role == nsIAccessibleRole::ROLE_TEXT_LEAF) {
return NS_ERROR_NO_INTERFACE;
}
return NS_ERROR_NO_INTERFACE;
*aInstancePtr = static_cast<nsIAccessibleEditableText*>(this);
NS_ADDREF_THIS();
return NS_OK;
}
}
@ -126,18 +124,6 @@ nsAccessibleWrap(aNode, aShell)
{
}
PRBool nsHyperTextAccessible::IsHyperText()
{
nsCOMPtr<nsIAccessible> accessible;
while (NextChild(accessible)) {
if (IsEmbeddedObject(accessible)) {
return PR_TRUE;
}
}
return PR_FALSE;
}
NS_IMETHODIMP nsHyperTextAccessible::GetRole(PRUint32 *aRole)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
@ -239,24 +225,24 @@ void nsHyperTextAccessible::CacheChildren()
}
// Substring must be entirely within the same text node
nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRInt32 aStartContentOffset,
PRInt32 aEndContentOffset)
nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRUint32 aStartRenderedOffset,
PRUint32 aEndRenderedOffset)
{
nsIntRect screenRect;
NS_ENSURE_TRUE(aFrame, screenRect);
PRUint32 startRenderedOFfset, endRenderedOFfset;
nsresult rv = ContentToRenderedOffset(aFrame, aStartContentOffset, &startRenderedOFfset);
PRInt32 startContentOffset, endContentOffset;
nsresult rv = RenderedToContentOffset(aFrame, aStartRenderedOffset, &startContentOffset);
NS_ENSURE_SUCCESS(rv, screenRect);
rv = ContentToRenderedOffset(aFrame, aEndContentOffset, &endRenderedOFfset);
rv = RenderedToContentOffset(aFrame, aEndRenderedOffset, &endContentOffset);
NS_ENSURE_SUCCESS(rv, screenRect);
nsIFrame *frame;
PRInt32 startRenderedOFfsetInFrame;
PRInt32 startContentOffsetInFrame;
// Get the right frame continuation -- not really a child, but a sibling of
// the primary frame passed in
rv = aFrame->GetChildFrameContainingOffset(startRenderedOFfset, PR_FALSE,
&startRenderedOFfsetInFrame, &frame);
rv = aFrame->GetChildFrameContainingOffset(startContentOffset, PR_FALSE,
&startContentOffsetInFrame, &frame);
NS_ENSURE_SUCCESS(rv, screenRect);
nsCOMPtr<nsIPresShell> shell = GetPresShell();
@ -274,7 +260,7 @@ nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRInt32 aS
nsPresContext *context = shell->GetPresContext();
while (frame && startRenderedOFfset < endRenderedOFfset) {
while (frame && startContentOffset < endContentOffset) {
// Start with this frame's screen rect, which we will
// shrink based on the substring we care about within it.
// We will then add that frame to the total screenRect we
@ -285,26 +271,26 @@ nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRInt32 aS
PRInt32 startFrameTextOffset, endFrameTextOffset;
frame->GetOffsets(startFrameTextOffset, endFrameTextOffset);
PRInt32 frameTotalTextLength = endFrameTextOffset - startFrameTextOffset;
PRInt32 seekLength = endRenderedOFfset - startRenderedOFfset;
PRInt32 frameSubStringLength = PR_MIN(frameTotalTextLength - startRenderedOFfsetInFrame, seekLength);
PRInt32 seekLength = endContentOffset - startContentOffset;
PRInt32 frameSubStringLength = PR_MIN(frameTotalTextLength - startContentOffsetInFrame, seekLength);
// Add the point where the string starts to the frameScreenRect
nsPoint frameTextStartPoint;
rv = frame->GetPointFromOffset(context, rc, startRenderedOFfset, &frameTextStartPoint);
rv = frame->GetPointFromOffset(context, rc, startContentOffset, &frameTextStartPoint);
NS_ENSURE_SUCCESS(rv, nsRect());
frameScreenRect.x += context->AppUnitsToDevPixels(frameTextStartPoint.x);
// Use the point for the end offset to calculate the width
nsPoint frameTextEndPoint;
rv = frame->GetPointFromOffset(context, rc, startRenderedOFfset + frameSubStringLength, &frameTextEndPoint);
rv = frame->GetPointFromOffset(context, rc, startContentOffset + frameSubStringLength, &frameTextEndPoint);
NS_ENSURE_SUCCESS(rv, nsRect());
frameScreenRect.width = context->AppUnitsToDevPixels(frameTextEndPoint.x - frameTextStartPoint.x);
screenRect.UnionRect(frameScreenRect, screenRect);
// Get ready to loop back for next frame continuation
startRenderedOFfset += frameSubStringLength;
startRenderedOFfsetInFrame = 0;
startContentOffset += frameSubStringLength;
startContentOffsetInFrame = 0;
frame = frame->GetNextContinuation();
}
@ -482,7 +468,10 @@ NS_IMETHODIMP nsHyperTextAccessible::GetCharacterAtOffset(PRInt32 aOffset, PRUni
}
nsAutoString text;
nsresult rv = GetText(aOffset, aOffset + 1, text);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
return rv;
}
if (text.IsEmpty()) {
return NS_ERROR_FAILURE;
}

View File

@ -114,8 +114,6 @@ public:
nsIAccessible **aFinalAccessible = nsnull);
protected:
PRBool IsHyperText();
/*
* This does the work for nsIAccessibleText::GetText[At|Before|After]Offset
* @param aType, eGetBefore, eGetAt, eGetAfter
@ -157,7 +155,7 @@ protected:
nsIFrame* GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset, nsAString *aText = nsnull,
nsIFrame **aEndFrame = nsnull, nsIntRect *aBoundsRect = nsnull);
nsIntRect GetBoundsForString(nsIFrame *aFrame, PRInt32 aStartContentOffset, PRInt32 aEndContentOffset);
nsIntRect GetBoundsForString(nsIFrame *aFrame, PRUint32 aStartRenderedOffset, PRUint32 aEndRenderedOffset);
// Editor helpers, subclasses of nsHyperTextAccessible may have editor
virtual void SetEditor(nsIEditor *aEditor) { return; }

View File

@ -89,7 +89,7 @@ class nsAccessibleWrap : public nsAccessible
role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
role == nsIAccessibleRole::ROLE_SPLITBUTTON ||
role == nsIAccessibleRole::ROLE_ENTRY ||
role == nsIAccessibleRole::ROLE_IMAGE);
role == nsIAccessibleRole::ROLE_GRAPHIC);
}
// ignored means that the accessible might still have children, but is not displayed

View File

@ -1241,40 +1241,40 @@ nsAccessibleWrap::get_states(AccessibleStates *aStates)
if (states & nsIAccessibleStates::STATE_INVALID)
*aStates |= IA2_STATE_INVALID_ENTRY;
else if (states & nsIAccessibleStates::STATE_REQUIRED)
if (states & nsIAccessibleStates::STATE_REQUIRED)
*aStates |= IA2_STATE_REQUIRED;
// The following IA2 states are not supported by Gecko
// IA2_STATE_ARMED
// IA2_STATE_MANAGES_DESCENDAN
// IA2_STATE_MANAGES_DESCENDANTS
// IA2_STATE_ICONIFIED
// IA2_STATE_INVALID
// IA2_STATE_INVALID // This is not a state, it is the absence of a state
if (extraStates & nsIAccessibleStates::EXT_STATE_ACTIVE)
*aStates |= IA2_STATE_ACTIVE;
else if (extraStates & nsIAccessibleStates::EXT_STATE_DEFUNCT)
if (extraStates & nsIAccessibleStates::EXT_STATE_DEFUNCT)
*aStates |= IA2_STATE_DEFUNCT;
else if (extraStates & nsIAccessibleStates::EXT_STATE_EDITABLE)
if (extraStates & nsIAccessibleStates::EXT_STATE_EDITABLE)
*aStates |= IA2_STATE_EDITABLE;
else if (extraStates & nsIAccessibleStates::EXT_STATE_HORIZONTAL)
if (extraStates & nsIAccessibleStates::EXT_STATE_HORIZONTAL)
*aStates |= IA2_STATE_HORIZONTAL;
else if (extraStates & nsIAccessibleStates::EXT_STATE_MODAL)
if (extraStates & nsIAccessibleStates::EXT_STATE_MODAL)
*aStates |= IA2_STATE_MODAL;
else if (extraStates & nsIAccessibleStates::EXT_STATE_MULTI_LINE)
if (extraStates & nsIAccessibleStates::EXT_STATE_MULTI_LINE)
*aStates |= IA2_STATE_MULTI_LINE;
else if (extraStates & nsIAccessibleStates::EXT_STATE_OPAQUE)
if (extraStates & nsIAccessibleStates::EXT_STATE_OPAQUE)
*aStates |= IA2_STATE_OPAQUE;
else if (extraStates & nsIAccessibleStates::EXT_STATE_SELECTABLE_TEXT)
if (extraStates & nsIAccessibleStates::EXT_STATE_SELECTABLE_TEXT)
*aStates |= IA2_STATE_SELECTABLE_TEXT;
else if (extraStates & nsIAccessibleStates::EXT_STATE_SINGLE_LINE)
if (extraStates & nsIAccessibleStates::EXT_STATE_SINGLE_LINE)
*aStates |= IA2_STATE_SINGLE_LINE;
else if (extraStates & nsIAccessibleStates::EXT_STATE_STALE)
if (extraStates & nsIAccessibleStates::EXT_STATE_STALE)
*aStates |= IA2_STATE_STALE;
else if (extraStates & nsIAccessibleStates::EXT_STATE_SUPPORTS_AUTOCOMPLETION)
if (extraStates & nsIAccessibleStates::EXT_STATE_SUPPORTS_AUTOCOMPLETION)
*aStates |= IA2_STATE_SUPPORTS_AUTOCOMPLETION;
else if (extraStates & nsIAccessibleStates::EXT_STATE_TRANSIENT)
if (extraStates & nsIAccessibleStates::EXT_STATE_TRANSIENT)
*aStates |= IA2_STATE_TRANSIENT;
else if (extraStates & nsIAccessibleStates::EXT_STATE_VERTICAL)
if (extraStates & nsIAccessibleStates::EXT_STATE_VERTICAL)
*aStates |= IA2_STATE_VERTICAL;
return S_OK;
@ -1295,6 +1295,7 @@ nsAccessibleWrap::get_localizedExtendedRole(BSTR *localizedExtendedRole)
STDMETHODIMP
nsAccessibleWrap::get_nExtendedStates(long *nExtendedStates)
{
*nExtendedStates = 0;
return E_NOTIMPL;
}
@ -1303,6 +1304,7 @@ nsAccessibleWrap::get_extendedStates(long maxExtendedStates,
BSTR **extendedStates,
long *nExtendedStates)
{
*nExtendedStates = 0;
return E_NOTIMPL;
}
@ -1311,6 +1313,7 @@ nsAccessibleWrap::get_localizedExtendedStates(long maxLocalizedExtendedStates,
BSTR **localizedExtendedStates,
long *nLocalizedExtendedStates)
{
*nLocalizedExtendedStates = 0;
return E_NOTIMPL;
}

View File

@ -819,17 +819,17 @@ xulrunner/installer/mac/Makefile
MAKEFILES_xulapp="
toolkit/Makefile
toolkit/library/Makefile
toolkit/airbag/Makefile
toolkit/airbag/client/Makefile
toolkit/airbag/airbag/src/client/Makefile
toolkit/airbag/airbag/src/client/mac/handler/Makefile
toolkit/airbag/airbag/src/client/windows/Makefile
toolkit/airbag/airbag/src/client/windows/handler/Makefile
toolkit/airbag/airbag/src/client/windows/sender/Makefile
toolkit/airbag/airbag/src/common/Makefile
toolkit/airbag/airbag/src/common/mac/Makefile
toolkit/airbag/airbag/src/common/windows/Makefile
toolkit/airbag/airbag/src/tools/mac/dump_syms/Makefile
toolkit/crashreporter/Makefile
toolkit/crashreporter/client/Makefile
toolkit/crashreporter/google-breakpad/src/client/Makefile
toolkit/crashreporter/google-breakpad/src/client/mac/handler/Makefile
toolkit/crashreporter/google-breakpad/src/client/windows/Makefile
toolkit/crashreporter/google-breakpad/src/client/windows/handler/Makefile
toolkit/crashreporter/google-breakpad/src/client/windows/sender/Makefile
toolkit/crashreporter/google-breakpad/src/common/Makefile
toolkit/crashreporter/google-breakpad/src/common/mac/Makefile
toolkit/crashreporter/google-breakpad/src/common/windows/Makefile
toolkit/crashreporter/google-breakpad/src/tools/mac/dump_syms/Makefile
toolkit/content/Makefile
toolkit/content/buildconfig.html
toolkit/obsolete/Makefile

View File

@ -497,6 +497,9 @@ pref("browser.feeds.handler", "ask");
pref("browser.safebrowsing.enabled", true);
pref("browser.safebrowsing.remoteLookups", false);
// Prevent loading of pages identified as malware
pref("browser.safebrowsing.malware.enabled", true);
// Non-enhanced mode (local url lists) URL list to check for updates
pref("browser.safebrowsing.provider.0.updateURL", "http://sb.google.com/safebrowsing/downloads?client={moz:client}&appver={moz:version}&pver=2.0");

View File

@ -366,9 +366,9 @@
fullscreentoolbar="true" mode="icons"
customizable="true"
#ifdef XP_MACOSX
defaultset="back-button,forward-button,reload-button,stop-button,home-button,urlbar-container,go-container,splitter,search-container,throbber-box"
defaultset="back-button,forward-button,reload-button,stop-button,home-button,urlbar-container,splitter,search-container,throbber-box"
#else
defaultset="back-button,forward-button,reload-button,stop-button,home-button,urlbar-container,go-container,splitter,search-container,fullscreenflex,window-controls"
defaultset="back-button,forward-button,reload-button,stop-button,home-button,urlbar-container,splitter,search-container,fullscreenflex,window-controls"
#endif
context="toolbar-context-menu">
#ifndef XP_MACOSX

View File

@ -54,7 +54,11 @@
class="feedTitle"/>
<xul:label xbl:inherits="value=type"/>
</xul:hbox>
<xul:textbox xbl:inherits="value=feedURL" readonly="true"/>
<xul:hbox>
<xul:label xbl:inherits="value=feedURL" class="text-link"
onclick="openUILink(this.value, event);"/>
<xul:spacer flex="1"/>
</xul:hbox>
<xul:hbox flex="1" class="feed-subscribe">
<xul:spacer flex="1"/>
<xul:button label="&feedSubscribe;" accesskey="&feedSubscribe.accesskey;"

View File

@ -1,41 +1,42 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Microsummarizer.
*
* The Initial Developer of the Original Code is Mozilla.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Myk Melez <myk@mozilla.org> (Original Author)
* Simon Bünzli <zeniko@gmail.com>
* Asaf Romano <mano@mozilla.com>
* Dan Mills <thunder@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 Microsummarizer.
#
# The Initial Developer of the Original Code is Mozilla.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Myk Melez <myk@mozilla.org> (Original Author)
# Simon Bünzli <zeniko@gmail.com>
# Asaf Romano <mano@mozilla.com>
# Dan Mills <thunder@mozilla.com>
# Ryan Flint <rflint@dslr.net>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -1691,6 +1692,8 @@ function MicrosummaryResource(uri) {
this._contentType = null;
this._isXML = false;
this.__authFailed = false;
this._status = null;
this._method = "GET";
// A function to call when we finish loading/parsing the resource.
this._loadCallback = null;
@ -1726,6 +1729,12 @@ MicrosummaryResource.prototype = {
return this._isXML;
},
get status() { return this._status },
set status(aStatus) { this._status = aStatus },
get method() { return this._method },
set method(aMethod) { this._method = aMethod },
// Implement notification callback interfaces so we can suppress UI
// and abort loads for bad SSL certs and HTTP authorization requests.
@ -1933,10 +1942,16 @@ MicrosummaryResource.prototype = {
if (this._self._loadTimer)
this._self._loadTimer.cancel();
if (this._self._authFailed) {
this._self.status = event.target.status;
if (this._self._authFailed || this._self.status >= 400) {
// Technically the request succeeded, but we treat it as a failure,
// since we aren't able to handle HTTP authentication.
LOG(this._self.uri.spec + " load failed; HTTP auth required");
// since we won't be able to extract anything relevant from the result.
// XXX For now HTTP is the only protocol we handle that might fail
// auth. This message will need to change once we support FTP, which
// returns 0 for all statuses.
LOG(this._self.uri.spec + " load failed; HTTP status: " + this._self.status);
try { this._self._handleError(event) }
finally { this._self = null }
}
@ -1988,7 +2003,7 @@ MicrosummaryResource.prototype = {
request.addEventListener("error", errorHandler, false);
request = request.QueryInterface(Ci.nsIXMLHttpRequest);
request.open("GET", this.uri.spec, true);
request.open(this.method, this.uri.spec, true);
request.setRequestHeader("X-Moz", "microsummary");
// Register ourselves as a listener for notification callbacks so we

View File

@ -53,15 +53,6 @@ const RELOAD_ACTION_REMOVE = 2;
// rows.
const RELOAD_ACTION_MOVE = 3;
#ifdef XP_MACOSX
// On Mac OSX, the transferable system converts "\r\n" to "\n\n", where we
// really just want "\n".
const NEWLINE= "\n";
#else
// On other platforms, the transferable system converts "\r\n" to "\n".
const NEWLINE = "\r\n";
#endif
/**
* Represents an insertion point within a container where we can insert
* items.
@ -1212,7 +1203,7 @@ PlacesController.prototype = {
copiedFolders.push(node);
function generateChunk(type, overrideURI) {
var suffix = i < (nodes.length - 1) ? "\n" : "";
var suffix = i < (nodes.length - 1) ? NEWLINE : "";
var uri = overrideURI;
if (PlacesUtils.nodeIsLivemarkContainer(node))

View File

@ -50,6 +50,15 @@ const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
const DESCRIPTION_ANNO = "bookmarkProperties/description";
const POST_DATA_ANNO = "URIProperties/POSTData";
#ifdef XP_MACOSX
// On Mac OSX, the transferable system converts "\r\n" to "\n\n", where we
// really just want "\n".
const NEWLINE= "\n";
#else
// On other platforms, the transferable system converts "\r\n" to "\n".
const NEWLINE = "\r\n";
#endif
function QI_node(aNode, aIID) {
var result = null;
try {
@ -530,10 +539,10 @@ var PlacesUtils = {
function gatherDataUrl(bNode) {
if (self.nodeIsLivemarkContainer(bNode)) {
var siteURI = self.livemarks.getSiteURI(bNode.itemId).spec;
return siteURI + "\n" + bNode.title;
return siteURI + NEWLINE + bNode.title;
}
if (self.nodeIsURI(bNode))
return (aOverrideURI || bNode.uri) + "\n" + bNode.title;
return (aOverrideURI || bNode.uri) + NEWLINE + bNode.title;
// ignore containers and separators - items without valid URIs
return "";
}
@ -553,7 +562,7 @@ var PlacesUtils = {
var escapedTitle = htmlEscape(bNode.title);
if (self.nodeIsLivemarkContainer(bNode)) {
var siteURI = self.livemarks.getSiteURI(bNode.itemId).spec;
return "<A HREF=\"" + siteURI + "\">" + escapedTitle + "</A>\n";
return "<A HREF=\"" + siteURI + "\">" + escapedTitle + "</A>" + NEWLINE;
}
if (self.nodeIsContainer(bNode)) {
asContainer(bNode);
@ -561,19 +570,21 @@ var PlacesUtils = {
if (!wasOpen)
bNode.containerOpen = true;
var childString = "<DL><DT>" + escapedTitle + "</DT>\n";
var childString = "<DL><DT>" + escapedTitle + "</DT>" + NEWLINE;
var cc = bNode.childCount;
for (var i = 0; i < cc; ++i)
childString += "<DD>\n"
childString += "<DD>"
+ NEWLINE
+ gatherDataHtml(bNode.getChild(i))
+ "</DD>\n";
+ "</DD>"
+ NEWLINE;
bNode.containerOpen = wasOpen;
return childString + "</DL>\n";
return childString + "</DL>" + NEWLINE;
}
if (self.nodeIsURI(bNode))
return "<A HREF=\"" + bNode.uri + "\">" + escapedTitle + "</A>\n";
return "<A HREF=\"" + bNode.uri + "\">" + escapedTitle + "</A>" + NEWLINE;
if (self.nodeIsSeparator(bNode))
return "<HR>\n";
return "<HR>" + NEWLINE;
return "";
}
return gatherDataHtml(convertNode(aNode));
@ -588,11 +599,11 @@ var PlacesUtils = {
if (!wasOpen)
bNode.containerOpen = true;
var childString = bNode.title + "\n";
var childString = bNode.title + NEWLINE;
var cc = bNode.childCount;
for (var i = 0; i < cc; ++i) {
var child = bNode.getChild(i);
var suffix = i < (cc - 1) ? "\n" : "";
var suffix = i < (cc - 1) ? NEWLINE : "";
childString += gatherDataText(child) + suffix;
}
bNode.containerOpen = wasOpen;

View File

@ -84,6 +84,7 @@ function PROT_Application() {
// expose some classes
this.PROT_Controller = PROT_Controller;
this.PROT_PhishingWarden = PROT_PhishingWarden;
this.PROT_MalwareWarden = PROT_MalwareWarden;
// Load data provider pref values
gDataProvider = new PROT_DataProvider();

View File

@ -0,0 +1,129 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 Google Safe Browsing.
#
# The Initial Developer of the Original Code is Google Inc.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Dave Camp <dcamp@mozilla.com>
# Fritz Schneider <fritz@google.com> (original phishing-warden.js author)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
// This warden manages updates to the malware list
const kMalwareWardenEnabledPref = "browser.safebrowsing.malware.enabled";
function PROT_MalwareWarden() {
PROT_ListWarden.call(this);
this.debugZone = "malwarewarden";
// Use this to query preferences
this.prefs_ = new G_Preferences();
// Global preference to enable the malware warden
this.malwareWardenEnabled_ =
this.prefs_.getPref(kMalwareWardenEnabledPref, null);
// Get notifications when the malware warden enabled pref changes
var malwareWardenPrefObserver =
BindToObject(this.onMalwareWardenEnabledPrefChanged, this);
this.prefs_.addObserver(kMalwareWardenEnabledPref, malwareWardenPrefObserver);
// Add a test chunk to the database
var testData = "mozilla.com/firefox/its-an-attack.html";
var testUpdate =
"n:1000\ni:test-malware-simple\nad:1\n" +
"a:1:" + testData.length + "\n" +
testData +
"\n";
var dbService_ = Cc["@mozilla.org/url-classifier/dbservice;1"]
.getService(Ci.nsIUrlClassifierDBService);
dbService_.update(testUpdate);
dbService_.finish(function(result) {}, function(error) {});
G_Debug(this, "malwareWarden initialized");
}
PROT_MalwareWarden.inherits(PROT_ListWarden);
/**
* Cleanup on shutdown.
*/
PROT_MalwareWarden.prototype.shutdown = function() {
this.prefs_.removeAllObservers();
this.listManager_ = null;
}
/**
* When a preference changes, we might have to start or stop asking for
* updates.
*/
PROT_MalwareWarden.prototype.maybeToggleUpdateChecking = function() {
var malwareWardenEnabled = this.prefs_.getPref(kMalwareWardenEnabledPref,
null);
G_Debug(this, "Maybe toggling update checking. " +
"Warden enabled? " + malwareWardenEnabled);
// Do nothing unless thre pref is set
if (malwareWardenEnabled === null)
return;
// We update and save to disk all tables if we don't have remote checking
// enabled.
if (malwareWardenEnabled === true) {
this.enableBlacklistTableUpdates();
} else {
// Anti-malware is off, disable table updates
this.disableBlacklistTableUpdates();
}
}
/**
* Deal with a user changing the pref that says whether we should
* enable the malware warden.
*
* @param prefName Name of the pref holding the value indicating whether
* we should enable the malware warden
*/
PROT_MalwareWarden.prototype.onMalwareWardenEnabledPrefChanged = function(
prefName) {
// Just to be safe, ignore changes to sub prefs.
if (prefName != kMalwareWardenEnabledPref)
return;
this.malwareWardenEnabled_ =
this.prefs_.getPref(prefName, this.malwareWardenEnabled_);
this.maybeToggleUpdateChecking();
}

View File

@ -69,6 +69,14 @@ var safebrowsing = {
var appContext = Cc["@mozilla.org/safebrowsing/application;1"]
.getService().wrappedJSObject;
var malwareWarden = new appContext.PROT_MalwareWarden();
safebrowsing.malwareWarden = malwareWarden;
// Register tables
malwareWarden.registerBlackTable("goog-malware-sha128");
malwareWarden.maybeToggleUpdateChecking();
// Each new browser window needs its own controller.
safebrowsing.progressListener.QueryInterface(Ci.nsIWebProgressListener);
@ -127,6 +135,9 @@ var safebrowsing = {
if (safebrowsing.phishWarden) {
safebrowsing.phishWarden.shutdown();
}
if (safebrowsing.malwareWarden) {
safebrowsing.malwareWarden.shutdown();
}
window.removeEventListener("unload", safebrowsing.shutdown, false);
},

View File

@ -18,6 +18,7 @@ Function.prototype.inherits = function(parentCtor) {
#include ../content/list-warden.js
#include ../content/phishing-afterload-displayer.js
#include ../content/phishing-warden.js
#include ../content/malware-warden.js
#include ../content/reporter.js
#include ../content/tr-fetcher.js

View File

@ -234,6 +234,9 @@ function (generatorURL)
{
debug("addMicrosummaryGenerator(" + generatorURL + ")");
if (!/^https?:/i.test(generatorURL))
return;
var stringBundle = srGetStrBundle("chrome://browser/locale/sidebar/sidebar.properties");
var titleMessage = stringBundle.GetStringFromName("addMicsumGenConfirmTitle");
var dialogMessage = stringBundle.formatStringFromName("addMicsumGenConfirmText", [generatorURL], 1);

View File

@ -990,16 +990,11 @@ statusbarpanel#statusbar-display {
/* ----- GO BUTTON ----- */
#go-button {
-moz-appearance: toolbarbutton;
height: 24px;
}
#go-button,
#go-container {
-moz-appearance: none;
background-color: transparent;
margin: 0;
padding: 0;
height: 24px;
border-left: 0 !important;
min-width: 0;
list-style-image: url("chrome://browser/skin/Go.png");

View File

@ -1,5 +1,4 @@
.folder-icon > .menulist-label-box > .menulist-icon,
.folder-icon > .menu-iconic-left > .menu-iconic-icon {
.folder-icon > .menulist-label-box > .menulist-icon {
width: 16px;
height: 16px;
}

View File

@ -64,11 +64,6 @@
-moz-margin-start: 3px;
}
#searchbar .searchbar-popup .menu-iconic-icon {
min-width: 16px;
min-height: 16px;
}
.searchbar-popup .open-engine-manager {
-moz-padding-start: 4px;
}
@ -173,8 +168,6 @@ menuitem.bookmark-item {
}
.bookmark-item > .menu-iconic-left > .menu-iconic-icon {
width: 16px;
height: 16px;
-moz-padding-start: 0px;
}

View File

@ -36,8 +36,7 @@
* ***** END LICENSE BLOCK ***** */
/**** folder menulist ****/
.folder-icon > .menulist-label-box > .menulist-icon,
.folder-icon > .menu-iconic-left > .menu-iconic-icon {
.folder-icon > .menulist-label-box > .menulist-icon {
width: 16px;
height: 16px;
}

View File

@ -256,7 +256,7 @@ nsScriptSecurityManager::SecurityCompareURIs(nsIURI* aSourceURI,
// security purposes. Otherwise, for example, two javascript: URIs that
// are otherwise unrelated could end up "same origin", which would be
// unfortunate.
if (aSourceURI == aTargetURI)
if (aSourceURI && aSourceURI == aTargetURI)
{
return PR_TRUE;
}
@ -1247,8 +1247,11 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
nsCOMPtr<nsIURI> sourceURI;
aPrincipal->GetURI(getter_AddRefs(sourceURI));
NS_ASSERTION(sourceURI, "Non-system principals passed to CheckLoadURIWithPrincipal must have a URI!");
if (!sourceURI) {
NS_ERROR("Non-system principals passed to CheckLoadURIWithPrincipal "
"must have a URI!");
return NS_ERROR_UNEXPECTED;
}
// Automatic loads are not allowed from certain protocols.
if (aFlags & nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT) {
@ -1663,21 +1666,24 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx,
// case.
nsCOMPtr<nsIURI> principalURI;
aPrincipal->GetURI(getter_AddRefs(principalURI));
if (principalURI)
{
PRBool isAbout;
rv = principalURI->SchemeIs("about", &isAbout);
if (NS_SUCCEEDED(rv) && isAbout) {
nsCOMPtr<nsIAboutModule> module;
rv = NS_GetAboutModule(principalURI, getter_AddRefs(module));
if (NS_SUCCEEDED(rv)) {
PRUint32 flags;
rv = module->GetURIFlags(principalURI, &flags);
if (NS_SUCCEEDED(rv) &&
(flags & nsIAboutModule::ALLOW_SCRIPT)) {
*result = PR_TRUE;
return NS_OK;
}
if (!principalURI) {
// Broken principal of some sort. Disallow.
*result = PR_FALSE;
return NS_ERROR_UNEXPECTED;
}
PRBool isAbout;
rv = principalURI->SchemeIs("about", &isAbout);
if (NS_SUCCEEDED(rv) && isAbout) {
nsCOMPtr<nsIAboutModule> module;
rv = NS_GetAboutModule(principalURI, getter_AddRefs(module));
if (NS_SUCCEEDED(rv)) {
PRUint32 flags;
rv = module->GetURIFlags(principalURI, &flags);
if (NS_SUCCEEDED(rv) &&
(flags & nsIAboutModule::ALLOW_SCRIPT)) {
*result = PR_TRUE;
return NS_OK;
}
}
}
@ -1918,6 +1924,8 @@ NS_IMETHODIMP
nsScriptSecurityManager::GetCodebasePrincipal(nsIURI *aURI,
nsIPrincipal **result)
{
NS_ENSURE_ARG(aURI);
PRBool inheritsPrincipal;
nsresult rv =
NS_URIChainHasFlags(aURI,

View File

@ -153,7 +153,7 @@ MOZ_MORKREADER = @MOZ_MORKREADER@
MOZ_NO_XPCOM_OBSOLETE = @MOZ_NO_XPCOM_OBSOLETE@
MOZ_NO_FAST_LOAD = @MOZ_NO_FAST_LOAD@
NS_PRINTING = @NS_PRINTING@
MOZ_AIRBAG = @MOZ_AIRBAG@
MOZ_CRASHREPORTER = @MOZ_CRASHREPORTER@
MOZ_MOCHITEST = @MOZ_MOCHITEST@
MOZ_JAVAXPCOM = @MOZ_JAVAXPCOM@

View File

@ -5292,23 +5292,23 @@ if test -n "${MOZ_JAVAXPCOM}"; then
fi
dnl ========================================================
dnl = Airbag crash reporting (on by default on supported platforms)
dnl = Breakpad crash reporting (on by default on supported platforms)
dnl ========================================================
if (test "$OS_ARCH" = "WINNT" -a -z "$GNU_CC" \
|| test "$OS_ARCH" = "Darwin" \
|| test "$OS_ARCH" = "Linux" -a "$CPU_ARCH" = "x86") \
&& test -z "$HAVE_64BIT_OS"; then
MOZ_AIRBAG=1
MOZ_CRASHREPORTER=1
fi
MOZ_ARG_DISABLE_BOOL(airbag,
[ --disable-airbag Disable airbag crash reporting],
MOZ_AIRBAG=,
MOZ_AIRBAG=1)
MOZ_ARG_DISABLE_BOOL(crashreporter,
[ --disable-crashreporter Disable breakpad crash reporting],
MOZ_CRASHREPORTER=,
MOZ_CRASHREPORTER=1)
if test -n "$MOZ_AIRBAG"; then
AC_DEFINE(MOZ_AIRBAG)
if test -n "$MOZ_CRASHREPORTER"; then
AC_DEFINE(MOZ_CRASHREPORTER)
if test "$OS_ARCH" = "Linux" && \
test -z "$SKIP_LIBRARY_CHECKS"; then
@ -5321,7 +5321,7 @@ if test -n "$MOZ_AIRBAG"; then
ac_cv_have_libcurl="yes",
ac_cv_have_libcurl="no")])
if test "$ac_cv_have_libcurl" = "no"; then
AC_MSG_ERROR([Couldn't find libcurl, which is required for the crash reporter. Use --disable-airbag to disable the crash reporter.])
AC_MSG_ERROR([Couldn't find libcurl, which is required for the crash reporter. Use --disable-crashreporter to disable the crash reporter.])
fi
LDFLAGS=$_SAVE_LDFLAGS
fi
@ -7437,7 +7437,7 @@ AC_SUBST(MOZ_VIEW_SOURCE)
AC_SUBST(MOZ_SPELLCHECK)
AC_SUBST(MOZ_XPFE_COMPONENTS)
AC_SUBST(MOZ_USER_DIR)
AC_SUBST(MOZ_AIRBAG)
AC_SUBST(MOZ_CRASHREPORTER)
AC_SUBST(MOZ_MOCHITEST)
AC_SUBST(ENABLE_STRIP)

View File

@ -39,6 +39,9 @@
/*
* Utility routines for checking content load/process policy settings,
* and routines helpful for content policy implementors.
*
* XXXbz it would be nice if some of this stuff could be out-of-lined in
* nsContentUtils. That would work for almost all the callers...
*/
#ifndef __nsContentPolicyUtils_h__
@ -50,6 +53,8 @@
#include "nsIContentPolicy.h"
#include "nsIServiceManager.h"
#include "nsIContent.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
//XXXtw sadly, this makes consumers of nsContentPolicyUtils depend on widget
#include "nsIDocument.h"
@ -163,21 +168,55 @@ NS_CP_ContentTypeName(PRUint32 contentType)
PR_END_MACRO
/**
* Alias for calling ShouldLoad on the content policy service.
* Parameters are the same as nsIContentPolicy::shouldLoad, except for
* the last parameter, which can be used to pass in a pointer to the
* service if the caller already has one.
* Check whether we can short-circuit this check and bail out. If not, get the
* origin URI to use.
*
* Note: requestOrigin is scoped outside the PR_BEGIN_MACRO/PR_END_MACRO on
* purpose */
#define CHECK_PRINCIPAL \
nsCOMPtr<nsIURI> requestOrigin; \
PR_BEGIN_MACRO \
if (originPrincipal) { \
nsCOMPtr<nsIScriptSecurityManager> secMan = aSecMan; \
if (!secMan) { \
secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); \
} \
if (secMan) { \
PRBool isSystem; \
nsresult rv = secMan->IsSystemPrincipal(originPrincipal, \
&isSystem); \
NS_ENSURE_SUCCESS(rv, rv); \
if (isSystem) { \
*decision = nsIContentPolicy::ACCEPT; \
return NS_OK; \
} \
} \
nsresult rv = originPrincipal->GetURI(getter_AddRefs(requestOrigin)); \
NS_ENSURE_SUCCESS(rv, rv); \
} \
PR_END_MACRO
/**
* Alias for calling ShouldLoad on the content policy service. Parameters are
* the same as nsIContentPolicy::shouldLoad, except for the originPrincipal
* parameter, which should be non-null if possible, and the last two
* parameters, which can be used to pass in pointer to some useful services if
* the caller already has them. The origin URI to pass to shouldLoad will be
* the URI of originPrincipal, unless originPrincipal is null (in which case a
* null origin URI will be passed).
*/
inline nsresult
NS_CheckContentLoadPolicy(PRUint32 contentType,
nsIURI *contentLocation,
nsIURI *requestOrigin,
nsIPrincipal *originPrincipal,
nsISupports *context,
const nsACString &mimeType,
nsISupports *extra,
PRInt16 *decision,
nsIContentPolicy *policyService = nsnull)
nsIContentPolicy *policyService = nsnull,
nsIScriptSecurityManager* aSecMan = nsnull)
{
CHECK_PRINCIPAL;
if (policyService) {
CHECK_CONTENT_POLICY_WITH_SERVICE(ShouldLoad, policyService);
}
@ -185,19 +224,26 @@ NS_CheckContentLoadPolicy(PRUint32 contentType,
}
/**
* Alias for calling ShouldProcess on the content policy service.
* Parameters are the same as nsIContentPolicy::shouldProcess.
* Alias for calling ShouldProcess on the content policy service. Parameters
* are the same as nsIContentPolicy::shouldLoad, except for the originPrincipal
* parameter, which should be non-null if possible, and the last two
* parameters, which can be used to pass in pointer to some useful services if
* the caller already has them. The origin URI to pass to shouldLoad will be
* the URI of originPrincipal, unless originPrincipal is null (in which case a
* null origin URI will be passed).
*/
inline nsresult
NS_CheckContentProcessPolicy(PRUint32 contentType,
nsIURI *contentLocation,
nsIURI *requestOrigin,
nsIPrincipal *originPrincipal,
nsISupports *context,
const nsACString &mimeType,
nsISupports *extra,
PRInt16 *decision,
nsIContentPolicy *policyService = nsnull)
nsIContentPolicy *policyService = nsnull,
nsIScriptSecurityManager* aSecMan = nsnull)
{
CHECK_PRINCIPAL;
if (policyService) {
CHECK_CONTENT_POLICY_WITH_SERVICE(ShouldProcess, policyService);
}

View File

@ -75,10 +75,12 @@ public:
virtual nsresult SetOwnerDocument(nsIDocument* aDocument) = 0;
protected:
#ifdef MOZILLA_INTERNAL_API
nsIAttribute(nsDOMAttributeMap *aAttrMap, nsINodeInfo *aNodeInfo)
: nsINode(aNodeInfo), mAttrMap(aAttrMap)
{
}
#endif //MOZILLA_INTERNAL_API
nsDOMAttributeMap *mAttrMap; // WEAK
};

View File

@ -2116,20 +2116,17 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext,
}
}
nsCOMPtr<nsIURI> loadingURI;
rv = aLoadingPrincipal->GetURI(getter_AddRefs(loadingURI));
NS_ENSURE_SUCCESS(rv, PR_FALSE);
PRInt16 decision = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_IMAGE,
aURI,
loadingURI,
aLoadingPrincipal,
aContext,
EmptyCString(), //mime guess
nsnull, //extra
&decision,
GetContentPolicy());
GetContentPolicy(),
sSecurityManager);
if (aImageBlockingStatus) {
*aImageBlockingStatus =
@ -3611,13 +3608,11 @@ nsContentUtils::CheckSecurityBeforeLoad(nsIURI* aURIToLoad,
const nsACString& aMimeGuess,
nsISupports* aExtra)
{
NS_PRECONDITION(aLoadingPrincipal, "Must have a loading principal here");
// XXXbz do we want to fast-path skin stylesheets loading XBL here somehow?
nsCOMPtr<nsIURI> loadingURI;
nsresult rv = aLoadingPrincipal->GetURI(getter_AddRefs(loadingURI));
NS_ENSURE_SUCCESS(rv, rv);
// CheckLoadURIWithPrincipal
rv = sSecurityManager->
nsresult rv = sSecurityManager->
CheckLoadURIWithPrincipal(aLoadingPrincipal, aURIToLoad, aCheckLoadFlags);
NS_ENSURE_SUCCESS(rv, rv);
@ -3625,12 +3620,13 @@ nsContentUtils::CheckSecurityBeforeLoad(nsIURI* aURIToLoad,
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(aContentPolicyType,
aURIToLoad,
loadingURI,
aLoadingPrincipal,
aContext,
aMimeGuess,
aExtra,
&shouldLoad,
GetContentPolicy());
GetContentPolicy(),
sSecurityManager);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_CP_REJECTED(shouldLoad)) {
return NS_ERROR_CONTENT_BLOCKED;
@ -3642,6 +3638,10 @@ nsContentUtils::CheckSecurityBeforeLoad(nsIURI* aURIToLoad,
SchemeIs(aURIToLoad, "chrome"))) {
return NS_OK;
}
nsCOMPtr<nsIURI> loadingURI;
rv = aLoadingPrincipal->GetURI(getter_AddRefs(loadingURI));
NS_ENSURE_SUCCESS(rv, rv);
return sSecurityManager->CheckSameOriginURI(loadingURI, aURIToLoad);
}

View File

@ -741,6 +741,7 @@ GK_ATOM(scrollbox, "scrollbox")
GK_ATOM(scrollcorner, "scrollcorner")
GK_ATOM(scrolling, "scrolling")
GK_ATOM(select, "select")
GK_ATOM(selectPopupList, "selectPopupList")
GK_ATOM(selectable, "selectable")
GK_ATOM(selected, "selected")
GK_ATOM(selectedIndex, "selectedIndex")

View File

@ -128,7 +128,8 @@ nsAsyncInstantiateEvent::Run()
// the type here - GetFrame() only returns object frames, and that means we're
// a plugin)
// Also make sure that we still refer to the same data.
if (mContent->GetFrame(PR_FALSE) == mFrame &&
nsIObjectFrame* frame = mContent->GetFrame(PR_FALSE);
if (frame == mFrame &&
mContent->mURI == mURI &&
mContent->mContentType.Equals(mContentType)) {
if (LOG_ENABLED()) {
@ -140,7 +141,7 @@ nsAsyncInstantiateEvent::Run()
mContent, mContentType.get(), mURI.get(), spec.get()));
}
nsresult rv = mContent->Instantiate(mContentType, mURI);
nsresult rv = mContent->Instantiate(frame, mContentType, mURI);
if (NS_FAILED(rv)) {
mContent->Fallback(PR_TRUE);
}
@ -643,7 +644,7 @@ nsObjectLoadingContent::EnsureInstantiation(nsIPluginInstance** aInstance)
// We may have a plugin instance already; if so, do nothing
nsresult rv = frame->GetPluginInstance(*aInstance);
if (!*aInstance) {
rv = Instantiate(mContentType, mURI);
rv = Instantiate(frame, mContentType, mURI);
if (NS_SUCCEEDED(rv)) {
rv = frame->GetPluginInstance(*aInstance);
} else {
@ -890,12 +891,13 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
rv =
NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OBJECT,
aURI,
doc->GetDocumentURI(),
doc->NodePrincipal(),
static_cast<nsIImageLoadingContent*>(this),
aTypeHint,
nsnull, //extra
&shouldLoad,
nsContentUtils::GetContentPolicy());
nsContentUtils::GetContentPolicy(),
nsContentUtils::GetSecurityManager());
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
// Must call UnloadContent first, as it overwrites
// mSuppressed/mUserDisabled. It also takes care of setting the type to
@ -931,6 +933,7 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
if (overrideType.IsEmpty()) {
newType = GetTypeOfContent(aTypeHint);
} else {
mContentType = overrideType;
newType = eType_Plugin;
}
@ -957,6 +960,7 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
// Must notify here for plugins
// If aNotify is false, we'll just wait until we get a frame and use the
// async instantiate path.
// XXX is this still needed? (for documents?)
mType = newType;
if (aNotify)
notifier.Notify();
@ -967,7 +971,7 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
rv = LoadImage(aURI, aForceLoad, PR_FALSE);
break;
case eType_Plugin:
rv = Instantiate(aTypeHint, aURI);
rv = TryInstantiate(mContentType, mURI);
break;
case eType_Document:
rv = mFrameLoader->LoadURI(aURI);
@ -1019,8 +1023,6 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
// Or: supported class id, plugin will handle the load.
LOG(("OBJLC [%p]: (classid) Changing type from %u to eType_Plugin\n", this, mType));
mType = eType_Plugin;
if (aNotify)
notifier.Notify();
// At this point, the stored content type
// must be equal to our type hint. Similar,
@ -1043,7 +1045,7 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
}
}
rv = Instantiate(mContentType, mURI);
rv = TryInstantiate(mContentType, mURI);
return NS_OK;
}
@ -1062,10 +1064,8 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
}
// E.g. mms://
mType = eType_Plugin;
if (aNotify)
notifier.Notify();
rv = Instantiate(aTypeHint, aURI);
rv = TryInstantiate(aTypeHint, aURI);
return NS_OK;
}
@ -1436,13 +1436,29 @@ nsObjectLoadingContent::GetFrame(PRBool aFlushLayout)
}
nsresult
nsObjectLoadingContent::Instantiate(const nsACString& aMIMEType, nsIURI* aURI)
nsObjectLoadingContent::TryInstantiate(const nsACString& aMIMEType,
nsIURI* aURI)
{
nsIObjectFrame* frame = GetFrame(PR_FALSE);
if (!frame) {
LOG(("OBJLC [%p]: Attempted to instantiate, but have no frame\n", this));
LOG(("OBJLC [%p]: No frame yet\n", this));
return NS_OK; // Not a failure to have no frame
}
nsIFrame* iframe;
CallQueryInterface(frame, &iframe);
if (iframe->GetStateBits() & NS_FRAME_FIRST_REFLOW) {
LOG(("OBJLC [%p]: Frame hasn't been reflown yet\n", this));
return NS_OK; // Not a failure to have no frame
}
return Instantiate(frame, aMIMEType, aURI);
}
nsresult
nsObjectLoadingContent::Instantiate(nsIObjectFrame* aFrame,
const nsACString& aMIMEType,
nsIURI* aURI)
{
NS_ASSERTION(aFrame, "Must have a frame here");
nsCString typeToUse(aMIMEType);
if (typeToUse.IsEmpty() && aURI) {
@ -1463,9 +1479,9 @@ nsObjectLoadingContent::Instantiate(const nsACString& aMIMEType, nsIURI* aURI)
// We'll always have a type or a URI by the time we get here
NS_ASSERTION(aURI || !typeToUse.IsEmpty(), "Need a URI or a type");
LOG(("OBJLC [%p]: Calling [%p]->Instantiate(<%s>, %p)\n", this, frame,
LOG(("OBJLC [%p]: Calling [%p]->Instantiate(<%s>, %p)\n", this, aFrame,
typeToUse.get(), aURI));
return frame->Instantiate(typeToUse.get(), aURI);
return aFrame->Instantiate(typeToUse.get(), aURI);
}
/* static */ PRBool

View File

@ -284,12 +284,18 @@ class nsObjectLoadingContent : public nsImageLoadingContent
*/
nsIObjectFrame* GetFrame(PRBool aFlushLayout);
/**
* Checks if we have a frame that's ready for instantiation, and if so,
* calls Instantiate().
*/
nsresult TryInstantiate(const nsACString& aMIMEType, nsIURI* aURI);
/**
* Instantiates the plugin. This differs from GetFrame()->Instantiate() in
* that it ensures that the URI will be non-null, and that a MIME type
* will be passed.
*/
nsresult Instantiate(const nsACString& aMIMEType, nsIURI* aURI);
nsresult Instantiate(nsIObjectFrame* aFrame, const nsACString& aMIMEType, nsIURI* aURI);
/**
* Whether to treat this content as a plugin, even though we can't handle

View File

@ -425,15 +425,15 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// After the security manager, the content-policy stuff gets a veto
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
nsIURI *docURI = mDocument->GetDocumentURI();
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT,
scriptURI,
docURI,
mDocument->NodePrincipal(),
aElement,
NS_LossyConvertUTF16toASCII(type),
nsnull, //extra
&shouldLoad,
nsContentUtils::GetContentPolicy());
nsContentUtils::GetContentPolicy(),
nsContentUtils::GetSecurityManager());
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) {
return NS_ERROR_CONTENT_BLOCKED;

View File

@ -1264,11 +1264,13 @@ nsXMLHttpRequest::OpenRequest(const nsACString& method,
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
uri,
(doc ? doc->GetDocumentURI() : nsnull),
(doc ? doc->NodePrincipal() : nsnull),
doc,
EmptyCString(), //mime guess
nsnull, //extra
&shouldLoad);
&shouldLoad,
nsContentUtils::GetContentPolicy(),
nsContentUtils::GetSecurityManager());
if (NS_FAILED(rv)) return rv;
if (NS_CP_REJECTED(shouldLoad)) {
// Disallowed by content policy

View File

@ -602,8 +602,80 @@ nsEventStateManager::Observe(nsISupports *aSubject,
return NS_OK;
}
NS_IMPL_CYCLE_COLLECTION_CLASS(nsEventStateManager)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEventStateManager)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEventStateManager)
NS_INTERFACE_MAP_ENTRY(nsIEventStateManager)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsEventStateManager, nsIEventStateManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsEventStateManager, nsIEventStateManager)
PR_STATIC_CALLBACK(PRBool)
TraverseAccessKeyContent(nsHashKey *aKey, void *aData, void* aClosure)
{
nsCycleCollectionTraversalCallback *cb =
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
nsIContent *content =
static_cast<nsIContent*>(aData);
cb->NoteXPCOMChild(content);
return kHashEnumerateNext;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventStateManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentTargetContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMouseOverElement);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGestureDownContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGestureDownFrameOwner);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastLeftMouseDownContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMiddleMouseDownContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastRightMouseDownContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mActiveContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHoverContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragOverContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mURLTargetContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentFocus);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastFocus);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastContentFocus);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstBlurEvent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstFocusEvent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOverEventElement);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOutEventElement);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument);
if (tmp->mAccessKeys) {
tmp->mAccessKeys->Enumerate(TraverseAccessKeyContent, &cb);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEventStateManager)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentTargetContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMouseOverElement);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGestureDownContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGestureDownFrameOwner);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastLeftMouseDownContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMiddleMouseDownContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastRightMouseDownContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mActiveContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHoverContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragOverContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURLTargetContent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentFocus);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastFocus);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastContentFocus);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstBlurEvent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstFocusEvent);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOverEventElement);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOutEventElement);
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument);
delete tmp->mAccessKeys;
tmp->mAccessKeys = nsnull;
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ISUPPORTS3(nsEventStateManager, nsIEventStateManager, nsIObserver, nsISupportsWeakReference)
NS_IMETHODIMP
nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
@ -5073,6 +5145,9 @@ nsEventStateManager::SetContentCaretVisible(nsIPresShell* aPresShell,
// First, tell the caret which selection to use
caret->SetCaretDOMSelection(domSelection);
// Ignore user-modify status of nodes when browsing with caret
caret->SetIgnoreUserModify(aVisible);
// In content, we need to set the caret
// the only other case is edit fields, where they have a different frame selection from the doc's
// in that case they'll take care of making the caret visible themselves
@ -5112,12 +5187,19 @@ nsEventStateManager::ResetBrowseWithCaret()
if (itemType == nsIDocShellTreeItem::typeChrome)
return; // Never browse with caret in chrome
nsIPresShell *presShell = mPresContext->GetPresShell();
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(shellItem));
if (editorDocShell) {
PRBool isEditable;
editorDocShell->GetEditable(&isEditable);
if (isEditable) {
return; // Reset caret visibility only if browsing, not editing
if (presShell && isEditable) {
nsCOMPtr<nsIHTMLDocument> doc =
do_QueryInterface(presShell->GetDocument());
if (!doc || doc->GetEditingState() != nsIHTMLDocument::eContentEditable) {
return; // Reset caret visibility only if browsing, not editing except
// for contentEditable
}
}
}
@ -5126,7 +5208,6 @@ nsEventStateManager::ResetBrowseWithCaret()
mBrowseWithCaret = browseWithCaret;
nsIPresShell *presShell = mPresContext->GetPresShell();
// Make caret visible or not, depending on what's appropriate
// Set caret visibility for focused document only

View File

@ -50,6 +50,7 @@
#include "nsIDocument.h"
#include "nsCOMArray.h"
#include "nsIFrame.h"
#include "nsCycleCollectionParticipant.h"
class nsIScrollableView;
class nsIPresShell;
@ -77,7 +78,7 @@ public:
nsEventStateManager();
virtual ~nsEventStateManager();
NS_DECL_ISUPPORTS
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_IMETHOD Init();
@ -155,6 +156,9 @@ public:
return sUserInputEventDepth > 0;
}
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventStateManager,
nsIEventStateManager)
protected:
/**
* In certain situations the focus controller's concept of focus gets out of

View File

@ -271,8 +271,6 @@ public:
{
}
NS_DECL_ISUPPORTS_INHERITED
// nsIFormSubmission
virtual nsresult AddNameValuePair(nsIDOMHTMLElement* aSource,
const nsAString& aName,
@ -320,10 +318,6 @@ private:
PRBool mWarnedFileControl;
};
NS_IMPL_RELEASE_INHERITED(nsFSURLEncoded, nsFormSubmission)
NS_IMPL_ADDREF_INHERITED(nsFSURLEncoded, nsFormSubmission)
NS_IMPL_QUERY_INTERFACE_INHERITED0(nsFSURLEncoded, nsFormSubmission)
nsresult
nsFSURLEncoded::AddNameValuePair(nsIDOMHTMLElement* aSource,
const nsAString& aName,
@ -611,8 +605,6 @@ public:
PRInt32 aBidiOptions);
virtual ~nsFSMultipartFormData() { }
NS_DECL_ISUPPORTS_INHERITED
// nsIFormSubmission
virtual nsresult AddNameValuePair(nsIDOMHTMLElement* aSource,
const nsAString& aName,
@ -692,10 +684,6 @@ private:
nsCString mBoundary;
};
NS_IMPL_RELEASE_INHERITED(nsFSMultipartFormData, nsFormSubmission)
NS_IMPL_ADDREF_INHERITED(nsFSMultipartFormData, nsFormSubmission)
NS_IMPL_QUERY_INTERFACE_INHERITED0(nsFSMultipartFormData, nsFormSubmission)
//
// Constructor
//
@ -937,8 +925,6 @@ public:
{
}
NS_DECL_ISUPPORTS_INHERITED
// nsIFormSubmission
virtual nsresult AddNameValuePair(nsIDOMHTMLElement* aSource,
const nsAString& aName,
@ -965,10 +951,6 @@ private:
nsString mBody;
};
NS_IMPL_RELEASE_INHERITED(nsFSTextPlain, nsFormSubmission)
NS_IMPL_ADDREF_INHERITED(nsFSTextPlain, nsFormSubmission)
NS_IMPL_QUERY_INTERFACE_INHERITED0(nsFSTextPlain, nsFormSubmission)
nsresult
nsFSTextPlain::AddNameValuePair(nsIDOMHTMLElement* aSource,
const nsAString& aName,

View File

@ -296,44 +296,6 @@ protected:
nsresult DoResolveName(const nsAString& aName, PRBool aFlushContent,
nsISupports** aReturn);
/**
* Reset the default submit element after the previous default submit control
* is removed.
*
* Note that this, in the worst case, needs to run through all the form's
* controls.
*
* @param aNotify If true, send nsIDocumentObserver notifications on the
* new and previous default elements.
* @param aPrevDefaultInElements If true, the previous default submit element
* was in the elements list. If false, it was
* in the not-in-elements list.
* @param aPrevDefaultIndex The index of the previous default submit control
* in the list determined by aPrevDefaultInElements.
*/
void ResetDefaultSubmitElement(PRBool aNotify,
PRBool aPrevDefaultInElements,
PRUint32 aPrevDefaultIndex);
/**
* Locates the default submit control. This is defined as the first element
* in document order which can submit a form. Returns null if there are no
* submit controls.
*
* Note that this, in the worst case, needs to run through all the form's
* controls.
*
* @param aPrevDefaultInElements If true, the previous default submit element
* was in the elements list. If false, it was
* in the not-in-elements list.
* @param aPrevDefaultIndex The index of the previous default submit control
* in the list determined by aPrevDefaultInElements.
* @return The default submit control for the form, or null if one does
* not exist.
*/
nsIFormControl* FindDefaultSubmit(PRBool aPrevDefaultInElements,
PRUint32 aPrevDefaultIndex) const;
//
// Data members
//
@ -368,6 +330,12 @@ protected:
/** The default submit element -- WEAK */
nsIFormControl* mDefaultSubmitElement;
/** The first submit element in mElements -- WEAK */
nsIFormControl* mFirstSubmitInElements;
/** The first submit element in mNotInElements -- WEAK */
nsIFormControl* mFirstSubmitNotInElements;
protected:
/** Detection of first form to notify observers */
static PRBool gFirstFormSubmitted;
@ -522,7 +490,9 @@ nsHTMLFormElement::nsHTMLFormElement(nsINodeInfo *aNodeInfo)
mSubmitInitiatedFromUserInput(PR_FALSE),
mPendingSubmission(nsnull),
mSubmittingRequest(nsnull),
mDefaultSubmitElement(nsnull)
mDefaultSubmitElement(nsnull),
mFirstSubmitInElements(nsnull),
mFirstSubmitNotInElements(nsnull)
{
}
@ -1312,30 +1282,49 @@ nsHTMLFormElement::AddElement(nsIFormControl* aChild,
// Default submit element handling
if (aChild->IsSubmitControl()) {
// The new child is the default submit if there was not previously
// a default submit element, or if the new child is before the old
// default submit element.
// To speed up parsing, the special case of a form that already
// has a default submit that's in the same list as the new child
// is ignored, since the new child then cannot be the default
// submit element.
nsIFormControl* oldControl = mDefaultSubmitElement;
if (!mDefaultSubmitElement ||
((!lastElement ||
ShouldBeInElements(mDefaultSubmitElement) != childInElements) &&
CompareFormControlPosition(aChild, mDefaultSubmitElement, this) < 0)) {
mDefaultSubmitElement = aChild;
// Update mDefaultSubmitElement, mFirstSubmitInElements,
// mFirstSubmitNotInElements.
nsIFormControl** firstSubmitSlot =
childInElements ? &mFirstSubmitInElements : &mFirstSubmitNotInElements;
// The new child is the new first submit in its list if the firstSubmitSlot
// is currently empty or if the child is before what's currently in the
// slot. Note that if we already have a control in firstSubmitSlot and
// we're appending this element can't possibly replace what's currently in
// the slot. Also note that aChild can't become the mDefaultSubmitElement
// unless it replaces what's in the slot. If it _does_ replace what's in
// the slot, it becomes the default submit if either the default submit is
// what's in the slot or the child is earlier than the default submit.
nsIFormControl* oldDefaultSubmit = mDefaultSubmitElement;
if (!*firstSubmitSlot ||
(!lastElement &&
CompareFormControlPosition(aChild, *firstSubmitSlot, this) < 0)) {
NS_ASSERTION(*firstSubmitSlot == mDefaultSubmitElement ||
mDefaultSubmitElement,
"How can we have a null mDefaultSubmitElement but a "
"first-submit slot in one of the lists?");
if (*firstSubmitSlot == mDefaultSubmitElement ||
CompareFormControlPosition(aChild,
mDefaultSubmitElement, this) < 0) {
mDefaultSubmitElement = aChild;
}
*firstSubmitSlot = aChild;
}
NS_POSTCONDITION(mDefaultSubmitElement == mFirstSubmitInElements ||
mDefaultSubmitElement == mFirstSubmitNotInElements,
"What happened here?");
// Notify that the state of the previous default submit element has changed
// if the element which is the default submit element has changed. The new
// default submit element is responsible for its own ContentStatesChanged
// call.
if (aNotify && oldControl != mDefaultSubmitElement) {
if (aNotify && oldDefaultSubmit &&
oldDefaultSubmit != mDefaultSubmitElement) {
nsIDocument* document = GetCurrentDoc();
if (document) {
MOZ_AUTO_DOC_UPDATE(document, UPDATE_CONTENT_STATE, PR_TRUE);
nsCOMPtr<nsIContent> oldElement(do_QueryInterface(oldControl));
nsCOMPtr<nsIContent> oldElement(do_QueryInterface(oldDefaultSubmit));
document->ContentStatesChanged(oldElement, nsnull,
NS_EVENT_STATE_DEFAULT);
}
@ -1380,86 +1369,63 @@ nsHTMLFormElement::RemoveElement(nsIFormControl* aChild,
controls.RemoveElementAt(index);
// Update our mFirstSubmit* values.
nsIFormControl** firstSubmitSlot =
childInElements ? &mFirstSubmitInElements : &mFirstSubmitNotInElements;
if (aChild == *firstSubmitSlot) {
*firstSubmitSlot = nsnull;
// We are removing the first submit in this list, find the new first submit
PRUint32 length = controls.Length();
for (PRUint32 i = index; i < length; ++i) {
nsIFormControl* currentControl = controls[i];
if (currentControl->IsSubmitControl()) {
*firstSubmitSlot = currentControl;
break;
}
}
}
if (aChild == mDefaultSubmitElement) {
// We are removing the default submit, find the new default
ResetDefaultSubmitElement(aNotify, childInElements, index );
// Need to reset mDefaultSubmitElement
if (!mFirstSubmitNotInElements) {
mDefaultSubmitElement = mFirstSubmitInElements;
} else if (!mFirstSubmitInElements) {
mDefaultSubmitElement = mFirstSubmitNotInElements;
} else {
NS_ASSERTION(mFirstSubmitInElements != mFirstSubmitNotInElements,
"How did that happen?");
// Have both; use the earlier one
mDefaultSubmitElement =
CompareFormControlPosition(mFirstSubmitInElements,
mFirstSubmitNotInElements, this) < 0 ?
mFirstSubmitInElements : mFirstSubmitNotInElements;
}
NS_POSTCONDITION(mDefaultSubmitElement == mFirstSubmitInElements ||
mDefaultSubmitElement == mFirstSubmitNotInElements,
"What happened here?");
// Notify about change. Note that we don't notify on the old default
// submit (which is being removed) because it's either being removed from
// the DOM or changing attributes in a way that makes it responsible for
// sending its own notifications.
if (aNotify && mDefaultSubmitElement) {
NS_ASSERTION(mDefaultSubmitElement != aChild,
"Notifying but elements haven't changed.");
nsIDocument* document = GetCurrentDoc();
if (document) {
MOZ_AUTO_DOC_UPDATE(document, UPDATE_CONTENT_STATE, PR_TRUE);
nsCOMPtr<nsIContent> newElement(do_QueryInterface(mDefaultSubmitElement));
document->ContentStatesChanged(newElement, nsnull,
NS_EVENT_STATE_DEFAULT);
}
}
}
return rv;
}
void
nsHTMLFormElement::ResetDefaultSubmitElement(PRBool aNotify,
PRBool aPrevDefaultInElements,
PRUint32 aPrevDefaultIndex)
{
nsIFormControl* oldDefaultSubmit = mDefaultSubmitElement;
mDefaultSubmitElement = FindDefaultSubmit(aPrevDefaultInElements,
aPrevDefaultIndex);
// Inform about change. Note that we don't notify on the old default submit
// (which is being removed) because it's either being removed from the DOM or
// changing attributes in a way that makes it responsible for sending its own
// notifications.
if (aNotify && (oldDefaultSubmit || mDefaultSubmitElement)) {
NS_ASSERTION(mDefaultSubmitElement != oldDefaultSubmit,
"Notifying but elements haven't changed.");
nsIDocument* document = GetCurrentDoc();
if (document) {
MOZ_AUTO_DOC_UPDATE(document, UPDATE_CONTENT_STATE, PR_TRUE);
nsCOMPtr<nsIContent> newElement(do_QueryInterface(mDefaultSubmitElement));
document->ContentStatesChanged(newElement, nsnull,
NS_EVENT_STATE_DEFAULT);
}
}
}
nsIFormControl*
nsHTMLFormElement::FindDefaultSubmit(PRBool aPrevDefaultInElements,
PRUint32 aPrevDefaultIndex) const
{
nsIFormControl* defaultSubmit = nsnull;
// Find the first submit control in the elements list. This list is
// in document order.
PRUint32 length = mControls->mElements.Length();
// If the previous default submit element was in the elements
// list, begin the search of the elements list at that index. Given
// that the list is sorted, the new default submit cannot be before
// the index of the old child as it already would've been the default submit.
PRUint32 i = aPrevDefaultInElements ? aPrevDefaultIndex : 0;
for (; i < length; ++i) {
nsIFormControl* currentControl = mControls->mElements[i];
if (currentControl->IsSubmitControl()) {
defaultSubmit = currentControl;
break;
}
}
// <input type=image> elements are submit controls but are not in the
// elements list. Search the not-in-elements list to find any submit control
// that is ordered in the document before any submit element found already.
// See the comment above for when not to start the search at the first
// element.
length = mControls->mNotInElements.Length();
i = !aPrevDefaultInElements ? aPrevDefaultIndex : 0;
for (; i < length; ++i) {
nsIFormControl* currControl = mControls->mNotInElements[i];
if (currControl->IsSubmitControl()) {
if (!defaultSubmit ||
CompareFormControlPosition(currControl, defaultSubmit,
NS_CONST_CAST(nsHTMLFormElement*, this)) < 0) {
defaultSubmit = currControl;
}
break;
}
}
return defaultSubmit;
}
NS_IMETHODIMP
nsHTMLFormElement::RemoveElementFromTable(nsIFormControl* aElement,
const nsAString& aName)
@ -1632,6 +1598,10 @@ nsHTMLFormElement::GetSortedControls(nsTArray<nsIFormControl*>& aControls) const
NS_IMETHODIMP_(nsIFormControl*)
nsHTMLFormElement::GetDefaultSubmitElement() const
{
NS_PRECONDITION(mDefaultSubmitElement == mFirstSubmitInElements ||
mDefaultSubmitElement == mFirstSubmitNotInElements,
"What happened here?");
return mDefaultSubmitElement;
}

View File

@ -69,6 +69,14 @@ _TEST_FILES = test_bug589.html \
bug340800_iframe.txt \
test_bug340800.html \
test_bug330705-1.html \
test_bug332893-1.html \
test_bug332893-2.html \
test_bug332893-3.html \
test_bug332893-4.html \
test_bug332893-5.html \
test_bug332893-6.html \
test_bug353415-1.html \
test_bug353415-2.html \
test_bug371375.html \
test_bug373589.html \
bug372098-link-target.html \

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<form id="form1">
<input id="F1I1" type="input" value="11"/>
<input id="F1I2" type="input" value="12"/>
</form>
<form id="form2">
<input id="F2I1" type="input" value="21"/>
<input id="F2I2" type="input" value="22"/>
</form>
<script>
<!-- Create a new input, add it to the first form, move it to the 2nd form, then move it back to the first -->
var form1 = document.getElementById("form1");
var form2 = document.getElementById("form2");
var newInput = document.createElement("input");
newInput.value = "13";
form1.insertBefore(newInput, form1.firstChild);
var F2I2 = document.getElementById("F2I2");
form2.insertBefore(newInput, F2I2);
form1.insertBefore(newInput, form1.firstChild);
is(form1.elements.length, "3", "Form 1 has the correct length");
is(form1.elements[0].value, "13", "Form 1 element 1 is correct");
is(form1.elements[1].value, "11", "Form 1 element 2 is correct");
is(form1.elements[2].value, "12", "Form 1 element 3 is correct");
is(form2.elements.length, "2", "Form 2 has the correct length");
is(form2.elements[0].value, "21", "Form 2 element 1 is correct");
is(form2.elements[1].value, "22", "Form 2 element 2 is correct");
</script>
</body>
</html>

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<form id="form1">
<table>
<tbody id="table1">
<tr id="F1I1"><td><input type="input" value="11"/></td></tr>
<tr id="F1I2"><td><input type="input" value="12"/></td></tr>
</tbody>
</table>
</form>
<form id="form2">
<table>
<tbody id="table2">
<tr id="F2I1"><td><input type="input" value="21"/></td></tr>
<tr id="F2I2"><td><input type="input" value="22"/></td></tr>
</tbody>
</table>
</form>
<script>
var table1 = document.getElementById("table1");
var F1I1 = table1.getElementsByTagName("tr")[0];
table1.removeChild(F1I1);
var table2 = document.getElementById("table2");
table2.insertBefore(F1I1, table2.firstChild);
var form1 = document.getElementById("form1");
var form2 = document.getElementById("form2");
is(form1.elements.length, 1, "Form 1 length is correct");
is(form1.elements[0].value, "12", "Form 1 element is correct");
is(form2.elements.length, 3, "Form 2 length is correct");
is(form2.elements[0].value, "11", "Form 2 element 1 is correct");
is(form2.elements[1].value, "21", "Form 2 element 2 is correct");
is(form2.elements[2].value, "22", "Form 2 element 3 is correct");
</script>
</body>
</html>

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<form id="form1">
<table>
<tbody>
<tr>
<td>
<table>
<tbody id="table1">
<tr id="F1I1"><td><input type="input" value="11"/></td></tr>
<tr id="F1I2"><td><input type="input" value="12"/></td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
<form id="form2">
<table>
<tbody id="table2">
<tr id="F2I1"><td><input type="input" value="21"/></td></tr>
<tr id="F2I2"><td><input type="input" value="22"/></td></tr>
</tbody>
</table>
</form>
<script>
var table1 = document.getElementById("table1");
var F1I1 = table1.getElementsByTagName("tr")[0];
table1.removeChild(F1I1);
var table2 = document.getElementById("table2");
table2.insertBefore(F1I1, table2.firstChild);
var form1 = document.getElementById("form1");
var form2 = document.getElementById("form2");
is(form1.elements.length, "1", "Form 1 has the correct length");
is(form1.elements[0].value, "12", "Form 1 element 1 is correct");
is(form2.elements.length, "3", "Form 2 has the correct length");
is(form2.elements[0].value, "11", "Form 2 element 1 is correct");
is(form2.elements[1].value, "21", "Form 2 element 2 is correct");
is(form2.elements[2].value, "22", "Form 2 element 2 is correct");
</script>
</body>
</html>

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<form id="form1">
<input id="input1" type="input" name="input" value="1"/>
<input id="input2" type="input" name="input" value="2"/>
<input id="input3" type="input" name="input" value="3"/>
</form>
<script>
var input1 = document.getElementById("input1");
var input2 = document.getElementById("input2");
var form1 = document.getElementById("form1");
form1.insertBefore(input2, input1);
is(form1.elements["input"].length, "3", "Form 1 'input' has the correct length");
todo(form1.elements["input"][0].value == "2", "Form 1 element 1 is correct");
todo(form1.elements["input"][1].value == "1", "Form 1 element 2 is correct");
todo(form1.elements["input"][2].value == "3", "Form 1 element 3 is correct");
todo(form1.elements["input"][0].id == "input2", "Form 1 element 1 id is correct");
todo(form1.elements["input"][1].id == "input1", "Form 1 element 2 id is correct");
todo(form1.elements["input"][2].id == "input3", "Form 1 element 3 id is correct");
</script>
</body>
</html>

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<form id="form1">
<input id="input1" type="input" name="input" value="1"/>
<input id="input" type="input" name="input_other" value="2"/>
<input id="input3" type="input" name="input" value="3"/>
</form>
<script>
var input1 = document.getElementById("input1");
var input2 = document.getElementById("input");
var form1 = document.getElementById("form1");
form1.insertBefore(input2, input1);
is(form1.elements["input"].length, "3", "Form 1 'input' has the correct length");
todo(form1.elements["input"][0].value == "2", "Form 1 element 1 is correct");
todo(form1.elements["input"][1].value == "1", "Form 1 element 2 is correct");
todo(form1.elements["input"][2].value == "3", "Form 1 element 3 is correct");
todo(form1.elements["input"][0].id == "input", "Form 1 element 1 id is correct");
todo(form1.elements["input"][1].id == "input1", "Form 1 element 2 id is correct");
todo(form1.elements["input"][2].id == "input3", "Form 1 element 3 id is correct");
</script>
</body>
</html>

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<form id="form1">
<input id="input1" type="input" name="input" value="1"/>
<input id="input" type="input" name="input_other" value="2"/>
<input id="input3" type="input" name="input" value="3"/>
</form>
<script>
var input1 = document.getElementById("input1");
var input2 = document.getElementById("input");
var form1 = document.getElementById("form1");
form1.insertBefore(input2, input1);
is(form1.elements["input"].length, "3", "Form 1 'input' has the correct length");
todo(form1.elements["input"][0].value == "2", "Form 1 element 1 is correct");
todo(form1.elements["input"][1].value == "1", "Form 1 element 2 is correct");
todo(form1.elements["input"][0].id == "input", "Form 1 element 1 id is correct");
todo(form1.elements["input"][1].id == "input1", "Form 1 element 2 id is correct");
</script>
</body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<iframe name="submit_frame" onLoad="doCheck();"></iframe>
<form method="get" id="form1" target="submit_frame" action="../../../../../blah">
<input type="text" name="field1" value="teststring"><br>
<input type="radio" name="field2" value="0" checked> 0
<input type="radio" name="field3" value="1"> 1<br>
<input type="checkbox" name="field4" value="1" checked> 1
<input type="checkbox" name="field5" value="2"> 2
<input type="checkbox" name="field6" value="3" checked> 3
<select name="field7">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input name="field8" value="8">
<input name="field9" value="9">
<input type="image" name="field10">
<label name="field11">
<input name="field12">
<input type="button" name="field13" value="button">
</form>
<script>
document.forms[0].submit();
SimpleTest.waitForExplicitFinish();
function doCheck(){
is(frames['submit_frame'].location.href, "http://localhost:8888/blah?field1=teststring&field2=0&field4=1&field6=3&field7=2&field8=8&field9=9&field12=", "Submit string was correct.");
SimpleTest.finish();
}
</script>
</body>
</html>

View File

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<iframe name="submit_frame" onLoad="doCheck();"></iframe>
<form method="get" id="form1" target="submit_frame" action="../../../../../blah">
<table>
<tr><td>
<input type="text" name="field1" value="teststring"><br>
<input type="radio" name="field2" value="0" checked> 0
<input type="radio" name="field3" value="1"> 1<br>
<input type="checkbox" name="field4" value="1" checked> 1
<input type="checkbox" name="field5" value="2"> 2
<input type="checkbox" name="field6" value="3" checked> 3
<select name="field7">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input name="field8" value="8">
<input name="field9" value="9">
<input type="image" name="field10">
<label name="field11">
<input name="field12">
<input type="button" name="field13" value="button">
<input type="hidden" name="field14" value="14">
</td>
<input type="text" name="field1-2" value="teststring"><br>
<input type="radio" name="field2-2" value="0" checked> 0
<input type="radio" name="field3-2" value="1"> 1<br>
<input type="checkbox" name="field4-2" value="1" checked> 1
<input type="checkbox" name="field5-2" value="2"> 2
<input type="checkbox" name="field6-2" value="3" checked> 3
<select name="field7-2">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input name="field8-2" value="8">
<input name="field9-2" value="9">
<input type="image" name="field10-2">
<label name="field11-2">
<input name="field12-2">
<input type="button" name="field13-2" value="button">
<input type="hidden" name="field14-2" value="14">
</tr>
</table>
</form>
<script>
document.forms[0].submit();
SimpleTest.waitForExplicitFinish();
function doCheck(){
is(frames['submit_frame'].location.href, "http://localhost:8888/blah?field1-2=teststring&field2-2=0&field4-2=1&field6-2=3&field7-2=2&field8-2=8&field9-2=9&field12-2=&field14-2=14&field1=teststring&field2=0&field4=1&field6=3&field7=2&field8=8&field9=9&field12=&field14=14", "Submit string was correct.");
SimpleTest.finish();
}
</script>
</body>
</html>

View File

@ -202,9 +202,9 @@ public:
nsresult ChangeContentEditableCount(nsIContent *aElement, PRInt32 aChange);
virtual PRBool IsEditingOn()
virtual EditingState GetEditingState()
{
return mEditingState != eOff;
return mEditingState;
}
virtual void DisableCookieAccess()
@ -375,12 +375,6 @@ protected:
nsresult EditingStateChanged();
PRUint32 mContentEditableCount;
enum EditingState {
eSettingUp = -1,
eOff = 0,
eDesignMode,
eContentEditable
};
EditingState mEditingState;
PRPackedBool mScriptsEnabled;
PRPackedBool mPluginsEnabled;

View File

@ -55,9 +55,8 @@ class nsIDOMHTMLBodyElement;
class nsIScriptElement;
#define NS_IHTMLDOCUMENT_IID \
{ 0xf6aa3582, 0x67c3, 0x4f42, \
{ 0xb6, 0xee, 0x89, 0x19, 0x24, 0x5c, 0x15, 0x89 } }
{ 0x61e989a8, 0x70cd, 0x4582, \
{ 0x84, 0x5e, 0x6e, 0x5e, 0x12, 0x55, 0x9a, 0x83 } }
/**
* HTML document extensions to nsIDocument.
@ -140,10 +139,27 @@ public:
virtual nsresult ChangeContentEditableCount(nsIContent *aElement,
PRInt32 aChange) = 0;
enum EditingState {
eSettingUp = -1,
eOff = 0,
eDesignMode,
eContentEditable
};
/**
* Returns whether the document is editable.
*/
virtual PRBool IsEditingOn() = 0;
PRBool IsEditingOn()
{
return GetEditingState() == eDesignMode ||
GetEditingState() == eContentEditable;
}
/**
* Returns the editing state of the document (not editable, contentEditable or
* designMode).
*/
virtual EditingState GetEditingState() = 0;
/**
* Returns the result of document.all[aID] which can either be a node

View File

@ -185,16 +185,23 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
nsCAutoString mimeType;
channel->GetContentType(mimeType);
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
nsCOMPtr<nsIPrincipal> channelPrincipal;
if (secMan) {
secMan->GetChannelPrincipal(channel, getter_AddRefs(channelPrincipal));
}
PRInt16 decision = nsIContentPolicy::ACCEPT;
nsresult rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_IMAGE,
channelURI,
nsnull,
channelPrincipal,
domWindow->GetFrameElementInternal(),
mimeType,
nsnull,
&decision,
nsContentUtils::GetContentPolicy());
nsContentUtils::GetContentPolicy(),
secMan);
if (NS_FAILED(rv) || NS_CP_REJECTED(decision)) {
request->Cancel(NS_ERROR_CONTENT_BLOCKED);

View File

@ -63,7 +63,7 @@ class nsXBLDocGlobalObject : public nsIScriptGlobalObject,
public nsIScriptObjectPrincipal
{
public:
nsXBLDocGlobalObject();
nsXBLDocGlobalObject(nsIScriptGlobalObjectOwner *aGlobalObjectOwner);
// nsISupports interface
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -73,8 +73,6 @@ public:
virtual nsresult SetScriptContext(PRUint32 lang_id, nsIScriptContext *aContext);
virtual nsIScriptContext *GetContext();
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
virtual JSObject *GetGlobalJSObject();
virtual void OnFinalize(PRUint32 aLangID, void *aScriptGlobal);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
@ -89,6 +87,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXBLDocGlobalObject,
nsIScriptGlobalObject)
void ClearGlobalObjectOwner();
protected:
virtual ~nsXBLDocGlobalObject();
@ -195,9 +195,9 @@ JSClass nsXBLDocGlobalObject::gSharedGlobalClass = {
// nsXBLDocGlobalObject
//
nsXBLDocGlobalObject::nsXBLDocGlobalObject()
nsXBLDocGlobalObject::nsXBLDocGlobalObject(nsIScriptGlobalObjectOwner *aGlobalObjectOwner)
: mJSObject(nsnull),
mGlobalObjectOwner(nsnull)
mGlobalObjectOwner(aGlobalObjectOwner) // weak reference
{
}
@ -352,15 +352,9 @@ nsXBLDocGlobalObject::GetContext()
}
void
nsXBLDocGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
nsXBLDocGlobalObject::ClearGlobalObjectOwner()
{
mGlobalObjectOwner = aOwner; // weak reference
}
nsIScriptGlobalObjectOwner *
nsXBLDocGlobalObject::GetGlobalObjectOwner()
{
return mGlobalObjectOwner;
mGlobalObjectOwner = nsnull;
}
JSObject *
@ -458,7 +452,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocumentInfo)
if (tmp->mBindingTable) {
tmp->mBindingTable->Enumerate(TraverseProtos, &cb);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalObject)
cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObject*>(tmp->mGlobalObject));
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXBLDocumentInfo)
@ -498,7 +492,7 @@ nsXBLDocumentInfo::~nsXBLDocumentInfo()
if (mGlobalObject) {
// remove circular reference
mGlobalObject->SetScriptContext(nsIProgrammingLanguage::JAVASCRIPT, nsnull);
mGlobalObject->SetGlobalObjectOwner(nsnull); // just in case
mGlobalObject->ClearGlobalObjectOwner(); // just in case
}
delete mBindingTable;
}
@ -577,13 +571,11 @@ nsIScriptGlobalObject*
nsXBLDocumentInfo::GetScriptGlobalObject()
{
if (!mGlobalObject) {
mGlobalObject = new nsXBLDocGlobalObject();
if (!mGlobalObject)
nsXBLDocGlobalObject *global = new nsXBLDocGlobalObject(this);
if (!global)
return nsnull;
mGlobalObject->SetGlobalObjectOwner(this); // does not refcount
mGlobalObject = global;
}
return mGlobalObject;

View File

@ -35,6 +35,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsIXBLDocumentInfo.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsWeakReference.h"
@ -43,6 +44,7 @@
class nsXBLPrototypeBinding;
class nsObjectHashtable;
class nsXBLDocGlobalObject;
class nsXBLDocumentInfo : public nsIXBLDocumentInfo, public nsIScriptGlobalObjectOwner, public nsSupportsWeakReference
{
@ -82,5 +84,5 @@ private:
// non-owning pointer to the first binding in the table
nsXBLPrototypeBinding* mFirstBinding;
nsCOMPtr<nsIScriptGlobalObject> mGlobalObject;
nsRefPtr<nsXBLDocGlobalObject> mGlobalObject;
};

View File

@ -110,6 +110,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult)
nsICSSLoader* cssLoader = doc->CSSLoader();
nsIURI *docURL = doc->GetDocumentURI();
nsIPrincipal* docPrincipal = doc->NodePrincipal();
nsCOMPtr<nsIURI> url;
@ -122,7 +123,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult)
continue;
if (curr->mType == nsGkAtoms::image) {
if (!nsContentUtils::CanLoadImage(url, doc, doc, doc->NodePrincipal())) {
if (!nsContentUtils::CanLoadImage(url, doc, doc, docPrincipal)) {
// We're not permitted to load this image, move on...
continue;
}
@ -131,7 +132,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult)
// Passing NULL for pretty much everything -- cause we don't care!
// XXX: initialDocumentURI is NULL!
nsCOMPtr<imgIRequest> req;
nsContentUtils::LoadImage(url, doc, doc->NodePrincipal(), docURL, nsnull,
nsContentUtils::LoadImage(url, doc, docPrincipal, docURL, nsnull,
nsIRequest::LOAD_BACKGROUND,
getter_AddRefs(req));
}
@ -155,7 +156,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult)
}
else
{
rv = cssLoader->LoadSheet(url, docURL, doc->NodePrincipal(), this);
rv = cssLoader->LoadSheet(url, docPrincipal, this);
if (NS_SUCCEEDED(rv))
++mPendingSheets;
}

View File

@ -763,12 +763,13 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
PRInt16 decision = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET,
url,
mDocument->GetDocumentURI(),
mDocument->NodePrincipal(),
aElement,
type,
nsnull,
&decision,
nsContentUtils::GetContentPolicy());
nsContentUtils::GetContentPolicy(),
nsContentUtils::GetSecurityManager());
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -448,9 +448,11 @@ CheckLoadURI(nsIURI *aUri, nsIURI *aReferrerUri,
// Then do a content policy check.
PRInt16 decision = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET,
aUri, aReferrerUri, aContext,
aUri, aReferrerPrincipal, aContext,
NS_LITERAL_CSTRING("application/xml"), nsnull,
&decision);
&decision,
nsContentUtils::GetContentPolicy(),
nsContentUtils::GetSecurityManager());
NS_ENSURE_SUCCESS(rv, rv);
return NS_CP_REJECTED(decision) ? NS_ERROR_XSLT_LOAD_BLOCKED_ERROR : NS_OK;
@ -473,9 +475,9 @@ protected:
nsAutoRefCnt mRefCnt;
private:
nsCOMPtr<nsIPrincipal> mCallerPrincipal;
nsRefPtr<txMozillaXSLTProcessor> mProcessor;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsIPrincipal> mCallerPrincipal;
protected:
// This exists solely to suppress a warning from nsDerivedSafe

View File

@ -3700,7 +3700,7 @@ nsXULDocument::AddPrototypeSheets()
nsCOMPtr<nsIURI> uri = sheets[i];
nsCOMPtr<nsICSSStyleSheet> incompleteSheet;
rv = CSSLoader()->LoadSheet(uri, mCurrentPrototype->GetURI(),
rv = CSSLoader()->LoadSheet(uri,
mCurrentPrototype->DocumentPrincipal(),
this, getter_AddRefs(incompleteSheet));

View File

@ -79,8 +79,6 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
// nsIScriptGlobalObject methods
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
virtual void OnFinalize(PRUint32 aLangID, void *aGlobal);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
virtual nsresult SetNewArguments(nsIArray *aArguments);
@ -97,6 +95,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPDGlobalObject,
nsIScriptGlobalObject)
void ClearGlobalObjectOwner();
protected:
virtual ~nsXULPDGlobalObject();
@ -109,7 +109,7 @@ protected:
};
nsIPrincipal* nsXULPrototypeDocument::gSystemPrincipal;
nsIScriptGlobalObject* nsXULPrototypeDocument::gSystemGlobal;
nsXULPDGlobalObject* nsXULPrototypeDocument::gSystemGlobal;
PRUint32 nsXULPrototypeDocument::gRefCnt;
@ -155,7 +155,6 @@ JSClass nsXULPDGlobalObject::gSharedGlobalClass = {
nsXULPrototypeDocument::nsXULPrototypeDocument()
: mRoot(nsnull),
mGlobalObject(nsnull),
mLoaded(PR_FALSE)
{
++gRefCnt;
@ -175,7 +174,7 @@ nsXULPrototypeDocument::~nsXULPrototypeDocument()
{
if (mGlobalObject) {
// cleaup cycles etc.
mGlobalObject->SetGlobalObjectOwner(nsnull);
mGlobalObject->ClearGlobalObjectOwner();
}
PRUint32 count = mProcessingInstructions.Length();
@ -198,13 +197,13 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULPrototypeDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mRoot,
nsXULPrototypeElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalObject)
cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObject*>(tmp->mGlobalObject));
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPrototypeDocument)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsISerializable)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsISerializable)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULPrototypeDocument,
@ -237,29 +236,27 @@ NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult)
// This method greatly reduces the number of nsXULPDGlobalObjects and their
// nsIScriptContexts in apps that load many XUL documents via chrome: URLs.
nsresult
nsXULPrototypeDocument::NewXULPDGlobalObject(nsIScriptGlobalObject** aResult)
nsXULPDGlobalObject *
nsXULPrototypeDocument::NewXULPDGlobalObject()
{
// Now compare DocumentPrincipal() to gSystemPrincipal, in order to create
// gSystemGlobal if the two pointers are equal. Thus, gSystemGlobal
// implies gSystemPrincipal.
nsCOMPtr<nsIScriptGlobalObject> global;
nsXULPDGlobalObject *global;
if (DocumentPrincipal() == gSystemPrincipal) {
if (!gSystemGlobal) {
gSystemGlobal = new nsXULPDGlobalObject(nsnull);
if (! gSystemGlobal)
return NS_ERROR_OUT_OF_MEMORY;
return nsnull;
NS_ADDREF(gSystemGlobal);
}
global = gSystemGlobal;
} else {
global = new nsXULPDGlobalObject(this); // does not refcount
if (! global)
return NS_ERROR_OUT_OF_MEMORY;
return nsnull;
}
*aResult = global;
NS_ADDREF(*aResult);
return NS_OK;
return global;
}
//----------------------------------------------------------------------
@ -292,8 +289,9 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
// Better safe than sorry....
mNodeInfoManager->SetDocumentPrincipal(principal);
// nsIScriptGlobalObject mGlobalObject
NewXULPDGlobalObject(getter_AddRefs(mGlobalObject));
mGlobalObject = NewXULPDGlobalObject();
if (! mGlobalObject)
return NS_ERROR_OUT_OF_MEMORY;
@ -603,7 +601,7 @@ nsIScriptGlobalObject*
nsXULPrototypeDocument::GetScriptGlobalObject()
{
if (!mGlobalObject)
NewXULPDGlobalObject(getter_AddRefs(mGlobalObject));
mGlobalObject = NewXULPDGlobalObject();
return mGlobalObject;
}
@ -759,25 +757,15 @@ nsXULPDGlobalObject::GetScriptGlobal(PRUint32 lang_id)
void
nsXULPDGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
nsXULPDGlobalObject::ClearGlobalObjectOwner()
{
if (!aOwner) {
PRUint32 lang_ndx;
NS_STID_FOR_INDEX(lang_ndx) {
if (mScriptContexts[lang_ndx]) {
mScriptContexts[lang_ndx]->FinalizeContext();
mScriptContexts[lang_ndx] = nsnull;
}
if (mScriptContexts[lang_ndx]) {
mScriptContexts[lang_ndx]->FinalizeContext();
mScriptContexts[lang_ndx] = nsnull;
}
}
} else {
NS_NOTREACHED("You can only set an owner when constructing the object.");
}
}
nsIScriptGlobalObjectOwner *
nsXULPDGlobalObject::GetGlobalObjectOwner()
{
return mGlobalObjectOwner;
}

View File

@ -155,7 +155,7 @@ protected:
nsTArray<nsXULPrototypePI*> mProcessingInstructions;
nsCOMArray<nsIURI> mStyleSheetReferences;
nsCOMPtr<nsIScriptGlobalObject> mGlobalObject;
nsRefPtr<nsXULPDGlobalObject> mGlobalObject;
PRPackedBool mLoaded;
nsTArray< nsRefPtr<nsXULDocument> > mPrototypeWaiters;
@ -169,10 +169,10 @@ protected:
friend NS_IMETHODIMP
NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult);
nsresult NewXULPDGlobalObject(nsIScriptGlobalObject** aResult);
nsXULPDGlobalObject *NewXULPDGlobalObject();
static nsIPrincipal* gSystemPrincipal;
static nsIScriptGlobalObject* gSystemGlobal;
static nsXULPDGlobalObject* gSystemGlobal;
static PRUint32 gRefCnt;
friend class nsXULPDGlobalObject;

View File

@ -3531,7 +3531,6 @@ nsDocShell::Destroy()
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(mScriptGlobal));
win->SetDocShell(nsnull);
mScriptGlobal->SetGlobalObjectOwner(nsnull);
mScriptGlobal = nsnull;
}
@ -6380,9 +6379,21 @@ nsDocShell::InternalLoad(nsIURI * aURI,
if (!context) {
context = mScriptGlobal;
}
// XXXbz would be nice to know the loading principal here... but we don't
nsCOMPtr<nsIPrincipal> loadingPrincipal;
if (aReferrer) {
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = secMan->GetCodebasePrincipal(aReferrer,
getter_AddRefs(loadingPrincipal));
}
rv = NS_CheckContentLoadPolicy(contentType,
aURI,
aReferrer,
loadingPrincipal,
context,
EmptyCString(), //mime guess
nsnull, //extra
@ -8500,22 +8511,25 @@ nsDocShell::EnsureScriptEnvironment()
do_GetService(kDOMScriptObjectFactoryCID);
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> parent;
GetParent(getter_AddRefs(parent));
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
NS_ENSURE_TRUE(browserChrome, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsPIDOMWindow> pw(do_GetInterface(parent));
PRUint32 chromeFlags;
browserChrome->GetChromeFlags(&chromeFlags);
// If the parent (chrome or not) is a modal content window, make
// this window a modal content window as well.
PRBool isModalContentWindow =
(chromeFlags & nsIWebBrowserChrome::CHROME_MODAL) &&
!(chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME);
// If our window is modal and we're not opened as chrome, make
// this window a modal content window.
factory->NewScriptGlobalObject(mItemType == typeChrome,
pw && pw->IsModalContentWindow(),
isModalContentWindow,
getter_AddRefs(mScriptGlobal));
NS_ENSURE_TRUE(mScriptGlobal, NS_ERROR_FAILURE);
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(mScriptGlobal));
win->SetDocShell(static_cast<nsIDocShell *>(this));
mScriptGlobal->
SetGlobalObjectOwner(static_cast<nsIScriptGlobalObjectOwner *>(this));
// Ensure the script object is set to run javascript - other languages
// setup on demand.

View File

@ -220,14 +220,9 @@ CheckPingURI(nsIURI* uri, nsIContent* content)
// Check with contentpolicy
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
nsIURI* docURI = nsnull;
nsIDocument* doc = content->GetOwnerDoc();
if (doc) {
docURI = doc->GetDocumentURI();
}
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_PING,
uri,
docURI,
content->NodePrincipal(),
content,
EmptyCString(), // mime hint
nsnull, //extra

View File

@ -102,9 +102,9 @@ NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
#define NS_ISCRIPTGLOBALOBJECT_IID \
{ /* {6E7EF978-47D0-47c9-9649-CDCDB1E4CCEC} */ \
0x6e7ef978, 0x47d0, 0x47c9, \
{ 0x96, 0x49, 0xcd, 0xcd, 0xb1, 0xe4, 0xcc, 0xec } }
{ /* {6afecd40-0b9a-4cfd-8c42-0f645cd91829} */ \
0x6afecd40, 0x0b9a, 0x4cfd, \
{ 0x8c, 0x42, 0x0f, 0x64, 0x5c, 0xd9, 0x18, 0x29 } }
/**
+ * The global object which keeps a script context for each supported script
@ -116,23 +116,6 @@ class nsIScriptGlobalObject : public nsISupports
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
/**
* Let the script global object know who its owner is.
* The script global object should not addref the owner. It
* will be told when the owner goes away.
* @return NS_OK if the method is successful
*/
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) = 0;
/**
* Get the owner of the script global object. The method
* addrefs the returned reference according to regular
* XPCOM rules, even though the internal reference itself
* is a "weak" reference.
*/
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner() = 0;
/**
* Ensure that the script global object is initialized for working with the
* specified script language ID. This will set up the nsIScriptContext

View File

@ -1405,18 +1405,6 @@ PrintWarningOnConsole(JSContext *cx, const char *stringBundleProperty)
}
}
static inline JSObject *
GetGlobalJSObject(JSContext *cx, JSObject *obj)
{
JSObject *tmp;
while ((tmp = ::JS_GetParent(cx, obj))) {
obj = tmp;
}
return obj;
}
static jsval
GetInternedJSVal(JSContext *cx, const char *str)
{
@ -1540,7 +1528,7 @@ nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = sXPConnect->WrapNative(cx, GetGlobalJSObject(cx, scope),
nsresult rv = sXPConnect->WrapNative(cx, ::JS_GetGlobalForObject(cx, scope),
native, aIID, getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
@ -3642,7 +3630,7 @@ nsDOMClassInfo::PostCreate(nsIXPConnectWrappedNative *wrapper,
// LookupProperty accomplishes that.
// XXX This shouldn't need to go through the JS engine. Instead, we should
// be calling nsWindowSH::GlobalResolve directly.
JSObject *global = GetGlobalJSObject(cx, obj);
JSObject *global = ::JS_GetGlobalForObject(cx, obj);
jsval val;
if (!::JS_LookupProperty(cx, global, mData->mName, &val)) {
return NS_ERROR_UNEXPECTED;
@ -3725,7 +3713,7 @@ nsresult
nsDOMClassInfo::ResolveConstructor(JSContext *cx, JSObject *obj,
JSObject **objp)
{
JSObject *global = GetGlobalJSObject(cx, obj);
JSObject *global = ::JS_GetGlobalForObject(cx, obj);
jsval val;
JSAutoRequest ar(cx);
@ -4130,7 +4118,8 @@ nsWindowSH::GlobalScopePolluterGetProperty(JSContext *cx, JSObject *obj,
// global scope, do a security check to make sure that's ok.
nsresult rv =
sSecMan->CheckPropertyAccess(cx, GetGlobalJSObject(cx, obj), "Window", id,
sSecMan->CheckPropertyAccess(cx, ::JS_GetGlobalForObject(cx, obj),
"Window", id,
nsIXPCSecurityManager::ACCESS_GET_PROPERTY);
if (NS_FAILED(rv)) {
@ -4156,7 +4145,8 @@ nsWindowSH::SecurityCheckOnSetProp(JSContext *cx, JSObject *obj, jsval id,
// global scope, do a security check to make sure that's ok.
nsresult rv =
sSecMan->CheckPropertyAccess(cx, GetGlobalJSObject(cx, obj), "Window", id,
sSecMan->CheckPropertyAccess(cx, ::JS_GetGlobalForObject(cx, obj),
"Window", id,
nsIXPCSecurityManager::ACCESS_SET_PROPERTY);
// If !NS_SUCCEEDED(rv) the security check failed. The security
@ -6168,7 +6158,7 @@ nsWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
scope = GetGlobalJSObject(cx, scope);
scope = ::JS_GetGlobalForObject(cx, scope);
jsval v;
rv = sXPConnect->GetCrossOriginWrapperForObject(cx, scope, winObj, &v);
*_retval = NS_SUCCEEDED(rv) ? JSVAL_TO_OBJECT(v) : nsnull;
@ -6737,7 +6727,7 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper,
nsresult rv;
JSObject *scope = GetGlobalJSObject(cx, obj);
JSObject *scope = ::JS_GetGlobalForObject(cx, obj);
if (compile) {
rv = manager->CompileScriptEventListener(script_cx, scope, piTarget, atom,
@ -7472,7 +7462,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval)
{
if (argc > 2) {
JSObject *global = GetGlobalJSObject(cx, obj);
JSObject *global = ::JS_GetGlobalForObject(cx, obj);
// DOM0 quirk that makes document.open() call window.open() if
// called with 3 or more arguments.
@ -7744,7 +7734,7 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSObject *obj, jsval id,
nsIHTMLDocument *doc = (nsIHTMLDocument *)::JS_GetPrivate(cx, obj);
JSObject *tags = ::JS_NewObject(cx, &sHTMLDocumentAllTagsClass, nsnull,
GetGlobalJSObject(cx, obj));
::JS_GetGlobalForObject(cx, obj));
if (!tags) {
return JS_FALSE;
}
@ -7888,7 +7878,7 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
}
JSObject *all = ::JS_NewObject(cx, &sHTMLDocumentAllClass, nsnull,
GetGlobalJSObject(cx, obj));
::JS_GetGlobalForObject(cx, obj));
if (!all) {
return JS_FALSE;
}
@ -8080,7 +8070,7 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
helper = ::JS_NewObject(cx, &sHTMLDocumentAllHelperClass,
::JS_GetPrototype(cx, obj),
GetGlobalJSObject(cx, obj));
::JS_GetGlobalForObject(cx, obj));
if (!helper) {
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -446,7 +446,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
mFireOfflineStatusChangeEventOnThaw(PR_FALSE),
mCreatingInnerWindow(PR_FALSE),
mIsChrome(PR_FALSE),
mGlobalObjectOwner(nsnull),
mTimeoutInsertionPoint(nsnull),
mTimeoutPublicIdCounter(1),
mTimeoutFiringDepth(0),
@ -1891,22 +1890,6 @@ nsGlobalWindow::SetOpenerWindow(nsIDOMWindowInternal* aOpener,
#endif
}
void
nsGlobalWindow::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
{
FORWARD_TO_OUTER_VOID(SetGlobalObjectOwner, (aOwner));
mGlobalObjectOwner = aOwner; // Note this is supposed to be a weak ref.
}
nsIScriptGlobalObjectOwner *
nsGlobalWindow::GetGlobalObjectOwner()
{
FORWARD_TO_OUTER(GetGlobalObjectOwner, (), nsnull);
return mGlobalObjectOwner;
}
nsresult
nsGlobalWindow::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{
@ -5111,6 +5094,10 @@ nsGlobalWindow::GetFrameElement(nsIDOMElement** aFrameElement)
return NS_OK;
}
// Helper for converting window.showModalDialog() options (list of ';'
// separated name (:|=) value pairs) to a format that's parsable by
// our normal window opening code.
void
ConvertDialogOptions(const nsAString& aOptions, nsAString& aResult)
{
@ -5239,12 +5226,15 @@ nsGlobalWindow::ShowModalDialog(const nsAString& aURI, nsIVariant *aArgs,
nsCOMPtr<nsIDOMWindow> dlgWin;
nsAutoString options(NS_LITERAL_STRING("modal=1,status=1"));
nsAutoString dialogOptions(aOptions);
ConvertDialogOptions(dialogOptions, options);
ConvertDialogOptions(aOptions, options);
options.AppendLiteral(",scrollbars=1,centerscreen=1,resizable=0");
// Before bringing up the window, unsuppress painting and flush
// pending reflows.
EnsureReflowFlushAndPaint();
nsresult rv = OpenInternal(aURI, EmptyString(), options,
PR_FALSE, // aDialog
PR_TRUE, // aCalledNoScript
@ -5253,7 +5243,7 @@ nsGlobalWindow::ShowModalDialog(const nsAString& aURI, nsIVariant *aArgs,
GetPrincipal(), // aCalleePrincipal
nsnull, // aJSCallerContext
getter_AddRefs(dlgWin));
if (NS_FAILED(rv))
if (NS_FAILED(rv) || !dlgWin)
return NS_OK;
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(dlgWin));
@ -6867,8 +6857,56 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
nsresult
nsGlobalWindow::SetTimeoutOrInterval(PRBool aIsInterval, PRInt32 *aReturn)
{
FORWARD_TO_INNER(SetTimeoutOrInterval, (aIsInterval, aReturn),
NS_ERROR_NOT_INITIALIZED);
// This needs to forward to the inner window, but since the current
// inner may not be the inner in the calling scope, we need to treat
// this specially here as we don't want timeouts registered in a
// dying inner window to get registered and run on the current inner
// window. To get this right, we need to forward this call to the
// inner window that's calling window.setTimeout().
if (IsOuterWindow()) {
nsCOMPtr<nsIXPCNativeCallContext> ncc;
nsresult rv = nsContentUtils::XPConnect()->
GetCurrentNativeCallContext(getter_AddRefs(ncc));
NS_ENSURE_SUCCESS(rv, rv);
if (!ncc) {
return NS_ERROR_NOT_AVAILABLE;
}
JSContext *cx = nsnull;
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, rv);
JSObject *scope = ::JS_GetScopeChain(cx);
if (!scope) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, ::JS_GetGlobalForObject(cx, scope),
getter_AddRefs(wrapper));
NS_ENSURE_TRUE(wrapper, NS_ERROR_NOT_AVAILABLE);
nsGlobalWindow *callerInner = FromWrapper(wrapper);
NS_ENSURE_TRUE(callerInner, NS_ERROR_NOT_AVAILABLE);
// If the caller and the callee share the same outer window,
// forward to the callee inner. Else, we forward to the current
// inner (e.g. someone is calling setTimeout() on a reference to
// some other window).
if (callerInner->GetOuterWindow() == this &&
callerInner->IsInnerWindow()) {
return callerInner->SetTimeoutOrInterval(aIsInterval, aReturn);
}
FORWARD_TO_INNER(SetTimeoutOrInterval, (aIsInterval, aReturn),
NS_ERROR_NOT_INITIALIZED);
}
PRInt32 interval = 0;
PRBool isInterval = aIsInterval;

View File

@ -253,8 +253,6 @@ public:
// for the context is created by the context's GetNativeGlobal() method.
virtual nsresult SetScriptContext(PRUint32 lang, nsIScriptContext *aContext);
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
virtual void OnFinalize(PRUint32 aLangID, void *aScriptGlobal);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
virtual nsresult SetNewArguments(nsIArray *aArguments);
@ -676,7 +674,6 @@ protected:
void * mScriptGlobals[NS_STID_ARRAY_UBOUND];
nsGlobalWindowObserver* mObserver;
nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // Weak Reference
nsCOMPtr<nsIDOMCrypto> mCrypto;
nsCOMPtr<nsIDOMPkcs11> mPkcs11;

View File

@ -367,6 +367,8 @@ nsresult NS_CreateJSTimeoutHandler(nsIScriptContext *aContext,
delete handler;
return rv;
}
return handler->QueryInterface(NS_GET_IID(nsIScriptTimeoutHandler),
reinterpret_cast<void **>(aRet));
NS_ADDREF(*aRet = handler);
return NS_OK;
}

View File

@ -275,7 +275,15 @@ Test.Unit.Assertions.prototype = {
},
fail: function(message) {
this.failures++;
this.messages.push("Failure: " + message);
var line = "";
try {
throw new Error("stack");
} catch(e){
line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
}
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
},
info: function(message) {
this.messages.push("Info: " + message);

View File

@ -153,3 +153,8 @@ function test_DOMStorage_global_Item(storage, key, expectedvalue, expectedlength
return item;
}
function is(left, right, str)
{
window.opener.wrappedJSObject.SimpleTest.is(left, right, str);
}

View File

@ -6,10 +6,6 @@
-->
<window id="sample-window" width="400" height="400"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="domstorage_global.js"/>

View File

@ -3552,7 +3552,7 @@ nsHTMLEditor::ReplaceStyleSheet(const nsAString& aURL)
rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
NS_ENSURE_SUCCESS(rv, rv);
rv = cssLoader->LoadSheet(uaURI, nsnull, nsnull, this);
rv = cssLoader->LoadSheet(uaURI, nsnull, this);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

View File

@ -69,6 +69,8 @@ REQUIRES = xpcom \
locale \
embed_base \
view \
caps \
xpconnect \
$(NULL)
ifdef MOZ_PHOENIX

View File

@ -176,24 +176,6 @@ nsPrompt::Init()
// nsPrompt::nsIPrompt
//*****************************************************************************
class nsAutoWindowStateHelper
{
public:
nsAutoWindowStateHelper(nsIDOMWindow *aWindow);
~nsAutoWindowStateHelper();
PRBool DefaultEnabled()
{
return mDefaultEnabled;
}
protected:
PRBool DispatchCustomEvent(const char *aEventName);
nsIDOMWindow *mWindow;
PRBool mDefaultEnabled;
};
nsAutoWindowStateHelper::nsAutoWindowStateHelper(nsIDOMWindow *aWindow)
: mWindow(aWindow),
mDefaultEnabled(DispatchCustomEvent("DOMWillOpenModalDialog"))
@ -228,9 +210,6 @@ nsAutoWindowStateHelper::DispatchCustomEvent(const char *aEventName)
#ifdef DEBUG
{
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mWindow));
NS_ASSERTION(window->GetExtantDocument() != nsnull,
"nsPrompt used too early on window object!");
}
#endif

View File

@ -79,6 +79,30 @@ protected:
nsCOMPtr<nsIPromptService2> mPromptService2;
};
/**
* Helper class for dealing with notifications around opening modal
* windows.
*/
class nsAutoWindowStateHelper
{
public:
nsAutoWindowStateHelper(nsIDOMWindow *aWindow);
~nsAutoWindowStateHelper();
PRBool DefaultEnabled()
{
return mDefaultEnabled;
}
protected:
PRBool DispatchCustomEvent(const char *aEventName);
nsIDOMWindow *mWindow;
PRBool mDefaultEnabled;
};
/**
* A class that wraps an nsIAuthPrompt so that it can be used as an
* nsIAuthPrompt2.

View File

@ -546,14 +546,6 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
nsCOMPtr<nsIDOMChromeWindow> chromeParent(do_QueryInterface(aParent));
// If we're not called through our JS version of the API, and we got
// a modal option, treat the window we're opening as a modal content
// window.
if (!aCalledFromJS && argv &&
WinHasOption(features.get(), "modal", 0, nsnull)) {
windowIsModalContentDialog = PR_TRUE;
}
// Make sure we call CalculateChromeFlags() *before* we push the
// callee context onto the context stack so that
// CalculateChromeFlags() sees the actual caller when doing it's
@ -562,6 +554,11 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
aDialog, uriToLoadIsChrome,
!aParent || chromeParent);
if ((chromeFlags & nsIWebBrowserChrome::CHROME_MODAL) &&
!(chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)) {
windowIsModalContentDialog = PR_TRUE;
}
SizeSpec sizeSpec;
CalcSizeSpec(features.get(), sizeSpec);
@ -673,8 +670,9 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
PRBool cancel = PR_FALSE;
rv = windowCreator2->CreateChromeWindow2(parentChrome, chromeFlags,
contextFlags, uriToLoad, &cancel,
getter_AddRefs(newChrome));
contextFlags, uriToLoad,
&cancel,
getter_AddRefs(newChrome));
if (NS_SUCCEEDED(rv) && cancel) {
newChrome = 0; // just in case
rv = NS_ERROR_ABORT;
@ -682,7 +680,7 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
}
else
rv = mWindowCreator->CreateChromeWindow(parentChrome, chromeFlags,
getter_AddRefs(newChrome));
getter_AddRefs(newChrome));
if (newChrome) {
/* It might be a chrome nsXULWindow, in which case it won't have
an nsIDOMWindow (primary content shell). But in that case, it'll
@ -729,7 +727,7 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
}
if ((aDialog || windowIsModalContentDialog) && argv) {
// Set the args on the new object.
// Set the args on the new window.
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(*_retval));
NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED);
rv = scriptGlobal->SetNewArguments(argv);
@ -912,9 +910,37 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
nsCOMPtr<nsIDocShellTreeOwner> newTreeOwner;
newDocShellItem->GetTreeOwner(getter_AddRefs(newTreeOwner));
nsCOMPtr<nsIWebBrowserChrome> newChrome(do_GetInterface(newTreeOwner));
if (newChrome)
newChrome->ShowAsModal();
NS_ASSERTION(newChrome, "show modal window failed: no available chrome");
// Throw an exception here if no web browser chrome is available,
// we need that to show a modal window.
NS_ENSURE_TRUE(newChrome, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsPIDOMWindow> modalContentWindow;
// Dispatch dialog events etc, but we only want to do that if
// we're opening a modal content window (the helper classes are
// no-ops if given no window), for chrome dialogs we don't want to
// do any of that (it's done elsewhere for us).
if (windowIsModalContentDialog) {
modalContentWindow = do_QueryInterface(*_retval);
}
nsAutoWindowStateHelper windowStateHelper(modalContentWindow);
if (!windowStateHelper.DefaultEnabled()) {
// Default to cancel not opening the modal window.
NS_RELEASE(*_retval);
return NS_OK;
}
// Reset popup state while opening a modal dialog, and firing
// events about the dialog, to prevent the current state from
// being active the whole time a modal dialog is open.
nsAutoPopupStatePusher popupStatePusher(modalContentWindow, openAbused);
newChrome->ShowAsModal();
}
return NS_OK;

View File

@ -60,6 +60,9 @@ REQUIRES = xpcom \
layout \
pref \
docshell \
caps \
xpconnect \
js \
$(NULL)
CPPSRCS = \

View File

@ -60,11 +60,10 @@
#ifndef HUNSPELL_WARNING
#ifdef HUNSPELL_WARNING_ON
#define HUNSPELL_WARNING fprintf
#define WARNVAR warnvar
#else
#define HUNSPELL_WARNING(a,b,...) {}
#define WARNVAR
static inline void HUNSPELL_WARNING(FILE *, const char *, ...) {}
#endif
#define WARNVAR warnvar
#endif
// HUNSTEM def.

View File

@ -1,48 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 Spellchecker Component.
#
# The Initial Developer of the Original Code is
# David Einstein.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): David Einstein <Deinst@world.std.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = myspell
DIRS = src
include $(topsrcdir)/config/rules.mk

View File

@ -1,70 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 Spellchecker Component.
#
# The Initial Developer of the Original Code is
# David Einstein.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): David Einstein <Deinst@world.std.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = myspell
LIBRARY_NAME = myspell_s
FORCE_STATIC_LIB = 1
LIBXUL_LIBRARY = 1
REQUIRES = xpcom \
string \
uconv \
unicharutil \
spellchecker \
xulapp \
$(NULL)
CPPSRCS = affentry.cpp \
affixmgr.cpp \
hashmgr.cpp \
suggestmgr.cpp \
csutil.cpp \
myspell.cpp \
mozMySpell.cpp \
$(NULL)
ifdef MOZ_XUL_APP
CPPSRCS += mozMySpellDirProvider.cpp
endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,101 +0,0 @@
MySpell is a simple spell checker that uses affix
compression and is modelled after the spell checker
ispell.
MySpell was written to explore how affix compression
can be implemented.
The Main features of MySpell are:
1. written in C++ to make it easier to interface with
Pspell, OpenOffice, AbiWord, etc
2. it is stateless, uses no static variables and
should be completely reentrant with almost no
ifdefs
3. it tries to be as compatible with ispell to
the extent it can. It can read slightly modified
versions of munched ispell dictionaries (and it
comes with a munched english wordlist borrowed from
Kevin Atkinson's excellent Aspell.
4. it uses a heavily modified aff file format that
can be derived from ispell aff files but uses
the iso-8859-X character sets only
5. it is simple with *lots* of comments that
describes how the affixes are stored
and tested for (based on the approach used by
ispell).
6. like ispell it has a BSD license (and no
advertising clause)
But ... it has *no* support for adding words
to a personal dictionary, *no* support for converting
between various text encodings, and *no* command line
interface (it is purely meant to be a library).
It can not (in any way) replace all of the functionality
of ispell or aspell/pspell. It is meant as a learning
tool for understanding affix compression and for
being used by front ends like OpenOffice, Abiword, etc.
MySpell has been tested under Linux and Solaris
and has the world's simplest Makefile and no
configure support.
It does come with a simple example program that
spell checks some words and returns suggestions.
To build a static library and an example
program under Linux simply type:
tar -zxvf myspell.tar.gz
cd myspell
make
To run the example program:
./example ./en_US.aff ./en_US.dic checkme.lst
Please play around with it and let me know
what you think.
Developer Credits:
Special credit and thanks go to ispell's creator Geoff Kuenning.
Ispell affix compression code was used as the basis for the
affix code used in MySpell. Specifically Geoff's use of a
conds[] array that makes it easy to check if the conditions
required for a particular affix are present was very
ingenious! Kudos to Geoff. Very nicely done.
BTW: ispell is available under a BSD style license
from Geoff Kuennings ispell website:
http://www.cs.ucla.edu/ficus-members/geoff/ispell.html
The Original MySpell code was written by Kevin Hendricks
and released under a BSD license. An almost complete rewrite
of MySpell for use by the Mozilla project has been developed by
David Einstein (Deinst@world.std.com). David and I are now
working on parallel development tracks to help our respective
projects (Mozilla and OpenOffice.org and we will maintain full
affix file and dictionary file compatibility and work on merging our
versions of MySpell back into a single tree. David has been
a significant help in improving MySpell.
Special thanks also go to La'szlo' Ne'meth <nemethl@gyorsposta.hu>
who is the author of the Hungarian dictionary and who
developed and contributed the code to support compound words in
MySpell and fixed numerous problems with the encoding case conversion
tables.
Thanks,
Kevin Hendricks
kevin.hendricks@sympatico.ca

View File

@ -1,21 +0,0 @@
There is experimental support for languages that need to allow
compound words. To enable compound word support, you need to
add the following lines to your affix (.aff) file.
COMPOUNDFLAG x
COMPOUNDMIN #
where 'x' is replaced by a specific affix character flag that have
been added to the dictionary (*.dic) file for words that can
run together to make a new word. All subwords of the compound word
must have this affix flag for the compound word to be correct.
and where '#' is replaced by the length of the shortest subword of
a compound word. If the "COMPOUNDMIN" line is not found COMPOUNDMIN
will default to 3
This support is still under rapid revisions and will change in the
future. Use only at your own risk.

View File

@ -1,80 +0,0 @@
This is a straight copy of the openoffice myspell component
Changes made for mozilla:
* Renamed *.cxx to .cpp, for the build system
* Replaced the makefile with a mozilla type makefile
* Added a wrapper, implementing mozISpellCheckingEngine and calling myspell
This wrapper does the conversion from unicode to the charset used
by myspell for the current dictionary.
* Rewrote get_current_cs to create tables when needed, to reduce size of
the resulting library.
* Commented out std namespace declarations from .cpp files (using namespace std;)
* Removed #include <unistd.h> for the build system
* Some specific changes are needed for SunONE studio compiler, please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=278672
* The files cctype.h,cstring.h,cstdio.h etc are not supported by all compilers.
So the following files need to be changed.
Refer bug 280901 (http://bugzilla.mozilla.org/show_bug.cgi?id=280901)
- mozilla/extensions/spellcheck/myspell/src/affentry.cpp
Use:
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
instead of
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cstdio>
- mozilla/extensions/spellcheck/myspell/src/affixmgr.cpp
Use:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
instead of:
#include <cstdlib>
#include <cstring>
#include <cstdio>
- mozilla/extensions/spellcheck/myspell/src/affixmgr.hxx
Use:
#include <stdio.h>
instead of:
#include <cstdio>
- mozilla/extensions/spellcheck/myspell/src/csutil.cpp
Use:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
instead of:
#include <cstdlib>
#include <cstring>
#include <cstdio>
- mozilla/extensions/spellcheck/myspell/src/hashmgr.cpp
Use:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
instead of:
#include <cstdlib>
#include <cstring>
#include <cstdio>
- mozilla/extensions/spellcheck/myspell/src/myspell.cpp
Use:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
instead of:
#include <cstring>
#include <cstdlib>
#include <cstdio>
- mozilla/extensions/spellcheck/myspell/src/suggestmgr.cpp
Use:
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
instead of:
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>

View File

@ -1,18 +0,0 @@
Build instructions for munch and unmunch utilities
---------------------------------------------------
Under Linux:
gcc -O2 -omunch -I. munch.c
gcc -O2 -ounmunch -I. unmunch.c
To see the correct syntax, run
./munch
and
./unmunch

View File

@ -1,390 +0,0 @@
#include "license.readme"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "affentry.hxx"
// using namespace std;
extern char * mystrdup(const char * s);
extern char * myrevstrdup(const char * s);
PfxEntry::PfxEntry(AffixMgr* pmgr, affentry* dp)
{
// register affix manager
pmyMgr = pmgr;
// set up its intial values
achar = dp->achar; // char flag
strip = dp->strip; // string to strip
appnd = dp->appnd; // string to append
stripl = dp->stripl; // length of strip string
appndl = dp->appndl; // length of append string
numconds = dp->numconds; // number of conditions to match
xpflg = dp->xpflg; // cross product flag
// then copy over all of the conditions
memcpy(&conds[0],&dp->conds[0],SETSIZE*sizeof(conds[0]));
next = NULL;
nextne = NULL;
nexteq = NULL;
}
PfxEntry::~PfxEntry()
{
achar = '\0';
if (appnd) free(appnd);
if (strip)free(strip);
pmyMgr = NULL;
appnd = NULL;
strip = NULL;
}
// add prefix to this word assuming conditions hold
char * PfxEntry::add(const char * word, int len)
{
int cond;
char tword[MAXWORDLEN+1];
/* make sure all conditions match */
if ((len > stripl) && (len >= numconds)) {
unsigned char * cp = (unsigned char *) word;
for (cond = 0; cond < numconds; cond++) {
if ((conds[*cp++] & (1 << cond)) == 0)
break;
}
if (cond >= numconds) {
/* we have a match so add prefix */
int tlen = 0;
if (appndl) {
strcpy(tword,appnd);
tlen += appndl;
}
char * pp = tword + tlen;
strcpy(pp, (word + stripl));
return mystrdup(tword);
}
}
return NULL;
}
// check if this prefix entry matches
struct hentry * PfxEntry::check(const char * word, int len)
{
int cond; // condition number being examined
int tmpl; // length of tmpword
struct hentry * he; // hash entry of root word or NULL
unsigned char * cp;
char tmpword[MAXWORDLEN+1];
// on entry prefix is 0 length or already matches the beginning of the word.
// So if the remaining root word has positive length
// and if there are enough chars in root word and added back strip chars
// to meet the number of characters conditions, then test it
tmpl = len - appndl;
if ((tmpl > 0) && (tmpl + stripl >= numconds)) {
// generate new root word by removing prefix and adding
// back any characters that would have been stripped
if (stripl) strcpy (tmpword, strip);
strcpy ((tmpword + stripl), (word + appndl));
// now make sure all of the conditions on characters
// are met. Please see the appendix at the end of
// this file for more info on exactly what is being
// tested
cp = (unsigned char *)tmpword;
for (cond = 0; cond < numconds; cond++) {
if ((conds[*cp++] & (1 << cond)) == 0) break;
}
// if all conditions are met then check if resulting
// root word in the dictionary
if (cond >= numconds) {
tmpl += stripl;
if ((he = pmyMgr->lookup(tmpword)) != NULL) {
if (TESTAFF(he->astr, achar, he->alen)) return he;
}
// prefix matched but no root word was found
// if XPRODUCT is allowed, try again but now
// ross checked combined with a suffix
if (xpflg & XPRODUCT) {
he = pmyMgr->suffix_check(tmpword, tmpl, XPRODUCT, (AffEntry *)this);
if (he) return he;
}
}
}
return NULL;
}
SfxEntry::SfxEntry(AffixMgr * pmgr, affentry* dp)
{
// register affix manager
pmyMgr = pmgr;
// set up its intial values
achar = dp->achar; // char flag
strip = dp->strip; // string to strip
appnd = dp->appnd; // string to append
stripl = dp->stripl; // length of strip string
appndl = dp->appndl; // length of append string
numconds = dp->numconds; // number of conditions to match
xpflg = dp->xpflg; // cross product flag
// then copy over all of the conditions
memcpy(&conds[0],&dp->conds[0],SETSIZE*sizeof(conds[0]));
rappnd = myrevstrdup(appnd);
}
SfxEntry::~SfxEntry()
{
achar = '\0';
if (appnd) free(appnd);
if (rappnd) free(rappnd);
if (strip) free(strip);
pmyMgr = NULL;
appnd = NULL;
strip = NULL;
}
// add suffix to this word assuming conditions hold
char * SfxEntry::add(const char * word, int len)
{
int cond;
char tword[MAXWORDLEN+1];
/* make sure all conditions match */
if ((len > stripl) && (len >= numconds)) {
unsigned char * cp = (unsigned char *) (word + len);
for (cond = numconds; --cond >=0; ) {
if ((conds[*--cp] & (1 << cond)) == 0)
break;
}
if (cond < 0) {
/* we have a match so add suffix */
strcpy(tword,word);
int tlen = len;
if (stripl) {
tlen -= stripl;
}
char * pp = (tword + tlen);
if (appndl) {
strcpy(pp,appnd);
tlen += appndl;
} else *pp = '\0';
return mystrdup(tword);
}
}
return NULL;
}
// see if this suffix is present in the word
struct hentry * SfxEntry::check(const char * word, int len, int optflags, AffEntry* ppfx)
{
int tmpl; // length of tmpword
int cond; // condition beng examined
struct hentry * he; // hash entry pointer
unsigned char * cp;
char tmpword[MAXWORDLEN+1];
PfxEntry* ep = (PfxEntry *) ppfx;
// if this suffix is being cross checked with a prefix
// but it does not support cross products skip it
if ((optflags & XPRODUCT) != 0 && (xpflg & XPRODUCT) == 0)
return NULL;
// upon entry suffix is 0 length or already matches the end of the word.
// So if the remaining root word has positive length
// and if there are enough chars in root word and added back strip chars
// to meet the number of characters conditions, then test it
tmpl = len - appndl;
if ((tmpl > 0) && (tmpl + stripl >= numconds)) {
// generate new root word by removing suffix and adding
// back any characters that would have been stripped or
// or null terminating the shorter string
strcpy (tmpword, word);
cp = (unsigned char *)(tmpword + tmpl);
if (stripl) {
strcpy ((char *)cp, strip);
tmpl += stripl;
cp = (unsigned char *)(tmpword + tmpl);
} else *cp = '\0';
// now make sure all of the conditions on characters
// are met. Please see the appendix at the end of
// this file for more info on exactly what is being
// tested
for (cond = numconds; --cond >= 0; ) {
if ((conds[*--cp] & (1 << cond)) == 0) break;
}
// if all conditions are met then check if resulting
// root word in the dictionary
if (cond < 0) {
if ((he = pmyMgr->lookup(tmpword)) != NULL) {
if (TESTAFF(he->astr, achar , he->alen) &&
((optflags & XPRODUCT) == 0 ||
TESTAFF(he->astr, ep->getFlag(), he->alen))) return he;
}
}
}
return NULL;
}
#if 0
Appendix: Understanding Affix Code
An affix is either a prefix or a suffix attached to root words to make
other words.
Basically a Prefix or a Suffix is set of AffEntry objects
which store information about the prefix or suffix along
with supporting routines to check if a word has a particular
prefix or suffix or a combination.
The structure affentry is defined as follows:
struct affentry
{
unsigned char achar; // char used to represent the affix
char * strip; // string to strip before adding affix
char * appnd; // the affix string to add
short stripl; // length of the strip string
short appndl; // length of the affix string
short numconds; // the number of conditions that must be met
short xpflg; // flag: XPRODUCT- combine both prefix and suffix
char conds[SETSIZE]; // array which encodes the conditions to be met
};
Here is a suffix borrowed from the en_US.aff file. This file
is whitespace delimited.
SFX D Y 4
SFX D 0 e d
SFX D y ied [^aeiou]y
SFX D 0 ed [^ey]
SFX D 0 ed [aeiou]y
This information can be interpreted as follows:
In the first line has 4 fields
Field
-----
1 SFX - indicates this is a suffix
2 D - is the name of the character flag which represents this suffix
3 Y - indicates it can be combined with prefixes (cross product)
4 4 - indicates that sequence of 4 affentry structures are needed to
properly store the affix information
The remaining lines describe the unique information for the 4 SfxEntry
objects that make up this affix. Each line can be interpreted
as follows: (note fields 1 and 2 are as a check against line 1 info)
Field
-----
1 SFX - indicates this is a suffix
2 D - is the name of the character flag for this affix
3 y - the string of chars to strip off before adding affix
(a 0 here indicates the NULL string)
4 ied - the string of affix characters to add
5 [^aeiou]y - the conditions which must be met before the affix
can be applied
Field 5 is interesting. Since this is a suffix, field 5 tells us that
there are 2 conditions that must be met. The first condition is that
the next to the last character in the word must *NOT* be any of the
following "a", "e", "i", "o" or "u". The second condition is that
the last character of the word must end in "y".
So how can we encode this information concisely and be able to
test for both conditions in a fast manner? The answer is found
but studying the wonderful ispell code of Geoff Kuenning, et.al.
(now available under a normal BSD license).
If we set up a conds array of 256 bytes indexed (0 to 255) and access it
using a character (cast to an unsigned char) of a string, we have 8 bits
of information we can store about that character. Specifically we
could use each bit to say if that character is allowed in any of the
last (or first for prefixes) 8 characters of the word.
Basically, each character at one end of the word (up to the number
of conditions) is used to index into the conds array and the resulting
value found there says whether the that character is valid for a
specific character position in the word.
For prefixes, it does this by setting bit 0 if that char is valid
in the first position, bit 1 if valid in the second position, and so on.
If a bit is not set, then that char is not valid for that postion in the
word.
If working with suffixes bit 0 is used for the character closest
to the front, bit 1 for the next character towards the end, ...,
with bit numconds-1 representing the last char at the end of the string.
Note: since entries in the conds[] are 8 bits, only 8 conditions
(read that only 8 character positions) can be examined at one
end of a word (the beginning for prefixes and the end for suffixes.
So to make this clearer, lets encode the conds array values for the
first two affentries for the suffix D described earlier.
For the first affentry:
numconds = 1 (only examine the last character)
conds['e'] = (1 << 0) (the word must end in an E)
all others are all 0
For the second affentry:
numconds = 2 (only examine the last two characters)
conds[X] = conds[X] | (1 << 0) (aeiou are not allowed)
where X is all characters *but* a, e, i, o, or u
conds['y'] = (1 << 1) (the last char must be a y)
all other bits for all other entries in the conds array are zero
#endif

View File

@ -1,86 +0,0 @@
#ifndef _AFFIX_HXX_
#define _AFFIX_HXX_
#include "atypes.hxx"
#include "baseaffix.hxx"
#include "affixmgr.hxx"
/* A Prefix Entry */
class PfxEntry : public AffEntry
{
AffixMgr* pmyMgr;
PfxEntry * next;
PfxEntry * nexteq;
PfxEntry * nextne;
PfxEntry * flgnxt;
public:
PfxEntry(AffixMgr* pmgr, affentry* dp );
~PfxEntry();
struct hentry * check(const char * word, int len);
inline bool allowCross() { return ((xpflg & XPRODUCT) != 0); }
inline unsigned char getFlag() { return achar; }
inline const char * getKey() { return appnd; }
char * add(const char * word, int len);
inline PfxEntry * getNext() { return next; }
inline PfxEntry * getNextNE() { return nextne; }
inline PfxEntry * getNextEQ() { return nexteq; }
inline PfxEntry * getFlgNxt() { return flgnxt; }
inline void setNext(PfxEntry * ptr) { next = ptr; }
inline void setNextNE(PfxEntry * ptr) { nextne = ptr; }
inline void setNextEQ(PfxEntry * ptr) { nexteq = ptr; }
inline void setFlgNxt(PfxEntry * ptr) { flgnxt = ptr; }
};
/* A Suffix Entry */
class SfxEntry : public AffEntry
{
AffixMgr* pmyMgr;
char * rappnd;
SfxEntry * next;
SfxEntry * nexteq;
SfxEntry * nextne;
SfxEntry * flgnxt;
public:
SfxEntry(AffixMgr* pmgr, affentry* dp );
~SfxEntry();
struct hentry * check(const char * word, int len, int optflags,
AffEntry* ppfx);
inline bool allowCross() { return ((xpflg & XPRODUCT) != 0); }
inline unsigned char getFlag() { return achar; }
inline const char * getKey() { return rappnd; }
char * add(const char * word, int len);
inline SfxEntry * getNext() { return next; }
inline SfxEntry * getNextNE() { return nextne; }
inline SfxEntry * getNextEQ() { return nexteq; }
inline SfxEntry * getFlgNxt() { return flgnxt; }
inline void setNext(SfxEntry * ptr) { next = ptr; }
inline void setNextNE(SfxEntry * ptr) { nextne = ptr; }
inline void setNextEQ(SfxEntry * ptr) { nexteq = ptr; }
inline void setFlgNxt(SfxEntry * ptr) { flgnxt = ptr; }
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,74 +0,0 @@
#ifndef _AFFIXMGR_HXX_
#define _AFFIXMGR_HXX_
#ifdef __SUNPRO_CC // for SunONE Studio compiler
using namespace std;
#endif
#include "atypes.hxx"
#include "baseaffix.hxx"
#include "hashmgr.hxx"
#include <stdio.h>
class AffixMgr
{
AffEntry * pStart[SETSIZE];
AffEntry * sStart[SETSIZE];
AffEntry * pFlag[SETSIZE];
AffEntry * sFlag[SETSIZE];
HashMgr * pHMgr;
char * trystring;
char * encoding;
char * compound;
int cpdmin;
int numrep;
replentry * reptable;
int nummap;
mapentry * maptable;
bool nosplitsugs;
public:
AffixMgr(const char * affpath, HashMgr * ptr);
~AffixMgr();
struct hentry * affix_check(const char * word, int len);
struct hentry * prefix_check(const char * word, int len);
struct hentry * suffix_check(const char * word, int len, int sfxopts, AffEntry* ppfx);
int expand_rootword(struct guessword * wlst, int maxn,
const char * ts, int wl, const char * ap, int al);
struct hentry * compound_check(const char * word, int len, char compound_flag);
struct hentry * lookup(const char * word);
int get_numrep();
struct replentry * get_reptable();
int get_nummap();
struct mapentry * get_maptable();
char * get_encoding();
char * get_try_string();
char * get_compound();
bool get_nosplitsugs();
private:
int parse_file(const char * affpath);
int parse_try(char * line);
int parse_set(char * line);
int parse_cpdflag(char * line);
int parse_cpdmin(char * line);
int parse_reptable(char * line, FILE * af);
int parse_maptable(char * line, FILE * af);
int parse_affix(char * line, const char at, FILE * af);
void encodeit(struct affentry * ptr, char * cs);
int build_pfxtree(AffEntry* pfxptr);
int build_sfxtree(AffEntry* sfxptr);
AffEntry* process_sfx_in_order(AffEntry* ptr, AffEntry* nptr);
AffEntry* process_pfx_in_order(AffEntry* ptr, AffEntry* nptr);
int process_pfx_tree_to_list();
int process_sfx_tree_to_list();
int process_pfx_order();
int process_sfx_order();
};
#endif

View File

@ -1,45 +0,0 @@
#ifndef _ATYPES_HXX_
#define _ATYPES_HXX_
#define SETSIZE 256
#define MAXAFFIXES 256
#define MAXWORDLEN 100
#define XPRODUCT (1 << 0)
#define MAXLNLEN 1024
#define TESTAFF( a , b , c ) memchr((void *)(a), (int)(b), (size_t)(c) )
struct affentry
{
char * strip;
char * appnd;
short stripl;
short appndl;
short numconds;
short xpflg;
char achar;
char conds[SETSIZE];
};
struct replentry {
char * pattern;
char * replacement;
};
struct mapentry {
char * set;
int len;
};
struct guessword {
char * word;
bool allow;
};
#endif

View File

@ -1,17 +0,0 @@
#ifndef _BASEAFF_HXX_
#define _BASEAFF_HXX_
class AffEntry
{
protected:
char * appnd;
char * strip;
short appndl;
short stripl;
short numconds;
short xpflg;
char achar;
char conds[SETSIZE];
};
#endif

View File

@ -1,292 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "csutil.hxx"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include "nsICaseConversion.h"
#include "nsICharsetConverterManager.h"
#include "nsUnicharUtilCIID.h"
#include "nsUnicharUtils.h"
#ifdef __SUNPRO_CC // for SunONE Studio compiler
using namespace std;
#endif
// strip strings into token based on single char delimiter
// acts like strsep() but only uses a delim char and not
// a delim string
char * mystrsep(char ** stringp, const char delim)
{
char * rv = NULL;
char * mp = *stringp;
int n = strlen(mp);
if (n > 0) {
char * dp = (char *)memchr(mp,(int)((unsigned char)delim),n);
if (dp) {
*stringp = dp+1;
int nc = (int)((unsigned long)dp - (unsigned long)mp);
rv = (char *) malloc(nc+1);
memcpy(rv,mp,nc);
*(rv+nc) = '\0';
return rv;
} else {
rv = (char *) malloc(n+1);
memcpy(rv, mp, n);
*(rv+n) = '\0';
*stringp = mp + n;
return rv;
}
}
return NULL;
}
// replaces strdup with ansi version
char * mystrdup(const char * s)
{
char * d = NULL;
if (s) {
int sl = strlen(s);
d = (char *) malloc(((sl+1) * sizeof(char)));
if (d) memcpy(d,s,((sl+1)*sizeof(char)));
}
return d;
}
// remove cross-platform text line end characters
void mychomp(char * s)
{
int k = strlen(s);
if ((k > 0) && ((*(s+k-1)=='\r') || (*(s+k-1)=='\n'))) *(s+k-1) = '\0';
if ((k > 1) && (*(s+k-2) == '\r')) *(s+k-2) = '\0';
}
// does an ansi strdup of the reverse of a string
char * myrevstrdup(const char * s)
{
char * d = NULL;
if (s) {
int sl = strlen(s);
d = (char *) malloc((sl+1) * sizeof(char));
if (d) {
const char * p = s + sl - 1;
char * q = d;
while (p >= s) *q++ = *p--;
*q = '\0';
}
}
return d;
}
#if 0
// return 1 if s1 is a leading subset of s2
int isSubset(const char * s1, const char * s2)
{
int l1 = strlen(s1);
int l2 = strlen(s2);
if (l1 > l2) return 0;
if (strncmp(s2,s1,l1) == 0) return 1;
return 0;
}
#endif
// return 1 if s1 is a leading subset of s2
int isSubset(const char * s1, const char * s2)
{
while( *s1 && (*s1 == *s2) ) {
s1++;
s2++;
}
return (*s1 == '\0');
}
// return 1 if s1 (reversed) is a leading subset of end of s2
int isRevSubset(const char * s1, const char * end_of_s2, int len)
{
while( (len > 0) && *s1 && (*s1 == *end_of_s2) ) {
s1++;
end_of_s2--;
len --;
}
return (*s1 == '\0');
}
#if 0
// Not needed in mozilla
// convert null terminated string to all caps using encoding
void enmkallcap(char * d, const char * p, const char * encoding)
{
struct cs_info * csconv = get_current_cs(encoding);
while (*p != '\0') {
*d++ = csconv[((unsigned char) *p)].cupper;
p++;
}
*d = '\0';
}
// convert null terminated string to all little using encoding
void enmkallsmall(char * d, const char * p, const char * encoding)
{
struct cs_info * csconv = get_current_cs(encoding);
while (*p != '\0') {
*d++ = csconv[((unsigned char) *p)].clower;
p++;
}
*d = '\0';
}
// convert null terminated string to have intial capital using encoding
void enmkinitcap(char * d, const char * p, const char * encoding)
{
struct cs_info * csconv = get_current_cs(encoding);
memcpy(d,p,(strlen(p)+1));
if (*p != '\0') *d= csconv[((unsigned char)*p)].cupper;
}
#endif
// convert null terminated string to all caps
void mkallcap(char * p, const struct cs_info * csconv)
{
while (*p != '\0') {
*p = csconv[((unsigned char) *p)].cupper;
p++;
}
}
// convert null terminated string to all little
void mkallsmall(char * p, const struct cs_info * csconv)
{
while (*p != '\0') {
*p = csconv[((unsigned char) *p)].clower;
p++;
}
}
// convert null terminated string to have intial capital
void mkinitcap(char * p, const struct cs_info * csconv)
{
if (*p != '\0') *p = csconv[((unsigned char)*p)].cupper;
}
// XXX This function was rewritten for mozilla. Instead of storing the
// conversion tables static in this file, create them when needed
// with help the mozilla backend.
struct cs_info * get_current_cs(const char * es) {
struct cs_info *ccs;
nsCOMPtr<nsIUnicodeEncoder> encoder;
nsCOMPtr<nsIUnicodeDecoder> decoder;
nsCOMPtr<nsICaseConversion> caseConv;
nsresult rv;
nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv))
return nsnull;
rv = ccm->GetUnicodeEncoder(es, getter_AddRefs(encoder));
if (encoder && NS_SUCCEEDED(rv))
encoder->SetOutputErrorBehavior(encoder->kOnError_Replace, nsnull, '?');
if (NS_FAILED(rv))
return nsnull;
rv = ccm->GetUnicodeDecoder(es, getter_AddRefs(decoder));
caseConv = do_GetService(NS_UNICHARUTIL_CONTRACTID, &rv);
if (NS_FAILED(rv))
return nsnull;
ccs = (struct cs_info *) malloc(256 * sizeof(cs_info));
PRInt32 charLength = 256;
PRInt32 uniLength = 512;
char *source = (char *)malloc(charLength * sizeof(char));
PRUnichar *uni = (PRUnichar *)malloc(uniLength * sizeof(PRUnichar));
char *lower = (char *)malloc(charLength * sizeof(char));
char *upper = (char *)malloc(charLength * sizeof(char));
// Create a long string of all chars.
unsigned int i;
for (i = 0x00; i <= 0xff ; ++i) {
source[i] = i;
}
// Convert this long string to unicode
rv = decoder->Convert(source, &charLength, uni, &uniLength);
// Do case conversion stuff, and convert back.
caseConv->ToUpper(uni, uni, uniLength);
encoder->Convert(uni, &uniLength, upper, &charLength);
uniLength = 512;
charLength = 256;
rv = decoder->Convert(source, &charLength, uni, &uniLength);
caseConv->ToLower(uni, uni, uniLength);
encoder->Convert(uni, &uniLength, lower, &charLength);
// Store
for (i = 0x00; i <= 0xff ; ++i) {
ccs[i].cupper = upper[i];
ccs[i].clower = lower[i];
if (ccs[i].clower != (unsigned char)i)
ccs[i].ccase = true;
else
ccs[i].ccase = false;
}
free(source);
free(uni);
free(lower);
free(upper);
return ccs;
}
struct lang_map lang2enc[] = {
{"ca","ISO8859-1"},
{"cs","ISO8859-2"},
{"da","ISO8859-1"},
{"de","ISO8859-1"},
{"el","ISO8859-7"},
{"en","ISO8859-1"},
{"es","ISO8859-1"},
{"fr","ISO8859-1"},
{"hr","ISO8859-2"},
{"hu","ISO8859-2"},
{"it","ISO8859-1"},
{"la","ISO8859-1"},
{"lv","ISO8859-13"},
{"nl","ISO8859-1"},
{"pl","ISO8859-2"},
{"pt","ISO8859-1"},
{"sv","ISO8859-1"},
{"ru","KOI8-R"},
{"bg","microsoft-cp1251"},
};
const char * get_default_enc(const char * lang) {
int n = sizeof(lang2enc) / sizeof(lang2enc[0]);
for (int i = 0; i < n; i++) {
if (strcmp(lang,lang2enc[i].lang) == 0) {
return lang2enc[i].def_enc;
}
}
return NULL;
}

View File

@ -1,73 +0,0 @@
#ifndef __CSUTILHXX__
#define __CSUTILHXX__
// First some base level utility routines
// remove end of line char(s)
void mychomp(char * s);
// duplicate string
char * mystrdup(const char * s);
// duplicate reverse of string
char * myrevstrdup(const char * s);
// parse into tokens with char delimiter
char * mystrsep(char ** sptr, const char delim);
// is one string a leading subset of another
int isSubset(const char * s1, const char * s2);
// is one reverse string a leading subset of the end of another
int isRevSubset(const char * s1, const char * end_of_s2, int s2_len);
// character encoding information
struct cs_info {
unsigned char ccase;
unsigned char clower;
unsigned char cupper;
};
struct enc_entry {
const char * enc_name;
struct cs_info * cs_table;
};
// language to encoding default map
struct lang_map {
const char * lang;
const char * def_enc;
};
struct cs_info * get_current_cs(const char * es);
const char * get_default_enc(const char * lang);
#if 0
// Not needed in mozilla
// convert null terminated string to all caps using encoding
void enmkallcap(char * d, const char * p, const char * encoding);
// convert null terminated string to all little using encoding
void enmkallsmall(char * d, const char * p, const char * encoding);
// convert null terminated string to have intial capital using encoding
void enmkinitcap(char * d, const char * p, const char * encoding);
#endif
// convert null terminated string to all caps
void mkallcap(char * p, const struct cs_info * csconv);
// convert null terminated string to all little
void mkallsmall(char * p, const struct cs_info * csconv);
// convert null terminated string to have intial capital
void mkinitcap(char * p, const struct cs_info * csconv);
#endif

View File

@ -1,224 +0,0 @@
#include "license.readme"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "hashmgr.hxx"
extern void mychomp(char * s);
extern char * mystrdup(const char *);
#ifdef __SUNPRO_CC // for SunONE Studio compiler
using namespace std;
#endif
// build a hash table from a munched word list
HashMgr::HashMgr(const char * tpath)
{
tablesize = 0;
tableptr = NULL;
int ec = load_tables(tpath);
if (ec) {
/* error condition - what should we do here */
fprintf(stderr,"Hash Manager Error : %d\n",ec);
fflush(stderr);
if (tableptr) {
free(tableptr);
tableptr = 0;
}
tablesize = 0;
}
}
HashMgr::~HashMgr()
{
if (tableptr) {
// now pass through hash table freeing up everything
// go through column by column of the table
for (int i=0; i < tablesize; i++) {
struct hentry * pt = &tableptr[i];
struct hentry * nt = NULL;
if (pt) {
if (pt->word) free(pt->word);
if (pt->astr) free(pt->astr);
pt = pt->next;
}
while(pt) {
nt = pt->next;
if (pt->word) free(pt->word);
if (pt->astr) free(pt->astr);
free(pt);
pt = nt;
}
}
free(tableptr);
}
tablesize = 0;
}
// lookup a root word in the hashtable
struct hentry * HashMgr::lookup(const char *word) const
{
struct hentry * dp;
if (tableptr) {
dp = &tableptr[hash(word)];
if (dp->word == NULL) return NULL;
for ( ; dp != NULL; dp = dp->next) {
if (strcmp(word,dp->word) == 0) return dp;
}
}
return NULL;
}
// add a word to the hash table (private)
int HashMgr::add_word(const char * word, int wl, const char * aff, int al)
{
int i = hash(word);
struct hentry * dp = &tableptr[i];
struct hentry* hp;
if (dp->word == NULL) {
dp->wlen = wl;
dp->alen = al;
dp->word = mystrdup(word);
dp->astr = mystrdup(aff);
dp->next = NULL;
if ((wl) && (dp->word == NULL)) return 1;
if ((al) && (dp->astr == NULL)) return 1;
} else {
hp = (struct hentry *) malloc (sizeof(struct hentry));
if (hp == NULL) return 1;
hp->wlen = wl;
hp->alen = al;
hp->word = mystrdup(word);
hp->astr = mystrdup(aff);
hp->next = NULL;
while (dp->next != NULL) dp=dp->next;
dp->next = hp;
if ((wl) && (hp->word == NULL)) return 1;
if ((al) && (hp->astr == NULL)) return 1;
}
return 0;
}
// walk the hash table entry by entry - null at end
struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const
{
//reset to start
if ((col < 0) || (hp == NULL)) {
col = -1;
hp = NULL;
}
if (hp && hp->next != NULL) {
hp = hp->next;
} else {
col++;
hp = (col < tablesize) ? &tableptr[col] : NULL;
// search for next non-blank column entry
while (hp && (hp->word == NULL)) {
col ++;
hp = (col < tablesize) ? &tableptr[col] : NULL;
}
if (col < tablesize) return hp;
hp = NULL;
col = -1;
}
return hp;
}
// load a munched word list and build a hash table on the fly
int HashMgr::load_tables(const char * tpath)
{
int wl, al;
char * ap;
// raw dictionary - munched file
FILE * rawdict = fopen(tpath, "r");
if (rawdict == NULL) {
return 1;
}
// first read the first line of file to get hash table size */
char ts[MAXDELEN];
if (!fgets(ts, MAXDELEN-1,rawdict)) {
fclose(rawdict);
return 2;
}
mychomp(ts);
tablesize = atoi(ts);
if (!tablesize) {
fclose(rawdict);
return 4;
}
tablesize = tablesize + 5;
if ((tablesize %2) == 0) tablesize++;
// allocate the hash table
tableptr = (struct hentry *) calloc(tablesize, sizeof(struct hentry));
if (!tableptr) {
fclose(rawdict);
return 3;
}
// loop through all words on much list and add to hash
// table and create word and affix strings
while (fgets(ts,MAXDELEN-1,rawdict)) {
mychomp(ts);
// split each line into word and affix char strings
ap = strchr(ts,'/');
if (ap) {
*ap = '\0';
ap++;
al = strlen(ap);
} else {
al = 0;
ap = NULL;
}
wl = strlen(ts);
// add the word and its index
if (add_word(ts,wl,ap,al)) {
fclose(rawdict);
return 5;
}
}
fclose(rawdict);
return 0;
}
// the hash function is a simple load and rotate
// algorithm borrowed
int HashMgr::hash(const char * word) const
{
long hv = 0;
for (int i=0; i < 4 && *word != 0; i++)
hv = (hv << 8) | (*word++);
while (*word != 0) {
ROTATE(hv,ROTATE_LEN);
hv ^= (*word++);
}
return (unsigned long) hv % tablesize;
}

View File

@ -1,27 +0,0 @@
#ifndef _HASHMGR_HXX_
#define _HASHMGR_HXX_
#include "htypes.hxx"
class HashMgr
{
int tablesize;
struct hentry * tableptr;
public:
HashMgr(const char * tpath);
~HashMgr();
struct hentry * lookup(const char *) const;
int hash(const char *) const;
struct hentry * walk_hashtable(int & col, struct hentry * hp) const;
private:
HashMgr( const HashMgr & ); // not implemented
HashMgr &operator=( const HashMgr & ); // not implemented
int load_tables(const char * tpath);
int add_word(const char * word, int wl, const char * ap, int al);
};
#endif

View File

@ -1,20 +0,0 @@
#ifndef _HTYPES_HXX_
#define _HTYPES_HXX_
#define MAXDELEN 256
#define ROTATE_LEN 5
#define ROTATE(v,q) \
(v) = ((v) << (q)) | (((v) >> (32 - q)) & ((1 << (q))-1));
struct hentry
{
short wlen;
short alen;
char * word;
char * astr;
struct hentry * next;
};
#endif

Some files were not shown because too many files have changed in this diff Show More