nsresult BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType, const BluetoothNamedValue& aValue, BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); if (!IsReady()) { NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!"); DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr); return NS_OK; } const nsString propName = aValue.name(); bt_property_t prop; bt_scan_mode_t scanMode; nsCString str; // For Bluedroid, it's necessary to check property name for SetProperty if (propName.EqualsLiteral("Name")) { prop.type = BT_PROPERTY_BDNAME; } else if (propName.EqualsLiteral("Discoverable")) { prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE; } else if (propName.EqualsLiteral("DiscoverableTimeout")) { prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT; } else { BT_LOGR("Warning: Property type is not supported yet, type: %d", prop.type); } if (aValue.value().type() == BluetoothValue::Tuint32_t) { // Set discoverable timeout prop.val = (void*)aValue.value().get_uint32_t(); } else if (aValue.value().type() == BluetoothValue::TnsString) { // Set name str = NS_ConvertUTF16toUTF8(aValue.value().get_nsString()); const char* name = str.get(); prop.val = (void*)name; prop.len = strlen(name); } else if (aValue.value().type() == BluetoothValue::Tbool) { scanMode = aValue.value().get_bool() ? BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE : BT_SCAN_MODE_CONNECTABLE; prop.val = (void*)&scanMode; prop.len = sizeof(scanMode); } else { BT_LOGR("SetProperty but the property cannot be recognized correctly."); return NS_OK; } sSetPropertyRunnableArray.AppendElement(aRunnable); int ret = sBtInterface->set_adapter_property(&prop); if (ret != BT_STATUS_SUCCESS) { ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING("SetProperty")); } return NS_OK; }
static void SetBooleanProperty(OperatorData* aOperatorData, nsString aName) { if (aName.IsEmpty()) return; if (aName.EqualsLiteral("stretchy") && (1 == aOperatorData->mStr.Length())) aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY; else if (aName.EqualsLiteral("fence")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_FENCE; else if (aName.EqualsLiteral("accent")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_ACCENT; else if (aName.EqualsLiteral("largeop")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_LARGEOP; else if (aName.EqualsLiteral("separator")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_SEPARATOR; else if (aName.EqualsLiteral("movablelimits")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_MOVABLELIMITS; else if (aName.EqualsLiteral("symmetric")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_SYMMETRIC; else if (aName.EqualsLiteral("integral")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_INTEGRAL; else if (aName.EqualsLiteral("mirrorable")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_MIRRORABLE; }
nscoord nsMathMLmfracFrame::CalcLineThickness(nsPresContext* aPresContext, nsStyleContext* aStyleContext, nsString& aThicknessAttribute, nscoord onePixel, nscoord aDefaultRuleThickness, float aFontSizeInflation) { nscoord defaultThickness = aDefaultRuleThickness; nscoord lineThickness = aDefaultRuleThickness; nscoord minimumThickness = onePixel; // linethickness // // "Specifies the thickness of the horizontal 'fraction bar', or 'rule'. The // default value is 'medium', 'thin' is thinner, but visible, 'thick' is // thicker; the exact thickness of these is left up to the rendering agent." // // values: length | "thin" | "medium" | "thick" // default: medium // if (!aThicknessAttribute.IsEmpty()) { if (aThicknessAttribute.EqualsLiteral("thin")) { lineThickness = NSToCoordFloor(defaultThickness * THIN_FRACTION_LINE); minimumThickness = onePixel * THIN_FRACTION_LINE_MINIMUM_PIXELS; // should visually decrease by at least one pixel, if default is not a pixel if (defaultThickness > onePixel && lineThickness > defaultThickness - onePixel) lineThickness = defaultThickness - onePixel; } else if (aThicknessAttribute.EqualsLiteral("medium")) { // medium is default } else if (aThicknessAttribute.EqualsLiteral("thick")) { lineThickness = NSToCoordCeil(defaultThickness * THICK_FRACTION_LINE); minimumThickness = onePixel * THICK_FRACTION_LINE_MINIMUM_PIXELS; // should visually increase by at least one pixel if (lineThickness < defaultThickness + onePixel) lineThickness = defaultThickness + onePixel; } else { // length value lineThickness = defaultThickness; ParseNumericValue(aThicknessAttribute, &lineThickness, nsMathMLElement::PARSE_ALLOW_UNITLESS, aPresContext, aStyleContext, aFontSizeInflation); } } // use minimum if the lineThickness is a non-zero value less than minimun if (lineThickness && lineThickness < minimumThickness) lineThickness = minimumThickness; return lineThickness; }
nscoord nsMathMLmfracFrame::CalcLineThickness(nsPresContext* aPresContext, nsStyleContext* aStyleContext, nsString& aThicknessAttribute, nscoord onePixel, nscoord aDefaultRuleThickness) { nscoord defaultThickness = aDefaultRuleThickness; nscoord lineThickness = aDefaultRuleThickness; nscoord minimumThickness = onePixel; if (!aThicknessAttribute.IsEmpty()) { if (aThicknessAttribute.EqualsLiteral("thin")) { lineThickness = NSToCoordFloor(defaultThickness * THIN_FRACTION_LINE); minimumThickness = onePixel * THIN_FRACTION_LINE_MINIMUM_PIXELS; // should visually decrease by at least one pixel, if default is not a pixel if (defaultThickness > onePixel && lineThickness > defaultThickness - onePixel) lineThickness = defaultThickness - onePixel; } else if (aThicknessAttribute.EqualsLiteral("medium")) { lineThickness = NSToCoordRound(defaultThickness * MEDIUM_FRACTION_LINE); minimumThickness = onePixel * MEDIUM_FRACTION_LINE_MINIMUM_PIXELS; // should visually increase by at least one pixel if (lineThickness < defaultThickness + onePixel) lineThickness = defaultThickness + onePixel; } else if (aThicknessAttribute.EqualsLiteral("thick")) { lineThickness = NSToCoordCeil(defaultThickness * THICK_FRACTION_LINE); minimumThickness = onePixel * THICK_FRACTION_LINE_MINIMUM_PIXELS; // should visually increase by at least two pixels if (lineThickness < defaultThickness + 2*onePixel) lineThickness = defaultThickness + 2*onePixel; } else { // see if it is a plain number, or a percentage, or a h/v-unit like 1ex, 2px, 1em nsCSSValue cssValue; if (ParseNumericValue(aThicknessAttribute, cssValue)) { nsCSSUnit unit = cssValue.GetUnit(); if (eCSSUnit_Number == unit) lineThickness = nscoord(float(defaultThickness) * cssValue.GetFloatValue()); else if (eCSSUnit_Percent == unit) lineThickness = nscoord(float(defaultThickness) * cssValue.GetPercentValue()); else if (eCSSUnit_Null != unit) lineThickness = CalcLength(aPresContext, aStyleContext, cssValue); } } } // use minimum if the lineThickness is a non-zero value less than minimun if (lineThickness && lineThickness < minimumThickness) lineThickness = minimumThickness; return lineThickness; }
static bool IsSupportedInitDataType(const nsString& aCandidate, const nsAString& aKeySystem) { // All supported keySystems can handle "cenc" initDataType. // ClearKey also supports "keyids" and "webm" initDataTypes. return aCandidate.EqualsLiteral("cenc") || ((aKeySystem.EqualsLiteral("org.w3.clearkey") #ifdef MOZ_WIDEVINE_EME || aKeySystem.EqualsLiteral("com.widevine.alpha") #endif ) && (aCandidate.EqualsLiteral("keyids") || aCandidate.EqualsLiteral("webm)"))); }
nsresult CryptoKey::SetType(const nsString& aType) { mAttributes &= CLEAR_TYPE; if (aType.EqualsLiteral(WEBCRYPTO_KEY_TYPE_SECRET)) { mAttributes |= SECRET; } else if (aType.EqualsLiteral(WEBCRYPTO_KEY_TYPE_PUBLIC)) { mAttributes |= PUBLIC; } else if (aType.EqualsLiteral(WEBCRYPTO_KEY_TYPE_PRIVATE)) { mAttributes |= PRIVATE; } else { mAttributes |= UNKNOWN; return NS_ERROR_DOM_SYNTAX_ERR; } return NS_OK; }
void MediaEngineCameraVideoSource::SetName(nsString aName) { mDeviceName = aName; bool hasFacingMode = false; VideoFacingModeEnum facingMode = VideoFacingModeEnum::User; // Set facing mode based on device name. #if defined(MOZ_B2G_CAMERA) && defined(MOZ_WIDGET_GONK) if (aName.EqualsLiteral("back")) { hasFacingMode = true; facingMode = VideoFacingModeEnum::Environment; } else if (aName.EqualsLiteral("front")) { hasFacingMode = true; facingMode = VideoFacingModeEnum::User; } #endif // MOZ_B2G_CAMERA #if defined(ANDROID) && !defined(MOZ_WIDGET_GONK) // Names are generated. Example: "Camera 0, Facing back, Orientation 90" // // See media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/ // webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java if (aName.Find(NS_LITERAL_STRING("Facing back")) != kNotFound) { hasFacingMode = true; facingMode = VideoFacingModeEnum::Environment; } else if (aName.Find(NS_LITERAL_STRING("Facing front")) != kNotFound) { hasFacingMode = true; facingMode = VideoFacingModeEnum::User; } #endif // ANDROID #ifdef XP_MACOSX // Kludge to test user-facing cameras on OSX. if (aName.Find(NS_LITERAL_STRING("Face")) != -1) { hasFacingMode = true; facingMode = VideoFacingModeEnum::User; } #endif if (hasFacingMode) { mFacingMode.Assign(NS_ConvertUTF8toUTF16( VideoFacingModeEnumValues::strings[uint32_t(facingMode)].value)); } else { mFacingMode.Truncate(); } }
mozilla::ipc::IPCResult GMPChild::AnswerStartPlugin(const nsString& aAdapter) { LOGD("%s", __FUNCTION__); nsCString libPath; if (!GetUTF8LibPath(libPath)) { return IPC_FAIL_NO_REASON(this); } auto platformAPI = new GMPPlatformAPI(); InitPlatformAPI(*platformAPI, this); mGMPLoader = MakeUnique<GMPLoader>(); #if defined(MOZ_GMP_SANDBOX) if (!mGMPLoader->CanSandbox()) { LOGD("%s Can't sandbox GMP, failing", __FUNCTION__); delete platformAPI; return IPC_FAIL_NO_REASON(this); } #endif bool isWidevine = aAdapter.EqualsLiteral("widevine"); bool isChromium = aAdapter.EqualsLiteral("chromium"); #if defined(MOZ_GMP_SANDBOX) && defined(XP_MACOSX) MacSandboxPluginType pluginType = MacSandboxPluginType_GMPlugin_Default; if (isWidevine || isChromium) { pluginType = MacSandboxPluginType_GMPlugin_EME_Widevine; } if (!SetMacSandboxInfo(pluginType)) { NS_WARNING("Failed to set Mac GMP sandbox info"); delete platformAPI; return IPC_FAIL_NO_REASON(this); } #endif GMPAdapter* adapter = nullptr; if (isWidevine) { adapter = new WidevineAdapter(); } else if (isChromium) { adapter = new ChromiumCDMAdapter(); } if (!mGMPLoader->Load(libPath.get(), libPath.Length(), platformAPI, adapter)) { NS_WARNING("Failed to load GMP"); delete platformAPI; return IPC_FAIL_NO_REASON(this); } return IPC_OK(); }
/*---------------------------------------------------------------------------- WindowKindFromTypeString ----------------------------------------------------------------------------*/ static TWindowKind WindowKindFromTypeString(const nsString& inWindowType) { if (inWindowType.IsEmpty()) return kAnyWindowKind; if (inWindowType.EqualsLiteral("navigator:browser")) return kBrowserWindowKind; if (inWindowType.EqualsLiteral("mail:3pane")) return kMailWindowKind; if (inWindowType.EqualsLiteral("msgcompose")) return kMailComposeWindowKind; if (inWindowType.EqualsLiteral("mail:addressbook")) return kAddressBookWindowKind; if (inWindowType.EqualsLiteral("composer:html")) return kComposerWindowKind; if (inWindowType.EqualsLiteral("composer:text")) return kComposerWindowKind; return kOtherWindowKind; }
UniqueSECKEYPublicKey CryptoKey::PublicECKeyFromRaw(CryptoBuffer& aKeyData, const nsString& aNamedCurve, const nsNSSShutDownPreventionLock& /*proofOfLock*/) { UniquePLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); if (!arena) { return nullptr; } SECItem rawItem = { siBuffer, nullptr, 0 }; if (!aKeyData.ToSECItem(arena.get(), &rawItem)) { return nullptr; } uint32_t flen; if (aNamedCurve.EqualsLiteral(WEBCRYPTO_NAMED_CURVE_P256)) { flen = 32; // bytes } else if (aNamedCurve.EqualsLiteral(WEBCRYPTO_NAMED_CURVE_P384)) { flen = 48; // bytes } else if (aNamedCurve.EqualsLiteral(WEBCRYPTO_NAMED_CURVE_P521)) { flen = 66; // bytes } else { return nullptr; } // Check length of uncompressed point coordinates. There are 2 field elements // and a leading point form octet (which must EC_POINT_FORM_UNCOMPRESSED). if (rawItem.len != (2 * flen + 1)) { return nullptr; } // No support for compressed points. if (rawItem.data[0] != EC_POINT_FORM_UNCOMPRESSED) { return nullptr; } return CreateECPublicKey(&rawItem, aNamedCurve); }
static void SetProperty(OperatorData* aOperatorData, nsString aName, nsString aValue) { if (aName.IsEmpty() || aValue.IsEmpty()) return; // XXX These ones are not kept in the dictionary // Support for these requires nsString member variables // maxsize (default: infinity) // minsize (default: 1) if (aName.EqualsLiteral("direction")) { if (aValue.EqualsLiteral("vertical")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_DIRECTION_VERTICAL; else if (aValue.EqualsLiteral("horizontal")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_DIRECTION_HORIZONTAL; else return; // invalid value } else { bool isLeadingSpace; if (aName.EqualsLiteral("lspace")) isLeadingSpace = true; else if (aName.EqualsLiteral("rspace")) isLeadingSpace = false; else return; // input is not applicable // aValue is assumed to be a digit from 0 to 7 nsresult error = NS_OK; float space = aValue.ToFloat(&error) / 18.0; if (NS_FAILED(error)) return; if (isLeadingSpace) aOperatorData->mLeadingSpace = space; else aOperatorData->mTrailingSpace = space; } }
GMPCodecString ToGMPAPICodecString(const nsString& aCodec) { if (IsAACCodecString(aCodec)) { return GMP_CODEC_AAC; } if (aCodec.EqualsLiteral("opus")) { return GMP_CODEC_OPUS; } if (aCodec.EqualsLiteral("vorbis")) { return GMP_CODEC_VORBIS; } if (IsH264CodecString(aCodec)) { return GMP_CODEC_H264; } if (IsVP8CodecString(aCodec)) { return GMP_CODEC_VP8; } if (IsVP9CodecString(aCodec)) { return GMP_CODEC_VP9; } return EmptyCString(); }
mozilla::ipc::IPCResult GMPChild::AnswerStartPlugin(const nsString& aAdapter) { LOGD("%s", __FUNCTION__); nsCString libPath; if (!GetUTF8LibPath(libPath)) { return IPC_FAIL_NO_REASON(this); } auto platformAPI = new GMPPlatformAPI(); InitPlatformAPI(*platformAPI, this); mGMPLoader = GMPProcessChild::GetGMPLoader(); if (!mGMPLoader) { NS_WARNING("Failed to get GMPLoader"); delete platformAPI; return IPC_FAIL_NO_REASON(this); } bool isWidevine = aAdapter.EqualsLiteral("widevine"); #if defined(MOZ_GMP_SANDBOX) && defined(XP_MACOSX) MacSandboxPluginType pluginType = MacSandboxPluginType_GMPlugin_Default; if (isWidevine) { pluginType = MacSandboxPluginType_GMPlugin_EME_Widevine; } if (!SetMacSandboxInfo(pluginType)) { NS_WARNING("Failed to set Mac GMP sandbox info"); delete platformAPI; return IPC_FAIL_NO_REASON(this); } #endif GMPAdapter* adapter = (isWidevine) ? new WidevineAdapter() : nullptr; if (!mGMPLoader->Load(libPath.get(), libPath.Length(), mNodeId.BeginWriting(), mNodeId.Length(), platformAPI, adapter)) { NS_WARNING("Failed to load GMP"); delete platformAPI; return IPC_FAIL_NO_REASON(this); } return IPC_OK(); }
/* static */ bool nsMathMLElement::ParseNamedSpaceValue(const nsString& aString, nsCSSValue& aCSSValue, uint32_t aFlags) { int32_t i = 0; // See if it is one of the 'namedspace' (ranging -7/18em, -6/18, ... 7/18em) if (aString.EqualsLiteral("veryverythinmathspace")) { i = 1; } else if (aString.EqualsLiteral("verythinmathspace")) { i = 2; } else if (aString.EqualsLiteral("thinmathspace")) { i = 3; } else if (aString.EqualsLiteral("mediummathspace")) { i = 4; } else if (aString.EqualsLiteral("thickmathspace")) { i = 5; } else if (aString.EqualsLiteral("verythickmathspace")) { i = 6; } else if (aString.EqualsLiteral("veryverythickmathspace")) { i = 7; } else if (aFlags & PARSE_ALLOW_NEGATIVE) { if (aString.EqualsLiteral("negativeveryverythinmathspace")) { i = -1; } else if (aString.EqualsLiteral("negativeverythinmathspace")) { i = -2; } else if (aString.EqualsLiteral("negativethinmathspace")) { i = -3; } else if (aString.EqualsLiteral("negativemediummathspace")) { i = -4; } else if (aString.EqualsLiteral("negativethickmathspace")) { i = -5; } else if (aString.EqualsLiteral("negativeverythickmathspace")) { i = -6; } else if (aString.EqualsLiteral("negativeveryverythickmathspace")) { i = -7; } } if (0 != i) { aCSSValue.SetFloatValue(float(i)/float(18), eCSSUnit_EM); return true; } return false; }
NS_IMETHODIMP nsPopupSetFrame::ShowPopup(nsIContent* aElementContent, nsIContent* aPopupContent, PRInt32 aXPos, PRInt32 aYPos, const nsString& aPopupType, const nsString& anAnchorAlignment, const nsString& aPopupAlignment) { NS_ASSERTION(aElementContent != aPopupContent, "self referential popup"); if (!MayOpenPopup(this)) return NS_OK; nsWeakFrame weakFrame(this); // First fire the popupshowing event. if (!OnCreate(aXPos, aYPos, aPopupContent) || !weakFrame.IsAlive()) return NS_OK; // See if we already have an entry in our list. We must create a new one on a miss. nsPopupFrameList* entry = nsnull; if (mPopupList) entry = mPopupList->GetEntry(aPopupContent); if (!entry) { entry = new nsPopupFrameList(aPopupContent, mPopupList); if (!entry) return NS_ERROR_OUT_OF_MEMORY; mPopupList = entry; } // Cache the element content we're supposed to sync to entry->mPopupType = aPopupType; entry->mElementContent = aElementContent; entry->mPopupAlign = aPopupAlignment; entry->mPopupAnchor = anAnchorAlignment; entry->mXPos = aXPos; entry->mYPos = aYPos; // If a frame exists already, go ahead and use it. mPresContext->PresShell()->GetPrimaryFrameFor(aPopupContent, &entry->mPopupFrame); #ifdef DEBUG_PINK printf("X Pos: %d\n", mXPos); printf("Y Pos: %d\n", mYPos); #endif // Generate the popup. entry->mCreateHandlerSucceeded = PR_TRUE; entry->mIsOpen = PR_TRUE; // This may destroy or change entry->mPopupFrame or remove the entry from // mPopupList. |this| may also get deleted. MarkAsGenerated(aPopupContent); if (!weakFrame.IsAlive()) { return NS_OK; } nsPopupFrameList* newEntry = mPopupList ? mPopupList->GetEntry(aPopupContent) : nsnull; if (!newEntry || newEntry != entry) { NS_WARNING("The popup entry for aPopupContent has changed!"); return NS_OK; } // determine if this menu is a context menu and flag it nsIMenuParent* childPopup = nsnull; if (entry->mPopupFrame) CallQueryInterface(entry->mPopupFrame, &childPopup); if ( childPopup && aPopupType.EqualsLiteral("context") ) childPopup->SetIsContextMenu(PR_TRUE); // Now open the popup. OpenPopup(entry, PR_TRUE); if (!weakFrame.IsAlive()) { return NS_OK; } // Now fire the popupshown event. OnCreated(aXPos, aYPos, aPopupContent); return NS_OK; }
mozilla::ipc::IPCResult GMPChild::AnswerStartPlugin(const nsString& aAdapter) { LOGD("%s", __FUNCTION__); nsCString libPath; if (!GetUTF8LibPath(libPath)) { CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("GMPLibraryPath"), NS_ConvertUTF16toUTF8(mPluginPath)); #ifdef XP_WIN return IPC_FAIL( this, nsPrintfCString("Failed to get lib path with error(%d).", GetLastError()) .get()); #else return IPC_FAIL( this, "Failed to get lib path."); #endif } auto platformAPI = new GMPPlatformAPI(); InitPlatformAPI(*platformAPI, this); mGMPLoader = MakeUnique<GMPLoader>(); #if defined(MOZ_GMP_SANDBOX) if (!mGMPLoader->CanSandbox()) { LOGD("%s Can't sandbox GMP, failing", __FUNCTION__); delete platformAPI; return IPC_FAIL(this, "Can't sandbox GMP."); } #endif bool isChromium = aAdapter.EqualsLiteral("chromium"); #if defined(MOZ_GMP_SANDBOX) && defined(XP_MACOSX) MacSandboxPluginType pluginType = MacSandboxPluginType_GMPlugin_Default; if (isChromium) { pluginType = MacSandboxPluginType_GMPlugin_EME_Widevine; } if (!SetMacSandboxInfo(pluginType)) { NS_WARNING("Failed to set Mac GMP sandbox info"); delete platformAPI; return IPC_FAIL( this, nsPrintfCString("Failed to set Mac GMP sandbox info with plugin type %d.", pluginType).get()); } #endif GMPAdapter* adapter = nullptr; if (isChromium) { auto&& paths = MakeCDMHostVerificationPaths(); GMP_LOG("%s CDM host paths=%s", __func__, ToCString(paths).get()); adapter = new ChromiumCDMAdapter(std::move(paths)); } if (!mGMPLoader->Load(libPath.get(), libPath.Length(), platformAPI, adapter)) { NS_WARNING("Failed to load GMP"); delete platformAPI; CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("GMPLibraryPath"), NS_ConvertUTF16toUTF8(mPluginPath)); #ifdef XP_WIN return IPC_FAIL( this, nsPrintfCString("Failed to load GMP with error(%d).", GetLastError()) .get()); #else return IPC_FAIL( this, "Failed to load GMP."); #endif } return IPC_OK(); }
bool GMPChild::AnswerStartPlugin(const nsString& aAdapter) { LOGD("%s", __FUNCTION__); if (!PreLoadPluginVoucher()) { NS_WARNING("Plugin voucher failed to load!"); return false; } PreLoadSandboxVoucher(); nsCString libPath; if (!GetUTF8LibPath(libPath)) { return false; } auto platformAPI = new GMPPlatformAPI(); InitPlatformAPI(*platformAPI, this); mGMPLoader = GMPProcessChild::GetGMPLoader(); if (!mGMPLoader) { NS_WARNING("Failed to get GMPLoader"); delete platformAPI; return false; } bool isWidevine = aAdapter.EqualsLiteral("widevine"); #if defined(MOZ_GMP_SANDBOX) && defined(XP_MACOSX) MacSandboxPluginType pluginType = MacSandboxPluginType_GMPlugin_Default; if (isWidevine) { pluginType = MacSandboxPluginType_GMPlugin_EME_Widevine; } if (!SetMacSandboxInfo(pluginType)) { NS_WARNING("Failed to set Mac GMP sandbox info"); delete platformAPI; return false; } #endif GMPAdapter* adapter = (isWidevine) ? new WidevineAdapter() : nullptr; if (!mGMPLoader->Load(libPath.get(), libPath.Length(), mNodeId.BeginWriting(), mNodeId.Length(), platformAPI, adapter)) { NS_WARNING("Failed to load GMP"); delete platformAPI; return false; } void* sh = nullptr; GMPAsyncShutdownHost* host = static_cast<GMPAsyncShutdownHost*>(this); GMPErr err = GetAPI(GMP_API_ASYNC_SHUTDOWN, host, &sh); if (err == GMPNoErr && sh) { mAsyncShutdown = reinterpret_cast<GMPAsyncShutdown*>(sh); SendAsyncShutdownRequired(); } return true; }
void SetProperty(OperatorData* aOperatorData, nsString aName, nsString aValue) { if (!aName.Length() || !aValue.Length()) return; // XXX These ones are not kept in the dictionary // Support for these requires nsString member variables // maxsize (default: infinity) // minsize (default: 1) if (aValue.EqualsLiteral("true")) { // see if we should enable flags with default value=false if (aName.EqualsLiteral("fence")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_FENCE; else if (aName.EqualsLiteral("accent")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_ACCENT; else if (aName.EqualsLiteral("largeop")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_LARGEOP; else if (aName.EqualsLiteral("separator")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_SEPARATOR; else if (aName.EqualsLiteral("movablelimits")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_MOVABLELIMITS; } else if (aValue.EqualsLiteral("false")) { // see if we should disable flags with default value=true if (aName.EqualsLiteral("symmetric")) aOperatorData->mFlags &= ~NS_MATHML_OPERATOR_SYMMETRIC; } else if (aName.EqualsLiteral("stretchy") && (1 == aOperatorData->mStr.Length())) { if (aValue.EqualsLiteral("vertical")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY_VERT; else if (aValue.EqualsLiteral("horizontal")) aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY_HORIZ; else return; // invalid value if (kNotFound == nsMathMLOperators::FindStretchyOperator(aOperatorData->mStr[0])) { gStretchyOperatorArray->AppendElement(aOperatorData); } } else { PRInt32 i = 0; float space = 0.0f; PRBool isLeftSpace; if (aName.EqualsLiteral("lspace")) isLeftSpace = PR_TRUE; else if (aName.EqualsLiteral("rspace")) isLeftSpace = PR_FALSE; else return; // input is not applicable // See if it is a numeric value (unit is assumed to be 'em') if (nsCRT::IsAsciiDigit(aValue[0])) { PRInt32 error = 0; space = aValue.ToFloat(&error); if (error) return; } // See if it is one of the 'namedspace' (ranging 1/18em...7/18em) else if (aValue.EqualsLiteral("veryverythinmathspace")) i = 1; else if (aValue.EqualsLiteral("verythinmathspace")) i = 2; else if (aValue.EqualsLiteral("thinmathspace")) i = 3; else if (aValue.EqualsLiteral("mediummathspace")) i = 4; else if (aValue.EqualsLiteral("thickmathspace")) i = 5; else if (aValue.EqualsLiteral("verythickmathspace")) i = 6; else if (aValue.EqualsLiteral("veryverythickmathspace")) i = 7; if (0 != i) // it was a namedspace value space = float(i)/float(18); if (isLeftSpace) aOperatorData->mLeftSpace = space; else aOperatorData->mRightSpace = space; } }
/* static */ PRBool nsMathMLFrame::ParseNamedSpaceValue(nsIFrame* aMathMLmstyleFrame, nsString& aString, nsCSSValue& aCSSValue) { aCSSValue.Reset(); aString.CompressWhitespace(); // aString is not a const in this code... if (!aString.Length()) return PR_FALSE; // See if it is one of the 'namedspace' (ranging 1/18em...7/18em) PRInt32 i = 0; nsIAtom* namedspaceAtom = nsnull; if (aString.EqualsLiteral("veryverythinmathspace")) { i = 1; namedspaceAtom = nsMathMLAtoms::veryverythinmathspace_; } else if (aString.EqualsLiteral("verythinmathspace")) { i = 2; namedspaceAtom = nsMathMLAtoms::verythinmathspace_; } else if (aString.EqualsLiteral("thinmathspace")) { i = 3; namedspaceAtom = nsMathMLAtoms::thinmathspace_; } else if (aString.EqualsLiteral("mediummathspace")) { i = 4; namedspaceAtom = nsMathMLAtoms::mediummathspace_; } else if (aString.EqualsLiteral("thickmathspace")) { i = 5; namedspaceAtom = nsMathMLAtoms::thickmathspace_; } else if (aString.EqualsLiteral("verythickmathspace")) { i = 6; namedspaceAtom = nsMathMLAtoms::verythickmathspace_; } else if (aString.EqualsLiteral("veryverythickmathspace")) { i = 7; namedspaceAtom = nsMathMLAtoms::veryverythickmathspace_; } if (0 != i) { if (aMathMLmstyleFrame) { // see if there is a <mstyle> that has overriden the default value // GetAttribute() will recurse all the way up into the <mstyle> hierarchy nsAutoString value; if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(nsnull, aMathMLmstyleFrame, namedspaceAtom, value)) { if (ParseNumericValue(value, aCSSValue) && aCSSValue.IsLengthUnit()) { return PR_TRUE; } } } // fall back to the default value aCSSValue.SetFloatValue(float(i)/float(18), eCSSUnit_EM); return PR_TRUE; } return PR_FALSE; }
// This implements part of the algorithm for legacy behavior described in // http://www.whatwg.org/specs/web-apps/current-work/complete/common-microsyntaxes.html#rules-for-parsing-a-legacy-color-value NS_GFX_(bool) NS_LooseHexToRGB(const nsString& aColorSpec, nscolor* aResult) { if (aColorSpec.EqualsLiteral("transparent")) { return false; } int nameLen = aColorSpec.Length(); const PRUnichar* colorSpec = aColorSpec.get(); if (nameLen > 128) { nameLen = 128; } if ('#' == colorSpec[0]) { ++colorSpec; --nameLen; } // digits per component int dpc = (nameLen + 2) / 3; int newdpc = dpc; // Use only the rightmost 8 characters of each component. if (newdpc > 8) { nameLen -= newdpc - 8; colorSpec += newdpc - 8; newdpc = 8; } // And then keep trimming characters at the left until we'd trim one // that would leave a nonzero value, but not past 2 characters per // component. while (newdpc > 2) { bool haveNonzero = false; for (int c = 0; c < 3; ++c) { NS_ABORT_IF_FALSE(c * dpc < nameLen, "should not pass end of string while newdpc > 2"); PRUnichar ch = colorSpec[c * dpc]; if (('1' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || ('a' <= ch && ch <= 'f')) { haveNonzero = true; break; } } if (haveNonzero) { break; } --newdpc; --nameLen; ++colorSpec; } // Translate components from hex to binary int r = ComponentValue(colorSpec, nameLen, 0, dpc); int g = ComponentValue(colorSpec, nameLen, 1, dpc); int b = ComponentValue(colorSpec, nameLen, 2, dpc); NS_ASSERTION((r >= 0) && (r <= 255), "bad r"); NS_ASSERTION((g >= 0) && (g <= 255), "bad g"); NS_ASSERTION((b >= 0) && (b <= 255), "bad b"); *aResult = NS_RGB(r, g, b); return true; }