diff --git a/accessible/public/nsIAccessibilityService.h b/accessible/public/nsIAccessibilityService.h index 77b7f91e441..e859630d01e 100644 --- a/accessible/public/nsIAccessibilityService.h +++ b/accessible/public/nsIAccessibilityService.h @@ -44,7 +44,10 @@ #include "nsIAccessibleRetrieval.h" #include "nsIAccessibleEvent.h" +#include "nsAutoPtr.h" + class nsAccessible; +class nsINode; class nsIContent; class nsIDocument; class nsIFrame; @@ -68,65 +71,56 @@ public: * @param aPresShell [in] the presentation shell which contains layout info * for the DOM node */ - virtual nsAccessible* GetAccessibleInShell(nsIDOMNode *aNode, - nsIPresShell *aPresShell) = 0; + virtual nsAccessible* GetAccessibleInShell(nsINode* aNode, + nsIPresShell* aPresShell) = 0; /** * Creates accessible for the given DOM node or frame. */ - virtual nsresult CreateOuterDocAccessible(nsIDOMNode *aNode, - nsIAccessible **aAccessible) = 0; - - virtual nsresult CreateHTML4ButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHyperTextAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLBRAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLLIAccessible(nsIFrame *aFrame, - nsIFrame *aBulletFrame, - const nsAString& aBulletText, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLCheckboxAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLComboboxAccessible(nsIDOMNode *aNode, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLGenericAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLGroupboxAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLHRAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLImageAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLLabelAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLListboxAccessible(nsIDOMNode *aNode, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLMediaAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLRadioButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLSelectOptionAccessible(nsIDOMNode *aNode, - nsIAccessible *aAccParent, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLTableAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLTableCellAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLTextAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLTextFieldAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; - virtual nsresult CreateHTMLCaptionAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) = 0; + virtual already_AddRefed + CreateHTMLBRAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTML4ButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLCaptionAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLCheckboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLComboboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLGroupboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLHRAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLImageAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLLabelAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLLIAccessible(nsIContent* aContent, nsIPresShell* aPresShell, + const nsAString& aBulletText) = 0; + virtual already_AddRefed + CreateHTMLListboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLMediaAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLObjectFrameAccessible(nsObjectFrame* aFrame, nsIContent* aContent, + nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLRadioButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLTableAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLTableCellAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHTMLTextFieldAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateHyperTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; + virtual already_AddRefed + CreateOuterDocAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0; /** * Adds/remove ATK root accessible for gtk+ native window to/from children diff --git a/accessible/src/base/nsAccUtils.cpp b/accessible/src/base/nsAccUtils.cpp index 537b5c8c851..73b06b3f4d8 100644 --- a/accessible/src/base/nsAccUtils.cpp +++ b/accessible/src/base/nsAccUtils.cpp @@ -159,10 +159,10 @@ nsAccUtils::GetPositionAndSizeForXULSelectControlItem(nsIContent *aContent, for (PRUint32 index = 0; index < itemsCount; index++) { nsCOMPtr currItem; control->GetItemAtIndex(index, getter_AddRefs(currItem)); - nsCOMPtr currNode(do_QueryInterface(currItem)); + nsCOMPtr currNode(do_QueryInterface(currItem)); + + nsAccessible* itemAcc = GetAccService()->GetAccessible(currNode); - nsCOMPtr itemAcc; - GetAccService()->GetAccessibleFor(currNode, getter_AddRefs(itemAcc)); if (!itemAcc || State(itemAcc) & nsIAccessibleStates::STATE_INVISIBLE) { (*aSetSize)--; @@ -201,9 +201,9 @@ nsAccUtils::GetPositionAndSizeForXULContainerItem(nsIContent *aContent, for (PRInt32 index = indexOf; index >= 0; index--) { nsCOMPtr item; container->GetItemAtIndex(index, getter_AddRefs(item)); + nsCOMPtr itemNode(do_QueryInterface(item)); - nsCOMPtr itemAcc; - GetAccService()->GetAccessibleFor(item, getter_AddRefs(itemAcc)); + nsAccessible* itemAcc = GetAccService()->GetAccessible(itemNode); if (itemAcc) { PRUint32 itemRole = Role(itemAcc); @@ -222,9 +222,9 @@ nsAccUtils::GetPositionAndSizeForXULContainerItem(nsIContent *aContent, index++) { nsCOMPtr item; container->GetItemAtIndex(index, getter_AddRefs(item)); + nsCOMPtr itemNode(do_QueryInterface(item)); - nsCOMPtr itemAcc; - GetAccService()->GetAccessibleFor(item, getter_AddRefs(itemAcc)); + nsAccessible* itemAcc = GetAccService()->GetAccessible(itemNode); if (itemAcc) { PRUint32 itemRole = Role(itemAcc); diff --git a/accessible/src/base/nsAccessNode.h b/accessible/src/base/nsAccessNode.h index 18fa3cd2da4..c41c82ff033 100644 --- a/accessible/src/base/nsAccessNode.h +++ b/accessible/src/base/nsAccessNode.h @@ -176,12 +176,6 @@ public: */ already_AddRefed GetPresShell(); - /** - * Return true if the accessible still has presentation shell. Light-weight - * version of IsDefunct() method. - */ - PRBool HasWeakShell() const { return !!mWeakShell; } - protected: nsPresContext* GetPresContext(); diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index cfb2afc9ead..5e2e8626406 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -186,268 +186,93 @@ nsAccessibilityService::FireAccessibleEvent(PRUint32 aEvent, return NS_OK; } -// nsAccessibilityService private -nsresult -nsAccessibilityService::GetInfo(nsIFrame *aFrame, nsIWeakReference **aShell, - nsIContent **aContent) -{ - NS_ASSERTION(aFrame,"Error -- 1st argument (aFrame) is null!!"); - if (!aFrame) { - return NS_ERROR_FAILURE; - } - nsIContent* content = aFrame->GetContent(); - if (!content) - return NS_ERROR_FAILURE; - - nsIDocument* document = content->GetOwnerDoc(); - if (!document) - return NS_ERROR_FAILURE; - - NS_ASSERTION(document->GetShell(), - "Error: aFrame's document doesn't have a PresShell!"); - - // do_GetWR only works into a |nsCOMPtr| :-( - nsCOMPtr weakShell = - do_GetWeakReference(document->GetShell()); - - weakShell.forget(aShell); - NS_IF_ADDREF(*aContent = content); - - return NS_OK; -} - //////////////////////////////////////////////////////////////////////////////// // nsIAccessibilityService -nsresult -nsAccessibilityService::CreateOuterDocAccessible(nsIDOMNode* aDOMNode, - nsIAccessible **aOuterDocAccessible) -{ - NS_ENSURE_ARG_POINTER(aDOMNode); - - *aOuterDocAccessible = nsnull; - - nsCOMPtr content(do_QueryInterface(aDOMNode)); - nsCOMPtr outerWeakShell = - nsCoreUtils::GetWeakShellFor(content); - NS_ENSURE_TRUE(outerWeakShell, NS_ERROR_FAILURE); - - nsOuterDocAccessible *outerDocAccessible = - new nsOuterDocAccessible(content, outerWeakShell); - NS_ENSURE_TRUE(outerDocAccessible, NS_ERROR_FAILURE); - - NS_ADDREF(*aOuterDocAccessible = outerDocAccessible); - - return NS_OK; -} - - /** - * HTML widget creation - */ -nsresult -nsAccessibilityService::CreateHTML4ButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) -{ - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTML4ButtonAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; -} - -nsresult -nsAccessibilityService::CreateHTMLButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) -{ - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLButtonAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; -} - -// nsAccessibilityService private already_AddRefed -nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame *aFrame, - nsIWeakReference *aWeakShell, - nsINode *aNode) +nsAccessibilityService::CreateOuterDocAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - // This method assumes we're in an HTML namespace. - nsRefPtr accessible; - - nsCOMPtr content(do_QueryInterface(aNode)); - nsIAtom *tag = content->Tag(); - if (tag == nsAccessibilityAtoms::legend) { - accessible = new nsHTMLLegendAccessible(content, aWeakShell); - } - else if (tag == nsAccessibilityAtoms::option) { - accessible = new nsHTMLSelectOptionAccessible(content, aWeakShell); - } - else if (tag == nsAccessibilityAtoms::optgroup) { - accessible = new nsHTMLSelectOptGroupAccessible(content, aWeakShell); - } - else if (tag == nsAccessibilityAtoms::ul || tag == nsAccessibilityAtoms::ol || - tag == nsAccessibilityAtoms::dl) { - accessible = new nsHTMLListAccessible(content, aWeakShell); - } - else if (tag == nsAccessibilityAtoms::a) { - - // Only some roles truly enjoy life as nsHTMLLinkAccessibles, for details - // see closed bug 494807. - nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(aNode); - if (roleMapEntry && roleMapEntry->role != nsIAccessibleRole::ROLE_NOTHING - && roleMapEntry->role != nsIAccessibleRole::ROLE_LINK) { - - accessible = new nsHyperTextAccessibleWrap(content, aWeakShell); - } else { - accessible = new nsHTMLLinkAccessible(content, aWeakShell); - } - } - else if (tag == nsAccessibilityAtoms::dt || - (tag == nsAccessibilityAtoms::li && - aFrame->GetType() != nsAccessibilityAtoms::blockFrame)) { - // Normally for li, it is created by the list item frame (in nsBlockFrame) - // which knows about the bullet frame; however, in this case the list item - // must have been styled using display: foo - accessible = new nsHTMLLIAccessible(content, aWeakShell, EmptyString()); - } - else if (tag == nsAccessibilityAtoms::abbr || - tag == nsAccessibilityAtoms::acronym || - tag == nsAccessibilityAtoms::blockquote || - tag == nsAccessibilityAtoms::dd || - tag == nsAccessibilityAtoms::form || - tag == nsAccessibilityAtoms::h1 || - tag == nsAccessibilityAtoms::h2 || - tag == nsAccessibilityAtoms::h3 || - tag == nsAccessibilityAtoms::h4 || - tag == nsAccessibilityAtoms::h5 || - tag == nsAccessibilityAtoms::h6 || - tag == nsAccessibilityAtoms::q) { - - accessible = new nsHyperTextAccessibleWrap(content, aWeakShell); - } - else if (tag == nsAccessibilityAtoms::tr) { - accessible = new nsEnumRoleAccessible(content, aWeakShell, - nsIAccessibleRole::ROLE_ROW); - } - else if (nsCoreUtils::IsHTMLTableHeader(content)) { - accessible = new nsHTMLTableHeaderCellAccessibleWrap(content, aWeakShell); - } - - return accessible.forget(); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsOuterDocAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLLIAccessible(nsIFrame *aFrame, - nsIFrame *aBulletFrame, - const nsAString& aBulletText, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTML4ButtonAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLLIAccessible(content, weakShell, aBulletText); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTML4ButtonAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHyperTextAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLButtonAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHyperTextAccessibleWrap(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLButtonAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLCheckboxAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLLIAccessible(nsIContent* aContent, + nsIPresShell* aPresShell, + const nsAString& aBulletText) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLCheckboxAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLLIAccessible(aContent, weakShell, + aBulletText); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLComboboxAccessible(nsIDOMNode *aDOMNode, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHyperTextAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content(do_QueryInterface(aDOMNode)); - *aAccessible = new nsHTMLComboboxAccessible(content, aPresShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLImageAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLCheckboxAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - NS_ENSURE_ARG_POINTER(aAccessible); - *aAccessible = nsnull; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLCheckboxAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; +} - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; +already_AddRefed +nsAccessibilityService::CreateHTMLComboboxAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) +{ + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLComboboxAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; +} +already_AddRefed +nsAccessibilityService::CreateHTMLImageAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) +{ nsCOMPtr htmlDoc = - do_QueryInterface(content->GetCurrentDoc()); + do_QueryInterface(aContent->GetCurrentDoc()); nsCOMPtr mapElm; if (htmlDoc) { nsAutoString mapElmName; - content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::usemap, - mapElmName); + aContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::usemap, + mapElmName); if (!mapElmName.IsEmpty()) { if (mapElmName.CharAt(0) == '#') @@ -456,110 +281,70 @@ nsAccessibilityService::CreateHTMLImageAccessible(nsIFrame *aFrame, } } - if (mapElm) - *aAccessible = new nsHTMLImageMapAccessible(content, weakShell, mapElm); - else - *aAccessible = new nsHTMLImageAccessibleWrap(content, weakShell); - - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = mapElm ? + new nsHTMLImageMapAccessible(aContent, weakShell, mapElm) : + new nsHTMLImageAccessibleWrap(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLGenericAccessible(nsIFrame *aFrame, nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLGroupboxAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - return CreateHyperTextAccessible(aFrame, aAccessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLGroupboxAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLGroupboxAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLListboxAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLGroupboxAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLSelectListAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLListboxAccessible(nsIDOMNode* aDOMNode, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLMediaAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content(do_QueryInterface(aDOMNode)); - *aAccessible = new nsHTMLSelectListAccessible(content, aPresShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsEnumRoleAccessible(aContent, weakShell, + nsIAccessibleRole::ROLE_GROUPING); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLMediaAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame* aFrame, + nsIContent* aContent, + nsIPresShell* aPresShell) { - NS_ENSURE_ARG_POINTER(aAccessible); - *aAccessible = nsnull; + // We can have several cases here: + // 1) a text or html embedded document where the contentDocument variable in + // the object element holds the content; + // 2) web content that uses a plugin, which means we will have to go to + // the plugin to get the accessible content; + // 3) an image or imagemap, where the image frame points back to the object + // element DOMNode. - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - NS_ENSURE_SUCCESS(rv, rv); + if (aFrame->GetRect().IsEmpty()) + return nsnull; - *aAccessible = new nsEnumRoleAccessible(content, weakShell, - nsIAccessibleRole::ROLE_GROUPING); - NS_ENSURE_TRUE(*aAccessible, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); - NS_ADDREF(*aAccessible); - return NS_OK; -} - -/** - * We can have several cases here. - * 1) a text or html embedded document where the contentDocument - * variable in the object element holds the content - * 2) web content that uses a plugin, which means we will - * have to go to the plugin to get the accessible content - * 3) An image or imagemap, where the image frame points back to - * the object element DOMNode - */ -nsresult -nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame, - nsIAccessible **aAccessible) -{ - NS_ENSURE_ARG_POINTER(aAccessible); - *aAccessible = nsnull; - - nsCOMPtr content; - nsCOMPtr weakShell; - GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(content)); - - if (aFrame->GetRect().IsEmpty()) { - return NS_ERROR_FAILURE; - } // 1) for object elements containing either HTML or TXT documents - nsCOMPtr obj(do_QueryInterface(content)); + nsCOMPtr obj(do_QueryInterface(aContent)); if (obj) { nsCOMPtr domDoc; obj->GetContentDocument(getter_AddRefs(domDoc)); - if (domDoc) { - nsCOMPtr DOMNode(do_QueryInterface(content)); - return CreateOuterDocAccessible(DOMNode, aAccessible); - } + if (domDoc) + return CreateOuterDocAccessible(aContent, aPresShell); } #ifdef XP_WIN @@ -571,214 +356,109 @@ nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame, HWND pluginPort = nsnull; aFrame->GetPluginPort(&pluginPort); - *aAccessible = - new nsHTMLWin32ObjectOwnerAccessible(content, weakShell, pluginPort); - NS_ENSURE_TRUE(*aAccessible, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aAccessible); - return NS_OK; + nsAccessible* accessible = new nsHTMLWin32ObjectOwnerAccessible(aContent, + weakShell, + pluginPort); + NS_IF_ADDREF(accessible); + return accessible; } #endif // 3) for images and imagemaps, or anything else with a child frame // we have the object frame, get the image frame - nsIFrame *frame = aFrame->GetFirstChild(nsnull); - if (frame) - return frame->GetAccessible(aAccessible); - - return NS_OK; + nsIFrame* frame = aFrame->GetFirstChild(nsnull); + return frame ? frame->CreateAccessible() : nsnull; } -nsresult -nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLRadioButtonAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLRadioButtonAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLSelectOptionAccessible(nsIDOMNode *aDOMNode, - nsIAccessible *aParent, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLTableAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content(do_QueryInterface(aDOMNode)); - *aAccessible = new nsHTMLSelectOptionAccessible(content, aPresShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTableAccessibleWrap(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLTableAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLTableCellAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLTableAccessibleWrap(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTableCellAccessibleWrap(aContent, + weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLTableCellAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLTextAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - NS_ENSURE_ARG_POINTER(aAccessible); - *aAccessible = nsnull; - - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLTableCellAccessibleWrap(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTextAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLTextAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLTextFieldAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - *aAccessible = nsnull; - - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - // XXX Don't create ATK objects for these - *aAccessible = new nsHTMLTextAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTextFieldAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLTextFieldAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLLabelAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLTextFieldAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLLabelAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLLabelAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLHRAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLLabelAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLHRAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLHRAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLBRAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLHRAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLBRAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } -nsresult -nsAccessibilityService::CreateHTMLBRAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) +already_AddRefed +nsAccessibilityService::CreateHTMLCaptionAccessible(nsIContent* aContent, + nsIPresShell* aPresShell) { - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLBRAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; -} - -nsresult -nsAccessibilityService::CreateHTMLCaptionAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible) -{ - nsCOMPtr content; - nsCOMPtr weakShell; - nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), - getter_AddRefs(content)); - if (NS_FAILED(rv)) - return rv; - - *aAccessible = new nsHTMLCaptionAccessible(content, weakShell); - if (!*aAccessible) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aAccessible); - return NS_OK; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLCaptionAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); + return accessible; } void @@ -1043,16 +723,15 @@ nsAccessibilityService::GetAccessibleFromCache(nsIDOMNode* aNode, // nsIAccesibilityService nsAccessible* -nsAccessibilityService::GetAccessibleInShell(nsIDOMNode *aNode, - nsIPresShell *aPresShell) +nsAccessibilityService::GetAccessibleInShell(nsINode* aNode, + nsIPresShell* aPresShell) { if (!aNode || !aPresShell) return nsnull; - nsCOMPtr node(do_QueryInterface(aNode)); nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); nsRefPtr accessible = - GetAccessible(node, aPresShell, weakShell); + GetAccessible(aNode, aPresShell, weakShell); return accessible; } @@ -1249,7 +928,10 @@ nsAccessibilityService::GetAccessible(nsINode *aNode, // for the image frame is the image content. If the frame is not an image // frame or the node is not an area element then null is returned. // This setup will change when bug 135040 is fixed. - return GetAreaAccessible(weakFrame.GetFrame(), aNode, aWeakShell); + nsAccessible* areaAcc = GetAreaAccessible(weakFrame.GetFrame(), + aNode, aWeakShell); + NS_IF_ADDREF(areaAcc); + return areaAcc; } // Attempt to create an accessible based on what we know. @@ -1269,14 +951,10 @@ nsAccessibilityService::GetAccessible(nsINode *aNode, } } if (weakFrame.IsAlive()) { - nsCOMPtr newAccessible; - weakFrame.GetFrame()->GetAccessible(getter_AddRefs(newAccessible)); - if (newAccessible) { - newAcc = do_QueryObject(newAccessible); - if (InitAccessible(newAcc, nsnull)) - return newAcc.forget(); - return nsnull; - } + newAcc = weakFrame.GetFrame()->CreateAccessible(); + if (InitAccessible(newAcc, nsnull)) + return newAcc.forget(); + return nsnull; } return nsnull; @@ -1412,8 +1090,8 @@ nsAccessibilityService::GetAccessible(nsINode *aNode, // The method creates accessibles for table related content too therefore // we do not call it if accessibles for table related content are // prevented above. - newAcc = CreateHTMLAccessibleByMarkup(weakFrame.GetFrame(), aWeakShell, - aNode); + newAcc = CreateHTMLAccessibleByMarkup(weakFrame.GetFrame(), content, + aWeakShell); if (!newAcc) { // Do not create accessible object subtrees for non-rendered table @@ -1437,9 +1115,7 @@ nsAccessibilityService::GetAccessible(nsINode *aNode, } // Try using frame to do it. - nsCOMPtr newAccessible; - f->GetAccessible(getter_AddRefs(newAccessible)); - newAcc = do_QueryObject(newAccessible); + newAcc = f->CreateAccessible(); } } } @@ -1629,7 +1305,7 @@ nsAccessibilityService::GetRelevantContentNodeFor(nsINode *aNode) return aNode; } -already_AddRefed +nsAccessible* nsAccessibilityService::GetAreaAccessible(nsIFrame *aImageFrame, nsINode *aAreaNode, nsIWeakReference *aWeakShell) @@ -1648,11 +1324,9 @@ nsAccessibilityService::GetAreaAccessible(nsIFrame *aImageFrame, nsRefPtr imageAcc = GetCachedAccessible(aImageFrame->GetContent(), aWeakShell); if (!imageAcc) { - nsCOMPtr imageAccessible; - CreateHTMLImageAccessible(aImageFrame, - getter_AddRefs(imageAccessible)); + imageAcc = CreateHTMLImageAccessible(aImageFrame->GetContent(), + aImageFrame->PresContext()->PresShell()); - imageAcc = do_QueryObject(imageAccessible); if (!InitAccessible(imageAcc, nsnull)) return nsnull; } @@ -1661,14 +1335,12 @@ nsAccessibilityService::GetAreaAccessible(nsIFrame *aImageFrame, // that they should be available in global cache. imageAcc->EnsureChildren(); - nsAccessible *cachedAreaAcc = GetCachedAccessible(aAreaNode, aWeakShell); - NS_IF_ADDREF(cachedAreaAcc); - return cachedAreaAcc; + return GetCachedAccessible(aAreaNode, aWeakShell); } already_AddRefed -nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, - nsIWeakReference *aWeakShell) +nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, + nsIWeakReference* aWeakShell) { nsCOMPtr accessibleProvider(do_QueryInterface(aContent)); if (!accessibleProvider) @@ -1679,12 +1351,13 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, if (NS_FAILED(rv)) return nsnull; - nsRefPtr accessible; if (type == nsIAccessibleProvider::OuterDoc) { - accessible = new nsOuterDocAccessible(aContent, aWeakShell); - return accessible.forget(); + nsAccessible* accessible = new nsOuterDocAccessible(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; } + nsAccessible* accessible = nsnull; switch (type) { #ifdef MOZ_XUL @@ -1695,27 +1368,35 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, case nsIAccessibleProvider::XULAlert: accessible = new nsXULAlertAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULButton: accessible = new nsXULButtonAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULCheckbox: accessible = new nsXULCheckboxAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULColorPicker: accessible = new nsXULColorPickerAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULColorPickerTile: accessible = new nsXULColorPickerTileAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULCombobox: accessible = new nsXULComboboxAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULDropmarker: accessible = new nsXULDropmarkerAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULGroupbox: accessible = new nsXULGroupboxAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULImage: { // Don't include nameless images in accessible tree. @@ -1725,31 +1406,40 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, accessible = new nsHTMLImageAccessibleWrap(aContent, aWeakShell); break; + } case nsIAccessibleProvider::XULLink: accessible = new nsXULLinkAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULListbox: accessible = new nsXULListboxAccessibleWrap(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULListCell: accessible = new nsXULListCellAccessibleWrap(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULListHead: accessible = new nsXULColumnsAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULListHeader: accessible = new nsXULColumnItemAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULListitem: accessible = new nsXULListitemAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULMenubar: accessible = new nsXULMenubarAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULMenuitem: accessible = new nsXULMenuitemAccessibleWrap(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULMenupopup: { #ifdef MOZ_ACCESSIBILITY_ATK @@ -1765,68 +1455,88 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, #endif accessible = new nsXULMenupopupAccessible(aContent, aWeakShell); break; + } case nsIAccessibleProvider::XULMenuSeparator: accessible = new nsXULMenuSeparatorAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULPane: accessible = new nsEnumRoleAccessible(aContent, aWeakShell, nsIAccessibleRole::ROLE_PANE); break; + case nsIAccessibleProvider::XULProgressMeter: accessible = new nsXULProgressMeterAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULStatusBar: accessible = new nsXULStatusBarAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULScale: accessible = new nsXULSliderAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULRadioButton: accessible = new nsXULRadioButtonAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULRadioGroup: accessible = new nsXULRadioGroupAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTab: accessible = new nsXULTabAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTabs: accessible = new nsXULTabsAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTabpanels: accessible = new nsXULTabpanelsAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULText: accessible = new nsXULTextAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTextBox: accessible = new nsXULTextFieldAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULThumb: accessible = new nsXULThumbAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTree: return CreateAccessibleForXULTree(aContent, aWeakShell); case nsIAccessibleProvider::XULTreeColumns: accessible = new nsXULTreeColumnsAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTreeColumnItem: accessible = new nsXULColumnItemAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULToolbar: accessible = new nsXULToolbarAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULToolbarSeparator: accessible = new nsXULToolbarSeparatorAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULTooltip: accessible = new nsXULTooltipAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XULToolbarButton: accessible = new nsXULToolbarButtonAccessible(aContent, aWeakShell); break; + #endif // MOZ_XUL #ifndef DISABLE_XFORMS_HOOKS @@ -1838,45 +1548,59 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, case nsIAccessibleProvider::XFormsLabel: accessible = new nsXFormsLabelAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsOutput: accessible = new nsXFormsOutputAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsTrigger: accessible = new nsXFormsTriggerAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsInput: accessible = new nsXFormsInputAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsInputBoolean: accessible = new nsXFormsInputBooleanAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsInputDate: accessible = new nsXFormsInputDateAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsSecret: accessible = new nsXFormsSecretAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsSliderRange: accessible = new nsXFormsRangeAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsSelect: accessible = new nsXFormsSelectAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsChoices: accessible = new nsXFormsChoicesAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsSelectFull: accessible = new nsXFormsSelectFullAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsItemCheckgroup: accessible = new nsXFormsItemCheckgroupAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsItemRadiogroup: accessible = new nsXFormsItemRadiogroupAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsSelectCombobox: accessible = new nsXFormsSelectComboboxAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsItemCombobox: accessible = new nsXFormsItemComboboxAccessible(aContent, aWeakShell); break; @@ -1884,21 +1608,122 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent, case nsIAccessibleProvider::XFormsDropmarkerWidget: accessible = new nsXFormsDropmarkerWidgetAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsCalendarWidget: accessible = new nsXFormsCalendarWidgetAccessible(aContent, aWeakShell); break; + case nsIAccessibleProvider::XFormsComboboxPopupWidget: accessible = new nsXFormsComboboxPopupWidgetAccessible(aContent, aWeakShell); break; + #endif default: return nsnull; } - return accessible.forget(); + NS_IF_ADDREF(accessible); + return accessible; } +already_AddRefed +nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, + nsIContent* aContent, + nsIWeakReference* aWeakShell) +{ + // This method assumes we're in an HTML namespace. + nsIAtom *tag = aContent->Tag(); + if (tag == nsAccessibilityAtoms::legend) { + nsAccessible* accessible = new nsHTMLLegendAccessible(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::option) { + nsAccessible* accessible = new nsHTMLSelectOptionAccessible(aContent, + aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::optgroup) { + nsAccessible* accessible = new nsHTMLSelectOptGroupAccessible(aContent, + aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::ul || tag == nsAccessibilityAtoms::ol || + tag == nsAccessibilityAtoms::dl) { + nsAccessible* accessible = new nsHTMLListAccessible(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::a) { + // Only some roles truly enjoy life as nsHTMLLinkAccessibles, for details + // see closed bug 494807. + nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(aContent); + if (roleMapEntry && roleMapEntry->role != nsIAccessibleRole::ROLE_NOTHING && + roleMapEntry->role != nsIAccessibleRole::ROLE_LINK) { + nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, + aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + nsAccessible* accessible = new nsHTMLLinkAccessible(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::dt || + (tag == nsAccessibilityAtoms::li && + aFrame->GetType() != nsAccessibilityAtoms::blockFrame)) { + // Normally for li, it is created by the list item frame (in nsBlockFrame) + // which knows about the bullet frame; however, in this case the list item + // must have been styled using display: foo + nsAccessible* accessible = new nsHTMLLIAccessible(aContent, aWeakShell, + EmptyString()); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::abbr || + tag == nsAccessibilityAtoms::acronym || + tag == nsAccessibilityAtoms::blockquote || + tag == nsAccessibilityAtoms::dd || + tag == nsAccessibilityAtoms::form || + tag == nsAccessibilityAtoms::h1 || + tag == nsAccessibilityAtoms::h2 || + tag == nsAccessibilityAtoms::h3 || + tag == nsAccessibilityAtoms::h4 || + tag == nsAccessibilityAtoms::h5 || + tag == nsAccessibilityAtoms::h6 || + tag == nsAccessibilityAtoms::q) { + nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (tag == nsAccessibilityAtoms::tr) { + nsAccessible* accessible = new nsEnumRoleAccessible(aContent, aWeakShell, + nsIAccessibleRole::ROLE_ROW); + NS_IF_ADDREF(accessible); + return accessible; + } + + if (nsCoreUtils::IsHTMLTableHeader(aContent)) { + nsAccessible* accessible = new nsHTMLTableHeaderCellAccessibleWrap(aContent, + aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + return nsnull; + } + //////////////////////////////////////////////////////////////////////////////// // nsIAccessibilityService (DON'T put methods here) @@ -1995,11 +1820,9 @@ NS_GetAccessibilityService(nsIAccessibilityService** aResult) already_AddRefed nsAccessibilityService::CreateAccessibleForDeckChild(nsIFrame* aFrame, - nsIContent *aContent, - nsIWeakReference *aWeakShell) + nsIContent* aContent, + nsIWeakReference* aWeakShell) { - nsRefPtr accessible; - if (aFrame->GetType() == nsAccessibilityAtoms::boxFrame || aFrame->GetType() == nsAccessibilityAtoms::scrollFrame) { @@ -2011,22 +1834,26 @@ nsAccessibilityService::CreateAccessibleForDeckChild(nsIFrame* aFrame, #ifdef MOZ_XUL if (parentContent->NodeInfo()->Equals(nsAccessibilityAtoms::tabpanels, kNameSpaceID_XUL)) { - accessible = new nsXULTabpanelAccessible(aContent, aWeakShell); - } else + nsAccessible* accessible = new nsXULTabpanelAccessible(aContent, + aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } #endif - accessible = - new nsEnumRoleAccessible(aContent, aWeakShell, - nsIAccessibleRole::ROLE_PROPERTYPAGE); + nsAccessible* accessible = new nsEnumRoleAccessible(aContent, aWeakShell, + nsIAccessibleRole::ROLE_PROPERTYPAGE); + NS_IF_ADDREF(accessible); + return accessible; } } - return accessible.forget(); + return nsnull; } #ifdef MOZ_XUL already_AddRefed -nsAccessibilityService::CreateAccessibleForXULTree(nsIContent *aContent, - nsIWeakReference *aWeakShell) +nsAccessibilityService::CreateAccessibleForXULTree(nsIContent* aContent, + nsIWeakReference* aWeakShell) { nsCOMPtr treeBoxObj = nsCoreUtils::GetTreeBoxObject(aContent); if (!treeBoxObj) @@ -2037,15 +1864,19 @@ nsAccessibilityService::CreateAccessibleForXULTree(nsIContent *aContent, if (!treeColumns) return nsnull; - nsRefPtr accessible; - PRInt32 count = 0; treeColumns->GetCount(&count); - if (count == 1) // outline of list accessible - accessible = new nsXULTreeAccessible(aContent, aWeakShell); - else // table or tree table accessible - accessible = new nsXULTreeGridAccessibleWrap(aContent, aWeakShell); - return accessible.forget(); + // Outline of list accessible. + if (count == 1) { + nsAccessible* accessible = new nsXULTreeAccessible(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; + } + + // Table or tree table accessible. + nsAccessible* accessible = new nsXULTreeGridAccessibleWrap(aContent, aWeakShell); + NS_IF_ADDREF(accessible); + return accessible; } #endif diff --git a/accessible/src/base/nsAccessibilityService.h b/accessible/src/base/nsAccessibilityService.h index f4683055924..48c08069378 100644 --- a/accessible/src/base/nsAccessibilityService.h +++ b/accessible/src/base/nsAccessibilityService.h @@ -58,61 +58,53 @@ public: NS_DECL_NSIOBSERVER // nsIAccessibilityService - virtual nsAccessible* GetAccessibleInShell(nsIDOMNode *aNode, - nsIPresShell *aPresShell); + virtual nsAccessible* GetAccessibleInShell(nsINode* aNode, + nsIPresShell* aPresShell); - virtual nsresult CreateOuterDocAccessible(nsIDOMNode *aNode, - nsIAccessible **aAccessible); - virtual nsresult CreateHTML4ButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHyperTextAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLBRAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLLIAccessible(nsIFrame *aFrame, - nsIFrame *aBulletFrame, - const nsAString& aBulletText, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLCheckboxAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLComboboxAccessible(nsIDOMNode *aNode, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLGenericAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLGroupboxAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLHRAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLImageAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLLabelAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLListboxAccessible(nsIDOMNode *aNode, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLMediaAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLRadioButtonAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLSelectOptionAccessible(nsIDOMNode *aNode, - nsIAccessible *aAccParent, - nsIWeakReference *aPresShell, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLTableAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLTableCellAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLTextAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLTextFieldAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); - virtual nsresult CreateHTMLCaptionAccessible(nsIFrame *aFrame, - nsIAccessible **aAccessible); + virtual already_AddRefed + CreateHTMLBRAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTML4ButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLCaptionAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLCheckboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLComboboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLGroupboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLHRAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLImageAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLLabelAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLLIAccessible(nsIContent* aContent, nsIPresShell* aPresShell, + const nsAString& aBulletText); + virtual already_AddRefed + CreateHTMLListboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLMediaAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLObjectFrameAccessible(nsObjectFrame* aFrame, nsIContent* aContent, + nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLRadioButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLTableAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLTableCellAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHTMLTextFieldAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateHyperTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell); + virtual already_AddRefed + CreateOuterDocAccessible(nsIContent* aContent, nsIPresShell* aPresShell); virtual nsAccessible* AddNativeRootAccessible(void* aAtkAccessible); virtual void RemoveNativeRootAccessible(nsAccessible* aRootAccessible); @@ -239,52 +231,39 @@ private: */ void Shutdown(); - /** - * Return presentation shell, DOM node for the given frame. - * - * @param aFrame [in] the given frame - * @param aShell [out] presentation shell for DOM node associated with the - * given frame - * @param aContent [out] DOM node associated with the given frame - */ - nsresult GetInfo(nsIFrame *aFrame, nsIWeakReference **aShell, - nsIContent **aContent); - /** * Return accessible for HTML area element associated with an image map. */ - already_AddRefed - GetAreaAccessible(nsIFrame *aImageFrame, nsINode *aAreaNode, - nsIWeakReference *aWeakShell); + nsAccessible* GetAreaAccessible(nsIFrame* aImageFrame, nsINode* aAreaNode, + nsIWeakReference* aWeakShell); /** * Create accessible for the element implementing nsIAccessibleProvider * interface. */ already_AddRefed - CreateAccessibleByType(nsIContent *aContent, nsIWeakReference *aWeakShell); + CreateAccessibleByType(nsIContent* aContent, nsIWeakReference* aWeakShell); /** * Create accessible for HTML node by tag name. */ already_AddRefed - CreateHTMLAccessibleByMarkup(nsIFrame *aFrame, nsIWeakReference *aWeakShell, - nsINode *aNode); + CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, nsIContent* aContent, + nsIWeakReference* aWeakShell); /** * Create accessible if parent is a deck frame. */ already_AddRefed - CreateAccessibleForDeckChild(nsIFrame *aFrame, nsIContent *aContent, - nsIWeakReference *aWeakShell); + CreateAccessibleForDeckChild(nsIFrame* aFrame, nsIContent* aContent, + nsIWeakReference* aWeakShell); #ifdef MOZ_XUL /** * Create accessible for XUL tree element. */ already_AddRefed - CreateAccessibleForXULTree(nsIContent *aContent, - nsIWeakReference *aWeakShell); + CreateAccessibleForXULTree(nsIContent* aContent, nsIWeakReference* aWeakShell); #endif /** @@ -328,7 +307,7 @@ static const char kRoleNames[][20] = { "nothing", //ROLE_NOTHING "titlebar", //ROLE_TITLEBAR "menubar", //ROLE_MENUBAR - "scrollbar", //ROLE_SCROLLBAR + "scrollbar", //ROLE_SCROLLBAR "grip", //ROLE_GRIP "sound", //ROLE_SOUND "cursor", //ROLE_CURSOR @@ -445,7 +424,7 @@ static const char kRoleNames[][20] = { "listbox option", //ROLE_OPTION "listbox rich option", //ROLE_RICH_OPTION "listbox", //ROLE_LISTBOX - "flat equation", //ROLE_FLAT_EQUATION + "flat equation", //ROLE_FLAT_EQUATION "gridcell", //ROLE_GRID_CELL "embedded object" //ROLE_EMBEDDED_OBJECT }; diff --git a/accessible/src/base/nsApplicationAccessible.cpp b/accessible/src/base/nsApplicationAccessible.cpp index 4dbf2f82244..b0ada234e73 100644 --- a/accessible/src/base/nsApplicationAccessible.cpp +++ b/accessible/src/base/nsApplicationAccessible.cpp @@ -453,9 +453,8 @@ nsApplicationAccessible::CacheChildren() nsCOMPtr DOMDocument; DOMWindow->GetDocument(getter_AddRefs(DOMDocument)); if (DOMDocument) { - nsCOMPtr accessible; - GetAccService()->GetAccessibleFor(DOMDocument, - getter_AddRefs(accessible)); + nsCOMPtr docNode(do_QueryInterface(DOMDocument)); + GetAccService()->GetDocAccessible(docNode); // ensure creation } } windowEnumerator->HasMoreElements(&hasMore); diff --git a/accessible/src/base/nsEventShell.cpp b/accessible/src/base/nsEventShell.cpp index 5fa020035ff..fc155f91dd1 100644 --- a/accessible/src/base/nsEventShell.cpp +++ b/accessible/src/base/nsEventShell.cpp @@ -195,10 +195,6 @@ nsAccEventQueue::WillRefresh(mozilla::TimeStamp aTime) if (!mDocument) return; - nsCOMPtr presShell = mDocument->GetPresShell(); - if (!presShell) - return; - // Process only currently queued events. Newly appended events during events // flushing won't be processed. nsTArray < nsRefPtr > events; @@ -208,14 +204,13 @@ nsAccEventQueue::WillRefresh(mozilla::TimeStamp aTime) for (PRUint32 index = 0; index < length; index ++) { - // No presshell means the document was shut down during event handling - // by AT. - if (!mDocument || !mDocument->HasWeakShell()) - break; - nsAccEvent *accEvent = events[index]; if (accEvent->mEventRule != nsAccEvent::eDoNotEmit) mDocument->ProcessPendingEvent(accEvent); + + // No document means it was shut down during event handling by AT + if (!mDocument) + return; } if (mEvents.Length() == 0) { diff --git a/accessible/src/base/nsRelUtils.cpp b/accessible/src/base/nsRelUtils.cpp index 25d0143a6d3..f272c4ded59 100644 --- a/accessible/src/base/nsRelUtils.cpp +++ b/accessible/src/base/nsRelUtils.cpp @@ -91,10 +91,7 @@ nsRelUtils::AddTargetFromContent(PRUint32 aRelationType, if (!aContent) return NS_OK_NO_RELATION_TARGET; - nsCOMPtr node(do_QueryInterface(aContent)); - - nsCOMPtr accessible; - GetAccService()->GetAccessibleFor(node, getter_AddRefs(accessible)); + nsAccessible* accessible = GetAccService()->GetAccessible(aContent); return AddTarget(aRelationType, aRelation, accessible); } diff --git a/accessible/src/html/nsHTMLSelectAccessible.cpp b/accessible/src/html/nsHTMLSelectAccessible.cpp index a376f2aa9cc..82eb4b911e9 100644 --- a/accessible/src/html/nsHTMLSelectAccessible.cpp +++ b/accessible/src/html/nsHTMLSelectAccessible.cpp @@ -822,10 +822,8 @@ nsIContent* nsHTMLSelectOptionAccessible::GetSelectState(PRUint32* aState, content = content->GetParent(); } - nsCOMPtr selectNode(do_QueryInterface(content)); - if (selectNode) { - nsCOMPtr selAcc; - GetAccService()->GetAccessibleFor(selectNode, getter_AddRefs(selAcc)); + if (content) { + nsAccessible* selAcc = GetAccService()->GetAccessible(content); if (selAcc) { selAcc->GetState(aState, aExtraState); return content; diff --git a/accessible/src/msaa/CAccessibleAction.cpp b/accessible/src/msaa/CAccessibleAction.cpp index ac50acf7ca6..c79f7a8d3b4 100644 --- a/accessible/src/msaa/CAccessibleAction.cpp +++ b/accessible/src/msaa/CAccessibleAction.cpp @@ -72,7 +72,7 @@ CAccessibleAction::nActions(long *aNumActions) __try { *aNumActions = 0; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -92,7 +92,7 @@ STDMETHODIMP CAccessibleAction::doAction(long aActionIndex) { __try { - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -110,7 +110,7 @@ CAccessibleAction::get_description(long aActionIndex, BSTR *aDescription) __try { *aDescription = NULL; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -140,7 +140,7 @@ __try { *aKeyBinding = NULL; *aNumBinding = 0; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -197,7 +197,7 @@ CAccessibleAction::get_name(long aActionIndex, BSTR *aName) __try { *aName = NULL; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleAction.h b/accessible/src/msaa/CAccessibleAction.h index 6dd771f2209..a874ceaf240 100644 --- a/accessible/src/msaa/CAccessibleAction.h +++ b/accessible/src/msaa/CAccessibleAction.h @@ -45,8 +45,7 @@ #include "AccessibleAction.h" -class CAccessibleAction: public nsISupports, - public IAccessibleAction +class CAccessibleAction: public IAccessibleAction { public: @@ -78,6 +77,9 @@ public: /* [in] */ long actionIndex, /* [retval][out] */ BSTR *localizedName); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + }; diff --git a/accessible/src/msaa/CAccessibleComponent.cpp b/accessible/src/msaa/CAccessibleComponent.cpp index 32eeac1564a..3e180c02bdf 100644 --- a/accessible/src/msaa/CAccessibleComponent.cpp +++ b/accessible/src/msaa/CAccessibleComponent.cpp @@ -85,7 +85,7 @@ __try { *aX = 0; *aY = 0; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -160,7 +160,7 @@ CAccessibleComponent::GetARGBValueFromCSSProperty(const nsAString& aPropName, __try { *aColorValue = 0; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleComponent.h b/accessible/src/msaa/CAccessibleComponent.h index 592c81f6061..25e874ac023 100644 --- a/accessible/src/msaa/CAccessibleComponent.h +++ b/accessible/src/msaa/CAccessibleComponent.h @@ -45,8 +45,7 @@ #include "AccessibleComponent.h" -class CAccessibleComponent: public nsISupports, - public IAccessibleComponent +class CAccessibleComponent: public IAccessibleComponent { public: @@ -64,6 +63,9 @@ public: virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_background( /* [retval][out] */ IA2Color *background); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + protected: /** diff --git a/accessible/src/msaa/CAccessibleEditableText.cpp b/accessible/src/msaa/CAccessibleEditableText.cpp index 2a710011b90..d30dc5c048e 100644 --- a/accessible/src/msaa/CAccessibleEditableText.cpp +++ b/accessible/src/msaa/CAccessibleEditableText.cpp @@ -48,7 +48,7 @@ #include "nsString.h" #define GET_NSIACCESSIBLEEDITABLETEXT \ -nsCOMPtr textAcc(do_QueryInterface(this));\ +nsCOMPtr textAcc(do_QueryObject(this));\ NS_ASSERTION(textAcc,\ "Subclass of CAccessibleEditableText doesn't implement nsIAccessibleEditableText");\ if (!textAcc)\ @@ -62,7 +62,7 @@ CAccessibleEditableText::QueryInterface(REFIID iid, void** ppv) *ppv = NULL; if (IID_IAccessibleEditableText == iid) { - nsCOMPtr editTextAcc(do_QueryInterface(this)); + nsCOMPtr editTextAcc(do_QueryObject(this)); if (!editTextAcc) return E_NOINTERFACE; *ppv = static_cast(this); diff --git a/accessible/src/msaa/CAccessibleEditableText.h b/accessible/src/msaa/CAccessibleEditableText.h index 27f412858b8..76987eafeee 100644 --- a/accessible/src/msaa/CAccessibleEditableText.h +++ b/accessible/src/msaa/CAccessibleEditableText.h @@ -46,8 +46,7 @@ #include "AccessibleEditableText.h" -class CAccessibleEditableText: public nsISupports, - public IAccessibleEditableText +class CAccessibleEditableText: public IAccessibleEditableText { public: @@ -83,6 +82,9 @@ public: /* [in] */ long startOffset, /* [in] */ long endOffset, /* [in] */ BSTR *attributes); + + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; }; #endif diff --git a/accessible/src/msaa/CAccessibleHyperlink.cpp b/accessible/src/msaa/CAccessibleHyperlink.cpp index 55d12903821..59ed9bd6d4a 100644 --- a/accessible/src/msaa/CAccessibleHyperlink.cpp +++ b/accessible/src/msaa/CAccessibleHyperlink.cpp @@ -62,7 +62,7 @@ CAccessibleHyperlink::QueryInterface(REFIID iid, void** ppv) *ppv = NULL; if (IID_IAccessibleHyperlink == iid) { - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_NOINTERFACE; @@ -82,7 +82,7 @@ CAccessibleHyperlink::get_anchor(long aIndex, VARIANT *aAnchor) __try { VariantInit(aAnchor); - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -115,7 +115,7 @@ CAccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT *aAnchorTarget) __try { VariantInit(aAnchorTarget); - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -153,7 +153,7 @@ CAccessibleHyperlink::get_startIndex(long *aIndex) __try { *aIndex = 0; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -175,7 +175,7 @@ CAccessibleHyperlink::get_endIndex(long *aIndex) __try { *aIndex = 0; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -197,7 +197,7 @@ CAccessibleHyperlink::get_valid(boolean *aValid) __try { *aValid = false; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleHyperlink.h b/accessible/src/msaa/CAccessibleHyperlink.h index e7523478f56..5b75d61dac9 100644 --- a/accessible/src/msaa/CAccessibleHyperlink.h +++ b/accessible/src/msaa/CAccessibleHyperlink.h @@ -74,6 +74,9 @@ public: virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_valid( /* [retval][out] */ boolean *valid); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + }; #endif diff --git a/accessible/src/msaa/CAccessibleHypertext.cpp b/accessible/src/msaa/CAccessibleHypertext.cpp index eccd4789495..55fced18349 100644 --- a/accessible/src/msaa/CAccessibleHypertext.cpp +++ b/accessible/src/msaa/CAccessibleHypertext.cpp @@ -51,7 +51,7 @@ CAccessibleHypertext::QueryInterface(REFIID iid, void** ppv) { *ppv = NULL; if (IID_IAccessibleHypertext == iid) { - nsCOMPtr hyperAcc(do_QueryInterface(this)); + nsCOMPtr hyperAcc(do_QueryObject(this)); if (!hyperAcc) return E_NOINTERFACE; @@ -117,7 +117,7 @@ CAccessibleHypertext::get_hyperlinkIndex(long aCharIndex, long *aHyperlinkIndex) __try { *aHyperlinkIndex = 0; - nsCOMPtr hyperAcc(do_QueryInterface(this)); + nsCOMPtr hyperAcc(do_QueryObject(this)); if (!hyperAcc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleImage.cpp b/accessible/src/msaa/CAccessibleImage.cpp index 7a7cd0c581c..a12b993acf3 100644 --- a/accessible/src/msaa/CAccessibleImage.cpp +++ b/accessible/src/msaa/CAccessibleImage.cpp @@ -58,7 +58,7 @@ CAccessibleImage::QueryInterface(REFIID iid, void** ppv) *ppv = NULL; if (IID_IAccessibleImage == iid) { - nsCOMPtr imageAcc(do_QueryInterface(this)); + nsCOMPtr imageAcc(do_QueryObject(this)); if (!imageAcc) return E_FAIL; @@ -78,7 +78,7 @@ CAccessibleImage::get_description(BSTR *aDescription) __try { *aDescription = NULL; - nsCOMPtr acc(do_QueryInterface(this)); + nsCOMPtr acc(do_QueryObject(this)); if (!acc) return E_FAIL; @@ -110,7 +110,7 @@ __try { nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; - nsCOMPtr imageAcc(do_QueryInterface(this)); + nsCOMPtr imageAcc(do_QueryObject(this)); if (!imageAcc) return E_FAIL; @@ -135,7 +135,7 @@ __try { *aHeight = 0; *aWidth = 0; - nsCOMPtr imageAcc(do_QueryInterface(this)); + nsCOMPtr imageAcc(do_QueryObject(this)); if (!imageAcc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleImage.h b/accessible/src/msaa/CAccessibleImage.h index 8a6c690c44c..deda9327885 100644 --- a/accessible/src/msaa/CAccessibleImage.h +++ b/accessible/src/msaa/CAccessibleImage.h @@ -45,8 +45,7 @@ #include "AccessibleImage.h" -class CAccessibleImage: public nsISupports, - public IAccessibleImage +class CAccessibleImage: public IAccessibleImage { public: @@ -66,6 +65,9 @@ public: /* [out] */ long *height, /* [retval][out] */ long *width); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + }; #endif diff --git a/accessible/src/msaa/CAccessibleTable.cpp b/accessible/src/msaa/CAccessibleTable.cpp index dee486c7fb2..c98cb8db913 100644 --- a/accessible/src/msaa/CAccessibleTable.cpp +++ b/accessible/src/msaa/CAccessibleTable.cpp @@ -88,7 +88,7 @@ CAccessibleTable::get_accessibleAt(long aRow, long aColumn, __try { *aAccessible = NULL; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -120,7 +120,7 @@ CAccessibleTable::get_caption(IUnknown **aAccessible) __try { *aAccessible = NULL; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -156,7 +156,7 @@ CAccessibleTable::get_childIndex(long aRowIndex, long aColumnIndex, __try { *aChildIndex = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -180,7 +180,7 @@ CAccessibleTable::get_columnDescription(long aColumn, BSTR *aDescription) __try { *aDescription = NULL; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -207,7 +207,7 @@ CAccessibleTable::get_columnExtentAt(long aRow, long aColumn, __try { *nColumnsSpanned = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -243,7 +243,7 @@ CAccessibleTable::get_columnIndex(long aChildIndex, long *aColumnIndex) __try { *aColumnIndex = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -267,7 +267,7 @@ CAccessibleTable::get_nColumns(long *aColumnCount) __try { *aColumnCount = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -291,7 +291,7 @@ CAccessibleTable::get_nRows(long *aRowCount) __try { *aRowCount = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -315,7 +315,7 @@ CAccessibleTable::get_nSelectedChildren(long *aChildCount) __try { *aChildCount = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -338,7 +338,7 @@ CAccessibleTable::get_nSelectedColumns(long *aColumnCount) __try { *aColumnCount = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -361,7 +361,7 @@ CAccessibleTable::get_nSelectedRows(long *aRowCount) __try { *aRowCount = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -384,7 +384,7 @@ CAccessibleTable::get_rowDescription(long aRow, BSTR *aDescription) __try { *aDescription = NULL; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -410,7 +410,7 @@ CAccessibleTable::get_rowExtentAt(long aRow, long aColumn, long *aNRowsSpanned) __try { *aNRowsSpanned = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -446,7 +446,7 @@ CAccessibleTable::get_rowIndex(long aChildIndex, long *aRowIndex) __try { *aRowIndex = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -520,7 +520,7 @@ CAccessibleTable::get_isColumnSelected(long aColumn, boolean *aIsSelected) __try { *aIsSelected = false; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -543,7 +543,7 @@ CAccessibleTable::get_isRowSelected(long aRow, boolean *aIsSelected) __try { *aIsSelected = false; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -566,7 +566,7 @@ CAccessibleTable::get_isSelected(long aRow, long aColumn, boolean *aIsSelected) __try { *aIsSelected = false; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -587,7 +587,7 @@ STDMETHODIMP CAccessibleTable::selectRow(long aRow) { __try { - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -603,7 +603,7 @@ STDMETHODIMP CAccessibleTable::selectColumn(long aColumn) { __try { - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -619,7 +619,7 @@ STDMETHODIMP CAccessibleTable::unselectRow(long aRow) { __try { - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -635,7 +635,7 @@ STDMETHODIMP CAccessibleTable::unselectColumn(long aColumn) { __try { - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -661,7 +661,7 @@ __try { *aColumnExtents = 0; *aIsSelected = false; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -730,7 +730,7 @@ STDMETHODIMP CAccessibleTable::get_selectedCells(IUnknown ***cells, long *nSelectedCells) { __try { - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; @@ -779,7 +779,7 @@ CAccessibleTable::GetSelectedItems(long **aItems, long *aItemsCount, { *aItemsCount = 0; - nsCOMPtr tableAcc(do_QueryInterface(this)); + nsCOMPtr tableAcc(do_QueryObject(this)); NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); if (!tableAcc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleTable.h b/accessible/src/msaa/CAccessibleTable.h index 07176874e6e..9f66e41851f 100644 --- a/accessible/src/msaa/CAccessibleTable.h +++ b/accessible/src/msaa/CAccessibleTable.h @@ -46,8 +46,7 @@ #include "AccessibleTable.h" #include "AccessibleTable2.h" -class CAccessibleTable: public nsISupports, - public IAccessibleTable, +class CAccessibleTable: public IAccessibleTable, public IAccessibleTable2 { public: @@ -195,6 +194,9 @@ public: /* [out, size_is(,*nRows)] */ long **selectedRows, /* [out, retval] */ long *nRows); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + private: enum eItemsType { ITEMSTYPE_CELLS, diff --git a/accessible/src/msaa/CAccessibleTableCell.cpp b/accessible/src/msaa/CAccessibleTableCell.cpp index b3c96f1bba8..a2e0bd83cc3 100644 --- a/accessible/src/msaa/CAccessibleTableCell.cpp +++ b/accessible/src/msaa/CAccessibleTableCell.cpp @@ -79,7 +79,7 @@ STDMETHODIMP CAccessibleTableCell::get_table(IUnknown **table) { __try { - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -113,7 +113,7 @@ CAccessibleTableCell::get_columnExtent(long *nColumnsSpanned) __try { *nColumnsSpanned = 0; - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -138,7 +138,7 @@ CAccessibleTableCell::get_columnHeaderCells(IUnknown ***cellAccessibles, long *nColumnHeaderCells) { __try { - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -163,7 +163,7 @@ CAccessibleTableCell::get_columnIndex(long *columnIndex) __try { *columnIndex = -1; - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -189,7 +189,7 @@ CAccessibleTableCell::get_rowExtent(long *nRowsSpanned) __try { *nRowsSpanned = 0; - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -214,7 +214,7 @@ CAccessibleTableCell::get_rowHeaderCells(IUnknown ***cellAccessibles, long *nRowHeaderCells) { __try { - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -239,7 +239,7 @@ CAccessibleTableCell::get_rowIndex(long *rowIndex) __try { *rowIndex = -1; - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -272,7 +272,7 @@ __try { *columnExtents = 0; *isSelected = false; - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; @@ -320,7 +320,7 @@ CAccessibleTableCell::get_isSelected(boolean *isSelected) __try { *isSelected = false; - nsCOMPtr tableCell(do_QueryInterface(this)); + nsCOMPtr tableCell(do_QueryObject(this)); NS_ASSERTION(tableCell, TABLECELL_INTERFACE_UNSUPPORTED_MSG); if (!tableCell) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleTableCell.h b/accessible/src/msaa/CAccessibleTableCell.h index 1669e5e07c0..18ae3ee9f76 100644 --- a/accessible/src/msaa/CAccessibleTableCell.h +++ b/accessible/src/msaa/CAccessibleTableCell.h @@ -45,8 +45,7 @@ #include "AccessibleTableCell.h" -class CAccessibleTableCell: public nsISupports, - public IAccessibleTableCell +class CAccessibleTableCell: public IAccessibleTableCell { public: @@ -87,6 +86,9 @@ public: virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_isSelected( /* [out, retval] */ boolean *isSelected); + + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; }; #endif diff --git a/accessible/src/msaa/CAccessibleText.cpp b/accessible/src/msaa/CAccessibleText.cpp index fe6d4e72f2d..d12f1d08a44 100644 --- a/accessible/src/msaa/CAccessibleText.cpp +++ b/accessible/src/msaa/CAccessibleText.cpp @@ -55,7 +55,7 @@ #include "nsString.h" #define GET_NSIACCESSIBLETEXT \ -nsCOMPtr textAcc(do_QueryInterface(this));\ +nsCOMPtr textAcc(do_QueryObject(this));\ NS_ASSERTION(textAcc,\ "Subclass of CAccessibleText doesn't implement nsIAccessibleText");\ if (!textAcc)\ @@ -69,7 +69,7 @@ CAccessibleText::QueryInterface(REFIID iid, void** ppv) *ppv = NULL; if (IID_IAccessibleText == iid) { - nsCOMPtr textAcc(do_QueryInterface(this)); + nsCOMPtr textAcc(do_QueryObject(this)); if (!textAcc) { return E_NOINTERFACE; } diff --git a/accessible/src/msaa/CAccessibleText.h b/accessible/src/msaa/CAccessibleText.h index 036ce1c3b11..b3366dd4ef1 100644 --- a/accessible/src/msaa/CAccessibleText.h +++ b/accessible/src/msaa/CAccessibleText.h @@ -46,8 +46,7 @@ #include "AccessibleText.h" -class CAccessibleText: public nsISupports, - public IAccessibleText +class CAccessibleText: public IAccessibleText { public: @@ -148,6 +147,9 @@ public: virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_oldText( /* [retval][out] */ IA2TextSegment *oldText); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + protected: virtual nsresult GetModifiedText(PRBool aGetInsertedText, nsAString& aText, PRUint32 *aStartOffset, diff --git a/accessible/src/msaa/CAccessibleValue.cpp b/accessible/src/msaa/CAccessibleValue.cpp index 29a154ff8d3..d708489c88f 100644 --- a/accessible/src/msaa/CAccessibleValue.cpp +++ b/accessible/src/msaa/CAccessibleValue.cpp @@ -56,7 +56,7 @@ CAccessibleValue::QueryInterface(REFIID iid, void** ppv) *ppv = NULL; if (IID_IAccessibleValue == iid) { - nsCOMPtr valueAcc(do_QueryInterface(this)); + nsCOMPtr valueAcc(do_QueryObject(this)); if (!valueAcc) return E_NOINTERFACE; @@ -76,7 +76,7 @@ CAccessibleValue::get_currentValue(VARIANT *aCurrentValue) __try { VariantInit(aCurrentValue); - nsCOMPtr valueAcc(do_QueryInterface(this)); + nsCOMPtr valueAcc(do_QueryObject(this)); if (!valueAcc) return E_FAIL; @@ -97,7 +97,7 @@ STDMETHODIMP CAccessibleValue::setCurrentValue(VARIANT aValue) { __try { - nsCOMPtr valueAcc(do_QueryInterface(this)); + nsCOMPtr valueAcc(do_QueryObject(this)); if (!valueAcc) return E_FAIL; @@ -117,7 +117,7 @@ CAccessibleValue::get_maximumValue(VARIANT *aMaximumValue) __try { VariantInit(aMaximumValue); - nsCOMPtr valueAcc(do_QueryInterface(this)); + nsCOMPtr valueAcc(do_QueryObject(this)); if (!valueAcc) return E_FAIL; @@ -140,7 +140,7 @@ CAccessibleValue::get_minimumValue(VARIANT *aMinimumValue) __try { VariantInit(aMinimumValue); - nsCOMPtr valueAcc(do_QueryInterface(this)); + nsCOMPtr valueAcc(do_QueryObject(this)); if (!valueAcc) return E_FAIL; diff --git a/accessible/src/msaa/CAccessibleValue.h b/accessible/src/msaa/CAccessibleValue.h index eccc154666e..75533b147d4 100644 --- a/accessible/src/msaa/CAccessibleValue.h +++ b/accessible/src/msaa/CAccessibleValue.h @@ -45,8 +45,7 @@ #include "AccessibleValue.h" -class CAccessibleValue: public nsISupports, - public IAccessibleValue +class CAccessibleValue: public IAccessibleValue { public: @@ -66,6 +65,9 @@ public: virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_minimumValue( /* [retval][out] */ VARIANT *minimumValue); + // nsISupports + NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; + }; #endif diff --git a/accessible/src/msaa/nsAccessNodeWrap.h b/accessible/src/msaa/nsAccessNodeWrap.h index b4f14ff649b..4f2eb5b362d 100644 --- a/accessible/src/msaa/nsAccessNodeWrap.h +++ b/accessible/src/msaa/nsAccessNodeWrap.h @@ -166,7 +166,6 @@ public: // construction, destruction static void DoATSpecificProcessing(); protected: - void GetAccessibleFor(nsIDOMNode *node, nsIAccessible **newAcc); /** * Return ISimpleDOMNode instance for existing accessible object or diff --git a/accessible/src/xforms/nsXFormsAccessible.cpp b/accessible/src/xforms/nsXFormsAccessible.cpp index be731ff3829..e08ec923622 100644 --- a/accessible/src/xforms/nsXFormsAccessible.cpp +++ b/accessible/src/xforms/nsXFormsAccessible.cpp @@ -398,7 +398,6 @@ nsXFormsSelectableAccessible::GetSelectionCount(PRInt32 *aCount) *aCount = 0; nsresult rv; - PRBool thisLineWasReviewedByDavid = PR_FALSE; nsCOMPtr DOMNode(do_QueryInterface(mContent)); if (mIsSelect1Element) { diff --git a/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/browser.js b/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/browser.js index 5386664694f..4641d68d99a 100644 --- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/browser.js +++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/browser.js @@ -150,6 +150,8 @@ var TestPilotMenuUtils; * after startup is complete. It's hacky, but the benefit is that * TestPilotSetup.onWindowLoad can treat all windows the same no matter * whether they opened with Firefox on startup or were opened later. */ + TestPilotWindowHandlers.setUpToolbarFeedbackButton(); + if (TestPilotSetup.startupComplete) { TestPilotSetup.onWindowLoad(window); } else { @@ -165,6 +167,31 @@ var TestPilotMenuUtils; } }, + setUpToolbarFeedbackButton: function() { + /* If this is first run, and it's ffx4 beta version, and the feedback + * button is not in the expected place, put it there! + * (copied from MozReporterButtons extension) */ + if (!window.document.getElementById("feedback-menu-happy-button")) { + return; + } + let firefoxnav = window.document.getElementById("nav-bar"); + let curSet = firefoxnav.currentSet; + + if (-1 == curSet.indexOf("feedback-menu-button")) { + // place the buttons after the search box. + let newSet = curSet + ",feedback-menu-button"; + + firefoxnav.setAttribute("currentset", newSet); + firefoxnav.currentSet = newSet; + window.document.persist("nav-bar", "currentset"); + // if you don't do the following call, funny things happen. + try { + BrowserToolboxCustomizeDone(true); + } catch (e) { + } + } + }, + onWindowUnload: function() { TestPilotSetup.onWindowUnload(window); } diff --git a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js index 7ddec9292d2..8be9462cff7 100644 --- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js +++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js @@ -213,35 +213,6 @@ let TestPilotSetup = { } }, - _setUpToolbarFeedbackButton: function TPS_toolbarFeedbackButton() { - /* If this is first run, and it's ffx4 beta version, and the feedback - * button is not in the expected place, put it there! - * (copied from MozReporterButtons extension) */ - let logger = this._logger; - try { - let win = this._getFrontBrowserWindow(); - let firefoxnav = win.document.getElementById("nav-bar"); - let curSet = firefoxnav.currentSet; - - if (-1 == curSet.indexOf("feedback-menu-button")) { - logger.info("Feedback toolbar button not present: Adding it."); - // place the buttons after the search box. - let newSet = curSet + ",feedback-menu-button"; - - firefoxnav.setAttribute("currentset", newSet); - firefoxnav.currentSet = newSet; - win.document.persist("nav-bar", "currentset"); - // if you don't do the following call, funny things happen. - try { - BrowserToolboxCustomizeDone(true); - } catch (e) { - } - } - } catch (e) { - logger.warn("Error in setUpToolbarFeedbackButton: " + e); - } - }, - globalStartup: function TPS__doGlobalSetup() { // Only ever run this stuff ONCE, on the first window restore. // Should get called by the Test Pilot component. @@ -296,11 +267,8 @@ let TestPilotSetup = { let url = self._prefs.getValue(FIRST_RUN_PREF, ""); let tab = browser.addTab(url); browser.selectedTab = tab; - } else { - // Don't show first run page in ffx4 beta version... but do - // set up the Feedback button in the toolbar. - self._setUpToolbarFeedbackButton(); } + // Don't show first run page in ffx4 beta version. } // Install tasks. (This requires knowing the version, so it is diff --git a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js index 3599154e924..021aa923508 100644 --- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js +++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js @@ -209,6 +209,9 @@ var TestPilotTask = { }, changeStatus: function TPS_changeStatus(newStatus, suppressNotification) { + // TODO we always suppress notifications except when new status is + // "finished"; maybe remove that argument and only fire notification + // when status is "finished". let logger = Log4Moz.repository.getLogger("TestPilot.Task"); logger.info("Changing task " + this._id + " status to " + newStatus); this._status = newStatus; @@ -584,7 +587,7 @@ TestPilotExperiment.prototype = { this._reschedule(); } else { // Normal case is reset to new. - this.changeStatus(TaskConstants.STATUS_NEW); + this.changeStatus(TaskConstants.STATUS_NEW, true); // increment count of how many times this recurring test has run let numTimesRun = this._numTimesRun; @@ -610,7 +613,7 @@ TestPilotExperiment.prototype = { } // clear the data before starting. this._dataStore.wipeAllData(); - this.changeStatus(TaskConstants.STATUS_STARTING); + this.changeStatus(TaskConstants.STATUS_STARTING, true); Application.prefs.setValue(GUID_PREF_PREFIX + this._id, uuid); this.onExperimentStartup(); } diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 705a24ac15f..3bff65ab6e7 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -1162,7 +1162,7 @@ let BookmarksMenuButton = { this._popupNeedsUpdating = true; let bookmarksToolbarItem = this.bookmarksToolbarItem; - if (isElementVisible(bookmarksToolbarItem)) { + if (bookmarksToolbarItem && !bookmarksToolbarItem.parentNode.collapsed) { if (this.button.parentNode != bookmarksToolbarItem) { this.resetView(); bookmarksToolbarItem.appendChild(this.button); diff --git a/browser/base/content/browser.css b/browser/base/content/browser.css index 36d849fd5c7..a03d1eb0397 100644 --- a/browser/base/content/browser.css +++ b/browser/base/content/browser.css @@ -201,7 +201,8 @@ toolbarbutton.bookmark-item { %ifdef MENUBAR_CAN_AUTOHIDE #toolbar-menubar:not([autohide="true"]) ~ #nav-bar > #bookmarks-menu-button-container, -#toolbar-menubar:not([autohide="true"]) ~ toolbar > #personal-bookmarks > #bookmarks-menu-button { +#toolbar-menubar:not([autohide="true"]) ~ toolbar > #personal-bookmarks > #bookmarks-menu-button, +#toolbar-menubar:not([autohide="true"]) > #personal-bookmarks > #bookmarks-menu-button { display: none; } %endif @@ -253,8 +254,11 @@ window[chromehidden~="toolbar"] toolbar:not(.toolbar-primary):not(.chromeclass-m /* Full Screen UI */ #fullscr-toggler { display: none; - min-height: 5px; - height: 5px; + min-height: 1px; + height: 1px; + background: black; + border-style: none; + -moz-appearance: none; } #navigator-toolbox[inFullscreen="true"] > #fullscr-toggler, diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index e19d213ce95..cfcf0d80ed0 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -4108,7 +4108,11 @@ var XULBrowserWindow = { let nBox = gBrowser.getNotificationBox(selectedBrowser); nBox.removeTransientNotifications(); - PopupNotifications.locationChange(); + // Only need to call locationChange if the PopupNotifications object + // for this window has already been initialized (i.e. its getter no + // longer exists) + if (!__lookupGetter__("PopupNotifications")) + PopupNotifications.locationChange(); } } @@ -4634,10 +4638,6 @@ var TabsOnTop = { gNavToolbox.setAttribute("tabsontop", !!val); this.syncCommand(); - //XXX: Trigger reframe. This is a workaround for bug 555987 and needs to be - // removed once that bug is fixed. - gNavToolbox.style.MozBoxOrdinalGroup = val ? 2 : 3; - return val; } } diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index a7e9829246c..4be9738dfa8 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -391,12 +391,10 @@ @@ -421,7 +418,6 @@ @@ -794,7 +787,7 @@ ._placesView._onChevronPopupShowing(event);"> diff --git a/browser/base/content/test/browser_drag.js b/browser/base/content/test/browser_drag.js index 2f52c3581d4..9e44b45bf1c 100644 --- a/browser/base/content/test/browser_drag.js +++ b/browser/base/content/test/browser_drag.js @@ -37,5 +37,5 @@ function test() finish(); }, true); - EventUtils.synthesizeDrop(tab, [[{type: "text/uri-list", data: "http://mochi.test:8888/"}]], "copy", window); + EventUtils.synthesizeDrop(tab, tab, [[{type: "text/uri-list", data: "http://mochi.test:8888/"}]], "copy", window); } diff --git a/browser/components/preferences/applications.js b/browser/components/preferences/applications.js index 1c3bb506793..5e05e0e41f8 100644 --- a/browser/components/preferences/applications.js +++ b/browser/components/preferences/applications.js @@ -438,6 +438,11 @@ HandlerInfoWrapper.prototype = { this._prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES, disabledPluginTypes.join(",")); + + // Update the category manager so existing browser windows update. + this._categoryMgr.deleteCategoryEntry("Gecko-Content-Viewers", + this.type, + false); }, enablePluginType: function() { @@ -448,6 +453,14 @@ HandlerInfoWrapper.prototype = { this._prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES, disabledPluginTypes.join(",")); + + // Update the category manager so existing browser windows update. + this._categoryMgr. + addCategoryEntry("Gecko-Content-Viewers", + this.type, + "@mozilla.org/content/plugin/document-loader-factory;1", + false, + true); }, diff --git a/browser/components/search/test/browser_426329.js b/browser/components/search/test/browser_426329.js index 40b79a7d07e..09dae5f8146 100644 --- a/browser/components/search/test/browser_426329.js +++ b/browser/components/search/test/browser_426329.js @@ -137,7 +137,7 @@ function test() { searchBar.addEventListener("popupshowing", stopPopup, true); // drop on the search button so that we don't need to worry about the // default handlers for textboxes. - EventUtils.synthesizeDrop(searchBar.searchButton, [[ {type: "text/plain", data: "Some Text" } ]], "copy", window); + EventUtils.synthesizeDrop(searchBar.searchButton, searchBar.searchButton, [[ {type: "text/plain", data: "Some Text" } ]], "copy", window); doOnloadOnce(function(event) { is(searchBar.value, "Some Text", "drop text/plain on searchbar"); testDropInternalText(); @@ -146,7 +146,7 @@ function test() { function testDropInternalText() { init(); - EventUtils.synthesizeDrop(searchBar.searchButton, [[ {type: "text/x-moz-text-internal", data: "More Text" } ]], "copy", window); + EventUtils.synthesizeDrop(searchBar.searchButton, searchBar.searchButton, [[ {type: "text/x-moz-text-internal", data: "More Text" } ]], "copy", window); doOnloadOnce(function(event) { is(searchBar.value, "More Text", "drop text/x-moz-text-internal on searchbar"); testDropLink(); @@ -155,7 +155,7 @@ function test() { function testDropLink() { init(); - EventUtils.synthesizeDrop(searchBar.searchButton, [[ {type: "text/uri-list", data: "http://www.mozilla.org" } ]], "copy", window); + EventUtils.synthesizeDrop(searchBar.searchButton, searchBar.searchButton, [[ {type: "text/uri-list", data: "http://www.mozilla.org" } ]], "copy", window); is(searchBar.value, "More Text", "drop text/uri-list on searchbar"); SimpleTest.executeSoon(testRightClick); } diff --git a/browser/config/version.txt b/browser/config/version.txt index 2d2021b0059..b074f2c69e9 100644 --- a/browser/config/version.txt +++ b/browser/config/version.txt @@ -1 +1 @@ -3.7a6pre +4.0b2pre diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 4e42e8f4015..afc35249c34 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -404,7 +404,122 @@ @BINPATH@/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}/icon.png @BINPATH@/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}/preview.png #if MOZ_UPDATE_CHANNEL == beta -@BINPATH@/extensions/testpilot@labs.mozilla.com/* +@BINPATH@/extensions/testpilot@labs.mozilla.com/chrome.manifest +@BINPATH@/extensions/testpilot@labs.mozilla.com/components/TestPilot.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/all-studies-window.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/all-studies-window.xul +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/browser.css +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/browser.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/debug.html +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/experiment-page.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/feedback-browser.xul +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.colorhelpers.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.colorhelpers.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.crosshair.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.crosshair.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.image.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.image.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.navigate.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.navigate.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.selection.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.selection.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.stack.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.stack.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.threshold.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.flot.threshold.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/flot/jquery.min.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/raw-data-dialog.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/raw-data-dialog.xul +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/screen.css +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/status-quit.html +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/status.html +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/survey-generator.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/take-survey.html +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/tp-browser.xul +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/welcome-page.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/welcome.html +@BINPATH@/extensions/testpilot@labs.mozilla.com/content/window-utils.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/defaults/preferences/preferences.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/install.rdf +@BINPATH@/extensions/testpilot@labs.mozilla.com/instrument/chrome.manifest +@BINPATH@/extensions/testpilot@labs.mozilla.com/instrument/install.rdf +@BINPATH@/extensions/testpilot@labs.mozilla.com/instrument/instrument.jsm +@BINPATH@/extensions/testpilot@labs.mozilla.com/instrument/instrument.xul +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/dbutils.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/experiment_data_store.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/extension-update.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/feedback.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/jar-code-store.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/cuddlefish.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/memory.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/observer-service.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/plain-text-console.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/preferences-service.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/securable-module.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/timer.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/traceback.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/unit-test.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/unload.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/lib/url.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/log4moz.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/metadata.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/Observers.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/setup.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/string_sanitizer.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/modules/tasks.js +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/badge-default.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/bg.jpg +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/css/screen-standalone.css +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/dino_32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/bg-status.jpg +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/callout.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/callout_continue.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/data1.jpg +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/data2.jpg +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_comments.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_computer.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_continue.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_quit.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_results.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_twitter.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/images/home_upcoming.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/logo.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/mozilla-logo.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/status-completed.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/status-ejected.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/status-missed.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/testpilot_16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/testPilot_200x200.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/testpilot_32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-completedstudies-32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-currentstudies-32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-generic-32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-learned-32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-results-48x48.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-settings-32x32.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-study-48x48.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/all/tp-submit-48x48.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/linux/close_button.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/linux/feedback-frown-16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/linux/feedback-smile-16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/linux/feedback.css +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/mac/close_button.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/mac/feedback-frown-16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/mac/feedback-smile-16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/mac/feedback.css +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/mac/notification-tail-down.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/mac/notification-tail-up.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/win/close_button.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/win/feedback-frown-16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/win/feedback-smile-16x16.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/win/feedback.css +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/win/notification-tail-down.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/skin/win/notification-tail-up.png +@BINPATH@/extensions/testpilot@labs.mozilla.com/tests/test_data_store.js #endif @BINPATH@/chrome/toolkit.jar @BINPATH@/chrome/toolkit.manifest diff --git a/browser/installer/removed-files.in b/browser/installer/removed-files.in index a51c196f654..fc7608f6fbb 100644 --- a/browser/installer/removed-files.in +++ b/browser/installer/removed-files.in @@ -48,6 +48,7 @@ components/history.xpt components/microsummaries.xpt components/myspell/en-US.aff components/myspell/en-US.dic +components/nsAddonRepository.js components/nsBackgroundUpdateService.js components/nsBookmarkTransactionManager.js components/nsCloseAllWindows.js diff --git a/browser/themes/gnomestripe/browser/browser.css b/browser/themes/gnomestripe/browser/browser.css index c7fa7c4e0d0..ad4a20b9513 100644 --- a/browser/themes/gnomestripe/browser/browser.css +++ b/browser/themes/gnomestripe/browser/browser.css @@ -580,7 +580,7 @@ toolbar[mode="full"] .toolbarbutton-menubutton-button { list-style-image: url("chrome://browser/skin/Toolbar-small.png"); } -toolbar[mode="icons"] #bookmarks-menu-button.toolbarbutton-1 { +#bookmarks-menu-button.toolbarbutton-1 { -moz-box-orient: horizontal; } diff --git a/browser/themes/pinstripe/browser/browser.css b/browser/themes/pinstripe/browser/browser.css index 492892cccd4..0cba7b9c83b 100644 --- a/browser/themes/pinstripe/browser/browser.css +++ b/browser/themes/pinstripe/browser/browser.css @@ -328,14 +328,8 @@ toolbar[mode="icons"] toolbarbutton[type="menu-button"] > .toolbarbutton-menubut #restore-button > .toolbarbutton-icon, toolbarbutton[type="menu-button"] > .toolbarbutton-menubutton-button > .toolbarbutton-icon { padding: 0; - max-height: 20px; -} - -/* Only set the max-width in icon-only mode because it affects the label, too */ -toolbar[mode="icons"] .toolbarbutton-1 > .toolbarbutton-icon, -toolbar[mode="icons"] #restore-button > .toolbarbutton-icon, -toolbar[mode="icons"] toolbarbutton[type="menu-button"] > .toolbarbutton-menubutton-button > .toolbarbutton-icon { - max-width: 20px; + height: 20px; + width: 20px; } .toolbarbutton-1[disabled="true"] > .toolbarbutton-icon, @@ -578,7 +572,7 @@ toolbar[iconsize="small"][mode="icons"] #forward-button:-moz-locale-dir(rtl) { list-style-image: url("chrome://browser/skin/Toolbar.png"); } -toolbar[mode="icons"] #bookmarks-menu-button.toolbarbutton-1 { +#bookmarks-menu-button.toolbarbutton-1 { -moz-box-orient: horizontal; } diff --git a/browser/themes/winstripe/browser/browser-aero.css b/browser/themes/winstripe/browser/browser-aero.css index b405090541d..73ca2abbc50 100644 --- a/browser/themes/winstripe/browser/browser-aero.css +++ b/browser/themes/winstripe/browser/browser-aero.css @@ -24,6 +24,11 @@ background: transparent; } + /* the new titlebar requires this, or content will be clipped at the top of the screen. */ + #main-window[sizemode="maximized"][chromemargin^="0,"] { + margin-top: 8px; + } + #main-window:not(:-moz-lwtheme)[inFullscreen="true"] { -moz-appearance: none; background-color: #556; diff --git a/browser/themes/winstripe/browser/browser.css b/browser/themes/winstripe/browser/browser.css index 334e92ca664..9c2c396efb0 100644 --- a/browser/themes/winstripe/browser/browser.css +++ b/browser/themes/winstripe/browser/browser.css @@ -163,6 +163,12 @@ statusbarpanel#statusbar-display { -moz-padding-end: 16px; } +.split-menuitem-item[_moz-menuactive="true"], +.split-menuitem-menu[_moz-menuactive="true"] { + background-color: -moz-menuhover; + color: -moz-menuhovertext; +} + /* XXX: stop-gap until the button can be drawn in the title bar */ %ifdef WINSTRIPE_AERO @media not all and (-moz-windows-compositor) { @@ -370,7 +376,7 @@ toolbar[iconsize="small"][mode="icons"] toolbarbutton[type="menu-button"] { .toolbarbutton-menubutton-button:not([disabled="true"]):not(:active):hover, toolbarbutton[type="menu-button"]:not([open="true"]):not(:active):hover > .toolbarbutton-menubutton-dropmarker:not([disabled="true"]), -.toolbarbutton-1:not([disabled="true"]):not([checked="true"]):not(:active):hover { +.toolbarbutton-1:not([disabled="true"]):not([checked="true"]):not([open="true"]):not(:active):hover { background-color: hsla(190,60%,70%,.5); border-color: hsla(190,50%,65%,.8) hsla(190,50%,50%,.8) hsla(190,50%,40%,.8); -moz-box-shadow: 0 0 0 1px rgba(255,255,255,.3) inset, @@ -605,7 +611,7 @@ toolbar:not([iconsize="small"])[mode="icons"] #forward-button:not([disabled="tru list-style-image: url("chrome://browser/skin/Toolbar.png"); } -toolbar[mode="icons"] #bookmarks-menu-button.toolbarbutton-1 { +#bookmarks-menu-button.toolbarbutton-1 { -moz-box-orient: horizontal; } diff --git a/build/Makefile.in b/build/Makefile.in index 3223c6aea92..e3b9995e49f 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -111,6 +111,9 @@ libs:: bloaturls.txt libs:: bloatcycle.html $(INSTALL) $< $(DIST)/bin/res +libs:: $(topsrcdir)/tools/rb/fix_stack_using_bpsyms.py + $(INSTALL) $< $(DIST)/bin + ifeq ($(OS_ARCH),Darwin) libs:: $(topsrcdir)/tools/rb/fix-macosx-stack.pl $(INSTALL) $< $(DIST)/bin diff --git a/build/automation.py.in b/build/automation.py.in index fa601460bf8..32d4f39bef9 100644 --- a/build/automation.py.in +++ b/build/automation.py.in @@ -583,7 +583,7 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t if not pHandle: return False pExitCode = ctypes.wintypes.DWORD() - ctypes.windll.kernel32.GetExitCodeProcess(pHandle, self.ctypes.byref(pExitCode)) + ctypes.windll.kernel32.GetExitCodeProcess(pHandle, ctypes.byref(pExitCode)) ctypes.windll.kernel32.CloseHandle(pHandle) if (pExitCode.value == STILL_ACTIVE): return True @@ -649,35 +649,44 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t self.log.info("Can't trigger Breakpad, just killing process") proc.kill() - def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo): + def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsPath): """ Look for timeout or crashes and return the status after the process terminates """ stackFixerProcess = None - stackFixerModule = None + stackFixerFunction = None didTimeout = False if proc.stdout is None: self.log.info("TEST-INFO: Not logging stdout or stderr due to debugger connection") else: logsource = proc.stdout - if self.IS_DEBUG_BUILD and self.IS_LINUX: - # Run logsource through fix-linux-stack.pl + + if self.IS_DEBUG_BUILD and (self.IS_MAC or self.IS_LINUX) and symbolsPath and os.path.exists(symbolsPath): + # Run each line through a function in fix_stack_using_bpsyms.py (uses breakpad symbol files) + # This method is preferred for Tinderbox builds, since native symbols may have been stripped. + sys.path.insert(0, utilityPath) + import fix_stack_using_bpsyms as stackFixerModule + stackFixerFunction = lambda line: stackFixerModule.fixSymbols(line, symbolsPath) + del sys.path[0] + elif self.IS_DEBUG_BUILD and self.IS_MAC and False: + # Run each line through a function in fix_macosx_stack.py (uses atos) + sys.path.insert(0, utilityPath) + import fix_macosx_stack as stackFixerModule + stackFixerFunction = lambda line: stackFixerModule.fixSymbols(line) + del sys.path[0] + elif self.IS_DEBUG_BUILD and self.IS_LINUX: + # Run logsource through fix-linux-stack.pl (uses addr2line) + # This method is preferred for developer machines, so we don't have to run "make buildsymbols". stackFixerProcess = self.Process([self.PERL, os.path.join(utilityPath, "fix-linux-stack.pl")], stdin=logsource, stdout=subprocess.PIPE) logsource = stackFixerProcess.stdout - if self.IS_DEBUG_BUILD and self.IS_MAC and False: - # Import fix_macosx_stack.py from utilityPath - sys.path.insert(0, utilityPath) - import fix_macosx_stack as stackFixerModule - del sys.path[0] - (line, didTimeout) = self.readWithTimeout(logsource, timeout) hitMaxTime = False while line != "" and not didTimeout: if "TEST-START" in line and "|" in line: self.lastTestSeen = line.split("|")[1].strip() - if stackFixerModule: - line = stackFixerModule.fixSymbols(line) + if stackFixerFunction: + line = stackFixerFunction(line) self.log.info(line.rstrip()) (line, didTimeout) = self.readWithTimeout(logsource, timeout) if not hitMaxTime and maxTime and datetime.now() - startTime > timedelta(seconds = maxTime): @@ -814,7 +823,7 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t stderr = subprocess.STDOUT) self.log.info("INFO | automation.py | Application pid: %d", proc.pid) - status = self.waitForFinish(proc, utilityPath, timeout, maxTime, startTime, debuggerInfo) + status = self.waitForFinish(proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsPath) self.log.info("INFO | automation.py | Application ran for: %s", str(datetime.now() - startTime)) # Do a final check for zombie child processes. diff --git a/build/mobile/remoteautomation.py b/build/mobile/remoteautomation.py index bbb1612c219..f5503ebb9ff 100644 --- a/build/mobile/remoteautomation.py +++ b/build/mobile/remoteautomation.py @@ -66,7 +66,7 @@ class RemoteAutomation(Automation): def setProduct(self, product): self._product = product - def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo): + def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsDir): # maxTime is used to override the default timeout, we should honor that status = proc.wait(timeout = maxTime) diff --git a/build/wince/shunt/environment.cpp b/build/wince/shunt/environment.cpp index 6eaa8fcdd5f..31f0e3d3cdd 100644 --- a/build/wince/shunt/environment.cpp +++ b/build/wince/shunt/environment.cpp @@ -159,8 +159,8 @@ getenv(const char* name) } char -GetEnvironmentVariableW(const unsigned short* lpName, - unsigned short* lpBuffer, +GetEnvironmentVariableW(const WCHAR* lpName, + WCHAR* lpBuffer, unsigned long nSize) { char key[256]; @@ -180,8 +180,8 @@ GetEnvironmentVariableW(const unsigned short* lpName, } char -SetEnvironmentVariableW(const unsigned short* name, - const unsigned short* value) +SetEnvironmentVariableW(const WCHAR* name, + const WCHAR* value) { char key[256]; char val[256]; @@ -204,8 +204,8 @@ SetEnvironmentVariableW(const unsigned short* name, } -unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc, - unsigned short* lpDst, +unsigned int ExpandEnvironmentStringsW(const WCHAR* lpSrc, + WCHAR* lpDst, unsigned int nSize) { if ( NULL == lpDst ) @@ -215,8 +215,8 @@ unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc, unsigned int index = 0; unsigned int origLen = wcslen(lpSrc); - const unsigned short *pIn = lpSrc; - unsigned short *pOut = lpDst; + const WCHAR *pIn = lpSrc; + WCHAR *pOut = lpDst; while ( index < origLen ) { @@ -228,7 +228,7 @@ unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc, // Have a starting '%' - look for matching '%' int envlen = 0; - const unsigned short *pTmp = pIn + 1; + const WCHAR *pTmp = pIn + 1; while ( *pTmp != L'%' && *pTmp != L' ' ) { envlen++, pTmp++; if ( origLen < index + envlen ) { // Ran past end of original @@ -274,7 +274,7 @@ unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc, return size; } -unsigned short * +WCHAR * mozce_GetEnvironmentCL() { env_entry *entry = env_head; diff --git a/build/wince/shunt/include/environment.h b/build/wince/shunt/include/environment.h index 825c03ffc18..f22aff3f308 100644 --- a/build/wince/shunt/include/environment.h +++ b/build/wince/shunt/include/environment.h @@ -47,14 +47,14 @@ extern "C" { /* Environment stuff */ char* getenv(const char* inName); int putenv(const char *a); -char SetEnvironmentVariableW(const unsigned short * name, const unsigned short * value ); -char GetEnvironmentVariableW(const unsigned short * lpName, unsigned short* lpBuffer, unsigned long nSize); +char SetEnvironmentVariableW(const wchar_t * name, const wchar_t * value ); +char GetEnvironmentVariableW(const wchar_t * lpName, wchar_t* lpBuffer, unsigned long nSize); -unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc, - unsigned short* lpDst, +unsigned int ExpandEnvironmentStringsW(const wchar_t* lpSrc, + wchar_t* lpDst, unsigned int nSize); -unsigned short* mozce_GetEnvironmentCL(); +wchar_t* mozce_GetEnvironmentCL(); #ifdef __cplusplus }; diff --git a/build/wince/shunt/include/mozce_shunt.h b/build/wince/shunt/include/mozce_shunt.h index 84d5ea48296..155adb1b978 100644 --- a/build/wince/shunt/include/mozce_shunt.h +++ b/build/wince/shunt/include/mozce_shunt.h @@ -38,8 +38,6 @@ #ifndef MOZCE_SHUNT_H #define MOZCE_SHUNT_H -#include "environment.h" - #ifdef __cplusplus extern "C" { #endif @@ -53,6 +51,8 @@ typedef unsigned short wchar_t; } //extern "C" #endif +#include "environment.h" + #ifdef MOZ_MEMORY #ifdef __cplusplus @@ -182,18 +182,18 @@ void abort(void); /* Environment stuff */ char* getenv(const char* inName); int putenv(const char *a); -char SetEnvironmentVariableW(const unsigned short * name, const unsigned short * value ); -char GetEnvironmentVariableW(const unsigned short * lpName, unsigned short* lpBuffer, unsigned long nSize); +char SetEnvironmentVariableW(const wchar_t * name, const wchar_t * value ); +char GetEnvironmentVariableW(const wchar_t * lpName, wchar_t* lpBuffer, unsigned long nSize); -unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc, - unsigned short* lpDst, +unsigned int ExpandEnvironmentStringsW(const wchar_t* lpSrc, + wchar_t* lpDst, unsigned int nSize); /* File system stuff */ -unsigned short * _wgetcwd(unsigned short* dir, unsigned long size); -unsigned short *_wfullpath( unsigned short *absPath, const unsigned short *relPath, unsigned long maxLength ); +wchar_t * _wgetcwd(wchar_t* dir, unsigned long size); +wchar_t *_wfullpath(wchar_t *absPath, const wchar_t *relPath, unsigned long maxLength ); int _unlink(const char *filename ); -int _wchdir(const unsigned short* path); +int _wchdir(const wchar_t* path); /* The time stuff should be defined here, but it can't be because it is already defined in time.h. @@ -228,7 +228,7 @@ struct tm* localtime_r(const time_t* inTimeT, struct tm* outRetval); */ -unsigned short* mozce_GetEnvironmentCL(); +wchar_t* mozce_GetEnvironmentCL(); /* square root of 1/2, missing from math.h */ #define M_SQRT1_2 0.707106781186547524401 diff --git a/build/wince/shunt/shunt.cpp b/build/wince/shunt/shunt.cpp index b3dd0c0e3e7..99d9d92eb13 100644 --- a/build/wince/shunt/shunt.cpp +++ b/build/wince/shunt/shunt.cpp @@ -113,15 +113,15 @@ int errno = 0; // File System Stuff //////////////////////////////////////////////////////// -unsigned short * _wgetcwd(unsigned short * dir, unsigned long size) +wchar_t * _wgetcwd(wchar_t * dir, unsigned long size) { - unsigned short tmp[MAX_PATH] = {0}; + wchar_t tmp[MAX_PATH] = {0}; GetEnvironmentVariableW(L"CWD", tmp, size); if (tmp && tmp[0]) { if (wcslen(tmp) > size) return 0; if (!dir) { - dir = (unsigned short*)malloc(sizeof(unsigned short) * (wcslen(tmp) + 2)); + dir = (wchar_t*)malloc(sizeof(wchar_t) * (wcslen(tmp) + 2)); if (!dir) return 0; } @@ -129,7 +129,7 @@ unsigned short * _wgetcwd(unsigned short * dir, unsigned long size) } else { unsigned long i; if (!dir) { - dir = (unsigned short*)malloc(sizeof(unsigned short) * (MAX_PATH + 1)); + dir = (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH + 1)); if (!dir) return 0; } @@ -147,12 +147,12 @@ unsigned short * _wgetcwd(unsigned short * dir, unsigned long size) return dir; } -unsigned short *_wfullpath( unsigned short *absPath, const unsigned short *relPath, unsigned long maxLength ) +wchar_t *_wfullpath( wchar_t *absPath, const wchar_t *relPath, unsigned long maxLength ) { if(absPath == NULL){ - absPath = (unsigned short *)malloc(maxLength*sizeof(unsigned short)); + absPath = (wchar_t *)malloc(maxLength*sizeof(wchar_t)); } - unsigned short cwd[MAX_PATH]; + wchar_t cwd[MAX_PATH]; if (NULL == _wgetcwd( cwd, MAX_PATH)) return NULL; @@ -181,7 +181,7 @@ int _wchdir(const WCHAR* path) { int _unlink(const char *filename) { - unsigned short wname[MAX_PATH]; + wchar_t wname[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 9ecc293a211..e5d0e7388c4 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -1778,30 +1778,10 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx, docshell = window->GetDocShell(); } - nsCOMPtr globalObjTreeItem = - do_QueryInterface(docshell); - - if (globalObjTreeItem) - { - nsCOMPtr treeItem(globalObjTreeItem); - nsCOMPtr parentItem; - - // Walk up the docshell tree to see if any containing docshell disallows scripts - do - { - rv = docshell->GetAllowJavascript(result); - if (NS_FAILED(rv)) return rv; - if (!*result) - return NS_OK; // Do not run scripts - treeItem->GetParent(getter_AddRefs(parentItem)); - treeItem.swap(parentItem); - docshell = do_QueryInterface(treeItem); -#ifdef DEBUG - if (treeItem && !docshell) { - NS_ERROR("cannot get a docshell from a treeItem!"); - } -#endif // DEBUG - } while (treeItem && docshell); + if (docshell) { + rv = docshell->GetCanExecuteScripts(result); + if (NS_FAILED(rv)) return rv; + if (!*result) return NS_OK; } // OK, the docshell doesn't have script execution explicitly disabled. diff --git a/client.mk b/client.mk index 20db4021cf8..bae7e80396e 100644 --- a/client.mk +++ b/client.mk @@ -84,9 +84,11 @@ endif ifndef TOPSRCDIR ifeq (,$(wildcard client.mk)) -$(error Must run from the client.mk directory, or specify TOPSRCDIR) +TOPSRCDIR := $(patsubst %/,%,$(dir $(MAKEFILE_LIST))) +MOZ_OBJDIR = . +else +TOPSRCDIR := $(CWD) endif -TOPSRCDIR = $(CWD) endif # try to find autoconf 2.13 - discard errors from 'which' diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index bc0b9154b2f..5dceb395bab 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -130,7 +130,6 @@ MOZ_JSLOADER = @MOZ_JSLOADER@ MOZ_USE_NATIVE_UCONV = @MOZ_USE_NATIVE_UCONV@ MOZ_BRANDING_DIRECTORY = @MOZ_BRANDING_DIRECTORY@ XPCOM_USE_LEA = @XPCOM_USE_LEA@ -MOZ_ENABLE_POSTSCRIPT = @MOZ_ENABLE_POSTSCRIPT@ MOZ_INSTALLER = @MOZ_INSTALLER@ MOZ_UPDATER = @MOZ_UPDATER@ MOZ_UPDATE_CHANNEL = @MOZ_UPDATE_CHANNEL@ diff --git a/config/config.mk b/config/config.mk index 3d5b58ff1cb..b980d8cf545 100644 --- a/config/config.mk +++ b/config/config.mk @@ -507,6 +507,13 @@ FAIL_ON_WARNINGS_DEBUG= FAIL_ON_WARNINGS= endif # WINNT && (MOS_PROFILE_GENERATE ^ MOZ_PROFILE_USE) +# Also clear FAIL_ON_WARNINGS[_DEBUG] for Android builds, since +# they have some platform-specific warnings we haven't fixed yet. +ifeq ($(OS_TARGET),Android) +FAIL_ON_WARNINGS_DEBUG= +FAIL_ON_WARNINGS= +endif # Android + # Now, check for debug version of flag; it turns on normal flag in debug builds. ifdef FAIL_ON_WARNINGS_DEBUG ifdef MOZ_DEBUG diff --git a/config/milestone.txt b/config/milestone.txt index 4f19240a7a8..c3ef4428bf3 100644 --- a/config/milestone.txt +++ b/config/milestone.txt @@ -10,4 +10,4 @@ # hardcoded milestones in the tree from these two files. #-------------------------------------------------------- -1.9.3a6pre +2.0b2pre diff --git a/config/rules.mk b/config/rules.mk index d2ac26303ec..d0d2239b18e 100644 --- a/config/rules.mk +++ b/config/rules.mk @@ -355,7 +355,6 @@ endif # ENABLE_CXX_EXCEPTIONS endif # WINNT ifeq ($(SOLARIS_SUNPRO_CXX),1) -CXXFLAGS += -features=extensions -D__FUNCTION__=__func__ ifeq (86,$(findstring 86,$(OS_TEST))) OS_LDFLAGS += -M $(topsrcdir)/config/solaris_ia32.map endif # x86 @@ -1357,7 +1356,7 @@ _MDDEPFILE = $(MDDEPDIR)/$(@F).pp define MAKE_DEPS_AUTO if test -d $(@D); then \ echo "Building deps for $<"; \ - $(MKDEPEND) -o'.$(OBJ_SUFFIX)' -f- $(DEFINES) $(ACDEFINES) $(INCLUDES) $< 2>/dev/null | sed -e "s|^[^ ]*/||" > $(_MDDEPFILE) ; \ + $(MKDEPEND) -o'.$(OBJ_SUFFIX)' -f- $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) $(INCLUDES) $< 2>/dev/null | sed -e "s|^[^ ]*/||" > $(_MDDEPFILE) ; \ fi endef diff --git a/configure.in b/configure.in index d437a161e9a..73f8a6e7465 100644 --- a/configure.in +++ b/configure.in @@ -666,14 +666,12 @@ case "$target" in elif test "$_CC_MAJOR_VERSION" = "15"; then _CC_SUITE=9 CXXFLAGS="$CXXFLAGS -Zc:wchar_t-" - LDFLAGS="$LDFLAGS -MANIFESTUAC:NO" _USE_DYNAMICBASE=1 AC_DEFINE(_CRT_SECURE_NO_WARNINGS) AC_DEFINE(_CRT_NONSTDC_NO_WARNINGS) elif test "$_CC_MAJOR_VERSION" = "16"; then _CC_SUITE=10 CXXFLAGS="$CXXFLAGS -Zc:wchar_t-" - LDFLAGS="$LDFLAGS -MANIFESTUAC:NO" _USE_DYNAMICBASE=1 AC_DEFINE(_CRT_SECURE_NO_WARNINGS) AC_DEFINE(_CRT_NONSTDC_NO_WARNINGS) @@ -1234,8 +1232,6 @@ USE_DEPENDENT_LIBS=1 _PLATFORM_DEFAULT_TOOLKIT=cairo-gtk2 -MOZ_ENABLE_POSTSCRIPT=1 - if test -n "$CROSS_COMPILE"; then OS_TARGET="${target_os}" OS_ARCH=`echo $target_os | sed -e 's|/|_|g'` @@ -1604,15 +1600,6 @@ if test "$GNU_CC"; then _DEFINES_CFLAGS='-include $(DEPTH)/mozilla-config.h -DMOZILLA_CLIENT' _USE_CPP_INCLUDE_FLAG=1 elif test "$SOLARIS_SUNPRO_CC"; then - MKSHLIB='$(LD) $(DSO_LDOPTS) -h $@ -o $@' - MKCSHLIB='$(LD) $(DSO_LDOPTS) -h $@ -o $@' - - DSO_LDOPTS='-shared' - if test "$GNU_LD"; then - # Don't allow undefined symbols in libraries - DSO_LDOPTS="$DSO_LDOPTS -z defs" - fi - DSO_CFLAGS='' if test "$CPU_ARCH" = "sparc"; then # for Sun Studio on Solaris/SPARC @@ -2041,7 +2028,6 @@ case "$target" in DSO_LDOPTS='' STRIP="$STRIP -x -S" _PLATFORM_DEFAULT_TOOLKIT='cairo-cocoa' - MOZ_ENABLE_POSTSCRIPT= TARGET_NSPR_MDCPUCFG='\"md/_darwin.cfg\"' # The ExceptionHandling framework is needed for Objective-C exception # logging code in nsObjCExceptions.h. Currently we only use that in debug @@ -2308,7 +2294,6 @@ ia64*-hpux*) TARGET_MD_ARCH=win32 _PLATFORM_DEFAULT_TOOLKIT='cairo-windows' BIN_SUFFIX='.exe' - MOZ_ENABLE_POSTSCRIPT= MOZ_USER_DIR="Mozilla" MOZ_GFX_OPTIMIZE_MOBILE=1 @@ -2431,7 +2416,6 @@ ia64*-hpux*) TARGET_MD_ARCH=win32 _PLATFORM_DEFAULT_TOOLKIT='cairo-windows' BIN_SUFFIX='.exe' - MOZ_ENABLE_POSTSCRIPT= MOZ_USER_DIR="Mozilla" dnl Hardcode to win95 for now - cls @@ -2635,7 +2619,6 @@ ia64*-hpux*) LIBXUL_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xul.lib $(LIBXUL_DIST)/lib/mozalloc.lib' TARGET_MD_ARCH=os2 _PLATFORM_DEFAULT_TOOLKIT="cairo-os2" - MOZ_ENABLE_POSTSCRIPT= RC=rc.exe RCFLAGS='-n' MOZ_USER_DIR="Mozilla" @@ -2722,19 +2705,19 @@ alpha*-*-osf*) AC_DEFINE(SOLARIS) TARGET_NSPR_MDCPUCFG='\"md/_solaris.cfg\"' SYSTEM_MAKEDEPEND= + MOZ_FIX_LINK_PATHS= # $ORIGIN/.. is for shared libraries under components/ to locate shared # libraries one level up (e.g. libnspr4.so) - LDFLAGS="$LDFLAGS -z ignore -R '\$\$ORIGIN:\$\$ORIGIN/..'" if test "$SOLARIS_SUNPRO_CC"; then - LIBS="-lCrun -lCstd $LIBS" + LDFLAGS="$LDFLAGS -z ignore -R '\$\$ORIGIN:\$\$ORIGIN/..' -z lazyload -z combreloc -z muldefs" + LIBS="-lCrun -lCstd -lc $LIBS" NS_USE_NATIVE=1 - MOZ_FIX_LINK_PATHS= AC_DEFINE(NSCAP_DISABLE_DEBUG_PTR_TYPES) - CFLAGS="$CFLAGS -xlibmieee -xstrconst -xbuiltin=%all" - CXXFLAGS="$CXXFLAGS -xlibmieee -xbuiltin=%all -features=tmplife,tmplrefstatic -norunpath" + CFLAGS="$CFLAGS -xlibmieee -xstrconst -xbuiltin=%all -D__FUNCTION__=__func__" + CXXFLAGS="$CXXFLAGS -xlibmieee -xbuiltin=%all -features=tmplife,tmplrefstatic,extensions -norunpath -D__FUNCTION__=__func__" _MOZ_EXCEPTIONS_FLAGS_ON='-features=except' _MOZ_EXCEPTIONS_FLAGS_OFF='-features=no%except' - LDFLAGS="-xildoff -z lazyload -z combreloc $LDFLAGS" + LDFLAGS="-xildoff $LDFLAGS" if test -z "$CROSS_COMPILE" && test -f /usr/lib/ld/map.noexstk; then _SAVE_LDFLAGS=$LDFLAGS LDFLAGS="-M /usr/lib/ld/map.noexstk $LDFLAGS" @@ -2746,10 +2729,10 @@ alpha*-*-osf*) WARNINGS_AS_ERRORS='-Werror' MOZ_OPTIMIZE_FLAGS="-xO4" MKSHLIB='$(CXX) $(CXXFLAGS) $(DSO_PIC_FLAGS) $(DSO_LDOPTS) -h $@ -o $@' - MKCSHLIB='$(CC) $(CFLAGS) $(DSO_PIC_FLAGS) -G -z muldefs -h $@ -o $@' + MKCSHLIB='$(CC) $(CFLAGS) $(DSO_PIC_FLAGS) $(DSO_LDOPTS) -h $@ -o $@' MKSHLIB_FORCE_ALL='-z allextract' MKSHLIB_UNFORCE_ALL='-z defaultextract' - DSO_LDOPTS='-G -z muldefs' + DSO_LDOPTS='-G' AR_LIST="$AR t" AR_EXTRACT="$AR x" AR_DELETE="$AR d" @@ -2769,25 +2752,38 @@ alpha*-*-osf*) #error "Denied" #endif], _BAD_COMPILER=,_BAD_COMPILER=1) - if test -n "$_BAD_COMPILER"; then - _res="no" - AC_MSG_ERROR([Sun C++ 5.9 (Sun Studio 12) or higher is required to build. Your compiler version is $CXX_VERSION .]) - else - _res="yes" - fi - AC_MSG_RESULT([$_res]) - AC_LANG_RESTORE + if test -n "$_BAD_COMPILER"; then + _res="no" + AC_MSG_ERROR([Sun C++ 5.9 (Sun Studio 12) or higher is required to build. Your compiler version is $CXX_VERSION .]) + else + _res="yes" + fi + AC_TRY_COMPILE([], + [#if (__SUNPRO_CC >= 0x5100) + #error "Sun C++ 5.10 or above" + #endif], + _ABOVE_SS12U1=,_ABOVE_SS12U1=1) + if test "$_ABOVE_SS12U1"; then + # disable xannotate + CXXFLAGS="$CXXFLAGS -xannotate=no" + fi + AC_MSG_RESULT([$_res]) + AC_LANG_RESTORE else + LDFLAGS="$LDFLAGS -Wl,-z,ignore -Wl,-R,'\$\$ORIGIN:\$\$ORIGIN/..' -Wl,-z,lazyload -Wl,-z,combreloc -Wl,-z,muldefs" + LIBS="-lc $LIBS" + MKSHLIB_FORCE_ALL='-Wl,-z -Wl,allextract' + MKSHLIB_UNFORCE_ALL='-Wl,-z -Wl,defaultextract' ASFLAGS="$ASFLAGS -fPIC" - DSO_LDOPTS='-G' + DSO_LDOPTS='-shared' _WARNINGS_CFLAGS='' _WARNINGS_CXXFLAGS='' if test "$OS_RELEASE" = "5.3"; then - AC_DEFINE(MUST_UNDEF_HAVE_BOOLEAN_AFTER_INCLUDES) + AC_DEFINE(MUST_UNDEF_HAVE_BOOLEAN_AFTER_INCLUDES) fi fi if test "$OS_RELEASE" = "5.5.1"; then - AC_DEFINE(NEED_USLEEP_PROTOTYPE) + AC_DEFINE(NEED_USLEEP_PROTOTYPE) fi ;; @@ -5937,6 +5933,14 @@ if test -n "$MOZ_WEBM"; then VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC" VPX_X86_ASM=1 ;; + SunOS:i?86) + VPX_ASFLAGS="-f elf32 -rnasm -pnasm" + VPX_X86_ASM=1 + ;; + SunOS:x86_64) + VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC" + VPX_X86_ASM=1 + ;; Darwin:i?86) VPX_ASFLAGS="-f macho32 -rnasm -pnasm -DPIC" VPX_X86_ASM=1 @@ -8713,7 +8717,6 @@ AC_SUBST(MOZ_PROFILELOCKING) AC_SUBST(HAVE_XIE) AC_SUBST(MOZ_XIE_LIBS) -AC_SUBST(MOZ_ENABLE_POSTSCRIPT) AC_SUBST(BUILD_STATIC_LIBS) AC_SUBST(MOZ_ENABLE_LIBXUL) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index a60f69fa606..157e9892f96 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -63,6 +63,7 @@ #include "nsSMILAnimationController.h" #endif // MOZ_SMIL #include "nsIScriptGlobalObject.h" +#include "nsIDocumentEncoder.h" class nsIContent; class nsPresContext; @@ -116,10 +117,9 @@ class Element; } // namespace mozilla -// fbcd570b-dbfa-479b-9bd0-02312129c044 #define NS_IDOCUMENT_IID \ -{ 0xfbcd570b, 0xdbfa, 0x479b, \ - { 0x9b, 0xd0, 0x02, 0x31, 0x21, 0x29, 0xc0, 0x44 } } +{ 0x1d8bd3d4, 0x6f6d, 0x49fe, \ + { 0xaf, 0xda, 0xc9, 0x4a, 0xef, 0x8f, 0xcf, 0x1f } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -1115,6 +1115,16 @@ public: // Do nothing. } + already_AddRefed GetCachedEncoder() + { + return mCachedEncoder.forget(); + } + + void SetCachedEncoder(nsIDocumentEncoder* aEncoder) + { + mCachedEncoder = aEncoder; + } + // In case of failure, the document really can't initialize the frame loader. virtual nsresult InitializeFrameLoader(nsFrameLoader* aLoader) = 0; // In case of failure, the caller must handle the error, for example by @@ -1422,6 +1432,17 @@ protected: return GetRootElement(); } + void SetContentTypeInternal(const nsACString& aType) + { + mCachedEncoder = nsnull; + mContentType = aType; + } + + nsCString GetContentTypeInternal() const + { + return mContentType; + } + nsCOMPtr mDocumentURI; nsCOMPtr mDocumentBaseURI; @@ -1530,7 +1551,9 @@ protected: PRUint32 mBidiOptions; nsCString mContentLanguage; +private: nsCString mContentType; +protected: // The document's security info nsCOMPtr mSecurityInfo; @@ -1560,6 +1583,8 @@ protected: // Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow, // updated on every set of mSecriptGlobalObject. nsPIDOMWindow *mWindow; + + nsCOMPtr mCachedEncoder; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID) diff --git a/content/base/public/nsIDocumentEncoder.idl b/content/base/public/nsIDocumentEncoder.idl index d83a2eabec8..13cadc20e92 100644 --- a/content/base/public/nsIDocumentEncoder.idl +++ b/content/base/public/nsIDocumentEncoder.idl @@ -44,6 +44,13 @@ interface nsISelection; interface nsIDOMNode; interface nsIOutputStream; +%{ C++ +class nsINode; +class nsIDocument; +%} +[ptr] native nsINodePtr(nsINode); +[ptr] native nsIDocumentPtr(nsIDocument); + [scriptable, uuid(c0da5b87-0ba7-4d7c-8cb3-fcb02af4253d)] interface nsIDocumentEncoderNodeFixup : nsISupports { @@ -61,7 +68,7 @@ interface nsIDocumentEncoderNodeFixup : nsISupports nsIDOMNode fixupNode(in nsIDOMNode aNode, out boolean aSerializeCloneKids); }; -[scriptable, uuid(794a81f6-bde6-4f76-9f5e-0ea0911a2d9f)] +[scriptable, uuid(7222bdf1-c2b9-41f1-a40a-a3d65283a95b)] interface nsIDocumentEncoder : nsISupports { // Output methods flag bits. There are a frightening number of these, @@ -238,6 +245,9 @@ interface nsIDocumentEncoder : nsISupports void init(in nsIDOMDocument aDocument, in AString aMimeType, in unsigned long aFlags); + [noscript] void nativeInit(in nsIDocumentPtr aDocument, + in AString aMimeType, + in unsigned long aFlags); /** * If the selection is set to a non-null value, then the @@ -270,6 +280,7 @@ interface nsIDocumentEncoder : nsISupports * @param aContainer The node which child nodes will be encoded. */ void setContainerNode(in nsIDOMNode aContainer); + [noscript] void setNativeContainerNode(in nsINodePtr aContainer); /** * Documents typically have an intrinsic character set, diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 6a378028a0a..55af91c55e3 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -475,6 +475,7 @@ nsContentUtils::InitializeEventTable() { { nsGkAtoms::ondblclick, NS_MOUSE_DOUBLECLICK, EventNameType_HTMLXUL, NS_MOUSE_EVENT }, { nsGkAtoms::onmouseover, NS_MOUSE_ENTER_SYNTH, EventNameType_All, NS_MOUSE_EVENT }, { nsGkAtoms::onmouseout, NS_MOUSE_EXIT_SYNTH, EventNameType_All, NS_MOUSE_EVENT }, + { nsGkAtoms::onMozMouseHittest, NS_MOUSE_MOZHITTEST, EventNameType_None, NS_MOUSE_EVENT }, { nsGkAtoms::onmousemove, NS_MOUSE_MOVE, EventNameType_All, NS_MOUSE_EVENT }, { nsGkAtoms::oncontextmenu, NS_CONTEXTMENU, EventNameType_HTMLXUL, NS_MOUSE_EVENT }, @@ -496,6 +497,7 @@ nsContentUtils::InitializeEventTable() { { nsGkAtoms::onunload, NS_PAGE_UNLOAD, (EventNameType_HTMLXUL | EventNameType_SVGSVG), NS_EVENT }, { nsGkAtoms::onhashchange, NS_HASHCHANGE, EventNameType_HTMLXUL, NS_EVENT }, + { nsGkAtoms::onreadystatechange, NS_READYSTATECHANGE, EventNameType_HTMLXUL }, { nsGkAtoms::onbeforeunload, NS_BEFORE_PAGE_UNLOAD, EventNameType_HTMLXUL, NS_EVENT }, { nsGkAtoms::onabort, NS_IMAGE_ABORT, (EventNameType_HTMLXUL | EventNameType_SVGSVG), NS_EVENT }, @@ -6182,30 +6184,19 @@ nsIContentUtils::FindInternalContentViewer(const char* aType, if (!catMan) return NULL; - FullPagePluginEnabledType pluginEnabled = NOT_ENABLED; - - nsCOMPtr pluginHost = - do_GetService(MOZ_PLUGIN_HOST_CONTRACTID); - if (pluginHost) { - pluginHost->IsFullPagePluginEnabledForType(aType, &pluginEnabled); - } - nsCOMPtr docFactory; - if (OVERRIDE_BUILTIN == pluginEnabled) { - docFactory = do_GetService(PLUGIN_DLF_CONTRACTID); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_PLUGIN; - } - return docFactory.forget(); - } - nsXPIDLCString contractID; nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", aType, getter_Copies(contractID)); if (NS_SUCCEEDED(rv)) { docFactory = do_GetService(contractID); if (docFactory && aLoaderType) { - *aLoaderType = contractID.EqualsLiteral(CONTENT_DLF_CONTRACTID) ? TYPE_CONTENT : TYPE_UNKNOWN; + if (contractID.EqualsLiteral(CONTENT_DLF_CONTRACTID)) + *aLoaderType = TYPE_CONTENT; + else if (contractID.EqualsLiteral(PLUGIN_DLF_CONTRACTID)) + *aLoaderType = TYPE_PLUGIN; + else + *aLoaderType = TYPE_UNKNOWN; } return docFactory.forget(); } @@ -6242,13 +6233,5 @@ nsIContentUtils::FindInternalContentViewer(const char* aType, #endif #endif // MOZ_MEDIA - if (AVAILABLE == pluginEnabled) { - docFactory = do_GetService(PLUGIN_DLF_CONTRACTID); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_PLUGIN; - } - return docFactory.forget(); - } - return NULL; } diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index acc9ad06e27..08ff0e469b6 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -70,6 +70,7 @@ #include "nsCOMArray.h" #include "nsGUIEvent.h" +#include "nsPLDOMEvent.h" #include "nsIDOMStyleSheet.h" #include "nsDOMAttribute.h" @@ -1392,7 +1393,7 @@ nsDOMImplementation::Init(nsIURI* aDocumentURI, nsIURI* aBaseURI, nsDocument::nsDocument(const char* aContentType) : nsIDocument() { - mContentType = aContentType; + SetContentTypeInternal(nsDependentCString(aContentType)); #ifdef PR_LOGGING if (!gDocumentLeakPRLog) @@ -1687,6 +1688,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstBaseNodeWithHref) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDOMImplementation) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOriginalDocument) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCachedEncoder) // Traverse all our nsCOMArrays. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mStyleSheets) @@ -1730,6 +1732,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstBaseNodeWithHref) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDOMImplementation) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOriginalDocument) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCachedEncoder) NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA @@ -1946,7 +1949,7 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup, mLastModified.Truncate(); // XXXbz I guess we're assuming that the caller will either pass in // a channel with a useful type or call SetContentType? - mContentType.Truncate(); + SetContentTypeInternal(EmptyCString()); mContentLanguage.Truncate(); mBaseTarget.Truncate(); mReferrer.Truncate(); @@ -2154,7 +2157,7 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, contentType.EndReading(end); semicolon = start; FindCharInReadable(';', semicolon, end); - mContentType = Substring(start, semicolon); + SetContentTypeInternal(Substring(start, semicolon)); } RetrieveRelevantHeaders(aChannel); @@ -2435,7 +2438,7 @@ nsDocument::SetApplicationCache(nsIApplicationCache *aApplicationCache) NS_IMETHODIMP nsDocument::GetContentType(nsAString& aContentType) { - CopyUTF8toUTF16(mContentType, aContentType); + CopyUTF8toUTF16(GetContentTypeInternal(), aContentType); return NS_OK; } @@ -2443,11 +2446,11 @@ nsDocument::GetContentType(nsAString& aContentType) void nsDocument::SetContentType(const nsAString& aContentType) { - NS_ASSERTION(mContentType.IsEmpty() || - mContentType.Equals(NS_ConvertUTF16toUTF8(aContentType)), + NS_ASSERTION(GetContentTypeInternal().IsEmpty() || + GetContentTypeInternal().Equals(NS_ConvertUTF16toUTF8(aContentType)), "Do you really want to change the content-type?"); - CopyUTF16toUTF8(aContentType, mContentType); + SetContentTypeInternal(NS_ConvertUTF16toUTF8(aContentType)); } /* Return true if the document is in the focused top-level window, and is an @@ -7304,7 +7307,7 @@ nsDocument::CloneDocHelper(nsDocument* clone) const clone->mCompatMode = mCompatMode; clone->mBidiOptions = mBidiOptions; clone->mContentLanguage = mContentLanguage; - clone->mContentType = mContentType; + clone->SetContentTypeInternal(GetContentTypeInternal()); clone->mSecurityInfo = mSecurityInfo; // State from nsDocument @@ -7318,7 +7321,12 @@ void nsDocument::SetReadyStateInternal(ReadyState rs) { mReadyState = rs; - // TODO fire "readystatechange" + + nsRefPtr plevent = + new nsPLDOMEvent(this, NS_LITERAL_STRING("readystatechange"), PR_FALSE, PR_FALSE); + if (plevent) { + plevent->RunDOMEventWhenSafe(); + } } nsIDocument::ReadyState diff --git a/content/base/src/nsDocumentEncoder.cpp b/content/base/src/nsDocumentEncoder.cpp index f7be93c89d6..34c5e3c22d2 100644 --- a/content/base/src/nsDocumentEncoder.cpp +++ b/content/base/src/nsDocumentEncoder.cpp @@ -81,6 +81,7 @@ #include "nsReadableUtils.h" #include "nsTArray.h" #include "nsIFrame.h" +#include "nsStringBuffer.h" nsresult NS_NewDomSelection(nsISelection **aDomSelection); @@ -95,12 +96,12 @@ public: nsDocumentEncoder(); virtual ~nsDocumentEncoder(); - NS_DECL_ISUPPORTS - + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsDocumentEncoder) NS_DECL_NSIDOCUMENTENCODER protected: - void Initialize(); + void Initialize(PRBool aClearCachedSerializer = PR_TRUE); nsresult SerializeNodeStart(nsINode* aNode, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString& aStr, nsINode* aOriginalNode = nsnull); @@ -175,24 +176,43 @@ protected: PRPackedBool mHaltRangeHint; PRPackedBool mIsCopying; // Set to PR_TRUE only while copying PRPackedBool mNodeIsContainer; + nsStringBuffer* mCachedBuffer; }; -NS_IMPL_ADDREF(nsDocumentEncoder) -NS_IMPL_RELEASE(nsDocumentEncoder) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocumentEncoder) -NS_INTERFACE_MAP_BEGIN(nsDocumentEncoder) +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDocumentEncoder) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDocumentEncoder) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocumentEncoder) NS_INTERFACE_MAP_ENTRY(nsIDocumentEncoder) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -nsDocumentEncoder::nsDocumentEncoder() +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocumentEncoder) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSelection) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRange) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mNode) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCommonParent) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocumentEncoder) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSelection) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRange) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNode) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCommonParent) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +nsDocumentEncoder::nsDocumentEncoder() : mCachedBuffer(nsnull) { Initialize(); mMimeType.AssignLiteral("text/plain"); } -void nsDocumentEncoder::Initialize() +void nsDocumentEncoder::Initialize(PRBool aClearCachedSerializer) { mFlags = 0; mWrapColumn = 72; @@ -202,10 +222,16 @@ void nsDocumentEncoder::Initialize() mEndRootIndex = 0; mHaltRangeHint = PR_FALSE; mNodeIsContainer = PR_FALSE; + if (aClearCachedSerializer) { + mSerializer = nsnull; + } } nsDocumentEncoder::~nsDocumentEncoder() { + if (mCachedBuffer) { + mCachedBuffer->Release(); + } } NS_IMETHODIMP @@ -216,10 +242,23 @@ nsDocumentEncoder::Init(nsIDOMDocument* aDocument, if (!aDocument) return NS_ERROR_INVALID_ARG; - Initialize(); + nsCOMPtr doc = do_QueryInterface(aDocument); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); - mDocument = do_QueryInterface(aDocument); - NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); + return NativeInit(doc, aMimeType, aFlags); +} + +NS_IMETHODIMP +nsDocumentEncoder::NativeInit(nsIDocument* aDocument, + const nsAString& aMimeType, + PRUint32 aFlags) +{ + if (!aDocument) + return NS_ERROR_INVALID_ARG; + + Initialize(!mMimeType.Equals(aMimeType)); + + mDocument = aDocument; mMimeType = aMimeType; @@ -266,6 +305,14 @@ nsDocumentEncoder::SetContainerNode(nsIDOMNode *aContainer) return NS_OK; } +NS_IMETHODIMP +nsDocumentEncoder::SetNativeContainerNode(nsINode* aContainer) +{ + mNodeIsContainer = PR_TRUE; + mNode = aContainer; + return NS_OK; +} + NS_IMETHODIMP nsDocumentEncoder::SetCharset(const nsACString& aCharset) { @@ -928,11 +975,26 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString) aOutputString.Truncate(); - nsCAutoString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX); - AppendUTF16toUTF8(mMimeType, progId); + nsString output; + static const size_t bufferSize = 2048; + if (!mCachedBuffer) { + mCachedBuffer = nsStringBuffer::Alloc(bufferSize); + } + NS_ASSERTION(!mCachedBuffer->IsReadonly(), + "DocumentEncoder shouldn't keep reference to non-readonly buffer!"); + static_cast(mCachedBuffer->Data())[0] = PRUnichar(0); + mCachedBuffer->ToString(0, output, PR_TRUE); + // output owns the buffer now! + mCachedBuffer = nsnull; + - mSerializer = do_CreateInstance(progId.get()); - NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED); + if (!mSerializer) { + nsCAutoString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX); + AppendUTF16toUTF8(mMimeType, progId); + + mSerializer = do_CreateInstance(progId.get()); + NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED); + } nsresult rv = NS_OK; @@ -966,47 +1028,59 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString) if (node != prevNode) { if (prevNode) { nsCOMPtr p = do_QueryInterface(prevNode); - rv = SerializeNodeEnd(p, aOutputString); + rv = SerializeNodeEnd(p, output); NS_ENSURE_SUCCESS(rv, rv); prevNode = nsnull; } nsCOMPtr content = do_QueryInterface(node); if (content && content->Tag() == nsGkAtoms::tr) { nsCOMPtr n = do_QueryInterface(node); - rv = SerializeNodeStart(n, 0, -1, aOutputString); + rv = SerializeNodeStart(n, 0, -1, output); NS_ENSURE_SUCCESS(rv, rv); prevNode = node; } } nsCOMPtr r = do_QueryInterface(range); - rv = SerializeRangeToString(r, aOutputString); + rv = SerializeRangeToString(r, output); NS_ENSURE_SUCCESS(rv, rv); } if (prevNode) { nsCOMPtr p = do_QueryInterface(prevNode); - rv = SerializeNodeEnd(p, aOutputString); + rv = SerializeNodeEnd(p, output); NS_ENSURE_SUCCESS(rv, rv); } mSelection = nsnull; } else if (mRange) { - rv = SerializeRangeToString(mRange, aOutputString); + rv = SerializeRangeToString(mRange, output); mRange = nsnull; } else if (mNode) { - rv = SerializeToStringRecursive(mNode, aOutputString, mNodeIsContainer); + rv = SerializeToStringRecursive(mNode, output, mNodeIsContainer); mNode = nsnull; } else { - rv = mSerializer->AppendDocumentStart(mDocument, aOutputString); + rv = mSerializer->AppendDocumentStart(mDocument, output); if (NS_SUCCEEDED(rv)) { - rv = SerializeToStringRecursive(mDocument, aOutputString, PR_FALSE); + rv = SerializeToStringRecursive(mDocument, output, PR_FALSE); } } NS_ENSURE_SUCCESS(rv, rv); - rv = mSerializer->Flush(aOutputString); + rv = mSerializer->Flush(output); + + if (NS_SUCCEEDED(rv)) { + aOutputString.Append(output.get(), output.Length()); + } + mCachedBuffer = nsStringBuffer::FromString(output); + // Try to cache the buffer. + if (mCachedBuffer && mCachedBuffer->StorageSize() == bufferSize && + !mCachedBuffer->IsReadonly()) { + mCachedBuffer->AddRef(); + } else { + mCachedBuffer = nsnull; + } return rv; } diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index b13f0c74fee..2e2ec5c5a1e 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -663,6 +663,7 @@ GK_ATOM(onmousedown, "onmousedown") GK_ATOM(onmousemove, "onmousemove") GK_ATOM(onmouseout, "onmouseout") GK_ATOM(onmouseover, "onmouseover") +GK_ATOM(onMozMouseHittest, "onMozMouseHittest") GK_ATOM(onmouseup, "onmouseup") GK_ATOM(onMozAfterPaint, "onMozAfterPaint") GK_ATOM(onMozMousePixelScroll, "onMozMousePixelScroll") @@ -679,6 +680,7 @@ GK_ATOM(onpopuphidden, "onpopuphidden") GK_ATOM(onpopuphiding, "onpopuphiding") GK_ATOM(onpopupshowing, "onpopupshowing") GK_ATOM(onpopupshown, "onpopupshown") +GK_ATOM(onreadystatechange, "onreadystatechange") GK_ATOM(onRequest, "onRequest") GK_ATOM(onreset, "onreset") GK_ATOM(onresize, "onresize") diff --git a/content/base/src/nsWebSocket.cpp b/content/base/src/nsWebSocket.cpp index e1783106e79..6d2459c29f8 100644 --- a/content/base/src/nsWebSocket.cpp +++ b/content/base/src/nsWebSocket.cpp @@ -102,7 +102,7 @@ static nsIThread *gWebSocketThread = nsnull; #define TIMEOUT_TRY_CONNECT_AGAIN 1000 #define TIMEOUT_WAIT_FOR_SERVER_RESPONSE 20000 -#define TIMEOUT_WAIT_FOR_CLOSING 5000 +#define TIMEOUT_WAIT_FOR_CLOSING 20000 #define ENSURE_TRUE_AND_FAIL_IF_FAILED(x, ret) \ PR_BEGIN_MACRO \ @@ -240,7 +240,10 @@ public: nsresult Init(nsWebSocket *aOwner); nsresult Disconnect(); - // these are called always on the main thread (they dispatch themselves) + // These are called always on the main thread (they dispatch themselves). + // ATTENTION, this method when called can release both the WebSocket object + // (i.e. mOwner) and its connection (i.e. *this*) if there are no strong event + // listeners. DECL_RUNNABLE_ON_MAIN_THREAD_METHOD(Close) DECL_RUNNABLE_ON_MAIN_THREAD_METHOD(FailConnection) @@ -253,6 +256,17 @@ public: static nsTArray >* sWSsConnecting; private: + enum WSFrameType { + eConnectFrame, + eUTF8MessageFrame, + eCloseFrame + }; + + struct nsWSFrame { + WSFrameType mType; + nsAutoPtr mData; + }; + // We can only establish one connection at a time per IP address. // TryConnect ensures this by checking sWSsConnecting. // If there is a IP address entry there it tries again after @@ -291,7 +305,8 @@ private: nsresult Reset(); void RemoveFromLoadGroup(); nsresult ProcessHeaders(); - nsresult PostData(nsCString *aBuffer, PRBool aIsMessage); + nsresult PostData(nsCString *aBuffer, + WSFrameType aWSFrameType); nsresult PrintErrorOnConsole(const char *aBundleURI, const PRUnichar *aError, const PRUnichar **aFormatStrings, @@ -324,7 +339,7 @@ private: nsCOMPtr mSocketInput; nsCOMPtr mSocketOutput; nsCOMPtr mProxyInfo; - nsDeque mOutgoingMessages; // has nsCString* which need to be sent + nsDeque mOutgoingMessages; // has nsWSFrame* which need to be sent PRUint32 mBytesAlreadySentOfFirstOutString; PRUint32 mOutgoingBufferedAmount; // not really necessary, but it is // here for fast access. @@ -652,14 +667,17 @@ nsWebSocketEstablishedConnection::nsWebSocketEstablishedConnection() : nsWebSocketEstablishedConnection::~nsWebSocketEstablishedConnection() { + NS_ASSERTION(!mOwner, "Disconnect wasn't called!"); } nsresult nsWebSocketEstablishedConnection::PostData(nsCString *aBuffer, - PRBool aIsMessage) + WSFrameType aWSFrameType) { NS_ASSERTION(NS_IsMainThread(), "Not running on main thread"); + nsAutoPtr data(aBuffer); + if (mStatus == CONN_CLOSED) { NS_ASSERTION(mOwner, "Posting data after disconnecting the websocket!"); // the tcp connection has been closed, but the main thread hasn't received @@ -669,14 +687,21 @@ nsWebSocketEstablishedConnection::PostData(nsCString *aBuffer, MutexAutoLock lockOut(mLockOutgoingMessages); + nsAutoPtr frame(new nsWSFrame()); + NS_ENSURE_TRUE(frame.get(), NS_ERROR_OUT_OF_MEMORY); + frame->mType = aWSFrameType; + frame->mData = data.forget(); + nsresult rv; PRInt32 sizeBefore = mOutgoingMessages.GetSize(); - mOutgoingMessages.Push(aBuffer); + mOutgoingMessages.Push(frame.forget()); NS_ENSURE_TRUE(mOutgoingMessages.GetSize() == sizeBefore + 1, NS_ERROR_OUT_OF_MEMORY); - if (aIsMessage) { + if (aWSFrameType == eUTF8MessageFrame) { // without the START_BYTE_OF_MESSAGE and END_BYTE_OF_MESSAGE bytes mOutgoingBufferedAmount += aBuffer->Length() - 2; + } else if (aWSFrameType == eCloseFrame) { + mPostedCloseFrame = PR_TRUE; } if (sizeBefore == 0) { @@ -752,7 +777,7 @@ nsWebSocketEstablishedConnection::PostMessage(const nsString& aMessage) ENSURE_TRUE_AND_FAIL_IF_FAILED(buf->Length() == static_cast(outLen), NS_ERROR_UNEXPECTED); - rv = PostData(buf.forget(), PR_TRUE); + rv = PostData(buf.forget(), eUTF8MessageFrame); ENSURE_SUCCESS_AND_FAIL_IF_FAILED(rv, rv); return NS_OK; @@ -873,7 +898,7 @@ IMPL_RUNNABLE_ON_MAIN_THREAD_METHOD_BEGIN(DoInitialRequest) mStatus = CONN_SENDING_INITIAL_REQUEST; - rv = PostData(buf.forget(), PR_FALSE); + rv = PostData(buf.forget(), eConnectFrame); CHECK_SUCCESS_AND_FAIL_IF_FAILED(rv); } IMPL_RUNNABLE_ON_MAIN_THREAD_METHOD_END @@ -1455,11 +1480,11 @@ nsWebSocketEstablishedConnection::Reset() mSocketOutput = nsnull; while (mOutgoingMessages.GetSize() != 0) { - delete static_cast(mOutgoingMessages.PopFront()); + delete static_cast(mOutgoingMessages.PopFront()); } while (mReceivedMessages.GetSize() != 0) { - delete static_cast(mReceivedMessages.PopFront()); + delete static_cast(mReceivedMessages.PopFront()); } mBytesAlreadySentOfFirstOutString = 0; @@ -1685,7 +1710,7 @@ nsWebSocketEstablishedConnection::DoConnect() mStatus = CONN_CONNECTING_TO_HTTP_PROXY; - rv = PostData(buf.forget(), PR_FALSE); + rv = PostData(buf.forget(), eConnectFrame); ENSURE_SUCCESS_AND_FAIL_IF_FAILED(rv, rv); return NS_OK; @@ -1945,6 +1970,10 @@ IMPL_RUNNABLE_ON_MAIN_THREAD_METHOD_BEGIN(Close) { nsresult rv; + // Disconnect() can release this object, so we keep a + // reference until the end of the method + nsRefPtr kungfuDeathGrip = this; + if (mOwner->mReadyState == nsIWebSocket::CONNECTING) { // we must not convey any failure information to scripts, so we just // disconnect and maintain the owner WebSocket object in the CONNECTING @@ -1987,13 +2016,11 @@ IMPL_RUNNABLE_ON_MAIN_THREAD_METHOD_BEGIN(Close) closeFrame->SetCharAt(START_BYTE_OF_CLOSE_FRAME, 0); closeFrame->SetCharAt(END_BYTE_OF_CLOSE_FRAME, 1); - rv = PostData(closeFrame.forget(), PR_FALSE); + rv = PostData(closeFrame.forget(), eCloseFrame); if (NS_FAILED(rv)) { NS_WARNING("Failed to post the close frame"); return; } - - mPostedCloseFrame = PR_TRUE; } else { // Probably failed to send the close frame. Just disconnect. Disconnect(); @@ -2004,6 +2031,10 @@ IMPL_RUNNABLE_ON_MAIN_THREAD_METHOD_END void nsWebSocketEstablishedConnection::ForceClose() { + // Disconnect() can release this object, so we keep a + // reference until the end of the method + nsRefPtr kungfuDeathGrip = this; + if (mOwner->mReadyState == nsIWebSocket::CONNECTING) { // we must not convey any failure information to scripts, so we just // disconnect and maintain the owner WebSocket object in the CONNECTING @@ -2061,6 +2092,12 @@ nsWebSocketEstablishedConnection::Disconnect() return NS_OK; } + // If mOwner is deleted when calling mOwner->DontKeepAliveAnyMore() + // then this method can be called again, and we will get a deadlock. + nsRefPtr kungfuDeathGrip = mOwner; + + mOwner->DontKeepAliveAnyMore(); + RemoveWSConnecting(); mStatus = CONN_CLOSED; @@ -2111,11 +2148,11 @@ nsWebSocketEstablishedConnection::Disconnect() mProxyInfo = nsnull; while (mOutgoingMessages.GetSize() != 0) { - delete static_cast(mOutgoingMessages.PopFront()); + delete static_cast(mOutgoingMessages.PopFront()); } while (mReceivedMessages.GetSize() != 0) { - delete static_cast(mReceivedMessages.PopFront()); + delete static_cast(mReceivedMessages.PopFront()); } // Remove ourselves from the document's load group. nsIRequest expects @@ -2606,13 +2643,13 @@ nsWebSocketEstablishedConnection::OnInputStreamReady(nsIAsyncInputStream *aStrea // closed. In this case we have to reset the WebSocket, not Close it. if (mStatus != CONN_RETRYING_TO_AUTHENTICATE) { mStatus = CONN_CLOSED; + mFailureStatus = NS_BASE_STREAM_CLOSED; if (mStatus < CONN_CONNECTED_AND_READY) { FailConnection(); } else { Close(); } } - mFailureStatus = NS_BASE_STREAM_CLOSED; return NS_BASE_STREAM_CLOSED; } @@ -2659,13 +2696,14 @@ nsWebSocketEstablishedConnection::OnOutputStreamReady(nsIAsyncOutputStream *aStr // send what we can of the 1st string - nsCString *strToSend = - static_cast(mOutgoingMessages.PeekFront()); + nsWSFrame *frameToSend = + static_cast(mOutgoingMessages.PeekFront()); + nsCString *strToSend = frameToSend->mData; PRUint32 sizeToSend = strToSend->Length() - mBytesAlreadySentOfFirstOutString; PRBool currentStrHasStartFrameByte = (mBytesAlreadySentOfFirstOutString == 0); - PRBool strIsMessage = (mStatus >= CONN_CONNECTED_AND_READY); + PRBool strIsMessage = (frameToSend->mType == eUTF8MessageFrame); if (sizeToSend != 0) { PRUint32 written; @@ -2691,12 +2729,12 @@ nsWebSocketEstablishedConnection::OnOutputStreamReady(nsIAsyncOutputStream *aStr if (written == 0) { mStatus = CONN_CLOSED; + mFailureStatus = NS_BASE_STREAM_CLOSED; if (mStatus < CONN_CONNECTED_AND_READY) { FailConnection(); } else { Close(); } - mFailureStatus = NS_BASE_STREAM_CLOSED; return NS_BASE_STREAM_CLOSED; } @@ -2731,7 +2769,7 @@ nsWebSocketEstablishedConnection::OnOutputStreamReady(nsIAsyncOutputStream *aStr // ok, send the next string mOutgoingMessages.PopFront(); - delete strToSend; + delete frameToSend; mBytesAlreadySentOfFirstOutString = 0; } @@ -2803,13 +2841,19 @@ nsWebSocketEstablishedConnection::GetInterface(const nsIID &aIID, // nsWebSocket //////////////////////////////////////////////////////////////////////////////// -nsWebSocket::nsWebSocket() : mReadyState(nsIWebSocket::CONNECTING), +nsWebSocket::nsWebSocket() : mHasStrongEventListeners(PR_FALSE), + mCheckThereAreStrongEventListeners(PR_TRUE), + mReadyState(nsIWebSocket::CONNECTING), mOutgoingBufferedAmount(0) { } nsWebSocket::~nsWebSocket() { + if (mConnection) { + mConnection->Disconnect(); + mConnection = nsnull; + } if (mListenerManager) { mListenerManager->Disconnect(); mListenerManager = nsnull; @@ -2832,16 +2876,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsWebSocket, nsDOMEventTargetWrapperCache) + if (tmp->mConnection) { + tmp->mConnection->Disconnect(); + tmp->mConnection = nsnull; + } NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnOpenListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnMessageListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCloseListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURI) - if (tmp->mConnection) { - tmp->mConnection->Disconnect(); - tmp->mConnection = nsnull; - } NS_IMPL_CYCLE_COLLECTION_UNLINK_END DOMCI_DATA(WebSocket, nsWebSocket) @@ -2955,7 +2999,9 @@ public: NS_IMETHOD Run() { - return mWebSocket->CreateAndDispatchCloseEvent(mWasClean); + nsresult rv = mWebSocket->CreateAndDispatchCloseEvent(mWasClean); + mWebSocket->UpdateMustKeepAlive(); + return rv; } private: @@ -3073,6 +3119,7 @@ nsWebSocket::SetReadyState(PRUint16 aNewReadyState) if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch the open event"); } + UpdateMustKeepAlive(); return; } @@ -3099,6 +3146,7 @@ nsWebSocket::SetReadyState(PRUint16 aNewReadyState) rv = NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch the close event"); + UpdateMustKeepAlive(); } } } @@ -3210,6 +3258,94 @@ nsWebSocket::SetProtocol(const nsString& aProtocol) return NS_OK; } +//----------------------------------------------------------------------------- +// Methods that keep alive the WebSocket object when there are +// onopen/onmessage event listeners. +//----------------------------------------------------------------------------- + +void +nsWebSocket::UpdateMustKeepAlive() +{ + if (!mCheckThereAreStrongEventListeners) { + return; + } + + if (mHasStrongEventListeners) { + if (!mListenerManager || + ((mReadyState != nsIWebSocket::CONNECTING || + !mListenerManager->HasListenersFor(NS_LITERAL_STRING("open"))) && + (mReadyState == nsIWebSocket::CLOSED || + !mListenerManager->HasListenersFor(NS_LITERAL_STRING("message"))))) { + mHasStrongEventListeners = PR_FALSE; + static_cast(this)->Release(); + } + } else { + if ((mReadyState == nsIWebSocket::CONNECTING && mListenerManager && + mListenerManager->HasListenersFor(NS_LITERAL_STRING("open"))) || + (mReadyState != nsIWebSocket::CLOSED && mListenerManager && + mListenerManager->HasListenersFor(NS_LITERAL_STRING("message")))) { + mHasStrongEventListeners = PR_TRUE; + static_cast(this)->AddRef(); + } + } +} + +void +nsWebSocket::DontKeepAliveAnyMore() +{ + if (mHasStrongEventListeners) { + mCheckThereAreStrongEventListeners = PR_FALSE; + mHasStrongEventListeners = PR_FALSE; + static_cast(this)->Release(); + } +} + +NS_IMETHODIMP +nsWebSocket::AddEventListener(const nsAString& aType, + nsIDOMEventListener* aListener, + PRBool aUseCapture) +{ + nsresult rv = nsDOMEventTargetHelper::AddEventListener(aType, + aListener, + aUseCapture); + if (NS_SUCCEEDED(rv)) { + UpdateMustKeepAlive(); + } + return rv; +} + +NS_IMETHODIMP +nsWebSocket::RemoveEventListener(const nsAString& aType, + nsIDOMEventListener* aListener, + PRBool aUseCapture) +{ + nsresult rv = nsDOMEventTargetHelper::RemoveEventListener(aType, + aListener, + aUseCapture); + if (NS_SUCCEEDED(rv)) { + UpdateMustKeepAlive(); + } + return rv; +} + +NS_IMETHODIMP +nsWebSocket::AddEventListener(const nsAString& aType, + nsIDOMEventListener *aListener, + PRBool aUseCapture, + PRBool aWantsUntrusted, + PRUint8 optional_argc) +{ + nsresult rv = nsDOMEventTargetHelper::AddEventListener(aType, + aListener, + aUseCapture, + aWantsUntrusted, + optional_argc); + if (NS_SUCCEEDED(rv)) { + UpdateMustKeepAlive(); + } + return rv; +} + //----------------------------------------------------------------------------- // nsWebSocket::nsIWebSocket methods: //----------------------------------------------------------------------------- @@ -3303,6 +3439,10 @@ nsWebSocket::Close() } if (mReadyState == nsIWebSocket::CONNECTING) { + // FailConnection() can release the object if there are no strong event + // listeners, so we keep a reference before calling it + nsRefPtr kungfuDeathGrip = this; + mConnection->FailConnection(); // We need to set the readyState here because mConnection would set it diff --git a/content/base/src/nsWebSocket.h b/content/base/src/nsWebSocket.h index 8daf40bc4b4..26d647e2824 100644 --- a/content/base/src/nsWebSocket.h +++ b/content/base/src/nsWebSocket.h @@ -86,6 +86,21 @@ public: NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext, JSObject* aObject, PRUint32 aArgc, jsval* aArgv); + // nsIDOMEventTarget + NS_IMETHOD AddEventListener(const nsAString& aType, + nsIDOMEventListener* aListener, + PRBool aUseCapture); + NS_IMETHOD RemoveEventListener(const nsAString& aType, + nsIDOMEventListener* aListener, + PRBool aUseCapture); + + // nsIDOMNSEventTarget + NS_IMETHOD AddEventListener(const nsAString& aType, + nsIDOMEventListener *aListener, + PRBool aUseCapture, + PRBool aWantsUntrusted, + PRUint8 optional_argc); + static void ReleaseGlobals(); protected: @@ -100,6 +115,14 @@ protected: // called from mConnection accordingly to the situation void SetReadyState(PRUint16 aNewReadyState); + // if there are onopen or onmessage event listeners ("strong event listeners") + // then this method keeps the object alive when js doesn't have strong + // references to it. + void UpdateMustKeepAlive(); + // Releases, if necessary, the strong event listeners. ATTENTION, when calling + // this method the object can be released (and possibly collected). + void DontKeepAliveAnyMore(); + nsRefPtr mOnOpenListener; nsRefPtr mOnErrorListener; nsRefPtr mOnMessageListener; @@ -109,6 +132,10 @@ protected: nsString mOriginalURL; PRPackedBool mSecure; // if true it is using SSL and the wss scheme, // otherwise it is using the ws scheme with no SSL + + PRPackedBool mHasStrongEventListeners; + PRPackedBool mCheckThereAreStrongEventListeners; + nsCString mAsciiHost; // hostname PRUint32 mPort; nsCString mResource; // [filepath[?query]] diff --git a/content/base/src/nsXHTMLContentSerializer.cpp b/content/base/src/nsXHTMLContentSerializer.cpp index 21d603fa33d..12bf1cc69b2 100644 --- a/content/base/src/nsXHTMLContentSerializer.cpp +++ b/content/base/src/nsXHTMLContentSerializer.cpp @@ -101,6 +101,8 @@ nsXHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, const char* aCharSet, PRBool aIsCopying, PRBool aRewriteEncodingDeclaration) { + mInBody = 0; + // The previous version of the HTML serializer did implicit wrapping // when there is no flags, so we keep wrapping in order to keep // compatibility with the existing calling code diff --git a/content/base/src/nsXMLContentSerializer.cpp b/content/base/src/nsXMLContentSerializer.cpp index f0295853899..aa65d058250 100644 --- a/content/base/src/nsXMLContentSerializer.cpp +++ b/content/base/src/nsXMLContentSerializer.cpp @@ -111,6 +111,15 @@ nsXMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, const char* aCharSet, PRBool aIsCopying, PRBool aRewriteEncodingDeclaration) { + mPrefixIndex = 0; + mColPos = 0; + mIndentOverflow = 0; + mIsIndentationAddedOnCurrentLine = PR_FALSE; + mInAttribute = PR_FALSE; + mAddNewlineForRootNode = PR_FALSE; + mAddSpace = PR_FALSE; + mMayIgnoreLineBreakSequence = PR_FALSE; + mCharset = aCharSet; mFlags = aFlags; diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index 97802778545..9695c144c86 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -394,6 +394,7 @@ _TEST_FILES2 = \ test_html_colors_quirks.html \ test_html_colors_standards.html \ test_bug571390.xul \ + test_bug300992.html \ test_websocket_hello.html \ file_websocket_hello_wsh.py \ test_ws_basic_tests.html \ diff --git a/content/base/test/file_websocket_wsh.py b/content/base/test/file_websocket_wsh.py index f4890d94ea2..1431d792b97 100644 --- a/content/base/test/file_websocket_wsh.py +++ b/content/base/test/file_websocket_wsh.py @@ -6,25 +6,56 @@ import sys # see the list of tests in test_websocket.html def web_socket_do_extra_handshake(request): - if request.ws_protocol == "test 6": - sys.exit(0) - elif request.ws_protocol == "test 19": - time.sleep(180) - pass - elif request.ws_protocol == "test 8": + if request.ws_protocol == "test 2.1": time.sleep(5) pass elif request.ws_protocol == "test 9": time.sleep(5) pass - elif request.ws_protocol == "test 10.1": + elif request.ws_protocol == "test 10": time.sleep(5) pass + elif request.ws_protocol == "test 19": + raise ValueError('Aborting (test 19)') + elif request.ws_protocol == "test 20" or request.ws_protocol == "test 17": + time.sleep(10) + pass + elif request.ws_protocol == "test 22": + time.sleep(60) + pass else: pass def web_socket_transfer_data(request): - if request.ws_protocol == "test 9": + if request.ws_protocol == "test 2.1" or request.ws_protocol == "test 2.2": + msgutil.close_connection(request) + elif request.ws_protocol == "test 6": + resp = "wrong message" + if msgutil.receive_message(request) == "1": + resp = "2" + msgutil.send_message(request, resp.decode('utf-8')) + resp = "wrong message" + if msgutil.receive_message(request) == "3": + resp = "4" + msgutil.send_message(request, resp.decode('utf-8')) + resp = "wrong message" + if msgutil.receive_message(request) == "5": + resp = "ã‚ã„ã†ãˆãŠ" + msgutil.send_message(request, resp.decode('utf-8')) + elif request.ws_protocol == "test 7": + try: + while not request.client_terminated: + msgutil.receive_message(request) + except msgutil.ConnectionTerminatedException, e: + pass + msgutil.send_message(request, "server data") + msgutil.send_message(request, "server data") + msgutil.send_message(request, "server data") + msgutil.send_message(request, "server data") + msgutil.send_message(request, "server data") + time.sleep(30) + msgutil.close_connection(request, True) + elif request.ws_protocol == "test 10": msgutil.close_connection(request) elif request.ws_protocol == "test 11": resp = "wrong message" @@ -41,27 +72,19 @@ def web_socket_transfer_data(request): request.connection.write('\xff\x00') msgutil.send_message(request, "server data") elif request.ws_protocol == "test 15": - sys.exit (0) - elif request.ws_protocol == "test 17": - while not request.client_terminated: - msgutil.send_message(request, "server data") - time.sleep(1) + msgutil.close_connection(request, True) + return + elif request.ws_protocol == "test 17" or request.ws_protocol == "test 21": + time.sleep(5) + resp = "wrong message" + if msgutil.receive_message(request) == "client data": + resp = "server data" + msgutil.send_message(request, resp.decode('utf-8')) + time.sleep(5) + msgutil.close_connection(request) + time.sleep(5) + elif request.ws_protocol == "test 20": msgutil.send_message(request, "server data") - sys.exit(0) - elif request.ws_protocol == "test 18": - resp = "wrong message" - if msgutil.receive_message(request) == "1": - resp = "2" - msgutil.send_message(request, resp.decode('utf-8')) - resp = "wrong message" - if msgutil.receive_message(request) == "3": - resp = "4" - msgutil.send_message(request, resp.decode('utf-8')) - resp = "wrong message" - if msgutil.receive_message(request) == "5": - resp = "ã‚ã„ã†ãˆãŠ" - msgutil.send_message(request, resp.decode('utf-8')) - elif request.ws_protocol == "test 10.1" or request.ws_protocol == "test 10.2": msgutil.close_connection(request) while not request.client_terminated: msgutil.receive_message(request) diff --git a/content/base/test/test_bug300992.html b/content/base/test/test_bug300992.html new file mode 100644 index 00000000000..97d727c52ed --- /dev/null +++ b/content/base/test/test_bug300992.html @@ -0,0 +1,46 @@ + + + + + Test for Bug 300992 + + + + + +Mozilla Bug 300992 +

+ +
+
+
+ + diff --git a/content/base/test/test_websocket.html b/content/base/test/test_websocket.html index f723a883725..f36df1d1a8d 100644 --- a/content/base/test/test_websocket.html +++ b/content/base/test/test_websocket.html @@ -18,16 +18,17 @@ /* * tests: * 1. client tries to connect to a http scheme location; - * 2. client tries to connect to an http resource; + * 2. assure serialization of the connections; * 3. client tries to connect to an non-existent ws server; * 4. client tries to connect using a relative url; * 5. client uses an invalid protocol value; - * 6. server closes the tcp connection before establishing the ws connection; - * 7. client calls close() and the server sends the close frame in + * 6. counter and encoding check; + * 7. client calls close() and the server keeps sending messages and it doesn't + * send the close frame; + * 8. client calls close() and the server sends the close frame in * acknowledgement; - * 8. client closes the connection before the ws connection is established; - * 9. client sends a message before the ws connection is established; - * 10. assure serialization of the connections; + * 9. client closes the connection before the ws connection is established; + * 10. client sends a message before the ws connection is established; * 11. a simple hello echo; * 12. client sends a message with bad bytes; * 13. server sends an invalid message; @@ -35,54 +36,46 @@ * it keeps sending normal ws messages; * 15. server closes the tcp connection, but it doesn't send the close frame; * 16. client calls close() and tries to send a message; - * 17. client calls close() and the server keeps sending messages and it doesn't - * send the close frame; - * 18. counter and encoding check; - * 19. server takes too long to establish the ws connection; + * 17. see bug 572975 - all event listeners set + * 18. client tries to connect to an http resource; + * 19. server closes the tcp connection before establishing the ws connection; + * 20. see bug 572975 - only on error and onclose event listeners set + * 21. see bug 572975 - same as test 17, but delete strong event listeners when + * receiving the message event; + * 22. server takes too long to establish the ws connection; */ var first_test = 1; -var last_test = 19; +var last_test = 22; -var current_test = 1; +var current_test = first_test; var timeoutToAbortTest = 60000; +var timeoutToOpenWS = 25000; var all_ws = []; function shouldNotOpen(e) { var ws = e.target; ok(false, "onopen shouldn't be called on test " + ws._testNumber + "!"); - if (ws._timeoutToSucceed != undefined) { - clearTimeout(ws._timeoutToSucceed); - } } function shouldNotReceiveCloseEvent(e) { var ws = e.target; ok(false, "onclose shouldn't be called on test " + ws._testNumber + "!"); - if (ws._timeoutToSucceed != undefined) { - clearTimeout(ws._timeoutToSucceed); - } } function shouldCloseCleanly(e) { var ws = e.target; - //ok(e.wasClean, "the ws connection in test " + ws._testNumber + " should be closed cleanly"); - if (ws._timeoutToSucceed != undefined) { - clearTimeout(ws._timeoutToSucceed); - } + ok(e.wasClean, "the ws connection in test " + ws._testNumber + " should be closed cleanly"); } function shouldCloseNotCleanly(e) { var ws = e.target; - //ok(!e.wasClean, "the ws connection in test " + ws._testNumber + " shouldn't be closed cleanly"); - if (ws._timeoutToSucceed != undefined) { - clearTimeout(ws._timeoutToSucceed); - } + ok(!e.wasClean, "the ws connection in test " + ws._testNumber + " shouldn't be closed cleanly"); } function CreateTestWS(ws_location, ws_protocol) @@ -119,6 +112,20 @@ function CreateTestWS(ws_location, ws_protocol) return ws; } +function forcegc() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + Components.utils.forceGC(); + var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils); + wu.garbageCollect(); + setTimeout(function() + { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + wu.garbageCollect(); + }, 1); +} + function doTest(number) { if (doTest.timeoutId !== null) { @@ -163,12 +170,28 @@ function test1() doTest(2); } +// this test expects that the serialization list to connect to the proxy +// is empty function test2() { - var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket_http_resource.txt"); - ws.onopen = shouldNotOpen; - ws.onclose = shouldNotReceiveCloseEvent; - doTest(3); + var ws1 = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 2.1"); + current_test--; // CreateTestWS incremented this + var ws2 = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 2.2"); + + var ws2CanConnect = false; + + // the server will delay ws1 for 5 seconds + + ws1.onopen = function() + { + ws2CanConnect = true; + } + + ws2.onopen = function() + { + ok(ws2CanConnect, "shouldn't connect yet in test 2!"); + doTest(3); + } } function test3() @@ -183,10 +206,10 @@ function test4() { try { var ws = CreateTestWS("file_websocket"); - ok(false, "test4 failed"); + ok(false, "test 4 failed"); } catch (e) { - ok(true, "test4 failed"); + ok(true, "test 4 failed"); } doTest(5); } @@ -214,9 +237,25 @@ function test5() function test6() { var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 6"); - ws.onopen = shouldNotOpen; - ws.onclose = shouldNotReceiveCloseEvent; - doTest(7); + var counter = 1; + ws.onopen = function() + { + ws.send(counter); + } + ws.onmessage = function(e) + { + if (counter == 5) { + ok(e.data == "ã‚ã„ã†ãˆãŠ"); + ws.close(); + doTest(7); + } else { + ok(e.data == counter+1, "bad counter"); + counter += 2; + ws.send(counter); + } + } + ws.onclose = shouldCloseCleanly; + ws._receivedCloseEvent = false; } function test7() @@ -228,7 +267,7 @@ function test7() } ws.onclose = function(e) { - shouldCloseCleanly(e); + shouldCloseNotCleanly(e); doTest(8); }; ws._receivedCloseEvent = false; @@ -237,20 +276,35 @@ function test7() function test8() { var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 8"); + ws.onopen = function() + { + ws.close(); + } + ws.onclose = function(e) + { + shouldCloseCleanly(e); + doTest(9); + }; + ws._receivedCloseEvent = false; +} + +function test9() +{ + var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 9"); ws.onopen = shouldNotOpen; ws.onclose = function(e) { shouldCloseNotCleanly(e); - doTest(9); + doTest(10); }; ws._receivedCloseEvent = false; ws.close(); } -function test9() +function test10() { - var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 9"); + var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 10"); ws.onclose = shouldCloseCleanly; ws._receivedCloseEvent = false; @@ -261,27 +315,8 @@ function test9() catch (e) { ok(true, "Couldn't send data before connecting!"); } - doTest(10); -} - -function test10() -{ - var ws1 = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 10.1"); - current_test--; // CreateTestWS incremented this - var ws2 = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 10.2"); - - var ws2CanConnect = false; - - // the server will delay ws1 for 5 seconds - - ws1.onopen = function() + ws.onopen = function() { - ws2CanConnect = true; - } - - ws2.onopen = function() - { - ok(ws2CanConnect, "shouldn't connect yet in test 10!"); doTest(11); } } @@ -336,8 +371,8 @@ function test13() { ws._timesCalledOnError++; if (ws._timesCalledOnError == 2) { + ok(true, "test 13 succeeded"); doTest(14); - ok(true, "test13 succeeded"); } } ws.onclose = shouldCloseCleanly; @@ -387,43 +422,63 @@ function test16() ws._receivedCloseEvent = false; } +var status_test17 = "not started"; + +window._test17 = function() +{ + var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 17"); + + status_test17 = "started"; + + local_ws.onopen = function(e) + { + status_test17 = "opened"; + e.target.send("client data"); + forcegc(); + }; + + local_ws.onerror = function() + { + ok(false, "onerror called on test " + e.target._testNumber + "!"); + }; + + local_ws.onmessage = function(e) + { + ok(e.data == "server data", "Bad message in test 17"); + status_test17 = "got message"; + forcegc(); + }; + + local_ws.onclose = function(e) + { + ok(status_test17 == "got message", "Didn't got message in test 17!"); + shouldCloseCleanly(e); + status_test17 = "closed"; + forcegc(); + doTest(18); + forcegc(); + }; + + local_ws = null; + window._test17 = null; + forcegc(); +} + function test17() { - var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 17"); - ws.onopen = function() - { - ws.close(); - } - ws.onclose = function(e) - { - shouldCloseNotCleanly(e); - doTest(18); - }; - ws._receivedCloseEvent = false; + window._test17(); } +// The tests that expects that their websockets neither open nor close MUST +// be in the end of the tests, i.e. HERE, in order to prevent blocking the other +// tests. + function test18() { - var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 18"); - var counter = 1; - ws.onopen = function() - { - ws.send(counter); - } - ws.onmessage = function(e) - { - if (counter == 5) { - ok(e.data == "ã‚ã„ã†ãˆãŠ"); - ws.close(); - doTest(19); - } else { - ok(e.data == counter+1, "bad counter"); - counter += 2; - ws.send(counter); - } - } - ws.onclose = shouldCloseCleanly; - ws._receivedCloseEvent = false; + var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket_http_resource.txt"); + ws.onopen = shouldNotOpen; + ws.onclose = shouldNotReceiveCloseEvent; + doTest(19); } function test19() @@ -434,6 +489,81 @@ function test19() doTest(20); } +window._test20 = function() +{ + var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 20"); + + local_ws.onerror = function() + { + ok(false, "onerror called on test " + e.target._testNumber + "!"); + }; + + local_ws.onclose = shouldNotReceiveCloseEvent; + + local_ws = null; + window._test20 = null; + forcegc(); +} + +function test20() +{ + window._test20(); + doTest(21); +} + +var timeoutTest21; + +window._test21 = function() +{ + var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 21"); + + local_ws.onopen = function(e) + { + e.target.send("client data"); + timeoutTest21 = setTimeout(function() + { + ok(false, "Didn't received message on test 21!"); + }, 15000); + forcegc(); + e.target.onopen = null; + forcegc(); + }; + + local_ws.onerror = function() + { + ok(false, "onerror called on test " + e.target._testNumber + "!"); + }; + + local_ws.onmessage = function(e) + { + clearTimeout(timeoutTest21); + ok(e.data == "server data", "Bad message in test 21"); + forcegc(); + e.target.onmessage = null; + forcegc(); + }; + + local_ws.onclose = shouldNotReceiveCloseEvent; + + local_ws = null; + window._test21 = null; + forcegc(); +} + +function test21() +{ + window._test21(); + doTest(22); +} + +function test22() +{ + var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 22"); + ws.onopen = shouldNotOpen; + ws.onclose = shouldNotReceiveCloseEvent; + doTest(23); +} + function finishWSTest() { for (i = 0; i < all_ws.length; ++i) { diff --git a/content/canvas/src/CustomQS_WebGL.h b/content/canvas/src/CustomQS_WebGL.h index bff9a795e36..8ebc277c6b8 100644 --- a/content/canvas/src/CustomQS_WebGL.h +++ b/content/canvas/src/CustomQS_WebGL.h @@ -308,6 +308,7 @@ nsICanvasRenderingContextWebGL_ReadPixels(JSContext *cx, uintN argc, jsval *vp) * TexImage2D takes: * TexImage2D(uint, int, uint, int, int, int, uint, uint, ArrayBufferView)\ * TexImage2D(uint, int, uint, uint, uint, nsIDOMElement) + * TexImage2D(uint, int, uint, uint, uint, ImageData) */ static JSBool nsICanvasRenderingContextWebGL_TexImage2D(JSContext *cx, uintN argc, jsval *vp) @@ -360,6 +361,34 @@ nsICanvasRenderingContextWebGL_TexImage2D(JSContext *cx, uintN argc, jsval *vp) if (NS_FAILED(rv)) return JS_FALSE; rv = self->TexImage2D_dom(argv0, argv1, argv2, argv3, argv4, elt); + + if (NS_FAILED(rv)) { + // failed to interprete argv[5] as a DOMElement, now try to interprete it as ImageData + JSObject *argv5 = JSVAL_TO_OBJECT(argv[5]); + jsval js_width, js_height, js_data; + JS_GetProperty(cx, argv5, "width", &js_width); + JS_GetProperty(cx, argv5, "height", &js_height); + JS_GetProperty(cx, argv5, "data", &js_data); + if (js_width == JSVAL_VOID || + js_height == JSVAL_VOID || + js_data == JSVAL_VOID) + { + xpc_qsThrowBadArg(cx, NS_ERROR_FAILURE, vp, 5); + return JS_FALSE; + } + int32 int_width, int_height; + JSObject *obj_data = JSVAL_TO_OBJECT(js_data); + if (!JS_ValueToECMAInt32(cx, js_width, &int_width) || + !JS_ValueToECMAInt32(cx, js_height, &int_height) || + !js_IsTypedArray(obj_data)) + { + xpc_qsThrowBadArg(cx, NS_ERROR_FAILURE, vp, 5); + return JS_FALSE; + } + rv = self->TexImage2D_array(argv0, argv1, argv2, + int_width, int_height, 0, + argv3, argv4, js::TypedArray::fromJSObject(obj_data)); + } } else if (argc > 8 && JSVAL_IS_OBJECT(argv[8])) { // implement the variants taking a buffer/array as argv[8] GET_UINT32_ARG(argv2, 2); @@ -403,6 +432,7 @@ nsICanvasRenderingContextWebGL_TexImage2D(JSContext *cx, uintN argc, jsval *vp) /* TexSubImage2D takes: * TexSubImage2D(uint, int, int, int, int, int, uint, uint, ArrayBufferView) * TexSubImage2D(uint, int, int, int, uint, uint, nsIDOMElement) + * TexSubImage2D(uint, int, int, int, uint, uint, ImageData) */ static JSBool nsICanvasRenderingContextWebGL_TexSubImage2D(JSContext *cx, uintN argc, jsval *vp) @@ -442,6 +472,35 @@ nsICanvasRenderingContextWebGL_TexSubImage2D(JSContext *cx, uintN argc, jsval *v if (NS_FAILED(rv)) return JS_FALSE; rv = self->TexSubImage2D_dom(argv0, argv1, argv2, argv3, argv4, argv5, elt); + + if (NS_FAILED(rv)) { + // failed to interprete argv[6] as a DOMElement, now try to interprete it as ImageData + JSObject *argv6 = JSVAL_TO_OBJECT(argv[6]); + jsval js_width, js_height, js_data; + JS_GetProperty(cx, argv6, "width", &js_width); + JS_GetProperty(cx, argv6, "height", &js_height); + JS_GetProperty(cx, argv6, "data", &js_data); + if (js_width == JSVAL_VOID || + js_height == JSVAL_VOID || + js_data == JSVAL_VOID) + { + xpc_qsThrowBadArg(cx, NS_ERROR_FAILURE, vp, 6); + return JS_FALSE; + } + int32 int_width, int_height; + JSObject *obj_data = JSVAL_TO_OBJECT(js_data); + if (!JS_ValueToECMAInt32(cx, js_width, &int_width) || + !JS_ValueToECMAInt32(cx, js_height, &int_height) || + !js_IsTypedArray(obj_data)) + { + xpc_qsThrowBadArg(cx, NS_ERROR_FAILURE, vp, 6); + return JS_FALSE; + } + rv = self->TexSubImage2D_array(argv0, argv1, argv2, argv3, + int_width, int_height, + argv4, argv5, + js::TypedArray::fromJSObject(obj_data)); + } } else if (argc > 8 && JSVAL_IS_OBJECT(argv[8])) { // implement the variants taking a buffer/array as argv[8] GET_INT32_ARG(argv4, 4); diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index fd29e14d7ae..664ac701f2e 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -290,6 +290,9 @@ public: nsresult ErrorInvalidEnum(const char *fmt = 0, ...); nsresult ErrorInvalidOperation(const char *fmt = 0, ...); nsresult ErrorInvalidValue(const char *fmt = 0, ...); + nsresult ErrorInvalidEnumInfo(const char *info) { + return ErrorInvalidEnum("%s: invalid enum value", info); + } already_AddRefed GetCanvasLayer(LayerManager *manager); void MarkContextClean() { } @@ -316,10 +319,17 @@ protected: PRBool SafeToCreateCanvas3DContext(nsHTMLCanvasElement *canvasElement); PRBool InitAndValidateGL(); PRBool ValidateBuffers(PRUint32 count); - static PRBool ValidateCapabilityEnum(WebGLenum cap); - static PRBool ValidateBlendEquationEnum(WebGLuint cap); - static PRBool ValidateBlendFuncDstEnum(WebGLuint mode); - static PRBool ValidateBlendFuncSrcEnum(WebGLuint mode); + PRBool ValidateCapabilityEnum(WebGLenum cap, const char *info); + PRBool ValidateBlendEquationEnum(WebGLuint cap, const char *info); + PRBool ValidateBlendFuncDstEnum(WebGLuint mode, const char *info); + PRBool ValidateBlendFuncSrcEnum(WebGLuint mode, const char *info); + PRBool ValidateTextureTargetEnum(WebGLenum target, const char *info); + PRBool ValidateComparisonEnum(WebGLenum target, const char *info); + PRBool ValidateStencilOpEnum(WebGLenum action, const char *info); + PRBool ValidateFaceEnum(WebGLenum target, const char *info); + PRBool ValidateTexFormatAndType(WebGLenum format, WebGLenum type, + PRUint32 *texelSize, const char *info); + void Invalidate(); void MakeContextCurrent() { gl->MakeCurrent(); } diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index 97e82bb599e..dd1dcc6f4d1 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -296,8 +296,8 @@ GL_SAME_METHOD_4(BlendColor, BlendColor, float, float, float, float) NS_IMETHODIMP WebGLContext::BlendEquation(WebGLenum mode) { - if (!ValidateBlendEquationEnum(mode)) - return ErrorInvalidEnum("BlendEquation: invalid mode"); + if (!ValidateBlendEquationEnum(mode, "blendEquation: mode")) + return NS_OK; MakeContextCurrent(); gl->fBlendEquation(mode); @@ -306,9 +306,9 @@ NS_IMETHODIMP WebGLContext::BlendEquation(WebGLenum mode) NS_IMETHODIMP WebGLContext::BlendEquationSeparate(WebGLenum modeRGB, WebGLenum modeAlpha) { - if (!ValidateBlendEquationEnum(modeRGB) - || !ValidateBlendEquationEnum(modeAlpha)) - return ErrorInvalidEnum("BlendEquationSeparate: invalid mode"); + if (!ValidateBlendEquationEnum(modeRGB, "blendEquationSeparate: modeRGB") || + !ValidateBlendEquationEnum(modeAlpha, "blendEquationSeparate: modeAlpha")) + return NS_OK; MakeContextCurrent(); gl->fBlendEquationSeparate(modeRGB, modeAlpha); @@ -317,10 +317,9 @@ NS_IMETHODIMP WebGLContext::BlendEquationSeparate(WebGLenum modeRGB, WebGLenum m NS_IMETHODIMP WebGLContext::BlendFunc(WebGLenum sfactor, WebGLenum dfactor) { - if (!ValidateBlendFuncSrcEnum(sfactor)) - return ErrorInvalidEnum("BlendFunc: invalid source factor"); - if (!ValidateBlendFuncDstEnum(dfactor)) - return ErrorInvalidEnum("BlendFunc: invalid destination factor"); + if (!ValidateBlendFuncSrcEnum(sfactor, "blendFunc: sfactor") || + !ValidateBlendFuncDstEnum(dfactor, "blendFunc: dfactor")) + return NS_OK; MakeContextCurrent(); gl->fBlendFunc(sfactor, dfactor); @@ -331,12 +330,11 @@ NS_IMETHODIMP WebGLContext::BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB, WebGLenum srcAlpha, WebGLenum dstAlpha) { - if (!ValidateBlendFuncSrcEnum(srcRGB) - || !ValidateBlendFuncSrcEnum(srcAlpha)) - return ErrorInvalidEnum("BlendFuncSeparate: invalid source factor"); - if (!ValidateBlendFuncDstEnum(dstRGB) - || !ValidateBlendFuncDstEnum(dstAlpha)) - return ErrorInvalidEnum("BlendFuncSeparate: invalid destination factor"); + if (!ValidateBlendFuncSrcEnum(srcRGB, "blendFuncSeparate: srcRGB") || + !ValidateBlendFuncSrcEnum(srcAlpha, "blendFuncSeparate: srcAlpha") || + !ValidateBlendFuncDstEnum(dstRGB, "blendFuncSeparate: dstRGB") || + !ValidateBlendFuncDstEnum(dstAlpha, "blendFuncSeparate: dstAlpha")) + return NS_OK; MakeContextCurrent(); gl->fBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); @@ -804,7 +802,16 @@ WebGLContext::DetachShader(nsIWebGLProgram *pobj, nsIWebGLShader *shobj) return NS_OK; } -GL_SAME_METHOD_1(DepthFunc, DepthFunc, WebGLenum) +NS_IMETHODIMP +WebGLContext::DepthFunc(WebGLenum func) +{ + if (!ValidateComparisonEnum(func, "depthFunc")) + return NS_OK; + + MakeContextCurrent(); + gl->fDepthFunc(func); + return NS_OK; +} GL_SAME_METHOD_1(DepthMask, DepthMask, WebGLboolean) @@ -946,8 +953,8 @@ WebGLContext::DrawElements(WebGLenum mode, WebGLsizei count, WebGLenum type, Web NS_IMETHODIMP WebGLContext::Enable(WebGLenum cap) { - if (!ValidateCapabilityEnum(cap)) - return ErrorInvalidEnum("Enable: invalid capability enum"); + if (!ValidateCapabilityEnum(cap, "enable")) + return NS_OK; MakeContextCurrent(); gl->fEnable(cap); @@ -956,8 +963,8 @@ NS_IMETHODIMP WebGLContext::Enable(WebGLenum cap) NS_IMETHODIMP WebGLContext::Disable(WebGLenum cap) { - if (!ValidateCapabilityEnum(cap)) - return ErrorInvalidEnum("Disable: invalid capability enum"); + if (!ValidateCapabilityEnum(cap, "disable")) + return NS_OK; MakeContextCurrent(); gl->fDisable(cap); @@ -1062,9 +1069,21 @@ GL_SAME_METHOD_0(Flush, Flush) GL_SAME_METHOD_0(Finish, Finish) -GL_SAME_METHOD_1(FrontFace, FrontFace, WebGLenum) +NS_IMETHODIMP +WebGLContext::FrontFace(WebGLenum mode) +{ + switch (mode) { + case LOCAL_GL_CW: + case LOCAL_GL_CCW: + break; + default: + return ErrorInvalidEnum("FrontFace: invalid mode"); + } -GL_SAME_METHOD_1(GenerateMipmap, GenerateMipmap, WebGLenum) + MakeContextCurrent(); + gl->fFrontFace(mode); + return NS_OK; +} // returns an object: { size: ..., type: ..., name: ... } NS_IMETHODIMP @@ -1107,6 +1126,17 @@ WebGLContext::GetActiveAttrib(nsIWebGLProgram *pobj, PRUint32 index, nsIWebGLAct return NS_OK; } +NS_IMETHODIMP +WebGLContext::GenerateMipmap(WebGLenum target) +{ + if (!ValidateTextureTargetEnum(target, "generateMipmap")) + return NS_OK; + + MakeContextCurrent(); + gl->fGenerateMipmap(target); + return NS_OK; +} + NS_IMETHODIMP WebGLContext::GetActiveUniform(nsIWebGLProgram *pobj, PRUint32 index, nsIWebGLActiveInfo **retval) { @@ -1152,7 +1182,7 @@ WebGLContext::GetAttachedShaders(nsIWebGLProgram *pobj, nsIVariant **retval) { WebGLProgram *prog; if (!GetConcreteObject(pobj, &prog)) - return ErrorInvalidOperation("GetActiveAttrib: invalid program"); + return ErrorInvalidOperation("GetAttachedShaders: invalid program"); nsCOMPtr wrval = do_CreateInstance("@mozilla.org/variant;1"); NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE); @@ -1246,27 +1276,19 @@ WebGLContext::GetParameter(PRUint32 pname, nsIVariant **retval) case LOCAL_GL_BLEND_DST_ALPHA: case LOCAL_GL_BLEND_EQUATION_RGB: case LOCAL_GL_BLEND_EQUATION_ALPHA: - //case LOCAL_GL_UNPACK_ALIGNMENT: // not supported - //case LOCAL_GL_PACK_ALIGNMENT: // not supported + case LOCAL_GL_UNPACK_ALIGNMENT: + case LOCAL_GL_PACK_ALIGNMENT: case LOCAL_GL_GENERATE_MIPMAP_HINT: case LOCAL_GL_SUBPIXEL_BITS: case LOCAL_GL_MAX_TEXTURE_SIZE: case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE: - case LOCAL_GL_MAX_ELEMENTS_INDICES: - case LOCAL_GL_MAX_ELEMENTS_VERTICES: case LOCAL_GL_SAMPLE_BUFFERS: case LOCAL_GL_SAMPLES: - //case LOCAL_GL_COMPRESSED_TEXTURE_FORMATS: - //case LOCAL_GL_NUM_SHADER_BINARY_FORMATS: case LOCAL_GL_MAX_VERTEX_ATTRIBS: - case LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS: - case LOCAL_GL_MAX_VARYING_FLOATS: case LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: case LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: case LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS: case LOCAL_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: - //case LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS: // not present in desktop OpenGL - //case LOCAL_GL_MAX_VARYING_VECTORS: // not present in desktop OpenGL case LOCAL_GL_MAX_RENDERBUFFER_SIZE: case LOCAL_GL_RED_BITS: case LOCAL_GL_GREEN_BITS: @@ -1274,9 +1296,8 @@ WebGLContext::GetParameter(PRUint32 pname, nsIVariant **retval) case LOCAL_GL_ALPHA_BITS: case LOCAL_GL_DEPTH_BITS: case LOCAL_GL_STENCIL_BITS: - case LOCAL_GL_PACK_ALIGNMENT: - //case LOCAL_GL_IMPLEMENTATION_COLOR_READ_TYPE: - //case LOCAL_GL_IMPLEMENTATION_COLOR_READ_FORMAT: + case LOCAL_GL_IMPLEMENTATION_COLOR_READ_TYPE: + case LOCAL_GL_IMPLEMENTATION_COLOR_READ_FORMAT: { GLint i = 0; gl->fGetIntegerv(pname, &i); @@ -1284,9 +1305,38 @@ WebGLContext::GetParameter(PRUint32 pname, nsIVariant **retval) } break; + #define LOCAL_GL_MAX_VARYING_VECTORS 0x8dfc // not present in desktop OpenGL + // temporarily add those defs here, as they're missing from + // gfx/thebes/public/GLDefs.h + // and from + // gfx/layers/opengl/glDefs.h + // and I don't know in which of these 2 files they should go (probably we're going to + // kill one of them soon?) + #define LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 + #define LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 + case LOCAL_GL_MAX_VARYING_VECTORS: + { + #ifdef USE_GLES2 + GLint i = 0; + gl->fGetIntegerv(pname, &i); + wrval->SetAsInt32(i); + #else + // since this pname is absent from desktop OpenGL, we have to implement it by hand. + // The formula below comes from the public_webgl list, "problematic GetParameter pnames" thread + GLint i = 0, j = 0; + gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS, &i); + gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS, &j); + wrval->SetAsInt32(PR_MIN(i,j)/4); + #endif + } + break; + case LOCAL_GL_NUM_COMPRESSED_TEXTURE_FORMATS: wrval->SetAsInt32(0); break; + case LOCAL_GL_COMPRESSED_TEXTURE_FORMATS: + wrval->SetAsVoid(); // the spec says we must return null + break; // unsigned int. here we may have to return very large values like 2^32-1 that can't be represented as // javascript integer values. We just return them as doubles and javascript doesn't care. @@ -1332,6 +1382,14 @@ WebGLContext::GetParameter(PRUint32 pname, nsIVariant **retval) } break; +// bool, WebGL-specific + case UNPACK_FLIP_Y_WEBGL: + wrval->SetAsBool(mPixelStoreFlipY); + break; + case UNPACK_PREMULTIPLY_ALPHA_WEBGL: + wrval->SetAsBool(mPixelStorePremultiplyAlpha); + break; + // // Complex values // @@ -1795,13 +1853,8 @@ WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, nsIVariant **re MakeContextCurrent(); - switch (target) { - case LOCAL_GL_TEXTURE_2D: - case LOCAL_GL_TEXTURE_CUBE_MAP: - break; - default: - return ErrorInvalidEnum("GetTexParameter: invalid target"); - } + if (!ValidateTextureTargetEnum(target, "getTexParameter: target")) + return NS_OK; switch (pname) { case LOCAL_GL_TEXTURE_MIN_FILTER: @@ -1816,7 +1869,7 @@ WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, nsIVariant **re break; default: - return ErrorInvalidEnum("GetTexParameter: invalid parameter"); + return ErrorInvalidEnum("getTexParameter: invalid parameter"); } *retval = wrval.forget().get(); @@ -2054,9 +2107,9 @@ WebGLContext::IsTexture(nsIWebGLTexture *tobj, WebGLboolean *retval) NS_IMETHODIMP WebGLContext::IsEnabled(WebGLenum cap, WebGLboolean *retval) { - if(!ValidateCapabilityEnum(cap)) { + if (!ValidateCapabilityEnum(cap, "isEnabled")) { *retval = 0; // as per the OpenGL ES spec - return ErrorInvalidEnum("IsEnabled: invalid capability enum"); + return NS_OK; } MakeContextCurrent(); @@ -2344,19 +2397,79 @@ WebGLContext::RenderbufferStorage(WebGLenum target, WebGLenum internalformat, We GL_SAME_METHOD_2(SampleCoverage, SampleCoverage, float, WebGLboolean) -GL_SAME_METHOD_4(Scissor, Scissor, WebGLint, WebGLint, WebGLsizei, WebGLsizei) +NS_IMETHODIMP +WebGLContext::Scissor(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height) +{ + if (width < 0 || height < 0) + return ErrorInvalidValue("Scissor: negative size"); -GL_SAME_METHOD_3(StencilFunc, StencilFunc, WebGLenum, WebGLint, WebGLuint) + MakeContextCurrent(); + gl->fScissor(x, y, width, height); + return NS_OK; +} -GL_SAME_METHOD_4(StencilFuncSeparate, StencilFuncSeparate, WebGLenum, WebGLenum, WebGLint, WebGLuint) +NS_IMETHODIMP +WebGLContext::StencilFunc(WebGLenum func, WebGLint ref, WebGLuint mask) +{ + if (!ValidateComparisonEnum(func, "stencilFunc: func")) + return NS_OK; + + MakeContextCurrent(); + gl->fStencilFunc(func, ref, mask); + return NS_OK; +} + +NS_IMETHODIMP +WebGLContext::StencilFuncSeparate(WebGLenum face, WebGLenum func, WebGLint ref, WebGLuint mask) +{ + if (!ValidateFaceEnum(face, "stencilFuncSeparate: face") || + !ValidateComparisonEnum(func, "stencilFuncSeparate: func")) + return NS_OK; + + MakeContextCurrent(); + gl->fStencilFuncSeparate(face, func, ref, mask); + return NS_OK; +} GL_SAME_METHOD_1(StencilMask, StencilMask, WebGLuint) -GL_SAME_METHOD_2(StencilMaskSeparate, StencilMaskSeparate, WebGLenum, WebGLuint) +NS_IMETHODIMP +WebGLContext::StencilMaskSeparate(WebGLenum face, WebGLuint mask) +{ + if (!ValidateFaceEnum(face, "stencilMaskSeparate: face")) + return NS_OK; -GL_SAME_METHOD_3(StencilOp, StencilOp, WebGLenum, WebGLenum, WebGLenum) + MakeContextCurrent(); + gl->fStencilMaskSeparate(face, mask); + return NS_OK; +} -GL_SAME_METHOD_4(StencilOpSeparate, StencilOpSeparate, WebGLenum, WebGLenum, WebGLenum, WebGLenum) +NS_IMETHODIMP +WebGLContext::StencilOp(WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass) +{ + if (!ValidateStencilOpEnum(sfail, "stencilOp: sfail") || + !ValidateStencilOpEnum(dpfail, "stencilOp: dpfail") || + !ValidateStencilOpEnum(dppass, "stencilOp: dppass")) + return NS_OK; + + MakeContextCurrent(); + gl->fStencilOp(sfail, dpfail, dppass); + return NS_OK; +} + +NS_IMETHODIMP +WebGLContext::StencilOpSeparate(WebGLenum face, WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass) +{ + if (!ValidateFaceEnum(face, "stencilOpSeparate: face") || + !ValidateStencilOpEnum(sfail, "stencilOpSeparate: sfail") || + !ValidateStencilOpEnum(dpfail, "stencilOpSeparate: dpfail") || + !ValidateStencilOpEnum(dppass, "stencilOpSeparate: dppass")) + return NS_OK; + + MakeContextCurrent(); + gl->fStencilOpSeparate(face, sfail, dpfail, dppass); + return NS_OK; +} template inline void convert_pixel(PRUint8* dst, const PRUint8* src) @@ -2660,7 +2773,16 @@ WebGLContext::CreateRenderbuffer(nsIWebGLRenderbuffer **retval) return NS_OK; } -GL_SAME_METHOD_4(Viewport, Viewport, PRInt32, PRInt32, PRInt32, PRInt32) +NS_IMETHODIMP +WebGLContext::Viewport(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height) +{ + if (width < 0 || height < 0) + return ErrorInvalidOperation("Viewport: negative size"); + + MakeContextCurrent(); + gl->fViewport(x, y, width, height); + return NS_OK; +} NS_IMETHODIMP WebGLContext::CompileShader(nsIWebGLShader *sobj) @@ -2886,7 +3008,7 @@ WebGLContext::TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum intern case LOCAL_GL_LUMINANCE_ALPHA: break; default: - return ErrorInvalidValue("TexImage2D: internal format not supported"); + return ErrorInvalidEnum("TexImage2D: invalid internal format"); } if (width < 0 || height < 0) @@ -2895,53 +3017,12 @@ WebGLContext::TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum intern if (border != 0) return ErrorInvalidValue("TexImage2D: border must be 0"); - // number of bytes per pixel - uint32 bufferPixelSize = 0; - switch (format) { - case LOCAL_GL_RED: - case LOCAL_GL_GREEN: - case LOCAL_GL_BLUE: - case LOCAL_GL_ALPHA: - case LOCAL_GL_LUMINANCE: - bufferPixelSize = 1; - break; - case LOCAL_GL_LUMINANCE_ALPHA: - bufferPixelSize = 2; - break; - case LOCAL_GL_RGB: - bufferPixelSize = 3; - break; - case LOCAL_GL_RGBA: - bufferPixelSize = 4; - break; - default: - return ErrorInvalidEnum("TexImage2D: pixel format not supported"); - } - - switch (type) { - case LOCAL_GL_BYTE: - case LOCAL_GL_UNSIGNED_BYTE: - break; - case LOCAL_GL_SHORT: - case LOCAL_GL_UNSIGNED_SHORT: - bufferPixelSize *= 2; - break; - case LOCAL_GL_INT: - case LOCAL_GL_UNSIGNED_INT: - case LOCAL_GL_FLOAT: - bufferPixelSize *= 4; - break; - case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4: - case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1: - case LOCAL_GL_UNSIGNED_SHORT_5_6_5: - bufferPixelSize *= 2; - break; - default: - return ErrorInvalidEnum("TexImage2D: invalid type argument"); - } + PRUint32 texelSize = 0; + if (!ValidateTexFormatAndType(format, type, &texelSize, "texImage2D")) + return NS_OK; // XXX overflow! - uint32 bytesNeeded = width * height * bufferPixelSize; + uint32 bytesNeeded = width * height * texelSize; if (byteLength && byteLength < bytesNeeded) return ErrorInvalidValue("TexImage2D: not enough data for operation (need %d, have %d)", @@ -3066,56 +3147,15 @@ WebGLContext::TexSubImage2D_base(WebGLenum target, WebGLint level, if (width < 0 || height < 0) return ErrorInvalidValue("TexSubImage2D: width and height must be > 0!"); + PRUint32 texelSize = 0; + if (!ValidateTexFormatAndType(format, type, &texelSize, "texSubImage2D")) + return NS_OK; + if (width == 0 || height == 0) return NS_OK; // ES 2.0 says it has no effect, we better return right now - // number of bytes per pixel - uint32 bufferPixelSize = 0; - switch (format) { - case LOCAL_GL_RED: - case LOCAL_GL_GREEN: - case LOCAL_GL_BLUE: - case LOCAL_GL_ALPHA: - case LOCAL_GL_LUMINANCE: - bufferPixelSize = 1; - break; - case LOCAL_GL_LUMINANCE_ALPHA: - bufferPixelSize = 2; - break; - case LOCAL_GL_RGB: - bufferPixelSize = 3; - break; - case LOCAL_GL_RGBA: - bufferPixelSize = 4; - break; - default: - return ErrorInvalidEnum("TexImage2D: pixel format not supported"); - } - - switch (type) { - case LOCAL_GL_BYTE: - case LOCAL_GL_UNSIGNED_BYTE: - break; - case LOCAL_GL_SHORT: - case LOCAL_GL_UNSIGNED_SHORT: - bufferPixelSize *= 2; - break; - case LOCAL_GL_INT: - case LOCAL_GL_UNSIGNED_INT: - case LOCAL_GL_FLOAT: - bufferPixelSize *= 4; - break; - case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4: - case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1: - case LOCAL_GL_UNSIGNED_SHORT_5_6_5: - bufferPixelSize *= 2; - break; - default: - return ErrorInvalidEnum("TexImage2D: invalid type argument"); - } - // XXX overflow! - uint32 bytesNeeded = width * height * bufferPixelSize; + uint32 bytesNeeded = width * height * texelSize; if (byteLength < bytesNeeded) return ErrorInvalidValue("TexSubImage2D: not enough data for operation (need %d, have %d)", bytesNeeded, byteLength); diff --git a/content/canvas/src/WebGLContextValidate.cpp b/content/canvas/src/WebGLContextValidate.cpp index 8ded807b5b8..9ea42705323 100644 --- a/content/canvas/src/WebGLContextValidate.cpp +++ b/content/canvas/src/WebGLContextValidate.cpp @@ -125,7 +125,7 @@ WebGLContext::ValidateBuffers(PRUint32 count) return PR_TRUE; } -PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap) +PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap, const char *info) { switch (cap) { case LOCAL_GL_BLEND: @@ -139,11 +139,12 @@ PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap) case LOCAL_GL_STENCIL_TEST: return PR_TRUE; default: + ErrorInvalidEnumInfo(info); return PR_FALSE; } } -PRBool WebGLContext::ValidateBlendEquationEnum(WebGLenum mode) +PRBool WebGLContext::ValidateBlendEquationEnum(WebGLenum mode, const char *info) { switch (mode) { case LOCAL_GL_FUNC_ADD: @@ -151,11 +152,12 @@ PRBool WebGLContext::ValidateBlendEquationEnum(WebGLenum mode) case LOCAL_GL_FUNC_REVERSE_SUBTRACT: return PR_TRUE; default: + ErrorInvalidEnumInfo(info); return PR_FALSE; } } -PRBool WebGLContext::ValidateBlendFuncDstEnum(WebGLenum factor) +PRBool WebGLContext::ValidateBlendFuncDstEnum(WebGLenum factor, const char *info) { switch (factor) { case LOCAL_GL_ZERO: @@ -174,16 +176,130 @@ PRBool WebGLContext::ValidateBlendFuncDstEnum(WebGLenum factor) case LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA: return PR_TRUE; default: + ErrorInvalidEnumInfo(info); return PR_FALSE; } } -PRBool WebGLContext::ValidateBlendFuncSrcEnum(WebGLenum factor) +PRBool WebGLContext::ValidateBlendFuncSrcEnum(WebGLenum factor, const char *info) { - if(factor == LOCAL_GL_SRC_ALPHA_SATURATE) + if (factor == LOCAL_GL_SRC_ALPHA_SATURATE) return PR_TRUE; else - return ValidateBlendFuncDstEnum(factor); + return ValidateBlendFuncDstEnum(factor, info); +} + +PRBool WebGLContext::ValidateTextureTargetEnum(WebGLenum target, const char *info) +{ + switch (target) { + case LOCAL_GL_TEXTURE_2D: + case LOCAL_GL_TEXTURE_CUBE_MAP: + return PR_TRUE; + default: + ErrorInvalidEnumInfo(info); + return PR_FALSE; + } +} + +PRBool WebGLContext::ValidateComparisonEnum(WebGLenum target, const char *info) +{ + switch (target) { + case LOCAL_GL_NEVER: + case LOCAL_GL_LESS: + case LOCAL_GL_LEQUAL: + case LOCAL_GL_GREATER: + case LOCAL_GL_GEQUAL: + case LOCAL_GL_EQUAL: + case LOCAL_GL_NOTEQUAL: + case LOCAL_GL_ALWAYS: + return PR_TRUE; + default: + ErrorInvalidEnumInfo(info); + return PR_FALSE; + } +} + +PRBool WebGLContext::ValidateStencilOpEnum(WebGLenum action, const char *info) +{ + switch (action) { + case LOCAL_GL_KEEP: + case LOCAL_GL_ZERO: + case LOCAL_GL_REPLACE: + case LOCAL_GL_INCR: + case LOCAL_GL_INCR_WRAP: + case LOCAL_GL_DECR: + case LOCAL_GL_DECR_WRAP: + case LOCAL_GL_INVERT: + return PR_TRUE; + default: + ErrorInvalidEnumInfo(info); + return PR_FALSE; + } +} + +PRBool WebGLContext::ValidateFaceEnum(WebGLenum target, const char *info) +{ + switch (target) { + case LOCAL_GL_FRONT: + case LOCAL_GL_BACK: + case LOCAL_GL_FRONT_AND_BACK: + return PR_TRUE; + default: + ErrorInvalidEnumInfo(info); + return PR_FALSE; + } +} + +PRBool WebGLContext::ValidateTexFormatAndType(WebGLenum format, WebGLenum type, + PRUint32 *texelSize, const char *info) +{ + if (type == LOCAL_GL_UNSIGNED_BYTE) + { + switch (format) { + case LOCAL_GL_RED: + case LOCAL_GL_GREEN: + case LOCAL_GL_BLUE: + case LOCAL_GL_ALPHA: + case LOCAL_GL_LUMINANCE: + *texelSize = 1; + return PR_TRUE; + case LOCAL_GL_LUMINANCE_ALPHA: + *texelSize = 2; + return PR_TRUE; + case LOCAL_GL_RGB: + *texelSize = 3; + return PR_TRUE; + case LOCAL_GL_RGBA: + *texelSize = 4; + return PR_TRUE; + default: + ErrorInvalidEnum("%s: invalid format", info); + return PR_FALSE; + } + } else { + switch (type) { + case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4: + case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1: + if (format == LOCAL_GL_RGBA) { + *texelSize = 2; + return PR_TRUE; + } else { + ErrorInvalidOperation("%s: mutually incompatible format and type", info); + return PR_FALSE; + } + case LOCAL_GL_UNSIGNED_SHORT_5_6_5: + if (format == LOCAL_GL_RGB) { + *texelSize = 2; + return PR_TRUE; + } else { + ErrorInvalidOperation("%s: mutually incompatible format and type", info); + return PR_FALSE; + } + default: + ErrorInvalidEnum("%s: invalid type", info); + return PR_FALSE; + } + } } PRBool diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 944e57167e1..b4ed4a65a8b 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -757,7 +757,9 @@ nsCanvasRenderingContext2D::~nsCanvasRenderingContext2D() void nsCanvasRenderingContext2D::Destroy() { - if (mValid) + // only do this for non-docshell created contexts, + // since those are the ones that we created a surface for + if (mValid && !mDocShell) gCanvasMemoryUsed -= mWidth * mHeight * 4; mSurface = nsnull; diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index f5f9992444b..11288418c0d 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -58,9 +58,10 @@ static const char* const sEventNames[] = { "mousedown", "mouseup", "click", "dblclick", "mouseover", - "mouseout", "mousemove", "contextmenu", "keydown", "keyup", "keypress", - "focus", "blur", "load", "popstate", "beforeunload", "unload", "hashchange", - "abort", "error", "submit", "reset", "change", "select", "input", "text", + "mouseout", "MozMouseHittest", "mousemove", "contextmenu", "keydown", "keyup", "keypress", + "focus", "blur", "load", "popstate", "beforeunload", "unload", + "hashchange", "readystatechange", "abort", "error", + "submit", "reset", "change", "select", "input", "text", "compositionstart", "compositionend", "popupshowing", "popupshown", "popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate", "dragenter", "dragover", "dragexit", "dragdrop", "draggesture", @@ -1072,6 +1073,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return sEventNames[eDOMEvents_mouseover]; case NS_MOUSE_EXIT_SYNTH: return sEventNames[eDOMEvents_mouseout]; + case NS_MOUSE_MOZHITTEST: + return sEventNames[eDOMEvents_MozMouseHittest]; case NS_MOUSE_MOVE: return sEventNames[eDOMEvents_mousemove]; case NS_KEY_UP: @@ -1100,6 +1103,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return sEventNames[eDOMEvents_unload]; case NS_HASHCHANGE: return sEventNames[eDOMEvents_hashchange]; + case NS_READYSTATECHANGE: + return sEventNames[eDOMEvents_readystatechange]; case NS_IMAGE_ABORT: return sEventNames[eDOMEvents_abort]; case NS_LOAD_ERROR: diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 4f1a03b48ab..81ba04ec099 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -67,6 +67,7 @@ public: eDOMEvents_dblclick, eDOMEvents_mouseover, eDOMEvents_mouseout, + eDOMEvents_MozMouseHittest, eDOMEvents_mousemove, eDOMEvents_contextmenu, eDOMEvents_keydown, @@ -79,6 +80,7 @@ public: eDOMEvents_beforeunload, eDOMEvents_unload, eDOMEvents_hashchange, + eDOMEvents_readystatechange, eDOMEvents_abort, eDOMEvents_error, eDOMEvents_submit, diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index c5078cc96b8..2bda542431f 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1879,14 +1879,6 @@ nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent) // If we're in the TRACKING state of the d&d gesture tracker, check the current position // of the mouse in relation to the old one. If we've moved a sufficient amount from // the mouse down, then fire off a drag gesture event. -// -// Note that when the mouse enters a new child window with its own view, the event's -// coordinates will be in relation to the origin of the inner child window, which could -// either be very different from that of the mouse coords of the mouse down and trigger -// a drag too early, or very similar which might not trigger a drag. -// -// Do we need to do anything about this? Let's wait and see. -// void nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext, nsMouseEvent *aEvent) @@ -3107,6 +3099,10 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext, nsMouseEvent* mouseEvent = static_cast(aEvent); event.refPoint = mouseEvent->refPoint; + if (mouseEvent->widget) { + event.refPoint += mouseEvent->widget->WidgetToScreenOffset(); + } + event.refPoint -= widget->WidgetToScreenOffset(); event.isShift = mouseEvent->isShift; event.isControl = mouseEvent->isControl; event.isAlt = mouseEvent->isAlt; diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 01b13d99101..ca565fc6dad 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -655,13 +655,11 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML) { aInnerHTML.Truncate(); - nsCOMPtr doc = GetOwnerDoc(); + nsIDocument* doc = GetOwnerDoc(); if (!doc) { return NS_OK; // We rely on the document for doing HTML conversion } - nsCOMPtr thisNode(do_QueryInterface(static_cast - (this))); nsresult rv = NS_OK; nsAutoString contentType; @@ -670,13 +668,15 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML) } else { doc->GetContentType(contentType); } - - nsCOMPtr docEncoder; - docEncoder = - do_CreateInstance(PromiseFlatCString( + + nsCOMPtr docEncoder = doc->GetCachedEncoder(); + if (!docEncoder) { + docEncoder = + do_CreateInstance(PromiseFlatCString( nsDependentCString(NS_DOC_ENCODER_CONTRACTID_BASE) + NS_ConvertUTF16toUTF8(contentType) ).get()); + } if (!(docEncoder || doc->IsHTML())) { // This could be some type for which we create a synthetic document. Try // again as XML @@ -686,17 +686,19 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML) NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE); - nsCOMPtr domDoc = do_QueryInterface(doc); - rv = docEncoder->Init(domDoc, contentType, - nsIDocumentEncoder::OutputEncodeBasicEntities | - // Output DOM-standard newlines - nsIDocumentEncoder::OutputLFLineBreak | - // Don't do linebreaking that's not present in the source - nsIDocumentEncoder::OutputRaw); + rv = docEncoder->NativeInit(doc, contentType, + nsIDocumentEncoder::OutputEncodeBasicEntities | + // Output DOM-standard newlines + nsIDocumentEncoder::OutputLFLineBreak | + // Don't do linebreaking that's not present in + // the source + nsIDocumentEncoder::OutputRaw); NS_ENSURE_SUCCESS(rv, rv); - docEncoder->SetContainerNode(thisNode); - return docEncoder->EncodeToString(aInnerHTML); + docEncoder->SetNativeContainerNode(this); + rv = docEncoder->EncodeToString(aInnerHTML); + doc->SetCachedEncoder(docEncoder); + return rv; } nsresult diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 708ebe4aa11..b8c57cf0db2 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -1316,7 +1316,16 @@ NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, \ return NS_NewHTMLSharedElement(aNodeInfo, aFromParser); \ } +// Disable MSVC warning that spams when we pass empty string as only macro arg. +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4003) +#endif NS_DECLARE_NS_NEW_HTML_ELEMENT() // HTMLElement +#ifdef _MSC_VER +#pragma warning(pop) +#endif + NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared) NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList) NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedObject) diff --git a/content/html/content/src/nsHTMLElement.cpp b/content/html/content/src/nsHTMLElement.cpp index 57af269f225..c612e28c2db 100644 --- a/content/html/content/src/nsHTMLElement.cpp +++ b/content/html/content/src/nsHTMLElement.cpp @@ -61,7 +61,15 @@ public: nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const; }; +// Disable MSVC warning that spams when we pass empty string as only macro arg. +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4003) +#endif NS_IMPL_NS_NEW_HTML_ELEMENT() // HTMLElement +#ifdef _MSC_VER +#pragma warning(pop) +#endif nsHTMLElement::nsHTMLElement(nsINodeInfo* aNodeInfo) : nsGenericHTMLElement(aNodeInfo) diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index 3fe0a7da7b8..3807085ce0b 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -960,7 +960,7 @@ nsHTMLTextAreaElement::ContentAppended(nsIDocument* aDocument, nsIContent* aFirstNewContent, PRInt32 /* unused */) { - ContentChanged(aContainer); + ContentChanged(aFirstNewContent); } void diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp index b1a81b0aed3..2ddc001b0b1 100644 --- a/content/html/content/src/nsTextEditorState.cpp +++ b/content/html/content/src/nsTextEditorState.cpp @@ -1726,8 +1726,14 @@ nsTextEditorState::SetValue(const nsAString& aValue, PRBool aUserInput) plaintextEditor->InsertText(insertValue); } if (!weakFrame.IsAlive()) { - NS_ASSERTION(!mBoundFrame, "The frame should have been unbounded"); - SetValue(newValue, PR_FALSE); + // If the frame was destroyed because of a flush somewhere inside + // InsertText, mBoundFrame here will be false. But it's also possible + // for the frame to go away because of another reason (such as deleting + // the existing selection -- see bug 574558), in which case we don't + // need to reset the value here. + if (!mBoundFrame) { + SetValue(newValue, PR_FALSE); + } valueSetter.Cancel(); return; } diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index d2a363f4d84..4e203af7eb9 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -342,7 +342,7 @@ nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup, // Make the content type default to "text/html", we are a HTML // document, after all. Once we start getting data, this may be // changed. - mContentType = "text/html"; + SetContentTypeInternal(nsDependentCString("text/html")); } nsStyleSet::sheetType @@ -1592,16 +1592,8 @@ nsHTMLDocument::GetBody(nsresult *aResult) // The document is most likely a frameset document so look for the // outer most frameset element - nsRefPtr nodeList; - - if (IsHTML()) { - nodeList = nsDocument::GetElementsByTagName(NS_LITERAL_STRING("frameset")); - } else { - nodeList = - nsDocument::GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"), - NS_LITERAL_STRING("frameset")); - } - + nsRefPtr nodeList = + NS_GetContentList(this, nsGkAtoms::frameset, kNameSpaceID_XHTML); if (!nodeList) { *aResult = NS_ERROR_OUT_OF_MEMORY; @@ -2035,7 +2027,7 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) } // This will be propagated to the parser when someone actually calls write() - mContentType = aContentType; + SetContentTypeInternal(aContentType); mWriteState = eDocumentOpened; @@ -2134,7 +2126,7 @@ nsHTMLDocument::Close() ++mWriteLevel; rv = mParser->Parse(EmptyString(), mParser->GetRootContextKey(), - mContentType, PR_TRUE); + GetContentTypeInternal(), PR_TRUE); --mWriteLevel; // XXX Make sure that all the document.written content is @@ -2234,11 +2226,11 @@ nsHTMLDocument::WriteCommon(const nsAString& aText, // why pay that price when we don't need to? if (aNewlineTerminate) { rv = mParser->Parse(aText + new_line, - key, mContentType, + key, GetContentTypeInternal(), (mWriteState == eNotWriting || (mWriteLevel > 1))); } else { rv = mParser->Parse(aText, - key, mContentType, + key, GetContentTypeInternal(), (mWriteState == eNotWriting || (mWriteLevel > 1))); } diff --git a/content/html/document/test/Makefile.in b/content/html/document/test/Makefile.in index 84ac72ee1a6..c2047461268 100644 --- a/content/html/document/test/Makefile.in +++ b/content/html/document/test/Makefile.in @@ -65,7 +65,6 @@ _TEST_FILES = test_bug1682.html \ test_bug369370.html \ bug369370-popup.png \ test_bug380383.html \ - test_bug386495.html \ test_bug391777.html \ test_bug402680.html \ test_bug403868.html \ @@ -103,6 +102,7 @@ _TEST_FILES = test_bug1682.html \ test_bug499092.html \ bug499092.xml \ bug499092.html \ + test_bug571981.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/html/document/test/test_bug386495.html b/content/html/document/test/test_bug386495.html deleted file mode 100644 index a700c9322f8..00000000000 --- a/content/html/document/test/test_bug386495.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - Test for Bug 386495 - - - - - -Mozilla Bug 386495 -

-
- -
-
-
-
- - diff --git a/content/html/document/test/test_bug571981.html b/content/html/document/test/test_bug571981.html new file mode 100644 index 00000000000..e354664cfc7 --- /dev/null +++ b/content/html/document/test/test_bug571981.html @@ -0,0 +1,59 @@ + + + + + Test for Bug 571981 + + + + + +Mozilla Bug 571981 +

+ +
+
+
+ + diff --git a/content/xul/content/crashtests/467869-1.xul b/content/xul/content/crashtests/467869-1.xul new file mode 100644 index 00000000000..6518cfab1a8 --- /dev/null +++ b/content/xul/content/crashtests/467869-1.xul @@ -0,0 +1,28 @@ + + + + + + + diff --git a/content/xul/content/crashtests/crashtests.list b/content/xul/content/crashtests/crashtests.list index 30916fcd7e9..421dfefaa2e 100644 --- a/content/xul/content/crashtests/crashtests.list +++ b/content/xul/content/crashtests/crashtests.list @@ -21,3 +21,4 @@ load 429085-1.xhtml load 431906-1.html load 451311-1.xul load 461917-1.xhtml +load 467869-1.xul diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index c04f3648664..647b860c66f 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -727,7 +727,7 @@ nsXULDocument::SynchronizeBroadcastListener(nsIDOMElement *aBroadcaster, } nsCOMPtr broadcaster = do_QueryInterface(aBroadcaster); nsCOMPtr listener = do_QueryInterface(aListener); - PRBool notify = mInitialLayoutComplete || mHandlingDelayedBroadcasters; + PRBool notify = mDocumentLoaded || mHandlingDelayedBroadcasters; // We may be copying event handlers etc, so we must also copy // the script-type to the listener. diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 7391ee95908..511d6680d73 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -11166,3 +11166,97 @@ nsDocShell::GetPrintPreview(nsIWebBrowserPrint** aPrintPreview) #ifdef DEBUG unsigned long nsDocShell::gNumberOfDocShells = 0; #endif + +NS_IMETHODIMP +nsDocShell::GetCanExecuteScripts(PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = PR_FALSE; // disallow by default + + nsCOMPtr docshell = this; + nsCOMPtr globalObjTreeItem = + do_QueryInterface(docshell); + + if (globalObjTreeItem) + { + nsCOMPtr treeItem(globalObjTreeItem); + nsCOMPtr parentItem; + PRBool firstPass = PR_TRUE; + PRBool lookForParents = PR_FALSE; + + // Walk up the docshell tree to see if any containing docshell disallows scripts + do + { + nsresult rv = docshell->GetAllowJavascript(aResult); + if (NS_FAILED(rv)) return rv; + if (!*aResult) { + nsDocShell* realDocshell = static_cast(docshell.get()); + if (realDocshell->mContentViewer) { + nsIDocument* doc = realDocshell->mContentViewer->GetDocument(); + if (doc && doc->HasFlag(NODE_IS_EDITABLE) && + realDocshell->mEditorData) { + nsCOMPtr editSession; + realDocshell->mEditorData->GetEditingSession(getter_AddRefs(editSession)); + PRBool jsDisabled = PR_FALSE; + if (editSession && + NS_SUCCEEDED(rv = editSession->GetJsAndPluginsDisabled(&jsDisabled))) { + if (firstPass) { + if (jsDisabled) { + // We have a docshell which has been explicitly set + // to design mode, so we disallow scripts. + return NS_OK; + } + // The docshell was not explicitly set to design mode, + // so it must be so because a parent was explicitly + // set to design mode. We don't need to look at higher + // docshells. + *aResult = PR_TRUE; + break; + } else if (lookForParents && jsDisabled) { + // If a parent was explicitly set to design mode, + // we should allow script execution on the child. + *aResult = PR_TRUE; + break; + } + // If the child docshell allows scripting, and the + // parent is inside design mode, we don't need to look + // further. + *aResult = PR_TRUE; + return NS_OK; + } + NS_WARNING("The editing session does not work?"); + return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE; + } + if (firstPass) { + // Don't be too hard on docshells on the first pass. + // There may be a parent docshell which has been set + // to design mode, so look for it. + lookForParents = PR_TRUE; + } else { + // We have a docshell which disallows scripts + // and is not editable, so we shouldn't allow + // scripts at all. + return NS_OK; + } + } + } else if (lookForParents) { + // The parent docshell was not explicitly set to design + // mode, so js on the child docshell was disabled for + // another reason. Therefore, we need to disable js. + return NS_OK; + } + firstPass = PR_FALSE; + + treeItem->GetParent(getter_AddRefs(parentItem)); + treeItem.swap(parentItem); + docshell = do_QueryInterface(treeItem); +#ifdef DEBUG + if (treeItem && !docshell) { + NS_ERROR("cannot get a docshell from a treeItem!"); + } +#endif // DEBUG + } while (treeItem && docshell); + } + + return NS_OK; +} diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 26c82da554c..ab652596c46 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -71,7 +71,7 @@ interface nsIPrincipal; interface nsIWebBrowserPrint; interface nsIVariant; -[scriptable, uuid(3adde256-05a9-43a7-a190-f8fe75eecfd6)] +[scriptable, uuid(8ac6b880-776a-44d4-b271-a7e64ae3debd)] interface nsIDocShell : nsISupports { /** @@ -511,4 +511,14 @@ interface nsIDocShell : nsISupports * is loaded. */ readonly attribute nsIWebBrowserPrint printPreview; + + /** + * Whether this docshell can execute scripts based on its hierarchy. + * The rule of thumb here is that we disable js if this docshell or any + * of its parents disallow scripting, unless the only reason for js being + * disabled in this docshell is a parent docshell having a document that + * is in design mode. In that case, we explicitly allow scripting on the + * current docshell. + */ + readonly attribute boolean canExecuteScripts; }; diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index c49c67f24e3..d2425ea5b7a 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -479,15 +479,15 @@ using namespace mozilla::dom; -#include "mozilla/dom/indexedDB/IndexedDatabaseRequest.h" +#include "mozilla/dom/indexedDB/IDBFactory.h" #include "mozilla/dom/indexedDB/IDBRequest.h" -#include "mozilla/dom/indexedDB/IDBDatabaseRequest.h" +#include "mozilla/dom/indexedDB/IDBDatabase.h" #include "mozilla/dom/indexedDB/IDBEvents.h" -#include "mozilla/dom/indexedDB/IDBObjectStoreRequest.h" -#include "mozilla/dom/indexedDB/IDBTransactionRequest.h" -#include "mozilla/dom/indexedDB/IDBCursorRequest.h" +#include "mozilla/dom/indexedDB/IDBObjectStore.h" +#include "mozilla/dom/indexedDB/IDBTransaction.h" +#include "mozilla/dom/indexedDB/IDBCursor.h" #include "mozilla/dom/indexedDB/IDBKeyRange.h" -#include "mozilla/dom/indexedDB/IDBIndexRequest.h" +#include "mozilla/dom/indexedDB/IDBIndex.h" static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); @@ -1418,11 +1418,11 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CloseEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(IndexedDatabaseRequest, nsDOMGenericSH, + NS_DEFINE_CLASSINFO_DATA(IDBFactory, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(IDBRequest, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(IDBDatabaseRequest, nsDOMGenericSH, + NS_DEFINE_CLASSINFO_DATA(IDBDatabase, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(IDBErrorEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1430,15 +1430,15 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(IDBTransactionEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(IDBObjectStoreRequest, nsDOMGenericSH, + NS_DEFINE_CLASSINFO_DATA(IDBObjectStore, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(IDBTransactionRequest, nsDOMGenericSH, + NS_DEFINE_CLASSINFO_DATA(IDBTransaction, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(IDBCursorRequest, nsDOMGenericSH, + NS_DEFINE_CLASSINFO_DATA(IDBCursor, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(IDBKeyRange, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(IDBIndexRequest, nsDOMGenericSH, + NS_DEFINE_CLASSINFO_DATA(IDBIndex, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) }; @@ -1532,6 +1532,7 @@ jsval nsDOMClassInfo::sOnpopstate_id = JSVAL_VOID; jsval nsDOMClassInfo::sOnbeforeunload_id = JSVAL_VOID; jsval nsDOMClassInfo::sOnunload_id = JSVAL_VOID; jsval nsDOMClassInfo::sOnhashchange_id = JSVAL_VOID; +jsval nsDOMClassInfo::sOnreadystatechange_id = JSVAL_VOID; jsval nsDOMClassInfo::sOnpageshow_id = JSVAL_VOID; jsval nsDOMClassInfo::sOnpagehide_id = JSVAL_VOID; jsval nsDOMClassInfo::sOnabort_id = JSVAL_VOID; @@ -1733,6 +1734,7 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx) SET_JSVAL_TO_STRING(sOnbeforeunload_id, cx, "onbeforeunload"); SET_JSVAL_TO_STRING(sOnunload_id, cx, "onunload"); SET_JSVAL_TO_STRING(sOnhashchange_id, cx, "onhashchange"); + SET_JSVAL_TO_STRING(sOnreadystatechange_id, cx, "onreadystatechange"); SET_JSVAL_TO_STRING(sOnpageshow_id, cx, "onpageshow"); SET_JSVAL_TO_STRING(sOnpagehide_id, cx, "onpagehide"); SET_JSVAL_TO_STRING(sOnabort_id, cx, "onabort"); @@ -3921,8 +3923,8 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_EVENT_MAP_ENTRIES DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(IndexedDatabaseRequest, nsIIndexedDatabaseRequest) - DOM_CLASSINFO_MAP_ENTRY(nsIIndexedDatabaseRequest) + DOM_CLASSINFO_MAP_BEGIN(IDBFactory, nsIIDBFactory) + DOM_CLASSINFO_MAP_ENTRY(nsIIDBFactory) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(IDBRequest, nsIIDBRequest) @@ -3931,8 +3933,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(IDBDatabaseRequest, nsIIDBDatabaseRequest) - DOM_CLASSINFO_MAP_ENTRY(nsIIDBDatabaseRequest) + DOM_CLASSINFO_MAP_BEGIN(IDBDatabase, nsIIDBDatabase) DOM_CLASSINFO_MAP_ENTRY(nsIIDBDatabase) DOM_CLASSINFO_MAP_END @@ -3955,20 +3956,17 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(IDBObjectStoreRequest, nsIIDBObjectStoreRequest) - DOM_CLASSINFO_MAP_ENTRY(nsIIDBObjectStoreRequest) + DOM_CLASSINFO_MAP_BEGIN(IDBObjectStore, nsIIDBObjectStore) DOM_CLASSINFO_MAP_ENTRY(nsIIDBObjectStore) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(IDBTransactionRequest, nsIIDBTransactionRequest) - DOM_CLASSINFO_MAP_ENTRY(nsIIDBTransactionRequest) + DOM_CLASSINFO_MAP_BEGIN(IDBTransaction, nsIIDBTransaction) DOM_CLASSINFO_MAP_ENTRY(nsIIDBTransaction) DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget) DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(IDBCursorRequest, nsIIDBCursorRequest) - DOM_CLASSINFO_MAP_ENTRY(nsIIDBCursorRequest) + DOM_CLASSINFO_MAP_BEGIN(IDBCursor, nsIIDBCursor) DOM_CLASSINFO_MAP_ENTRY(nsIIDBCursor) DOM_CLASSINFO_MAP_END @@ -3976,8 +3974,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIIDBKeyRange) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(IDBIndexRequest, nsIIDBIndexRequest) - DOM_CLASSINFO_MAP_ENTRY(nsIIDBIndexRequest) + DOM_CLASSINFO_MAP_BEGIN(IDBIndex, nsIIDBIndex) DOM_CLASSINFO_MAP_ENTRY(nsIIDBIndex) DOM_CLASSINFO_MAP_END @@ -4709,6 +4706,7 @@ nsDOMClassInfo::ShutDown() sOnbeforeunload_id = JSVAL_VOID; sOnunload_id = JSVAL_VOID; sOnhashchange_id = JSVAL_VOID; + sOnreadystatechange_id = JSVAL_VOID; sOnpageshow_id = JSVAL_VOID; sOnpagehide_id = JSVAL_VOID; sOnabort_id = JSVAL_VOID; @@ -7646,7 +7644,8 @@ nsEventReceiverSH::ReallyIsEventName(jsval id, jschar aFirstChar) id == sOnmouseup_id || id == sOnmousedown_id); case 'r' : - return (id == sOnreset_id || + return (id == sOnreadystatechange_id || + id == sOnreset_id || id == sOnresize_id); case 's' : return (id == sOnscroll_id || diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 9ae2f9e12c4..8f0a97fe8e3 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -321,6 +321,7 @@ protected: static jsval sOnbeforeunload_id; static jsval sOnunload_id; static jsval sOnhashchange_id; + static jsval sOnreadystatechange_id; static jsval sOnpageshow_id; static jsval sOnpagehide_id; static jsval sOnabort_id; diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index cc1a4aaa77b..5cc1a55af78 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -480,14 +480,14 @@ DOMCI_CLASS(FormData) DOMCI_CLASS(WebSocket) DOMCI_CLASS(CloseEvent) -DOMCI_CLASS(IndexedDatabaseRequest) +DOMCI_CLASS(IDBFactory) DOMCI_CLASS(IDBRequest) -DOMCI_CLASS(IDBDatabaseRequest) +DOMCI_CLASS(IDBDatabase) DOMCI_CLASS(IDBErrorEvent) DOMCI_CLASS(IDBSuccessEvent) DOMCI_CLASS(IDBTransactionEvent) -DOMCI_CLASS(IDBObjectStoreRequest) -DOMCI_CLASS(IDBTransactionRequest) -DOMCI_CLASS(IDBCursorRequest) +DOMCI_CLASS(IDBObjectStore) +DOMCI_CLASS(IDBTransaction) +DOMCI_CLASS(IDBCursor) DOMCI_CLASS(IDBKeyRange) -DOMCI_CLASS(IDBIndexRequest) +DOMCI_CLASS(IDBIndex) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 63f3f8a789e..1f2c5b972c2 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -215,7 +215,7 @@ #endif #include "prlog.h" -#include "mozilla/dom/indexedDB/IndexedDatabaseRequest.h" +#include "mozilla/dom/indexedDB/IDBFactory.h" #ifdef PR_LOGGING static PRLogModuleInfo* gDOMLeakPRLog; @@ -7596,14 +7596,14 @@ nsGlobalWindow::GetLocalStorage(nsIDOMStorage ** aLocalStorage) } NS_IMETHODIMP -nsGlobalWindow::GetMoz_indexedDB(nsIIndexedDatabaseRequest** _retval) +nsGlobalWindow::GetMoz_indexedDB(nsIIDBFactory** _retval) { if (!mIndexedDB) { - mIndexedDB = mozilla::dom::indexedDB::IndexedDatabaseRequest::Create(); + mIndexedDB = mozilla::dom::indexedDB::IDBFactory::Create(); NS_ENSURE_TRUE(mIndexedDB, NS_ERROR_FAILURE); } - nsCOMPtr request(mIndexedDB); + nsCOMPtr request(mIndexedDB); request.forget(_retval); return NS_OK; } diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 37529257d66..eee4a6c0d0d 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -101,7 +101,7 @@ #include "nsPIDOMEventTarget.h" #include "nsIArray.h" #include "nsIContent.h" -#include "nsIIndexedDatabaseRequest.h" +#include "nsIIDBFactory.h" #include "nsFrameMessageManager.h" #define DEFAULT_HOME_PAGE "www.mozilla.org" @@ -830,7 +830,7 @@ protected: nsCOMPtr mSuspendedDoc; - nsCOMPtr mIndexedDB; + nsCOMPtr mIndexedDB; // A unique (as long as our 64-bit counter doesn't roll over) id for // this window. diff --git a/dom/indexedDB/AsyncConnectionHelper.cpp b/dom/indexedDB/AsyncConnectionHelper.cpp index a321edc2ec4..a5ffe30dd4b 100644 --- a/dom/indexedDB/AsyncConnectionHelper.cpp +++ b/dom/indexedDB/AsyncConnectionHelper.cpp @@ -47,7 +47,7 @@ #include "nsThreadUtils.h" #include "IDBEvents.h" -#include "IDBTransactionRequest.h" +#include "IDBTransaction.h" #include "TransactionThreadPool.h" using mozilla::TimeStamp; @@ -67,17 +67,17 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIEVENTTARGET - TransactionPoolEventTarget(IDBTransactionRequest* aTransaction) + TransactionPoolEventTarget(IDBTransaction* aTransaction) : mTransaction(aTransaction) { } private: - IDBTransactionRequest* mTransaction; + IDBTransaction* mTransaction; }; } // anonymous namespace -AsyncConnectionHelper::AsyncConnectionHelper(IDBDatabaseRequest* aDatabase, +AsyncConnectionHelper::AsyncConnectionHelper(IDBDatabase* aDatabase, IDBRequest* aRequest) : mDatabase(aDatabase), mRequest(aRequest), @@ -89,7 +89,7 @@ AsyncConnectionHelper::AsyncConnectionHelper(IDBDatabaseRequest* aDatabase, NS_ASSERTION(mRequest, "Null request!"); } -AsyncConnectionHelper::AsyncConnectionHelper(IDBTransactionRequest* aTransaction, +AsyncConnectionHelper::AsyncConnectionHelper(IDBTransaction* aTransaction, IDBRequest* aRequest) : mDatabase(aTransaction->mDatabase), mTransaction(aTransaction), @@ -109,10 +109,10 @@ AsyncConnectionHelper::~AsyncConnectionHelper() "This should only happen if NOREPLY was returned or if the " "runnable already ran on the main thread!"); - IDBDatabaseRequest* database; + IDBDatabase* database; mDatabase.forget(&database); - IDBTransactionRequest* transaction; + IDBTransaction* transaction; mTransaction.forget(&transaction); IDBRequest* request; diff --git a/dom/indexedDB/AsyncConnectionHelper.h b/dom/indexedDB/AsyncConnectionHelper.h index 584843b5998..248474a87e7 100644 --- a/dom/indexedDB/AsyncConnectionHelper.h +++ b/dom/indexedDB/AsyncConnectionHelper.h @@ -42,7 +42,7 @@ // Only meant to be included in IndexedDB source files, not exported. #include "IndexedDatabase.h" -#include "IDBDatabaseRequest.h" +#include "IDBDatabase.h" #include "IDBRequest.h" #include "mozIStorageProgressHandler.h" @@ -56,7 +56,7 @@ class mozIStorageConnection; BEGIN_INDEXEDDB_NAMESPACE -class IDBTransactionRequest; +class IDBTransaction; /** * Must be subclassed. The subclass must implement DoDatabaseWork. It may then @@ -97,10 +97,10 @@ public: nsresult DispatchToTransactionPool(); protected: - AsyncConnectionHelper(IDBDatabaseRequest* aDatabase, + AsyncConnectionHelper(IDBDatabase* aDatabase, IDBRequest* aRequest); - AsyncConnectionHelper(IDBTransactionRequest* aTransaction, + AsyncConnectionHelper(IDBTransaction* aTransaction, IDBRequest* aRequest); virtual ~AsyncConnectionHelper(); @@ -154,8 +154,8 @@ protected: virtual PRUint16 GetSuccessResult(nsIWritableVariant* aVariant); protected: - nsRefPtr mDatabase; - nsRefPtr mTransaction; + nsRefPtr mDatabase; + nsRefPtr mTransaction; nsRefPtr mRequest; private: diff --git a/dom/indexedDB/DatabaseInfo.h b/dom/indexedDB/DatabaseInfo.h index 5d6c7a40430..99ab9206d6c 100644 --- a/dom/indexedDB/DatabaseInfo.h +++ b/dom/indexedDB/DatabaseInfo.h @@ -43,7 +43,7 @@ // Only meant to be included in IndexedDB source files, not exported. #include "IndexedDatabase.h" -#include "IDBObjectStoreRequest.h" +#include "IDBObjectStore.h" BEGIN_INDEXEDDB_NAMESPACE diff --git a/dom/indexedDB/IDBCursorRequest.cpp b/dom/indexedDB/IDBCursor.cpp similarity index 71% rename from dom/indexedDB/IDBCursorRequest.cpp rename to dom/indexedDB/IDBCursor.cpp index 0a9204578f3..b6aab3da5a0 100644 --- a/dom/indexedDB/IDBCursorRequest.cpp +++ b/dom/indexedDB/IDBCursor.cpp @@ -41,7 +41,7 @@ #include "jscntxt.h" #include "jsapi.h" -#include "IDBCursorRequest.h" +#include "IDBCursor.h" #include "nsIIDBDatabaseException.h" #include "nsIVariant.h" @@ -57,9 +57,9 @@ #include "AsyncConnectionHelper.h" #include "DatabaseInfo.h" #include "IDBEvents.h" -#include "IDBIndexRequest.h" -#include "IDBObjectStoreRequest.h" -#include "IDBTransactionRequest.h" +#include "IDBIndex.h" +#include "IDBObjectStore.h" +#include "IDBTransaction.h" #include "Savepoint.h" #include "TransactionThreadPool.h" @@ -70,7 +70,7 @@ namespace { class UpdateHelper : public AsyncConnectionHelper { public: - UpdateHelper(IDBTransactionRequest* aTransaction, + UpdateHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, PRInt64 aObjectStoreID, const nsAString& aValue, @@ -98,7 +98,7 @@ private: class RemoveHelper : public AsyncConnectionHelper { public: - RemoveHelper(IDBTransactionRequest* aTransaction, + RemoveHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, PRInt64 aObjectStoreID, const Key& aKey, @@ -127,30 +127,30 @@ class ContinueRunnable : public nsRunnable public: NS_DECL_NSIRUNNABLE - ContinueRunnable(IDBCursorRequest* aCursor, + ContinueRunnable(IDBCursor* aCursor, const Key& aKey) : mCursor(aCursor), mKey(aKey) { } private: - nsRefPtr mCursor; + nsRefPtr mCursor; const Key mKey; }; END_INDEXEDDB_NAMESPACE // static -already_AddRefed -IDBCursorRequest::Create(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - IDBObjectStoreRequest* aObjectStore, - PRUint16 aDirection, - nsTArray& aData) +already_AddRefed +IDBCursor::Create(IDBRequest* aRequest, + IDBTransaction* aTransaction, + IDBObjectStore* aObjectStore, + PRUint16 aDirection, + nsTArray& aData) { NS_ASSERTION(aObjectStore, "Null pointer!"); - nsRefPtr cursor = - IDBCursorRequest::CreateCommon(aRequest, aTransaction, aDirection); + nsRefPtr cursor = + IDBCursor::CreateCommon(aRequest, aTransaction, aDirection); cursor->mObjectStore = aObjectStore; @@ -167,17 +167,17 @@ IDBCursorRequest::Create(IDBRequest* aRequest, } // static -already_AddRefed -IDBCursorRequest::Create(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - IDBIndexRequest* aIndex, - PRUint16 aDirection, - nsTArray& aData) +already_AddRefed +IDBCursor::Create(IDBRequest* aRequest, + IDBTransaction* aTransaction, + IDBIndex* aIndex, + PRUint16 aDirection, + nsTArray& aData) { NS_ASSERTION(aIndex, "Null pointer!"); - nsRefPtr cursor = - IDBCursorRequest::CreateCommon(aRequest, aTransaction, aDirection); + nsRefPtr cursor = + IDBCursor::CreateCommon(aRequest, aTransaction, aDirection); cursor->mObjectStore = aIndex->ObjectStore(); cursor->mIndex = aIndex; @@ -195,17 +195,17 @@ IDBCursorRequest::Create(IDBRequest* aRequest, } // static -already_AddRefed -IDBCursorRequest::Create(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - IDBIndexRequest* aIndex, - PRUint16 aDirection, - nsTArray& aData) +already_AddRefed +IDBCursor::Create(IDBRequest* aRequest, + IDBTransaction* aTransaction, + IDBIndex* aIndex, + PRUint16 aDirection, + nsTArray& aData) { NS_ASSERTION(aIndex, "Null pointer!"); - nsRefPtr cursor = - IDBCursorRequest::CreateCommon(aRequest, aTransaction, aDirection); + nsRefPtr cursor = + IDBCursor::CreateCommon(aRequest, aTransaction, aDirection); cursor->mObjectStore = aIndex->ObjectStore(); cursor->mIndex = aIndex; @@ -223,16 +223,16 @@ IDBCursorRequest::Create(IDBRequest* aRequest, } // static -already_AddRefed -IDBCursorRequest::CreateCommon(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - PRUint16 aDirection) +already_AddRefed +IDBCursor::CreateCommon(IDBRequest* aRequest, + IDBTransaction* aTransaction, + PRUint16 aDirection) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aRequest, "Null pointer!"); NS_ASSERTION(aTransaction, "Null pointer!"); - nsRefPtr cursor(new IDBCursorRequest()); + nsRefPtr cursor(new IDBCursor()); cursor->mRequest = aRequest; cursor->mTransaction = aTransaction; cursor->mDirection = aDirection; @@ -240,7 +240,7 @@ IDBCursorRequest::CreateCommon(IDBRequest* aRequest, return cursor.forget(); } -IDBCursorRequest::IDBCursorRequest() +IDBCursor::IDBCursor() : mDirection(nsIIDBCursor::NEXT), mCachedValue(JSVAL_VOID), mHaveCachedValue(false), @@ -252,7 +252,7 @@ IDBCursorRequest::IDBCursorRequest() NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); } -IDBCursorRequest::~IDBCursorRequest() +IDBCursor::~IDBCursor() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -261,20 +261,19 @@ IDBCursorRequest::~IDBCursorRequest() } } -NS_IMPL_ADDREF(IDBCursorRequest) -NS_IMPL_RELEASE(IDBCursorRequest) +NS_IMPL_ADDREF(IDBCursor) +NS_IMPL_RELEASE(IDBCursor) -NS_INTERFACE_MAP_BEGIN(IDBCursorRequest) +NS_INTERFACE_MAP_BEGIN(IDBCursor) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator) - NS_INTERFACE_MAP_ENTRY(nsIIDBCursorRequest) NS_INTERFACE_MAP_ENTRY(nsIIDBCursor) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBCursorRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBCursor) NS_INTERFACE_MAP_END -DOMCI_DATA(IDBCursorRequest, IDBCursorRequest) +DOMCI_DATA(IDBCursor, IDBCursor) NS_IMETHODIMP -IDBCursorRequest::GetDirection(PRUint16* aDirection) +IDBCursor::GetDirection(PRUint16* aDirection) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -283,7 +282,7 @@ IDBCursorRequest::GetDirection(PRUint16* aDirection) } NS_IMETHODIMP -IDBCursorRequest::GetKey(nsIVariant** aKey) +IDBCursor::GetKey(nsIVariant** aKey) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -325,89 +324,52 @@ IDBCursorRequest::GetKey(nsIVariant** aKey) } NS_IMETHODIMP -IDBCursorRequest::GetValue(nsIVariant** aValue) +IDBCursor::GetValue(JSContext* aCx, + jsval* aValue) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); nsresult rv; if (mType == INDEX) { - nsCOMPtr variant = - do_CreateInstance(NS_VARIANT_CONTRACTID); - if (!variant) { - NS_ERROR("Couldn't create variant!"); - return NS_ERROR_FAILURE; - } - const Key& value = mKeyData[mDataIndex].value; NS_ASSERTION(!value.IsUnset() && !value.IsNull(), "Bad key!"); - if (value.IsInt()) { - rv = variant->SetAsInt64(value.IntValue()); - } - else if (value.IsString()) { - rv = variant->SetAsAString(value.StringValue()); - } - else { - NS_NOTREACHED("Bad key type!"); - } + + rv = IDBObjectStore::GetJSValFromKey(value, aCx, aValue); NS_ENSURE_SUCCESS(rv, rv); - rv = variant->SetWritable(PR_FALSE);; - NS_ENSURE_SUCCESS(rv, rv); - - nsIWritableVariant* result; - variant.forget(&result); - *aValue = result; return NS_OK; } - NS_WARNING("Using a slow path for GetValue! Fix this now!"); - - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); - - nsAXPCNativeCallContext* cc; - rv = xpc->GetCurrentNativeCallContext(&cc); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); - - jsval* retval; - rv = cc->GetRetValPtr(&retval); - NS_ENSURE_SUCCESS(rv, rv); - if (!mHaveCachedValue) { - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); - - JSAutoRequest ar(cx); + JSAutoRequest ar(aCx); if (!mJSRuntime) { - JSRuntime* rt = JS_GetRuntime(cx); + JSRuntime* rt = JS_GetRuntime(aCx); JSBool ok = JS_AddNamedRootRT(rt, &mCachedValue, - "IDBCursorRequest::mCachedValue"); + "IDBCursor::mCachedValue"); NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); mJSRuntime = rt; } nsCOMPtr json(new nsJSON()); - rv = json->DecodeToJSVal(mData[mDataIndex].value, cx, &mCachedValue); + rv = json->DecodeToJSVal(mData[mDataIndex].value, aCx, &mCachedValue); NS_ENSURE_SUCCESS(rv, rv); mHaveCachedValue = true; } - *retval = mCachedValue; - cc->SetReturnValueWasSet(PR_TRUE); + *aValue = mCachedValue; return NS_OK; } NS_IMETHODIMP -IDBCursorRequest::Continue(nsIVariant* aKey, - PRUint8 aOptionalArgCount, - PRBool* _retval) +IDBCursor::Continue(jsval aKey, + JSContext* aCx, + PRUint8 aOptionalArgCount, + PRBool* _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -420,7 +382,7 @@ IDBCursorRequest::Continue(nsIVariant* aKey, } Key key; - nsresult rv = IDBObjectStoreRequest::GetKeyFromVariant(aKey, key); + nsresult rv = IDBObjectStore::GetKeyFromJSVal(aKey, key); NS_ENSURE_SUCCESS(rv, rv); if (key.IsNull()) { @@ -449,8 +411,9 @@ IDBCursorRequest::Continue(nsIVariant* aKey, } NS_IMETHODIMP -IDBCursorRequest::Update(nsIVariant* aValue, - nsIIDBRequest** _retval) +IDBCursor::Update(jsval aValue, + JSContext* aCx, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -470,38 +433,11 @@ IDBCursorRequest::Update(nsIVariant* aValue, const Key& key = mData[mDataIndex].key; NS_ASSERTION(!key.IsUnset() && !key.IsNull(), "Bad key!"); - // This is the slow path, need to do this better once XPIDL can have raw - // jsvals as arguments. - NS_WARNING("Using a slow path for Update! Fix this now!"); + JSAutoRequest ar(aCx); - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); - - nsAXPCNativeCallContext* cc; - nsresult rv = xpc->GetCurrentNativeCallContext(&cc); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); - - PRUint32 argc; - rv = cc->GetArgc(&argc); - NS_ENSURE_SUCCESS(rv, rv); - - if (argc < 1) { - return NS_ERROR_XPC_NOT_ENOUGH_ARGS; - } - - jsval* argv; - rv = cc->GetArgvPtr(&argv); - NS_ENSURE_SUCCESS(rv, rv); - - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); - - JSAutoRequest ar(cx); - - js::AutoValueRooter clone(cx); - rv = nsContentUtils::CreateStructuredClone(cx, argv[0], clone.addr()); + js::AutoValueRooter clone(aCx); + nsresult rv = nsContentUtils::CreateStructuredClone(aCx, aValue, + clone.addr()); if (NS_FAILED(rv)) { return rv; } @@ -513,73 +449,40 @@ IDBCursorRequest::Update(nsIVariant* aValue, const jschar* keyPathChars = reinterpret_cast(keyPath.get()); const size_t keyPathLen = keyPath.Length(); - js::AutoValueRooter prop(cx); - JSBool ok = JS_GetUCProperty(cx, JSVAL_TO_OBJECT(clone.value()), + js::AutoValueRooter prop(aCx); + JSBool ok = JS_GetUCProperty(aCx, JSVAL_TO_OBJECT(clone.value()), keyPathChars, keyPathLen, prop.addr()); NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); if (JSVAL_IS_VOID(prop.value())) { - if (key.IsInt()) { - ok = JS_NewNumberValue(cx, key.IntValue(), prop.addr()); - NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); - } - else if (key.IsString()) { - const nsString& keyString = key.StringValue(); - JSString* str = - JS_NewUCStringCopyN(cx, - reinterpret_cast(keyString.get()), - keyString.Length()); - NS_ENSURE_TRUE(str, NS_ERROR_FAILURE); + rv = IDBObjectStore::GetJSValFromKey(key, aCx, prop.addr()); + NS_ENSURE_SUCCESS(rv, rv); - prop.set(STRING_TO_JSVAL(str)); - } - else { - NS_NOTREACHED("Bad key!"); - } - - ok = JS_DefineUCProperty(cx, JSVAL_TO_OBJECT(clone.value()), keyPathChars, - keyPathLen, prop.value(), nsnull, nsnull, - JSPROP_ENUMERATE); + ok = JS_DefineUCProperty(aCx, JSVAL_TO_OBJECT(clone.value()), + keyPathChars, keyPathLen, prop.value(), nsnull, + nsnull, JSPROP_ENUMERATE); NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); } + else { + Key newKey; + rv = IDBObjectStore::GetKeyFromJSVal(prop.value(), newKey); + NS_ENSURE_SUCCESS(rv, rv); - if (JSVAL_IS_NULL(prop.value())) { - return NS_ERROR_INVALID_ARG; - } - - if (JSVAL_IS_INT(prop.value())) { - if (!key.IsInt() || JSVAL_TO_INT(prop.value()) != key.IntValue()) { - return NS_ERROR_INVALID_ARG; - } - } - - if (JSVAL_IS_DOUBLE(prop.value())) { - if (!key.IsInt() || *JSVAL_TO_DOUBLE(prop.value()) != key.IntValue()) { - return NS_ERROR_INVALID_ARG; - } - } - - if (JSVAL_IS_STRING(prop.value())) { - if (!key.IsString()) { - return NS_ERROR_INVALID_ARG; - } - - if (key.StringValue() != nsDependentJSString(prop.value())) { + if (newKey.IsUnset() || newKey.IsNull() || newKey != key) { return NS_ERROR_INVALID_ARG; } } } nsTArray indexUpdateInfo; - rv = IDBObjectStoreRequest::GetIndexUpdateInfo(mObjectStore->GetObjectStoreInfo(), - cx, clone.value(), - indexUpdateInfo); + rv = IDBObjectStore::GetIndexUpdateInfo(mObjectStore->GetObjectStoreInfo(), + aCx, clone.value(), indexUpdateInfo); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr json(new nsJSON()); nsString jsonValue; - rv = json->EncodeFromJSVal(clone.addr(), cx, jsonValue); + rv = json->EncodeFromJSVal(clone.addr(), aCx, jsonValue); NS_ENSURE_SUCCESS(rv, rv); nsRefPtr request = GenerateWriteRequest(); @@ -596,7 +499,7 @@ IDBCursorRequest::Update(nsIVariant* aValue, } NS_IMETHODIMP -IDBCursorRequest::Remove(nsIIDBRequest** _retval) +IDBCursor::Remove(nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -671,9 +574,9 @@ UpdateHelper::DoDatabaseWork(mozIStorageConnection* aConnection) // Update our indexes if needed. if (!mIndexUpdateInfo.IsEmpty()) { PRInt64 objectDataId = mAutoIncrement ? mKey.IntValue() : LL_MININT; - rv = IDBObjectStoreRequest::UpdateIndexes(mTransaction, mOSID, mKey, - mAutoIncrement, true, - objectDataId, mIndexUpdateInfo); + rv = IDBObjectStore::UpdateIndexes(mTransaction, mOSID, mKey, + mAutoIncrement, true, + objectDataId, mIndexUpdateInfo); if (rv == NS_ERROR_STORAGE_CONSTRAINT) { return nsIIDBDatabaseException::CONSTRAINT_ERR; } @@ -771,7 +674,7 @@ ContinueRunnable::Run() mCursor->mHaveCachedValue = false; mCursor->mContinueCalled = false; - if (mCursor->mType == IDBCursorRequest::INDEX) { + if (mCursor->mType == IDBCursor::INDEX) { mCursor->mKeyData.RemoveElementAt(mCursor->mDataIndex); } else { @@ -788,7 +691,7 @@ ContinueRunnable::Run() return NS_ERROR_FAILURE; } - PRBool empty = mCursor->mType == IDBCursorRequest::INDEX ? + PRBool empty = mCursor->mType == IDBCursor::INDEX ? mCursor->mKeyData.IsEmpty() : mCursor->mData.IsEmpty(); @@ -806,7 +709,7 @@ ContinueRunnable::Run() // Skip ahead to our next key match. PRInt32 index = PRInt32(mCursor->mDataIndex); - if (mCursor->mType == IDBCursorRequest::INDEX) { + if (mCursor->mType == IDBCursor::INDEX) { while (index >= 0) { const Key& key = mCursor->mKeyData[index].key; if (mKey == key) { diff --git a/dom/indexedDB/IDBCursorRequest.h b/dom/indexedDB/IDBCursor.h similarity index 72% rename from dom/indexedDB/IDBCursorRequest.h rename to dom/indexedDB/IDBCursor.h index 621344ed2f6..abdd2d62689 100644 --- a/dom/indexedDB/IDBCursorRequest.h +++ b/dom/indexedDB/IDBCursor.h @@ -37,22 +37,20 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_dom_indexeddb_idbcursorrequest_h__ -#define mozilla_dom_indexeddb_idbcursorrequest_h__ +#ifndef mozilla_dom_indexeddb_idbcursor_h__ +#define mozilla_dom_indexeddb_idbcursor_h__ -#include "mozilla/dom/indexedDB/IDBObjectStoreRequest.h" -#include "nsIIDBCursorRequest.h" - -#include "jsapi.h" +#include "mozilla/dom/indexedDB/IDBObjectStore.h" +#include "nsIIDBCursor.h" class nsIRunnable; BEGIN_INDEXEDDB_NAMESPACE -class IDBIndexRequest; +class IDBIndex; class IDBRequest; -class IDBObjectStoreRequest; -class IDBTransactionRequest; +class IDBObjectStore; +class IDBTransaction; struct KeyValuePair { @@ -68,37 +66,36 @@ struct KeyKeyPair class ContinueRunnable; -class IDBCursorRequest : public IDBRequest::Generator, - public nsIIDBCursorRequest +class IDBCursor : public IDBRequest::Generator, + public nsIIDBCursor { friend class ContinueRunnable; public: NS_DECL_ISUPPORTS NS_DECL_NSIIDBCURSOR - NS_DECL_NSIIDBCURSORREQUEST static - already_AddRefed + already_AddRefed Create(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - IDBObjectStoreRequest* aObjectStore, + IDBTransaction* aTransaction, + IDBObjectStore* aObjectStore, PRUint16 aDirection, nsTArray& aData); static - already_AddRefed + already_AddRefed Create(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - IDBIndexRequest* aIndex, + IDBTransaction* aTransaction, + IDBIndex* aIndex, PRUint16 aDirection, nsTArray& aData); static - already_AddRefed + already_AddRefed Create(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, - IDBIndexRequest* aIndex, + IDBTransaction* aTransaction, + IDBIndex* aIndex, PRUint16 aDirection, nsTArray& aData); @@ -110,19 +107,19 @@ public: }; protected: - IDBCursorRequest(); - ~IDBCursorRequest(); + IDBCursor(); + ~IDBCursor(); static - already_AddRefed + already_AddRefed CreateCommon(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction, + IDBTransaction* aTransaction, PRUint16 aDirection); nsRefPtr mRequest; - nsRefPtr mTransaction; - nsRefPtr mObjectStore; - nsRefPtr mIndex; + nsRefPtr mTransaction; + nsRefPtr mObjectStore; + nsRefPtr mIndex; PRUint16 mDirection; @@ -141,4 +138,4 @@ protected: END_INDEXEDDB_NAMESPACE -#endif // mozilla_dom_indexeddb_idbcursorrequest_h__ +#endif // mozilla_dom_indexeddb_idbcursor_h__ diff --git a/dom/indexedDB/IDBDatabaseRequest.cpp b/dom/indexedDB/IDBDatabase.cpp similarity index 83% rename from dom/indexedDB/IDBDatabaseRequest.cpp rename to dom/indexedDB/IDBDatabase.cpp index ec140bcd9e4..39f84e26b67 100644 --- a/dom/indexedDB/IDBDatabaseRequest.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -37,10 +37,9 @@ * * ***** END LICENSE BLOCK ***** */ -#include "IDBDatabaseRequest.h" +#include "IDBDatabase.h" #include "nsIIDBDatabaseException.h" -#include "nsIIDBTransactionRequest.h" #include "mozilla/storage.h" #include "nsDOMClassInfo.h" @@ -50,9 +49,9 @@ #include "AsyncConnectionHelper.h" #include "DatabaseInfo.h" #include "IDBEvents.h" -#include "IDBObjectStoreRequest.h" -#include "IDBTransactionRequest.h" -#include "IndexedDatabaseRequest.h" +#include "IDBObjectStore.h" +#include "IDBTransaction.h" +#include "IDBFactory.h" #include "LazyIdleThread.h" USING_INDEXEDDB_NAMESPACE @@ -63,7 +62,7 @@ const PRUint32 kDefaultDatabaseTimeoutSeconds = 30; inline nsISupports* -isupports_cast(IDBDatabaseRequest* aClassPtr) +isupports_cast(IDBDatabase* aClassPtr) { return static_cast( static_cast(aClassPtr)); @@ -72,7 +71,7 @@ isupports_cast(IDBDatabaseRequest* aClassPtr) class SetVersionHelper : public AsyncConnectionHelper { public: - SetVersionHelper(IDBTransactionRequest* aTransaction, + SetVersionHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const nsAString& aVersion) : AsyncConnectionHelper(aTransaction, aRequest), mVersion(aVersion) @@ -89,7 +88,7 @@ private: class CreateObjectStoreHelper : public AsyncConnectionHelper { public: - CreateObjectStoreHelper(IDBTransactionRequest* aTransaction, + CreateObjectStoreHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const nsAString& aName, const nsAString& aKeyPath, @@ -115,7 +114,7 @@ protected: class RemoveObjectStoreHelper : public AsyncConnectionHelper { public: - RemoveObjectStoreHelper(IDBTransactionRequest* aTransaction, + RemoveObjectStoreHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const nsAString& aName) : AsyncConnectionHelper(aTransaction, aRequest), mName(aName) @@ -210,17 +209,17 @@ ConvertVariantToStringArray(nsIVariant* aVariant, } // anonymous namespace // static -already_AddRefed -IDBDatabaseRequest::Create(DatabaseInfo* aDatabaseInfo, - LazyIdleThread* aThread, - nsCOMPtr& aConnection) +already_AddRefed +IDBDatabase::Create(DatabaseInfo* aDatabaseInfo, + LazyIdleThread* aThread, + nsCOMPtr& aConnection) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aDatabaseInfo, "Null pointer!"); NS_ASSERTION(aThread, "Null pointer!"); NS_ASSERTION(aConnection, "Null pointer!"); - nsRefPtr db(new IDBDatabaseRequest()); + nsRefPtr db(new IDBDatabase()); db->mDatabaseId = aDatabaseInfo->id; db->mName = aDatabaseInfo->name; @@ -235,13 +234,13 @@ IDBDatabaseRequest::Create(DatabaseInfo* aDatabaseInfo, return db.forget(); } -IDBDatabaseRequest::IDBDatabaseRequest() +IDBDatabase::IDBDatabase() : mDatabaseId(0) { } -IDBDatabaseRequest::~IDBDatabaseRequest() +IDBDatabase::~IDBDatabase() { if (mConnectionThread) { mConnectionThread->SetWeakIdleObserver(nsnull); @@ -263,12 +262,12 @@ IDBDatabaseRequest::~IDBDatabaseRequest() } nsresult -IDBDatabaseRequest::GetOrCreateConnection(mozIStorageConnection** aResult) +IDBDatabase::GetOrCreateConnection(mozIStorageConnection** aResult) { NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!"); if (!mConnection) { - mConnection = IndexedDatabaseRequest::GetConnection(mFilePath); + mConnection = IDBFactory::GetConnection(mFilePath); NS_ENSURE_TRUE(mConnection, NS_ERROR_FAILURE); } @@ -278,7 +277,7 @@ IDBDatabaseRequest::GetOrCreateConnection(mozIStorageConnection** aResult) } void -IDBDatabaseRequest::CloseConnection() +IDBDatabase::CloseConnection() { if (mConnection) { if (mConnectionThread) { @@ -292,21 +291,20 @@ IDBDatabaseRequest::CloseConnection() } } -NS_IMPL_ADDREF(IDBDatabaseRequest) -NS_IMPL_RELEASE(IDBDatabaseRequest) +NS_IMPL_ADDREF(IDBDatabase) +NS_IMPL_RELEASE(IDBDatabase) -NS_INTERFACE_MAP_BEGIN(IDBDatabaseRequest) +NS_INTERFACE_MAP_BEGIN(IDBDatabase) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator) - NS_INTERFACE_MAP_ENTRY(nsIIDBDatabaseRequest) NS_INTERFACE_MAP_ENTRY(nsIIDBDatabase) NS_INTERFACE_MAP_ENTRY(nsIObserver) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBDatabaseRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBDatabase) NS_INTERFACE_MAP_END -DOMCI_DATA(IDBDatabaseRequest, IDBDatabaseRequest) +DOMCI_DATA(IDBDatabase, IDBDatabase) NS_IMETHODIMP -IDBDatabaseRequest::GetName(nsAString& aName) +IDBDatabase::GetName(nsAString& aName) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); aName.Assign(mName); @@ -314,7 +312,7 @@ IDBDatabaseRequest::GetName(nsAString& aName) } NS_IMETHODIMP -IDBDatabaseRequest::GetDescription(nsAString& aDescription) +IDBDatabase::GetDescription(nsAString& aDescription) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -323,7 +321,7 @@ IDBDatabaseRequest::GetDescription(nsAString& aDescription) } NS_IMETHODIMP -IDBDatabaseRequest::GetVersion(nsAString& aVersion) +IDBDatabase::GetVersion(nsAString& aVersion) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); DatabaseInfo* info; @@ -336,7 +334,7 @@ IDBDatabaseRequest::GetVersion(nsAString& aVersion) } NS_IMETHODIMP -IDBDatabaseRequest::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) +IDBDatabase::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -363,10 +361,10 @@ IDBDatabaseRequest::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) } NS_IMETHODIMP -IDBDatabaseRequest::CreateObjectStore(const nsAString& aName, - const nsAString& aKeyPath, - PRBool aAutoIncrement, - nsIIDBRequest** _retval) +IDBDatabase::CreateObjectStore(const nsAString& aName, + const nsAString& aKeyPath, + PRBool aAutoIncrement, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -400,10 +398,9 @@ IDBDatabaseRequest::CreateObjectStore(const nsAString& aName, return nsIIDBDatabaseException::UNKNOWN_ERR; } - nsRefPtr transaction = - IDBTransactionRequest::Create(this, objectStores, - nsIIDBTransaction::READ_WRITE, - kDefaultDatabaseTimeoutSeconds); + nsRefPtr transaction = + IDBTransaction::Create(this, objectStores, nsIIDBTransaction::READ_WRITE, + kDefaultDatabaseTimeoutSeconds); nsRefPtr helper = new CreateObjectStoreHelper(transaction, request, aName, keyPath, @@ -416,8 +413,8 @@ IDBDatabaseRequest::CreateObjectStore(const nsAString& aName, } NS_IMETHODIMP -IDBDatabaseRequest::RemoveObjectStore(const nsAString& aName, - nsIIDBRequest** _retval) +IDBDatabase::RemoveObjectStore(const nsAString& aName, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -441,10 +438,9 @@ IDBDatabaseRequest::RemoveObjectStore(const nsAString& aName, return NS_ERROR_OUT_OF_MEMORY; } - nsRefPtr transaction = - IDBTransactionRequest::Create(this, storesToOpen, - nsIIDBTransaction::READ_WRITE, - kDefaultDatabaseTimeoutSeconds); + nsRefPtr transaction = + IDBTransaction::Create(this, storesToOpen, nsIIDBTransaction::READ_WRITE, + kDefaultDatabaseTimeoutSeconds); NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE); @@ -460,8 +456,8 @@ IDBDatabaseRequest::RemoveObjectStore(const nsAString& aName, } NS_IMETHODIMP -IDBDatabaseRequest::SetVersion(const nsAString& aVersion, - nsIIDBRequest** _retval) +IDBDatabase::SetVersion(const nsAString& aVersion, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -475,10 +471,9 @@ IDBDatabaseRequest::SetVersion(const nsAString& aVersion, // Lock the whole database nsTArray storesToOpen; - nsRefPtr transaction = - IDBTransactionRequest::Create(this, storesToOpen, - IDBTransactionRequest::FULL_LOCK, - kDefaultDatabaseTimeoutSeconds); + nsRefPtr transaction = + IDBTransaction::Create(this, storesToOpen, IDBTransaction::FULL_LOCK, + kDefaultDatabaseTimeoutSeconds); NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE); nsRefPtr helper = @@ -491,11 +486,11 @@ IDBDatabaseRequest::SetVersion(const nsAString& aVersion, } NS_IMETHODIMP -IDBDatabaseRequest::Transaction(nsIVariant* aStoreNames, - PRUint16 aMode, - PRUint32 aTimeout, - PRUint8 aOptionalArgCount, - nsIIDBTransactionRequest** _retval) +IDBDatabase::Transaction(nsIVariant* aStoreNames, + PRUint16 aMode, + PRUint32 aTimeout, + PRUint8 aOptionalArgCount, + nsIIDBTransaction** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -617,9 +612,9 @@ IDBDatabaseRequest::Transaction(nsIVariant* aStoreNames, return NS_ERROR_ILLEGAL_VALUE; } - nsRefPtr transaction = - IDBTransactionRequest::Create(this, storesToOpen, aMode, - kDefaultDatabaseTimeoutSeconds); + nsRefPtr transaction = + IDBTransaction::Create(this, storesToOpen, aMode, + kDefaultDatabaseTimeoutSeconds); NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE); transaction.forget(_retval); @@ -627,10 +622,10 @@ IDBDatabaseRequest::Transaction(nsIVariant* aStoreNames, } NS_IMETHODIMP -IDBDatabaseRequest::ObjectStore(const nsAString& aName, - PRUint16 aMode, - PRUint8 aOptionalArgCount, - nsIIDBObjectStoreRequest** _retval) +IDBDatabase::ObjectStore(const nsAString& aName, + PRUint16 aMode, + PRUint8 aOptionalArgCount, + nsIIDBObjectStore** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -665,9 +660,9 @@ IDBDatabaseRequest::ObjectStore(const nsAString& aName, return NS_ERROR_OUT_OF_MEMORY; } - nsRefPtr transaction = - IDBTransactionRequest::Create(this, storesToOpen, aMode, - kDefaultDatabaseTimeoutSeconds); + nsRefPtr transaction = + IDBTransaction::Create(this, storesToOpen, aMode, + kDefaultDatabaseTimeoutSeconds); NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE); nsresult rv = transaction->ObjectStore(aName, _retval); @@ -677,9 +672,9 @@ IDBDatabaseRequest::ObjectStore(const nsAString& aName, } NS_IMETHODIMP -IDBDatabaseRequest::Observe(nsISupports* aSubject, - const char* aTopic, - const PRUnichar* aData) +IDBDatabase::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ENSURE_FALSE(strcmp(aTopic, IDLE_THREAD_TOPIC), NS_ERROR_UNEXPECTED); @@ -772,7 +767,7 @@ CreateObjectStoreHelper::GetSuccessResult(nsIWritableVariant* aResult) } info.forget(); - nsCOMPtr result; + nsCOMPtr result; nsresult rv = mTransaction->ObjectStore(mName, getter_AddRefs(result)); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); diff --git a/dom/indexedDB/IDBDatabaseRequest.h b/dom/indexedDB/IDBDatabase.h similarity index 85% rename from dom/indexedDB/IDBDatabaseRequest.h rename to dom/indexedDB/IDBDatabase.h index eccf4ae9c02..8123003d7d1 100644 --- a/dom/indexedDB/IDBDatabaseRequest.h +++ b/dom/indexedDB/IDBDatabase.h @@ -37,14 +37,14 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_dom_indexeddb_idbdatabaserequest_h__ -#define mozilla_dom_indexeddb_idbdatabaserequest_h__ +#ifndef mozilla_dom_indexeddb_idbdatabase_h__ +#define mozilla_dom_indexeddb_idbdatabase_h__ #include "mozilla/dom/indexedDB/IDBRequest.h" #include "mozilla/dom/indexedDB/LazyIdleThread.h" #include "mozIStorageConnection.h" -#include "nsIIDBDatabaseRequest.h" +#include "nsIIDBDatabase.h" #include "nsIObserver.h" #include "nsDOMLists.h" @@ -53,21 +53,20 @@ BEGIN_INDEXEDDB_NAMESPACE class AsyncConnectionHelper; struct DatabaseInfo; -class IDBTransactionRequest; +class IDBTransaction; -class IDBDatabaseRequest : public IDBRequest::Generator, - public nsIIDBDatabaseRequest, - public nsIObserver +class IDBDatabase : public IDBRequest::Generator, + public nsIIDBDatabase, + public nsIObserver { friend class AsyncConnectionHelper; public: NS_DECL_ISUPPORTS NS_DECL_NSIIDBDATABASE - NS_DECL_NSIIDBDATABASEREQUEST NS_DECL_NSIOBSERVER - static already_AddRefed + static already_AddRefed Create(DatabaseInfo* aDatabaseInfo, LazyIdleThread* aThread, nsCOMPtr& aConnection); @@ -87,8 +86,8 @@ public: } protected: - IDBDatabaseRequest(); - ~IDBDatabaseRequest(); + IDBDatabase(); + ~IDBDatabase(); // Only meant to be called on mStorageThread! nsresult GetOrCreateConnection(mozIStorageConnection** aConnection); @@ -108,4 +107,4 @@ private: END_INDEXEDDB_NAMESPACE -#endif // mozilla_dom_indexeddb_idbdatabaserequest_h__ +#endif // mozilla_dom_indexeddb_idbdatabase_h__ diff --git a/dom/indexedDB/IDBEvents.cpp b/dom/indexedDB/IDBEvents.cpp index 637fcdba742..2e8cfadba92 100644 --- a/dom/indexedDB/IDBEvents.cpp +++ b/dom/indexedDB/IDBEvents.cpp @@ -49,7 +49,7 @@ #include "nsThreadUtils.h" #include "IDBRequest.h" -#include "IDBTransactionRequest.h" +#include "IDBTransaction.h" #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, _condition) \ if ((_condition) && (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ @@ -294,7 +294,7 @@ IDBErrorEvent::SetMessage(const nsAString& aMessage) already_AddRefed IDBSuccessEvent::Create(IDBRequest* aRequest, nsIVariant* aResult, - nsIIDBTransactionRequest* aTransaction) + nsIIDBTransaction* aTransaction) { nsRefPtr event(new IDBSuccessEvent()); @@ -318,7 +318,7 @@ IDBSuccessEvent::Create(IDBRequest* aRequest, already_AddRefed IDBSuccessEvent::CreateRunnable(IDBRequest* aRequest, nsIVariant* aResult, - nsIIDBTransactionRequest* aTransaction) + nsIIDBTransaction* aTransaction) { nsCOMPtr event = IDBSuccessEvent::Create(aRequest, aResult, aTransaction); @@ -343,24 +343,38 @@ DOMCI_DATA(IDBSuccessEvent, IDBSuccessEvent) DOMCI_DATA(IDBTransactionEvent, IDBSuccessEvent) NS_IMETHODIMP -IDBSuccessEvent::GetResult(nsIVariant** aResult) +IDBSuccessEvent::GetResult(JSContext* aCx, + jsval* aResult) { - nsCOMPtr result(mResult); - result.forget(aResult); + if (!mResult) { + *aResult = JSVAL_VOID; + return NS_OK; + } + + nsIXPConnect* xpc = nsContentUtils::XPConnect(); + NS_ENSURE_STATE(xpc); + + JSAutoRequest ar(aCx); + JSObject* scope = JS_GetGlobalObject(aCx); + NS_ENSURE_STATE(scope); + + nsresult rv = xpc->VariantToJS(aCx, scope, mResult, aResult); + NS_ENSURE_SUCCESS(rv, rv); + return NS_OK; } NS_IMETHODIMP -IDBSuccessEvent::GetTransaction(nsIIDBTransactionRequest** aTransaction) +IDBSuccessEvent::GetTransaction(nsIIDBTransaction** aTransaction) { - nsCOMPtr transaction(mTransaction); + nsCOMPtr transaction(mTransaction); transaction.forget(aTransaction); return NS_OK; } nsresult GetSuccessEvent::Init(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction) + IDBTransaction* aTransaction) { mSource = aRequest->GetGenerator(); mTransaction = aTransaction; @@ -376,26 +390,11 @@ GetSuccessEvent::Init(IDBRequest* aRequest, } NS_IMETHODIMP -GetSuccessEvent::GetResult(nsIVariant** /* aResult */) +GetSuccessEvent::GetResult(JSContext* aCx, + jsval* aResult) { - // This is the slow path, need to do this better once XPIDL can pass raw - // jsvals. - NS_WARNING("Using a slow path for GetResult! Fix this now!"); - - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); - - nsAXPCNativeCallContext* cc; - nsresult rv = xpc->GetCurrentNativeCallContext(&cc); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); - - jsval* retval; - rv = cc->GetRetValPtr(&retval); - NS_ENSURE_SUCCESS(rv, rv); - if (mValue.IsVoid()) { - *retval = JSVAL_VOID; + *aResult = JSVAL_VOID; return NS_OK; } @@ -403,13 +402,9 @@ GetSuccessEvent::GetResult(nsIVariant** /* aResult */) nsString jsonValue = mValue; mValue.Truncate(); - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); + JSAutoRequest ar(aCx); - JSAutoRequest ar(cx); - - JSRuntime* rt = JS_GetRuntime(cx); + JSRuntime* rt = JS_GetRuntime(aCx); JSBool ok = JS_AddNamedRootRT(rt, &mCachedValue, "GetSuccessEvent::mCachedValue"); @@ -418,7 +413,7 @@ GetSuccessEvent::GetResult(nsIVariant** /* aResult */) mJSRuntime = rt; nsCOMPtr json(new nsJSON()); - rv = json->DecodeToJSVal(jsonValue, cx, &mCachedValue); + nsresult rv = json->DecodeToJSVal(jsonValue, aCx, &mCachedValue); if (NS_FAILED(rv)) { mCachedValue = JSVAL_VOID; @@ -427,38 +422,18 @@ GetSuccessEvent::GetResult(nsIVariant** /* aResult */) } } - *retval = mCachedValue; - cc->SetReturnValueWasSet(PR_TRUE); + *aResult = mCachedValue; return NS_OK; } NS_IMETHODIMP -GetAllSuccessEvent::GetResult(nsIVariant** /* aResult */) +GetAllSuccessEvent::GetResult(JSContext* aCx, + jsval* aResult) { - // This is the slow path, need to do this better once XPIDL can pass raw - // jsvals. - NS_WARNING("Using a slow path for GetResult! Fix this now!"); - - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); - - nsAXPCNativeCallContext* cc; - nsresult rv = xpc->GetCurrentNativeCallContext(&cc); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); - - jsval* retval; - rv = cc->GetRetValPtr(&retval); - NS_ENSURE_SUCCESS(rv, rv); - if (!mJSRuntime) { - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); + JSAutoRequest ar(aCx); - JSAutoRequest ar(cx); - - JSRuntime* rt = JS_GetRuntime(cx); + JSRuntime* rt = JS_GetRuntime(aCx); JSBool ok = JS_AddNamedRootRT(rt, &mCachedValue, "GetSuccessEvent::mCachedValue"); @@ -474,7 +449,7 @@ GetAllSuccessEvent::GetResult(nsIVariant** /* aResult */) return NS_ERROR_FAILURE; } - JSObject* array = JS_NewArrayObject(cx, 0, NULL); + JSObject* array = JS_NewArrayObject(aCx, 0, NULL); if (!array) { NS_ERROR("Failed to make array!"); return NS_ERROR_FAILURE; @@ -483,14 +458,14 @@ GetAllSuccessEvent::GetResult(nsIVariant** /* aResult */) mCachedValue = OBJECT_TO_JSVAL(array); if (!values.IsEmpty()) { - if (!JS_SetArrayLength(cx, array, jsuint(values.Length()))) { + if (!JS_SetArrayLength(aCx, array, jsuint(values.Length()))) { mCachedValue = JSVAL_VOID; NS_ERROR("Failed to set array length!"); return NS_ERROR_FAILURE; } nsCOMPtr json(new nsJSON()); - js::AutoValueRooter value(cx); + js::AutoValueRooter value(aCx); jsint count = jsint(values.Length()); @@ -498,14 +473,14 @@ GetAllSuccessEvent::GetResult(nsIVariant** /* aResult */) nsString jsonValue = values[index]; values[index].Truncate(); - rv = json->DecodeToJSVal(jsonValue, cx, value.addr()); + nsresult rv = json->DecodeToJSVal(jsonValue, aCx, value.addr()); if (NS_FAILED(rv)) { mCachedValue = JSVAL_VOID; NS_ERROR("Failed to decode!"); return rv; } - if (!JS_SetElement(cx, array, index, value.addr())) { + if (!JS_SetElement(aCx, array, index, value.addr())) { mCachedValue = JSVAL_VOID; NS_ERROR("Failed to set array element!"); return NS_ERROR_FAILURE; @@ -514,38 +489,18 @@ GetAllSuccessEvent::GetResult(nsIVariant** /* aResult */) } } - *retval = mCachedValue; - cc->SetReturnValueWasSet(PR_TRUE); + *aResult = mCachedValue; return NS_OK; } NS_IMETHODIMP -GetAllKeySuccessEvent::GetResult(nsIVariant** /* aResult */) +GetAllKeySuccessEvent::GetResult(JSContext* aCx, + jsval* aResult) { - // This is the slow path, need to do this better once XPIDL can pass raw - // jsvals. - NS_WARNING("Using a slow path for GetResult! Fix this now!"); - - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); - - nsAXPCNativeCallContext* cc; - nsresult rv = xpc->GetCurrentNativeCallContext(&cc); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); - - jsval* retval; - rv = cc->GetRetValPtr(&retval); - NS_ENSURE_SUCCESS(rv, rv); - if (!mJSRuntime) { - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); + JSAutoRequest ar(aCx); - JSAutoRequest ar(cx); - - JSRuntime* rt = JS_GetRuntime(cx); + JSRuntime* rt = JS_GetRuntime(aCx); JSBool ok = JS_AddNamedRootRT(rt, &mCachedValue, "GetSuccessEvent::mCachedValue"); @@ -561,7 +516,7 @@ GetAllKeySuccessEvent::GetResult(nsIVariant** /* aResult */) return NS_ERROR_FAILURE; } - JSObject* array = JS_NewArrayObject(cx, 0, NULL); + JSObject* array = JS_NewArrayObject(aCx, 0, NULL); if (!array) { NS_ERROR("Failed to make array!"); return NS_ERROR_FAILURE; @@ -570,13 +525,13 @@ GetAllKeySuccessEvent::GetResult(nsIVariant** /* aResult */) mCachedValue = OBJECT_TO_JSVAL(array); if (!keys.IsEmpty()) { - if (!JS_SetArrayLength(cx, array, jsuint(keys.Length()))) { + if (!JS_SetArrayLength(aCx, array, jsuint(keys.Length()))) { mCachedValue = JSVAL_VOID; NS_ERROR("Failed to set array length!"); return NS_ERROR_FAILURE; } - js::AutoValueRooter value(cx); + js::AutoValueRooter value(aCx); jsint count = jsint(keys.Length()); @@ -584,40 +539,22 @@ GetAllKeySuccessEvent::GetResult(nsIVariant** /* aResult */) const Key& key = keys[index]; NS_ASSERTION(!key.IsUnset() && !key.IsNull(), "Bad key!"); - if (key.IsInt()) { - if (!JS_NewNumberValue(cx, key.IntValue(), value.addr())) { - mCachedValue = JSVAL_VOID; - NS_ERROR("Failed to make number value!"); - return NS_ERROR_FAILURE; - } - } - else if (key.IsString()) { - const nsString& keyString = key.StringValue(); - JSString* str = JS_NewUCStringCopyN(cx, - reinterpret_cast(keyString.get()), - keyString.Length()); - if (!str) { - mCachedValue = JSVAL_VOID; - NS_ERROR("Failed to make new string value!"); - return NS_ERROR_FAILURE; - } - - value.set(STRING_TO_JSVAL(str)); - } - else { - NS_NOTREACHED("Bad key!"); - } - - if (!JS_SetElement(cx, array, index, value.addr())) { + nsresult rv = IDBObjectStore::GetJSValFromKey(key, aCx, value.addr()); + if (NS_FAILED(rv)) { mCachedValue = JSVAL_VOID; - NS_ERROR("Failed to set array element!"); + NS_WARNING("Failed to get jsval for key!"); + return rv; + } + + if (!JS_SetElement(aCx, array, index, value.addr())) { + mCachedValue = JSVAL_VOID; + NS_WARNING("Failed to set array element!"); return NS_ERROR_FAILURE; } } } } - *retval = mCachedValue; - cc->SetReturnValueWasSet(PR_TRUE); + *aResult = mCachedValue; return NS_OK; } diff --git a/dom/indexedDB/IDBEvents.h b/dom/indexedDB/IDBEvents.h index 8b81e02990e..ce5ee4ef6d4 100644 --- a/dom/indexedDB/IDBEvents.h +++ b/dom/indexedDB/IDBEvents.h @@ -46,14 +46,13 @@ #include "nsIIDBErrorEvent.h" #include "nsIIDBSuccessEvent.h" #include "nsIIDBTransactionEvent.h" -#include "nsIIDBTransactionRequest.h" +#include "nsIIDBTransaction.h" #include "nsIRunnable.h" #include "nsIVariant.h" -#include "jsapi.h" #include "nsDOMEvent.h" -#include "mozilla/dom/indexedDB/IDBObjectStoreRequest.h" +#include "mozilla/dom/indexedDB/IDBObjectStore.h" #define SUCCESS_EVT_STR "success" #define ERROR_EVT_STR "error" @@ -64,7 +63,7 @@ BEGIN_INDEXEDDB_NAMESPACE class IDBRequest; -class IDBTransactionRequest; +class IDBTransaction; class IDBEvent : public nsDOMEvent, public nsIIDBEvent @@ -125,18 +124,18 @@ public: static already_AddRefed Create(IDBRequest* aRequest, nsIVariant* aResult, - nsIIDBTransactionRequest* aTransaction); + nsIIDBTransaction* aTransaction); static already_AddRefed CreateRunnable(IDBRequest* aRequest, nsIVariant* aResult, - nsIIDBTransactionRequest* aTransaction); + nsIIDBTransaction* aTransaction); protected: IDBSuccessEvent() { } nsCOMPtr mResult; - nsCOMPtr mTransaction; + nsCOMPtr mTransaction; }; class GetSuccessEvent : public IDBSuccessEvent @@ -155,10 +154,11 @@ public: } } - NS_IMETHOD GetResult(nsIVariant** aResult); + NS_IMETHOD GetResult(JSContext* aCx, + jsval* aResult); nsresult Init(IDBRequest* aRequest, - IDBTransactionRequest* aTransaction); + IDBTransaction* aTransaction); private: nsString mValue; @@ -179,7 +179,8 @@ public: } } - NS_IMETHOD GetResult(nsIVariant** aResult); + NS_IMETHOD GetResult(JSContext* aCx, + jsval* aResult); private: nsTArray mValues; @@ -196,7 +197,8 @@ public: } } - NS_IMETHOD GetResult(nsIVariant** aResult); + NS_IMETHOD GetResult(JSContext* aCx, + jsval* aResult); private: nsTArray mKeys; diff --git a/dom/indexedDB/IndexedDatabaseRequest.cpp b/dom/indexedDB/IDBFactory.cpp similarity index 93% rename from dom/indexedDB/IndexedDatabaseRequest.cpp rename to dom/indexedDB/IDBFactory.cpp index 7027ff6edee..4e91d29f23f 100644 --- a/dom/indexedDB/IndexedDatabaseRequest.cpp +++ b/dom/indexedDB/IDBFactory.cpp @@ -37,7 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include "IndexedDatabaseRequest.h" +#include "IDBFactory.h" #include "nsIIDBDatabaseException.h" #include "nsILocalFile.h" @@ -55,7 +55,7 @@ #include "AsyncConnectionHelper.h" #include "DatabaseInfo.h" -#include "IDBDatabaseRequest.h" +#include "IDBDatabase.h" #include "IDBKeyRange.h" #include "LazyIdleThread.h" @@ -84,7 +84,7 @@ public: const nsAString& aDescription, const nsACString& aASCIIOrigin, LazyIdleThread* aThread) - : AsyncConnectionHelper(static_cast(nsnull), aRequest), + : AsyncConnectionHelper(static_cast(nsnull), aRequest), mName(aName), mDescription(aDescription), mASCIIOrigin(aASCIIOrigin), mThread(aThread), mDatabaseId(0) { } @@ -451,17 +451,17 @@ ValidateVariantForKey(nsIVariant* aVariant) } // anonyomous namespace // static -already_AddRefed -IndexedDatabaseRequest::Create() +already_AddRefed +IDBFactory::Create() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsCOMPtr request(new IndexedDatabaseRequest()); + nsCOMPtr request(new IDBFactory()); return request.forget(); } // static already_AddRefed -IndexedDatabaseRequest::GetConnection(const nsAString& aDatabaseFilePath) +IDBFactory::GetConnection(const nsAString& aDatabaseFilePath) { NS_ASSERTION(StringEndsWith(aDatabaseFilePath, NS_LITERAL_STRING(".sqlite")), "Bad file path!"); @@ -504,21 +504,21 @@ IndexedDatabaseRequest::GetConnection(const nsAString& aDatabaseFilePath) return connection.forget(); } -NS_IMPL_ADDREF(IndexedDatabaseRequest) -NS_IMPL_RELEASE(IndexedDatabaseRequest) +NS_IMPL_ADDREF(IDBFactory) +NS_IMPL_RELEASE(IDBFactory) -NS_INTERFACE_MAP_BEGIN(IndexedDatabaseRequest) +NS_INTERFACE_MAP_BEGIN(IDBFactory) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator) - NS_INTERFACE_MAP_ENTRY(nsIIndexedDatabaseRequest) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IndexedDatabaseRequest) + NS_INTERFACE_MAP_ENTRY(nsIIDBFactory) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBFactory) NS_INTERFACE_MAP_END -DOMCI_DATA(IndexedDatabaseRequest, IndexedDatabaseRequest) +DOMCI_DATA(IDBFactory, IDBFactory) NS_IMETHODIMP -IndexedDatabaseRequest::Open(const nsAString& aName, - const nsAString& aDescription, - nsIIDBRequest** _retval) +IDBFactory::Open(const nsAString& aName, + const nsAString& aDescription, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -555,8 +555,8 @@ IndexedDatabaseRequest::Open(const nsAString& aName, } NS_IMETHODIMP -IndexedDatabaseRequest::MakeSingleKeyRange(nsIVariant* aValue, - nsIIDBKeyRange** _retval) +IDBFactory::MakeSingleKeyRange(nsIVariant* aValue, + nsIIDBKeyRange** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -575,9 +575,9 @@ IndexedDatabaseRequest::MakeSingleKeyRange(nsIVariant* aValue, } NS_IMETHODIMP -IndexedDatabaseRequest::MakeLeftBoundKeyRange(nsIVariant* aBound, - PRBool aOpen, - nsIIDBKeyRange** _retval) +IDBFactory::MakeLeftBoundKeyRange(nsIVariant* aBound, + PRBool aOpen, + nsIIDBKeyRange** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -598,9 +598,9 @@ IndexedDatabaseRequest::MakeLeftBoundKeyRange(nsIVariant* aBound, } NS_IMETHODIMP -IndexedDatabaseRequest::MakeRightBoundKeyRange(nsIVariant* aBound, - PRBool aOpen, - nsIIDBKeyRange** _retval) +IDBFactory::MakeRightBoundKeyRange(nsIVariant* aBound, + PRBool aOpen, + nsIIDBKeyRange** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -621,11 +621,11 @@ IndexedDatabaseRequest::MakeRightBoundKeyRange(nsIVariant* aBound, } NS_IMETHODIMP -IndexedDatabaseRequest::MakeBoundKeyRange(nsIVariant* aLeft, - nsIVariant* aRight, - PRBool aOpenLeft, - PRBool aOpenRight, - nsIIDBKeyRange **_retval) +IDBFactory::MakeBoundKeyRange(nsIVariant* aLeft, + nsIVariant* aRight, + PRBool aOpenLeft, + PRBool aOpenRight, + nsIIDBKeyRange **_retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -879,8 +879,7 @@ OpenDatabaseHelper::GetSuccessResult(nsIWritableVariant* aResult) } } - nsRefPtr db = - IDBDatabaseRequest::Create(dbInfo, mThread, mConnection); + nsRefPtr db = IDBDatabase::Create(dbInfo, mThread, mConnection); NS_ASSERTION(db, "This can't fail!"); NS_ASSERTION(!mConnection, "Should have swapped out!"); diff --git a/dom/indexedDB/IndexedDatabaseRequest.h b/dom/indexedDB/IDBFactory.h similarity index 82% rename from dom/indexedDB/IndexedDatabaseRequest.h rename to dom/indexedDB/IDBFactory.h index 619032105c1..a64c7fc23b1 100644 --- a/dom/indexedDB/IndexedDatabaseRequest.h +++ b/dom/indexedDB/IDBFactory.h @@ -37,25 +37,25 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_dom_indexeddb_indexeddatabaserequest_h__ -#define mozilla_dom_indexeddb_indexeddatabaserequest_h__ +#ifndef mozilla_dom_indexeddb_idbfactory_h__ +#define mozilla_dom_indexeddb_idbfactory_h__ #include "mozilla/dom/indexedDB/IDBRequest.h" #include "mozIStorageConnection.h" -#include "nsIIndexedDatabaseRequest.h" +#include "nsIIDBFactory.h" BEGIN_INDEXEDDB_NAMESPACE -class IndexedDatabaseRequest : public IDBRequest::Generator, - public nsIIndexedDatabaseRequest +class IDBFactory : public IDBRequest::Generator, + public nsIIDBFactory { public: NS_DECL_ISUPPORTS - NS_DECL_NSIINDEXEDDATABASEREQUEST + NS_DECL_NSIIDBFACTORY static - already_AddRefed + already_AddRefed Create(); static @@ -64,9 +64,9 @@ public: protected: // Only called by Create(). - IndexedDatabaseRequest() { } + IDBFactory() { } }; END_INDEXEDDB_NAMESPACE -#endif // mozilla_dom_indexeddb_indexeddatabaserequest_h__ +#endif // mozilla_dom_indexeddb_idbfactory_h__ diff --git a/dom/indexedDB/IDBIndexRequest.cpp b/dom/indexedDB/IDBIndex.cpp similarity index 91% rename from dom/indexedDB/IDBIndexRequest.cpp rename to dom/indexedDB/IDBIndex.cpp index 3bae61d5300..d4c53221536 100644 --- a/dom/indexedDB/IDBIndexRequest.cpp +++ b/dom/indexedDB/IDBIndex.cpp @@ -38,7 +38,7 @@ * ***** END LICENSE BLOCK ***** */ -#include "IDBIndexRequest.h" +#include "IDBIndex.h" #include "nsIIDBDatabaseException.h" #include "nsIIDBKeyRange.h" @@ -48,10 +48,10 @@ #include "mozilla/storage.h" #include "AsyncConnectionHelper.h" -#include "IDBCursorRequest.h" +#include "IDBCursor.h" #include "IDBEvents.h" -#include "IDBObjectStoreRequest.h" -#include "IDBTransactionRequest.h" +#include "IDBObjectStore.h" +#include "IDBTransaction.h" #include "DatabaseInfo.h" USING_INDEXEDDB_NAMESPACE @@ -61,7 +61,7 @@ namespace { class GetHelper : public AsyncConnectionHelper { public: - GetHelper(IDBTransactionRequest* aTransaction, + GetHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const Key& aKey, PRInt64 aId, @@ -85,7 +85,7 @@ protected: class GetObjectHelper : public GetHelper { public: - GetObjectHelper(IDBTransactionRequest* aTransaction, + GetObjectHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const Key& aKey, PRInt64 aId, @@ -104,7 +104,7 @@ protected: class GetAllHelper : public GetHelper { public: - GetAllHelper(IDBTransactionRequest* aTransaction, + GetAllHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const Key& aKey, PRInt64 aId, @@ -126,7 +126,7 @@ protected: class GetAllObjectsHelper : public GetHelper { public: - GetAllObjectsHelper(IDBTransactionRequest* aTransaction, + GetAllObjectsHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const Key& aKey, PRInt64 aId, @@ -148,9 +148,9 @@ protected: class OpenCursorHelper : public AsyncConnectionHelper { public: - OpenCursorHelper(IDBTransactionRequest* aTransaction, + OpenCursorHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, - IDBIndexRequest* aIndex, + IDBIndex* aIndex, PRInt64 aId, bool aUnique, bool aAutoIncrement, @@ -170,7 +170,7 @@ public: private: // In-params. - nsRefPtr mIndex; + nsRefPtr mIndex; const PRInt64 mId; const bool mUnique; const bool mAutoIncrement; @@ -187,9 +187,9 @@ private: class OpenObjectCursorHelper : public AsyncConnectionHelper { public: - OpenObjectCursorHelper(IDBTransactionRequest* aTransaction, + OpenObjectCursorHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, - IDBIndexRequest* aIndex, + IDBIndex* aIndex, PRInt64 aId, bool aUnique, bool aAutoIncrement, @@ -209,7 +209,7 @@ public: private: // In-params. - nsRefPtr mIndex; + nsRefPtr mIndex; const PRInt64 mId; const bool mUnique; const bool mAutoIncrement; @@ -226,15 +226,15 @@ private: } // anonymous namespace // static -already_AddRefed -IDBIndexRequest::Create(IDBObjectStoreRequest* aObjectStore, - const IndexInfo* aIndexInfo) +already_AddRefed +IDBIndex::Create(IDBObjectStore* aObjectStore, + const IndexInfo* aIndexInfo) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aObjectStore, "Null pointer!"); NS_ASSERTION(aIndexInfo, "Null pointer!"); - nsRefPtr index = new IDBIndexRequest(); + nsRefPtr index = new IDBIndex(); index->mObjectStore = aObjectStore; index->mId = aIndexInfo->id; @@ -246,7 +246,7 @@ IDBIndexRequest::Create(IDBObjectStoreRequest* aObjectStore, return index.forget(); } -IDBIndexRequest::IDBIndexRequest() +IDBIndex::IDBIndex() : mId(LL_MININT), mUnique(false), mAutoIncrement(false) @@ -254,25 +254,24 @@ IDBIndexRequest::IDBIndexRequest() NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); } -IDBIndexRequest::~IDBIndexRequest() +IDBIndex::~IDBIndex() { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); } -NS_IMPL_ADDREF(IDBIndexRequest) -NS_IMPL_RELEASE(IDBIndexRequest) +NS_IMPL_ADDREF(IDBIndex) +NS_IMPL_RELEASE(IDBIndex) -NS_INTERFACE_MAP_BEGIN(IDBIndexRequest) +NS_INTERFACE_MAP_BEGIN(IDBIndex) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator) - NS_INTERFACE_MAP_ENTRY(nsIIDBIndexRequest) NS_INTERFACE_MAP_ENTRY(nsIIDBIndex) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBIndexRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBIndex) NS_INTERFACE_MAP_END -DOMCI_DATA(IDBIndexRequest, IDBIndexRequest) +DOMCI_DATA(IDBIndex, IDBIndex) NS_IMETHODIMP -IDBIndexRequest::GetName(nsAString& aName) +IDBIndex::GetName(nsAString& aName) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -281,7 +280,7 @@ IDBIndexRequest::GetName(nsAString& aName) } NS_IMETHODIMP -IDBIndexRequest::GetStoreName(nsAString& aStoreName) +IDBIndex::GetStoreName(nsAString& aStoreName) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -289,7 +288,7 @@ IDBIndexRequest::GetStoreName(nsAString& aStoreName) } NS_IMETHODIMP -IDBIndexRequest::GetKeyPath(nsAString& aKeyPath) +IDBIndex::GetKeyPath(nsAString& aKeyPath) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -298,7 +297,7 @@ IDBIndexRequest::GetKeyPath(nsAString& aKeyPath) } NS_IMETHODIMP -IDBIndexRequest::GetUnique(PRBool* aUnique) +IDBIndex::GetUnique(PRBool* aUnique) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -307,15 +306,13 @@ IDBIndexRequest::GetUnique(PRBool* aUnique) } NS_IMETHODIMP -IDBIndexRequest::Get(nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBIndex::Get(nsIVariant* aKey, + nsIIDBRequest** _retval) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); - NS_WARNING("Using a slow path for Get! Fix this now!"); - Key key; - nsresult rv = IDBObjectStoreRequest::GetKeyFromVariant(aKey, key); + nsresult rv = IDBObjectStore::GetKeyFromVariant(aKey, key); NS_ENSURE_SUCCESS(rv, rv); if (key.IsUnset() || key.IsNull()) { @@ -336,15 +333,13 @@ IDBIndexRequest::Get(nsIVariant* aKey, } NS_IMETHODIMP -IDBIndexRequest::GetObject(nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBIndex::GetObject(nsIVariant* aKey, + nsIIDBRequest** _retval) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); - NS_WARNING("Using a slow path for Get! Fix this now!"); - Key key; - nsresult rv = IDBObjectStoreRequest::GetKeyFromVariant(aKey, key); + nsresult rv = IDBObjectStore::GetKeyFromVariant(aKey, key); NS_ENSURE_SUCCESS(rv, rv); if (key.IsUnset() || key.IsNull()) { @@ -365,15 +360,15 @@ IDBIndexRequest::GetObject(nsIVariant* aKey, } NS_IMETHODIMP -IDBIndexRequest::GetAll(nsIVariant* aKey, - PRUint32 aLimit, - PRUint8 aOptionalArgCount, - nsIIDBRequest** _retval) +IDBIndex::GetAll(nsIVariant* aKey, + PRUint32 aLimit, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); Key key; - nsresult rv = IDBObjectStoreRequest::GetKeyFromVariant(aKey, key); + nsresult rv = IDBObjectStore::GetKeyFromVariant(aKey, key); NS_ENSURE_SUCCESS(rv, rv); if (key.IsNull()) { @@ -398,15 +393,15 @@ IDBIndexRequest::GetAll(nsIVariant* aKey, } NS_IMETHODIMP -IDBIndexRequest::GetAllObjects(nsIVariant* aKey, - PRUint32 aLimit, - PRUint8 aOptionalArgCount, - nsIIDBRequest** _retval) +IDBIndex::GetAllObjects(nsIVariant* aKey, + PRUint32 aLimit, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); Key key; - nsresult rv = IDBObjectStoreRequest::GetKeyFromVariant(aKey, key); + nsresult rv = IDBObjectStore::GetKeyFromVariant(aKey, key); NS_ENSURE_SUCCESS(rv, rv); if (key.IsNull()) { @@ -431,11 +426,11 @@ IDBIndexRequest::GetAllObjects(nsIVariant* aKey, } NS_IMETHODIMP -IDBIndexRequest::OpenCursor(nsIIDBKeyRange* aKeyRange, - PRUint16 aDirection, - PRBool aPreload, - PRUint8 aOptionalArgCount, - nsIIDBRequest** _retval) +IDBIndex::OpenCursor(nsIIDBKeyRange* aKeyRange, + PRUint16 aDirection, + PRBool aPreload, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -455,13 +450,13 @@ IDBIndexRequest::OpenCursor(nsIIDBKeyRange* aKeyRange, rv = aKeyRange->GetLeft(getter_AddRefs(variant)); NS_ENSURE_SUCCESS(rv, rv); - rv = IDBObjectStoreRequest::GetKeyFromVariant(variant, leftKey); + rv = IDBObjectStore::GetKeyFromVariant(variant, leftKey); NS_ENSURE_SUCCESS(rv, rv); rv = aKeyRange->GetRight(getter_AddRefs(variant)); NS_ENSURE_SUCCESS(rv, rv); - rv = IDBObjectStoreRequest::GetKeyFromVariant(variant, rightKey); + rv = IDBObjectStore::GetKeyFromVariant(variant, rightKey); NS_ENSURE_SUCCESS(rv, rv); } @@ -498,11 +493,11 @@ IDBIndexRequest::OpenCursor(nsIIDBKeyRange* aKeyRange, } NS_IMETHODIMP -IDBIndexRequest::OpenObjectCursor(nsIIDBKeyRange* aKeyRange, - PRUint16 aDirection, - PRBool aPreload, - PRUint8 aOptionalArgCount, - nsIIDBRequest** _retval) +IDBIndex::OpenObjectCursor(nsIIDBKeyRange* aKeyRange, + PRUint16 aDirection, + PRBool aPreload, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -522,13 +517,13 @@ IDBIndexRequest::OpenObjectCursor(nsIIDBKeyRange* aKeyRange, rv = aKeyRange->GetLeft(getter_AddRefs(variant)); NS_ENSURE_SUCCESS(rv, rv); - rv = IDBObjectStoreRequest::GetKeyFromVariant(variant, leftKey); + rv = IDBObjectStore::GetKeyFromVariant(variant, leftKey); NS_ENSURE_SUCCESS(rv, rv); rv = aKeyRange->GetRight(getter_AddRefs(variant)); NS_ENSURE_SUCCESS(rv, rv); - rv = IDBObjectStoreRequest::GetKeyFromVariant(variant, rightKey); + rv = IDBObjectStore::GetKeyFromVariant(variant, rightKey); NS_ENSURE_SUCCESS(rv, rv); } @@ -1140,9 +1135,8 @@ OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult) return OK; } - nsRefPtr cursor = - IDBCursorRequest::Create(mRequest, mTransaction, mIndex, mDirection, - mData); + nsRefPtr cursor = + IDBCursor::Create(mRequest, mTransaction, mIndex, mDirection, mData); NS_ENSURE_TRUE(cursor, nsIIDBDatabaseException::UNKNOWN_ERR); aResult->SetAsISupports(static_cast(cursor)); @@ -1342,9 +1336,8 @@ OpenObjectCursorHelper::GetSuccessResult(nsIWritableVariant* aResult) return OK; } - nsRefPtr cursor = - IDBCursorRequest::Create(mRequest, mTransaction, mIndex, mDirection, - mData); + nsRefPtr cursor = + IDBCursor::Create(mRequest, mTransaction, mIndex, mDirection, mData); NS_ENSURE_TRUE(cursor, nsIIDBDatabaseException::UNKNOWN_ERR); aResult->SetAsISupports(static_cast(cursor)); diff --git a/dom/indexedDB/IDBIndexRequest.h b/dom/indexedDB/IDBIndex.h similarity index 79% rename from dom/indexedDB/IDBIndexRequest.h rename to dom/indexedDB/IDBIndex.h index 8f13671d509..bb66178c4dd 100644 --- a/dom/indexedDB/IDBIndexRequest.h +++ b/dom/indexedDB/IDBIndex.h @@ -37,41 +37,40 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_dom_indexeddb_idbindexrequest_h__ -#define mozilla_dom_indexeddb_idbindexrequest_h__ +#ifndef mozilla_dom_indexeddb_idbindex_h__ +#define mozilla_dom_indexeddb_idbindex_h__ #include "mozilla/dom/indexedDB/IDBRequest.h" -#include "nsIIDBIndexRequest.h" +#include "nsIIDBIndex.h" BEGIN_INDEXEDDB_NAMESPACE -class IDBObjectStoreRequest; +class IDBObjectStore; struct IndexInfo; -class IDBIndexRequest : public IDBRequest::Generator, - public nsIIDBIndexRequest +class IDBIndex : public IDBRequest::Generator, + public nsIIDBIndex { public: NS_DECL_ISUPPORTS NS_DECL_NSIIDBINDEX - NS_DECL_NSIIDBINDEXREQUEST - static already_AddRefed - Create(IDBObjectStoreRequest* aObjectStore, + static already_AddRefed + Create(IDBObjectStore* aObjectStore, const IndexInfo* aIndexInfo); - IDBObjectStoreRequest* ObjectStore() + IDBObjectStore* ObjectStore() { return mObjectStore; } protected: - IDBIndexRequest(); - ~IDBIndexRequest(); + IDBIndex(); + ~IDBIndex(); private: - nsRefPtr mObjectStore; + nsRefPtr mObjectStore; PRInt64 mId; nsString mName; @@ -82,4 +81,4 @@ private: END_INDEXEDDB_NAMESPACE -#endif // mozilla_dom_indexeddb_idbindexrequest_h__ +#endif // mozilla_dom_indexeddb_idbindex_h__ diff --git a/dom/indexedDB/IDBKeyRange.h b/dom/indexedDB/IDBKeyRange.h index db03bb3ac30..de3b59ced2f 100644 --- a/dom/indexedDB/IDBKeyRange.h +++ b/dom/indexedDB/IDBKeyRange.h @@ -47,11 +47,11 @@ BEGIN_INDEXEDDB_NAMESPACE -class IndexedDatabaseRequest; +class IDBFactory; class IDBKeyRange : public nsIIDBKeyRange { - friend class IndexedDatabaseRequest; + friend class IDBFactory; public: NS_DECL_ISUPPORTS diff --git a/dom/indexedDB/IDBObjectStoreRequest.cpp b/dom/indexedDB/IDBObjectStore.cpp similarity index 86% rename from dom/indexedDB/IDBObjectStoreRequest.cpp rename to dom/indexedDB/IDBObjectStore.cpp index f4eefa07f0c..88f056ba748 100644 --- a/dom/indexedDB/IDBObjectStoreRequest.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -37,46 +37,39 @@ * * ***** END LICENSE BLOCK ***** */ -// XXX remove once we can get jsvals out of XPIDL -#include "jscntxt.h" -#include "jsapi.h" -#include "nsContentUtils.h" -#include "nsJSON.h" -#include "IDBEvents.h" - -#include "IDBObjectStoreRequest.h" -#include "IDBIndexRequest.h" +#include "IDBObjectStore.h" #include "nsIIDBDatabaseException.h" #include "nsIJSContextStack.h" #include "nsIUUIDGenerator.h" #include "nsIVariant.h" +#include "jscntxt.h" +#include "mozilla/storage.h" +#include "nsContentUtils.h" #include "nsDOMClassInfo.h" +#include "nsJSON.h" #include "nsJSUtils.h" #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" -#include "mozilla/storage.h" #include "AsyncConnectionHelper.h" -#include "IDBCursorRequest.h" +#include "IDBCursor.h" +#include "IDBEvents.h" +#include "IDBIndex.h" #include "IDBKeyRange.h" -#include "IDBTransactionRequest.h" +#include "IDBTransaction.h" #include "DatabaseInfo.h" #include "Savepoint.h" USING_INDEXEDDB_NAMESPACE -BEGIN_INDEXEDDB_NAMESPACE - -END_INDEXEDDB_NAMESPACE - namespace { class AddHelper : public AsyncConnectionHelper { public: - AddHelper(IDBTransactionRequest* aTransaction, + AddHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, PRInt64 aObjectStoreID, const nsAString& aKeyPath, @@ -116,7 +109,7 @@ private: class GetHelper : public AsyncConnectionHelper { public: - GetHelper(IDBTransactionRequest* aTransaction, + GetHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, PRInt64 aObjectStoreID, const Key& aKey, @@ -142,7 +135,7 @@ private: class RemoveHelper : public GetHelper { public: - RemoveHelper(IDBTransactionRequest* aTransaction, + RemoveHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, PRInt64 aObjectStoreID, const Key& aKey, @@ -158,9 +151,9 @@ public: class OpenCursorHelper : public AsyncConnectionHelper { public: - OpenCursorHelper(IDBTransactionRequest* aTransaction, + OpenCursorHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, - IDBObjectStoreRequest* aObjectStore, + IDBObjectStore* aObjectStore, const Key& aLeftKey, const Key& aRightKey, PRUint16 aKeyRangeFlags, @@ -176,7 +169,7 @@ public: private: // In-params. - nsRefPtr mObjectStore; + nsRefPtr mObjectStore; const Key mLeftKey; const Key mRightKey; const PRUint16 mKeyRangeFlags; @@ -190,13 +183,13 @@ private: class CreateIndexHelper : public AsyncConnectionHelper { public: - CreateIndexHelper(IDBTransactionRequest* aTransaction, + CreateIndexHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, const nsAString& aName, const nsAString& aKeyPath, bool aUnique, bool aAutoIncrement, - IDBObjectStoreRequest* aObjectStore) + IDBObjectStore* aObjectStore) : AsyncConnectionHelper(aTransaction, aRequest), mName(aName), mKeyPath(aKeyPath), mUnique(aUnique), mAutoIncrement(aAutoIncrement), mObjectStore(aObjectStore), mId(LL_MININT) @@ -213,7 +206,7 @@ private: nsString mKeyPath; const bool mUnique; const bool mAutoIncrement; - nsRefPtr mObjectStore; + nsRefPtr mObjectStore; // Out-params. PRInt64 mId; @@ -222,10 +215,10 @@ private: class RemoveIndexHelper : public AsyncConnectionHelper { public: - RemoveIndexHelper(IDBTransactionRequest* aDatabase, + RemoveIndexHelper(IDBTransaction* aDatabase, IDBRequest* aRequest, const nsAString& aName, - IDBObjectStoreRequest* aObjectStore) + IDBObjectStore* aObjectStore) : AsyncConnectionHelper(aDatabase, aRequest), mName(aName), mObjectStore(aObjectStore) { } @@ -236,13 +229,13 @@ public: private: // In-params nsString mName; - nsRefPtr mObjectStore; + nsRefPtr mObjectStore; }; class GetAllHelper : public AsyncConnectionHelper { public: - GetAllHelper(IDBTransactionRequest* aTransaction, + GetAllHelper(IDBTransaction* aTransaction, IDBRequest* aRequest, PRInt64 aObjectStoreID, const Key& aLeftKey, @@ -289,47 +282,24 @@ GetKeyFromObject(JSContext* aCx, JSBool ok = JS_GetUCProperty(aCx, aObj, keyPathChars, keyPathLen, &key); NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); - if (JSVAL_IS_VOID(key)) { - aKey = Key::UNSETKEY; - return NS_OK; - } + nsresult rv = IDBObjectStore::GetKeyFromJSVal(key, aKey); + NS_ENSURE_SUCCESS(rv, rv); - if (JSVAL_IS_NULL(key)) { - aKey = Key::NULLKEY; - return NS_OK; - } - - if (JSVAL_IS_INT(key)) { - aKey = JSVAL_TO_INT(key); - return NS_OK; - } - - if (JSVAL_IS_DOUBLE(key)) { - aKey = *JSVAL_TO_DOUBLE(key); - return NS_OK; - } - - if (JSVAL_IS_STRING(key)) { - aKey = nsDependentJSString(key); - return NS_OK; - } - - // We only support those types. - return NS_ERROR_INVALID_ARG; + return NS_OK; } } // anonymous namespace // static -already_AddRefed -IDBObjectStoreRequest::Create(IDBDatabaseRequest* aDatabase, - IDBTransactionRequest* aTransaction, - const ObjectStoreInfo* aStoreInfo, - PRUint16 aMode) +already_AddRefed +IDBObjectStore::Create(IDBDatabase* aDatabase, + IDBTransaction* aTransaction, + const ObjectStoreInfo* aStoreInfo, + PRUint16 aMode) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr objectStore = new IDBObjectStoreRequest(); + nsRefPtr objectStore = new IDBObjectStore(); objectStore->mDatabase = aDatabase; objectStore->mTransaction = aTransaction; @@ -345,8 +315,8 @@ IDBObjectStoreRequest::Create(IDBDatabaseRequest* aDatabase, // static nsresult -IDBObjectStoreRequest::GetKeyFromVariant(nsIVariant* aKeyVariant, - Key& aKey) +IDBObjectStore::GetKeyFromVariant(nsIVariant* aKeyVariant, + Key& aKey) { if (!aKeyVariant) { aKey = Key::UNSETKEY; @@ -387,8 +357,73 @@ IDBObjectStoreRequest::GetKeyFromVariant(nsIVariant* aKeyVariant, // static nsresult -IDBObjectStoreRequest::GetJSONFromArg0(/* jsval arg0, */ - nsAString& aJSON) +IDBObjectStore::GetKeyFromJSVal(jsval aKeyVal, + Key& aKey) +{ + if (JSVAL_IS_VOID(aKeyVal)) { + aKey = Key::UNSETKEY; + } + else if (JSVAL_IS_NULL(aKeyVal)) { + aKey = Key::NULLKEY; + } + else if (JSVAL_IS_STRING(aKeyVal)) { + aKey = nsDependentJSString(aKeyVal); + } + else if (JSVAL_IS_INT(aKeyVal)) { + aKey = JSVAL_TO_INT(aKeyVal); + } + else if (JSVAL_IS_DOUBLE(aKeyVal)) { + aKey = *JSVAL_TO_DOUBLE(aKeyVal); + } + else { + return NS_ERROR_INVALID_ARG; + } + + return NS_OK; +} + +// static +nsresult +IDBObjectStore::GetJSValFromKey(const Key& aKey, + JSContext* aCx, + jsval* aKeyVal) +{ + if (aKey.IsUnset()) { + *aKeyVal = JSVAL_VOID; + return NS_OK; + } + + if (aKey.IsNull()) { + *aKeyVal = JSVAL_NULL; + return NS_OK; + } + + if (aKey.IsInt()) { + JSBool ok = JS_NewNumberValue(aCx, aKey.IntValue(), aKeyVal); + NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); + return NS_OK; + } + + if (aKey.IsString()) { + const nsString& keyString = aKey.StringValue(); + JSString* str = + JS_NewUCStringCopyN(aCx, + reinterpret_cast(keyString.get()), + keyString.Length()); + NS_ENSURE_TRUE(str, NS_ERROR_FAILURE); + + *aKeyVal = STRING_TO_JSVAL(str); + return NS_OK; + } + + NS_NOTREACHED("Unknown key type!"); + return NS_ERROR_INVALID_ARG; +} + +// static +nsresult +IDBObjectStore::GetJSONFromArg0(/* jsval arg0, */ + nsAString& aJSON) { nsIXPConnect* xpc = nsContentUtils::XPConnect(); NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); @@ -432,10 +467,10 @@ IDBObjectStoreRequest::GetJSONFromArg0(/* jsval arg0, */ // static nsresult -IDBObjectStoreRequest::GetKeyPathValueFromJSON(const nsAString& aJSON, - const nsAString& aKeyPath, - JSContext** aCx, - Key& aValue) +IDBObjectStore::GetKeyPathValueFromJSON(const nsAString& aJSON, + const nsAString& aKeyPath, + JSContext** aCx, + Key& aValue) { NS_ASSERTION(!aJSON.IsEmpty(), "Empty JSON!"); NS_ASSERTION(!aKeyPath.IsEmpty(), "Empty keyPath!"); @@ -473,17 +508,10 @@ IDBObjectStoreRequest::GetKeyPathValueFromJSON(const nsAString& aJSON, value.addr()); NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); - if (JSVAL_IS_INT(value.value())) { - aValue = JSVAL_TO_INT(value.value()); - } - else if (JSVAL_IS_DOUBLE(value.value())) { - aValue = *JSVAL_TO_DOUBLE(value.value()); - } - else if (JSVAL_IS_STRING(value.value())) { - aValue = nsDependentJSString(value.value()); - } - else { - // If the object doesn't have a value for our index then we leave it unset. + rv = GetKeyFromJSVal(value.value(), aValue); + if (NS_FAILED(rv) || aValue.IsNull()) { + // If the object doesn't have a value that we can use for our index then we + // leave it unset. aValue = Key::UNSETKEY; } @@ -492,10 +520,10 @@ IDBObjectStoreRequest::GetKeyPathValueFromJSON(const nsAString& aJSON, /* static */ nsresult -IDBObjectStoreRequest::GetIndexUpdateInfo(ObjectStoreInfo* aObjectStoreInfo, - JSContext* aCx, - jsval aObject, - nsTArray& aUpdateInfoArray) +IDBObjectStore::GetIndexUpdateInfo(ObjectStoreInfo* aObjectStoreInfo, + JSContext* aCx, + jsval aObject, + nsTArray& aUpdateInfoArray) { JSObject* cloneObj = nsnull; @@ -521,26 +549,8 @@ IDBObjectStoreRequest::GetIndexUpdateInfo(ObjectStoreInfo* aObjectStoreInfo, NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); Key value; - - if (JSVAL_IS_INT(keyPathValue)) { - value = JSVAL_TO_INT(keyPathValue); - } - else if (JSVAL_IS_DOUBLE(keyPathValue)) { - value = *JSVAL_TO_DOUBLE(keyPathValue); - } - else if (JSVAL_IS_STRING(keyPathValue)) { - JSString* str = JSVAL_TO_STRING(keyPathValue); - size_t len = JS_GetStringLength(str); - if (len) { - const PRUnichar* chars = - reinterpret_cast(JS_GetStringChars(str)); - value = nsDependentString(chars, len); - } - else { - value = EmptyString(); - } - } - else { + nsresult rv = GetKeyFromJSVal(keyPathValue, value); + if (NS_FAILED(rv) || value.IsUnset() || value.IsNull()) { // Not a value we can do anything with, ignore it. continue; } @@ -559,13 +569,13 @@ IDBObjectStoreRequest::GetIndexUpdateInfo(ObjectStoreInfo* aObjectStoreInfo, /* static */ nsresult -IDBObjectStoreRequest::UpdateIndexes(IDBTransactionRequest* aTransaction, - PRInt64 aObjectStoreId, - const Key& aObjectStoreKey, - bool aAutoIncrement, - bool aOverwrite, - PRInt64 aObjectDataId, - const nsTArray& aUpdateInfoArray) +IDBObjectStore::UpdateIndexes(IDBTransaction* aTransaction, + PRInt64 aObjectStoreId, + const Key& aObjectStoreKey, + bool aAutoIncrement, + bool aOverwrite, + PRInt64 aObjectDataId, + const nsTArray& aUpdateInfoArray) { #ifdef DEBUG if (aAutoIncrement) { @@ -682,7 +692,7 @@ IDBObjectStoreRequest::UpdateIndexes(IDBTransactionRequest* aTransaction, } ObjectStoreInfo* -IDBObjectStoreRequest::GetObjectStoreInfo() +IDBObjectStore::GetObjectStoreInfo() { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -694,7 +704,7 @@ IDBObjectStoreRequest::GetObjectStoreInfo() return info; } -IDBObjectStoreRequest::IDBObjectStoreRequest() +IDBObjectStore::IDBObjectStore() : mId(LL_MININT), mAutoIncrement(PR_FALSE), mMode(nsIIDBTransaction::READ_WRITE) @@ -702,64 +712,31 @@ IDBObjectStoreRequest::IDBObjectStoreRequest() NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); } -IDBObjectStoreRequest::~IDBObjectStoreRequest() +IDBObjectStore::~IDBObjectStore() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); } nsresult -IDBObjectStoreRequest::GetAddInfo(/* jsval aValue, */ - nsIVariant* aKeyVariant, - nsString& aJSON, - Key& aKey, - nsTArray& aUpdateInfoArray) +IDBObjectStore::GetAddInfo(JSContext* aCx, + jsval aValue, + jsval aKeyVal, + nsString& aJSON, + Key& aKey, + nsTArray& aUpdateInfoArray) { - // This is the slow path, need to do this better once XPIDL can have raw - // jsvals as arguments. - NS_WARNING("Using a slow path for Add! Fix this now!"); + JSAutoRequest ar(aCx); - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED); - - nsAXPCNativeCallContext* cc; - nsresult rv = xpc->GetCurrentNativeCallContext(&cc); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); - - PRUint32 argc; - rv = cc->GetArgc(&argc); - NS_ENSURE_SUCCESS(rv, rv); - - if (argc < 1) { - return NS_ERROR_XPC_NOT_ENOUGH_ARGS; - } - - jsval* argv; - rv = cc->GetArgvPtr(&argv); - NS_ENSURE_SUCCESS(rv, rv); - - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); - - JSAutoRequest ar(cx); - - js::AutoValueRooter clone(cx); - rv = nsContentUtils::CreateStructuredClone(cx, argv[0], clone.addr()); + js::AutoValueRooter clone(aCx); + nsresult rv = nsContentUtils::CreateStructuredClone(aCx, aValue, + clone.addr()); if (NS_FAILED(rv)) { return rv; } if (mKeyPath.IsEmpty()) { - // Key was passed in. - if (argc < 2) { - // Actually, nothing was passed in, and we can skip this. - aKey = Key::UNSETKEY; - } - else { - rv = GetKeyFromVariant(aKeyVariant, aKey); - NS_ENSURE_SUCCESS(rv, rv); - } + rv = GetKeyFromJSVal(aKeyVal, aKey); + NS_ENSURE_SUCCESS(rv, rv); } else { // Inline keys live on the object. Make sure it is an object. @@ -767,12 +744,12 @@ IDBObjectStoreRequest::GetAddInfo(/* jsval aValue, */ return NS_ERROR_INVALID_ARG; } - rv = GetKeyFromObject(cx, JSVAL_TO_OBJECT(clone.value()), mKeyPath, aKey); + rv = GetKeyFromObject(aCx, JSVAL_TO_OBJECT(clone.value()), mKeyPath, aKey); NS_ENSURE_SUCCESS(rv, rv); // Except if null was passed, in which case we're supposed to generate the // key. - if (aKey.IsUnset() && argc >= 2 && JSVAL_IS_NULL(argv[1])) { + if (aKey.IsUnset() && JSVAL_IS_NULL(aKeyVal)) { aKey = Key::NULLKEY; } } @@ -785,30 +762,29 @@ IDBObjectStoreRequest::GetAddInfo(/* jsval aValue, */ ObjectStoreInfo* objectStoreInfo = GetObjectStoreInfo(); NS_ENSURE_TRUE(objectStoreInfo, NS_ERROR_FAILURE); - rv = GetIndexUpdateInfo(objectStoreInfo, cx, clone.value(), aUpdateInfoArray); + rv = GetIndexUpdateInfo(objectStoreInfo, aCx, clone.value(), aUpdateInfoArray); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr json(new nsJSON()); - rv = json->EncodeFromJSVal(clone.addr(), cx, aJSON); + rv = json->EncodeFromJSVal(clone.addr(), aCx, aJSON); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } -NS_IMPL_ADDREF(IDBObjectStoreRequest) -NS_IMPL_RELEASE(IDBObjectStoreRequest) +NS_IMPL_ADDREF(IDBObjectStore) +NS_IMPL_RELEASE(IDBObjectStore) -NS_INTERFACE_MAP_BEGIN(IDBObjectStoreRequest) +NS_INTERFACE_MAP_BEGIN(IDBObjectStore) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, IDBRequest::Generator) - NS_INTERFACE_MAP_ENTRY(nsIIDBObjectStoreRequest) NS_INTERFACE_MAP_ENTRY(nsIIDBObjectStore) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBObjectStoreRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBObjectStore) NS_INTERFACE_MAP_END -DOMCI_DATA(IDBObjectStoreRequest, IDBObjectStoreRequest) +DOMCI_DATA(IDBObjectStore, IDBObjectStore) NS_IMETHODIMP -IDBObjectStoreRequest::GetName(nsAString& aName) +IDBObjectStore::GetName(nsAString& aName) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -817,7 +793,7 @@ IDBObjectStoreRequest::GetName(nsAString& aName) } NS_IMETHODIMP -IDBObjectStoreRequest::GetKeyPath(nsAString& aKeyPath) +IDBObjectStore::GetKeyPath(nsAString& aKeyPath) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -826,7 +802,7 @@ IDBObjectStoreRequest::GetKeyPath(nsAString& aKeyPath) } NS_IMETHODIMP -IDBObjectStoreRequest::GetIndexNames(nsIDOMDOMStringList** aIndexNames) +IDBObjectStore::GetIndexNames(nsIDOMDOMStringList** aIndexNames) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -846,8 +822,8 @@ IDBObjectStoreRequest::GetIndexNames(nsIDOMDOMStringList** aIndexNames) } NS_IMETHODIMP -IDBObjectStoreRequest::Get(nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBObjectStore::Get(nsIVariant* aKey, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -876,10 +852,10 @@ IDBObjectStoreRequest::Get(nsIVariant* aKey, } NS_IMETHODIMP -IDBObjectStoreRequest::GetAll(nsIIDBKeyRange* aKeyRange, - PRUint32 aLimit, - PRUint8 aOptionalArgCount, - nsIIDBRequest** _retval) +IDBObjectStore::GetAll(nsIIDBKeyRange* aKeyRange, + PRUint32 aLimit, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -928,9 +904,11 @@ IDBObjectStoreRequest::GetAll(nsIIDBKeyRange* aKeyRange, } NS_IMETHODIMP -IDBObjectStoreRequest::Add(nsIVariant* /* aValue */, - nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBObjectStore::Add(jsval aValue, + jsval aKey, + JSContext* aCx, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -942,11 +920,15 @@ IDBObjectStoreRequest::Add(nsIVariant* /* aValue */, return NS_ERROR_OBJECT_IS_IMMUTABLE; } + if (aOptionalArgCount < 1) { + aKey = JSVAL_VOID; + } + nsString jsonValue; Key key; nsTArray updateInfo; - nsresult rv = GetAddInfo(aKey, jsonValue, key, updateInfo); + nsresult rv = GetAddInfo(aCx, aValue, aKey, jsonValue, key, updateInfo); if (NS_FAILED(rv)) { return rv; } @@ -969,9 +951,11 @@ IDBObjectStoreRequest::Add(nsIVariant* /* aValue */, } NS_IMETHODIMP -IDBObjectStoreRequest::Modify(nsIVariant* /* aValue */, - nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBObjectStore::Modify(jsval aValue, + jsval aKey, + JSContext* aCx, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -983,11 +967,15 @@ IDBObjectStoreRequest::Modify(nsIVariant* /* aValue */, return NS_ERROR_OBJECT_IS_IMMUTABLE; } + if (aOptionalArgCount < 1) { + aKey = JSVAL_VOID; + } + nsString jsonValue; Key key; nsTArray updateInfo; - nsresult rv = GetAddInfo(aKey, jsonValue, key, updateInfo); + nsresult rv = GetAddInfo(aCx, aValue, aKey, jsonValue, key, updateInfo); if (NS_FAILED(rv)) { return rv; } @@ -1010,9 +998,11 @@ IDBObjectStoreRequest::Modify(nsIVariant* /* aValue */, } NS_IMETHODIMP -IDBObjectStoreRequest::AddOrModify(nsIVariant* /* aValue */, - nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBObjectStore::AddOrModify(jsval aValue, + jsval aKey, + JSContext* aCx, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -1024,11 +1014,15 @@ IDBObjectStoreRequest::AddOrModify(nsIVariant* /* aValue */, return NS_ERROR_OBJECT_IS_IMMUTABLE; } + if (aOptionalArgCount < 1) { + aKey = JSVAL_VOID; + } + nsString jsonValue; Key key; nsTArray updateInfo; - nsresult rv = GetAddInfo(aKey, jsonValue, key, updateInfo); + nsresult rv = GetAddInfo(aCx, aValue, aKey, jsonValue, key, updateInfo); if (NS_FAILED(rv)) { return rv; } @@ -1051,8 +1045,8 @@ IDBObjectStoreRequest::AddOrModify(nsIVariant* /* aValue */, } NS_IMETHODIMP -IDBObjectStoreRequest::Remove(nsIVariant* aKey, - nsIIDBRequest** _retval) +IDBObjectStore::Remove(nsIVariant* aKey, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -1087,11 +1081,11 @@ IDBObjectStoreRequest::Remove(nsIVariant* aKey, } NS_IMETHODIMP -IDBObjectStoreRequest::OpenCursor(nsIIDBKeyRange* aKeyRange, - PRUint16 aDirection, - PRBool aPreload, - PRUint8 aOptionalArgCount, - nsIIDBRequest** _retval) +IDBObjectStore::OpenCursor(nsIIDBKeyRange* aKeyRange, + PRUint16 aDirection, + PRBool aPreload, + PRUint8 aOptionalArgCount, + nsIIDBRequest** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -1154,10 +1148,10 @@ IDBObjectStoreRequest::OpenCursor(nsIIDBKeyRange* aKeyRange, } NS_IMETHODIMP -IDBObjectStoreRequest::CreateIndex(const nsAString& aName, - const nsAString& aKeyPath, - PRBool aUnique, - nsIIDBRequest** _retval) +IDBObjectStore::CreateIndex(const nsAString& aName, + const nsAString& aKeyPath, + PRBool aUnique, + nsIIDBRequest** _retval) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -1204,8 +1198,8 @@ IDBObjectStoreRequest::CreateIndex(const nsAString& aName, } NS_IMETHODIMP -IDBObjectStoreRequest::Index(const nsAString& aName, - nsIIDBIndexRequest** _retval) +IDBObjectStore::Index(const nsAString& aName, + nsIIDBIndex** _retval) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -1233,16 +1227,15 @@ IDBObjectStoreRequest::Index(const nsAString& aName, return NS_ERROR_NOT_AVAILABLE; } - nsRefPtr request = - IDBIndexRequest::Create(this, indexInfo); + nsRefPtr request = IDBIndex::Create(this, indexInfo); request.forget(_retval); return NS_OK; } NS_IMETHODIMP -IDBObjectStoreRequest::RemoveIndex(const nsAString& aName, - nsIIDBRequest** _retval) +IDBObjectStore::RemoveIndex(const nsAString& aName, + nsIIDBRequest** _retval) { NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!"); @@ -1435,9 +1428,9 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection) // Update our indexes if needed. if (!mIndexUpdateInfo.IsEmpty()) { PRInt64 objectDataId = mAutoIncrement ? mKey.IntValue() : LL_MININT; - rv = IDBObjectStoreRequest::UpdateIndexes(mTransaction, mOSID, mKey, - mAutoIncrement, mOverwrite, - objectDataId, mIndexUpdateInfo); + rv = IDBObjectStore::UpdateIndexes(mTransaction, mOSID, mKey, + mAutoIncrement, mOverwrite, + objectDataId, mIndexUpdateInfo); if (rv == NS_ERROR_STORAGE_CONSTRAINT) { return nsIIDBDatabaseException::CONSTRAINT_ERR; } @@ -1786,9 +1779,8 @@ OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult) return OK; } - nsRefPtr cursor = - IDBCursorRequest::Create(mRequest, mTransaction, mObjectStore, mDirection, - mData); + nsRefPtr cursor = + IDBCursor::Create(mRequest, mTransaction, mObjectStore, mDirection, mData); NS_ENSURE_TRUE(cursor, nsIIDBDatabaseException::UNKNOWN_ERR); aResult->SetAsISupports(static_cast(cursor)); @@ -1906,8 +1898,7 @@ CreateIndexHelper::InsertDataFromObjectStore(mozIStorageConnection* aConnection) Key key; JSContext* cx = nsnull; - rv = IDBObjectStoreRequest::GetKeyPathValueFromJSON(json, mKeyPath, &cx, - key); + rv = IDBObjectStore::GetKeyPathValueFromJSON(json, mKeyPath, &cx, key); // XXX this should be a constraint error maybe? NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); @@ -1972,7 +1963,7 @@ CreateIndexHelper::GetSuccessResult(nsIWritableVariant* aResult) newInfo->unique = mUnique; newInfo->autoIncrement = mAutoIncrement; - nsCOMPtr result; + nsCOMPtr result; nsresult rv = mObjectStore->Index(mName, getter_AddRefs(result)); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); diff --git a/dom/indexedDB/IDBObjectStoreRequest.h b/dom/indexedDB/IDBObjectStore.h similarity index 86% rename from dom/indexedDB/IDBObjectStoreRequest.h rename to dom/indexedDB/IDBObjectStore.h index f02f5490c51..2f508136c66 100644 --- a/dom/indexedDB/IDBObjectStoreRequest.h +++ b/dom/indexedDB/IDBObjectStore.h @@ -37,14 +37,14 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_dom_indexeddb_idbobjectstorerequest_h__ -#define mozilla_dom_indexeddb_idbobjectstorerequest_h__ +#ifndef mozilla_dom_indexeddb_idbobjectstore_h__ +#define mozilla_dom_indexeddb_idbobjectstore_h__ #include "mozilla/dom/indexedDB/IDBRequest.h" -#include "mozilla/dom/indexedDB/IDBDatabaseRequest.h" -#include "mozilla/dom/indexedDB/IDBTransactionRequest.h" +#include "mozilla/dom/indexedDB/IDBDatabase.h" +#include "mozilla/dom/indexedDB/IDBTransaction.h" -#include "nsIIDBObjectStoreRequest.h" +#include "nsIIDBObjectStore.h" struct JSContext; @@ -125,6 +125,11 @@ public: return false; } + bool operator!=(const Key& aOther) const + { + return !(*this == aOther); + } + bool operator<(const Key& aOther) const { switch (mType) { @@ -205,17 +210,16 @@ private: PRInt64 mInt; }; -class IDBObjectStoreRequest : public IDBRequest::Generator, - public nsIIDBObjectStoreRequest +class IDBObjectStore : public IDBRequest::Generator, + public nsIIDBObjectStore { public: NS_DECL_ISUPPORTS NS_DECL_NSIIDBOBJECTSTORE - NS_DECL_NSIIDBOBJECTSTOREREQUEST - static already_AddRefed - Create(IDBDatabaseRequest* aDatabase, - IDBTransactionRequest* aTransaction, + static already_AddRefed + Create(IDBDatabase* aDatabase, + IDBTransaction* aTransaction, const ObjectStoreInfo* aInfo, PRUint16 aMode); @@ -223,6 +227,15 @@ public: GetKeyFromVariant(nsIVariant* aKeyVariant, Key& aKey); + static nsresult + GetKeyFromJSVal(jsval aKeyVal, + Key& aKey); + + static nsresult + GetJSValFromKey(const Key& aKey, + JSContext* aCx, + jsval* aKeyVal); + static nsresult GetJSONFromArg0(/* jsval arg0, */ nsAString& aJSON); @@ -240,7 +253,7 @@ public: nsTArray& aUpdateInfoArray); static nsresult - UpdateIndexes(IDBTransactionRequest* aTransaction, + UpdateIndexes(IDBTransaction* aTransaction, PRInt64 aObjectStoreId, const Key& aObjectStoreKey, bool aAutoIncrement, @@ -274,7 +287,7 @@ public: return mKeyPath; } - IDBTransactionRequest* Transaction() + IDBTransaction* Transaction() { return mTransaction; } @@ -282,18 +295,19 @@ public: ObjectStoreInfo* GetObjectStoreInfo(); protected: - IDBObjectStoreRequest(); - ~IDBObjectStoreRequest(); + IDBObjectStore(); + ~IDBObjectStore(); - nsresult GetAddInfo(/* jsval aValue, */ - nsIVariant* aKeyVariant, + nsresult GetAddInfo(JSContext* aCx, + jsval aValue, + jsval aKeyVal, nsString& aJSON, Key& aKey, nsTArray& aUpdateInfoArray); private: - nsRefPtr mDatabase; - nsRefPtr mTransaction; + nsRefPtr mDatabase; + nsRefPtr mTransaction; PRInt64 mId; nsString mName; @@ -305,4 +319,4 @@ private: END_INDEXEDDB_NAMESPACE -#endif // mozilla_dom_indexeddb_idbobjectstorerequest_h__ +#endif // mozilla_dom_indexeddb_idbobjectstore_h__ diff --git a/dom/indexedDB/IDBRequest.h b/dom/indexedDB/IDBRequest.h index 4942fcff5bd..91f7d8ac062 100644 --- a/dom/indexedDB/IDBRequest.h +++ b/dom/indexedDB/IDBRequest.h @@ -52,8 +52,8 @@ BEGIN_INDEXEDDB_NAMESPACE class AsyncConnectionHelper; -class IndexedDatabaseRequest; -class IDBDatabaseRequest; +class IDBFactory; +class IDBDatabase; class IDBRequest : public nsDOMEventTargetHelper, public nsIIDBRequest diff --git a/dom/indexedDB/IDBTransactionRequest.cpp b/dom/indexedDB/IDBTransaction.cpp similarity index 84% rename from dom/indexedDB/IDBTransactionRequest.cpp rename to dom/indexedDB/IDBTransaction.cpp index efc2a1c40ef..5b278408e1a 100644 --- a/dom/indexedDB/IDBTransactionRequest.cpp +++ b/dom/indexedDB/IDBTransaction.cpp @@ -37,7 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include "IDBTransactionRequest.h" +#include "IDBTransaction.h" #include "mozilla/storage.h" #include "nsDOMClassInfo.h" @@ -45,9 +45,9 @@ #include "nsThreadUtils.h" #include "IDBEvents.h" -#include "IDBCursorRequest.h" -#include "IDBObjectStoreRequest.h" -#include "IndexedDatabaseRequest.h" +#include "IDBCursor.h" +#include "IDBObjectStore.h" +#include "IDBFactory.h" #include "DatabaseInfo.h" #include "TransactionThreadPool.h" @@ -71,15 +71,15 @@ DoomCachedStatements(const nsACString& aQuery, } // anonymous namespace // static -already_AddRefed -IDBTransactionRequest::Create(IDBDatabaseRequest* aDatabase, - nsTArray& aObjectStoreNames, - PRUint16 aMode, - PRUint32 aTimeout) +already_AddRefed +IDBTransaction::Create(IDBDatabase* aDatabase, + nsTArray& aObjectStoreNames, + PRUint16 aMode, + PRUint32 aTimeout) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr transaction = new IDBTransactionRequest(); + nsRefPtr transaction = new IDBTransaction(); transaction->mDatabase = aDatabase; transaction->mMode = aMode; @@ -98,7 +98,7 @@ IDBTransactionRequest::Create(IDBDatabaseRequest* aDatabase, return transaction.forget(); } -IDBTransactionRequest::IDBTransactionRequest() +IDBTransaction::IDBTransaction() : mReadyState(nsIIDBTransaction::INITIAL), mMode(nsIIDBTransaction::READ_ONLY), mTimeout(0), @@ -110,7 +110,7 @@ IDBTransactionRequest::IDBTransactionRequest() NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); } -IDBTransactionRequest::~IDBTransactionRequest() +IDBTransaction::~IDBTransaction() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(!mPendingRequests, "Should have no pending requests here!"); @@ -123,7 +123,7 @@ IDBTransactionRequest::~IDBTransactionRequest() } void -IDBTransactionRequest::OnNewRequest() +IDBTransaction::OnNewRequest() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!mPendingRequests) { @@ -135,7 +135,7 @@ IDBTransactionRequest::OnNewRequest() } void -IDBTransactionRequest::OnRequestFinished() +IDBTransaction::OnRequestFinished() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(mPendingRequests, "Mismatched calls!"); @@ -151,7 +151,7 @@ IDBTransactionRequest::OnRequestFinished() } nsresult -IDBTransactionRequest::CommitOrRollback() +IDBTransaction::CommitOrRollback() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(mReadyState == nsIIDBTransaction::DONE, "Bad readyState!"); @@ -171,7 +171,7 @@ IDBTransactionRequest::CommitOrRollback() } bool -IDBTransactionRequest::StartSavepoint() +IDBTransaction::StartSavepoint() { NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!"); NS_PRECONDITION(mConnection, "No connection!"); @@ -199,7 +199,7 @@ IDBTransactionRequest::StartSavepoint() } nsresult -IDBTransactionRequest::ReleaseSavepoint() +IDBTransaction::ReleaseSavepoint() { NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!"); NS_PRECONDITION(mConnection, "No connection!"); @@ -216,7 +216,7 @@ IDBTransactionRequest::ReleaseSavepoint() } void -IDBTransactionRequest::RollbackSavepoint() +IDBTransaction::RollbackSavepoint() { NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!"); NS_PRECONDITION(mConnection, "No connection!"); @@ -232,13 +232,13 @@ IDBTransactionRequest::RollbackSavepoint() } nsresult -IDBTransactionRequest::GetOrCreateConnection(mozIStorageConnection** aResult) +IDBTransaction::GetOrCreateConnection(mozIStorageConnection** aResult) { NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!"); if (!mConnection) { nsCOMPtr connection = - IndexedDatabaseRequest::GetConnection(mDatabase->FilePath()); + IDBFactory::GetConnection(mDatabase->FilePath()); NS_ENSURE_TRUE(connection, NS_ERROR_FAILURE); connection.swap(mConnection); @@ -250,9 +250,9 @@ IDBTransactionRequest::GetOrCreateConnection(mozIStorageConnection** aResult) } already_AddRefed -IDBTransactionRequest::AddStatement(bool aCreate, - bool aOverwrite, - bool aAutoIncrement) +IDBTransaction::AddStatement(bool aCreate, + bool aOverwrite, + bool aAutoIncrement) { #ifdef DEBUG if (!aCreate) { @@ -301,7 +301,7 @@ IDBTransactionRequest::AddStatement(bool aCreate, } already_AddRefed -IDBTransactionRequest::RemoveStatement(bool aAutoIncrement) +IDBTransaction::RemoveStatement(bool aAutoIncrement) { if (aAutoIncrement) { return GetCachedStatement( @@ -318,7 +318,7 @@ IDBTransactionRequest::RemoveStatement(bool aAutoIncrement) } already_AddRefed -IDBTransactionRequest::GetStatement(bool aAutoIncrement) +IDBTransaction::GetStatement(bool aAutoIncrement) { if (aAutoIncrement) { return GetCachedStatement( @@ -337,8 +337,8 @@ IDBTransactionRequest::GetStatement(bool aAutoIncrement) } already_AddRefed -IDBTransactionRequest::IndexGetStatement(bool aUnique, - bool aAutoIncrement) +IDBTransaction::IndexGetStatement(bool aUnique, + bool aAutoIncrement) { if (aAutoIncrement) { if (aUnique) { @@ -373,8 +373,8 @@ IDBTransactionRequest::IndexGetStatement(bool aUnique, } already_AddRefed -IDBTransactionRequest::IndexGetObjectStatement(bool aUnique, - bool aAutoIncrement) +IDBTransaction::IndexGetObjectStatement(bool aUnique, + bool aAutoIncrement) { if (aAutoIncrement) { if (aUnique) { @@ -417,9 +417,9 @@ IDBTransactionRequest::IndexGetObjectStatement(bool aUnique, } already_AddRefed -IDBTransactionRequest::IndexUpdateStatement(bool aAutoIncrement, - bool aUnique, - bool aOverwrite) +IDBTransaction::IndexUpdateStatement(bool aAutoIncrement, + bool aUnique, + bool aOverwrite) { if (aAutoIncrement) { if (aUnique) { @@ -478,7 +478,7 @@ IDBTransactionRequest::IndexUpdateStatement(bool aAutoIncrement, } already_AddRefed -IDBTransactionRequest::GetCachedStatement(const nsACString& aQuery) +IDBTransaction::GetCachedStatement(const nsACString& aQuery) { NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(!aQuery.IsEmpty(), "Empty sql statement!"); @@ -513,7 +513,7 @@ IDBTransactionRequest::GetCachedStatement(const nsACString& aQuery) #ifdef DEBUG bool -IDBTransactionRequest::TransactionIsOpen() const +IDBTransaction::TransactionIsOpen() const { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); return mReadyState == nsIIDBTransaction::INITIAL || @@ -521,42 +521,41 @@ IDBTransactionRequest::TransactionIsOpen() const } bool -IDBTransactionRequest::IsWriteAllowed() const +IDBTransaction::IsWriteAllowed() const { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); return mMode == nsIIDBTransaction::READ_WRITE; } #endif -NS_IMPL_CYCLE_COLLECTION_CLASS(IDBTransactionRequest) +NS_IMPL_CYCLE_COLLECTION_CLASS(IDBTransaction) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBTransactionRequest, +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBTransaction, nsDOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCompleteListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnAbortListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnTimeoutListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransactionRequest, +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransaction, nsDOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCompleteListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnAbortListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnTimeoutListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBTransactionRequest) - NS_INTERFACE_MAP_ENTRY(nsIIDBTransactionRequest) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBTransaction) NS_INTERFACE_MAP_ENTRY(nsIIDBTransaction) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBTransactionRequest) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBTransaction) NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) -NS_IMPL_ADDREF_INHERITED(IDBTransactionRequest, nsDOMEventTargetHelper) -NS_IMPL_RELEASE_INHERITED(IDBTransactionRequest, nsDOMEventTargetHelper) +NS_IMPL_ADDREF_INHERITED(IDBTransaction, nsDOMEventTargetHelper) +NS_IMPL_RELEASE_INHERITED(IDBTransaction, nsDOMEventTargetHelper) -DOMCI_DATA(IDBTransactionRequest, IDBTransactionRequest) +DOMCI_DATA(IDBTransaction, IDBTransaction) NS_IMETHODIMP -IDBTransactionRequest::GetDb(nsIIDBDatabase** aDB) +IDBTransaction::GetDb(nsIIDBDatabase** aDB) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -565,7 +564,7 @@ IDBTransactionRequest::GetDb(nsIIDBDatabase** aDB) } NS_IMETHODIMP -IDBTransactionRequest::GetReadyState(PRUint16* aReadyState) +IDBTransaction::GetReadyState(PRUint16* aReadyState) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -574,17 +573,17 @@ IDBTransactionRequest::GetReadyState(PRUint16* aReadyState) } NS_IMETHODIMP -IDBTransactionRequest::GetMode(PRUint16* aMode) +IDBTransaction::GetMode(PRUint16* aMode) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - *aMode = mMode == IDBTransactionRequest::FULL_LOCK ? + *aMode = mMode == IDBTransaction::FULL_LOCK ? nsIIDBTransaction::READ_WRITE : mMode; return NS_OK; } NS_IMETHODIMP -IDBTransactionRequest::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) +IDBTransaction::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -593,7 +592,7 @@ IDBTransactionRequest::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) nsTArray stackArray; nsTArray* arrayOfNames; - if (mMode == IDBTransactionRequest::FULL_LOCK) { + if (mMode == IDBTransaction::FULL_LOCK) { DatabaseInfo* info; if (!DatabaseInfo::Get(mDatabase->Id(), &info)) { NS_ERROR("This should never fail!"); @@ -621,8 +620,8 @@ IDBTransactionRequest::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores) } NS_IMETHODIMP -IDBTransactionRequest::ObjectStore(const nsAString& aName, - nsIIDBObjectStoreRequest** _retval) +IDBTransaction::ObjectStore(const nsAString& aName, + nsIIDBObjectStore** _retval) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -647,8 +646,8 @@ IDBTransactionRequest::ObjectStore(const nsAString& aName, return NS_ERROR_NOT_AVAILABLE; } - nsRefPtr objectStore = - IDBObjectStoreRequest::Create(mDatabase, this, info, mMode); + nsRefPtr objectStore = + IDBObjectStore::Create(mDatabase, this, info, mMode); NS_ENSURE_TRUE(objectStore, NS_ERROR_FAILURE); objectStore.forget(_retval); @@ -656,7 +655,7 @@ IDBTransactionRequest::ObjectStore(const nsAString& aName, } NS_IMETHODIMP -IDBTransactionRequest::Abort() +IDBTransaction::Abort() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -671,7 +670,7 @@ IDBTransactionRequest::Abort() } NS_IMETHODIMP -IDBTransactionRequest::GetOncomplete(nsIDOMEventListener** aOncomplete) +IDBTransaction::GetOncomplete(nsIDOMEventListener** aOncomplete) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -679,7 +678,7 @@ IDBTransactionRequest::GetOncomplete(nsIDOMEventListener** aOncomplete) } NS_IMETHODIMP -IDBTransactionRequest::SetOncomplete(nsIDOMEventListener* aOncomplete) +IDBTransaction::SetOncomplete(nsIDOMEventListener* aOncomplete) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -688,7 +687,7 @@ IDBTransactionRequest::SetOncomplete(nsIDOMEventListener* aOncomplete) } NS_IMETHODIMP -IDBTransactionRequest::GetOnabort(nsIDOMEventListener** aOnabort) +IDBTransaction::GetOnabort(nsIDOMEventListener** aOnabort) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -696,7 +695,7 @@ IDBTransactionRequest::GetOnabort(nsIDOMEventListener** aOnabort) } NS_IMETHODIMP -IDBTransactionRequest::SetOnabort(nsIDOMEventListener* aOnabort) +IDBTransaction::SetOnabort(nsIDOMEventListener* aOnabort) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -705,7 +704,7 @@ IDBTransactionRequest::SetOnabort(nsIDOMEventListener* aOnabort) } NS_IMETHODIMP -IDBTransactionRequest::GetOntimeout(nsIDOMEventListener** aOntimeout) +IDBTransaction::GetOntimeout(nsIDOMEventListener** aOntimeout) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -713,7 +712,7 @@ IDBTransactionRequest::GetOntimeout(nsIDOMEventListener** aOntimeout) } NS_IMETHODIMP -IDBTransactionRequest::SetOntimeout(nsIDOMEventListener* aOntimeout) +IDBTransaction::SetOntimeout(nsIDOMEventListener* aOntimeout) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); diff --git a/dom/indexedDB/IDBTransactionRequest.h b/dom/indexedDB/IDBTransaction.h similarity index 86% rename from dom/indexedDB/IDBTransactionRequest.h rename to dom/indexedDB/IDBTransaction.h index 5ef45a21b2e..ab7fc43cdb3 100644 --- a/dom/indexedDB/IDBTransactionRequest.h +++ b/dom/indexedDB/IDBTransaction.h @@ -37,13 +37,13 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_dom_indexeddb_idbtransactionrequest_h__ -#define mozilla_dom_indexeddb_idbtransactionrequest_h__ +#ifndef mozilla_dom_indexeddb_idbtransaction_h__ +#define mozilla_dom_indexeddb_idbtransaction_h__ #include "mozilla/dom/indexedDB/IDBRequest.h" -#include "mozilla/dom/indexedDB/IDBDatabaseRequest.h" +#include "mozilla/dom/indexedDB/IDBDatabase.h" -#include "nsIIDBTransactionRequest.h" +#include "nsIIDBTransaction.h" #include "nsIRunnable.h" #include "nsDOMEventTargetHelper.h" @@ -62,9 +62,9 @@ class CommitHelper; struct ObjectStoreInfo; class TransactionThreadPool; -class IDBTransactionRequest : public nsDOMEventTargetHelper, - public IDBRequest::Generator, - public nsIIDBTransactionRequest +class IDBTransaction : public nsDOMEventTargetHelper, + public IDBRequest::Generator, + public nsIIDBTransaction { friend class AsyncConnectionHelper; friend class CommitHelper; @@ -73,13 +73,12 @@ class IDBTransactionRequest : public nsDOMEventTargetHelper, public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIIDBTRANSACTION - NS_DECL_NSIIDBTRANSACTIONREQUEST - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransactionRequest, + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, nsDOMEventTargetHelper) - static already_AddRefed - Create(IDBDatabaseRequest* aDatabase, + static already_AddRefed + Create(IDBDatabase* aDatabase, nsTArray& aObjectStoreNames, PRUint16 aMode, PRUint32 aTimeout); @@ -146,15 +145,15 @@ public: enum { FULL_LOCK = nsIIDBTransaction::SNAPSHOT_READ + 1 }; private: - IDBTransactionRequest(); - ~IDBTransactionRequest(); + IDBTransaction(); + ~IDBTransaction(); // Only meant to be called on mStorageThread! nsresult GetOrCreateConnection(mozIStorageConnection** aConnection); nsresult CommitOrRollback(); - nsRefPtr mDatabase; + nsRefPtr mDatabase; nsTArray mObjectStoreNames; PRUint16 mReadyState; PRUint16 mMode; @@ -183,7 +182,7 @@ NS_STACK_CLASS class AutoTransactionRequestNotifier { public: - AutoTransactionRequestNotifier(IDBTransactionRequest* aTransaction) + AutoTransactionRequestNotifier(IDBTransaction* aTransaction) : mTransaction(aTransaction) { NS_ASSERTION(mTransaction, "Null pointer!"); @@ -196,7 +195,7 @@ public: } private: - nsRefPtr mTransaction; + nsRefPtr mTransaction; }; class CommitHelper : public nsIRunnable @@ -205,7 +204,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE - CommitHelper(IDBTransactionRequest* aTransaction) + CommitHelper(IDBTransaction* aTransaction) : mTransaction(aTransaction), mAborted(!!aTransaction->mAborted), mHasInitialSavepoint(!!aTransaction->mHasInitialSavepoint) @@ -227,7 +226,7 @@ public: } private: - nsRefPtr mTransaction; + nsRefPtr mTransaction; nsCOMPtr mConnection; nsAutoTArray, 10> mDoomedObjects; bool mAborted; @@ -236,4 +235,4 @@ private: END_INDEXEDDB_NAMESPACE -#endif // mozilla_dom_indexeddb_idbtransactionrequest_h__ +#endif // mozilla_dom_indexeddb_idbtransaction_h__ diff --git a/dom/indexedDB/Makefile.in b/dom/indexedDB/Makefile.in index 57ada2bad1c..815e9435b34 100644 --- a/dom/indexedDB/Makefile.in +++ b/dom/indexedDB/Makefile.in @@ -54,30 +54,30 @@ EXPORTS_NAMESPACES = mozilla/dom/indexedDB CPPSRCS = \ AsyncConnectionHelper.cpp \ DatabaseInfo.cpp \ - IDBCursorRequest.cpp \ - IDBDatabaseRequest.cpp \ + IDBCursor.cpp \ + IDBDatabase.cpp \ IDBEvents.cpp \ - IDBIndexRequest.cpp \ + IDBIndex.cpp \ IDBKeyRange.cpp \ - IDBObjectStoreRequest.cpp \ + IDBObjectStore.cpp \ IDBRequest.cpp \ - IDBTransactionRequest.cpp \ - IndexedDatabaseRequest.cpp \ + IDBTransaction.cpp \ + IDBFactory.cpp \ LazyIdleThread.cpp \ TransactionThreadPool.cpp \ $(NULL) EXPORTS_mozilla/dom/indexedDB = \ - IDBCursorRequest.h \ - IDBDatabaseRequest.h \ + IDBCursor.h \ + IDBDatabase.h \ IDBEvents.h \ - IDBIndexRequest.h \ + IDBIndex.h \ IDBKeyRange.h \ - IDBObjectStoreRequest.h \ + IDBObjectStore.h \ IDBRequest.h \ - IDBTransactionRequest.h \ + IDBTransaction.h \ IndexedDatabase.h \ - IndexedDatabaseRequest.h \ + IDBFactory.h \ LazyIdleThread.h \ $(NULL) @@ -93,23 +93,18 @@ DEFINES += -D_IMPL_NS_LAYOUT # js/src/xpconnect/src/dom_quickstubs.qsconf. XPIDLSRCS = \ nsIIDBCursor.idl \ - nsIIDBCursorRequest.idl \ nsIIDBDatabase.idl \ nsIIDBDatabaseException.idl \ - nsIIDBDatabaseRequest.idl \ nsIIDBEvent.idl \ nsIIDBErrorEvent.idl \ nsIIDBIndex.idl \ - nsIIDBIndexRequest.idl \ nsIIDBKeyRange.idl \ nsIIDBObjectStore.idl \ - nsIIDBObjectStoreRequest.idl \ nsIIDBRequest.idl \ nsIIDBSuccessEvent.idl \ nsIIDBTransaction.idl \ nsIIDBTransactionEvent.idl \ - nsIIDBTransactionRequest.idl \ - nsIIndexedDatabaseRequest.idl \ + nsIIDBFactory.idl \ $(NULL) ifdef ENABLE_TESTS diff --git a/dom/indexedDB/Savepoint.h b/dom/indexedDB/Savepoint.h index a484637969a..7119fddb120 100644 --- a/dom/indexedDB/Savepoint.h +++ b/dom/indexedDB/Savepoint.h @@ -41,7 +41,7 @@ #define mozilla_dom_indexeddb_savepoint_h__ // Only meant to be included in IndexedDB source files, not exported. -#include "IDBTransactionRequest.h" +#include "IDBTransaction.h" BEGIN_INDEXEDDB_NAMESPACE @@ -49,7 +49,7 @@ NS_STACK_CLASS class Savepoint { public: - Savepoint(IDBTransactionRequest* aTransaction) + Savepoint(IDBTransaction* aTransaction) : mTransaction(aTransaction) , mHasSavepoint(false) { @@ -77,7 +77,7 @@ public: } private: - IDBTransactionRequest* mTransaction; + IDBTransaction* mTransaction; bool mHasSavepoint; }; diff --git a/dom/indexedDB/TransactionThreadPool.cpp b/dom/indexedDB/TransactionThreadPool.cpp index 5fb53040640..b421e532dd9 100644 --- a/dom/indexedDB/TransactionThreadPool.cpp +++ b/dom/indexedDB/TransactionThreadPool.cpp @@ -71,7 +71,7 @@ struct QueuedDispatchInfo : finish(false) { } - nsRefPtr transaction; + nsRefPtr transaction; nsCOMPtr runnable; nsCOMPtr finishRunnable; bool finish; @@ -83,11 +83,11 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE - inline FinishTransactionRunnable(IDBTransactionRequest* aTransaction, + inline FinishTransactionRunnable(IDBTransaction* aTransaction, nsCOMPtr& aFinishRunnable); private: - IDBTransactionRequest* mTransaction; + IDBTransaction* mTransaction; nsCOMPtr mFinishRunnable; }; @@ -189,13 +189,13 @@ TransactionThreadPool::Cleanup() } void -TransactionThreadPool::FinishTransaction(IDBTransactionRequest* aTransaction) +TransactionThreadPool::FinishTransaction(IDBTransaction* aTransaction) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aTransaction, "Null pointer!"); // AddRef here because removing from the hash will call Release. - nsRefPtr transaction(aTransaction); + nsRefPtr transaction(aTransaction); const PRUint32 databaseId = aTransaction->mDatabase->Id(); @@ -211,7 +211,7 @@ TransactionThreadPool::FinishTransaction(IDBTransactionRequest* aTransaction) PRUint32 count = transactionsInProgress.Length(); #ifdef DEBUG - if (aTransaction->mMode == IDBTransactionRequest::FULL_LOCK) { + if (aTransaction->mMode == IDBTransaction::FULL_LOCK) { NS_ASSERTION(dbTransactionInfo->locked, "Should be locked!"); NS_ASSERTION(count == 1, "More transactions running than should be!"); } @@ -255,7 +255,7 @@ TransactionThreadPool::FinishTransaction(IDBTransactionRequest* aTransaction) } bool -TransactionThreadPool::TransactionCanRun(IDBTransactionRequest* aTransaction, +TransactionThreadPool::TransactionCanRun(IDBTransaction* aTransaction, TransactionQueue** aQueue) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -279,7 +279,7 @@ TransactionThreadPool::TransactionCanRun(IDBTransactionRequest* aTransaction, PRUint32 transactionCount = transactionsInProgress.Length(); - if (mode == IDBTransactionRequest::FULL_LOCK) { + if (mode == IDBTransaction::FULL_LOCK) { switch (transactionCount) { case 0: { *aQueue = nsnull; @@ -390,7 +390,7 @@ TransactionThreadPool::TransactionCanRun(IDBTransactionRequest* aTransaction, } nsresult -TransactionThreadPool::Dispatch(IDBTransactionRequest* aTransaction, +TransactionThreadPool::Dispatch(IDBTransaction* aTransaction, nsIRunnable* aRunnable, bool aFinish, nsIRunnable* aFinishRunnable) @@ -423,7 +423,7 @@ TransactionThreadPool::Dispatch(IDBTransactionRequest* aTransaction, const PRUint32 databaseId = aTransaction->mDatabase->Id(); #ifdef DEBUG - if (aTransaction->mMode == IDBTransactionRequest::FULL_LOCK) { + if (aTransaction->mMode == IDBTransaction::FULL_LOCK) { NS_ASSERTION(!mTransactionsInProgress.Get(databaseId, nsnull), "Shouldn't have anything in progress!"); } @@ -438,7 +438,7 @@ TransactionThreadPool::Dispatch(IDBTransactionRequest* aTransaction, dbTransactionInfo = autoDBTransactionInfo; } - if (aTransaction->mMode == IDBTransactionRequest::FULL_LOCK) { + if (aTransaction->mMode == IDBTransaction::FULL_LOCK) { NS_ASSERTION(!dbTransactionInfo->locked, "Already locked?!"); dbTransactionInfo->locked = true; } @@ -494,7 +494,7 @@ TransactionThreadPool::Observe(nsISupports* /* aSubject */, } TransactionThreadPool:: -TransactionQueue::TransactionQueue(IDBTransactionRequest* aTransaction, +TransactionQueue::TransactionQueue(IDBTransaction* aTransaction, nsIRunnable* aRunnable) : mMutex("TransactionQueue::mMutex"), mCondVar(mMutex, "TransactionQueue::mCondVar"), @@ -585,7 +585,7 @@ TransactionThreadPool::TransactionQueue::Run() } FinishTransactionRunnable::FinishTransactionRunnable( - IDBTransactionRequest* aTransaction, + IDBTransaction* aTransaction, nsCOMPtr& aFinishRunnable) : mTransaction(aTransaction) { diff --git a/dom/indexedDB/TransactionThreadPool.h b/dom/indexedDB/TransactionThreadPool.h index 1fad4bed0f1..26b49d48bc3 100644 --- a/dom/indexedDB/TransactionThreadPool.h +++ b/dom/indexedDB/TransactionThreadPool.h @@ -51,7 +51,7 @@ #include "nsHashKeys.h" #include "nsRefPtrHashtable.h" -#include "IDBTransactionRequest.h" +#include "IDBTransaction.h" class nsIRunnable; class nsIThreadPool; @@ -73,7 +73,7 @@ public: static TransactionThreadPool* GetOrCreate(); static void Shutdown(); - nsresult Dispatch(IDBTransactionRequest* aTransaction, + nsresult Dispatch(IDBTransaction* aTransaction, nsIRunnable* aRunnable, bool aFinish, nsIRunnable* aFinishRunnable); @@ -85,7 +85,7 @@ protected: NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE - inline TransactionQueue(IDBTransactionRequest* aTransaction, + inline TransactionQueue(IDBTransaction* aTransaction, nsIRunnable* aRunnable); inline void Dispatch(nsIRunnable* aRunnable); @@ -95,7 +95,7 @@ protected: private: mozilla::Mutex mMutex; mozilla::CondVar mCondVar; - IDBTransactionRequest* mTransaction; + IDBTransaction* mTransaction; nsAutoTArray, 10> mQueue; nsCOMPtr mFinishRunnable; bool mShouldFinish; @@ -118,7 +118,7 @@ protected: : mode(nsIIDBTransaction::READ_ONLY) { } - nsRefPtr transaction; + nsRefPtr transaction; nsRefPtr queue; nsTArray objectStoreInfo; PRUint16 mode; @@ -141,9 +141,9 @@ protected: nsresult Init(); nsresult Cleanup(); - void FinishTransaction(IDBTransactionRequest* aTransaction); + void FinishTransaction(IDBTransaction* aTransaction); - bool TransactionCanRun(IDBTransactionRequest* aTransaction, + bool TransactionCanRun(IDBTransaction* aTransaction, TransactionQueue** aQueue); nsCOMPtr mThreadPool; diff --git a/dom/indexedDB/nsIIDBCursor.idl b/dom/indexedDB/nsIIDBCursor.idl index d8894b1b0bd..d104f071871 100644 --- a/dom/indexedDB/nsIIDBCursor.idl +++ b/dom/indexedDB/nsIIDBCursor.idl @@ -39,12 +39,19 @@ #include "nsISupports.idl" +interface nsIIDBRequest; +interface nsIVariant; + +%{C++ +#include "jsapi.h" +%} + /** * IDBCursor interface. See * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBCursor for more * information. */ -[scriptable, uuid(06b5980f-e5e1-433c-9df4-5ecef0238715)] +[scriptable, uuid(f0954b7d-b639-49ac-ad4b-b5e072fd0cc5)] interface nsIIDBCursor : nsISupports { const unsigned short NEXT = 0; @@ -52,4 +59,26 @@ interface nsIIDBCursor : nsISupports const unsigned short PREV = 2; const unsigned short PREV_NO_DUPLICATE = 3; readonly attribute unsigned short direction; + + readonly attribute nsIVariant key; + + [implicit_jscontext] + readonly attribute jsval value; + + // Returns true always for non-preloaded cursors. Calling continue means that + // the same onsuccess function will be called again with the new key/value + // (or null if no more matches). + // + // For preloaded cursors returns true if key/value have been set to new + // values. If false then no more matches are available and getting the key, + // value property will throw, as will calling update() and remove(). + [implicit_jscontext, optional_argc] + boolean continue([optional /* undefined */] in jsval key); + + // Success fires IDBTransactionEvent, result == key + [implicit_jscontext] + nsIIDBRequest update(in jsval value); + + // Success fires IDBTransactionEvent, result == null + nsIIDBRequest remove(); }; diff --git a/dom/indexedDB/nsIIDBCursorRequest.idl b/dom/indexedDB/nsIIDBCursorRequest.idl deleted file mode 100644 index 14aeddc35ed..00000000000 --- a/dom/indexedDB/nsIIDBCursorRequest.idl +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* ***** 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 Indexed Database. - * - * The Initial Developer of the Original Code is - * The Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2010 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ben Turner - * - * 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 ***** */ - -#include "nsIIDBCursor.idl" - -interface nsIIDBRequest; -interface nsIVariant; - -/** - * IDBCursorRequest interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBCursorRequest for more - * information. - */ -[scriptable, uuid(12ba5905-de6b-40f9-8c97-aec5f9dc706c)] -interface nsIIDBCursorRequest : nsIIDBCursor -{ - readonly attribute nsIVariant key; - - readonly attribute nsIVariant value; - - // Returns true always for non-preloaded cursors. Calling continue means that - // the same onsuccess function will be called again with the new key/value - // (or null if no more matches). - // - // For preloaded cursors returns true if key/value have been set to new - // values. If false then no more matches are available and getting the key, - // value property will throw, as will calling update() and remove(). - [optional_argc] - boolean continue([optional /* null */] in nsIVariant key); - - // Success fires IDBTransactionEvent, result == key - nsIIDBRequest update(in nsIVariant value); - - // Success fires IDBTransactionEvent, result == null - nsIIDBRequest remove(); -}; diff --git a/dom/indexedDB/nsIIDBDatabase.idl b/dom/indexedDB/nsIIDBDatabase.idl index 2645607e242..61aaf93975b 100644 --- a/dom/indexedDB/nsIIDBDatabase.idl +++ b/dom/indexedDB/nsIIDBDatabase.idl @@ -39,15 +39,18 @@ #include "nsISupports.idl" -interface nsIDOMDOMStringList; +interface nsIVariant; +interface nsIIDBObjectStore; +interface nsIIDBRequest; interface nsIIDBTransaction; +interface nsIDOMDOMStringList; /** * IDBDatabase interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBDatabase for more - * information. + * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBDatabase + * for more information. */ -[scriptable, uuid(828a5080-6912-4e4d-afe0-57846788eb2e)] +[scriptable, uuid(e258ad44-3306-427f-ac17-c528060c661a)] interface nsIIDBDatabase : nsISupports { readonly attribute DOMString name; @@ -57,4 +60,26 @@ interface nsIIDBDatabase : nsISupports readonly attribute DOMString version; readonly attribute nsIDOMDOMStringList objectStoreNames; + + nsIIDBRequest + createObjectStore(in AString name, + in AString keyPath, + [optional /* false */] in boolean autoIncrement); + + nsIIDBRequest + removeObjectStore(in AString name); + + nsIIDBRequest + setVersion(in AString version); + + [optional_argc] + nsIIDBTransaction + transaction(in nsIVariant storeNames, // js array of strings + [optional /* READ_ONLY */] in unsigned short mode, + [optional /* 5000ms */] in unsigned long timeout); + + [optional_argc] + nsIIDBObjectStore + objectStore(in AString name, + [optional /* READ_ONLY */] in unsigned short mode); }; diff --git a/dom/indexedDB/nsIIndexedDatabaseRequest.idl b/dom/indexedDB/nsIIDBFactory.idl similarity index 93% rename from dom/indexedDB/nsIIndexedDatabaseRequest.idl rename to dom/indexedDB/nsIIDBFactory.idl index 224081cf0fe..09d8dc6f172 100644 --- a/dom/indexedDB/nsIIndexedDatabaseRequest.idl +++ b/dom/indexedDB/nsIIDBFactory.idl @@ -46,11 +46,11 @@ interface nsIVariant; /** * Interface that defines the indexedDB property on a window. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IndexedDatabaseRequest + * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBFactory * for more information. */ -[scriptable, uuid(043161e0-93b8-43b4-94d8-f34046d679b4)] -interface nsIIndexedDatabaseRequest : nsISupports +[scriptable, uuid(a1e1dbd1-53a7-490a-ab6f-aa55809dd867)] +interface nsIIDBFactory : nsISupports { nsIIDBRequest open(in AString name, diff --git a/dom/indexedDB/nsIIDBIndex.idl b/dom/indexedDB/nsIIDBIndex.idl index db8015e4bf6..709ff4aa55f 100644 --- a/dom/indexedDB/nsIIDBIndex.idl +++ b/dom/indexedDB/nsIIDBIndex.idl @@ -39,12 +39,16 @@ #include "nsISupports.idl" +interface nsIIDBKeyRange; +interface nsIIDBRequest; +interface nsIVariant; + /** * IDBIndex interface. See * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBIndex for more * information. */ -[scriptable, uuid(7df8a6cc-d11a-48c9-9cd4-6d18a9df3c09)] +[scriptable, uuid(2451a60c-349a-4b7c-bab4-93ba8f52abec)] interface nsIIDBIndex : nsISupports { readonly attribute DOMString name; @@ -54,4 +58,33 @@ interface nsIIDBIndex : nsISupports readonly attribute DOMString keyPath; readonly attribute boolean unique; + + nsIIDBRequest + get(in nsIVariant key); + + nsIIDBRequest + getObject(in nsIVariant key); + + [optional_argc] + nsIIDBRequest + getAll([optional /* null */] in nsIVariant key, + [optional /* unlimited */] in unsigned long limit); + + [optional_argc] + nsIIDBRequest + getAllObjects([optional /* null */] in nsIVariant key, + [optional /* unlimited */] in unsigned long limit); + + [optional_argc] + nsIIDBRequest + openCursor([optional /* null */] in nsIIDBKeyRange range, + [optional /* nsIIDBCursor::NEXT */] in unsigned short direction, + [optional /* false */] in boolean preload); + + [optional_argc] + nsIIDBRequest + openObjectCursor([optional /* null */] in nsIIDBKeyRange range, + [optional /* nsIIDBCursor::NEXT */] + in unsigned short direction, + [optional /* false */] in boolean preload); }; diff --git a/dom/indexedDB/nsIIDBIndexRequest.idl b/dom/indexedDB/nsIIDBIndexRequest.idl deleted file mode 100644 index 90bc77d565a..00000000000 --- a/dom/indexedDB/nsIIDBIndexRequest.idl +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* ***** 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 Indexed Database. - * - * The Initial Developer of the Original Code is - * The Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2010 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ben Turner - * - * 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 ***** */ - -#include "nsIIDBIndex.idl" - -interface nsIIDBKeyRange; -interface nsIIDBRequest; -interface nsIVariant; - -/** - * IDBIndexRequest interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBIndexRequest for more - * information. - */ -[scriptable, uuid(8c21dfc3-62fa-470e-bc92-7d115b0fac97)] -interface nsIIDBIndexRequest : nsIIDBIndex -{ - nsIIDBRequest - get(in nsIVariant key); - - nsIIDBRequest - getObject(in nsIVariant key); - - [optional_argc] - nsIIDBRequest - getAll([optional /* null */] in nsIVariant key, - [optional /* unlimited */] in unsigned long limit); - - [optional_argc] - nsIIDBRequest - getAllObjects([optional /* null */] in nsIVariant key, - [optional /* unlimited */] in unsigned long limit); - - [optional_argc] - nsIIDBRequest - openCursor([optional /* null */] in nsIIDBKeyRange range, - [optional /* nsIIDBCursor::NEXT */] in unsigned short direction, - [optional /* false */] in boolean preload); - - [optional_argc] - nsIIDBRequest - openObjectCursor([optional /* null */] in nsIIDBKeyRange range, - [optional /* nsIIDBCursor::NEXT */] - in unsigned short direction, - [optional /* false */] in boolean preload); -}; diff --git a/dom/indexedDB/nsIIDBObjectStore.idl b/dom/indexedDB/nsIIDBObjectStore.idl index 8cae78523a2..e089f6c0ca7 100644 --- a/dom/indexedDB/nsIIDBObjectStore.idl +++ b/dom/indexedDB/nsIIDBObjectStore.idl @@ -39,14 +39,22 @@ #include "nsISupports.idl" +interface nsIIDBIndex; +interface nsIIDBKeyRange; +interface nsIIDBRequest; +interface nsIVariant; interface nsIDOMDOMStringList; +%{C++ +#include "jsapi.h" +%} + /** - * IDBObjectStore interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBObjectStore for more - * information. + * nsIIDBObjectStore interface. See + * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore + * for more information. */ -[scriptable, uuid(783a49b0-c5f0-4d97-9349-532f4ec1f7ce)] +[scriptable, uuid(9cb63602-a52f-4d21-b802-e7165143f83d)] interface nsIIDBObjectStore : nsISupports { readonly attribute DOMString name; @@ -54,4 +62,58 @@ interface nsIIDBObjectStore : nsISupports readonly attribute DOMString keyPath; readonly attribute nsIDOMDOMStringList indexNames; + + // Success fires IDBTransactionEvent, result == value for key + nsIIDBRequest + get(in nsIVariant key); + + // Success fires IDBTransactionEvent, result == array of values for given keys + [optional_argc] + nsIIDBRequest + getAll([optional /* null */] in nsIIDBKeyRange key, + [optional /* unlimited */] in unsigned long limit); + + // Success fires IDBTransactionEvent, result == key + [implicit_jscontext, optional_argc] + nsIIDBRequest + add(in jsval value, + [optional /* undefined */] in jsval key); + + // Success fires IDBTransactionEvent, result == key + [implicit_jscontext, optional_argc] + nsIIDBRequest + modify(in jsval value, + [optional /* undefined */] in jsval key); + + // Success fires IDBTransactionEvent, result == key + [implicit_jscontext, optional_argc] + nsIIDBRequest + addOrModify(in jsval value, + [optional /* undefined */] in jsval key); + + // Success fires IDBTransactionEvent, result == null + nsIIDBRequest + remove(in nsIVariant key); + + // Success fires IDBTransactionEvent, result == IDBCursor or + // IDBCursorPreloadedRequest if preload == true. result == null if no match. + [optional_argc] + nsIIDBRequest + openCursor([optional /* null */] in nsIIDBKeyRange range, + [optional /* NEXT */] in unsigned short direction, + [optional /* false */] in boolean preload); + + // Success fires IDBTransactionEvent, result == IDBIndex + nsIIDBRequest + createIndex(in AString name, + in AString keyPath, + [optional /* false */] in boolean unique); + + // Returns object immediately + nsIIDBIndex + index(in AString name); + + // Success fires IDBTransactionEvent, result == null + nsIIDBRequest + removeIndex(in AString name); }; diff --git a/dom/indexedDB/nsIIDBObjectStoreRequest.idl b/dom/indexedDB/nsIIDBObjectStoreRequest.idl deleted file mode 100644 index 3cf5bd26c88..00000000000 --- a/dom/indexedDB/nsIIDBObjectStoreRequest.idl +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* ***** 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 Indexed Database. - * - * The Initial Developer of the Original Code is - * The Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2010 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ben Turner - * - * 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 ***** */ - -#include "nsIIDBObjectStore.idl" - -interface nsIIDBIndexRequest; -interface nsIIDBKeyRange; -interface nsIIDBRequest; -interface nsIVariant; - -/** - * nsIIDBObjectStoreRequest interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStoreRequest - * for more information. - */ -[scriptable, uuid(ce65fbc2-06a0-4f1c-89e4-0d9a636179c7)] -interface nsIIDBObjectStoreRequest : nsIIDBObjectStore -{ - // Success fires IDBTransactionEvent, result == value for key - nsIIDBRequest - get(in nsIVariant key); - - // Success fires IDBTransactionEvent, result == array of values for given keys - [optional_argc] - nsIIDBRequest - getAll([optional /* null */] in nsIIDBKeyRange key, - [optional /* unlimited */] in unsigned long limit); - - // Success fires IDBTransactionEvent, result == key - nsIIDBRequest - add(in nsIVariant value, - [optional /* null */] in nsIVariant key); - - // Success fires IDBTransactionEvent, result == key - nsIIDBRequest - modify(in nsIVariant value, - [optional /* null */] in nsIVariant key); - - // Success fires IDBTransactionEvent, result == key - nsIIDBRequest - addOrModify(in nsIVariant value, - [optional /* null */] in nsIVariant key); - - // Success fires IDBTransactionEvent, result == null - nsIIDBRequest - remove(in nsIVariant key); - - // Success fires IDBTransactionEvent, result == IDBCursorRequest or - // IDBCursorPreloadedRequest if preload == true. result == null if no match. - [optional_argc] - nsIIDBRequest - openCursor([optional /* null */] in nsIIDBKeyRange range, - [optional /* NEXT */] in unsigned short direction, - [optional /* false */] in boolean preload); - - // Success fires IDBTransactionEvent, result == IDBIndexRequest - nsIIDBRequest - createIndex(in AString name, - in AString keyPath, - [optional /* false */] in boolean unique); - - // Returns object immediately - nsIIDBIndexRequest - index(in AString name); - - // Success fires IDBTransactionEvent, result == null - nsIIDBRequest - removeIndex(in AString name); -}; diff --git a/dom/indexedDB/nsIIDBSuccessEvent.idl b/dom/indexedDB/nsIIDBSuccessEvent.idl index af41f600283..6ca2a3616d8 100644 --- a/dom/indexedDB/nsIIDBSuccessEvent.idl +++ b/dom/indexedDB/nsIIDBSuccessEvent.idl @@ -39,10 +39,13 @@ #include "nsIIDBEvent.idl" -interface nsIVariant; +%{C++ +#include "jsapi.h" +%} [scriptable, uuid(9275d34f-54e1-4ab0-b4ca-f8d4359eec9c)] interface nsIIDBSuccessEvent : nsIIDBEvent { - readonly attribute nsIVariant result; + [implicit_jscontext] + readonly attribute jsval result; }; diff --git a/dom/indexedDB/nsIIDBTransaction.idl b/dom/indexedDB/nsIIDBTransaction.idl index 40a97675679..84cc0629c05 100644 --- a/dom/indexedDB/nsIIDBTransaction.idl +++ b/dom/indexedDB/nsIIDBTransaction.idl @@ -39,15 +39,18 @@ #include "nsISupports.idl" +interface nsIDOMEventListener; +interface nsIIDBObjectStore; +interface nsIIDBRequest; interface nsIIDBDatabase; interface nsIDOMDOMStringList; /** * IDBDTransaction interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBDTransaction for more - * information. + * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBTransaction + * for more information. */ -[scriptable, uuid(00c3f651-f4bf-416b-9dc4-759135a35fa9)] +[scriptable, uuid(99bb825e-56aa-4cb9-b640-4fadb00b874d)] interface nsIIDBTransaction : nsISupports { readonly attribute nsIIDBDatabase db; @@ -63,4 +66,24 @@ interface nsIIDBTransaction : nsISupports readonly attribute unsigned short mode; readonly attribute nsIDOMDOMStringList objectStoreNames; + + nsIIDBObjectStore + objectStore(in AString name); + + // Don't commit the transaction. + void abort(); + + // Event listener that fires when the transaction is completed + // successfully. Receives an Event. + attribute nsIDOMEventListener oncomplete; + + // Event listener that fires when the transaction is aborted. + // Receives an Event. + attribute nsIDOMEventListener onabort; + + // Event listener that fires when the transaction times out while + // attempting to grab the relevant locks, as specified by the + // timeoutSeconds parameter + // Receives an Event. + attribute nsIDOMEventListener ontimeout; }; diff --git a/dom/indexedDB/nsIIDBTransactionEvent.idl b/dom/indexedDB/nsIIDBTransactionEvent.idl index bdef0134386..1eee0b976b2 100644 --- a/dom/indexedDB/nsIIDBTransactionEvent.idl +++ b/dom/indexedDB/nsIIDBTransactionEvent.idl @@ -39,10 +39,10 @@ #include "nsIIDBSuccessEvent.idl" -interface nsIIDBTransactionRequest; +interface nsIIDBTransaction; -[scriptable, uuid(f84fa3ee-2df2-4d55-b8bc-27d7d9438336)] +[scriptable, uuid(cdf58757-78b9-4f5f-8559-1bf96e1cdfba)] interface nsIIDBTransactionEvent : nsIIDBSuccessEvent { - readonly attribute nsIIDBTransactionRequest transaction; + readonly attribute nsIIDBTransaction transaction; }; diff --git a/dom/indexedDB/nsIIDBTransactionRequest.idl b/dom/indexedDB/nsIIDBTransactionRequest.idl deleted file mode 100644 index b1b5af2ce2d..00000000000 --- a/dom/indexedDB/nsIIDBTransactionRequest.idl +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* ***** 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 Indexed Database. - * - * The Initial Developer of the Original Code is - * The Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2010 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ben Turner - * - * 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 ***** */ - -#include "nsIIDBTransaction.idl" - -interface nsIDOMEventListener; -interface nsIIDBObjectStoreRequest; -interface nsIIDBRequest; - -/** - * IDBDTransactionRequest interface. See - * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBDTransactionRequest for - * more information. - */ -[scriptable, uuid(073f5f2e-fecc-4f96-bba2-d8a90532c926)] -interface nsIIDBTransactionRequest : nsIIDBTransaction -{ - nsIIDBObjectStoreRequest - objectStore(in AString name); - - // Don't commit the transaction. - void abort(); - - // Event listener that fires when the transaction is completed - // successfully. Receives an Event. - attribute nsIDOMEventListener oncomplete; - - // Event listener that fires when the transaction is aborted. - // Receives an Event. - attribute nsIDOMEventListener onabort; - - // Event listener that fires when the transaction times out while - // attempting to grab the relevant locks, as specified by the - // timeoutSeconds parameter - // Receives an Event. - attribute nsIDOMEventListener ontimeout; -}; diff --git a/dom/interfaces/storage/nsIDOMStorageWindow.idl b/dom/interfaces/storage/nsIDOMStorageWindow.idl index 798adb42093..0c0bd0f08d6 100644 --- a/dom/interfaces/storage/nsIDOMStorageWindow.idl +++ b/dom/interfaces/storage/nsIDOMStorageWindow.idl @@ -48,7 +48,7 @@ interface nsIDOMStorageObsolete; interface nsIDOMStorage; interface nsIDOMStorageList; -interface nsIIndexedDatabaseRequest; +interface nsIIDBFactory; [scriptable, uuid(b6f6efd8-1bdc-43af-b8ef-6685d6260931)] interface nsIDOMStorageWindow : nsISupports @@ -71,5 +71,5 @@ interface nsIDOMStorageWindow : nsISupports /** * Indexed Databases for the current browsing context. */ - readonly attribute nsIIndexedDatabaseRequest moz_indexedDB; + readonly attribute nsIIDBFactory moz_indexedDB; }; diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index 5b59d05b60c..14ba6be54d5 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -61,4 +61,5 @@ EmptyGetElementByIdParam=Empty string passed to getElementById(). LowMemoryTitle=Warning: Low memory LowMemoryMessage=A script on this page has been stopped due to a low memory condition. WrongEventPropertyAccessWarning=The '%S' property of a %S event should not be used. The value is meaningless. +SpeculationFailed=An unbalanced tree was written using document.write() causing data from the network to be reparsed. For more information https://developer.mozilla.org/en/Optimizing_Your_Pages_for_Speculative_Parsing diff --git a/editor/composer/public/nsIEditingSession.idl b/editor/composer/public/nsIEditingSession.idl index d27715b851e..97866dac8ad 100644 --- a/editor/composer/public/nsIEditingSession.idl +++ b/editor/composer/public/nsIEditingSession.idl @@ -43,7 +43,7 @@ interface nsIEditor; -[scriptable, uuid(274cd32e-3675-47e1-9d8a-fc6504ded9ce)] +[scriptable, uuid(24f3f4da-18a4-448d-876d-7360fefac029)] interface nsIEditingSession : nsISupports { @@ -128,5 +128,10 @@ interface nsIEditingSession : nsISupports * to the window. */ void reattachToWindow(in nsIDOMWindow aWindow); + + /** + * Whether this session has disabled JS and plugins. + */ + readonly attribute boolean jsAndPluginsDisabled; }; diff --git a/editor/composer/src/nsEditingSession.cpp b/editor/composer/src/nsEditingSession.cpp index 2d172ee2e2f..8b758446102 100644 --- a/editor/composer/src/nsEditingSession.cpp +++ b/editor/composer/src/nsEditingSession.cpp @@ -261,6 +261,14 @@ nsEditingSession::RestoreJSAndPlugins(nsIDOMWindow *aWindow) return docShell->SetAllowPlugins(mPluginsEnabled); } +NS_IMETHODIMP +nsEditingSession::GetJsAndPluginsDisabled(PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = mDisabledJSAndPlugins; + return NS_OK; +} + /*--------------------------------------------------------------------------- WindowIsEditable diff --git a/editor/composer/test/Makefile.in b/editor/composer/test/Makefile.in index 9b7488c513c..ab969629cd3 100644 --- a/editor/composer/test/Makefile.in +++ b/editor/composer/test/Makefile.in @@ -48,6 +48,7 @@ _TEST_FILES = \ test_bug348497.html \ test_bug384147.html \ test_bug389350.html \ + test_bug519928.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/editor/composer/test/test_bug519928.html b/editor/composer/test/test_bug519928.html new file mode 100644 index 00000000000..a6986b286b0 --- /dev/null +++ b/editor/composer/test/test_bug519928.html @@ -0,0 +1,96 @@ + + + + + Test for Bug 519928 + + + + + +Mozilla Bug 519928 +

+
+ +
+
+
+
+ + + diff --git a/editor/idl/nsIEditorIMESupport.idl b/editor/idl/nsIEditorIMESupport.idl index 92baebcb45a..f6b9359779a 100644 --- a/editor/idl/nsIEditorIMESupport.idl +++ b/editor/idl/nsIEditorIMESupport.idl @@ -39,39 +39,10 @@ #include "nsISupports.idl" #include "domstubs.idl" -%{C++ -class nsIPrivateTextRangeList; -%} - -[ptr] native nsIPrivateTextRangeListPtr(nsIPrivateTextRangeList); - - -[scriptable, uuid(5cb3f9c9-5ab9-40fd-8ee2-0d1c7abd20dd)] +[scriptable, uuid(a64744c5-d3ff-46ba-b9b1-57f79ff7d97d)] interface nsIEditorIMESupport : nsISupports { - - - /** - * beginComposition() Handles the start of inline input composition. - */ - - [noscript] void beginComposition(); - - /** - * setCompositionString() Sets the inline input composition string. - * beginComposition must be called prior to this. - */ - - [noscript] void setCompositionString(in DOMString aCompositionString, - in nsIPrivateTextRangeListPtr aTextRange); - - /** - * endComposition() Handles the end of inline input composition. - */ - - [noscript] void endComposition(); - /** * forceCompositionEnd() force the composition end */ diff --git a/editor/libeditor/base/DeleteRangeTxn.cpp b/editor/libeditor/base/DeleteRangeTxn.cpp index 5caa0927b3b..58a5e8eb57a 100644 --- a/editor/libeditor/base/DeleteRangeTxn.cpp +++ b/editor/libeditor/base/DeleteRangeTxn.cpp @@ -204,7 +204,11 @@ NS_IMETHODIMP DeleteRangeTxn::DoTransaction(void) { nsCOMPtr selection; result = mEditor->GetSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(result, result); + // At this point, it is possible that the frame for our root element + // might have been destroyed, in which case, the above call returns + // an error. We eat that error here intentionally. See bug 574558 + // for a sample case where this happens. + NS_ENSURE_SUCCESS(result, NS_OK); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); result = selection->Collapse(mStartParent, mStartOffset); } diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index cebfc29d09f..c423f496227 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -1852,48 +1852,43 @@ nsEditor::StopPreservingSelection() #ifdef XP_MAC #pragma mark - -#pragma mark nsIEditorIMESupport +#pragma mark IME event handlers #pragma mark - #endif -// -// The BeingComposition method is called from the Editor Composition event listeners. -// -NS_IMETHODIMP -nsEditor::BeginComposition() +nsresult +nsEditor::BeginIMEComposition() { -#ifdef DEBUG_tague - printf("nsEditor::StartComposition\n"); -#endif mInIMEMode = PR_TRUE; - if (mPhonetic) + if (mPhonetic) { mPhonetic->Truncate(0); - + } return NS_OK; } -NS_IMETHODIMP -nsEditor::EndComposition(void) +nsresult +nsEditor::EndIMEComposition() { NS_ENSURE_TRUE(mInIMEMode, NS_OK); // nothing to do - - nsresult result = NS_OK; + + nsresult rv = NS_OK; // commit the IME transaction..we can get at it via the transaction mgr. // Note that this means IME won't work without an undo stack! - if (mTxnMgr) - { + if (mTxnMgr) { nsCOMPtr txn; - result = mTxnMgr->PeekUndoStack(getter_AddRefs(txn)); + rv = mTxnMgr->PeekUndoStack(getter_AddRefs(txn)); + NS_ASSERTION(NS_SUCCEEDED(rv), "PeekUndoStack() failed"); nsCOMPtr plcTxn = do_QueryInterface(txn); - if (plcTxn) - { - result = plcTxn->Commit(); + if (plcTxn) { + rv = plcTxn->Commit(); + NS_ASSERTION(NS_SUCCEEDED(rv), + "nsIAbsorbingTransaction::Commit() failed"); } } /* reset the data we need to construct a transaction */ - mIMETextNode = do_QueryInterface(nsnull); + mIMETextNode = nsnull; mIMETextOffset = 0; mIMEBufferLength = 0; mInIMEMode = PR_FALSE; @@ -1902,15 +1897,16 @@ nsEditor::EndComposition(void) // notify editor observers of action NotifyEditorObservers(); - return result; + return rv; } -NS_IMETHODIMP -nsEditor::SetCompositionString(const nsAString& aCompositionString, - nsIPrivateTextRangeList* aTextRangeList) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} + +#ifdef XP_MAC +#pragma mark - +#pragma mark nsIPhonetic +#pragma mark - +#endif + NS_IMETHODIMP nsEditor::GetPhonetic(nsAString& aPhonetic) @@ -1924,6 +1920,13 @@ nsEditor::GetPhonetic(nsAString& aPhonetic) } +#ifdef XP_MAC +#pragma mark - +#pragma mark nsIEditorIMESupport +#pragma mark - +#endif + + static nsresult GetEditorContentWindow(nsIDOMElement *aRoot, nsIWidget **aResult) { diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 845b2f74c86..397ceb4c72f 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -193,6 +193,12 @@ public: */ nsresult CreateHTMLContent(const nsAString& aTag, nsIContent** aContent); + // IME event handlers + virtual nsresult BeginIMEComposition(); + virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString, + nsIPrivateTextRangeList *aTextRange)=0; + nsresult EndIMEComposition(); + protected: nsCString mContentMIMEType; // MIME type of the doc we are editing. diff --git a/editor/libeditor/base/nsEditorEventListener.cpp b/editor/libeditor/base/nsEditorEventListener.cpp index 663351655be..8b8f183969c 100644 --- a/editor/libeditor/base/nsEditorEventListener.cpp +++ b/editor/libeditor/base/nsEditorEventListener.cpp @@ -500,7 +500,7 @@ nsEditorEventListener::HandleText(nsIDOMEvent* aTextEvent) return NS_OK; } - return mEditor->SetCompositionString(composedText, textRangeList); + return mEditor->UpdateIMEComposition(composedText, textRangeList); } /** @@ -773,14 +773,14 @@ NS_IMETHODIMP nsEditorEventListener::HandleStartComposition(nsIDOMEvent* aCompositionEvent) { NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_AVAILABLE); - return mEditor->BeginComposition(); + return mEditor->BeginIMEComposition(); } NS_IMETHODIMP nsEditorEventListener::HandleEndComposition(nsIDOMEvent* aCompositionEvent) { NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_AVAILABLE); - return mEditor->EndComposition(); + return mEditor->EndIMEComposition(); } /** diff --git a/editor/libeditor/base/nsSelectionState.cpp b/editor/libeditor/base/nsSelectionState.cpp index f8fe33ffdc6..000dce20005 100644 --- a/editor/libeditor/base/nsSelectionState.cpp +++ b/editor/libeditor/base/nsSelectionState.cpp @@ -249,7 +249,9 @@ nsRangeUpdater::SelAdjCreateNode(nsIDOMNode *aParent, PRInt32 aPosition) if (mLock) return NS_OK; // lock set by Will/DidReplaceParent, etc... NS_ENSURE_TRUE(aParent, NS_ERROR_NULL_POINTER); PRUint32 i, count = mArray.Length(); - NS_ENSURE_TRUE(count, NS_OK); + if (!count) { + return NS_OK; + } nsRangeStore *item; diff --git a/editor/libeditor/html/crashtests/574558-1.xhtml b/editor/libeditor/html/crashtests/574558-1.xhtml new file mode 100644 index 00000000000..6aac47072f6 --- /dev/null +++ b/editor/libeditor/html/crashtests/574558-1.xhtml @@ -0,0 +1,15 @@ +
diff --git a/editor/libeditor/html/crashtests/crashtests.list b/editor/libeditor/html/crashtests/crashtests.list index d697e0002de..52a814e4363 100644 --- a/editor/libeditor/html/crashtests/crashtests.list +++ b/editor/libeditor/html/crashtests/crashtests.list @@ -15,3 +15,4 @@ asserts(1) load 467647-1.html # bug 382210 load 503709-1.xhtml load 513375-1.xhtml load 535632-1.xhtml +load 574558-1.xhtml diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 820d8e36bc0..2578173058e 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -924,26 +924,77 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak() return res; } -NS_IMETHODIMP -nsPlaintextEditor::BeginComposition() +nsresult +nsPlaintextEditor::BeginIMEComposition() { NS_ENSURE_TRUE(!mInIMEMode, NS_OK); - if (IsPasswordEditor()) { - if (mRules) { - // Protect the edit rules object from dying - nsCOMPtr kungFuDeathGrip(mRules); + if (IsPasswordEditor()) { + NS_ENSURE_TRUE(mRules, NS_ERROR_NULL_POINTER); + // Protect the edit rules object from dying + nsCOMPtr kungFuDeathGrip(mRules); - nsIEditRules *p = mRules.get(); - nsTextEditRules *textEditRules = static_cast(p); - textEditRules->ResetIMETextPWBuf(); + nsTextEditRules *textEditRules = + static_cast(mRules.get()); + textEditRules->ResetIMETextPWBuf(); + } + + return nsEditor::BeginIMEComposition(); +} + +nsresult +nsPlaintextEditor::UpdateIMEComposition(const nsAString& aCompositionString, + nsIPrivateTextRangeList* aTextRangeList) +{ + if (!aTextRangeList && !aCompositionString.IsEmpty()) { + NS_ERROR("aTextRangeList is null but the composition string is not null"); + return NS_ERROR_NULL_POINTER; + } + + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED); + + nsCOMPtr selection; + nsresult rv = GetSelection(getter_AddRefs(selection)); + NS_ENSURE_SUCCESS(rv, rv); + + nsRefPtr caretP = ps->GetCaret(); + + // We should return caret position if it is possible. Because this event + // dispatcher always expects to be returned the correct caret position. + // But in following cases, we don't need to process the composition string, + // so, we only need to return the caret position. + + // aCompositionString.IsEmpty() && !mIMETextNode: + // Workaround for Windows IME bug 23558: We get every IME event twice. + // For escape keypress, this causes an empty string to be passed + // twice, which freaks out the editor. + + // aCompositionString.IsEmpty() && !aTextRangeList: + // Some Chinese IMEs for Linux are always composition string and text range + // list are empty when listing the Chinese characters. In this case, + // we don't need to process composition string too. See bug 271815. + + if (!aCompositionString.IsEmpty() || (mIMETextNode && aTextRangeList)) { + mIMETextRangeList = aTextRangeList; + + SetIsIMEComposing(); // We set mIsIMEComposing properly. + + rv = InsertText(aCompositionString); + + mIMEBufferLength = aCompositionString.Length(); + + if (caretP) { + caretP->SetCaretDOMSelection(selection); } - else { - return NS_ERROR_NULL_POINTER; + + // second part of 23558 fix: + if (aCompositionString.IsEmpty()) { + mIMETextNode = nsnull; } } - return nsEditor::BeginComposition(); + return rv; } NS_IMETHODIMP @@ -1617,68 +1668,6 @@ nsPlaintextEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) } -#ifdef XP_MAC -#pragma mark - -#pragma mark nsIEditorIMESupport overrides -#pragma mark - -#endif - -NS_IMETHODIMP -nsPlaintextEditor::SetCompositionString(const nsAString& aCompositionString, - nsIPrivateTextRangeList* aTextRangeList) -{ - if (!aTextRangeList && !aCompositionString.IsEmpty()) - { - NS_ERROR("aTextRangeList is null but the composition string is not null"); - return NS_ERROR_NULL_POINTER; - } - - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED); - - nsCOMPtr selection; - nsresult result = GetSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(result, result); - - nsRefPtr caretP = ps->GetCaret(); - - // We should return caret position if it is possible. Because this event - // dispatcher always expects to be returned the correct caret position. - // But in following cases, we don't need to process the composition string, - // so, we only need to return the caret position. - - // aCompositionString.IsEmpty() && !mIMETextNode: - // Workaround for Windows IME bug 23558: We get every IME event twice. - // For escape keypress, this causes an empty string to be passed - // twice, which freaks out the editor. - - // aCompositionString.IsEmpty() && !aTextRangeList: - // Some Chinese IMEs for Linux are always composition string and text range - // list are empty when listing the Chinese characters. In this case, - // we don't need to process composition string too. See bug 271815. - - if (!aCompositionString.IsEmpty() || (mIMETextNode && aTextRangeList)) - { - mIMETextRangeList = aTextRangeList; - - SetIsIMEComposing(); // We set mIsIMEComposing properly. - - result = InsertText(aCompositionString); - - mIMEBufferLength = aCompositionString.Length(); - - if (caretP) - caretP->SetCaretDOMSelection(selection); - - // second part of 23558 fix: - if (aCompositionString.IsEmpty()) - mIMETextNode = nsnull; - } - - - return result; -} - #ifdef XP_MAC #pragma mark - #pragma mark nsEditor overrides diff --git a/editor/libeditor/text/nsPlaintextEditor.h b/editor/libeditor/text/nsPlaintextEditor.h index 00e4131694c..87373866557 100644 --- a/editor/libeditor/text/nsPlaintextEditor.h +++ b/editor/libeditor/text/nsPlaintextEditor.h @@ -87,12 +87,7 @@ public: /* ------------ nsIEditorMailSupport overrides -------------- */ NS_DECL_NSIEDITORMAILSUPPORT - /* ------------ nsIEditorIMESupport overrides -------------- */ - NS_IMETHOD SetCompositionString(const nsAString &aCompositionString, - nsIPrivateTextRangeList *aTextRange); - /* ------------ Overrides of nsEditor interface methods -------------- */ - NS_IMETHOD BeginComposition(); NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement, const nsAString & aAttribute, const nsAString & aValue, @@ -152,6 +147,10 @@ public: virtual already_AddRefed GetPIDOMEventTarget(); + virtual nsresult BeginIMEComposition(); + virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString, + nsIPrivateTextRangeList *aTextRange); + /* ------------ Utility Routines, not part of public API -------------- */ NS_IMETHOD TypedText(const nsAString& aString, PRInt32 aAction); diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 9c0d47755bb..40a81f933fe 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -60,8 +60,6 @@ abstract public class GeckoApp public static GeckoSurfaceView surfaceView; public static GeckoApp mAppContext; - public static boolean useSoftwareDrawing; - void launch() { // unpack files in the components directory @@ -121,8 +119,6 @@ abstract public class GeckoApp new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); - useSoftwareDrawing = true; //isInEmulator() == 1; - if (!GeckoAppShell.sGeckoRunning) { // Load our JNI libs; we need to do this before launch() because // setInitialSize will be called even before Gecko is actually up diff --git a/embedding/android/GeckoInputConnection.java b/embedding/android/GeckoInputConnection.java new file mode 100644 index 00000000000..c1f124822ee --- /dev/null +++ b/embedding/android/GeckoInputConnection.java @@ -0,0 +1,174 @@ +/* -*- Mode: Java; tab-width: 20; indent-tabs-mode: nil; -*- + * ***** 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 Android code. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Michael Wu + * + * 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 ***** */ + +package org.mozilla.gecko; + +import java.io.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import android.os.*; +import android.app.*; +import android.text.*; +import android.view.*; +import android.view.inputmethod.*; +import android.content.*; + +import android.util.*; + +public class GeckoInputConnection + extends BaseInputConnection +{ + public GeckoInputConnection (View targetView) { + super(targetView, true); + mQueryResult = new SynchronousQueue(); + mExtractedText.partialStartOffset = -1; + mExtractedText.partialEndOffset = -1; + } + + @Override + public Editable getEditable() { + Log.i("GeckoAppJava", "getEditable"); + return null; + } + + @Override + public boolean beginBatchEdit() { + GeckoAppShell.sendEventToGecko(new GeckoEvent(true, null)); + return true; + } + @Override + public boolean commitCompletion(CompletionInfo text) { + Log.i("GeckoAppJava", "Stub: commitCompletion"); + return true; + } + @Override + public boolean commitText(CharSequence text, int newCursorPosition) { + GeckoAppShell.sendEventToGecko(new GeckoEvent(true, text.toString())); + endBatchEdit(); + return true; + } + @Override + public boolean deleteSurroundingText(int leftLength, int rightLength) { + GeckoAppShell.sendEventToGecko(new GeckoEvent(leftLength, rightLength)); + updateExtractedText(); + return true; + } + @Override + public boolean endBatchEdit() { + updateExtractedText(); + GeckoAppShell.sendEventToGecko(new GeckoEvent(false, null)); + return true; + } + @Override + public boolean finishComposingText() { + endBatchEdit(); + return true; + } + @Override + public int getCursorCapsMode(int reqModes) { + return 0; + } + @Override + public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) { + mExtractToken = req.token; + GeckoAppShell.sendEventToGecko(new GeckoEvent(false, 0)); + try { + mExtractedText.text = mQueryResult.take(); + mExtractedText.selectionStart = mSelectionStart; + mExtractedText.selectionEnd = mSelectionEnd; + } catch (InterruptedException e) { + Log.i("GeckoAppJava", "getExtractedText: Interrupted!"); + } + return mExtractedText; + } + @Override + public CharSequence getTextAfterCursor(int length, int flags) { + GeckoAppShell.sendEventToGecko(new GeckoEvent(true, length)); + try { + String result = mQueryResult.take(); + return result; + } catch (InterruptedException e) { + Log.i("GeckoAppJava", "getTextAfterCursor: Interrupted!"); + } + return null; + } + @Override + public CharSequence getTextBeforeCursor(int length, int flags) { + GeckoAppShell.sendEventToGecko(new GeckoEvent(false, length)); + try { + String result = mQueryResult.take(); + return result; + } catch (InterruptedException e) { + Log.i("GeckoAppJava", "getTextBeforeCursor: Interrupted!"); + } + return null; + } + @Override + public boolean setComposingText(CharSequence text, int newCursorPosition) { + beginBatchEdit(); + GeckoAppShell.sendEventToGecko(new GeckoEvent(true, text.toString())); + return true; + } + @Override + public boolean setSelection(int start, int end) { + Log.i("GeckoAppJava", "Stub: setSelection " + start + " " + end); + return true; + } + + private void updateExtractedText() { + GeckoAppShell.sendEventToGecko(new GeckoEvent(false, 0)); + try { + mExtractedText.text = mQueryResult.take(); + mExtractedText.selectionStart = mSelectionStart; + mExtractedText.selectionEnd = mSelectionEnd; + } catch (InterruptedException e) { + Log.i("GeckoAppJava", "getExtractedText: Interrupted!"); + } + + InputMethodManager imm = (InputMethodManager) + GeckoApp.surfaceView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.updateExtractedText(GeckoApp.surfaceView, mExtractToken, mExtractedText); + } + + int mExtractToken; + final ExtractedText mExtractedText = new ExtractedText(); + + int mSelectionStart, mSelectionEnd; + SynchronousQueue mQueryResult; +} diff --git a/embedding/android/GeckoSurfaceView.java b/embedding/android/GeckoSurfaceView.java index 8028b6463ab..a10fb05fb14 100644 --- a/embedding/android/GeckoSurfaceView.java +++ b/embedding/android/GeckoSurfaceView.java @@ -45,15 +45,6 @@ import java.util.concurrent.atomic.*; import java.util.zip.*; import java.nio.*; -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGL11; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLContext; -import javax.microedition.khronos.egl.EGLDisplay; -import javax.microedition.khronos.egl.EGLSurface; -import javax.microedition.khronos.opengles.GL; -import javax.microedition.khronos.opengles.GL10; - import android.os.*; import android.app.*; import android.text.*; @@ -85,9 +76,6 @@ class GeckoSurfaceView setFocusable(true); setFocusableInTouchMode(true); - if (!GeckoApp.useSoftwareDrawing) - startEgl(); - mWidth = 0; mHeight = 0; mBufferWidth = 0; @@ -98,284 +86,6 @@ class GeckoSurfaceView protected void finalize() throws Throwable { super.finalize(); - if (!GeckoApp.useSoftwareDrawing) - finishEgl(); - } - - private static final int EGL_OPENGL_ES2_BIT = 4; - private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; - - private void printConfig(EGL10 egl, EGLDisplay display, - EGLConfig config) { - int[] attributes = { - EGL10.EGL_BUFFER_SIZE, - EGL10.EGL_ALPHA_SIZE, - EGL10.EGL_BLUE_SIZE, - EGL10.EGL_GREEN_SIZE, - EGL10.EGL_RED_SIZE, - EGL10.EGL_DEPTH_SIZE, - EGL10.EGL_STENCIL_SIZE, - EGL10.EGL_CONFIG_CAVEAT, - EGL10.EGL_CONFIG_ID, - EGL10.EGL_LEVEL, - EGL10.EGL_MAX_PBUFFER_HEIGHT, - EGL10.EGL_MAX_PBUFFER_PIXELS, - EGL10.EGL_MAX_PBUFFER_WIDTH, - EGL10.EGL_NATIVE_RENDERABLE, - EGL10.EGL_NATIVE_VISUAL_ID, - EGL10.EGL_NATIVE_VISUAL_TYPE, - 0x3030, // EGL10.EGL_PRESERVED_RESOURCES, - EGL10.EGL_SAMPLES, - EGL10.EGL_SAMPLE_BUFFERS, - EGL10.EGL_SURFACE_TYPE, - EGL10.EGL_TRANSPARENT_TYPE, - EGL10.EGL_TRANSPARENT_RED_VALUE, - EGL10.EGL_TRANSPARENT_GREEN_VALUE, - EGL10.EGL_TRANSPARENT_BLUE_VALUE, - 0x3039, // EGL10.EGL_BIND_TO_TEXTURE_RGB, - 0x303A, // EGL10.EGL_BIND_TO_TEXTURE_RGBA, - 0x303B, // EGL10.EGL_MIN_SWAP_INTERVAL, - 0x303C, // EGL10.EGL_MAX_SWAP_INTERVAL, - EGL10.EGL_LUMINANCE_SIZE, - EGL10.EGL_ALPHA_MASK_SIZE, - EGL10.EGL_COLOR_BUFFER_TYPE, - EGL10.EGL_RENDERABLE_TYPE, - 0x3042 // EGL10.EGL_CONFORMANT - }; - String[] names = { - "EGL_BUFFER_SIZE", - "EGL_ALPHA_SIZE", - "EGL_BLUE_SIZE", - "EGL_GREEN_SIZE", - "EGL_RED_SIZE", - "EGL_DEPTH_SIZE", - "EGL_STENCIL_SIZE", - "EGL_CONFIG_CAVEAT", - "EGL_CONFIG_ID", - "EGL_LEVEL", - "EGL_MAX_PBUFFER_HEIGHT", - "EGL_MAX_PBUFFER_PIXELS", - "EGL_MAX_PBUFFER_WIDTH", - "EGL_NATIVE_RENDERABLE", - "EGL_NATIVE_VISUAL_ID", - "EGL_NATIVE_VISUAL_TYPE", - "EGL_PRESERVED_RESOURCES", - "EGL_SAMPLES", - "EGL_SAMPLE_BUFFERS", - "EGL_SURFACE_TYPE", - "EGL_TRANSPARENT_TYPE", - "EGL_TRANSPARENT_RED_VALUE", - "EGL_TRANSPARENT_GREEN_VALUE", - "EGL_TRANSPARENT_BLUE_VALUE", - "EGL_BIND_TO_TEXTURE_RGB", - "EGL_BIND_TO_TEXTURE_RGBA", - "EGL_MIN_SWAP_INTERVAL", - "EGL_MAX_SWAP_INTERVAL", - "EGL_LUMINANCE_SIZE", - "EGL_ALPHA_MASK_SIZE", - "EGL_COLOR_BUFFER_TYPE", - "EGL_RENDERABLE_TYPE", - "EGL_CONFORMANT" - }; - int[] value = new int[1]; - for (int i = 0; i < attributes.length; i++) { - int attribute = attributes[i]; - String name = names[i]; - if ( egl.eglGetConfigAttrib(display, config, attribute, value)) { - Log.w("GeckoAppJava", String.format(" %s: %d\n", name, value[0])); - } else { - Log.w("GeckoAppJava", String.format(" %s: failed\n", name)); - // while (egl.eglGetError() != EGL10.EGL_SUCCESS); - } - } - } - - public void startEgl() { - if (mEgl != null) - return; - - mEgl = (EGL10) EGLContext.getEGL(); - mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); - - // initialize egl - int[] version = new int[2]; - mEgl.eglInitialize(mEglDisplay, version); - - // flip this to true to dump all the EGL configs - if (false) { - int[] cs = { EGL10.EGL_NONE }; - int[] ptrnum = new int[1]; - - mEgl.eglChooseConfig(mEglDisplay, cs, null, 0, ptrnum); - - int num = ptrnum[0]; - EGLConfig[] confs = new EGLConfig[num]; - - mEgl.eglChooseConfig(mEglDisplay, cs, confs, num, ptrnum); - - for (int i = 0; i < num; ++i) { - Log.w("GeckoAppJava", "=== EGL config " + i + " ==="); - printConfig(mEgl, mEglDisplay, confs[i]); - } - } - } - - public void finishEgl() { - if (mEglDisplay != null) { - mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, - EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); - } - - if (mEglContext != null) { - mEgl.eglDestroyContext(mEglDisplay, mEglContext); - mEglContext = null; - } - - if (mEglSurface != null) { - mEgl.eglDestroySurface(mEglDisplay, mEglSurface); - mEglSurface = null; - } - - if (mEglDisplay != null) { - mEgl.eglTerminate(mEglDisplay); - mEglDisplay = null; - } - - mEglConfig = null; - mEgl = null; - - mSurfaceChanged = false; - } - - public void chooseEglConfig() { - int redBits, greenBits, blueBits, alphaBits; - - // There are some shenanigans here. - // We're required to choose an exact EGL config to match - // the surface format, or we get an error. However, - // on Droid at least, the format is -1, which is PixelFormat.OPAQUE. - // That's not a valid format to be reported; that should just be a - // valid value for *setFormat*. We have a catch-all case that - // assumes 565 for those cases, but it's pretty ugly. - - Log.i("GeckoAppJava", "GeckoView PixelFormat format is " + mFormat); - if (mFormat == PixelFormat.RGB_565) { - redBits = 5; - greenBits = 6; - blueBits = 5; - alphaBits = 0; - } else if (mFormat == PixelFormat.RGB_888 || - mFormat == PixelFormat.RGBX_8888) - { - redBits = 8; - greenBits = 8; - blueBits = 8; - alphaBits = 0; - } else if (mFormat == PixelFormat.RGBA_8888) { - redBits = 8; - greenBits = 8; - blueBits = 8; - alphaBits = 8; - } else { - Log.w("GeckoAppJava", "Unknown PixelFormat for surface (format is " + mFormat + "), assuming 5650!"); - redBits = 5; - greenBits = 6; - blueBits = 5; - alphaBits = 0; - } - - // PowerVR SGX (Droid) seems to really want depth == 24 for - // performance, even 0 is slower. However, other platforms, - // like Tegra, don't -have- a 24 bit depth config (have 16). - // So that's not good. We'll try with 24 first, and if - // nothing, then we'll go to 0. I'm not sure what the nexus - // one chip wants. - - int[] confSpec = new int[] { - // DEPTH_SIZE must be the first pair - EGL10.EGL_DEPTH_SIZE, 24, - EGL10.EGL_RED_SIZE, redBits, - EGL10.EGL_GREEN_SIZE, greenBits, - EGL10.EGL_BLUE_SIZE, blueBits, - EGL10.EGL_ALPHA_SIZE, alphaBits, - EGL10.EGL_STENCIL_SIZE, 0, - EGL10.EGL_CONFIG_CAVEAT, EGL10.EGL_NONE, - EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL10.EGL_NONE }; - - // so tortured to pass an int as an out param... - int[] ptrNumConfigs = new int[1]; - mEgl.eglChooseConfig(mEglDisplay, confSpec, null, 0, ptrNumConfigs); - - int numConfigs = ptrNumConfigs[0]; - - if (numConfigs == 0) { - // twiddle the DEPTH_SIZE value - confSpec[1] = 0; - Log.i("GeckoAppJava", "Couldn't find any valid EGL configs with 24 bit depth, trying 0."); - - mEgl.eglChooseConfig(mEglDisplay, confSpec, null, 0, ptrNumConfigs); - numConfigs = ptrNumConfigs[0]; - } - - if (numConfigs <= 0) { - // couldn't find a config? - Log.w("GeckoAppJava", "Couldn't find any valid EGL configs, blindly trying them all!"); - - int[] fallbackConfSpec = new int[] { - EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL10.EGL_NONE }; - confSpec = fallbackConfSpec; - - mEgl.eglChooseConfig(mEglDisplay, confSpec, null, 0, ptrNumConfigs); - numConfigs = ptrNumConfigs[0]; - - if (numConfigs == 0) { - Log.e("GeckoAppJava", "There aren't any EGL configs available on this system."); - finishEgl(); - mSurfaceValid = false; - return; - } - } - - EGLConfig[] configs = new EGLConfig[numConfigs]; - mEgl.eglChooseConfig(mEglDisplay, confSpec, configs, numConfigs, ptrNumConfigs); - - // Find the first config that has the exact RGB sizes that we - // need for our window surface. - int[] ptrVal = new int[1]; - for (int i = 0; i < configs.length; ++i) { - int confRed = -1, confGreen = -1, confBlue = -1, confAlpha = -1; - - if (mEgl.eglGetConfigAttrib(mEglDisplay, configs[i], EGL10.EGL_RED_SIZE, ptrVal)) - confRed = ptrVal[0]; - if (mEgl.eglGetConfigAttrib(mEglDisplay, configs[i], EGL10.EGL_GREEN_SIZE, ptrVal)) - confGreen = ptrVal[0]; - if (mEgl.eglGetConfigAttrib(mEglDisplay, configs[i], EGL10.EGL_BLUE_SIZE, ptrVal)) - confBlue = ptrVal[0]; - if (mEgl.eglGetConfigAttrib(mEglDisplay, configs[i], EGL10.EGL_ALPHA_SIZE, ptrVal)) - confAlpha = ptrVal[0]; - - if (confRed == redBits && - confGreen == greenBits && - confBlue == blueBits && - confAlpha == alphaBits) - { - mEglConfig = configs[i]; - break; - } - } - - if (mEglConfig == null) { - Log.w("GeckoAppJava", "Couldn't find EGL config matching colors; using first, hope it works!"); - mEglConfig = configs[0]; - } - - Log.i("GeckoAppJava", "====== Chosen config: ======"); - printConfig(mEgl, mEglDisplay, mEglConfig); - - mEglContext = null; - mEglSurface = null; } /* @@ -390,6 +100,13 @@ class GeckoSurfaceView Log.w("GeckoAppJava", "surfaceChanged while mInDrawing is true!"); } + if (width == 0 || height == 0) + mSoftwareBuffer = null; + else if (mSoftwareBuffer == null || + mSoftwareBuffer.capacity() < (width * height * 2) || + mWidth != width || mHeight != height) + mSoftwareBuffer = ByteBuffer.allocateDirect(width * height * 2); + mFormat = format; mWidth = width; mHeight = height; @@ -397,10 +114,6 @@ class GeckoSurfaceView Log.i("GeckoAppJava", "surfaceChanged: fmt: " + format + " dim: " + width + " " + height); - if (!GeckoApp.useSoftwareDrawing) { - chooseEglConfig(); - } - // XXX This code doesn't seem to actually get hit if (!GeckoAppShell.sGeckoRunning) { GeckoAppShell.setInitialSize(width, height); @@ -416,8 +129,6 @@ class GeckoSurfaceView } mSurfaceChanged = true; - - //Log.i("GeckoAppJava", "<< surfaceChanged"); } finally { mSurfaceLock.unlock(); } @@ -431,14 +142,10 @@ class GeckoSurfaceView public void surfaceDestroyed(SurfaceHolder holder) { Log.i("GeckoAppJava", "surface destroyed"); mSurfaceValid = false; + mSoftwareBuffer = null; } public ByteBuffer getSoftwareDrawBuffer() { - //#ifdef DEBUG - if (!mSurfaceLock.isHeldByCurrentThread()) - Log.e("GeckoAppJava", "getSoftwareDrawBuffer called outside of mSurfaceLock!"); - //#endif - return mSoftwareBuffer; } @@ -448,108 +155,8 @@ class GeckoSurfaceView public static final int DRAW_ERROR = 0; public static final int DRAW_GLES_2 = 1; - public static final int DRAW_SOFTWARE = 2; - - int innerBeginDrawing() { - /* - * Software (non-GL) rendering - */ - if (GeckoApp.useSoftwareDrawing) { - if (mWidth != mBufferWidth || - mHeight != mBufferHeight || - mSurfaceChanged) - { - if (mWidth*mHeight != mBufferWidth*mBufferHeight) - mSoftwareBuffer = ByteBuffer.allocateDirect(mWidth*mHeight*4); - - mSoftwareBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); - - mBufferWidth = mWidth; - mBufferHeight = mHeight; - mSurfaceChanged = false; - } - - mSoftwareCanvas = getHolder().lockCanvas(null); - if (mSoftwareCanvas == null) { - Log.e("GeckoAppJava", "lockCanvas failed! << beginDrawing"); - return DRAW_ERROR; - } - - return DRAW_SOFTWARE; - } - - /* - * GL rendering - */ - - if (mEgl == null || mEglDisplay == null || mEglConfig == null) { - Log.e("GeckoAppJava", "beginDrawing called, but EGL was never initialized!"); - - mSurfaceLock.unlock(); - return DRAW_ERROR; - } - - /* - * If the surface doesn't exist, or if its dimensions or something else changed, - * recreate it. - */ - if (mEglSurface == null || - mWidth != mBufferWidth || - mHeight != mBufferHeight || - mSurfaceChanged) - { - if (mEglContext != null) { - mEgl.eglDestroyContext(mEglDisplay, mEglContext); - mEglContext = null; - } - - if (mEglSurface != null) - mEgl.eglDestroySurface(mEglDisplay, mEglSurface); - - mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, getHolder(), null); - if (mEglSurface == EGL10.EGL_NO_SURFACE) - { - Log.e("GeckoAppJava", "eglCreateWindowSurface failed!"); - mSurfaceValid = false; - return DRAW_ERROR; - } - - mBufferWidth = mWidth; - mBufferHeight = mHeight; - - mSurfaceChanged = false; - } - - if (mEglContext == null) { - int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, - EGL10.EGL_NONE }; - mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); - if (mEglContext == EGL10.EGL_NO_CONTEXT) - { - Log.e("GeckoAppJava", "eglCreateContext failed! " + mEgl.eglGetError()); - mSurfaceValid = false; - return DRAW_ERROR; - } - - Log.i("GeckoAppJava", "EglContext created"); - } - - // Hmm, should we issue this makecurrent for each frame? - // We'll likely have to, as other bits might switch the context (e.g. - // WebGL, video, etc.). - - if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { - int err = mEgl.eglGetError(); - Log.e("GeckoAppJava", "eglMakeCurrent failed! " + err); - return DRAW_ERROR; - } - - return DRAW_GLES_2; - } public int beginDrawing() { - //Log.i("GeckoAppJava", ">> beginDrawing"); - if (mInDrawing) { Log.e("GeckoAppJava", "Recursive beginDrawing call!"); return DRAW_ERROR; @@ -574,21 +181,11 @@ class GeckoSurfaceView return DRAW_ERROR; } - // call the inner function to do the work, so we can sanely unlock on error - int result = innerBeginDrawing(); - - if (result == DRAW_ERROR) { - mSurfaceLock.unlock(); - return DRAW_ERROR; - } - mInDrawing = true; - return result; + return DRAW_GLES_2; } public void endDrawing() { - //Log.w("GeckoAppJava", ">> endDrawing"); - if (!mInDrawing) { Log.e("GeckoAppJava", "endDrawing without beginDrawing!"); return; @@ -599,41 +196,36 @@ class GeckoSurfaceView Log.e("GeckoAppJava", "endDrawing with false mSurfaceValid"); return; } - - if (GeckoApp.useSoftwareDrawing) { - if (!mSurfaceChanged) { - mSoftwareBitmap.copyPixelsFromBuffer(mSoftwareBuffer); - mSoftwareCanvas.drawBitmap(mSoftwareBitmap, 0, 0, null); - - getHolder().unlockCanvasAndPost(mSoftwareCanvas); - mSoftwareCanvas = null; - } - } else { - // If the surface was changed while we were drawing; - // don't even bother trying to swap, it won't work, - // and may cause further problems. Note that - // eglSwapBuffers might also throw an - // IllegalArgumentException; we catch that as well. - if (!mSurfaceChanged) { - mEgl.eglSwapBuffers(mEglDisplay, mEglSurface); - if (mEgl.eglGetError() == EGL11.EGL_CONTEXT_LOST) - mSurfaceChanged = true; - } - } } catch (java.lang.IllegalArgumentException ex) { mSurfaceChanged = true; } finally { mInDrawing = false; - //#ifdef DEBUG if (!mSurfaceLock.isHeldByCurrentThread()) Log.e("GeckoAppJava", "endDrawing while mSurfaceLock not held by current thread!"); - //#endif mSurfaceLock.unlock(); } } + public void draw2D(ByteBuffer buffer) { + Canvas c = getHolder().lockCanvas(); + if (c == null) + return; + if (buffer != mSoftwareBuffer) { + getHolder().unlockCanvasAndPost(c); + return; + } + if (mSoftwareBitmap == null || + mSoftwareBitmap.getHeight() != mHeight || + mSoftwareBitmap.getWidth() != mWidth) { + mSoftwareBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.RGB_565); + } + mSoftwareBitmap.copyPixelsFromBuffer(mSoftwareBuffer); + c.drawBitmap(mSoftwareBitmap, 0, 0, null); + getHolder().unlockCanvasAndPost(c); + } + @Override public boolean onCheckIsTextEditor () { return false; @@ -718,141 +310,4 @@ class GeckoSurfaceView // Software rendering ByteBuffer mSoftwareBuffer; Bitmap mSoftwareBitmap; - Canvas mSoftwareCanvas; - - // GL rendering - EGL10 mEgl; - EGLDisplay mEglDisplay; - EGLSurface mEglSurface; - EGLConfig mEglConfig; - EGLContext mEglContext; -} - -class GeckoInputConnection - extends BaseInputConnection -{ - public GeckoInputConnection (View targetView) { - super(targetView, true); - mQueryResult = new SynchronousQueue(); - mExtractedText.partialStartOffset = -1; - mExtractedText.partialEndOffset = -1; - } - - @Override - public Editable getEditable() { - Log.i("GeckoAppJava", "getEditable"); - return null; - } - - @Override - public boolean beginBatchEdit() { - if (mComposing) - return true; - GeckoAppShell.sendEventToGecko(new GeckoEvent(true, null)); - mComposing = true; - return true; - } - @Override - public boolean commitCompletion(CompletionInfo text) { - Log.i("GeckoAppJava", "Stub: commitCompletion"); - return true; - } - @Override - public boolean commitText(CharSequence text, int newCursorPosition) { - GeckoAppShell.sendEventToGecko(new GeckoEvent(true, text.toString())); - endBatchEdit(); - return true; - } - @Override - public boolean deleteSurroundingText(int leftLength, int rightLength) { - GeckoAppShell.sendEventToGecko(new GeckoEvent(leftLength, rightLength)); - updateExtractedText(); - return true; - } - @Override - public boolean endBatchEdit() { - updateExtractedText(); - if (!mComposing) - return true; - GeckoAppShell.sendEventToGecko(new GeckoEvent(false, null)); - mComposing = false; - return true; - } - @Override - public boolean finishComposingText() { - endBatchEdit(); - return true; - } - @Override - public int getCursorCapsMode(int reqModes) { - return 0; - } - @Override - public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) { - mExtractToken = req.token; - GeckoAppShell.sendEventToGecko(new GeckoEvent(false, 0)); - try { - mExtractedText.text = mQueryResult.take(); - mExtractedText.selectionStart = mSelectionStart; - mExtractedText.selectionEnd = mSelectionEnd; - } catch (InterruptedException e) { - Log.i("GeckoAppJava", "getExtractedText: Interrupted!"); - } - return mExtractedText; - } - @Override - public CharSequence getTextAfterCursor(int length, int flags) { - GeckoAppShell.sendEventToGecko(new GeckoEvent(true, length)); - try { - String result = mQueryResult.take(); - return result; - } catch (InterruptedException e) { - Log.i("GeckoAppJava", "getTextAfterCursor: Interrupted!"); - } - return null; - } - @Override - public CharSequence getTextBeforeCursor(int length, int flags) { - GeckoAppShell.sendEventToGecko(new GeckoEvent(false, length)); - try { - String result = mQueryResult.take(); - return result; - } catch (InterruptedException e) { - Log.i("GeckoAppJava", "getTextBeforeCursor: Interrupted!"); - } - return null; - } - @Override - public boolean setComposingText(CharSequence text, int newCursorPosition) { - beginBatchEdit(); - GeckoAppShell.sendEventToGecko(new GeckoEvent(true, text.toString())); - return true; - } - @Override - public boolean setSelection(int start, int end) { - Log.i("GeckoAppJava", "Stub: setSelection " + start + " " + end); - return true; - } - - private void updateExtractedText() { - GeckoAppShell.sendEventToGecko(new GeckoEvent(false, 0)); - try { - mExtractedText.text = mQueryResult.take(); - mExtractedText.selectionStart = mSelectionStart; - mExtractedText.selectionEnd = mSelectionEnd; - } catch (InterruptedException e) { - Log.i("GeckoAppJava", "getExtractedText: Interrupted!"); - } - - InputMethodManager imm = (InputMethodManager) - GeckoApp.surfaceView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.updateExtractedText(GeckoApp.surfaceView, mExtractToken, mExtractedText); - } - - boolean mComposing; - int mExtractToken; - final ExtractedText mExtractedText = new ExtractedText(); - - int mSelectionStart, mSelectionEnd; - SynchronousQueue mQueryResult; } diff --git a/embedding/android/Makefile.in b/embedding/android/Makefile.in index 51e1c0c6d28..8bc3c457a70 100644 --- a/embedding/android/Makefile.in +++ b/embedding/android/Makefile.in @@ -48,6 +48,7 @@ JAVAFILES = \ GeckoAppShell.java \ GeckoEvent.java \ GeckoSurfaceView.java \ + GeckoInputConnection.java \ $(NULL) DEFINES += \ diff --git a/embedding/components/find/src/nsFind.cpp b/embedding/components/find/src/nsFind.cpp index 6bbf4e68b0d..884cf97ae2b 100644 --- a/embedding/components/find/src/nsFind.cpp +++ b/embedding/components/find/src/nsFind.cpp @@ -74,6 +74,10 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); #define CH_SHY ((PRUnichar) 0xAD) +// nsFind::Find casts CH_SHY to char before calling StripChars +// This works correctly if and only if CH_SHY <= 255 +PR_STATIC_ASSERT(CH_SHY <= 255); + // ----------------------------------------------------------------------- // nsFindContentIterator is a special iterator that also goes through // any existing + + diff --git a/layout/base/crashtests/534768-1.html b/layout/base/crashtests/534768-1.html new file mode 100644 index 00000000000..17c9ac68fe0 --- /dev/null +++ b/layout/base/crashtests/534768-1.html @@ -0,0 +1,23 @@ + + + + + + + ‮ + + diff --git a/layout/base/crashtests/534768-2.html b/layout/base/crashtests/534768-2.html new file mode 100644 index 00000000000..67ecb4b6bd9 --- /dev/null +++ b/layout/base/crashtests/534768-2.html @@ -0,0 +1,22 @@ + + + + + + + ‮ + + diff --git a/layout/base/crashtests/536720.xul b/layout/base/crashtests/536720.xul new file mode 100644 index 00000000000..2b8c0b61437 --- /dev/null +++ b/layout/base/crashtests/536720.xul @@ -0,0 +1,23 @@ + + + + + + + + +T + + + diff --git a/layout/base/crashtests/540760.xul b/layout/base/crashtests/540760.xul new file mode 100644 index 00000000000..b0e857ec9fc --- /dev/null +++ b/layout/base/crashtests/540760.xul @@ -0,0 +1,18 @@ + + + + + + + diff --git a/layout/base/crashtests/540771-1.xhtml b/layout/base/crashtests/540771-1.xhtml new file mode 100644 index 00000000000..3830e148d66 --- /dev/null +++ b/layout/base/crashtests/540771-1.xhtml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/layout/base/crashtests/572003.xul b/layout/base/crashtests/572003.xul new file mode 100644 index 00000000000..10488fc6462 --- /dev/null +++ b/layout/base/crashtests/572003.xul @@ -0,0 +1,3 @@ + +P + diff --git a/layout/base/crashtests/crashtests.list b/layout/base/crashtests/crashtests.list index 5ab1dfebdbf..c1408d50eb4 100644 --- a/layout/base/crashtests/crashtests.list +++ b/layout/base/crashtests/crashtests.list @@ -269,6 +269,7 @@ load 492014.xhtml load 492112-1.xhtml load 492163-1.xhtml load 495350-1.html +load 496011-1.xhtml load 497519-1.xhtml load 497519-2.xhtml load 499741-1.xhtml @@ -281,19 +282,25 @@ load 522374-1.html load 522374-2.html load 526378-1.xul load 534367-1.xhtml +load 534768-1.html +load 534768-2.html load 535721-1.xhtml load 535911-1.xhtml load 536623-1.xhtml +load 536720.xul load 537059-1.xhtml load 537141-1.xhtml load 537562-1.xhtml load 538082-1.xul load 538207-1.xhtml load 538210-1.html +load 540760.xul +load 540771-1.xhtml load 541869-1.xhtml load 541869-2.html load 560441-1.xhtml load 560447-1.html load 564063-1.html load 567292-1.xhtml +load 572003.xul load 572582-1.xhtml diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index d6a58e03d57..e46a45465e3 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -110,6 +110,7 @@ #include "nsCopySupport.h" #include "nsIDOMHTMLFrameSetElement.h" #ifdef MOZ_XUL +#include "nsIXULWindow.h" #include "nsIXULDocument.h" #include "nsXULPopupManager.h" #endif @@ -1943,7 +1944,24 @@ DocumentViewerImpl::Show(void) } } - if (mWindow) { + // XXX - If this DocumentViewer belongs to an nsIXULWindow that will at some + // point in the future call 'Show' on its window, we shouldn't call it. + // See bug 574690. + nsCOMPtr treeItem = do_QueryReferent(mContainer); + nsCOMPtr xulWin; + PRBool willShowWindow = PR_FALSE; + if (treeItem) { + nsCOMPtr owner; + treeItem->GetTreeOwner(getter_AddRefs(owner)); + if (owner) { + xulWin = do_GetInterface(owner); + if (xulWin) { + xulWin->WillShowWindow(&willShowWindow); + } + } + } + + if (mWindow && !willShowWindow) { mWindow->Show(PR_TRUE); } diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 5ec5d552067..36beac6095c 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -248,9 +248,7 @@ nsLayoutUtils::GetChildListNameFor(nsIFrame* aChildFrame) : nsnull; NS_ASSERTION(!firstPopup || !firstPopup->GetNextSibling(), "We assume popupList only has one child, but it has more."); - listName = (!firstPopup || firstPopup == aChildFrame) - ? nsGkAtoms::popupList - : nsnull; + listName = firstPopup == aChildFrame ? nsGkAtoms::popupList : nsnull; } else if (nsGkAtoms::tableColGroupFrame == childType) { listName = nsGkAtoms::colGroupList; } else if (nsGkAtoms::tableCaptionFrame == aChildFrame->GetType()) { @@ -2193,8 +2191,10 @@ nsLayoutUtils::ComputeWidthDependentValue( nscoord aContainingBlockWidth, const nsStyleCoord& aCoord) { - NS_PRECONDITION(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE, - "unconstrained widths no longer supported"); + NS_WARN_IF_FALSE(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE, + "have unconstrained width; this should only result from " + "very large sizes, not attempts at intrinsic width " + "calculation"); if (eStyleUnit_Coord == aCoord.GetUnit()) { return aCoord.GetCoordValue(); diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index dc30f1103f9..73c7e3ab8c0 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -5824,9 +5824,7 @@ static void DrawThebesLayer(ThebesLayer* aLayer, PaintParams* params = static_cast(aCallbackData); nsIFrame* frame = params->mFrame; if (frame) { - // We're drawing into a child window. Don't pass - // nsLayoutUtils::PAINT_WIDGET_LAYERS, since that will draw into - // the widget for the display root. + // We're drawing into a child window. nsIDeviceContext* devCtx = frame->PresContext()->DeviceContext(); nsCOMPtr rc; nsresult rv = devCtx->CreateRenderingContextInstance(*getter_AddRefs(rc)); @@ -5837,7 +5835,8 @@ static void DrawThebesLayer(ThebesLayer* aLayer, nsIRenderingContext::AutoPushTranslation push(rc, -params->mOffsetToWidget.x, -params->mOffsetToWidget.y); nsLayoutUtils::PaintFrame(rc, frame, dirtyRegion, - params->mBackgroundColor); + params->mBackgroundColor, + nsLayoutUtils::PAINT_WIDGET_LAYERS); } } else { aContext->NewPath(); @@ -6567,10 +6566,7 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, return NS_OK; } - nsCOMPtr domNode(do_QueryInterface(mDocument)); - NS_ASSERTION(domNode, "No dom node for doc"); - - accEvent->mAccessible = accService->GetAccessibleInShell(domNode, this); + accEvent->mAccessible = accService->GetAccessibleInShell(mDocument, this); // Ensure this is set in case a11y was activated before any // nsPresShells existed to observe "a11y-init-or-shutdown" topic @@ -6998,11 +6994,12 @@ PresShell::GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl, // don't check menulists as the selected item will be inside a popup. nsCOMPtr menulist = do_QueryInterface(aCurrentEl); if (!menulist) { - checkLineHeight = PR_FALSE; nsCOMPtr select = do_QueryInterface(aCurrentEl); - if (select) + if (select) { + checkLineHeight = PR_FALSE; select->GetSelectedItem(getter_AddRefs(item)); + } } } diff --git a/layout/base/nsRefreshDriver.h b/layout/base/nsRefreshDriver.h index e13dc30637f..50320b839c1 100644 --- a/layout/base/nsRefreshDriver.h +++ b/layout/base/nsRefreshDriver.h @@ -63,7 +63,7 @@ public: // nsISupports will already have methods with the correct signature. // // The refresh driver does NOT hold references to refresh observers - // except while it is notifying them. + // except while it is notifying them. NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt) Release(void) = 0; diff --git a/layout/build/Makefile.in b/layout/build/Makefile.in index d3358be33e9..aa5b20eef18 100644 --- a/layout/build/Makefile.in +++ b/layout/build/Makefile.in @@ -278,7 +278,7 @@ ifeq ($(OS_ARCH),Linux) EXTRA_DSO_LDOPTS += $(MOZ_ALSA_LIBS) endif ifeq ($(OS_ARCH),Darwin) -OS_LIBS += -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon +OS_LIBS += -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon -framework IOKit endif endif diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 2d4d1c347d9..24ba6159650 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -300,17 +300,17 @@ NS_QUERYFRAME_HEAD(nsComboboxControlFrame) NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame) #ifdef ACCESSIBILITY -NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsComboboxControlFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsCOMPtr weakShell(do_GetWeakReference(PresContext()->PresShell())); - return accService->CreateHTMLComboboxAccessible(node, weakShell, aAccessible); + return accService->CreateHTMLComboboxAccessible(mContent, + PresContext()->PresShell()); } - return NS_ERROR_FAILURE; + return nsnull; } #endif diff --git a/layout/forms/nsComboboxControlFrame.h b/layout/forms/nsComboboxControlFrame.h index fbb34ff712b..31e5c710313 100644 --- a/layout/forms/nsComboboxControlFrame.h +++ b/layout/forms/nsComboboxControlFrame.h @@ -103,7 +103,7 @@ public: virtual nsIFrame* CreateFrameFor(nsIContent* aContent); #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext); diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp index 0dbc8796d0c..6f3f674bcd1 100644 --- a/layout/forms/nsFieldSetFrame.cpp +++ b/layout/forms/nsFieldSetFrame.cpp @@ -108,7 +108,7 @@ public: virtual PRBool IsContainingBlock() const; #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif #ifdef DEBUG @@ -649,15 +649,17 @@ nsFieldSetFrame::RemoveFrame(nsIAtom* aListName, } #ifdef ACCESSIBILITY -NS_IMETHODIMP nsFieldSetFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsFieldSetFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - return accService->CreateHTMLGroupboxAccessible(static_cast(this), aAccessible); + return accService->CreateHTMLGroupboxAccessible(mContent, + PresContext()->PresShell()); } - return NS_ERROR_FAILURE; + return nsnull; } #endif diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index c292d6ecfed..80c7de7cd1f 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -842,14 +842,16 @@ nsFileControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, } #ifdef ACCESSIBILITY -NS_IMETHODIMP nsFileControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsFileControlFrame::CreateAccessible() { // Accessible object exists just to hold onto its children, for later shutdown nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (!accService) - return NS_ERROR_FAILURE; + return nsnull; - return accService->CreateHTMLGenericAccessible(static_cast(this), aAccessible); + return accService->CreateHyperTextAccessible(mContent, + PresContext()->PresShell()); } #endif diff --git a/layout/forms/nsFileControlFrame.h b/layout/forms/nsFileControlFrame.h index 63a02543ccf..1b0aec18e53 100644 --- a/layout/forms/nsFileControlFrame.h +++ b/layout/forms/nsFileControlFrame.h @@ -95,7 +95,7 @@ public: virtual void AppendAnonymousContentTo(nsBaseContentList& aElements); #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif // create and destroy the static UploadLastDir object for remembering diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp index 146f7803d1c..6b9b9c8058c 100644 --- a/layout/forms/nsGfxButtonControlFrame.cpp +++ b/layout/forms/nsGfxButtonControlFrame.cpp @@ -181,19 +181,6 @@ nsGfxButtonControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) cons return rv; } -#ifdef ACCESSIBILITY -NS_IMETHODIMP nsGfxButtonControlFrame::GetAccessible(nsIAccessible** aAccessible) -{ - nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); - - if (accService) { - return accService->CreateHTMLButtonAccessible(static_cast(this), aAccessible); - } - - return NS_ERROR_FAILURE; -} -#endif - NS_QUERYFRAME_HEAD(nsGfxButtonControlFrame) NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator) NS_QUERYFRAME_TAIL_INHERITING(nsHTMLButtonControlFrame) diff --git a/layout/forms/nsGfxButtonControlFrame.h b/layout/forms/nsGfxButtonControlFrame.h index b039cab2f12..52d6de899f9 100644 --- a/layout/forms/nsGfxButtonControlFrame.h +++ b/layout/forms/nsGfxButtonControlFrame.h @@ -66,11 +66,6 @@ public: nsGUIEvent* aEvent, nsEventStatus* aEventStatus); - -#ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); -#endif - virtual nsIAtom* GetType() const; #ifdef DEBUG diff --git a/layout/forms/nsGfxCheckboxControlFrame.cpp b/layout/forms/nsGfxCheckboxControlFrame.cpp index a2247e586af..813ad8a568e 100644 --- a/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -120,18 +120,18 @@ nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame() } #ifdef ACCESSIBILITY -NS_IMETHODIMP -nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsGfxCheckboxControlFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - return accService->CreateHTMLCheckboxAccessible( - static_cast(this), aAccessible); + return accService->CreateHTMLCheckboxAccessible(mContent, + PresContext()->PresShell()); } - return NS_ERROR_FAILURE; + return nsnull; } #endif diff --git a/layout/forms/nsGfxCheckboxControlFrame.h b/layout/forms/nsGfxCheckboxControlFrame.h index 2727b5a8cad..2a2eacf94a1 100644 --- a/layout/forms/nsGfxCheckboxControlFrame.h +++ b/layout/forms/nsGfxCheckboxControlFrame.h @@ -62,7 +62,7 @@ public: const nsDisplayListSet& aLists); #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif protected: diff --git a/layout/forms/nsGfxRadioControlFrame.cpp b/layout/forms/nsGfxRadioControlFrame.cpp index 4cd0ea05afe..75d7c10f675 100644 --- a/layout/forms/nsGfxRadioControlFrame.cpp +++ b/layout/forms/nsGfxRadioControlFrame.cpp @@ -65,18 +65,18 @@ nsGfxRadioControlFrame::~nsGfxRadioControlFrame() } #ifdef ACCESSIBILITY -NS_IMETHODIMP -nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsGfxRadioControlFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - return accService->CreateHTMLRadioButtonAccessible( - static_cast(this), aAccessible); + return accService->CreateHTMLRadioButtonAccessible(mContent, + PresContext()->PresShell()); } - return NS_ERROR_FAILURE; + return nsnull; } #endif diff --git a/layout/forms/nsGfxRadioControlFrame.h b/layout/forms/nsGfxRadioControlFrame.h index 011131ef11e..8863f9347d3 100644 --- a/layout/forms/nsGfxRadioControlFrame.h +++ b/layout/forms/nsGfxRadioControlFrame.h @@ -55,7 +55,7 @@ public: NS_DECL_FRAMEARENA_HELPERS #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder, diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp index 829ef8f0bc8..cd41c5c998c 100644 --- a/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/layout/forms/nsHTMLButtonControlFrame.cpp @@ -110,21 +110,18 @@ NS_QUERYFRAME_HEAD(nsHTMLButtonControlFrame) NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame) #ifdef ACCESSIBILITY -NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsHTMLButtonControlFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - nsIContent* content = GetContent(); - nsCOMPtr buttonElement(do_QueryInterface(content)); - if (buttonElement) //If turned XBL-base form control off, the frame contains HTML 4 button - return accService->CreateHTML4ButtonAccessible(static_cast(this), aAccessible); - nsCOMPtr inputElement(do_QueryInterface(content)); - if (inputElement) //If turned XBL-base form control on, the frame contains normal HTML button - return accService->CreateHTMLButtonAccessible(static_cast(this), aAccessible); + return IsInput() ? + accService->CreateHTMLButtonAccessible(mContent, PresContext()->PresShell()) : + accService->CreateHTML4ButtonAccessible(mContent, PresContext()->PresShell()); } - return NS_ERROR_FAILURE; + return nsnull; } #endif diff --git a/layout/forms/nsHTMLButtonControlFrame.h b/layout/forms/nsHTMLButtonControlFrame.h index 2308be62ab9..511c0dae7ab 100644 --- a/layout/forms/nsHTMLButtonControlFrame.h +++ b/layout/forms/nsHTMLButtonControlFrame.h @@ -104,7 +104,7 @@ public: nsIFrame* aOldFrame); #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif virtual nsIAtom* GetType() const; diff --git a/layout/forms/nsImageControlFrame.cpp b/layout/forms/nsImageControlFrame.cpp index c5943ff3745..9dd5520ba37 100644 --- a/layout/forms/nsImageControlFrame.cpp +++ b/layout/forms/nsImageControlFrame.cpp @@ -96,7 +96,7 @@ public: virtual nsIAtom* GetType() const; #ifdef ACCESSIBILITY - NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); + virtual already_AddRefed CreateAccessible(); #endif #ifdef DEBUG @@ -164,20 +164,21 @@ NS_QUERYFRAME_HEAD(nsImageControlFrame) NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper) #ifdef ACCESSIBILITY -NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsImageControlFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { if (mContent->Tag() == nsGkAtoms::button) { - return accService->CreateHTML4ButtonAccessible(static_cast(this), aAccessible); + return accService->CreateHTML4ButtonAccessible(mContent, PresContext()->PresShell()); } else if (mContent->Tag() == nsGkAtoms::input) { - return accService->CreateHTMLButtonAccessible(static_cast(this), aAccessible); + return accService->CreateHTMLButtonAccessible(mContent, PresContext()->PresShell()); } } - return NS_ERROR_FAILURE; + return nsnull; } #endif diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 18c4c8ade43..269699d10d6 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -403,17 +403,17 @@ NS_QUERYFRAME_HEAD(nsListControlFrame) NS_QUERYFRAME_TAIL_INHERITING(nsHTMLScrollFrame) #ifdef ACCESSIBILITY -NS_IMETHODIMP nsListControlFrame::GetAccessible(nsIAccessible** aAccessible) +already_AddRefed +nsListControlFrame::CreateAccessible() { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsCOMPtr weakShell(do_GetWeakReference(PresContext()->PresShell())); - return accService->CreateHTMLListboxAccessible(node, weakShell, aAccessible); + return accService->CreateHTMLListboxAccessible(mContent, + PresContext()->PresShell()); } - return NS_ERROR_FAILURE; + return nsnull; } #endif @@ -1510,28 +1510,42 @@ nsListControlFrame::AddOption(PRInt32 aIndex) return NS_OK; } +static PRInt32 +DecrementAndClamp(PRInt32 aSelectionIndex, PRInt32 aLength) +{ + return aLength == 0 ? kNothingSelected : NS_MAX(0, aSelectionIndex - 1); +} + NS_IMETHODIMP nsListControlFrame::RemoveOption(PRInt32 aIndex) { + NS_PRECONDITION(aIndex >= 0, "negative