Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit bcb6f55

Browse files
author
Trevor Saunders
committed
bug 825341 - convert range to webidl r=bz, smaug
1 parent 3143368 commit bcb6f55

40 files changed

Lines changed: 956 additions & 455 deletions

accessible/src/generic/HyperTextAccessible.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ HyperTextAccessible::SetSelectionBounds(int32_t aSelectionNum,
18241824

18251825
nsRefPtr<nsRange> range;
18261826
if (aSelectionNum == rangeCount)
1827-
range = new nsRange();
1827+
range = new nsRange(mContent);
18281828
else
18291829
range = domSel->GetRangeAt(aSelectionNum);
18301830

@@ -1886,7 +1886,7 @@ HyperTextAccessible::ScrollSubstringTo(int32_t aStartIndex, int32_t aEndIndex,
18861886
if (IsDefunct())
18871887
return NS_ERROR_FAILURE;
18881888

1889-
nsRefPtr<nsRange> range = new nsRange();
1889+
nsRefPtr<nsRange> range = new nsRange(mContent);
18901890
nsresult rv = HypertextOffsetsToDOMRange(aStartIndex, aEndIndex, range);
18911891
NS_ENSURE_SUCCESS(rv, rv);
18921892

@@ -1910,7 +1910,7 @@ HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartIndex,
19101910
nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
19111911
this);
19121912

1913-
nsRefPtr<nsRange> range = new nsRange();
1913+
nsRefPtr<nsRange> range = new nsRange(mContent);
19141914
nsresult rv = HypertextOffsetsToDOMRange(aStartIndex, aEndIndex, range);
19151915
NS_ENSURE_SUCCESS(rv, rv);
19161916

accessible/src/windows/msaa/TextLeafAccessibleWrap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ TextLeafAccessibleWrap::scrollToSubstring(
158158
if (IsDefunct())
159159
return E_FAIL;
160160

161-
nsRefPtr<nsRange> range = new nsRange();
161+
nsRefPtr<nsRange> range = new nsRange(mContent);
162162
if (NS_FAILED(range->SetStart(mContent, aStartIndex)))
163163
return E_FAIL;
164164

content/base/public/nsContentUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ namespace layers {
112112
} // namespace layers
113113

114114
namespace dom {
115+
class DocumentFragment;
115116
class Element;
116117
} // namespace dom
117118

@@ -366,6 +367,7 @@ class nsContentUtils
366367

367368
// Check if the (JS) caller can access aNode.
368369
static bool CanCallerAccess(nsIDOMNode *aNode);
370+
static bool CanCallerAccess(nsINode* aNode);
369371

370372
// Check if the (JS) caller can access aWindow.
371373
// aWindow can be either outer or inner window.
@@ -1084,6 +1086,10 @@ class nsContentUtils
10841086
const nsAString& aFragment,
10851087
bool aPreventScriptExecution,
10861088
nsIDOMDocumentFragment** aReturn);
1089+
static already_AddRefed<mozilla::dom::DocumentFragment>
1090+
CreateContextualFragment(nsINode* aContextNode, const nsAString& aFragment,
1091+
bool aPreventScriptExecution,
1092+
mozilla::ErrorResult& aRv);
10871093

10881094
/**
10891095
* Invoke the fragment parsing algorithm (innerHTML) using the HTML parser.

content/base/public/nsIDocument.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,10 @@ nsresult
24722472
NS_NewVideoDocument(nsIDocument** aInstancePtrResult);
24732473
#endif
24742474

2475+
already_AddRefed<mozilla::dom::DocumentFragment>
2476+
NS_NewDocumentFragment(nsNodeInfoManager* aNodeInfoManager,
2477+
mozilla::ErrorResult& aRv);
2478+
24752479
nsresult
24762480
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
24772481
nsNodeInfoManager *aNodeInfoManager);

content/base/src/DocumentFragment.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,33 @@ nsresult
2222
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
2323
nsNodeInfoManager *aNodeInfoManager)
2424
{
25-
using namespace mozilla::dom;
25+
mozilla::ErrorResult rv;
26+
*aInstancePtrResult = NS_NewDocumentFragment(aNodeInfoManager, rv).get();
27+
return rv.ErrorCode();
28+
}
2629

27-
NS_ENSURE_ARG(aNodeInfoManager);
30+
already_AddRefed<mozilla::dom::DocumentFragment>
31+
NS_NewDocumentFragment(nsNodeInfoManager* aNodeInfoManager,
32+
mozilla::ErrorResult& aRv)
33+
{
34+
using namespace mozilla::dom;
2835

29-
nsCOMPtr<nsINodeInfo> nodeInfo;
30-
nodeInfo = aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName,
31-
nullptr, kNameSpaceID_None,
32-
nsIDOMNode::DOCUMENT_FRAGMENT_NODE);
33-
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
36+
if (!aNodeInfoManager) {
37+
aRv.Throw(NS_ERROR_INVALID_ARG);
38+
return nullptr;
39+
}
3440

35-
DocumentFragment *it = new DocumentFragment(nodeInfo.forget());
36-
NS_ADDREF(*aInstancePtrResult = it);
41+
nsCOMPtr<nsINodeInfo> nodeInfo =
42+
aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName,
43+
nullptr, kNameSpaceID_None,
44+
nsIDOMNode::DOCUMENT_FRAGMENT_NODE);
45+
if (!nodeInfo) {
46+
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
47+
return nullptr;
48+
}
3749

38-
return NS_OK;
50+
nsRefPtr<DocumentFragment> it = new DocumentFragment(nodeInfo.forget());
51+
return it.forget();
3952
}
4053

4154
namespace mozilla {

content/base/src/nsContentUtils.cpp

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
#include "nsSVGFeatures.h"
169169
#include "MediaDecoder.h"
170170
#include "DecoderTraits.h"
171+
#include "mozilla/dom/DocumentFragment.h"
171172

172173
#include "nsWrapperCacheInlines.h"
173174
#include "nsViewportInfo.h"
@@ -1588,6 +1589,15 @@ nsContentUtils::CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
15881589
// static
15891590
bool
15901591
nsContentUtils::CanCallerAccess(nsIDOMNode *aNode)
1592+
{
1593+
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
1594+
NS_ENSURE_TRUE(node, false);
1595+
return CanCallerAccess(node);
1596+
}
1597+
1598+
// static
1599+
bool
1600+
nsContentUtils::CanCallerAccess(nsINode* aNode)
15911601
{
15921602
// XXXbz why not check the IsCapabilityEnabled thing up front, and not bother
15931603
// with the system principal games? But really, there should be a simpler
@@ -1602,10 +1612,7 @@ nsContentUtils::CanCallerAccess(nsIDOMNode *aNode)
16021612
return true;
16031613
}
16041614

1605-
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
1606-
NS_ENSURE_TRUE(node, false);
1607-
1608-
return CanCallerAccess(subjectPrincipal, node->NodePrincipal());
1615+
return CanCallerAccess(subjectPrincipal, aNode->NodePrincipal());
16091616
}
16101617

16111618
// static
@@ -4045,8 +4052,22 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
40454052
bool aPreventScriptExecution,
40464053
nsIDOMDocumentFragment** aReturn)
40474054
{
4048-
*aReturn = nullptr;
4049-
NS_ENSURE_ARG(aContextNode);
4055+
ErrorResult rv;
4056+
*aReturn = CreateContextualFragment(aContextNode, aFragment,
4057+
aPreventScriptExecution, rv).get();
4058+
return rv.ErrorCode();
4059+
}
4060+
4061+
already_AddRefed<DocumentFragment>
4062+
nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
4063+
const nsAString& aFragment,
4064+
bool aPreventScriptExecution,
4065+
ErrorResult& aRv)
4066+
{
4067+
if (!aContextNode) {
4068+
aRv.Throw(NS_ERROR_INVALID_ARG);
4069+
return nullptr;
4070+
}
40504071

40514072
// If we don't have a document here, we can't get the right security context
40524073
// for compiling event handlers... so just bail out.
@@ -4058,8 +4079,8 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
40584079
#endif
40594080

40604081
if (isHTML) {
4061-
nsCOMPtr<nsIDOMDocumentFragment> frag;
4062-
NS_NewDocumentFragment(getter_AddRefs(frag), document->NodeInfoManager());
4082+
nsRefPtr<DocumentFragment> frag =
4083+
NS_NewDocumentFragment(document->NodeInfoManager(), aRv);
40634084

40644085
nsCOMPtr<nsIContent> contextAsContent = do_QueryInterface(aContextNode);
40654086
if (contextAsContent && !contextAsContent->IsElement()) {
@@ -4070,28 +4091,23 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
40704091
}
40714092
}
40724093

4073-
nsresult rv;
4074-
nsCOMPtr<nsIContent> fragment = do_QueryInterface(frag);
40754094
if (contextAsContent && !contextAsContent->IsHTML(nsGkAtoms::html)) {
4076-
rv = ParseFragmentHTML(aFragment,
4077-
fragment,
4078-
contextAsContent->Tag(),
4079-
contextAsContent->GetNameSpaceID(),
4080-
(document->GetCompatibilityMode() ==
4095+
aRv = ParseFragmentHTML(aFragment, frag,
4096+
contextAsContent->Tag(),
4097+
contextAsContent->GetNameSpaceID(),
4098+
(document->GetCompatibilityMode() ==
40814099
eCompatibility_NavQuirks),
4082-
aPreventScriptExecution);
4100+
aPreventScriptExecution);
40834101
} else {
4084-
rv = ParseFragmentHTML(aFragment,
4085-
fragment,
4086-
nsGkAtoms::body,
4087-
kNameSpaceID_XHTML,
4088-
(document->GetCompatibilityMode() ==
4102+
aRv = ParseFragmentHTML(aFragment, frag,
4103+
nsGkAtoms::body,
4104+
kNameSpaceID_XHTML,
4105+
(document->GetCompatibilityMode() ==
40894106
eCompatibility_NavQuirks),
4090-
aPreventScriptExecution);
4107+
aPreventScriptExecution);
40914108
}
40924109

4093-
frag.forget(aReturn);
4094-
return rv;
4110+
return frag.forget();
40954111
}
40964112

40974113
nsAutoTArray<nsString, 32> tagStack;
@@ -4103,7 +4119,10 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
41034119

41044120
while (content && content->IsElement()) {
41054121
nsString& tagName = *tagStack.AppendElement();
4106-
NS_ENSURE_TRUE(&tagName, NS_ERROR_OUT_OF_MEMORY);
4122+
if (!&tagName) {
4123+
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
4124+
return nullptr;
4125+
}
41074126

41084127
tagName = content->NodeInfo()->QualifiedName();
41094128

@@ -4149,11 +4168,10 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
41494168
content = content->GetParent();
41504169
}
41514170

4152-
return ParseFragmentXML(aFragment,
4153-
document,
4154-
tagStack,
4155-
aPreventScriptExecution,
4156-
aReturn);
4171+
nsCOMPtr<nsIDOMDocumentFragment> frag;
4172+
aRv = ParseFragmentXML(aFragment, document, tagStack,
4173+
aPreventScriptExecution, getter_AddRefs(frag));
4174+
return static_cast<DocumentFragment*>(frag.forget().get());
41574175
}
41584176

41594177
/* static */

content/base/src/nsCopySupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode,
294294
NS_ENSURE_SUCCESS(rv, rv);
295295
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
296296
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
297-
nsRefPtr<nsRange> range = new nsRange();
297+
nsRefPtr<nsRange> range = new nsRange(aNode);
298298
rv = range->SelectNode(node);
299299
NS_ENSURE_SUCCESS(rv, rv);
300300
rv = selection->AddRange(range);

content/base/src/nsDocument.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5573,7 +5573,7 @@ nsDocument::CreateRange(nsIDOMRange** aReturn)
55735573
already_AddRefed<nsRange>
55745574
nsIDocument::CreateRange(ErrorResult& rv)
55755575
{
5576-
nsRefPtr<nsRange> range = new nsRange();
5576+
nsRefPtr<nsRange> range = new nsRange(this);
55775577
nsresult res = range->Set(this, 0, this, 0);
55785578
if (NS_FAILED(res)) {
55795579
rv.Throw(res);

0 commit comments

Comments
 (0)