Compare commits
2 Commits
CAMINO_2_0
...
mozilla
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a637f81f7f | ||
|
|
6cfadae5d1 |
@@ -1 +0,0 @@
|
||||
2.0.9
|
||||
1203
mozilla/client.mk
1203
mozilla/client.mk
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,577 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 sw=2 et 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 "nsQueryContentEventHandler.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsRange.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsICaret.h"
|
||||
#include "nsFrameSelection.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIContentIterator.h"
|
||||
#include "nsTextFragment.h"
|
||||
#include "nsTextFrame.h"
|
||||
|
||||
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
|
||||
|
||||
/******************************************************************/
|
||||
/* nsQueryContentEventHandler */
|
||||
/******************************************************************/
|
||||
|
||||
nsQueryContentEventHandler::nsQueryContentEventHandler(
|
||||
nsPresContext* aPresContext) :
|
||||
mPresContext(aPresContext),
|
||||
mPresShell(aPresContext->GetPresShell()), mSelection(nsnull),
|
||||
mFirstSelectedRange(nsnull), mRootContent(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::Init(nsQueryContentEvent* aEvent)
|
||||
{
|
||||
NS_ASSERTION(aEvent, "aEvent must not be null");
|
||||
|
||||
if (mSelection)
|
||||
return NS_OK;
|
||||
|
||||
aEvent->mSucceeded = PR_FALSE;
|
||||
|
||||
if (!mPresShell)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsresult rv = mPresShell->GetSelectionForCopy(getter_AddRefs(mSelection));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(mSelection,
|
||||
"GetSelectionForCopy succeeded, but the result is null");
|
||||
|
||||
nsCOMPtr<nsIDOMRange> firstRange;
|
||||
rv = mSelection->GetRangeAt(0, getter_AddRefs(firstRange));
|
||||
// This shell doesn't support selection.
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
mFirstSelectedRange = do_QueryInterface(firstRange);
|
||||
NS_ENSURE_TRUE(mFirstSelectedRange, NS_ERROR_FAILURE);
|
||||
|
||||
nsINode* startNode = mFirstSelectedRange->GetStartParent();
|
||||
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
||||
mRootContent = startNode->GetSelectionRootContent(mPresShell);
|
||||
NS_ENSURE_TRUE(mRootContent, NS_ERROR_FAILURE);
|
||||
|
||||
aEvent->mReply.mContentsRoot = mRootContent.get();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void ConvertToNativeNewlines(nsAFlatString& aString)
|
||||
{
|
||||
#if defined(XP_MACOSX)
|
||||
aString.ReplaceSubstring(NS_LITERAL_STRING("\n"), NS_LITERAL_STRING("\r"));
|
||||
#elif defined(XP_WIN)
|
||||
aString.ReplaceSubstring(NS_LITERAL_STRING("\n"), NS_LITERAL_STRING("\r\n"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ConvertToXPNewlines(nsAFlatString& aString)
|
||||
{
|
||||
#if defined(XP_MACOSX)
|
||||
aString.ReplaceSubstring(NS_LITERAL_STRING("\r"), NS_LITERAL_STRING("\n"));
|
||||
#elif defined(XP_WIN)
|
||||
aString.ReplaceSubstring(NS_LITERAL_STRING("\r\n"), NS_LITERAL_STRING("\n"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void AppendString(nsAString& aString, nsIContent* aContent)
|
||||
{
|
||||
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
||||
"aContent is not a text node!");
|
||||
const nsTextFragment* text = aContent->GetText();
|
||||
if (!text)
|
||||
return;
|
||||
text->AppendTo(aString);
|
||||
}
|
||||
|
||||
static void AppendSubString(nsAString& aString, nsIContent* aContent,
|
||||
PRUint32 aXPOffset, PRUint32 aXPLength)
|
||||
{
|
||||
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
||||
"aContent is not a text node!");
|
||||
const nsTextFragment* text = aContent->GetText();
|
||||
if (!text)
|
||||
return;
|
||||
text->AppendTo(aString, PRInt32(aXPOffset), PRInt32(aXPLength));
|
||||
}
|
||||
|
||||
static PRUint32 GetNativeTextLength(nsIContent* aContent)
|
||||
{
|
||||
nsAutoString str;
|
||||
if (aContent->IsNodeOfType(nsINode::eTEXT))
|
||||
AppendString(str, aContent);
|
||||
else if (aContent->IsNodeOfType(nsINode::eHTML) &&
|
||||
aContent->Tag() == nsGkAtoms::br)
|
||||
str.Assign(PRUnichar('\n'));
|
||||
ConvertToNativeNewlines(str);
|
||||
return str.Length();
|
||||
}
|
||||
|
||||
static PRUint32 ConvertToXPOffset(nsIContent* aContent, PRUint32 aNativeOffset)
|
||||
{
|
||||
|
||||
nsAutoString str;
|
||||
AppendString(str, aContent);
|
||||
ConvertToNativeNewlines(str);
|
||||
NS_ASSERTION(aNativeOffset <= str.Length(),
|
||||
"aOffsetForNativeLF is too large!");
|
||||
str.Truncate(aNativeOffset);
|
||||
ConvertToXPNewlines(str);
|
||||
return str.Length();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::GenerateFlatTextContent(nsIRange* aRange,
|
||||
nsAFlatString& aString)
|
||||
{
|
||||
nsCOMPtr<nsIContentIterator> iter;
|
||||
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
|
||||
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(aRange));
|
||||
NS_ASSERTION(domRange, "aRange doesn't have nsIDOMRange!");
|
||||
iter->Init(domRange);
|
||||
|
||||
NS_ASSERTION(aString.IsEmpty(), "aString must be empty string");
|
||||
|
||||
nsINode* startNode = aRange->GetStartParent();
|
||||
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
||||
nsINode* endNode = aRange->GetEndParent();
|
||||
NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
|
||||
|
||||
if (startNode == endNode && startNode->IsNodeOfType(nsINode::eTEXT)) {
|
||||
nsIContent* content = static_cast<nsIContent*>(startNode);
|
||||
AppendSubString(aString, content, aRange->StartOffset(),
|
||||
aRange->EndOffset() - aRange->StartOffset());
|
||||
ConvertToNativeNewlines(aString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoString tmpStr;
|
||||
for (; !iter->IsDone(); iter->Next()) {
|
||||
nsIContent* content = iter->GetCurrentNode();
|
||||
if (!content)
|
||||
continue;
|
||||
|
||||
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
||||
if (content == startNode)
|
||||
AppendSubString(aString, content, aRange->StartOffset(),
|
||||
content->TextLength() - aRange->StartOffset());
|
||||
else if (content == endNode)
|
||||
AppendSubString(aString, content, 0, aRange->EndOffset());
|
||||
else
|
||||
AppendString(aString, content);
|
||||
} else if (content->IsNodeOfType(nsINode::eHTML) &&
|
||||
content->Tag() == nsGkAtoms::br)
|
||||
aString.Append(PRUnichar('\n'));
|
||||
}
|
||||
ConvertToNativeNewlines(aString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent,
|
||||
PRBool aForward,
|
||||
PRUint32* aXPOffset)
|
||||
{
|
||||
NS_ASSERTION(*aXPOffset >= 0 && *aXPOffset <= aContent->TextLength(),
|
||||
"offset is out of range.");
|
||||
|
||||
// XXX This method assumes that the frame boundaries must be cluster
|
||||
// boundaries. It's false, but no problem now, maybe.
|
||||
if (!aContent->IsNodeOfType(nsINode::eTEXT) ||
|
||||
*aXPOffset == 0 || *aXPOffset == aContent->TextLength())
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
|
||||
PRInt32 offsetInFrame;
|
||||
nsFrameSelection::HINT hint =
|
||||
aForward ? nsFrameSelection::HINTLEFT : nsFrameSelection::HINTRIGHT;
|
||||
nsIFrame* frame = fs->GetFrameForNodeOffset(aContent, PRInt32(*aXPOffset),
|
||||
hint, &offsetInFrame);
|
||||
if (!frame) {
|
||||
// This content doesn't have any frames, we only can check surrogate pair...
|
||||
const nsTextFragment* text = aContent->GetText();
|
||||
NS_ENSURE_TRUE(text, NS_ERROR_FAILURE);
|
||||
if (NS_IS_LOW_SURROGATE(text->CharAt(*aXPOffset)) &&
|
||||
NS_IS_HIGH_SURROGATE(text->CharAt(*aXPOffset - 1)))
|
||||
*aXPOffset += aForward ? 1 : -1;
|
||||
return NS_OK;
|
||||
}
|
||||
PRInt32 startOffset, endOffset;
|
||||
nsresult rv = frame->GetOffsets(startOffset, endOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (*aXPOffset == PRUint32(startOffset) || *aXPOffset == PRUint32(endOffset))
|
||||
return NS_OK;
|
||||
if (frame->GetType() != nsGkAtoms::textFrame)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
|
||||
PRInt32 newOffsetInFrame = offsetInFrame;
|
||||
newOffsetInFrame += aForward ? -1 : 1;
|
||||
textFrame->PeekOffsetCharacter(aForward, &newOffsetInFrame);
|
||||
*aXPOffset = startOffset + newOffsetInFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::SetRangeFromFlatTextOffset(
|
||||
nsIRange* aRange,
|
||||
PRUint32 aNativeOffset,
|
||||
PRUint32 aNativeLength,
|
||||
PRBool aExpandToClusterBoundaries)
|
||||
{
|
||||
nsCOMPtr<nsIContentIterator> iter;
|
||||
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
|
||||
rv = iter->Init(mRootContent);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(aRange));
|
||||
NS_ASSERTION(domRange, "aRange doesn't have nsIDOMRange!");
|
||||
|
||||
PRUint32 nativeOffset = 0;
|
||||
PRUint32 nativeEndOffset = aNativeOffset + aNativeLength;
|
||||
nsIContent* content = nsnull;
|
||||
for (; !iter->IsDone(); iter->Next()) {
|
||||
content = iter->GetCurrentNode();
|
||||
if (!content)
|
||||
continue;
|
||||
|
||||
PRUint32 nativeTextLength;
|
||||
nativeTextLength = GetNativeTextLength(content);
|
||||
if (nativeTextLength == 0)
|
||||
continue;
|
||||
|
||||
if (nativeOffset <= aNativeOffset &&
|
||||
aNativeOffset < nativeOffset + nativeTextLength) {
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
|
||||
NS_ASSERTION(domNode, "aContent doesn't have nsIDOMNode!");
|
||||
|
||||
PRUint32 xpOffset =
|
||||
content->IsNodeOfType(nsINode::eTEXT) ?
|
||||
ConvertToXPOffset(content, aNativeOffset - nativeOffset) : 0;
|
||||
|
||||
if (aExpandToClusterBoundaries) {
|
||||
rv = ExpandToClusterBoundary(content, PR_FALSE, &xpOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
rv = domRange->SetStart(domNode, PRInt32(xpOffset));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (aNativeLength == 0) {
|
||||
// Ensure that the end offset and the start offset are same.
|
||||
rv = domRange->SetEnd(domNode, PRInt32(xpOffset));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if (nativeEndOffset <= nativeOffset + nativeTextLength) {
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
|
||||
NS_ASSERTION(domNode, "aContent doesn't have nsIDOMNode!");
|
||||
|
||||
PRUint32 xpOffset;
|
||||
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
||||
xpOffset = ConvertToXPOffset(content, nativeEndOffset - nativeOffset);
|
||||
if (aExpandToClusterBoundaries) {
|
||||
rv = ExpandToClusterBoundary(content, PR_TRUE, &xpOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
} else {
|
||||
// Use first position of next node, because the end node is ignored
|
||||
// by ContentIterator when the offset is zero.
|
||||
xpOffset = 0;
|
||||
iter->Next();
|
||||
if (iter->IsDone())
|
||||
break;
|
||||
domNode = do_QueryInterface(iter->GetCurrentNode());
|
||||
}
|
||||
|
||||
rv = domRange->SetEnd(domNode, PRInt32(xpOffset));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nativeOffset += nativeTextLength;
|
||||
}
|
||||
|
||||
if (nativeOffset < aNativeOffset)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mRootContent));
|
||||
NS_ASSERTION(domNode, "lastContent doesn't have nsIDOMNode!");
|
||||
if (!content) {
|
||||
rv = domRange->SetStart(domNode, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
rv = domRange->SetEnd(domNode, PRInt32(mRootContent->GetChildCount()));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "nsIDOMRange::SetEnd failed");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::OnQuerySelectedText(nsQueryContentEvent* aEvent)
|
||||
{
|
||||
nsresult rv = Init(aEvent);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
|
||||
"The reply string must be empty");
|
||||
|
||||
rv = GetFlatTextOffsetOfRange(mFirstSelectedRange, &aEvent->mReply.mOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool isCollapsed;
|
||||
rv = mSelection->GetIsCollapsed(&isCollapsed);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!isCollapsed) {
|
||||
nsCOMPtr<nsIDOMRange> domRange;
|
||||
rv = mSelection->GetRangeAt(0, getter_AddRefs(domRange));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(domRange, "GetRangeAt succeeded, but the result is null");
|
||||
|
||||
nsCOMPtr<nsIRange> range(do_QueryInterface(domRange));
|
||||
NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
|
||||
rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
aEvent->mSucceeded = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::OnQueryTextContent(nsQueryContentEvent* aEvent)
|
||||
{
|
||||
nsresult rv = Init(aEvent);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
|
||||
"The reply string must be empty");
|
||||
|
||||
nsCOMPtr<nsIRange> range = new nsRange();
|
||||
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
|
||||
aEvent->mInput.mLength, PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aEvent->mSucceeded = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::QueryRectFor(nsQueryContentEvent* aEvent,
|
||||
nsIRange* aRange,
|
||||
nsICaret* aCaret)
|
||||
{
|
||||
PRInt32 offsetInFrame;
|
||||
nsIFrame* frame;
|
||||
nsresult rv = GetStartFrameAndOffset(aRange, &frame, &offsetInFrame);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsPoint posInFrame;
|
||||
rv = frame->GetPointFromOffset(aRange->StartOffset(), &posInFrame);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aEvent->mReply.mRect.y = posInFrame.y;
|
||||
aEvent->mReply.mRect.height = frame->GetSize().height;
|
||||
|
||||
if (aEvent->message == NS_QUERY_CHARACTER_RECT) {
|
||||
nsPoint nextPos;
|
||||
rv = frame->GetPointFromOffset(aRange->EndOffset(), &nextPos);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aEvent->mReply.mRect.x = PR_MIN(posInFrame.x, nextPos.x);
|
||||
aEvent->mReply.mRect.width = PR_ABS(posInFrame.x - nextPos.x);
|
||||
} else {
|
||||
aEvent->mReply.mRect.x = posInFrame.x;
|
||||
aEvent->mReply.mRect.width = aCaret->GetCaretRect().width;
|
||||
}
|
||||
|
||||
// The coordinates are app units here, they will be converted to system
|
||||
// coordinates by view manager.
|
||||
rv = ConvertToRootViewRelativeOffset(frame, aEvent->mReply.mRect);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aEvent->mSucceeded = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::OnQueryCharacterRect(nsQueryContentEvent* aEvent)
|
||||
{
|
||||
nsresult rv = Init(aEvent);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRange> range = new nsRange();
|
||||
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, 1, PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (range->Collapsed()) {
|
||||
// There is no character at the offset.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return QueryRectFor(aEvent, range, nsnull);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::OnQueryCaretRect(nsQueryContentEvent* aEvent)
|
||||
{
|
||||
nsresult rv = Init(aEvent);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsICaret> caret;
|
||||
rv = mPresShell->GetCaret(getter_AddRefs(caret));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(caret, "GetCaret succeeded, but the result is null");
|
||||
|
||||
// When the selection is collapsed and the queried offset is current caret
|
||||
// position, we should return the "real" caret rect.
|
||||
PRBool selectionIsCollapsed;
|
||||
rv = mSelection->GetIsCollapsed(&selectionIsCollapsed);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (selectionIsCollapsed) {
|
||||
PRUint32 offset;
|
||||
rv = GetFlatTextOffsetOfRange(mFirstSelectedRange, &offset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (offset == aEvent->mInput.mOffset) {
|
||||
PRBool isCollapsed;
|
||||
rv = caret->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates,
|
||||
mSelection, &aEvent->mReply.mRect,
|
||||
&isCollapsed, nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aEvent->mSucceeded = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, we should set the guessed caret rect.
|
||||
nsCOMPtr<nsIRange> range = new nsRange();
|
||||
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, 0, PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return QueryRectFor(aEvent, range, caret);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::GetFlatTextOffsetOfRange(nsIRange* aRange,
|
||||
PRUint32* aNativeOffset)
|
||||
{
|
||||
NS_ASSERTION(aNativeOffset, "param is invalid");
|
||||
|
||||
nsCOMPtr<nsIRange> prev = new nsRange();
|
||||
NS_ENSURE_TRUE(prev, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsCOMPtr<nsIDOMRange> domPrev(do_QueryInterface(prev));
|
||||
NS_ASSERTION(domPrev, "nsRange doesn't have nsIDOMRange??");
|
||||
nsCOMPtr<nsIDOMNode> rootDOMNode(do_QueryInterface(mRootContent));
|
||||
domPrev->SetStart(rootDOMNode, 0);
|
||||
|
||||
nsINode* startNode = aRange->GetStartParent();
|
||||
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 startOffset = aRange->StartOffset();
|
||||
nsCOMPtr<nsIDOMNode> startDOMNode(do_QueryInterface(startNode));
|
||||
NS_ASSERTION(startDOMNode, "startNode doesn't have nsIDOMNode");
|
||||
domPrev->SetEnd(startDOMNode, startOffset);
|
||||
|
||||
nsAutoString prevStr;
|
||||
nsresult rv = GenerateFlatTextContent(prev, prevStr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
*aNativeOffset = prevStr.Length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::GetStartFrameAndOffset(nsIRange* aRange,
|
||||
nsIFrame** aFrame,
|
||||
PRInt32* aOffsetInFrame)
|
||||
{
|
||||
NS_ASSERTION(aRange && aFrame && aOffsetInFrame, "params are invalid");
|
||||
|
||||
nsIContent* content = nsnull;
|
||||
nsINode* node = aRange->GetStartParent();
|
||||
if (node && node->IsNodeOfType(nsINode::eCONTENT))
|
||||
content = static_cast<nsIContent*>(node);
|
||||
NS_ASSERTION(content, "the start node doesn't have nsIContent!");
|
||||
|
||||
nsCOMPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
|
||||
*aFrame = fs->GetFrameForNodeOffset(content, aRange->StartOffset(),
|
||||
fs->GetHint(), aOffsetInFrame);
|
||||
NS_ENSURE_TRUE((*aFrame), NS_ERROR_FAILURE);
|
||||
NS_ASSERTION((*aFrame)->GetType() == nsGkAtoms::textFrame,
|
||||
"The frame is not textframe");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsQueryContentEventHandler::ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
|
||||
nsRect& aRect)
|
||||
{
|
||||
NS_ASSERTION(aFrame, "aFrame must not be null");
|
||||
|
||||
nsIView* view = nsnull;
|
||||
nsPoint posInView;
|
||||
aFrame->GetOffsetFromView(posInView, &view);
|
||||
if (!view)
|
||||
return NS_ERROR_FAILURE;
|
||||
aRect += posInView + view->GetOffsetTo(nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,532 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** 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 Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 ***** */
|
||||
|
||||
/*
|
||||
* JS math package.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include "jslibmath.h"
|
||||
#include <stdlib.h>
|
||||
#include "jstypes.h"
|
||||
#include "jslong.h"
|
||||
#include "prmjtime.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsconfig.h"
|
||||
#include "jslock.h"
|
||||
#include "jsmath.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsobj.h"
|
||||
|
||||
#ifndef M_E
|
||||
#define M_E 2.7182818284590452354
|
||||
#endif
|
||||
#ifndef M_LOG2E
|
||||
#define M_LOG2E 1.4426950408889634074
|
||||
#endif
|
||||
#ifndef M_LOG10E
|
||||
#define M_LOG10E 0.43429448190325182765
|
||||
#endif
|
||||
#ifndef M_LN2
|
||||
#define M_LN2 0.69314718055994530942
|
||||
#endif
|
||||
#ifndef M_LN10
|
||||
#define M_LN10 2.30258509299404568402
|
||||
#endif
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880
|
||||
#endif
|
||||
#ifndef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440
|
||||
#endif
|
||||
|
||||
static JSConstDoubleSpec math_constants[] = {
|
||||
{M_E, "E", 0, {0,0,0}},
|
||||
{M_LOG2E, "LOG2E", 0, {0,0,0}},
|
||||
{M_LOG10E, "LOG10E", 0, {0,0,0}},
|
||||
{M_LN2, "LN2", 0, {0,0,0}},
|
||||
{M_LN10, "LN10", 0, {0,0,0}},
|
||||
{M_PI, "PI", 0, {0,0,0}},
|
||||
{M_SQRT2, "SQRT2", 0, {0,0,0}},
|
||||
{M_SQRT1_2, "SQRT1_2", 0, {0,0,0}},
|
||||
{0,0,0,{0,0,0}}
|
||||
};
|
||||
|
||||
JSClass js_MathClass = {
|
||||
js_Math_str,
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Math),
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
|
||||
JSCLASS_NO_OPTIONAL_MEMBERS
|
||||
};
|
||||
|
||||
static JSBool
|
||||
math_abs(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_fabs(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_acos(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
#if !JS_USE_FDLIBM_MATH && defined(SOLARIS) && defined(__GNUC__)
|
||||
if (x < -1 || 1 < x) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
z = fd_acos(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_asin(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
#if !JS_USE_FDLIBM_MATH && defined(SOLARIS) && defined(__GNUC__)
|
||||
if (x < -1 || 1 < x) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
z = fd_asin(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_atan(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_atan(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_atan2(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, y, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
y = js_ValueToNumber(cx, &vp[3]);
|
||||
if (JSVAL_IS_NULL(vp[3]))
|
||||
return JS_FALSE;
|
||||
#if !JS_USE_FDLIBM_MATH && defined(_MSC_VER)
|
||||
/*
|
||||
* MSVC's atan2 does not yield the result demanded by ECMA when both x
|
||||
* and y are infinite.
|
||||
* - The result is a multiple of pi/4.
|
||||
* - The sign of x determines the sign of the result.
|
||||
* - The sign of y determines the multiplicator, 1 or 3.
|
||||
*/
|
||||
if (JSDOUBLE_IS_INFINITE(x) && JSDOUBLE_IS_INFINITE(y)) {
|
||||
z = fd_copysign(M_PI / 4, x);
|
||||
if (y < 0)
|
||||
z *= 3;
|
||||
return js_NewDoubleInRootedValue(cx, z, vp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !JS_USE_FDLIBM_MATH && defined(SOLARIS) && defined(__GNUC__)
|
||||
if (x == 0) {
|
||||
if (JSDOUBLE_IS_NEGZERO(y)) {
|
||||
z = fd_copysign(M_PI, x);
|
||||
return js_NewDoubleInRootedValue(cx, z, vp);
|
||||
}
|
||||
if (y == 0) {
|
||||
z = x;
|
||||
return js_NewDoubleInRootedValue(cx, z, vp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
z = fd_atan2(x, y);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_ceil(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_ceil(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_cos(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_cos(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_exp(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
#ifdef _WIN32
|
||||
if (!JSDOUBLE_IS_NaN(x)) {
|
||||
if (x == *cx->runtime->jsPositiveInfinity) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (x == *cx->runtime->jsNegativeInfinity) {
|
||||
*vp = JSVAL_ZERO;
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
z = fd_exp(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_floor(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_floor(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_log(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
#if !JS_USE_FDLIBM_MATH && defined(SOLARIS) && defined(__GNUC__)
|
||||
if (x < 0) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
z = fd_log(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_max(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z = *cx->runtime->jsNegativeInfinity;
|
||||
jsval *argv;
|
||||
uintN i;
|
||||
|
||||
if (argc == 0) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNegativeInfinity);
|
||||
return JS_TRUE;
|
||||
}
|
||||
argv = vp + 2;
|
||||
for (i = 0; i < argc; i++) {
|
||||
x = js_ValueToNumber(cx, &argv[i]);
|
||||
if (JSVAL_IS_NULL(argv[i]))
|
||||
return JS_FALSE;
|
||||
if (JSDOUBLE_IS_NaN(x)) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (x == 0 && x == z && fd_copysign(1.0, z) == -1)
|
||||
z = x;
|
||||
else
|
||||
z = (x > z) ? x : z;
|
||||
}
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_min(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z = *cx->runtime->jsPositiveInfinity;
|
||||
jsval *argv;
|
||||
uintN i;
|
||||
|
||||
if (argc == 0) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
|
||||
return JS_TRUE;
|
||||
}
|
||||
argv = vp + 2;
|
||||
for (i = 0; i < argc; i++) {
|
||||
x = js_ValueToNumber(cx, &argv[i]);
|
||||
if (JSVAL_IS_NULL(argv[i]))
|
||||
return JS_FALSE;
|
||||
if (JSDOUBLE_IS_NaN(x)) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (x == 0 && x == z && fd_copysign(1.0,x) == -1)
|
||||
z = x;
|
||||
else
|
||||
z = (x < z) ? x : z;
|
||||
}
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_pow(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, y, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
y = js_ValueToNumber(cx, &vp[3]);
|
||||
if (JSVAL_IS_NULL(vp[3]))
|
||||
return JS_FALSE;
|
||||
#if !JS_USE_FDLIBM_MATH
|
||||
/*
|
||||
* Because C99 and ECMA specify different behavior for pow(),
|
||||
* we need to wrap the libm call to make it ECMA compliant.
|
||||
*/
|
||||
if (!JSDOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0)) {
|
||||
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
/* pow(x, +-0) is always 1, even for x = NaN. */
|
||||
if (y == 0) {
|
||||
*vp = JSVAL_ONE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
z = fd_pow(x, y);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static const int64 RNG_MULTIPLIER = 0x5DEECE66DLL;
|
||||
static const int64 RNG_ADDEND = 0xBLL;
|
||||
static const int64 RNG_MASK = (1LL << 48) - 1;
|
||||
static const jsdouble RNG_DSCALE = (1LL << 53);
|
||||
|
||||
/*
|
||||
* Math.random() support, lifted from java.util.Random.java.
|
||||
*/
|
||||
static inline void
|
||||
random_setSeed(JSContext *cx, int64 seed)
|
||||
{
|
||||
cx->rngSeed = (seed ^ RNG_MULTIPLIER) & RNG_MASK;
|
||||
}
|
||||
|
||||
void
|
||||
js_InitRandom(JSContext *cx)
|
||||
{
|
||||
/*
|
||||
* Set the seed from current time. Since we have a RNG per context and we often bring
|
||||
* up several contexts at the same time, we xor in some additional values, namely
|
||||
* the context and its successor. We don't just use the context because it might be
|
||||
* possible to reverse engineer the context pointer if one guesses the time right.
|
||||
*/
|
||||
random_setSeed(cx,
|
||||
(PRMJ_Now() / 1000) ^
|
||||
(int64)(cx) ^
|
||||
(int64)(cx->links.next));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
random_next(JSContext *cx, int bits)
|
||||
{
|
||||
uint64 nextseed = cx->rngSeed * RNG_MULTIPLIER;
|
||||
nextseed += RNG_ADDEND;
|
||||
nextseed &= RNG_MASK;
|
||||
cx->rngSeed = nextseed;
|
||||
return nextseed >> (48 - bits);
|
||||
}
|
||||
|
||||
static inline jsdouble
|
||||
random_nextDouble(JSContext *cx)
|
||||
{
|
||||
return (jsdouble)((random_next(cx, 26) << 27) + random_next(cx, 27)) / RNG_DSCALE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_random(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble z = random_nextDouble(cx);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
#if defined _WIN32 && !defined WINCE && _MSC_VER < 1400
|
||||
/* Try to work around apparent _copysign bustage in VC6 and VC7. */
|
||||
double
|
||||
js_copysign(double x, double y)
|
||||
{
|
||||
jsdpun xu, yu;
|
||||
|
||||
xu.d = x;
|
||||
yu.d = y;
|
||||
xu.s.hi &= ~JSDOUBLE_HI32_SIGNBIT;
|
||||
xu.s.hi |= yu.s.hi & JSDOUBLE_HI32_SIGNBIT;
|
||||
return xu.d;
|
||||
}
|
||||
#endif
|
||||
|
||||
static JSBool
|
||||
math_round(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_copysign(fd_floor(x + 0.5), x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_sin(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_sin(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_sqrt(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_sqrt(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
math_tan(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsdouble x, z;
|
||||
|
||||
x = js_ValueToNumber(cx, &vp[2]);
|
||||
if (JSVAL_IS_NULL(vp[2]))
|
||||
return JS_FALSE;
|
||||
z = fd_tan(x);
|
||||
return js_NewNumberInRootedValue(cx, z, vp);
|
||||
}
|
||||
|
||||
#if JS_HAS_TOSOURCE
|
||||
static JSBool
|
||||
math_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
*vp = ATOM_KEY(CLASS_ATOM(cx, Math));
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static JSFunctionSpec math_static_methods[] = {
|
||||
#if JS_HAS_TOSOURCE
|
||||
JS_FN(js_toSource_str, math_toSource, 0, 0, 0),
|
||||
#endif
|
||||
JS_FN("abs", math_abs, 1, 1, 0),
|
||||
JS_FN("acos", math_acos, 1, 1, 0),
|
||||
JS_FN("asin", math_asin, 1, 1, 0),
|
||||
JS_FN("atan", math_atan, 1, 1, 0),
|
||||
JS_FN("atan2", math_atan2, 2, 2, 0),
|
||||
JS_FN("ceil", math_ceil, 1, 1, 0),
|
||||
JS_FN("cos", math_cos, 1, 1, 0),
|
||||
JS_FN("exp", math_exp, 1, 1, 0),
|
||||
JS_FN("floor", math_floor, 1, 1, 0),
|
||||
JS_FN("log", math_log, 1, 1, 0),
|
||||
JS_FN("max", math_max, 0, 2, 0),
|
||||
JS_FN("min", math_min, 0, 2, 0),
|
||||
JS_FN("pow", math_pow, 2, 2, 0),
|
||||
JS_FN("random", math_random, 0, 0, 0),
|
||||
JS_FN("round", math_round, 1, 1, 0),
|
||||
JS_FN("sin", math_sin, 1, 1, 0),
|
||||
JS_FN("sqrt", math_sqrt, 1, 1, 0),
|
||||
JS_FN("tan", math_tan, 1, 1, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
JSObject *
|
||||
js_InitMathClass(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSObject *Math;
|
||||
|
||||
Math = JS_DefineObject(cx, obj, js_Math_str, &js_MathClass, NULL, 0);
|
||||
if (!Math)
|
||||
return NULL;
|
||||
if (!JS_DefineFunctions(cx, Math, math_static_methods))
|
||||
return NULL;
|
||||
if (!JS_DefineConstDoubles(cx, Math, math_constants))
|
||||
return NULL;
|
||||
return Math;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 ***** */
|
||||
|
||||
/* -*- Mode: C; tab-width: 8 -*-
|
||||
* Copyright (C) 1998-1999 Netscape Communications Corporation, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef jsmath_h___
|
||||
#define jsmath_h___
|
||||
/*
|
||||
* JS math functions.
|
||||
*/
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSClass js_MathClass;
|
||||
|
||||
extern JSObject *
|
||||
js_InitMathClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern void
|
||||
js_InitRandom(JSContext *cx);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsmath_h___ */
|
||||
@@ -1,109 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is Mozilla Communicator client code, released
|
||||
# March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1998
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = liveconnect
|
||||
LIBRARY_NAME = jsj
|
||||
EXPORT_LIBRARY = 1
|
||||
ifeq ($(OS_ARCH)$(MOZ_ENABLE_LIBXUL),WINNT)
|
||||
LIBRARY_NAME = jsj$(MOZ_BITS)$(VERSION_NUMBER)
|
||||
MAPFILE = $(LIBRARY_NAME).map
|
||||
endif
|
||||
JNI_GEN_DIR = _jni
|
||||
GRE_MODULE = 1
|
||||
LIBXUL_LIBRARY = 1
|
||||
|
||||
PACKAGE_FILE = liveconnect.pkg
|
||||
|
||||
REQUIRES = js \
|
||||
xpcom \
|
||||
xpconnect \
|
||||
java \
|
||||
caps \
|
||||
necko \
|
||||
string \
|
||||
plugin \
|
||||
oji \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
jsj.c \
|
||||
jsj_JSObject.c \
|
||||
jsj_JavaArray.c \
|
||||
jsj_JavaClass.c \
|
||||
jsj_JavaMember.c \
|
||||
jsj_JavaObject.c \
|
||||
jsj_JavaPackage.c \
|
||||
jsj_array.c \
|
||||
jsj_class.c \
|
||||
jsj_convert.c \
|
||||
jsj_field.c \
|
||||
jsj_hash.c \
|
||||
jsj_method.c \
|
||||
jsj_utils.c \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsCLiveconnect.cpp \
|
||||
nsCLiveconnectFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(srcdir)/jsjava.h \
|
||||
$(srcdir)/$(JNI_GEN_DIR)/netscape_javascript_JSObject.h \
|
||||
$(srcdir)/$(JNI_GEN_DIR)/netscape_javascript_JSException.h \
|
||||
$(srcdir)/nsILiveconnect.h \
|
||||
$(srcdir)/nsISecureLiveconnect.h \
|
||||
$(srcdir)/nsISecurityContext.h \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(LIBS_DIR) \
|
||||
$(MOZ_JS_LIBS) \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
@@ -1,876 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** 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 Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* This file is part of the Java-vendor-neutral implementation of LiveConnect
|
||||
*
|
||||
* It contains the implementation providing nsIFactory XP-COM interface.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prprf.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include "jsj_private.h"
|
||||
#include "jsjava.h"
|
||||
|
||||
#include "jsdbgapi.h"
|
||||
#include "jsarena.h"
|
||||
#include "jsfun.h"
|
||||
#include "jscntxt.h" /* For js_ReportErrorAgain().*/
|
||||
#include "jsscript.h"
|
||||
|
||||
#include "netscape_javascript_JSObject.h" /* javah-generated headers */
|
||||
#include "nsISecurityContext.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsJVMManager.h"
|
||||
#include "nsIPluginInstancePeer2.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* A captured JavaScript error, created when JS_ReportError() is called while
|
||||
running JavaScript code that is itself called from Java. */
|
||||
struct CapturedJSError {
|
||||
char * message;
|
||||
JSErrorReport report; /* Line # of error, etc. */
|
||||
jthrowable java_exception; /* Java exception, error, or null */
|
||||
CapturedJSError * next; /* Next oldest captured JS error */
|
||||
};
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#include "nsCLiveconnect.h"
|
||||
|
||||
#include "jsinterp.h" // XXX private API so we can auto-push a JSStackFrame
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsISecurityContext.h"
|
||||
#include "prmem.h"
|
||||
|
||||
/***************************************************************************/
|
||||
// A class to put on the stack to manage JS contexts when we are entering JS.
|
||||
// This pushes and pops the given context
|
||||
// with the nsThreadJSContextStack service as this object goes into and out
|
||||
// of scope. It is optimized to not push/pop the cx if it is already on top
|
||||
// of the stack. We need to push the JSContext when we enter JS because the
|
||||
// JS security manager looks on the context stack for permissions information.
|
||||
|
||||
class AutoPushJSContext
|
||||
{
|
||||
public:
|
||||
AutoPushJSContext(nsISupports* aSecuritySupports,
|
||||
JSContext *cx);
|
||||
|
||||
~AutoPushJSContext();
|
||||
|
||||
nsresult ResultOfPush() { return mPushResult; }
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIJSContextStack> mContextStack;
|
||||
JSContext* mContext;
|
||||
JSStackFrame mFrame;
|
||||
JSFrameRegs mRegs;
|
||||
nsresult mPushResult;
|
||||
};
|
||||
|
||||
AutoPushJSContext::AutoPushJSContext(nsISupports* aSecuritySupports,
|
||||
JSContext *cx)
|
||||
: mContext(cx), mPushResult(NS_OK)
|
||||
{
|
||||
nsCOMPtr<nsIJSContextStack> contextStack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
|
||||
JS_BeginRequest(cx);
|
||||
|
||||
JSContext* currentCX;
|
||||
if(contextStack &&
|
||||
// Don't push if the current context is already on the stack.
|
||||
(NS_FAILED(contextStack->Peek(¤tCX)) ||
|
||||
cx != currentCX) )
|
||||
{
|
||||
if (NS_SUCCEEDED(contextStack->Push(cx)))
|
||||
{
|
||||
// Leave the reference in mContextStack to
|
||||
// indicate that we need to pop it in our dtor.
|
||||
mContextStack.swap(contextStack);
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secMan(
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &mPushResult));
|
||||
|
||||
if (NS_FAILED(mPushResult))
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
mPushResult = secMan->GetPrincipalFromContext(cx, getter_AddRefs(principal));
|
||||
|
||||
if (NS_FAILED(mPushResult))
|
||||
{
|
||||
JS_ReportError(cx, "failed to get a principal");
|
||||
return;
|
||||
}
|
||||
|
||||
// See if JavaScript is enabled for the current window
|
||||
PRBool jsEnabled = PR_FALSE;
|
||||
mPushResult = secMan->CanExecuteScripts(cx, principal, &jsEnabled);
|
||||
if (!jsEnabled)
|
||||
mPushResult = NS_ERROR_FAILURE;
|
||||
|
||||
memset(&mFrame, 0, sizeof(mFrame));
|
||||
|
||||
if (NS_SUCCEEDED(mPushResult))
|
||||
{
|
||||
// See if there are any scripts on the stack.
|
||||
// If not, we need to add a dummy frame with a principal.
|
||||
|
||||
PRBool hasScript = PR_FALSE;
|
||||
JSStackFrame* tempFP = cx->fp;
|
||||
while (tempFP)
|
||||
{
|
||||
if (tempFP->script)
|
||||
{
|
||||
hasScript = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
tempFP = tempFP->down;
|
||||
};
|
||||
|
||||
if (!hasScript)
|
||||
{
|
||||
JSPrincipals* jsprinc;
|
||||
principal->GetJSPrincipals(cx, &jsprinc);
|
||||
|
||||
JSFunction *fun = JS_CompileFunctionForPrincipals(cx, JS_GetGlobalObject(cx),
|
||||
jsprinc, "anonymous", 0, nsnull,
|
||||
"", 0, "", 1);
|
||||
JSPRINCIPALS_DROP(cx, jsprinc);
|
||||
|
||||
if (fun)
|
||||
{
|
||||
JSScript *script = JS_GetFunctionScript(cx, fun);
|
||||
mFrame.fun = fun;
|
||||
mFrame.script = script;
|
||||
mFrame.callee = JS_GetFunctionObject(fun);
|
||||
mFrame.scopeChain = JS_GetParent(cx, mFrame.callee);
|
||||
mFrame.down = cx->fp;
|
||||
mRegs.pc = script->code + script->length
|
||||
- JSOP_STOP_LENGTH;
|
||||
mRegs.sp = NULL;
|
||||
mFrame.regs = &mRegs;
|
||||
cx->fp = &mFrame;
|
||||
}
|
||||
else
|
||||
mPushResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AutoPushJSContext::~AutoPushJSContext()
|
||||
{
|
||||
if (mContextStack)
|
||||
mContextStack->Pop(nsnull);
|
||||
|
||||
if (mFrame.callobj)
|
||||
js_PutCallObject(mContext, &mFrame);
|
||||
if (mFrame.argsobj)
|
||||
js_PutArgsObject(mContext, &mFrame);
|
||||
JS_ClearPendingException(mContext);
|
||||
if (mFrame.script)
|
||||
mContext->fp = mFrame.down;
|
||||
|
||||
JS_EndRequest(mContext);
|
||||
}
|
||||
|
||||
// nsILiveconnect methods (which constitute OJI's Java-to-JavaScript API) may
|
||||
// call back into Java (using the OJI plugin's implementation of the
|
||||
// nsISecureEnv interface). But these nsISecureEnv methods assume there is
|
||||
// JavaScript on the stack, and Java code can call nsILiveconnect methods
|
||||
// "spontaneously" (without any JavaScript on the stack). So the
|
||||
// nsCLiveconnect methods below (those that implement the nsILiveconnect
|
||||
// interface) always create an AutoPushJSContext object, which guarantees the
|
||||
// presence on the JavaScript stack of at least a dummy frame with a principal.
|
||||
//
|
||||
// Ordinarily we rely on jsj_enter_js() to tell us which JSContext to pass to
|
||||
// the AutoPushJSContext constructor, and really only need to create an
|
||||
// AutoPushJSContext object after jsj_enter_js() has returned. But the first
|
||||
// time jsj_enter_js() is called we initialize a bunch of Java classes and
|
||||
// their methods and fields (in jsj.c's init_netscape_java_classes() and
|
||||
// init_java_VM_reflection()). This involves calling into Java, and thus
|
||||
// using the plugin's nsISecureEnv methods -- which assume there is JavaScript
|
||||
// on the stack.
|
||||
//
|
||||
// So to deal with this edge case (to make sure jsj_enter_js() behaves
|
||||
// properly the first time it's called) we need to create an AutoPushJSContext
|
||||
// object *before* calling jsj_enter_js() -- which requires that we know which
|
||||
// JSContex to pass to the AutoPushJSContext constructor before the call to
|
||||
// jsj_enter_js();
|
||||
//
|
||||
// That's what this function does -- it tells us which JSContext the call to
|
||||
// jsj_enter_js() will return (as a result of indirectly calling
|
||||
// map_jsj_thread_to_js_context_impl() in lcglue.cpp).
|
||||
static JSContext* JSContextForPluginInstance(nsIPluginInstance* pluginInstance)
|
||||
{
|
||||
JSContext* context = NULL;
|
||||
if (pluginInstance) {
|
||||
nsCOMPtr<nsIPluginInstancePeer> pluginPeer;
|
||||
if (NS_SUCCEEDED(pluginInstance->GetPeer(getter_AddRefs(pluginPeer)))) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPluginInstancePeer2> pluginPeer2 = do_QueryInterface(pluginPeer, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
pluginPeer2->GetJSContext(&context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsISupports and AggregatedQueryInterface:
|
||||
|
||||
// Thes macro expands to the aggregated query interface scheme.
|
||||
|
||||
NS_IMPL_AGGREGATED(nsCLiveconnect)
|
||||
NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsCLiveconnect)
|
||||
NS_INTERFACE_MAP_ENTRY(nsILiveconnect)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsILiveconnect:
|
||||
|
||||
/**
|
||||
* get member of a Native JSObject for a given name.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
* @param name - Name of a member.
|
||||
* @param pjobj - return parameter as a java object representing
|
||||
* the member. If it is a basic data type it is converted to
|
||||
* a corresponding java type. If it is a NJSObject, then it is
|
||||
* wrapped up as java wrapper netscape.javascript.JSObject.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::GetMember(JNIEnv *jEnv, lcjsobject obj, const jchar *name, jsize length, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports, jobject *pjobj)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jobject member = NULL;
|
||||
jsval js_val;
|
||||
int dummy_cost = 0;
|
||||
JSBool dummy_bool = PR_FALSE;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!name) {
|
||||
JS_ReportError(cx, "illegal null member name");
|
||||
member = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!JS_GetUCProperty(cx, js_obj, name, length, &js_val))
|
||||
goto done;
|
||||
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &member, &dummy_bool);
|
||||
|
||||
done:
|
||||
if (!jsj_exit_js(cx, jsj_env, saved_state))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*pjobj = member;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get member of a Native JSObject for a given index.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
* @param index - Index of a member.
|
||||
* @param pjobj - return parameter as a java object representing
|
||||
* the member.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::GetSlot(JNIEnv *jEnv, lcjsobject obj, jint slot, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports, jobject *pjobj)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jobject member = NULL;
|
||||
jsval js_val;
|
||||
int dummy_cost = 0;
|
||||
JSBool dummy_bool = PR_FALSE;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// =-= sudu: check to see if slot can be passed in as is.
|
||||
// Should it be converted to a jsint?
|
||||
if (!JS_GetElement(cx, js_obj, slot, &js_val))
|
||||
goto done;
|
||||
if (!jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &member, &dummy_bool))
|
||||
goto done;
|
||||
|
||||
done:
|
||||
if (!jsj_exit_js(cx, jsj_env, saved_state))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*pjobj = member;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* set member of a Native JSObject for a given name.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
* @param name - Name of a member.
|
||||
* @param jobj - Value to set. If this is a basic data type, it is converted
|
||||
* using standard JNI calls but if it is a wrapper to a JSObject
|
||||
* then a internal mapping is consulted to convert to a NJSObject.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::SetMember(JNIEnv *jEnv, lcjsobject obj, const jchar *name, jsize length, jobject java_obj, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jsval js_val;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!name) {
|
||||
JS_ReportError(cx, "illegal null member name");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_obj, &js_val))
|
||||
goto done;
|
||||
|
||||
JS_SetUCProperty(cx, js_obj, name, length, &js_val);
|
||||
|
||||
done:
|
||||
jsj_exit_js(cx, jsj_env, saved_state);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set member of a Native JSObject for a given index.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
* @param index - Index of a member.
|
||||
* @param jobj - Value to set. If this is a basic data type, it is converted
|
||||
* using standard JNI calls but if it is a wrapper to a JSObject
|
||||
* then a internal mapping is consulted to convert to a NJSObject.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::SetSlot(JNIEnv *jEnv, lcjsobject obj, jint slot, jobject java_obj, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jsval js_val;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_obj, &js_val))
|
||||
goto done;
|
||||
JS_SetElement(cx, js_obj, slot, &js_val);
|
||||
|
||||
done:
|
||||
jsj_exit_js(cx, jsj_env, saved_state);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* remove member of a Native JSObject for a given name.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
* @param name - Name of a member.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::RemoveMember(JNIEnv *jEnv, lcjsobject obj, const jchar *name, jsize length, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jsval js_val;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!name) {
|
||||
JS_ReportError(cx, "illegal null member name");
|
||||
goto done;
|
||||
}
|
||||
|
||||
JS_DeleteUCProperty2(cx, js_obj, name, length, &js_val);
|
||||
|
||||
done:
|
||||
jsj_exit_js(cx, jsj_env, saved_state);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* call a method of Native JSObject.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
* @param name - Name of a method.
|
||||
* @param jobjArr - Array of jobjects representing parameters of method being caled.
|
||||
* @param pjobj - return value.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::Call(JNIEnv *jEnv, lcjsobject obj, const jchar *name, jsize length, jobjectArray java_args, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports, jobject *pjobj)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int argc = 0;
|
||||
int arg_num = 0;
|
||||
jsval *argv = 0;
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jsval js_val;
|
||||
jsval function_val = 0;
|
||||
int dummy_cost = 0;
|
||||
JSBool dummy_bool = PR_FALSE;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
jobject result = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = NULL;
|
||||
|
||||
if (!name) {
|
||||
JS_ReportError(cx, "illegal null JavaScript function name");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Allocate space for JS arguments */
|
||||
argc = java_args ? jEnv->GetArrayLength(java_args) : 0;
|
||||
if (argc) {
|
||||
argv = (jsval*)JS_malloc(cx, argc * sizeof(jsval));
|
||||
if (!argv)
|
||||
goto done;
|
||||
} else {
|
||||
argv = 0;
|
||||
}
|
||||
|
||||
/* Convert arguments from Java to JS values */
|
||||
for (arg_num = 0; arg_num < argc; arg_num++) {
|
||||
jobject arg = jEnv->GetObjectArrayElement(java_args, arg_num);
|
||||
JSBool ret = jsj_ConvertJavaObjectToJSValue(cx, jEnv, arg, &argv[arg_num]);
|
||||
|
||||
jEnv->DeleteLocalRef(arg);
|
||||
if (!ret)
|
||||
goto cleanup_argv;
|
||||
JS_AddRoot(cx, &argv[arg_num]);
|
||||
}
|
||||
|
||||
if (!JS_GetUCProperty(cx, js_obj, name, length, &function_val))
|
||||
goto cleanup_argv;
|
||||
|
||||
if (!JS_CallFunctionValue(cx, js_obj, function_val, argc, argv, &js_val))
|
||||
goto cleanup_argv;
|
||||
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &result, &dummy_bool);
|
||||
|
||||
cleanup_argv:
|
||||
if (argv) {
|
||||
for (i = 0; i < arg_num; i++)
|
||||
JS_RemoveRoot(cx, &argv[i]);
|
||||
JS_free(cx, argv);
|
||||
}
|
||||
|
||||
done:
|
||||
if (!jsj_exit_js(cx, jsj_env, saved_state))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*pjobj = result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsCLiveconnect::Eval(JNIEnv *jEnv, lcjsobject obj, const jchar *script, jsize length, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports, jobject *pjobj)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
jsval js_val;
|
||||
int dummy_cost = 0;
|
||||
JSBool dummy_bool = PR_FALSE;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
jobject result = NULL;
|
||||
const char *codebase = NULL;
|
||||
JSPrincipals *principals = NULL;
|
||||
JSBool eval_succeeded = PR_FALSE;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = NULL;
|
||||
|
||||
if (!script) {
|
||||
JS_ReportError(cx, "illegal null string eval argument");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Set up security stuff */
|
||||
if (JSJ_callbacks && JSJ_callbacks->get_JSPrincipals_from_java_caller)
|
||||
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv, cx, principalsArray, numPrincipals, securitySupports);
|
||||
codebase = principals ? principals->codebase : NULL;
|
||||
|
||||
/* Have the JS engine evaluate the unicode string */
|
||||
eval_succeeded = JS_EvaluateUCScriptForPrincipals(cx, js_obj, principals,
|
||||
script, length,
|
||||
codebase, 0, &js_val);
|
||||
|
||||
if (!eval_succeeded)
|
||||
goto done;
|
||||
|
||||
/* Convert result to a subclass of java.lang.Object */
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &result, &dummy_bool);
|
||||
|
||||
done:
|
||||
if (principals)
|
||||
JSPRINCIPALS_DROP(cx, principals);
|
||||
if (!jsj_exit_js(cx, jsj_env, saved_state))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*pjobj = result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the window object for a plugin instance.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param pJavaObject - Either a jobject or a pointer to a plugin instance
|
||||
* representing the java object.
|
||||
* @param pjobj - return value. This is a native js object
|
||||
* representing the window object of a frame
|
||||
* in which a applet/bean resides.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::GetWindow(JNIEnv *jEnv, void *pJavaObject, void* principalsArray[],
|
||||
int numPrincipals, nsISupports *securitySupports, lcjsobject *pobj)
|
||||
{
|
||||
if(jEnv == NULL || JSJ_callbacks == NULL)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// associate this Java client with this LiveConnect connection.
|
||||
mJavaClient = pJavaObject;
|
||||
|
||||
char *err_msg = NULL;
|
||||
JSContext *cx = NULL;
|
||||
JSObject *js_obj = NULL;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(securitySupports, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, principalsArray, numPrincipals, securitySupports);
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
err_msg = NULL;
|
||||
|
||||
js_obj = JSJ_callbacks->map_java_object_to_js_object(jEnv, mJavaClient, &err_msg);
|
||||
if (!js_obj) {
|
||||
if (err_msg) {
|
||||
JS_ReportError(cx, err_msg);
|
||||
free(err_msg);
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
*pobj = (jint)js_obj;
|
||||
#else
|
||||
/* FIXME: to handle PRESERVE_JSOBJECT_IDENTITY case, this needs to
|
||||
just return a raw JSObject reference. FIXME !!! */
|
||||
/* Create a tiny stub object to act as the GC root that points to the
|
||||
JSObject from its netscape.javascript.JSObject counterpart. */
|
||||
handle = (JSObjectHandle*)JS_malloc(cx, sizeof(JSObjectHandle));
|
||||
if (handle != NULL)
|
||||
{
|
||||
handle->js_obj = js_obj;
|
||||
handle->rt = JS_GetRuntime(cx);
|
||||
}
|
||||
*pobj = (lcjsobject)handle;
|
||||
/* FIXME: what if the window is explicitly disposed of, how do we
|
||||
notify Java? */
|
||||
#endif
|
||||
done:
|
||||
if (!jsj_exit_js(cx, jsj_env, saved_state))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the window object for a plugin instance.
|
||||
*
|
||||
* @param jEnv - JNIEnv on which the call is being made.
|
||||
* @param obj - A Native JS Object.
|
||||
*/
|
||||
NS_METHOD
|
||||
nsCLiveconnect::FinalizeJSObject(JNIEnv *jEnv, lcjsobject obj)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSObjectHandle *handle = (JSObjectHandle *)obj;
|
||||
|
||||
if (!handle)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
JS_RemoveRootRT(handle->rt, &handle->js_obj);
|
||||
free(handle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsCLiveconnect::ToString(JNIEnv *jEnv, lcjsobject obj, jstring *pjstring)
|
||||
{
|
||||
if(jEnv == NULL || obj == 0)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSJavaThreadState *jsj_env = NULL;
|
||||
JSObjectHandle *handle = (JSObjectHandle*)obj;
|
||||
JSObject *js_obj = handle->js_obj;
|
||||
JSContext *cx = NULL;
|
||||
JSErrorReporter saved_state = NULL;
|
||||
jstring result = NULL;
|
||||
JSString *jsstr = NULL;
|
||||
|
||||
cx = JSContextForPluginInstance(reinterpret_cast<nsIPluginInstance*>(mJavaClient));
|
||||
if (!cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
AutoPushJSContext autopush(nsnull, cx);
|
||||
if (NS_FAILED(autopush.ResultOfPush()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, mJavaClient, NULL, &cx, NULL, &saved_state, NULL, 0, NULL );
|
||||
if (!jsj_env)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = NULL;
|
||||
|
||||
jsstr = JS_ValueToString(cx, OBJECT_TO_JSVAL(js_obj));
|
||||
if (jsstr)
|
||||
result = jsj_ConvertJSStringToJavaString(cx, jEnv, jsstr);
|
||||
if (!result)
|
||||
result = jEnv->NewStringUTF("*JavaObject*");
|
||||
|
||||
if (!jsj_exit_js(cx, jsj_env, saved_state))
|
||||
return NS_ERROR_FAILURE;
|
||||
*pjstring = result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// from nsCLiveconnect:
|
||||
|
||||
nsCLiveconnect::nsCLiveconnect(nsISupports *aOuter)
|
||||
: mJavaClient(NULL)
|
||||
{
|
||||
NS_INIT_AGGREGATED(aOuter);
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
jsj_init_js_obj_reflections_table();
|
||||
#endif
|
||||
}
|
||||
|
||||
nsCLiveconnect::~nsCLiveconnect()
|
||||
{
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
48
mozilla/mozilla.kdevprj
Normal file
48
mozilla/mozilla.kdevprj
Normal file
@@ -0,0 +1,48 @@
|
||||
# KDE Config File
|
||||
[mozilla.lsm]
|
||||
install_location=
|
||||
dist=true
|
||||
install=false
|
||||
type=DATA
|
||||
[Config for BinMakefileAm]
|
||||
ldflags=
|
||||
cxxflags=-O0 -g3 -Wall
|
||||
bin_program=mozilla
|
||||
[po/Makefile.am]
|
||||
sub_dirs=
|
||||
type=po
|
||||
[LFV Groups]
|
||||
Dialogs=*.kdevdlg,
|
||||
Others=*,
|
||||
Translations=*.po,
|
||||
groups=Headers,Sources,Dialogs,Translations,Others,
|
||||
Sources=*.cpp,*.c,*.cc,*.C,*.cxx,*.ec,*.ecpp,*.lxx,*.l++,*.ll,*.l,
|
||||
Headers=*.h,*.hh,*.hxx,*.hpp,*.H,
|
||||
[mozilla.kdevprj]
|
||||
install_location=
|
||||
dist=true
|
||||
install=false
|
||||
type=DATA
|
||||
[mozilla/docs/en/Makefile.am]
|
||||
sub_dirs=
|
||||
type=normal
|
||||
[mozilla/Makefile.am]
|
||||
sub_dirs=
|
||||
type=prog_main
|
||||
[General]
|
||||
makefiles=Makefile.am,mozilla/Makefile.am,mozilla/docs/Makefile.am,mozilla/docs/en/Makefile.am,po/Makefile.am,
|
||||
version_control=CVS
|
||||
author=Heikki Toivonen
|
||||
project_type=normal_empty
|
||||
sub_dir=mozilla/
|
||||
version=0.1
|
||||
project_name=Mozilla
|
||||
email=heikki@netscape.com
|
||||
kdevprj_version=1.2
|
||||
[Makefile.am]
|
||||
files=mozilla.kdevprj,mozilla.lsm,
|
||||
sub_dirs=mozilla,
|
||||
type=normal
|
||||
[mozilla/docs/Makefile.am]
|
||||
sub_dirs=
|
||||
type=normal
|
||||
14
mozilla/mozilla.lsm
Normal file
14
mozilla/mozilla.lsm
Normal file
@@ -0,0 +1,14 @@
|
||||
Begin3
|
||||
Title: Mozilla
|
||||
Version: 0.1
|
||||
Entered-date:
|
||||
Description:
|
||||
Keywords:
|
||||
Author: Heikki Toivonen <heikki@netscape.com>
|
||||
Maintained-by: Heikki Toivonen <heikki@netscape.com>
|
||||
Primary-site:
|
||||
Home-page: http://
|
||||
Original-site:
|
||||
Platforms: Linux and other Unices
|
||||
Copying-policy: GNU Public License
|
||||
End
|
||||
20
mozilla/mozilla/templates/cpp_template
Normal file
20
mozilla/mozilla/templates/cpp_template
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
20
mozilla/mozilla/templates/header_template
Normal file
20
mozilla/mozilla/templates/header_template
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,261 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** 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.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Kai Engert <kengert@redhat.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NSNSSCALLBACKS_H_
|
||||
#define _NSNSSCALLBACKS_H_
|
||||
|
||||
#include "pk11func.h"
|
||||
#include "nspr.h"
|
||||
#include "ocspt.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
char* PR_CALLBACK
|
||||
PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg);
|
||||
|
||||
void PR_CALLBACK HandshakeCallback(PRFileDesc *fd, void *client_data);
|
||||
SECStatus PR_CALLBACK AuthCertificateCallback(void* client_data, PRFileDesc* fd,
|
||||
PRBool checksig, PRBool isServer);
|
||||
|
||||
PRErrorCode PSM_SSL_BlacklistDigiNotar(CERTCertificate * serverCert,
|
||||
CERTCertList * serverCertChain);
|
||||
|
||||
SECStatus RegisterMyOCSPAIAInfoCallback();
|
||||
SECStatus UnregisterMyOCSPAIAInfoCallback();
|
||||
|
||||
class nsHTTPListener : public nsIStreamLoaderObserver
|
||||
{
|
||||
private:
|
||||
// For XPCOM implementations that are not a base class for some other
|
||||
// class, it is good practice to make the destructor non-virtual and
|
||||
// private. Then the only way to delete the object is via Release.
|
||||
~nsHTTPListener();
|
||||
|
||||
public:
|
||||
nsHTTPListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> mLoader;
|
||||
|
||||
nsresult mResultCode;
|
||||
|
||||
PRBool mHttpRequestSucceeded;
|
||||
PRUint16 mHttpResponseCode;
|
||||
nsCString mHttpResponseContentType;
|
||||
|
||||
const PRUint8* mResultData; // not owned, refers to mLoader
|
||||
PRUint32 mResultLen;
|
||||
|
||||
nsresult InitLocks();
|
||||
|
||||
PRLock *mLock;
|
||||
PRCondVar *mCondition;
|
||||
volatile PRBool mWaitFlag;
|
||||
|
||||
PRBool mResponsibleForDoneSignal;
|
||||
void send_done_signal();
|
||||
|
||||
// no nsCOMPtr. When I use it, I get assertions about
|
||||
// loadgroup not being thread safe.
|
||||
// So, let's use a raw pointer and ensure we only create and destroy
|
||||
// it on the network thread ourselves.
|
||||
nsILoadGroup *mLoadGroup;
|
||||
PRThread *mLoadGroupOwnerThread;
|
||||
void FreeLoadGroup(PRBool aCancelLoad);
|
||||
};
|
||||
|
||||
class nsNSSHttpServerSession
|
||||
{
|
||||
public:
|
||||
nsCString mHost;
|
||||
PRUint16 mPort;
|
||||
|
||||
static SECStatus createSessionFcn(const char *host,
|
||||
PRUint16 portnum,
|
||||
SEC_HTTP_SERVER_SESSION *pSession);
|
||||
};
|
||||
|
||||
class nsNSSHttpRequestSession
|
||||
{
|
||||
protected:
|
||||
PRInt32 mRefCount;
|
||||
|
||||
public:
|
||||
static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
|
||||
const char *http_protocol_variant,
|
||||
const char *path_and_query_string,
|
||||
const char *http_request_method,
|
||||
const PRIntervalTime timeout,
|
||||
SEC_HTTP_REQUEST_SESSION *pRequest);
|
||||
|
||||
SECStatus setPostDataFcn(const char *http_data,
|
||||
const PRUint32 http_data_len,
|
||||
const char *http_content_type);
|
||||
|
||||
SECStatus addHeaderFcn(const char *http_header_name,
|
||||
const char *http_header_value);
|
||||
|
||||
SECStatus trySendAndReceiveFcn(PRPollDesc **pPollDesc,
|
||||
PRUint16 *http_response_code,
|
||||
const char **http_response_content_type,
|
||||
const char **http_response_headers,
|
||||
const char **http_response_data,
|
||||
PRUint32 *http_response_data_len);
|
||||
|
||||
SECStatus cancelFcn();
|
||||
SECStatus freeFcn();
|
||||
|
||||
void AddRef();
|
||||
void Release();
|
||||
|
||||
nsCString mURL;
|
||||
nsCString mRequestMethod;
|
||||
|
||||
PRBool mHasPostData;
|
||||
nsCString mPostData;
|
||||
nsCString mPostContentType;
|
||||
|
||||
PRIntervalTime mTimeoutInterval;
|
||||
|
||||
nsCOMPtr<nsHTTPListener> mListener;
|
||||
|
||||
protected:
|
||||
nsNSSHttpRequestSession();
|
||||
~nsNSSHttpRequestSession();
|
||||
|
||||
SECStatus internal_send_receive_attempt(PRBool &retryable_error,
|
||||
PRPollDesc **pPollDesc,
|
||||
PRUint16 *http_response_code,
|
||||
const char **http_response_content_type,
|
||||
const char **http_response_headers,
|
||||
const char **http_response_data,
|
||||
PRUint32 *http_response_data_len);
|
||||
};
|
||||
|
||||
class nsNSSHttpInterface
|
||||
{
|
||||
public:
|
||||
static SECStatus createSessionFcn(const char *host,
|
||||
PRUint16 portnum,
|
||||
SEC_HTTP_SERVER_SESSION *pSession)
|
||||
{
|
||||
return nsNSSHttpServerSession::createSessionFcn(host, portnum, pSession);
|
||||
}
|
||||
|
||||
static SECStatus keepAliveFcn(SEC_HTTP_SERVER_SESSION session,
|
||||
PRPollDesc **pPollDesc)
|
||||
{
|
||||
// Not yet implemented, however, Necko does transparent keep-alive
|
||||
// anyway, when enabled in Necko's prefs.
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
static SECStatus freeSessionFcn(SEC_HTTP_SERVER_SESSION session)
|
||||
{
|
||||
delete static_cast<nsNSSHttpServerSession*>(session);
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
|
||||
const char *http_protocol_variant,
|
||||
const char *path_and_query_string,
|
||||
const char *http_request_method,
|
||||
const PRIntervalTime timeout,
|
||||
SEC_HTTP_REQUEST_SESSION *pRequest)
|
||||
{
|
||||
return nsNSSHttpRequestSession::createFcn(session, http_protocol_variant,
|
||||
path_and_query_string, http_request_method,
|
||||
timeout, pRequest);
|
||||
}
|
||||
|
||||
static SECStatus setPostDataFcn(SEC_HTTP_REQUEST_SESSION request,
|
||||
const char *http_data,
|
||||
const PRUint32 http_data_len,
|
||||
const char *http_content_type)
|
||||
{
|
||||
return static_cast<nsNSSHttpRequestSession*>(request)
|
||||
->setPostDataFcn(http_data, http_data_len, http_content_type);
|
||||
}
|
||||
|
||||
static SECStatus addHeaderFcn(SEC_HTTP_REQUEST_SESSION request,
|
||||
const char *http_header_name,
|
||||
const char *http_header_value)
|
||||
{
|
||||
return static_cast<nsNSSHttpRequestSession*>(request)
|
||||
->addHeaderFcn(http_header_name, http_header_value);
|
||||
}
|
||||
|
||||
static SECStatus trySendAndReceiveFcn(SEC_HTTP_REQUEST_SESSION request,
|
||||
PRPollDesc **pPollDesc,
|
||||
PRUint16 *http_response_code,
|
||||
const char **http_response_content_type,
|
||||
const char **http_response_headers,
|
||||
const char **http_response_data,
|
||||
PRUint32 *http_response_data_len)
|
||||
{
|
||||
return static_cast<nsNSSHttpRequestSession*>(request)
|
||||
->trySendAndReceiveFcn(pPollDesc, http_response_code, http_response_content_type,
|
||||
http_response_headers, http_response_data, http_response_data_len);
|
||||
}
|
||||
|
||||
static SECStatus cancelFcn(SEC_HTTP_REQUEST_SESSION request)
|
||||
{
|
||||
return static_cast<nsNSSHttpRequestSession*>(request)
|
||||
->cancelFcn();
|
||||
}
|
||||
|
||||
static SECStatus freeFcn(SEC_HTTP_REQUEST_SESSION request)
|
||||
{
|
||||
return static_cast<nsNSSHttpRequestSession*>(request)
|
||||
->freeFcn();
|
||||
}
|
||||
|
||||
static void initTable();
|
||||
static SEC_HttpClientFcn sNSSInterfaceTable;
|
||||
|
||||
void registerHttpClient();
|
||||
void unregisterHttpClient();
|
||||
};
|
||||
|
||||
#endif // _NSNSSCALLBACKS_H_
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,303 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** 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.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Kai Engert <kengert@redhat.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NSNSSIOLAYER_H
|
||||
#define _NSNSSIOLAYER_H
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
#include "certt.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsITransportSecurityInfo.h"
|
||||
#include "nsISSLSocketControl.h"
|
||||
#include "nsSSLStatus.h"
|
||||
#include "nsISSLStatusProvider.h"
|
||||
#include "nsIIdentityInfo.h"
|
||||
#include "nsIAssociatedContentSecurity.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsNSSShutDown.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsNSSCertificate.h"
|
||||
|
||||
class nsIChannel;
|
||||
class nsSSLThread;
|
||||
|
||||
/*
|
||||
* This class is used to store SSL socket I/O state information,
|
||||
* that is not being executed directly, but defered to
|
||||
* the separate SSL thread.
|
||||
*/
|
||||
class nsSSLSocketThreadData
|
||||
{
|
||||
public:
|
||||
nsSSLSocketThreadData();
|
||||
~nsSSLSocketThreadData();
|
||||
|
||||
PRBool ensure_buffer_size(PRInt32 amount);
|
||||
|
||||
enum ssl_state {
|
||||
ssl_invalid, // used for initializating, should never occur
|
||||
ssl_idle, // not in use by SSL thread, no activity pending
|
||||
ssl_pending_write, // waiting for SSL thread to complete writing
|
||||
ssl_pending_read, // waiting for SSL thread to complete reading
|
||||
ssl_writing_done, // SSL write completed, results are ready
|
||||
ssl_reading_done // SSL read completed, results are ready
|
||||
};
|
||||
|
||||
ssl_state mSSLState;
|
||||
|
||||
// Used to transport I/O error codes between SSL thread
|
||||
// and initial caller thread.
|
||||
PRErrorCode mPRErrorCode;
|
||||
|
||||
// A buffer used to transfer I/O data between threads
|
||||
char *mSSLDataBuffer;
|
||||
PRInt32 mSSLDataBufferAllocatedSize;
|
||||
|
||||
// The amount requested to read or write by the caller.
|
||||
PRInt32 mSSLRequestedTransferAmount;
|
||||
|
||||
// A pointer into our buffer, to the first byte
|
||||
// that has not yet been delivered to the caller.
|
||||
// Necessary, as the caller of the read function
|
||||
// might request smaller chunks.
|
||||
const char *mSSLRemainingReadResultData;
|
||||
|
||||
// The caller previously requested to read or write.
|
||||
// As the initial request to read or write is defered,
|
||||
// the caller might (in theory) request smaller chunks
|
||||
// in subsequent calls.
|
||||
// This variable stores the amount of bytes successfully
|
||||
// transfered, that have not yet been reported to the caller.
|
||||
PRInt32 mSSLResultRemainingBytes;
|
||||
|
||||
// When defering SSL read/write activity to another thread,
|
||||
// we switch the SSL level file descriptor of the original
|
||||
// layered file descriptor to a pollable event,
|
||||
// so we can wake up the original caller of the I/O function
|
||||
// as soon as data is ready.
|
||||
// This variable is used to save the SSL level file descriptor,
|
||||
// to allow us to restore the original file descriptor layering.
|
||||
PRFileDesc *mReplacedSSLFileDesc;
|
||||
|
||||
PRBool mOneBytePendingFromEarlierWrite;
|
||||
unsigned char mThePendingByte;
|
||||
PRInt32 mOriginalRequestedTransferAmount;
|
||||
};
|
||||
|
||||
class nsNSSSocketInfo : public nsITransportSecurityInfo,
|
||||
public nsISSLSocketControl,
|
||||
public nsIInterfaceRequestor,
|
||||
public nsISSLStatusProvider,
|
||||
public nsIIdentityInfo,
|
||||
public nsIAssociatedContentSecurity,
|
||||
public nsISerializable,
|
||||
public nsIClassInfo,
|
||||
public nsNSSShutDownObject,
|
||||
public nsOnPK11LogoutCancelObject
|
||||
{
|
||||
public:
|
||||
nsNSSSocketInfo();
|
||||
virtual ~nsNSSSocketInfo();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITRANSPORTSECURITYINFO
|
||||
NS_DECL_NSISSLSOCKETCONTROL
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
NS_DECL_NSISSLSTATUSPROVIDER
|
||||
NS_DECL_NSIIDENTITYINFO
|
||||
NS_DECL_NSIASSOCIATEDCONTENTSECURITY
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_DECL_NSICLASSINFO
|
||||
|
||||
nsresult SetSecurityState(PRUint32 aState);
|
||||
nsresult SetShortSecurityDescription(const PRUnichar *aText);
|
||||
nsresult SetErrorMessage(const PRUnichar *aText);
|
||||
|
||||
nsresult SetForSTARTTLS(PRBool aForSTARTTLS);
|
||||
nsresult GetForSTARTTLS(PRBool *aForSTARTTLS);
|
||||
|
||||
nsresult GetFileDescPtr(PRFileDesc** aFilePtr);
|
||||
nsresult SetFileDescPtr(PRFileDesc* aFilePtr);
|
||||
|
||||
nsresult GetHandshakePending(PRBool *aHandshakePending);
|
||||
nsresult SetHandshakePending(PRBool aHandshakePending);
|
||||
|
||||
nsresult GetHostName(char **aHostName);
|
||||
nsresult SetHostName(const char *aHostName);
|
||||
|
||||
nsresult GetPort(PRInt32 *aPort);
|
||||
nsresult SetPort(PRInt32 aPort);
|
||||
|
||||
nsresult GetCert(nsIX509Cert** _result);
|
||||
nsresult SetCert(nsIX509Cert *aCert);
|
||||
|
||||
nsresult GetPreviousCert(nsIX509Cert** _result);
|
||||
|
||||
void SetCanceled(PRBool aCanceled);
|
||||
PRBool GetCanceled();
|
||||
|
||||
void SetHasCleartextPhase(PRBool aHasCleartextPhase);
|
||||
PRBool GetHasCleartextPhase();
|
||||
|
||||
void SetHandshakeInProgress(PRBool aIsIn);
|
||||
PRBool GetHandshakeInProgress() { return mHandshakeInProgress; }
|
||||
PRBool HandshakeTimeout();
|
||||
|
||||
void SetAllowTLSIntoleranceTimeout(PRBool aAllow);
|
||||
|
||||
nsresult GetExternalErrorReporting(PRBool* state);
|
||||
nsresult SetExternalErrorReporting(PRBool aState);
|
||||
|
||||
nsresult RememberCAChain(CERTCertList *aCertList);
|
||||
|
||||
/* Set SSL Status values */
|
||||
nsresult SetSSLStatus(nsSSLStatus *aSSLStatus);
|
||||
nsSSLStatus* SSLStatus() { return mSSLStatus; }
|
||||
PRBool hasCertErrors();
|
||||
|
||||
PRStatus CloseSocketAndDestroy();
|
||||
|
||||
PRBool IsCertIssuerBlacklisted() const {
|
||||
return mIsCertIssuerBlacklisted;
|
||||
}
|
||||
void SetCertIssuerBlacklisted() {
|
||||
mIsCertIssuerBlacklisted = PR_TRUE;
|
||||
}
|
||||
protected:
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
PRFileDesc* mFd;
|
||||
nsCOMPtr<nsIX509Cert> mCert;
|
||||
nsCOMPtr<nsIX509Cert> mPreviousCert; // DocShellDependent
|
||||
enum {
|
||||
blocking_state_unknown, is_nonblocking_socket, is_blocking_socket
|
||||
} mBlockingState;
|
||||
PRUint32 mSecurityState;
|
||||
PRInt32 mSubRequestsHighSecurity;
|
||||
PRInt32 mSubRequestsLowSecurity;
|
||||
PRInt32 mSubRequestsBrokenSecurity;
|
||||
PRInt32 mSubRequestsNoSecurity;
|
||||
nsString mShortDesc;
|
||||
nsString mErrorMessage;
|
||||
PRPackedBool mDocShellDependentStuffKnown;
|
||||
PRPackedBool mExternalErrorReporting; // DocShellDependent
|
||||
PRPackedBool mForSTARTTLS;
|
||||
PRPackedBool mHandshakePending;
|
||||
PRPackedBool mCanceled;
|
||||
PRPackedBool mHasCleartextPhase;
|
||||
PRPackedBool mHandshakeInProgress;
|
||||
PRPackedBool mAllowTLSIntoleranceTimeout;
|
||||
PRIntervalTime mHandshakeStartTime;
|
||||
PRInt32 mPort;
|
||||
nsXPIDLCString mHostName;
|
||||
PRErrorCode mIsCertIssuerBlacklisted;
|
||||
|
||||
/* SSL Status */
|
||||
nsRefPtr<nsSSLStatus> mSSLStatus;
|
||||
|
||||
nsresult ActivateSSL();
|
||||
|
||||
nsSSLSocketThreadData *mThreadData;
|
||||
|
||||
nsresult EnsureDocShellDependentStuffKnown();
|
||||
|
||||
private:
|
||||
virtual void virtualDestroyNSSReference();
|
||||
void destructorSafeDestroyNSSReference();
|
||||
|
||||
friend class nsSSLThread;
|
||||
};
|
||||
|
||||
class nsCStringHashSet;
|
||||
|
||||
class nsSSLIOLayerHelpers
|
||||
{
|
||||
public:
|
||||
static nsresult Init();
|
||||
static void Cleanup();
|
||||
|
||||
static PRBool nsSSLIOLayerInitialized;
|
||||
static PRDescIdentity nsSSLIOLayerIdentity;
|
||||
static PRIOMethods nsSSLIOLayerMethods;
|
||||
|
||||
static PRLock *mutex;
|
||||
static nsCStringHashSet *mTLSIntolerantSites;
|
||||
|
||||
static PRBool rememberPossibleTLSProblemSite(PRFileDesc* fd, nsNSSSocketInfo *socketInfo);
|
||||
|
||||
static void addIntolerantSite(const nsCString &str);
|
||||
static PRBool isKnownAsIntolerantSite(const nsCString &str);
|
||||
|
||||
static PRFileDesc *mSharedPollableEvent;
|
||||
static nsNSSSocketInfo *mSocketOwningPollableEvent;
|
||||
|
||||
static PRBool mPollableEventCurrentlySet;
|
||||
};
|
||||
|
||||
nsresult nsSSLIOLayerNewSocket(PRInt32 family,
|
||||
const char *host,
|
||||
PRInt32 port,
|
||||
const char *proxyHost,
|
||||
PRInt32 proxyPort,
|
||||
PRFileDesc **fd,
|
||||
nsISupports **securityInfo,
|
||||
PRBool forSTARTTLS);
|
||||
|
||||
nsresult nsSSLIOLayerAddToSocket(PRInt32 family,
|
||||
const char *host,
|
||||
PRInt32 port,
|
||||
const char *proxyHost,
|
||||
PRInt32 proxyPort,
|
||||
PRFileDesc *fd,
|
||||
nsISupports **securityInfo,
|
||||
PRBool forSTARTTLS);
|
||||
|
||||
nsresult nsSSLIOLayerFreeTLSIntolerantSites();
|
||||
nsresult displayUnknownCertErrorAlert(nsNSSSocketInfo *infoObject, int error);
|
||||
|
||||
// 16786594-0296-4471-8096-8f84497ca428
|
||||
#define NS_NSSSOCKETINFO_CID \
|
||||
{ 0x16786594, 0x0296, 0x4471, \
|
||||
{ 0x80, 0x96, 0x8f, 0x84, 0x49, 0x7c, 0xa4, 0x28 } }
|
||||
|
||||
|
||||
#endif /* _NSNSSIOLAYER_H */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,90 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef NSSCKBI_H
|
||||
#define NSSCKBI_H
|
||||
|
||||
/*
|
||||
* NSS BUILTINS Version numbers.
|
||||
*
|
||||
* These are the version numbers for the builtins module packaged with
|
||||
* this release on NSS. To determine the version numbers of the builtin
|
||||
* module you are using, use the appropriate PKCS #11 calls.
|
||||
*
|
||||
* These version numbers detail changes to the PKCS #11 interface. They map
|
||||
* to the PKCS #11 spec versions.
|
||||
*/
|
||||
#define NSS_BUILTINS_CRYPTOKI_VERSION_MAJOR 2
|
||||
#define NSS_BUILTINS_CRYPTOKI_VERSION_MINOR 20
|
||||
|
||||
/* These version numbers detail the changes
|
||||
* to the list of trusted certificates.
|
||||
*
|
||||
* The NSS_BUILTINS_LIBRARY_VERSION_MINOR macro needs to be bumped
|
||||
* for each NSS minor release AND whenever we change the list of
|
||||
* trusted certificates. 10 minor versions are allocated for each
|
||||
* NSS 3.x branch as follows, allowing us to change the list of
|
||||
* trusted certificates up to 9 times on each branch.
|
||||
* - NSS 3.5 branch: 3-9
|
||||
* - NSS 3.6 branch: 10-19
|
||||
* - NSS 3.7 branch: 20-29
|
||||
* - NSS 3.8 branch: 30-39
|
||||
* - NSS 3.9 branch: 40-49
|
||||
* - NSS 3.10 branch: 50-59
|
||||
* - NSS 3.11 branch: 60-69
|
||||
* ...
|
||||
* - NSS 3.14 branch: 90-99
|
||||
* ...
|
||||
* - NSS 3.30 branch: 250-255
|
||||
*
|
||||
* NSS_BUILTINS_LIBRARY_VERSION_MINOR is a CK_BYTE. It's not clear
|
||||
* whether we may use its full range (0-255) or only 0-99 because
|
||||
* of the comment in the CK_VERSION type definition.
|
||||
*/
|
||||
#define NSS_BUILTINS_LIBRARY_VERSION_MAJOR 1
|
||||
#define NSS_BUILTINS_LIBRARY_VERSION_MINOR 76
|
||||
#define NSS_BUILTINS_LIBRARY_VERSION "1.76"
|
||||
|
||||
/* These version numbers detail the semantic changes to the ckfw engine. */
|
||||
#define NSS_BUILTINS_HARDWARE_VERSION_MAJOR 1
|
||||
#define NSS_BUILTINS_HARDWARE_VERSION_MINOR 0
|
||||
|
||||
/* These version numbers detail the semantic changes to ckbi itself
|
||||
* (new PKCS #11 objects), etc. */
|
||||
#define NSS_BUILTINS_FIRMWARE_VERSION_MAJOR 1
|
||||
#define NSS_BUILTINS_FIRMWARE_VERSION_MINOR 0
|
||||
|
||||
#endif /* NSSCKBI_H */
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user