nsresult nsPermissionManager::CommonTestPermission(nsIURI *aURI, const char *aType, PRUint32 *aPermission, PRBool aExactHostMatch) { NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_ARG_POINTER(aType); // set the default *aPermission = nsIPermissionManager::UNKNOWN_ACTION; nsCAutoString host; nsresult rv = GetHost(aURI, host); // no host doesn't mean an error. just return the default if (NS_FAILED(rv)) return NS_OK; PRInt32 typeIndex = GetTypeIndex(aType, PR_FALSE); // If type == -1, the type isn't known, // so just return NS_OK if (typeIndex == -1) return NS_OK; nsHostEntry *entry = GetHostEntry(host, typeIndex, aExactHostMatch); if (entry) *aPermission = entry->GetPermission(typeIndex).mPermission; return NS_OK; }
void ButtonComponent::ParseAttribute(const TiXmlAttribute* attribute) { Component::ParseAttribute(attribute); if (IsEqual(attribute->Name(), "texture_focused")) { SetTexture(FOCUSED, attribute->Value()); } else if (IsEqual(attribute->Name(), "texture_unfocused")) { SetTexture(UNFOCUSED, attribute->Value()); } else if (IsEqual(attribute->Name(), "size")) { SetSize(ParseVector2f(attribute->Value())); } else if (IsEqual(attribute->Name(), "next_menu")) { m_nextMenu = attribute->Value(); } else if (IsEqual(attribute->Name(), "type")) { SetType(GetTypeIndex(attribute->Value())); } else if (IsEqual(attribute->Name(), "style")) { SetStyle(GetStyleIndex(attribute->Value())); } else if (IsEqual(attribute->Name(), "text")) { SetText(attribute->Value()); } else if (IsEqual(attribute->Name(), "text_font")) { SetTextFont(attribute->Value()); } else if (IsEqual(attribute->Name(), "text_size")) { SetFontSize(attribute->UnsignedValue()); } else if (IsEqual(attribute->Name(), "text_color")) { SetTextColor(ParseVector3f(attribute->Value())); } else if (IsEqual(attribute->Name(), "text_highlight_color")) { SetHighlightTextColor(ParseVector3f(attribute->Value())); } else if (IsEqual(attribute->Name(), "has_textures")) { SetIfHasTextures(attribute->BoolValue()); } else if (IsEqual(attribute->Name(), "text_highlights")) { SetIfTextHighlights(attribute->BoolValue()); } }
str InputElement::GetName() const { str __name; switch (GetInterpretation()) { case InputElement::kAbsoluteAxis: __name += "AbsoluteAxis"; break; case InputElement::kRelativeAxis: __name += "RelativeAxis"; break; default: __name += "Button"; break; } __name += strutil::IntToString(GetTypeIndex(), 10); return (__name); }
nsresult nsPermissionManager::AddInternal(const nsAFlatCString &aHost, const nsAFlatCString &aType, PRUint32 aPermission, PRInt64 aID, PRUint32 aExpireType, PRInt64 aExpireTime, NotifyOperationType aNotifyOperation, DBOperationType aDBOperation) { if (!gHostArena) { gHostArena = new PLArenaPool; if (!gHostArena) return NS_ERROR_OUT_OF_MEMORY; PL_INIT_ARENA_POOL(gHostArena, "PermissionHostArena", HOST_ARENA_SIZE); } // look up the type index PRInt32 typeIndex = GetTypeIndex(aType.get(), PR_TRUE); NS_ENSURE_TRUE(typeIndex != -1, NS_ERROR_OUT_OF_MEMORY); // When an entry already exists, PutEntry will return that, instead // of adding a new one nsHostEntry *entry = mHostTable.PutEntry(aHost.get()); if (!entry) return NS_ERROR_FAILURE; if (!entry->GetKey()) { mHostTable.RawRemoveEntry(entry); return NS_ERROR_OUT_OF_MEMORY; } // figure out the transaction type, and get any existing permission value OperationType op; PRInt32 index = entry->GetPermissionIndex(typeIndex); if (index == -1) { if (aPermission == nsIPermissionManager::UNKNOWN_ACTION) op = eOperationNone; else op = eOperationAdding; } else { nsPermissionEntry oldPermissionEntry = entry->GetPermissions()[index]; // remove the permission if the permission is UNKNOWN, update the // permission if its value or expire type have changed OR if the time has // changed and the expire type is time, otherwise, don't modify. There's // no need to modify a permission that doesn't expire with time when the // only thing changed is the expire time. if (aPermission == oldPermissionEntry.mPermission && aExpireType == oldPermissionEntry.mExpireType && (aExpireType != nsIPermissionManager::EXPIRE_TIME || aExpireTime == oldPermissionEntry.mExpireTime)) op = eOperationNone; else if (aPermission == nsIPermissionManager::UNKNOWN_ACTION) op = eOperationRemoving; else op = eOperationChanging; } // do the work for adding, deleting, or changing a permission: // update the in-memory list, write to the db, and notify consumers. PRInt64 id; switch (op) { case eOperationNone: { // nothing to do return NS_OK; } case eOperationAdding: { if (aDBOperation == eWriteToDB) { // we'll be writing to the database - generate a known unique id id = ++mLargestID; } else { // we're reading from the database - use the id already assigned id = aID; } entry->GetPermissions().AppendElement(nsPermissionEntry(typeIndex, aPermission, id, aExpireType, aExpireTime)); if (aDBOperation == eWriteToDB && aExpireType != nsIPermissionManager::EXPIRE_SESSION) UpdateDB(op, mStmtInsert, id, aHost, aType, aPermission, aExpireType, aExpireTime); if (aNotifyOperation == eNotify) { NotifyObserversWithPermission(aHost, mTypeArray[typeIndex], aPermission, aExpireType, aExpireTime, NS_LITERAL_STRING("added").get()); } break; } case eOperationRemoving: { nsPermissionEntry oldPermissionEntry = entry->GetPermissions()[index]; id = oldPermissionEntry.mID; entry->GetPermissions().RemoveElementAt(index); // If no more types are present, remove the entry if (entry->GetPermissions().IsEmpty()) mHostTable.RawRemoveEntry(entry); if (aDBOperation == eWriteToDB) UpdateDB(op, mStmtDelete, id, EmptyCString(), EmptyCString(), 0, nsIPermissionManager::EXPIRE_NEVER, 0); if (aNotifyOperation == eNotify) { NotifyObserversWithPermission(aHost, mTypeArray[typeIndex], oldPermissionEntry.mPermission, oldPermissionEntry.mExpireType, oldPermissionEntry.mExpireTime, NS_LITERAL_STRING("deleted").get()); } break; } case eOperationChanging: { id = entry->GetPermissions()[index].mID; entry->GetPermissions()[index].mPermission = aPermission; if (aDBOperation == eWriteToDB && aExpireType != nsIPermissionManager::EXPIRE_SESSION) UpdateDB(op, mStmtUpdate, id, EmptyCString(), EmptyCString(), aPermission, aExpireType, aExpireTime); if (aNotifyOperation == eNotify) { NotifyObserversWithPermission(aHost, mTypeArray[typeIndex], aPermission, aExpireType, aExpireTime, NS_LITERAL_STRING("changed").get()); } break; } } return NS_OK; }