void
PopupBoxObject::GetPopupState(nsString& aState)
{
  // set this here in case there's no frame for the popup
  aState.AssignLiteral("closed");

  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
  if (menuPopupFrame) {
    switch (menuPopupFrame->PopupState()) {
      case ePopupShown:
        aState.AssignLiteral("open");
        break;
      case ePopupShowing:
      case ePopupOpening:
      case ePopupVisible:
        aState.AssignLiteral("showing");
        break;
      case ePopupHiding:
      case ePopupInvisible:
        aState.AssignLiteral("hiding");
        break;
      case ePopupClosed:
        break;
      default:
        NS_NOTREACHED("Bad popup state");
        break;
    }
  }
}
void
mozTXTToHTMLConv::CompleteAbbreviatedURL(const PRUnichar * aInString, PRInt32 aInLength, 
                                         const PRUint32 pos, nsString& aOutString)
{
  NS_ASSERTION(PRInt32(pos) < aInLength, "bad args to CompleteAbbreviatedURL, see bug #190851");
  if (PRInt32(pos) >= aInLength)
    return;

  if (aInString[pos] == '@')
  {
    // only pre-pend a mailto url if the string contains a .domain in it..
    //i.e. we want to linkify [email protected] but not "let's meet @8pm"
    nsDependentString inString(aInString, aInLength);
    if (inString.FindChar('.', pos) != kNotFound) // if we have a '.' after the @ sign....
    {
      aOutString.AssignLiteral("mailto:");
      aOutString += aInString;
    }
  }
  else if (aInString[pos] == '.')
  {
    if (ItMatchesDelimited(aInString, aInLength,
                           NS_LITERAL_STRING("www.").get(), 4, LT_IGNORE, LT_IGNORE))
    {
      aOutString.AssignLiteral("http://");
      aOutString += aInString;
    }
    else if (ItMatchesDelimited(aInString,aInLength, NS_LITERAL_STRING("ftp.").get(), 4, LT_IGNORE, LT_IGNORE))
    { 
      aOutString.AssignLiteral("ftp://");
      aOutString += aInString;
    }
  }
}
Beispiel #3
0
void
FontFace::GetDesc(nsCSSFontDesc aDescID,
                  nsCSSProperty aPropID,
                  nsString& aResult) const
{
  MOZ_ASSERT(aDescID == eCSSFontDesc_UnicodeRange ||
             aPropID != eCSSProperty_UNKNOWN,
             "only pass eCSSProperty_UNKNOWN for eCSSFontDesc_UnicodeRange");

  nsCSSValue value;
  GetDesc(aDescID, value);

  aResult.Truncate();

  // Fill in a default value for missing descriptors.
  if (value.GetUnit() == eCSSUnit_Null) {
    if (aDescID == eCSSFontDesc_UnicodeRange) {
      aResult.AssignLiteral("U+0-10FFFF");
    } else if (aDescID != eCSSFontDesc_Family &&
               aDescID != eCSSFontDesc_Src) {
      aResult.AssignLiteral("normal");
    }
    return;
  }

  if (aDescID == eCSSFontDesc_UnicodeRange) {
    // Since there's no unicode-range property, we can't use
    // nsCSSValue::AppendToString to serialize this descriptor.
    nsStyleUtil::AppendUnicodeRange(value, aResult);
  } else {
    value.AppendToString(aPropID, aResult, nsCSSValue::eNormalized);
  }
}
Beispiel #4
0
void
CryptoKey::GetType(nsString& aRetVal) const
{
  uint32_t type = mAttributes & TYPE_MASK;
  switch (type) {
    case PUBLIC:  aRetVal.AssignLiteral(WEBCRYPTO_KEY_TYPE_PUBLIC); break;
    case PRIVATE: aRetVal.AssignLiteral(WEBCRYPTO_KEY_TYPE_PRIVATE); break;
    case SECRET:  aRetVal.AssignLiteral(WEBCRYPTO_KEY_TYPE_SECRET); break;
  }
}
Beispiel #5
0
void
nsPerformanceSnapshot::GetGroupId(JSContext* cx,
                                  uint64_t uid,
                                  nsString& groupId)
{
  JSRuntime* rt = JS_GetRuntime(cx);
  uint64_t runtimeId = reinterpret_cast<uintptr_t>(rt);

  groupId.AssignLiteral("process: ");
  groupId.AppendInt(mProcessId);
  groupId.AssignLiteral(", thread: ");
  groupId.AppendInt(runtimeId);
  groupId.AppendLiteral(", group: ");
  groupId.AppendInt(uid);
}
void nsEudoraWin32::GetAccountName( const char *pSection, nsString& str)
{
  str.Truncate();

  nsCString s(pSection);

  if (s.Equals(NS_LITERAL_CSTRING("Settings"), nsCaseInsensitiveCStringComparator()))
  {
    str.AssignLiteral("Eudora ");
    str.Append(NS_ConvertASCIItoUTF16(pSection));
  }
  else
  {
    nsCString tStr;
    CopyASCIItoUTF16(pSection, str);
    if (s.Length() > 8)
    {
      s.Left( tStr, 8);
      if (tStr.Equals(NS_LITERAL_CSTRING("Persona-"), nsCaseInsensitiveCStringComparator()))
      {
        s.Right( tStr, s.Length() - 8);
        CopyASCIItoUTF16(tStr, str);
      }
    }
  }
}
void RecipientToString2(ews_recipient * r, int c, nsString & v) {
    std::string vv("");

    RecipientToStdString(r, c, vv);

    v.AssignLiteral(vv.c_str());
}
void
PopupBoxObject::GetAlignmentPosition(nsString& positionStr)
{
  positionStr.Truncate();

  // This needs to flush layout.
  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(true));
  if (!menuPopupFrame)
    return;

  int8_t position = menuPopupFrame->GetAlignmentPosition();
  switch (position) {
    case POPUPPOSITION_AFTERSTART:
      positionStr.AssignLiteral("after_start");
      break;
    case POPUPPOSITION_AFTEREND:
      positionStr.AssignLiteral("after_end");
      break;
    case POPUPPOSITION_BEFORESTART:
      positionStr.AssignLiteral("before_start");
      break;
    case POPUPPOSITION_BEFOREEND:
      positionStr.AssignLiteral("before_end");
      break;
    case POPUPPOSITION_STARTBEFORE:
      positionStr.AssignLiteral("start_before");
      break;
    case POPUPPOSITION_ENDBEFORE:
      positionStr.AssignLiteral("end_before");
      break;
    case POPUPPOSITION_STARTAFTER:
      positionStr.AssignLiteral("start_after");
      break;
    case POPUPPOSITION_ENDAFTER:
      positionStr.AssignLiteral("end_after");
      break;
    case POPUPPOSITION_OVERLAP:
      positionStr.AssignLiteral("overlap");
      break;
    case POPUPPOSITION_AFTERPOINTER:
      positionStr.AssignLiteral("after_pointer");
      break;
    default:
      // Leave as an empty string.
      break;
  }
}
static void getDriverDetails(nsCString& driverId, nsString& aDriverVersion, nsString& aDriverDate)
{
  HKEY key, subkey;
  LONG result, enumresult;
  DWORD index = 0;
  char subkeyname[64];
  TCHAR value[128];
  DWORD dwcbData = sizeof(subkeyname);
  
  // "{4D36E968-E325-11CE-BFC1-08002BE10318}" is the display class
  result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
                        "System\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}", 
                        0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &key);
  if (result != ERROR_SUCCESS) {
    return;
  }
  
  nsCString wantedDriverId(driverId);
  normalizeDriverId(wantedDriverId);
  
  while((enumresult = RegEnumKeyEx(key, index, subkeyname, &dwcbData, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS) {
    result = RegOpenKeyEx(key, subkeyname, 0, KEY_QUERY_VALUE, &subkey);
    if (result == ERROR_SUCCESS) {
      dwcbData = sizeof(value);
      result = RegQueryValueEx(subkey, "MatchingDeviceId", 0, NULL, (LPBYTE)value, &dwcbData);
      if (result == ERROR_SUCCESS) {
        nsCString matchingDeviceId(value);
        normalizeDriverId(matchingDeviceId);
        if (wantedDriverId.Equals(matchingDeviceId)) {
          result = RegQueryValueEx(subkey, "DriverVersion", 0, NULL, (LPBYTE)value, &dwcbData);
          if (result == ERROR_SUCCESS) 
            aDriverVersion.AssignLiteral(value);
          result = RegQueryValueEx(subkey, "DriverDate", 0, NULL, (LPBYTE)value, &dwcbData);
          if (result == ERROR_SUCCESS) 
            aDriverDate.AssignLiteral(value);
          break;
        }
      }
      RegCloseKey(subkey);
    }
    index++;
    dwcbData = sizeof(subkeyname);
  }
  
  RegCloseKey(key);
  return;
}
bool
mozTXTToHTMLConv::CheckURLAndCreateHTML(
     const nsString& txtURL, const nsString& desc, const modetype mode,
     nsString& outputHTML)
{
  // Create *uri from txtURL
  nsCOMPtr<nsIURI> uri;
  nsresult rv;
  // Lazily initialize mIOService
  if (!mIOService)
  {
    mIOService = do_GetIOService();

    if (!mIOService)
      return false;
  }

  // See if the url should be linkified.
  NS_ConvertUTF16toUTF8 utf8URL(txtURL);
  if (!ShouldLinkify(utf8URL))
    return false;

  // it would be faster if we could just check to see if there is a protocol
  // handler for the url and return instead of actually trying to create a url...
  rv = mIOService->NewURI(utf8URL, nsnull, nsnull, getter_AddRefs(uri));

  // Real work
  if (NS_SUCCEEDED(rv) && uri)
  {
    outputHTML.AssignLiteral("<a class=\"moz-txt-link-");
    switch(mode)
    {
    case RFC1738:
      outputHTML.AppendLiteral("rfc1738");
      break;
    case RFC2396E:
      outputHTML.AppendLiteral("rfc2396E");
      break;
    case freetext:
      outputHTML.AppendLiteral("freetext");
      break;
    case abbreviated:
      outputHTML.AppendLiteral("abbreviated");
      break;
    default: break;
    }
    nsAutoString escapedURL(txtURL);
    EscapeStr(escapedURL, true);

    outputHTML.AppendLiteral("\" href=\"");
    outputHTML += escapedURL;
    outputHTML.AppendLiteral("\">");
    outputHTML += desc;
    outputHTML.AppendLiteral("</a>");
    return true;
  }
  else
    return false;
}
Beispiel #11
0
void
FontFace::GetVariant(nsString& aResult)
{
  mFontFaceSet->FlushUserFontSet();

  // XXX Just expose the font-variant descriptor as "normal" until we
  // support it properly (bug 1055385).
  aResult.AssignLiteral("normal");
}
static void
AssignSourceNameHelper(nsIURI* aSourceURI, nsString& aSourceNameDest)
{
    if (!aSourceURI)
        return;

    if (NS_FAILED(NS_GetSanitizedURIStringFromURI(aSourceURI,
                                                  aSourceNameDest))) {
        aSourceNameDest.AssignLiteral("[nsIURI::GetSpec failed]");
    }
}
Beispiel #13
0
void
nsScreen::GetMozOrientation(nsString& aOrientation)
{
  switch (mOrientation) {
  case eScreenOrientation_PortraitPrimary:
    aOrientation.AssignLiteral("portrait-primary");
    break;
  case eScreenOrientation_PortraitSecondary:
    aOrientation.AssignLiteral("portrait-secondary");
    break;
  case eScreenOrientation_LandscapePrimary:
    aOrientation.AssignLiteral("landscape-primary");
    break;
  case eScreenOrientation_LandscapeSecondary:
    aOrientation.AssignLiteral("landscape-secondary");
    break;
  case eScreenOrientation_None:
  default:
    MOZ_NOT_REACHED("Unacceptable mOrientation value");
  }
}
/*virtual*/
bool
nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
                           gfxFontStyle& aFontStyle)
{
    aFontName.AssignLiteral("\"Droid Sans\"");
    aFontStyle.style = NS_FONT_STYLE_NORMAL;
    aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
    aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
    aFontStyle.size = 9.0 * 96.0f / 72.0f;
    aFontStyle.systemFont = true;
    return true;
}
Beispiel #15
0
void
nsScreen::GetMozOrientation(nsString& aOrientation,
                            CallerType aCallerType) const
{
  switch (mScreenOrientation->DeviceType(aCallerType)) {
  case OrientationType::Portrait_primary:
    aOrientation.AssignLiteral("portrait-primary");
    break;
  case OrientationType::Portrait_secondary:
    aOrientation.AssignLiteral("portrait-secondary");
    break;
  case OrientationType::Landscape_primary:
    aOrientation.AssignLiteral("landscape-primary");
    break;
  case OrientationType::Landscape_secondary:
    aOrientation.AssignLiteral("landscape-secondary");
    break;
  default:
    MOZ_CRASH("Unacceptable screen orientation type.");
  }
}
Beispiel #16
0
nsresult CViewSourceHTML::CreateViewSourceURL(const nsAString& linkUrl,
                                              nsString& viewSourceUrl) {
  nsCOMPtr<nsIURI> baseURI;
  nsCOMPtr<nsIURI> hrefURI;
  nsresult rv;

  // Default the view source URL to the empty string in case we fail.
  viewSourceUrl.Truncate();

  // Get the BaseURI.
  rv = GetBaseURI(getter_AddRefs(baseURI));
  NS_ENSURE_SUCCESS(rv, rv);

  // Use the link URL and the base URI to build a URI for the link.  Note that
  // the link URL may have untranslated entities in it.
  nsAutoString expandedLinkUrl;
  ExpandEntities(linkUrl, expandedLinkUrl);
  rv = NS_NewURI(getter_AddRefs(hrefURI), expandedLinkUrl, mCharset.get(), baseURI);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the absolute URL from the link URI.
  nsCString absoluteLinkUrl;
  hrefURI->GetSpec(absoluteLinkUrl);

  // URLs that execute script (e.g. "javascript:" URLs) should just be
  // ignored.  There's nothing reasonable we can do with them, and allowing
  // them to execute in the context of the view-source window presents a
  // security risk.  Just return the empty string in this case.
  PRBool openingExecutesScript = PR_FALSE;
  rv = NS_URIChainHasFlags(hrefURI, nsIProtocolHandler::URI_OPENING_EXECUTES_SCRIPT,
                           &openingExecutesScript);
  NS_ENSURE_SUCCESS(rv, NS_OK); // if there's an error, return the empty string
  if (openingExecutesScript) {
    return NS_OK;
  }

  // URLs that return data (e.g. "http:" URLs) should be prefixed with
  // "view-source:".  URLs that don't return data should just be returned
  // undecorated.
  PRBool doesNotReturnData = PR_FALSE;
  rv = NS_URIChainHasFlags(hrefURI, nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
                           &doesNotReturnData);
  NS_ENSURE_SUCCESS(rv, NS_OK);  // if there's an error, return the empty string
  if (!doesNotReturnData) {
    viewSourceUrl.AssignLiteral("view-source:");    
  }

  viewSourceUrl.AppendWithConversion(absoluteLinkUrl);

  return NS_OK;
}
Beispiel #17
0
void
nsScreen::GetMozOrientation(nsString& aOrientation) const
{
    if (ShouldResistFingerprinting()) {
        aOrientation.AssignLiteral("landscape-primary");
    } else {
        switch (mScreenOrientation->DeviceType()) {
        case OrientationType::Portrait_primary:
            aOrientation.AssignLiteral("portrait-primary");
            break;
        case OrientationType::Portrait_secondary:
            aOrientation.AssignLiteral("portrait-secondary");
            break;
        case OrientationType::Landscape_primary:
            aOrientation.AssignLiteral("landscape-primary");
            break;
        case OrientationType::Landscape_secondary:
            aOrientation.AssignLiteral("landscape-secondary");
            break;
        default:
            MOZ_CRASH("Unacceptable screen orientation type.");
        }
    }
}
Beispiel #18
0
void nsEudoraWin32::GetAccountName( const char *pSection, nsString& str)
{
  str.Truncate();

  nsCString s(pSection);

  if (s.LowerCaseEqualsLiteral("settings"))
  {
    str.AssignLiteral("Eudora ");
    str.Append(NS_ConvertASCIItoUTF16(pSection));
  }
  else
  {
    str.AssignASCII(pSection);
    if (StringBeginsWith(s, NS_LITERAL_CSTRING("persona-"), nsCaseInsensitiveCStringComparator()))
      CopyASCIItoUTF16(Substring(s, 8), str);
  }
}
Beispiel #19
0
void CMapiFolderList::ChangeName( nsString& name)
{
  if (name.IsEmpty()) {
    name.AssignLiteral("1");
    return;
  }
  PRUnichar lastC = name.Last();
  if ((lastC >= '0') && (lastC <= '9')) {
    lastC++;
    if (lastC > '9') {
      lastC = '1';
      name.SetCharAt( lastC, name.Length() - 1);
      name.AppendLiteral("0");
    }
    else {
      name.SetCharAt( lastC, name.Length() - 1);
    }
  }
  else {
    name.AppendLiteral(" 2");
  }
}
ENameValueFlag
XULMenubarAccessible::NativeName(nsString& aName) const
{
  aName.AssignLiteral("Application");
  return eNameOK;
}
Beispiel #21
0
/* virtual */ void
nsHTMLStyleSheet::GetType(nsString& aType) const
{
  aType.AssignLiteral("text/html");
}
/* virtual */ void
nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
{
  aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
}
// Virtual function of class SocketConsumer
void
BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
{
  uint8_t opCode;
  int packetLength;
  int receivedLength = aMessage->mSize;

  if (mPacketLeftLength > 0) {
    opCode = ObexRequestCode::Put;
    packetLength = mPacketLeftLength;
  } else {
    opCode = aMessage->mData[0];
    packetLength = (((int)aMessage->mData[1]) << 8) | aMessage->mData[2];
  }

  if (mLastCommand == ObexRequestCode::Connect) {
    if (opCode == ObexResponseCode::Success) {
      mConnected = true;

      // Keep remote information
      mRemoteObexVersion = aMessage->mData[3];
      mRemoteConnectionFlags = aMessage->mData[4];
      mRemoteMaxPacketLength =
        (((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);

      if (mBlob) {
        /*
         * Before sending content, we have to send a header including
         * information such as file name, file length and content type.
         */
        nsresult rv;
        nsCOMPtr<nsIDOMFile> file = do_QueryInterface(mBlob);
        if (file) {
          rv = file->GetName(sFileName);
        }

        if (!file || sFileName.IsEmpty()) {
          sFileName.AssignLiteral("Unknown");
        }

        rv = mBlob->GetSize(&sFileLength);
        if (NS_FAILED(rv)) {
          NS_WARNING("Can't get file size");
          return;
        }

        if (NS_FAILED(NS_NewThread(getter_AddRefs(mReadFileThread)))) {
          NS_WARNING("Can't create thread");
          SendDisconnectRequest();
          return;
        }

        sUpdateProgressCounter = 1;
        sSentFileLength = 0;
        mAbortFlag = false;
        sInstance->SendPutHeaderRequest(sFileName, sFileLength);
      }
    }
  } else if (mLastCommand == ObexRequestCode::Disconnect) {
    if (opCode != ObexResponseCode::Success) {
      // FIXME: Needs error handling here
      NS_WARNING("[OPP] Disconnect failed");
    } else {
      mConnected = false;
      mLastCommand = 0;
      mBlob = nullptr;
      mReadFileThread = nullptr;
    }
  } else if (mLastCommand == ObexRequestCode::Put) {
    if (opCode != ObexResponseCode::Continue) {
      // FIXME: Needs error handling here
      NS_WARNING("[OPP] Put failed");
    } else {
      if (mAbortFlag || mReadFileThread == nullptr) {
        SendAbortRequest();
      } else {
        // Sending system message "bluetooth-opp-update-progress" every 50kb,
        if (kUpdateProgressBase * sUpdateProgressCounter < sSentFileLength) {
          UpdateProgress(sSentFileLength, sFileLength);
          ++sUpdateProgressCounter;
        }

        nsRefPtr<ReadFileTask> task = new ReadFileTask(mBlob);

        if (NS_FAILED(mReadFileThread->Dispatch(task, NS_DISPATCH_NORMAL))) {
          NS_WARNING("Cannot dispatch ring task!");
        }
      }
    }
  } else if (mLastCommand == ObexRequestCode::PutFinal) {
    if (opCode != ObexResponseCode::Success) {
      // FIXME: Needs error handling here
      NS_WARNING("[OPP] PutFinal failed");
    } else {
      FileTransferComplete(true, false, sFileName, sSentFileLength);
      SendDisconnectRequest();
    }
  } else if (mLastCommand == ObexRequestCode::Abort) {
    if (opCode != ObexResponseCode::Success) {
      NS_WARNING("[OPP] Abort failed");
    }

    FileTransferComplete(false, false, sFileName, sSentFileLength);
    SendDisconnectRequest();
  } else {
    // Remote request or unknown mLastCommand
    if (opCode == ObexRequestCode::Connect) {
      ReplyToConnect();
    } else if (opCode == ObexRequestCode::Disconnect) {
      ReplyToDisconnect();
    } else if (opCode == ObexRequestCode::Put ||
               opCode == ObexRequestCode::PutFinal) {
      /*
       * A PUT request from remote devices may be divided into multiple parts.
       * In other words, one request may need to be received multiple times,
       * so here we keep a variable mPacketLeftLength to indicate if current
       * PUT request is done.
       */
      bool final = (opCode == ObexRequestCode::PutFinal);

      if (mPacketLeftLength == 0) {
        if (receivedLength < packetLength) {
          mPacketLeftLength = packetLength - receivedLength;
        } else {
          ReplyToPut(final);
        }
      } else {
        NS_ASSERTION(mPacketLeftLength < receivedLength,
                     "Invalid packet length");

        if (mPacketLeftLength <= receivedLength) {
          ReplyToPut(final);
          mPacketLeftLength = 0;
        } else {