Many changes to XMLterm; updated for M12 Mozilla release,
autodetection of markup, document display using IFRAMEs,
Javascript command line
This commit is contained in:
svn%xmlterm.org 1999-12-26 15:19:45 +00:00
Родитель d637f1f3c9
Коммит 01c59e17b2
27 изменённых файлов: 919 добавлений и 209 удалений

Просмотреть файл

@ -86,6 +86,7 @@ CPPSRCS = \
mozXMLTermSession.cpp \
mozXMLTermListeners.cpp \
mozXMLTermShell.cpp \
mozXMLTermStream.cpp \
mozXMLTermFactory.cpp \
$(NULL)
@ -93,8 +94,8 @@ MODULE = xmlterm
IS_COMPONENT = 1
EXTRA_DSO_LDOPTS = $(TK_LIBS) \
-L$(DIST)/bin $(NSPR_LIBS) \
-L$(DIST)/bin -lxpcom
$(MOZ_COMPONENT_LIBS) \
$(NULL)
XPIDLSRCS = \
mozILineTerm.idl \

Просмотреть файл

@ -264,7 +264,8 @@ int lterm_metacomplete(int lterm, const UNICHAR *buf, int count);
* OPCODES contains a bit mask describing the type of output (see below).
* Using Extended Backus-Naur Form notation:
*
* OPCODES ::= STREAMDATA NEWLINE? COOKIESTR? XMLSTREAM? DOCSTREAM? WINSTREAM?
* OPCODES ::= STREAMDATA NEWLINE?
COOKIESTR? DOCSTREAM? XMLSTREAM? JSSTREAM? WINSTREAM?
* if StreamMode data is being returned.
*
* OPCODES ::= SCREENDATA BELL? ( CLEAR
@ -276,7 +277,7 @@ int lterm_metacomplete(int lterm, const UNICHAR *buf, int count);
* OPCODES ::= LINEDATA BELL? ( CLEAR
* | ( PROMPT | OUTPUT)? INPUT ( NEWLINE HIDE? )?
* | PROMPT? INPUT META ( COMPLETION | NEWLINE HIDE? )
* | OUTPUT NEWLINE? )
* | PROMPT? OUTPUT NEWLINE? )
* if LineMode data is being returned.
*
* If OPCODES == 0, then it means that no data has been read.
@ -324,9 +325,10 @@ int lterm_read(int lterm, int timeout, UNICHAR *buf, int count,
#define LTERM_HIDE_CODE 0x4000U /* Hide output */
#define LTERM_COOKIESTR_CODE 0x8000U /* Stream prefixed with cookie */
#define LTERM_XMLSTREAM_CODE 0x10000U /* Stream contains XML, not HTML */
#define LTERM_DOCSTREAM_CODE 0x20000U /* Stream contains complete document */
#define LTERM_WINSTREAM_CODE 0x40000U /* Display stream in entire window */
#define LTERM_DOCSTREAM_CODE 0x10000U /* Stream contains complete document */
#define LTERM_XMLSTREAM_CODE 0x20000U /* Stream contains XML, not HTML */
#define LTERM_JSSTREAM_CODE 0x40000U /* Stream contains Javascript */
#define LTERM_WINSTREAM_CODE 0x80000U /* Display stream in entire window */
/* LTERM/XTERM 16-bit style mask:

Просмотреть файл

@ -891,6 +891,7 @@ static int ltermProcessXMLTermSequence(struct lterms *lts, const UNICHAR *buf,
}
return 0;
case U_J_CHAR: /* Switch to null-terminated Javascript stream mode */
case U_S_CHAR: /* Switch to null-terminated stream mode, with cookie */
if (lto->outputMode == LTERM1_SCREEN_MODE) {
@ -904,14 +905,21 @@ static int ltermProcessXMLTermSequence(struct lterms *lts, const UNICHAR *buf,
/* Set stream codes */
streamOpcodes = 0;
if (param1)
streamOpcodes |= LTERM_XMLSTREAM_CODE;
if (termChar == U_J_CHAR) {
/* Javascript stream */
streamOpcodes |= LTERM_JSSTREAM_CODE;
if (param2)
streamOpcodes |= LTERM_DOCSTREAM_CODE;
} else {
/* HTML/XML stream */
if (param1)
streamOpcodes |= LTERM_DOCSTREAM_CODE;
if (param3)
streamOpcodes |= LTERM_WINSTREAM_CODE;
if (param2)
streamOpcodes |= LTERM_XMLSTREAM_CODE;
if (param3)
streamOpcodes |= LTERM_WINSTREAM_CODE;
}
/* Check if cookie matches */
if ((strLength > 0) && (strcmp(paramCString, lts->cookie) == 0)) {

Просмотреть файл

@ -437,7 +437,7 @@ int ltermWrite(struct lterms *lts, int *opcodes)
/** Reads a (possibly incomplete) line from LTERM.
* The LtermRead structure *LTR contains both input and output parameters,
* returning opcodes values of
* OPCODES ::= STREAMDATA NEWLINE? COOKIESTR? XMLSTREAM? DOCSTREAM? WINSTREAM?
* OPCODES ::= STREAMDATA NEWLINE? COOKIESTR? DOCSTREAM? XMLSTREAM? WINSTREAM?
* if StreamMode data is being returned.
*
* OPCODES ::= SCREENDATA BELL? ( CLEAR
@ -788,7 +788,7 @@ int ltermRead(struct lterms *lts, struct LtermRead *ltr, int timeout)
/** Returns stream data from STDOUT
* (Auxiliary procedure for ltermRead.)
* OPCODES ::= STREAMDATA NEWLINE? COOKIESTR? XMLSTREAM? DOCSTREAM? WINSTREAM?
* OPCODES ::= STREAMDATA NEWLINE? COOKIESTR? DOCSTREAM? XMLSTREAM? WINSTREAM?
* The LtermRead structure *LTR contains both input and output parameters.
* @return 0 if successful,
* -1 if an error occurred while reading,
@ -1082,20 +1082,19 @@ static int ltermReturnOutputLine(struct lterms *lts, struct LtermRead *ltr)
returnCode = -3;
}
if ((lto->promptChars > 0) && (lto->promptChars == lto->outputChars)) {
/* Copy prompt characters (plain text; no markup or escape sequences) */
/* Copy output characters (plain text; no markup or escape sequences) */
ltr->opcodes |= LTERM_OUTPUT_CODE;
for (j=0; j<charCount; j++) {
ltr->buf[j] = lto->outputLine[j];
ltr->style[j] = lto->outputStyle[j];
}
if ((lto->promptChars > 0) && (lto->promptChars <= charCount)) {
/* Set prompt style */
ltr->opcodes |= LTERM_PROMPT_CODE;
for (j=0; j<charCount; j++) {
ltr->buf[j] = lto->outputLine[j];
for (j=0; j<lto->promptChars; j++) {
ltr->style[j] = LTERM_PROMPT_STYLE;
}
} else {
/* Copy output characters (plain text; no markup or escape sequences) */
ltr->opcodes |= LTERM_OUTPUT_CODE;
for (j=0; j<charCount; j++) {
ltr->buf[j] = lto->outputLine[j];
ltr->style[j] = lto->outputStyle[j];
}
}
ltr->buf_row = -1;

Просмотреть файл

@ -77,6 +77,7 @@ LtermGlobal ltermGlobal;
int ltermClose(struct lterms *lts);
static int ltermShellInit(struct lterms *lts);
static int ltermCreatePipe(FILEDESC *writePIPE, FILEDESC *readPIPE);
static int ltermCreateProcess(struct LtermProcess *ltp,
char *const argv[], int nostderr, int noexport);
@ -388,7 +389,8 @@ int lterm_open(int lterm, char *const argv[], const char* cookie,
/* TTY options */
lts->options = options;
lts->noTTYEcho = (options & LTERM_NOECHO_FLAG) != 0;
lts->disabledInputEcho = 0;
lts->disabledInputEcho = 1;
lts->restoreInputEcho = 1;
nostderr = (options & LTERM_NOSTDERR_FLAG) != 0;
@ -524,6 +526,38 @@ int lterm_open(int lterm, char *const argv[], const char* cookie,
LTERM_LOG(lterm_open,11,("cookie='%s'\n",lts->cookie));
/* Shell initialization string */
if (lts->processType == LTERM_UNKNOWN_PROCESS) {
lts->shellInitStr[0] = '\0';
} else {
int result;
char* shellInitFormat;
if ((lts->processType == LTERM_CSH_PROCESS) ||
(lts->processType == LTERM_TCSH_PROCESS)) {
/* C-shell family */
shellInitFormat = "setenv LTERM_COOKIE '%s'\n";
} else {
/* Bourne-shell family */
shellInitFormat = "LTERM_COOKIE='%s'; export LTERM_COOKIE\n";
}
if (strlen(shellInitFormat)+strlen(lts->cookie) <= MAXSHELLINITSTR+1) {
sprintf(lts->shellInitStr, shellInitFormat, lts->cookie);
} else {
LTERM_WARNING("lterm_open: Warning - shell initialization string too long\n");
lts->shellInitStr[0] = '\0';
}
}
LTERM_LOG(lterm_open,11,("shellInitStr='%s'\n",lts->shellInitStr));
/* Shell initialization commands have not been sent yet */
lts->shellInitFlag = 0;
/* Initialize regular expression string matching command prompt */
if ((ucslen(prompt_regexp) == 0) ||
(ucslen(prompt_regexp) > MAXPROMPT-1)) {
@ -813,7 +847,16 @@ int lterm_setecho(int lterm, int echo_flag)
return -2;
}
if (!lts->shellInitFlag) {
/* send shell initialization string */
if (ltermShellInit(lts) != 0) {
GLOBAL_UNLOCK;
return -1;
}
}
lts->disabledInputEcho = !echo_flag;
lts->restoreInputEcho = 0;
GLOBAL_UNLOCK;
@ -850,6 +893,20 @@ int lterm_write(int lterm, const UNICHAR *buf, int count, int dataType)
/* Save copy of input buffer file descriptor */
writeBUFFER = lts->writeBUFFER;
if (lts->restoreInputEcho == 1) {
/* Restore TTY echo on input */
lts->restoreInputEcho = 0;
lts->disabledInputEcho = 0;
}
if (!lts->shellInitFlag) {
/* send shell initialization string */
if (ltermShellInit(lts) != 0) {
GLOBAL_UNLOCK;
return -1;
}
}
GLOBAL_UNLOCK;
assert(count >= 0);
@ -913,6 +970,8 @@ int lterm_write(int lterm, const UNICHAR *buf, int count, int dataType)
return 0;
}
/** Reads a (possibly incomplete) line from LTERM
* (documented in the LTERM interface)
*/
@ -980,12 +1039,62 @@ int lterm_read(int lterm, int timeout, UNICHAR *buf, int count,
RELEASE_UNILOCK(outputMutex,outputMutexLocked)
LTERM_LOG(lterm_read,11,("return code = %d\n", returnCode));
GLOBAL_LOCK;
if ((*opcodes != 0) && !lts->shellInitFlag) {
/* send shell initialization string */
if (ltermShellInit(lts) != 0) {
GLOBAL_UNLOCK;
return -1;
}
}
GLOBAL_UNLOCK;
LTERM_LOG(lterm_read,11,("return code = %d, opcodes=0x%x\n",
returnCode, *opcodes));
return returnCode;
}
/** Sends shell initialization string
* (WORKS UNDER GLOBAL_LOCK)
* @return 0 on success and -1 on error.
*/
static int ltermShellInit(struct lterms *lts)
{
int shellInitLen = strlen(lts->shellInitStr);
LTERM_LOG(ltermShellInit,20,("sending shell initialization string\n"));
lts->shellInitFlag = 1;
if (shellInitLen > 0) {
/* Send shell initialization string */
UNICHAR temLine[PIPEHEADER+MAXCOL];
int remaining, encoded, byteCount;
utf8toucs(lts->shellInitStr, shellInitLen,
temLine+PIPEHEADER, MAXCOL,
1, &remaining, &encoded);
if (remaining > 0) {
LTERM_ERROR("ltermShellInit: Shell initialization string too long\n");
return -1;
}
temLine[0] = (UNICHAR) encoded;
temLine[PHDR_TYPE] = (UNICHAR) LTERM_WRITE_PLAIN_INPUT;
byteCount = (PIPEHEADER+encoded)*sizeof(UNICHAR);
if (WRITE(lts->writeBUFFER, temLine, (SIZE_T)byteCount) != byteCount) {
LTERM_ERROR("ltermShellInit: Error in writing to input pipe buffer\n");
return -1;
}
}
return 0;
}
/** Creates unidirectional pipe which can be written to and read from using
* the file descriptors writePIPE and readPIPE.
* @return 0 on success and -1 on error.

Просмотреть файл

@ -424,7 +424,7 @@ int ltermSwitchToStreamMode(struct lterms *lts, int streamOpcodes,
struct LtermOutput *lto = &(lts->ltermOutput);
int strLength;
LTERM_LOG(ltermSwitchToStreamMode,40,("streamOpcodes=0x%s\n",streamOpcodes));
LTERM_LOG(ltermSwitchToStreamMode,40,("streamOpcodes=0x%x\n",streamOpcodes));
if (streamTerminator != NULL) {
/* Save terminator string (may be null) */
@ -846,7 +846,7 @@ static int ltermDecode(const char *rawBuf, int n_total,
}
LTERM_LOG(ltermDecode,41,("result=%d, incomplete=%d, n_decoded=%d\n",
result, rawIncompleteBytes, n_decoded));
result, *rawIncompleteBytes, n_decoded));
LTERM_LOGUNICODE(ltermDecode,42,(decodedBuf, n_decoded));
return n_decoded;

Просмотреть файл

@ -235,6 +235,7 @@ typedef FILE FILESTREAM;
#define MAXPROMPT 256 /* Maximum length of prompt regexp+1 */
#define MAXRAWINCOMPLETE 5 /* Maximum incomplete raw buffer size */
#define MAXSTREAMTERM 11 /* Maximum stream terminator buffer size */
#define MAXSHELLINITSTR 128 /* Maximum length of shell init string+1 */
#define MAXCOOKIESTR 64 /* Maximum length of cookie string+1 */
#define MAXESCAPEPARAMS 16 /* Maximum no. of numeric ESCAPE parameters */
#define MAXSTRINGPARAM 512 /* Maximum length of string ESCAPE parameters */
@ -469,6 +470,7 @@ struct lterms {
int ptyMode; /* pseudo-TTY mode flag */
int noTTYEcho; /* no TTY echo flag */
int disabledInputEcho; /* disabled input echo flag */
int restoreInputEcho; /* restore input echo flag */
int processType; /* Process type code */
int maxInputMode; /* maximum allowed input mode value */
@ -476,6 +478,7 @@ struct lterms {
int interleave; /* interleave STDERR/STDOUT flag */
UNICHAR control[MAXTTYCONTROL]; /* TTY control characters */
int commandNumber; /* output command number
* (0 if not command line)
*/
@ -504,6 +507,9 @@ struct lterms {
JUST A LIST OF DELIMITERS AT PRESENT */
char cookie[MAXCOOKIESTR]; /* cookie string */
char shellInitStr[MAXSHELLINITSTR];
/* shell initialization string */
int shellInitFlag; /* shell initialization flag */
struct ptys pty; /* pseudo-tty (PTY) stream info for LTERM */
struct LtermProcess ltermProcess; /* LTERM process structure */

Просмотреть файл

@ -111,7 +111,12 @@ public:
*/
NS_IMETHOD GetDocument(nsIDOMDocument** aDoc) = 0;
/** Gets presentation shell with XMLterm
/** Gets web shell associated with XMLterm
* @param aWebShell (output) web shell
*/
NS_IMETHOD GetWebShell(nsIWebShell** aWebShell) = 0;
/** Gets presentation shell associated with XMLterm
* @param aPresShell (output) presentation shell
*/
NS_IMETHOD GetPresShell(nsIPresShell** aPresShell) = 0;

Просмотреть файл

@ -667,6 +667,8 @@ NS_IMETHODIMP mozLineTerm::SetEchoFlag(PRBool aEchoFlag)
return NS_ERROR_FAILURE;
}
XMLT_LOG(mozLineTerm::SetEchoFlag,70,("aEchoFlag=0x%x\n", aEchoFlag));
if (aEchoFlag) {
result = lterm_setecho(mLTerm, 1);
} else {

Просмотреть файл

@ -51,11 +51,14 @@
#include "mozXMLT.h"
#include "mozILineTermAux.h"
#include "mozIXMLTerminal.h"
#include "mozXMLTermUtils.h"
#include "mozXMLTermSession.h"
/////////////////////////////////////////////////////////////////////////
// mozXMLTermSession definition
/////////////////////////////////////////////////////////////////////////
static const char* kWhitespace=" \b\t\r\n";
const char* const mozXMLTermSession::sessionElementNames[] = {
"session",
"entry",
@ -77,8 +80,9 @@ const char* const mozXMLTermSession::metaCommandNames[] = {
"",
"",
"http",
"ls",
"tree"
"js",
"tree",
"ls"
};
const char* const mozXMLTermSession::fileTypeNames[] = {
@ -123,6 +127,8 @@ mozXMLTermSession::mozXMLTermSession() :
mOutputDisplayNode(nsnull),
mOutputTextNode(nsnull),
mXMLTermStream(nsnull),
mMetaCommandType(NO_META_COMMAND),
mOutputDisplayType(NO_NODE),
@ -137,6 +143,9 @@ mozXMLTermSession::mozXMLTermSession() :
mPreTextBuffered(""),
mPreTextDisplayed(""),
mRestoreInputEcho(false),
mShellPrompt(""),
mPromptHTML(""),
mFragmentBuffer("")
@ -242,6 +251,8 @@ NS_IMETHODIMP mozXMLTermSession::Finalize(void)
mOutputDisplayNode = nsnull;
mOutputTextNode = nsnull;
mXMLTermStream = nsnull;
mPromptSpanNode = nsnull;
mCommandSpanNode = nsnull;
mInputTextNode = nsnull;
@ -335,16 +346,20 @@ NS_IMETHODIMP mozXMLTermSession::Preprocess(const nsString& aString,
/** Reads all available data from LineTerm and displays it;
* returns when no more data is available.
* @param lineTermAux LineTermAux object to read data from
* @param processedData (output) true if any data was processed
*/
NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux,
PRBool& processedData)
{
PRInt32 opcodes, buf_row, buf_col;
PRUnichar *buf_str, *buf_style;
PRBool newline, streamData, promptLine, inputLine, metaCommand;
PRBool newline, streamData;
nsAutoString bufString, bufStyle;
XMLT_LOG(mozXMLTermSession::ReadAll,60,("\n"));
processedData = false;
if (lineTermAux == nsnull)
return NS_ERROR_FAILURE;
@ -352,6 +367,7 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
PRBool flushOutput = false;
PRBool metaNextCommand = false;
for (;;) {
// NOTE: Remember to de-allocate buf_str and buf_style
// using nsAllocator::Free, if opcodes != 0
@ -366,6 +382,8 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
if (opcodes == 0) break;
processedData = true;
streamData = (opcodes & LTERM_STREAMDATA_CODE);
newline = (opcodes & LTERM_NEWLINE_CODE);
@ -384,11 +402,35 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
// Disable input echo
lineTermAux->SetEchoFlag(false);
mRestoreInputEcho = true;
// Determine stream markup type
OutputMarkupType streamMarkupType = HTML_FRAGMENT;
// Determine effective stream URL and default markup type
nsAutoString streamURL;
OutputMarkupType streamMarkupType;
if (opcodes & LTERM_COOKIESTR_CODE) {
// Secure stream, i.e., prefixed with cookie; fragments allowed
streamURL = "chrome://xmlterm/content/xmltblank.html";
if (opcodes & LTERM_JSSTREAM_CODE) {
// Javascript stream
streamMarkupType = JS_FRAGMENT;
} else {
// HTML/XML stream
streamMarkupType = HTML_FRAGMENT;
}
} else {
// Insecure stream; treat as text fragment
streamURL = "http://in.sec.ure";
streamMarkupType = TEXT_FRAGMENT;
}
if (!(opcodes & LTERM_JSSTREAM_CODE) &&
(opcodes & LTERM_DOCSTREAM_CODE)) {
// Stream contains complete document (not Javascript)
if (opcodes & LTERM_DOCSTREAM_CODE) {
if (opcodes & LTERM_XMLSTREAM_CODE) {
streamMarkupType = XML_DOCUMENT;
} else {
@ -397,7 +439,6 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
}
// Initialize stream output
nsAutoString streamURL = "";
result = InitStream(streamURL, streamMarkupType);
if (NS_FAILED(result))
return result;
@ -405,7 +446,7 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
// Process stream output
bufStyle = "";
result = ProcessOutput(bufString, bufStyle, true, true);
result = ProcessOutput(bufString, bufStyle, false, true);
if (NS_FAILED(result))
return result;
@ -422,24 +463,24 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
mMetaCommandType = NO_META_COMMAND;
flushOutput = true;
// Enable input echo
lineTermAux->SetEchoFlag(false);
}
} else {
// Process non-stream data
PRBool promptLine, inputLine, metaCommand, completionRequested;
flushOutput = true;
inputLine = (opcodes & LTERM_INPUT_CODE);
promptLine = (opcodes & LTERM_PROMPT_CODE);
metaCommand = (opcodes & LTERM_META_CODE);
completionRequested = (opcodes & LTERM_COMPLETION_CODE);
nsAutoString promptStr ("");
PRInt32 promptLength = 0;
if (promptLine) {
// Process prompt
// Count prompt characters
const PRUnichar *styleVals = bufStyle.GetUnicode();
const PRInt32 bufLength = bufStyle.Length();
@ -457,28 +498,48 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
// Extract prompt string
bufString.Left(promptStr, promptLength);
// Remove prompt chars/style from buffer strings
bufString.Cut(0, promptLength);
bufStyle.Cut(0, promptLength);
if ( (promptLength < bufLength) &&
!inputLine &&
!promptStr.Equals(mShellPrompt) ) {
// Ignore the mismatched prompt in the output line
int j;
promptLine = 0;
for (j=0; j<promptLength; j++)
bufStyle.SetCharAt((UNICHAR) LTERM_STDOUT_STYLE, j);
} else {
// Remove prompt chars/style from buffer strings
bufString.Cut(0, promptLength);
bufStyle.Cut(0, promptLength);
// Save prompt string
mShellPrompt = promptStr;
}
}
if (!metaCommand && inputLine) {
if (metaNextCommand) {
// Echo of transmitted meta command
metaNextCommand = false;
} else {
// No meta command; enable input echo
mMetaCommandType = NO_META_COMMAND;
lineTermAux->SetEchoFlag(true);
if (mRestoreInputEcho) {
lineTermAux->SetEchoFlag(true);
mRestoreInputEcho = false;
}
}
}
if (metaCommand) {
if (metaCommand && !completionRequested) {
// Identify meta command type
// Eliminate leading spaces/TABs
nsAutoString metaLine = bufString;
metaLine.Trim(" \t", PR_TRUE, PR_FALSE);
metaLine.Trim(kWhitespace, PR_TRUE, PR_FALSE);
int delimOffset = metaLine.FindChar((PRUnichar) ':');
PR_ASSERT(delimOffset >= 0);
@ -514,12 +575,74 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
metaLine.Right(commandArgs, argChars);
// Eliminate leading spaces/TABs
commandArgs.Trim(" \t", PR_TRUE, PR_FALSE);
commandArgs.Trim(kWhitespace, PR_TRUE, PR_FALSE);
// Display meta command
if (mEntryHasOutput) {
// Break previous output display
result = BreakOutput();
// Create new entry block
result = NewEntry(promptStr);
if (NS_FAILED(result))
return result;
}
// Display input and position cursor
PRInt32 cursorCol = 0;
result = lineTermAux->GetCursorColumn(&cursorCol);
// Remove prompt offset
cursorCol -= promptLength;
if (cursorCol < 0) cursorCol = 0;
XMLT_LOG(mozXMLTermSession::ReadAll,62,("cursorCol=%d\n", cursorCol));
result = DisplayInput(bufString, bufStyle, cursorCol);
if (NS_FAILED(result))
return NS_ERROR_FAILURE;
if (newline && mXMLTerminal) {
// Complete meta command; XMLterm instantiated
nsAutoString metaCommandOutput = "";
switch (mMetaCommandType) {
case HTTP_META_COMMAND:
{
// Display URL using IFRAME
nsAutoString url = "http:";
url.Append(commandArgs);
nsAutoString width = "100%";
nsAutoString height = "100";
result = NewIFrame(mCurrentEntryNumber, mOutputBlockNode,
url, width, height);
if (NS_FAILED(result))
return result;
}
break;
case JS_META_COMMAND:
{
// Execute JavaScript command
result = mozXMLTermUtils::ExecuteScript(mDOMDocument,
commandArgs,
metaCommandOutput);
if (NS_FAILED(result))
metaCommandOutput = "Error in executing JavaScript command\n";
nsCAutoString cstrout = metaCommandOutput;
printf("mozXMLTermSession::ReadAll, JS output=%s\n",
cstrout.GetBuffer());
}
break;
case TREE_META_COMMAND:
XMLT_WARNING("\nTraverseDOMTree: use arrow keys; A for attributes; H for HTML; Q to quit\n");
break;
case LS_META_COMMAND:
{
// Disable input echo and transmit command
@ -538,42 +661,44 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
/* Set flag to recognize transmitted command */
metaNextCommand = true;
mRestoreInputEcho = true;
}
break;
case TREE_META_COMMAND:
XMLT_WARNING("\nTraverseDOMTree: use arrow keys; A for attributes; H for HTML; Q to quit\n");
default:
break;
}
if (mMetaCommandType == JS_META_COMMAND) {
// Display metacommand output
mEntryHasOutput = true;
XMLT_LOG(mozXMLTermSession::ReadAll,62,("metaCommandOutput\n"));
// Check metacommand output for markup (secure)
result = AutoDetectMarkup(metaCommandOutput, true, true);
if (NS_FAILED(result))
return result;
nsAutoString nullStyle ("");
result = ProcessOutput(metaCommandOutput, nullStyle, true,
mOutputMarkupType != PLAIN_TEXT);
if (NS_FAILED(result))
return result;
// Break metacommand output display
result = BreakOutput();
}
// Reset newline flag
newline = false;
}
// Clear the meta command from the string nuffer
bufString = "";
bufStyle = "";
}
if (!promptLine) {
// Not prompt line
if (!mEntryHasOutput) {
// Start of command output
mEntryHasOutput = true;
mFirstOutputLine = true;
}
if (newline) {
// Complete line; check for markup
result = AutoDetectMarkup(bufString, bufStyle, mFirstOutputLine);
if (NS_FAILED(result))
return result;
// Not first output line anymore
mFirstOutputLine = false;
}
// Display output
result = ProcessOutput(bufString, bufStyle, newline, false);
if (NS_FAILED(result))
return result;
} else {
if (promptLine) {
// Prompt line
if (mEntryHasOutput) {
// Break previous output display
@ -604,6 +729,39 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux)
// (this is needed to properly handle commands with no output!)
mEntryHasOutput = true;
mFirstOutputLine = true;
}
} else {
// Not prompt line
if (!mEntryHasOutput) {
// Start of command output
mEntryHasOutput = true;
mFirstOutputLine = true;
}
if (newline) {
// Complete line; check for markup (insecure)
result = AutoDetectMarkup(bufString, mFirstOutputLine, false);
if (NS_FAILED(result))
return result;
// Not first output line anymore
mFirstOutputLine = false;
}
if (mOutputMarkupType == PLAIN_TEXT) {
// Display plain text output
result = ProcessOutput(bufString, bufStyle, newline, false);
if (NS_FAILED(result))
return result;
} else if (newline) {
// Process autodetected stream output (complete lines only)
bufStyle = "";
result = ProcessOutput(bufString, bufStyle, true, true);
if (NS_FAILED(result))
return result;
}
}
}
@ -694,15 +852,19 @@ NS_IMETHODIMP mozXMLTermSession::DisplayInput(const nsString& aString,
/** Autodetects markup in current output line
* @param aString string to be displayed
* @param firstOutputLine true if this is the first output line
* @param secure true if output data is secure
* (usually true for metacommand output only)
*/
NS_IMETHODIMP mozXMLTermSession::AutoDetectMarkup(const nsString& aString,
const nsString& aStyle,
PRBool firstOutputLine)
PRBool firstOutputLine,
PRBool secure)
{
nsresult result;
XMLT_LOG(mozXMLTermSession::AutoDetectMarkup,70,("\n"));
XMLT_LOG(mozXMLTermSession::AutoDetectMarkup,70,("firstOutputLine=0x%x\n",
firstOutputLine));
// If autodetect disabled or not plain text, do nothing
if ((mAutoDetect == NO_MARKUP) ||
@ -712,9 +874,50 @@ NS_IMETHODIMP mozXMLTermSession::AutoDetectMarkup(const nsString& aString,
OutputMarkupType newMarkupType = PLAIN_TEXT;
// Copy string and trim leading spaces/backspaces/tabs
nsAutoString str = aString;
str.Trim(kWhitespace, PR_TRUE, PR_FALSE);
if (str.First() == U_LESSTHAN) {
// Markup tag detected
str.CompressWhitespace();
str.Append(" ");
if ( (str.Find("<!DOCTYPE HTML",PR_TRUE) == 0) ||
(str.Find("<BASE ",PR_TRUE) == 0) ||
(str.Find("<HTML>",PR_TRUE) == 0) ) {
// HTML document
newMarkupType = HTML_DOCUMENT;
} else if (str.Find("<?xml ",PR_FALSE) == 0) {
// XML document
newMarkupType = XML_DOCUMENT;
} else {
// HTML fragment
if (secure) {
// Secure HTML fragment
newMarkupType = HTML_FRAGMENT;
} else {
// Insecure; treat as text fragment for security reasons
newMarkupType = TEXT_FRAGMENT;
}
}
} else if (firstOutputLine && str.Find("Content-Type",PR_TRUE) == 0) {
// Possible MIME content type header
str.StripWhitespace();
if (str.Find("Content-Type:text/html",PR_TRUE) == 0) {
// MIME content type header for HTML document
newMarkupType = HTML_DOCUMENT;
}
}
if (newMarkupType != PLAIN_TEXT) {
// Markup found; initialize stream
nsAutoString streamURL = "";
// Markup found; initialize (insecure) stream
nsAutoString streamURL = "http://in.sec.ure";
result = InitStream(streamURL, newMarkupType);
if (NS_FAILED(result))
return result;
@ -724,13 +927,16 @@ NS_IMETHODIMP mozXMLTermSession::AutoDetectMarkup(const nsString& aString,
mOutputMarkupType = PLAIN_TEXT;
}
XMLT_LOG(mozXMLTermSession::AutoDetectMarkup,71,("mOutputMarkupType=%d\n",
mOutputMarkupType));
return NS_OK;
}
/** Initializes display of stream output with specified markup type
* @param streamURL effective URL of stream output
* @param streamMarkupType stream markup stype
* @param streamMarkupType stream markup type
*/
NS_IMETHODIMP mozXMLTermSession::InitStream(const nsString& streamURL,
OutputMarkupType streamMarkupType)
@ -745,17 +951,72 @@ NS_IMETHODIMP mozXMLTermSession::InitStream(const nsString& streamURL,
if (NS_FAILED(result))
return result;
// Initialize markup handling
switch (mOutputMarkupType) {
case HTML_FRAGMENT:
if ((streamMarkupType == TEXT_FRAGMENT) ||
(streamMarkupType == JS_FRAGMENT) ||
(streamMarkupType == HTML_FRAGMENT)) {
// Initialize fragment buffer
mFragmentBuffer = "";
break;
default:
PR_ASSERT(0);
break;
} else {
// Create IFRAME to display stream document
nsAutoString src = "about:blank";
nsAutoString width = "100%";
nsAutoString height = "10";
result = NewIFrame(mCurrentEntryNumber, mOutputBlockNode,
src, width, height);
if (NS_FAILED(result))
return result;
result = NS_NewXMLTermStream(getter_AddRefs(mXMLTermStream));
if (NS_FAILED(result))
return result;
nsCOMPtr<nsIWebShell> webShell;
result = mXMLTerminal->GetWebShell(getter_AddRefs(webShell));
if (NS_FAILED(result) || !webShell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMWindow> outerDOMWindow;
result = mozXMLTermUtils::ConvertWebShellToDOMWindow(webShell,
getter_AddRefs(outerDOMWindow));
if (NS_FAILED(result) || !outerDOMWindow) {
fprintf(stderr,
"mozXMLTermSession::InitStream: Failed to convert webshell\n");
return NS_ERROR_FAILURE;
}
// Initialize markup handling
nsCAutoString iframeName = "iframet";
//iframeName.Append(mCurrentEntryNumber,10);
nsCAutoString contentType;
switch (streamMarkupType) {
case HTML_DOCUMENT:
contentType = "text/html";
break;
case XML_DOCUMENT:
contentType = "text/xml";
break;
default:
PR_ASSERT(0);
break;
}
nsCAutoString url ( streamURL );
result = mXMLTermStream->Open(outerDOMWindow, iframeName.GetBuffer(),
url.GetBuffer(),
contentType.GetBuffer(), 800);
if (NS_FAILED(result)) {
fprintf(stderr, "mozXMLTerminal::Activate: Failed to open stream\n");
return result;
}
}
mOutputMarkupType = streamMarkupType;
@ -772,8 +1033,60 @@ NS_IMETHODIMP mozXMLTermSession::BreakOutput(void)
XMLT_LOG(mozXMLTermSession::BreakOutput,70,("mOutputMarkupType=%d\n",
mOutputMarkupType));
if (!mEntryHasOutput)
return NS_OK;
switch (mOutputMarkupType) {
case TEXT_FRAGMENT:
{
// Display text fragment using new SPAN node
nsCOMPtr<nsIDOMNode> spanNode, textNode;
nsAutoString tagName = "span";
nsAutoString elementName = "stream";
result = NewElementWithText(tagName, elementName, -1,
mOutputBlockNode, spanNode, textNode);
if (NS_FAILED(result) || !spanNode || !textNode)
return NS_ERROR_FAILURE;
// Append node
nsCOMPtr<nsIDOMNode> resultNode;
result = mOutputBlockNode->AppendChild(spanNode,
getter_AddRefs(resultNode));
// Display text
result = SetDOMText(textNode, mFragmentBuffer);
if (NS_FAILED(result))
return result;
mFragmentBuffer = "";
break;
}
case JS_FRAGMENT:
{
// Execute JS fragment
nsAutoString jsOutput = "";
result = mozXMLTermUtils::ExecuteScript(mDOMDocument,
mFragmentBuffer,
jsOutput);
if (NS_FAILED(result))
jsOutput = "Error in JavaScript execution\n";
mFragmentBuffer = "";
if (jsOutput.Length() > 0) {
// Display JS output as HTML fragment
result = InsertFragment(jsOutput, mOutputBlockNode,
mCurrentEntryNumber);
if (NS_FAILED(result))
return result;
}
}
break;
case HTML_FRAGMENT:
// Display HTML fragment
result = InsertFragment(mFragmentBuffer, mOutputBlockNode,
@ -785,7 +1098,14 @@ NS_IMETHODIMP mozXMLTermSession::BreakOutput(void)
break;
case HTML_DOCUMENT:
// Close HTML document
case XML_DOCUMENT:
// Close HTML/XML document
result = mXMLTermStream->Close();
if (NS_FAILED(result)) {
fprintf(stderr, "mozXMLTermSession::BreakOutput: Failed to close stream\n");
return result;
}
mXMLTermStream = nsnull;
break;
default:
@ -839,23 +1159,31 @@ NS_IMETHODIMP mozXMLTermSession::ProcessOutput(const nsString& aString,
switch (mOutputMarkupType) {
case TEXT_FRAGMENT:
case JS_FRAGMENT:
case HTML_FRAGMENT:
// Append complete lines to HTML fragment buffer
// Append complete lines to fragment buffer
if (newline || streamOutput) {
mFragmentBuffer += aString;
if (!streamOutput)
if (newline)
mFragmentBuffer += '\n';
}
break;
case HTML_DOCUMENT:
case XML_DOCUMENT:
// Write complete lines to document stream
if (newline || streamOutput) {
// ********** streamWrite(aString.GetUnicode());
if (!streamOutput) {
static const PRUnichar lineFeed[] = {U_LINEFEED, U_NUL};
// ************ streamWrite(lineFeed);
nsAutoString str = aString;
if (newline)
str.Append("\n");
result = mXMLTermStream->Write(str.GetUnicode());
if (NS_FAILED(result)) {
fprintf(stderr, "mozXMLTermSession::ProcessOutput: Failed to write to stream\n");
return result;
}
}
break;
@ -1060,7 +1388,7 @@ NS_IMETHODIMP mozXMLTermSession::AppendOutput(const nsString& aString,
// Display line
result = SetDOMText(mOutputTextNode, aString);
if (NS_FAILED(result))
return NS_ERROR_FAILURE;
return NS_ERROR_FAILURE;
if (newline) {
mOutputDisplayType = NO_NODE;
@ -1134,7 +1462,7 @@ NS_IMETHODIMP mozXMLTermSession::AppendLineLS(const nsString& aString,
if (wordBegin >= lineLength) break;
// Locate end of word (non-space character)
PRInt32 wordEnd = aString.FindCharInSet(" \t", wordBegin);
PRInt32 wordEnd = aString.FindCharInSet(kWhitespace, wordBegin);
if (wordEnd < 0) {
wordEnd = lineLength-1;
} else {
@ -1261,8 +1589,8 @@ NS_IMETHODIMP mozXMLTermSession::AppendLineLS(const nsString& aString,
* @param replace if true, replace beforeNode with inserted fragment
* (default value is false)
*/
NS_IMETHODIMP mozXMLTermSession::InsertFragment(const nsString& aString,
nsCOMPtr<nsIDOMNode>& parentNode,
NS_IMETHODIMP mozXMLTermSession::InsertFragment(const nsString& aString,
nsIDOMNode* parentNode,
PRInt32 entryNumber,
nsIDOMNode* beforeNode,
PRBool replace)
@ -2103,6 +2431,89 @@ NS_IMETHODIMP mozXMLTermSession::NewTextNode( nsIDOMNode* parentNode,
}
/** Creates a new IFRAME element with attributes NAME="iframe#",
* FRAMEBORDER="0" and appends it as a child of the specified parent.
* ("#" denotes the specified number)
* @param number numeric suffix for element ID
* (If < 0, no name attribute is defined)
* @param parentNode parent node for element
* @param src IFRAME SRC attribute
* @param width IFRAME width attribute
* @param height IFRAME height attribute
*/
NS_IMETHODIMP mozXMLTermSession::NewIFrame(PRInt32 number,
nsIDOMNode* parentNode,
const nsString& src,
const nsString& width,
const nsString& height)
{
nsresult result;
XMLT_LOG(mozXMLTermSession::NewIFrame,80,("\n"));
#if 0
nsAutoString iframeFrag = "<iframe name='iframe";
iframeFrag.Append(number,10);
iframeFrag.Append("' src='");
iframeFrag.Append(src)
iframeFrag.Append("' frameborder=0> </iframe>\n");
result = InsertFragment(iframeFrag, parentNode, number);
if (NS_FAILED(result))
return result;
return NS_OK;
#else
// Create IFRAME element
nsCOMPtr<nsIDOMElement> newElement;
nsAutoString tagName = "iframe";
result = mDOMDocument->CreateElement(tagName, getter_AddRefs(newElement));
if (NS_FAILED(result) || !newElement)
return NS_ERROR_FAILURE;
nsAutoString attName, attValue;
// Set attributes
if (number >= 0) {
attName = "name";
attValue = "iframe";
attValue.Append(number,10);
newElement->SetAttribute(attName, attValue);
}
attName = "frameborder";
attValue = "0";
newElement->SetAttribute(attName, attValue);
if (src.Length() > 0) {
// Set SRC attribute
attName = "src";
newElement->SetAttribute(attName, src);
}
if (width.Length() > 0) {
// Set WIDTH attribute
attName = "width";
newElement->SetAttribute(attName, width);
}
if (height.Length() > 0) {
// Set HEIGHT attribute
attName = "height";
newElement->SetAttribute(attName, height);
}
// Append child to parent
nsCOMPtr<nsIDOMNode> iframeNode;
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(newElement);
result = parentNode->AppendChild(newNode, getter_AddRefs(iframeNode));
if (NS_FAILED(result) || !iframeNode)
return NS_ERROR_FAILURE;
return NS_OK;
#endif
}
/** Add event attributes (onclick, ondblclick, ...) to DOM node
* @param name name of DOM node (supplied as argument to the event handler)
* @param number entry number (supplied as argument to the event handler)

Просмотреть файл

@ -38,6 +38,7 @@
#include "mozXMLT.h"
#include "mozILineTermAux.h"
#include "mozIXMLTerminal.h"
#include "mozIXMLTermStream.h"
class mozXMLTermSession
@ -69,8 +70,9 @@ class mozXMLTermSession
/** Reads all available data from LineTerm and displays it;
* returns when no more data is available.
* @param lineTermAux LineTermAux object to read data from
* @param processedData (output) true if any data was processed
*/
NS_IMETHOD ReadAll(mozILineTermAux* lineTermAux);
NS_IMETHOD ReadAll(mozILineTermAux* lineTermAux, PRBool& processedData);
/** Gets current entry (command) number
* @param aNumber (output) current entry number
@ -136,6 +138,8 @@ protected:
/** markup style of output */
enum OutputMarkupType {
PLAIN_TEXT = 0,
TEXT_FRAGMENT,
JS_FRAGMENT,
HTML_FRAGMENT,
HTML_DOCUMENT,
XML_DOCUMENT
@ -161,8 +165,9 @@ protected:
NO_META_COMMAND = 0,
STREAM_META_COMMAND,
HTTP_META_COMMAND,
LS_META_COMMAND,
JS_META_COMMAND,
TREE_META_COMMAND,
LS_META_COMMAND,
META_COMMAND_TYPES
};
@ -196,12 +201,13 @@ protected:
/** Autodetects markup in current output line
* @param aString string to be displayed
* @param aStyle style values for string (see lineterm.h)
* @param firstOutputLine true if this is the first output line
* @param secure true if output data is secure
* (usually true for metacommand output only)
*/
NS_IMETHOD AutoDetectMarkup(const nsString& aString,
const nsString& aStyle,
PRBool firstOutputLine);
PRBool firstOutputLine,
PRBool secure);
/** Initializes display of stream output with specified markup type
* @param streamURL effective URL of stream output
@ -258,7 +264,7 @@ protected:
* (default value is false)
*/
NS_IMETHOD InsertFragment(const nsString& aString,
nsCOMPtr<nsIDOMNode>& parentNode,
nsIDOMNode* parentNode,
PRInt32 entryNumber = -1,
nsIDOMNode* beforeNode = nsnull,
PRBool replace = false);
@ -363,6 +369,22 @@ protected:
NS_IMETHOD NewTextNode( nsIDOMNode* parentNode,
nsCOMPtr<nsIDOMNode>& textNode);
/** Creates a new IFRAME element with attributes NAME="iframe#",
* FRAMEBORDER="0" and appends it as a child of the specified parent.
* ("#" denotes the specified number)
* @param number numeric suffix for element ID
* (If < 0, no name attribute is defined)
* @param parentNode parent node for element
* @param src IFRAME SRC attribute
* @param width IFRAME width attribute
* @param height IFRAME height attribute
*/
NS_IMETHOD NewIFrame(PRInt32 number,
nsIDOMNode* parentNode,
const nsString& src,
const nsString& width,
const nsString& height);
/** Add event attributes (onclick, ondblclick, ...) to DOM node
* @param name name of DOM node (supplied as argument to the event handler)
* @param number entry number (supplied as argument to the event handler)
@ -495,6 +517,9 @@ protected:
/** current text node for command output */
nsCOMPtr<nsIDOMNode> mOutputTextNode;
/** current XMLTerm stream interface for stream display */
nsCOMPtr<mozIXMLTermStream> mXMLTermStream;
/** currently active meta command (if any) */
MetaCommandType mMetaCommandType;
@ -528,6 +553,12 @@ protected:
nsString mPreTextDisplayed;
/** restore input echo flag */
PRBool mRestoreInputEcho;
/** shell prompt string */
nsString mShellPrompt;
/** prompt string (HTML) */
nsString mPromptHTML;

Просмотреть файл

@ -55,7 +55,7 @@
#include "nsIDocument.h"
#include "nsIURL.h"
#include "nsNeckoUtil.h"
#include "nsNetUtil.h"
#include "mozXMLT.h"
#include "mozXMLTermUtils.h"
@ -92,11 +92,15 @@ mozXMLTermStream::mozXMLTermStream() :
mUTF8Offset(0),
mMaxResizeHeight(0),
mDOMWindow( nsnull ),
#ifdef NO_WORKAROUND
mDOMIFrameElement( nsnull ),
mContext( nsnull ),
mLoadGroup( nsnull ),
mChannel( nsnull ),
mStreamListener( nsnull )
#else // !NO_WORKAROUND
mDOMHTMLDocument( nsnull )
#endif // !NO_WORKAROUND
{
NS_INIT_REFCNT();
}
@ -247,9 +251,8 @@ NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindow* aDOMWindow,
if (NS_FAILED(result) || !webShell)
return NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIIOService, ioService, kIOServiceCID, &result);
if (NS_FAILED(result))
return result;
#ifdef NO_WORKAROUND
printf("mozXMLTermStream::Open, NO_WORKAROUND\n");
nsCOMPtr<nsIInputStream> inputStream = this;
@ -258,14 +261,17 @@ NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindow* aDOMWindow,
if (NS_FAILED(result))
return result;
result = NS_NewLoadGroup(nsnull, nsnull, nsnull, getter_AddRefs(mLoadGroup));
result = NS_NewLoadGroup(nsnull, getter_AddRefs(mLoadGroup));
if (NS_FAILED(result))
return result;
PRInt32 contentLength = 1024; // ??? What's this length
result = ioService->NewInputStreamChannel(uri, contentType, contentLength,
inputStream, mLoadGroup, nsnull,
getter_AddRefs(mChannel));
result = NS_NewInputStreamChannel(uri, contentType, contentLength,
inputStream, mLoadGroup,
nsnull, // notificationCallbacks
nsIChannel::LOAD_NORMAL,
nsnull, 0, 0,
getter_AddRefs(mChannel));
if (NS_FAILED(result))
return result;
@ -314,6 +320,25 @@ NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindow* aDOMWindow,
result = mStreamListener->OnStartRequest(mChannel, mContext);
if (NS_FAILED(result))
return result;
#else // !NO_WORKAROUND
printf("mozXMLTermStream::Open, WORKAROUND\n");
nsCOMPtr<nsIDOMDocument> innerDOMDoc;
result = mDOMWindow->GetDocument(getter_AddRefs(innerDOMDoc));
printf("mozXMLTermStream::Open,check1, 0x%x\n", result);
if (NS_FAILED(result) || !innerDOMDoc)
return NS_ERROR_FAILURE;
mDOMHTMLDocument = do_QueryInterface(innerDOMDoc);
printf("mozXMLTermStream::Open,check2, 0x%x\n", result);
if (!mDOMHTMLDocument)
return NS_ERROR_FAILURE;
result = mDOMHTMLDocument->Open();
printf("mozXMLTermStream::Open,check3, 0x%x\n", result);
if (NS_FAILED(result))
return result;
#endif // !NO_WORKAROUND
XMLT_LOG(mozXMLTermStream::Open,21,("returning\n"));
@ -331,6 +356,7 @@ NS_IMETHODIMP mozXMLTermStream::Close(void)
mUTF8Buffer = "";
mUTF8Offset = 0;
#ifdef NO_WORKAROUND
PRUint32 sourceOffset = 0;
PRUint32 count = 0;
result = mStreamListener->OnDataAvailable(mChannel, mContext,
@ -345,6 +371,17 @@ NS_IMETHODIMP mozXMLTermStream::Close(void)
if (NS_FAILED(result))
return result;
mContext = nsnull;
mLoadGroup = nsnull;
mChannel = nsnull;
mStreamListener = nsnull;
#else // !NO_WORKAROUND
result = mDOMHTMLDocument->Close();
if (NS_FAILED(result))
return result;
#endif // !NO_WORKAROUND
if (mMaxResizeHeight && mDOMIFrameElement) {
// Size frame to content
result = SizeToContentHeight(mMaxResizeHeight);
@ -354,10 +391,6 @@ NS_IMETHODIMP mozXMLTermStream::Close(void)
// Release interfaces etc
mDOMWindow = nsnull;
mDOMIFrameElement = nsnull;
mContext = nsnull;
mLoadGroup = nsnull;
mChannel = nsnull;
mStreamListener = nsnull;
return NS_OK;
}
@ -551,6 +584,7 @@ NS_IMETHODIMP mozXMLTermStream::Write(const PRUnichar* buf)
mUTF8Offset = 0;
#ifdef NO_WORKAROUND
PRUint32 sourceOffset = 0;
while (mUTF8Offset < mUTF8Buffer.Length()) {
@ -561,6 +595,14 @@ NS_IMETHODIMP mozXMLTermStream::Write(const PRUnichar* buf)
return result;
}
#else // !NO_WORKAROUND
result = mDOMHTMLDocument->Write(strBuf);
if (NS_FAILED(result))
return result;
#endif // !NO_WORKAROUND
printf("mozXMLTermStream::Write: str=%s\n", mUTF8Buffer.GetBuffer());
XMLT_LOG(mozXMLTermStream::Write,51,("returning mUTF8Offset=%d\n",
mUTF8Offset));

Просмотреть файл

@ -81,6 +81,7 @@ class mozXMLTermStream : public mozIXMLTermStream
/** Frame element in which to display stream */
nsCOMPtr<nsIDOMElement> mDOMIFrameElement;
#ifdef NO_WORKAROUND
/** Context for stream display (what's this??) */
nsCOMPtr<nsISupports> mContext;
@ -92,5 +93,8 @@ class mozXMLTermStream : public mozIXMLTermStream
/** Stream listener object */
nsCOMPtr<nsIStreamListener> mStreamListener;
#else // !NO_WORKAROUND
nsCOMPtr<nsIDOMHTMLDocument> mDOMHTMLDocument;
#endif // !NO_WORKAROUND
};

Просмотреть файл

@ -26,6 +26,7 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIInterfaceRequestor.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
@ -147,12 +148,9 @@ mozXMLTermUtils::ConvertWebShellToDOMWindow(nsIWebShell* aWebShell,
*aDOMWindow = nsnull;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObj(do_QueryInterface(aWebShell));
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject(do_GetInterface(aWebShell));
if (!scriptGlobalObj)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(scriptGlobalObj));
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(scriptGlobalObject));
if (!domWindow)
return NS_ERROR_FAILURE;
@ -349,12 +347,14 @@ mozXMLTermUtils::ExecuteScript(nsIDOMDocument* aDOMDocument,
// Execute script
PRBool isUndefined = PR_FALSE;
nsString outputString = "";
const char* URL = "";
const char* version = "";
result = scriptContext-> EvaluateString(aScript, (void *) nsnull,
docPrincipal, URL, 0, version,
aOutput, &isUndefined);
result = scriptContext->EvaluateString(aScript, (void *) nsnull,
docPrincipal, URL, 0, nsnull,
aOutput, &isUndefined);
XMLT_LOG(mozXMLTermUtils::ExecuteScript,0,("result=0x%x, isUndefined=0x%x\n",
result, isUndefined));
return result;
}

Просмотреть файл

@ -92,6 +92,7 @@ mozXMLTerminal::mozXMLTerminal() :
mCommand(""),
mPromptExpr(""),
mFirstInput(""),
mXMLTermShell(nsnull),
@ -109,6 +110,7 @@ mozXMLTerminal::mozXMLTerminal() :
mDragListener(nsnull)
{
NS_INIT_REFCNT();
mFirstInputLock = PR_NewLock();
}
@ -117,6 +119,8 @@ mozXMLTerminal::~mozXMLTerminal()
if (mInitialized) {
Finalize();
}
PR_DestroyLock(mFirstInputLock);
}
@ -341,10 +345,12 @@ NS_IMETHODIMP mozXMLTerminal::Activate(void)
result = mozXMLTermUtils::ConvertWebShellToDOMWindow(mWebShell,
getter_AddRefs(outerDOMWindow));
if (NS_FAILED(result) || !outerDOMWindow)
if (NS_FAILED(result) || !outerDOMWindow) {
fprintf(stderr, "mozXMLTerminal::Activate: Failed to convert webshell\n");
return NS_ERROR_FAILURE;
}
result = stream->Open(outerDOMWindow, "iframe1", "chrome://dummy",
result = stream->Open(outerDOMWindow, "iframet", "chrome://dummy",
"text/html", 800);
if (NS_FAILED(result)) {
fprintf(stderr, "mozXMLTerminal::Activate: Failed to open stream\n");
@ -450,13 +456,6 @@ NS_IMETHODIMP mozXMLTerminal::Activate(void)
// Save cookie
mCookie = cookie;
if (mFirstInput.Length() > 0) {
// Send first input command line
result = SendTextAux(mFirstInput);
if (NS_FAILED(result))
return result;
}
// Get the DOM event receiver for document
nsCOMPtr<nsIDOMEventReceiver> eventReceiver;
result = mDOMDocument->QueryInterface(nsIDOMEventReceiver::GetIID(),
@ -547,12 +546,26 @@ NS_IMETHODIMP mozXMLTerminal::SendText(const nsString& aString,
if (!mLineTermAux)
return NS_ERROR_FAILURE;
nsAutoString sendStr = aString;
// Preprocess string and check if it is to be consumed
PRBool consumed = false;
result = mXMLTermSession->Preprocess(aString, consumed);
result = mXMLTermSession->Preprocess(sendStr, consumed);
if (!consumed) {
result = mLineTermAux->Write(aString.GetUnicode(), aCookie);
PR_Lock(mFirstInputLock);
if (mFirstInput.Length() > 0) {
result = mLineTermAux->Write(mFirstInput.GetUnicode(), aCookie);
if (NS_FAILED(result))
return result;
mFirstInput = "";
}
PR_Unlock(mFirstInputLock);
result = mLineTermAux->Write(sendStr.GetUnicode(), aCookie);
if (NS_FAILED(result)) {
// Close LineTerm
mLineTermAux->Close(aCookie);
@ -642,7 +655,29 @@ NS_IMETHODIMP mozXMLTerminal::Poll(void)
XMLT_LOG(mozXMLTerminal::Poll,20,("\n"));
return mXMLTermSession->ReadAll(mLineTermAux);
nsresult result;
PRBool processedData;
result = mXMLTermSession->ReadAll(mLineTermAux, processedData);
if (NS_FAILED(result))
return result;
if (processedData && (mFirstInput.Length() > 0)) {
// Send first input command line(s)
PR_Lock(mFirstInputLock);
result = mLineTermAux->Write(mFirstInput.GetUnicode(),
mCookie.GetUnicode());
mFirstInput = "";
PR_Unlock(mFirstInputLock);
if (NS_FAILED(result))
return result;
}
return NS_OK;
}
@ -654,7 +689,9 @@ NS_IMETHODIMP mozXMLTerminal::Observe(nsISupports *aSubject,
nsCOMPtr<mozILineTermAux> lineTermAux = do_QueryInterface(aSubject);
PR_ASSERT(lineTermAux != nsnull);
return mXMLTermSession->ReadAll(lineTermAux);
PR_ASSERT(lineTermAux.get() == mLineTermAux.get());
return Poll();
}
@ -673,6 +710,21 @@ NS_IMETHODIMP mozXMLTerminal::GetDocument(nsIDOMDocument** aDoc)
}
// Returns web shell associated with XMLTerm
NS_IMETHODIMP mozXMLTerminal::GetWebShell(nsIWebShell** aWebShell)
{
if (!aWebShell)
return NS_ERROR_NULL_POINTER;
*aWebShell = nsnull;
NS_PRECONDITION(mWebShell, "bad state, null mWebShell");
if (!mWebShell)
return NS_ERROR_NOT_INITIALIZED;
return mWebShell->QueryInterface(nsIWebShell::GetIID(),
(void **)aWebShell);
}
// Returns presentation shell associated with XMLTerm
NS_IMETHODIMP mozXMLTerminal::GetPresShell(nsIPresShell** aPresShell)
{
@ -687,6 +739,7 @@ NS_IMETHODIMP mozXMLTerminal::GetPresShell(nsIPresShell** aPresShell)
(void **)aPresShell);
}
// nsIDocumentLoaderObserver methods
NS_IMETHODIMP
mozXMLTerminal::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL,

Просмотреть файл

@ -74,6 +74,8 @@ class mozXMLTerminal : public mozIXMLTerminal,
NS_IMETHOD GetDocument(nsIDOMDocument** aDoc);
NS_IMETHOD GetWebShell(nsIWebShell** aWebShell);
NS_IMETHOD GetPresShell(nsIPresShell** aPresShell);
// nsIDocumentLoaderObserver interface
@ -122,6 +124,9 @@ class mozXMLTerminal : public mozIXMLTerminal,
/** initial input string to be sent to LineTerm */
nsString mFirstInput;
/** first input lock */
PRLock* mFirstInputLock;
/** non-owning reference to containing XMLTermShell object */
mozIXMLTermShell* mXMLTermShell;

Просмотреть файл

@ -1,9 +1,13 @@
Known bugs
----------
10 Nov 1999
25 Dec 1999
1. Command line completion output duplicates command line
1. Early use of "xls -i" does not scroll properly
2. Early use of "xls -i" does not scroll properly
2. DOM/IFRAME bug: window.document object not defined for dynamically
created IFRAME elements using DOM
3. Typing text in text input element causes input to be duplicated
in the command line

Просмотреть файл

@ -5,7 +5,7 @@ XMLterm installation instructions for Linux binaries
*NOTE* Check the XMLterm web site <http://xmlterm.org> for updates.
19 Nov 1999
26 Dec 1999
1. First obtain the Mozilla Linux binary tar file
ftp://ftp.mozilla.org/pub/mozilla/releases/m11/mozilla-i686-pc-linux-gnu-M11.tar.gz"

Просмотреть файл

@ -25,10 +25,8 @@
#include <gtk/gtk.h>
#if 0 // USE_SUPERWIN
#include "gtkmozarea.h"
#include "gdksuperwin.h"
#endif // USE_SUPERWIN
#include "nscore.h"
#include "nsCOMPtr.h"
@ -109,15 +107,8 @@ static gint event_processor_quit(gpointer data,
int main( int argc, char *argv[] )
{
GtkWidget *mainWin = NULL;
GtkWidget *vertBox = NULL;
GtkWidget *horBox = NULL;
GtkWidget *testButton = NULL;
#if 0 // USE_SUPERWIN
GdkSuperWin *termWidget = NULL;
GtkWidget *mozArea;
#else // USE_SUPERWIN
GtkWidget *termWidget = NULL;
#endif // !USE_SUPERWIN
GtkWidget *mozArea = NULL;
GdkSuperWin *superWin = NULL;
nsIEventQueue *mEventQueue = nsnull;
@ -144,7 +135,7 @@ int main( int argc, char *argv[] )
}
// Get the event queue for the thread.
result = eventQService->GetThreadEventQueue(PR_GetCurrentThread(),
result = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD,
&mEventQueue);
if (!mEventQueue) {
@ -156,14 +147,14 @@ int main( int argc, char *argv[] )
}
// Get the event queue for the thread
result = eventQService->GetThreadEventQueue(PR_GetCurrentThread(), &mEventQueue);
result = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue);
if (NS_FAILED(result)) {
NS_ASSERTION("Could not obtain the thread event queue", PR_FALSE);
return result;
}
}
// Creat pref object
// Create pref object
nsCOMPtr<nsIPref> mPref = nsnull;
result = nsComponentManager::CreateInstance(kPrefCID, NULL,
kIPrefIID, getter_AddRefs(mPref));
@ -185,46 +176,23 @@ int main( int argc, char *argv[] )
mainWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size( GTK_WINDOW(mainWin), 600, 400);
gtk_window_set_title(GTK_WINDOW(mainWin), "XMLterm");
// VBox top level
vertBox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(mainWin), vertBox);
gtk_widget_show(vertBox);
// HBox for toolbar
horBox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vertBox), horBox, FALSE, FALSE, 0);
testButton = gtk_button_new_with_label("Test");
gtk_box_pack_start (GTK_BOX (horBox), testButton, FALSE, FALSE, 0);
gtk_widget_show(testButton);
gtk_widget_show(horBox);
#if 0 // USE_SUPERWIN
gtk_window_set_policy(GTK_WINDOW(mainWin), PR_TRUE, PR_TRUE, PR_FALSE);
mozArea = gtk_mozarea_new();
gtk_container_add(GTK_CONTAINER(mainWin), mozArea);
gtk_widget_realize(GTK_WIDGET(mozArea));
termWidget = GTK_MOZAREA(mozArea)->superwin;
gtk_widget_realize(mozArea);
gtk_widget_show(mozArea);
superWin = GTK_MOZAREA(mozArea)->superwin;
#else // USE_SUPERWIN
// XMLterm layout widget
termWidget = gtk_layout_new(NULL, NULL);
GTK_WIDGET_SET_FLAGS(termWidget, GTK_CAN_FOCUS);
gtk_widget_set_app_paintable(termWidget, TRUE);
gtk_box_pack_start(GTK_BOX(vertBox), termWidget, TRUE, TRUE, 0);
gtk_widget_show_all(termWidget);
gdk_window_show(superWin->bin_window);
gdk_window_show(superWin->shell_window);
gtk_widget_show(mainWin);
#endif // !USE_SUPERWIN
// Configure event handler
gtk_signal_connect_after( GTK_OBJECT(mainWin), "configure_event",
GTK_SIGNAL_FUNC(event_processor_configure),
termWidget);
mainWin);
// Cleanup and exit when window is deleted
gtk_signal_connect( GTK_OBJECT(mainWin), "delete_event",
@ -245,10 +213,10 @@ int main( int argc, char *argv[] )
}
// Determine window dimensions
GtkAllocation *alloc = &GTK_WIDGET(termWidget)->allocation;
GtkAllocation *alloc = &GTK_WIDGET(mainWin)->allocation;
// Initialize container to hold a web shell
result = gSimpleContainer->Init((nsNativeWidget *) termWidget,
// Initialize container it to hold a web shell
result = gSimpleContainer->Init((nsNativeWidget *) superWin,
alloc->width, alloc->height, mPref);
if (NS_FAILED(result)) {

Просмотреть файл

@ -30,6 +30,7 @@
#include "nsISupports.h"
#include "nsIWebShell.h"
#include "nsIBaseWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIPresContext.h"
@ -168,7 +169,11 @@ NS_IMETHODIMP mozSimpleContainer::Init(nsNativeWidget aNativeWidget,
if (aPref) {
mWebShell->SetPrefs(aPref);
}
mWebShell->Show();
nsCOMPtr<nsIBaseWindow> window = do_QueryInterface(mWebShell);
if (window) {
window->SetVisibility(PR_TRUE);
}
return NS_OK;
}
@ -290,7 +295,10 @@ NS_IMETHODIMP mozSimpleContainer::Resize(PRInt32 aWidth, PRInt32 aHeight)
{
if (!mWebShell) return NS_ERROR_FAILURE;
mWebShell->SetBounds(0, 0, aWidth, aHeight);
nsCOMPtr<nsIBaseWindow> window = do_QueryInterface(mWebShell);
if (window) {
window->SetPositionAndSize(0, 0, aWidth, aHeight, PR_FALSE);
}
return NS_OK;
}

Просмотреть файл

@ -1,11 +1,18 @@
/* HelloWorld.c: Simple demo program for "pagelets" */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char ch;
printf("\033{S\007"); /* XMLTerm escape sequence signalling start of HTML */
char* cookie;
cookie = getenv("LTERM_COOKIE"); /* Get security cookie */
if (cookie == NULL)
cookie = "";
printf("\033{S%s\007", cookie); /* Escape sequence for start of HTML frag */
printf("<FORM> \
<IMG align=center src='chrome://navigator/skin/animthrob_single.gif'> \
@ -13,20 +20,20 @@ int main(void)
<INPUT ID='button-b#' TYPE=button VALUE='Bold' \
onClick=\"return clickXMLTerm('sendln','#','b')\"> \
<INPUT ID='button-e#' TYPE=button VALUE='Emphasis' \
onClick=\"return clickXMLTerm('sendln',#,'e')\"> \
onClick=\"return clickXMLTerm('sendln','#','e')\"> \
<INPUT ID='button-q#' TYPE=button VALUE='Quit' \
onClick=\"return clickXMLTerm('sendln',#,'q')\"> \
onClick=\"return clickXMLTerm('sendln','#','q')\"> \
<BR></FORM>");
printf("%c", '\0'); /* XMLTerm escape sequence signalling end of HTML */
printf("%c", '\0'); /* Escape sequence signalling end of HTML */
while((ch = getchar())){ /* Poll for data generated by button click events */
switch (ch) {
case 'b':
printf("\033{S\007<B>Hello World!</B><BR> %c", '\0');
printf("\033{S%s\007<B>Hello World!</B><BR> %c", cookie, '\0');
break;
case 'e':
printf("\033{S\007<EM>Hello World!</EM><BR> %c", '\0');
printf("\033{S%s\007<EM>Hello World!</EM><BR> %c", cookie, '\0');
break;
case 'q':
return 0;
@ -36,5 +43,7 @@ int main(void)
}
}
printf("\033{1E\007"); /* Enable input echo */
return 0;
}

Просмотреть файл

@ -0,0 +1,31 @@
#!/bin/csh
# xcat.csh: a C-shell XMLterm wrapper for the UNIX "cat" command
# Usage: xcat.csh <filename1> <filename2> ...
##set echocmd="/usr/bin/echo"
set echocmd="/bin/echo -e"
foreach file ($*)
set ext=${file:e}
set firstchar = `echo $file|cut -c1`
if ("$firstchar" == "/") then
set url="file:$file"
else
set url="file:$PWD/$file"
endif
switch ($ext)
case "gif":
case "png":
# Is this a security risk??? Perhaps display using IFRAME?
$echocmd "\033{S${LTERM_COOKIE}\007\c"
cat <<EOF
<IMG SRC='$url'>
EOF
$echocmd '\000\c'
breaksw
default:
cat $file
endsw
end

Просмотреть файл

@ -26,7 +26,8 @@ $imgdir = "file:/usr/share/pixmaps/mc";
$ncols = 5;
$ncols = $opt_cols if ($opt_cols);
print "\e{S\a"; # HTML stream escape sequence
$cookie = $ENV{LTERM_COOKIE}; # XMLTerm cookie
print "\e{S$cookie\a"; # HTML stream escape sequence
print "<TABLE FRAME=none BORDER=0>";
print "<COLGROUP COLSPAN=$ncols WIDTH=1*>";

Просмотреть файл

@ -25,7 +25,7 @@ foreach arg ($*)
endsw
end
$echocmd '\033{S\007\c'
$echocmd "\033{S${LTERM_COOKIE}\007\c"
$echocmd '<TABLE FRAME=none BORDER=0>'
$echocmd "<COLGROUP COLSPAN=$ncols WIDTH=1*>"

Просмотреть файл

@ -55,6 +55,7 @@ include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_CONTENT = \
$(srcdir)/xmlterm.html \
$(srcdir)/xmltblank.html \
$(NULL)
install::

Просмотреть файл

@ -0,0 +1,10 @@
<!-- xmlblank.html: XMLterm blank page -->
<HTML>
<HEAD>
<TITLE>XMLterm Blank Page</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>

Просмотреть файл

@ -227,10 +227,10 @@
</TABLE>
<!--
<IFRAME NAME="iframe1" SRC="file:///home/svn/xmlterm/doc/web/tem2.html"
FRAMEBORDER=0 WIDTH="20" HEIGHT=60>
<IFRAME NAME="iframet" SRC="chrome://xmlterm/content/xmltblank.html"
FRAMEBORDER=0>
</IFRAME>
-->
-->
<DIV CLASS="session" ID="session">
</DIV>