NS_IMETHODIMP
nsHTMLFormatConverter::ConvertFromHTMLToAOLMail(const nsAutoString & aFromStr,
                                                nsAutoString & aToStr)
{
  aToStr.AssignLiteral("<HTML>");
  aToStr.Append(aFromStr);
  aToStr.AppendLiteral("</HTML>");

  return NS_OK;
}
예제 #2
0
//
// ConvertFromHTMLToUnicode
//
// Takes HTML and converts it to plain text but in unicode.
//
NS_IMETHODIMP
nsHTMLFormatConverter::ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr)
{
    // create the parser to do the conversion.
    aToStr.SetLength(0);
    nsresult rv;
    nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
    if ( !parser )
        return rv;

    // convert it!
    nsCOMPtr<nsIContentSink> sink;

    sink = do_CreateInstance(NS_PLAINTEXTSINK_CONTRACTID);
    NS_ENSURE_TRUE(sink, NS_ERROR_FAILURE);

    nsCOMPtr<nsIHTMLToTextSink> textSink(do_QueryInterface(sink));
    NS_ENSURE_TRUE(textSink, NS_ERROR_FAILURE);

    textSink->Initialize(&aToStr, nsIDocumentEncoder::OutputSelectionOnly
                         | nsIDocumentEncoder::OutputAbsoluteLinks, 0);

    parser->SetContentSink(sink);

    parser->Parse(aFromStr, 0, NS_LITERAL_CSTRING("text/html"), PR_TRUE, eDTDMode_fragment);

    return NS_OK;
} // ConvertFromHTMLToUnicode
//
// ConvertFromHTMLToUnicode
//
// Takes HTML and converts it to plain text but in unicode.
//
NS_IMETHODIMP
nsHTMLFormatConverter::ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr)
{
  // create the parser to do the conversion.
  aToStr.SetLength(0);
  nsresult rv;
  nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
  if ( !parser )
    return rv;

  // convert it!
  nsCOMPtr<nsIContentSink> sink;

  sink = do_CreateInstance(NS_PLAINTEXTSINK_CONTRACTID);
  NS_ENSURE_TRUE(sink, NS_ERROR_FAILURE);

  nsCOMPtr<nsIHTMLToTextSink> textSink(do_QueryInterface(sink));
  NS_ENSURE_TRUE(textSink, NS_ERROR_FAILURE);

  // We set OutputNoScriptContent and OutputNoFramesContent unconditionally
  // here because |aFromStr| is already filtered based on user preferences.
  PRUint32 flags =
    nsIDocumentEncoder::OutputSelectionOnly |
    nsIDocumentEncoder::OutputAbsoluteLinks |
    nsIDocumentEncoder::OutputNoScriptContent |
    nsIDocumentEncoder::OutputNoFramesContent;
  textSink->Initialize(&aToStr, flags, 0);

  parser->SetContentSink(sink);

  parser->Parse(aFromStr, 0, NS_LITERAL_CSTRING("text/html"), PR_TRUE, eDTDMode_fragment);
  
  return NS_OK;
} // ConvertFromHTMLToUnicode
nsresult
mozSqlResultMysql::AppendKeys(Row* aRow, nsAutoString& aKeys)
{
  PRInt32 i;
  for (i = 0; i < mColumnInfo.Count(); i++) {
    if (((ColumnInfo*)mColumnInfo[i])->mIsPrimaryKey){
      if (i){
        aKeys.Append(NS_LITERAL_STRING(" AND "));
      }
      aKeys.Append(((ColumnInfo*)mColumnInfo[i])->mName);
      aKeys.Append(PRUnichar('='));

      Cell* cell = aRow->mCells[i];
      AppendValue(cell, aKeys);
    }
  }

  return NS_OK;
}
void
nsHtml5Highlighter::Start(const nsAutoString& aTitle)
{
  // Doctype
  mOpQueue.AppendElement()->Init(nsGkAtoms::html, EmptyString(), EmptyString());

  mOpQueue.AppendElement()->Init(STANDARDS_MODE);

  nsIContent** root = CreateElement(nsHtml5Atoms::html, nullptr);
  mOpQueue.AppendElement()->Init(eTreeOpAppendToDocument, root);
  mStack.AppendElement(root);

  Push(nsGkAtoms::head, nullptr);

  Push(nsGkAtoms::title, nullptr);
  // XUL will add the "Source of: " prefix.
  uint32_t length = aTitle.Length();
  if (length > INT32_MAX) {
    length = INT32_MAX;
  }
  AppendCharacters(aTitle.get(), 0, (int32_t)length);
  Pop(); // title

  Push(nsGkAtoms::link, nsHtml5ViewSourceUtils::NewLinkAttributes());

  mOpQueue.AppendElement()->Init(eTreeOpUpdateStyleSheet, CurrentNode());

  Pop(); // link

  Pop(); // head

  Push(nsGkAtoms::body, nsHtml5ViewSourceUtils::NewBodyAttributes());

  nsHtml5HtmlAttributes* preAttrs = new nsHtml5HtmlAttributes(0);
  nsString* preId = new nsString(NS_LITERAL_STRING("line1"));
  preAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, preId);
  Push(nsGkAtoms::pre, preAttrs);

  StartCharacters();

  mOpQueue.AppendElement()->Init(eTreeOpStartLayout);
}
예제 #6
0
  void Serialize(const nsCString& aInput)
  {
    const unsigned char* p = (const unsigned char*) aInput.get();

    while (p && *p) {
      // ' ' to '+'
      if (*p == 0x20) {
        mValue.Append(0x2B);
      // Percent Encode algorithm
      } else if (*p == 0x2A || *p == 0x2D || *p == 0x2E ||
                 (*p >= 0x30 && *p <= 0x39) ||
                 (*p >= 0x41 && *p <= 0x5A) || *p == 0x5F ||
                 (*p >= 0x61 && *p <= 0x7A)) {
        mValue.Append(*p);
      } else {
        mValue.AppendPrintf("%%%X", *p);
      }

      ++p;
    }
  }
nsresult LaunchHelper(nsAutoString& aPath, nsAutoString& aParams) {
  SHELLEXECUTEINFOW executeInfo = {0};

  executeInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
  executeInfo.hwnd = NULL;
  executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  executeInfo.lpDirectory = NULL;
  executeInfo.lpFile = aPath.get();
  executeInfo.lpParameters = aParams.get();
  executeInfo.nShow = SW_SHOWNORMAL;

  if (ShellExecuteExW(&executeInfo))
    // Block until the program exits
    WaitForSingleObject(executeInfo.hProcess, INFINITE);
  else
    return NS_ERROR_ABORT;

  // We're going to ignore errors here since there's nothing we can do about
  // them, and helper.exe seems to return non-zero ret on success.
  return NS_OK;
}
bool
nsTreeSanitizer::SanitizeStyleRule(mozilla::css::StyleRule *aRule,
                                   nsAutoString &aRuleText)
{
  bool didSanitize = false;
  aRuleText.Truncate();
  mozilla::css::Declaration* style = aRule->GetDeclaration();
  if (style) {
    didSanitize = style->HasProperty(eCSSProperty_binding);
    style->RemoveProperty(eCSSProperty_binding);
    style->ToString(aRuleText);
  }
  return didSanitize;
}
예제 #9
0
void
nsBox::ListBox(nsAutoString& aResult)
{
    nsAutoString name;
    GetBoxName(name);

    char addr[100];
    sprintf(addr, "[@%p] ", static_cast<void*>(this));

    aResult.AppendASCII(addr);
    aResult.Append(name);
    aResult.AppendLiteral(" ");

    nsIContent* content = GetContent();

    // add on all the set attributes
    if (content) {
      nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
      nsCOMPtr<nsIDOMNamedNodeMap> namedMap;

      node->GetAttributes(getter_AddRefs(namedMap));
      PRUint32 length;
      namedMap->GetLength(&length);

      nsCOMPtr<nsIDOMNode> attribute;
      for (PRUint32 i = 0; i < length; ++i)
      {
        namedMap->Item(i, getter_AddRefs(attribute));
        nsCOMPtr<nsIDOMAttr> attr(do_QueryInterface(attribute));
        attr->GetName(name);
        nsAutoString value;
        attr->GetValue(value);
        AppendAttribute(name, value, aResult);
      }
    }
}
예제 #10
0
/* returns true if aText represented a valid direction
 */
PRBool
nsResizerFrame::EvalDirection(nsAutoString& aText,eDirection& aDir)
{
  PRBool aResult = PR_TRUE;

  if( aText.Equals( NS_LITERAL_STRING("topleft") ) )
  {
    aDir = topleft;
  }
  else if( aText.Equals( NS_LITERAL_STRING("top") ) )
  {
    aDir = top;
  }
  else if( aText.Equals( NS_LITERAL_STRING("topright") ) )
  {
    aDir = topright;
  }
  else if( aText.Equals( NS_LITERAL_STRING("left") ) )
  {
    aDir = left;
  }
  else if( aText.Equals( NS_LITERAL_STRING("right") ) )
  {
    aDir = right;
  }
  else if( aText.Equals( NS_LITERAL_STRING("bottomleft") ) )
  {
    aDir = bottomleft;
  }
  else if( aText.Equals( NS_LITERAL_STRING("bottom") ) )
  {
    aDir = bottom;
  }
  else if( aText.Equals( NS_LITERAL_STRING("bottomright") ) )
  {
    aDir = bottomright;
  }
  else
  {
    aResult = PR_FALSE;
  }

  return aResult;
}
예제 #11
0
void
nsBox::GetBoxName(nsAutoString& aName)
{
  aName.AssignLiteral("Box");
}
예제 #12
0
nsresult
nsNSSCertificate::FormatUIStrings(const nsAutoString &nickname, nsAutoString &nickWithSerial, nsAutoString &details)
{
  if (!NS_IsMainThread()) {
    NS_ERROR("nsNSSCertificate::FormatUIStrings called off the main thread");
    return NS_ERROR_NOT_SAME_THREAD;
  }
  
  nsresult rv = NS_OK;

  nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));

  if (NS_FAILED(rv) || !nssComponent) {
    return NS_ERROR_FAILURE;
  }
  
  nsAutoString info;
  nsAutoString temp1;

  nickWithSerial.Append(nickname);

  if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoIssuedFor", info))) {
    details.Append(info);
    details.Append(PRUnichar(' '));
    if (NS_SUCCEEDED(GetSubjectName(temp1)) && !temp1.IsEmpty()) {
      details.Append(temp1);
    }
    details.Append(PRUnichar('\n'));
  }

  if (NS_SUCCEEDED(GetSerialNumber(temp1)) && !temp1.IsEmpty()) {
    details.AppendLiteral("  ");
    if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertDumpSerialNo", info))) {
      details.Append(info);
      details.AppendLiteral(": ");
    }
    details.Append(temp1);

    nickWithSerial.AppendLiteral(" [");
    nickWithSerial.Append(temp1);
    nickWithSerial.Append(PRUnichar(']'));

    details.Append(PRUnichar('\n'));
  }

  nsCOMPtr<nsIX509CertValidity> validity;
  rv = GetValidity(getter_AddRefs(validity));
  if (NS_SUCCEEDED(rv) && validity) {
    details.AppendLiteral("  ");
    if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoValid", info))) {
      details.Append(info);
    }

    if (NS_SUCCEEDED(validity->GetNotBeforeLocalTime(temp1)) && !temp1.IsEmpty()) {
      details.Append(PRUnichar(' '));
      if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoFrom", info))) {
        details.Append(info);
        details.Append(PRUnichar(' '));
      }
      details.Append(temp1);
    }

    if (NS_SUCCEEDED(validity->GetNotAfterLocalTime(temp1)) && !temp1.IsEmpty()) {
      details.Append(PRUnichar(' '));
      if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoTo", info))) {
        details.Append(info);
        details.Append(PRUnichar(' '));
      }
      details.Append(temp1);
    }

    details.Append(PRUnichar('\n'));
  }

  if (NS_SUCCEEDED(GetKeyUsagesString(mCert, nssComponent, temp1)) && !temp1.IsEmpty()) {
    details.AppendLiteral("  ");
    if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertDumpKeyUsage", info))) {
      details.Append(info);
      details.AppendLiteral(": ");
    }
    details.Append(temp1);
    details.Append(PRUnichar('\n'));
  }

  nsAutoString firstEmail;
  const char *aWalkAddr;
  for (aWalkAddr = CERT_GetFirstEmailAddress(mCert)
        ;
        aWalkAddr
        ;
        aWalkAddr = CERT_GetNextEmailAddress(mCert, aWalkAddr))
  {
    NS_ConvertUTF8toUTF16 email(aWalkAddr);
    if (email.IsEmpty())
      continue;

    if (firstEmail.IsEmpty()) {
      /*
        * If the first email address from the subject DN is also present
        * in the subjectAltName extension, GetEmailAddresses() will return
        * it twice (as received from NSS). Remember the first address so that
        * we can filter out duplicates later on.
        */
      firstEmail = email;

      details.AppendLiteral("  ");
      if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoEmail", info))) {
        details.Append(info);
        details.AppendLiteral(": ");
      }
      details.Append(email);
    }
    else {
      // Append current address if it's different from the first one.
      if (!firstEmail.Equals(email)) {
        details.AppendLiteral(", ");
        details.Append(email);
      }
    }
  }

  if (!firstEmail.IsEmpty()) {
    // We got at least one email address, so we want a newline
    details.Append(PRUnichar('\n'));
  }

  if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoIssuedBy", info))) {
    details.Append(info);
    details.Append(PRUnichar(' '));

    if (NS_SUCCEEDED(GetIssuerName(temp1)) && !temp1.IsEmpty()) {
      details.Append(temp1);
    }

    details.Append(PRUnichar('\n'));
  }

  if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoStoredIn", info))) {
    details.Append(info);
    details.Append(PRUnichar(' '));

    if (NS_SUCCEEDED(GetTokenName(temp1)) && !temp1.IsEmpty()) {
      details.Append(temp1);
    }
  }

  /*
    the above produces the following output:

    Issued to: $subjectName
    Serial number: $serialNumber
    Valid from: $starting_date to $expiration_date
    Certificate Key usage: $usages
    Email: $address(es)
    Issued by: $issuerName
    Stored in: $token
  */
  
  return rv;
}
PRBool nsPropertiesParser::ParseValueCharacter(
    PRUnichar c, const PRUnichar* cur, const PRUnichar* &tokenStart,
    nsAString& oldValue)
{
  switch (mSpecialState) {

    // the normal state - look for special characters
  case eParserSpecial_None:
    switch (c) {
    case '\\':
      if (mHaveMultiLine)
        // there is nothing to append to mValue yet
        mHaveMultiLine = PR_FALSE;
      else
        mValue += Substring(tokenStart, cur);

      mSpecialState = eParserSpecial_Escaped;
      break;

    case '\n':
      // if we detected multiline and got only "\\\r" ignore next "\n" if any
      if (mHaveMultiLine && mMultiLineCanSkipN) {
        // but don't allow another '\n' to be skipped
        mMultiLineCanSkipN = PR_FALSE;
        // Now there is nothing to append to the mValue since we are skipping
        // whitespaces at the beginning of the new line of the multiline
        // property. Set tokenStart properly to ensure that nothing is appended
        // if we find regular line-end or the end of the buffer.
        tokenStart = cur+1;
        break;
      }
      // no break

    case '\r':
      // we're done! We have a key and value
      mValue += Substring(tokenStart, cur);
      FinishValueState(oldValue);
      mHaveMultiLine = PR_FALSE;
      break;

    default:
      // there is nothing to do with normal characters,
      // but handle multilines correctly
      if (mHaveMultiLine) {
        if (c == ' ' || c == '\t') {
          // don't allow another '\n' to be skipped
          mMultiLineCanSkipN = PR_FALSE;
          // Now there is nothing to append to the mValue since we are skipping
          // whitespaces at the beginning of the new line of the multiline
          // property. Set tokenStart properly to ensure that nothing is appended
          // if we find regular line-end or the end of the buffer.
          tokenStart = cur+1;
          break;
        }
        mHaveMultiLine = PR_FALSE;
        tokenStart = cur;
      }
      break; // from switch on (c)
    }
    break; // from switch on (mSpecialState)

    // saw a \ character, so parse the character after that
  case eParserSpecial_Escaped:
    // probably want to start parsing at the next token
    // other characters, like 'u' might override this
    tokenStart = cur+1;
    mSpecialState = eParserSpecial_None;

    switch (c) {

      // the easy characters - \t, \n, and so forth
    case 't':
      mValue += PRUnichar('\t');
      mMinLength = mValue.Length();
      break;
    case 'n':
      mValue += PRUnichar('\n');
      mMinLength = mValue.Length();
      break;
    case 'r':
      mValue += PRUnichar('\r');
      mMinLength = mValue.Length();
      break;
    case '\\':
      mValue += PRUnichar('\\');
      break;

      // switch to unicode mode!
    case 'u':
    case 'U':
      mSpecialState = eParserSpecial_Unicode;
      mUnicodeValuesRead = 0;
      mUnicodeValue = 0;
      break;

      // a \ immediately followed by a newline means we're going multiline
    case '\r':
    case '\n':
      mHaveMultiLine = PR_TRUE;
      mMultiLineCanSkipN = (c == '\r');
      mSpecialState = eParserSpecial_None;
      break;

    default:
      // don't recognize the character, so just append it
      mValue += c;
      break;
    }
    break;

    // we're in the middle of parsing a 4-character unicode value
    // like \u5f39
  case eParserSpecial_Unicode:

    if(('0' <= c) && (c <= '9'))
      mUnicodeValue =
        (mUnicodeValue << 4) | (c - '0');
    else if(('a' <= c) && (c <= 'f'))
      mUnicodeValue =
        (mUnicodeValue << 4) | (c - 'a' + 0x0a);
    else if(('A' <= c) && (c <= 'F'))
      mUnicodeValue =
        (mUnicodeValue << 4) | (c - 'A' + 0x0a);
    else {
      // non-hex character. Append what we have, and move on.
      mValue += mUnicodeValue;
      mMinLength = mValue.Length();
      mSpecialState = eParserSpecial_None;

      // leave tokenStart at this unknown character, so it gets appended
      tokenStart = cur;

      // ensure parsing this non-hex character again
      return PR_FALSE;
    }

    if (++mUnicodeValuesRead >= 4) {
      tokenStart = cur+1;
      mSpecialState = eParserSpecial_None;
      mValue += mUnicodeValue;
      mMinLength = mValue.Length();
    }

    break;
  }

  return PR_TRUE;
}
예제 #14
0
bool
SVGTests::PassesConditionalProcessingTests(const nsString *aAcceptLangs) const
{
    // Required Features
    if (mStringListAttributes[FEATURES].IsExplicitlySet()) {
        if (mStringListAttributes[FEATURES].IsEmpty()) {
            return false;
        }
        nsCOMPtr<nsIContent> content(
            do_QueryInterface(const_cast<SVGTests*>(this)));

        for (uint32_t i = 0; i < mStringListAttributes[FEATURES].Length(); i++) {
            if (!nsSVGFeatures::HasFeature(content, mStringListAttributes[FEATURES][i])) {
                return false;
            }
        }
    }

    // Required Extensions
    //
    // The requiredExtensions  attribute defines a list of required language
    // extensions. Language extensions are capabilities within a user agent that
    // go beyond the feature set defined in the SVG specification.
    // Each extension is identified by a URI reference.
    // For now, claim that mozilla's SVG implementation supports XHTML and MathML.
    if (mStringListAttributes[EXTENSIONS].IsExplicitlySet()) {
        if (mStringListAttributes[EXTENSIONS].IsEmpty()) {
            return false;
        }
        for (uint32_t i = 0; i < mStringListAttributes[EXTENSIONS].Length(); i++) {
            if (!nsSVGFeatures::HasExtension(mStringListAttributes[EXTENSIONS][i])) {
                return false;
            }
        }
    }

    if (aAcceptLangs == kIgnoreSystemLanguage) {
        return true;
    }

    // systemLanguage
    //
    // Evaluates to "true" if one of the languages indicated by user preferences
    // exactly equals one of the languages given in the value of this parameter,
    // or if one of the languages indicated by user preferences exactly equals a
    // prefix of one of the languages given in the value of this parameter such
    // that the first tag character following the prefix is "-".
    if (mStringListAttributes[LANGUAGE].IsExplicitlySet()) {
        if (mStringListAttributes[LANGUAGE].IsEmpty()) {
            return false;
        }

        // Get our language preferences
        const nsAutoString acceptLangs(aAcceptLangs ? *aAcceptLangs :
                                       Preferences::GetLocalizedString("intl.accept_languages"));

        if (acceptLangs.IsEmpty()) {
            NS_WARNING("no default language specified for systemLanguage conditional test");
            return false;
        }

        const nsDefaultStringComparator defaultComparator;

        for (uint32_t i = 0; i < mStringListAttributes[LANGUAGE].Length(); i++) {
            nsCharSeparatedTokenizer languageTokenizer(acceptLangs, ',');
            while (languageTokenizer.hasMoreTokens()) {
                if (nsStyleUtil::DashMatchCompare(mStringListAttributes[LANGUAGE][i],
                                                  languageTokenizer.nextToken(),
                                                  defaultComparator)) {
                    return true;
                }
            }
        }
        return false;
    }

    return true;
}