当前位置: 首页>>代码示例>>C++>>正文


C++ NS_ADDREF函数代码示例

本文整理汇总了C++中NS_ADDREF函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_ADDREF函数的具体用法?C++ NS_ADDREF怎么用?C++ NS_ADDREF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NS_ADDREF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NS_ASSERTION

void
XPCCallContext::Init(XPCContext::LangType callerLanguage,
                     JSBool callBeginRequest,
                     JSObject* obj,
                     JSObject* funobj,
                     WrapperInitOptions wrapperInitOptions,
                     jsid name,
                     uintN argc,
                     jsval *argv,
                     jsval *rval)
{
    if (!mXPC)
        return;

    mThreadData = XPCPerThreadData::GetData(mJSContext);

    if (!mThreadData)
        return;

    XPCJSContextStack* stack = mThreadData->GetJSContextStack();
    JSContext* topJSContext;

    if (!stack || NS_FAILED(stack->Peek(&topJSContext))) {
        // If we don't have a stack we're probably in shutdown.
        NS_ASSERTION(!stack, "Bad, Peek failed!");
        mJSContext = nsnull;
        return;
    }

    if (!mJSContext) {
        // This is slightly questionable. If called without an explicit
        // JSContext (generally a call to a wrappedJS) we will use the JSContext
        // on the top of the JSContext stack - if there is one - *before*
        // falling back on the safe JSContext.
        // This is good AND bad because it makes calls from JS -> native -> JS
        // have JS stack 'continuity' for purposes of stack traces etc.
        // Note: this *is* what the pre-XPCCallContext xpconnect did too.

        if (topJSContext)
            mJSContext = topJSContext;
        else if (NS_FAILED(stack->GetSafeJSContext(&mJSContext)) || !mJSContext)
            return;
    }

    if (topJSContext != mJSContext) {
        if (NS_FAILED(stack->Push(mJSContext))) {
            NS_ERROR("bad!");
            return;
        }
        mContextPopRequired = JS_TRUE;
    }

    // Get into the request as early as we can to avoid problems with scanning
    // callcontexts on other threads from within the gc callbacks.

    NS_ASSERTION(!callBeginRequest || mCallerLanguage == NATIVE_CALLER,
                 "Don't call JS_BeginRequest unless the caller is native.");
    if (callBeginRequest)
        JS_BeginRequest(mJSContext);

    mXPCContext = XPCContext::GetXPCContext(mJSContext);
    mPrevCallerLanguage = mXPCContext->SetCallingLangType(mCallerLanguage);

    // hook into call context chain for our thread
    mPrevCallContext = mThreadData->SetCallContext(this);

    // We only need to addref xpconnect once so only do it if this is the first
    // context in the chain.
    if (!mPrevCallContext)
        NS_ADDREF(mXPC);

    mState = HAVE_CONTEXT;

    if (!obj)
        return;

    mScopeForNewJSObjects = obj;

    mState = HAVE_SCOPE;

    mMethodIndex = 0xDEAD;

    mState = HAVE_OBJECT;

    mTearOff = nsnull;
    if (wrapperInitOptions == INIT_SHOULD_LOOKUP_WRAPPER) {
        mWrapper = XPCWrappedNative::GetWrappedNativeOfJSObject(mJSContext, obj,
                                                                funobj,
                                                                &mFlattenedJSObject,
                                                                &mTearOff);
        if (mWrapper) {
            DEBUG_CheckWrapperThreadSafety(mWrapper);

            mFlattenedJSObject = mWrapper->GetFlatJSObject();

            if (mTearOff)
                mScriptableInfo = nsnull;
            else
                mScriptableInfo = mWrapper->GetScriptableInfo();
        } else {
//.........这里部分代码省略.........
开发者ID:krad-radio,项目名称:mozilla-krad,代码行数:101,代码来源:XPCCallContext.cpp

示例2: NS_INIT_ISUPPORTS

nsXPIDLPlugin::nsXPIDLPlugin( nsIXPIDLPlugin *plugin )
{
  NS_INIT_ISUPPORTS();
  this->plugin = plugin;
  NS_ADDREF( plugin );
}
开发者ID:EdgarChen,项目名称:mozilla-cvs-history,代码行数:6,代码来源:nsXPIDLPlugin.cpp

示例3: LOG

NS_IMETHODIMP
nsJavaXPTCStub::QueryInterface(const nsID &aIID, void **aInstancePtr)
{
  nsresult rv;

  LOG(("JavaStub::QueryInterface()\n"));
  *aInstancePtr = nsnull;
  nsJavaXPTCStub *master = mMaster ? mMaster : this;

  // This helps us differentiate between the help classes.
  if (aIID.Equals(NS_GET_IID(nsJavaXPTCStub)))
  {
    *aInstancePtr = master;
    NS_ADDREF(this);
    return NS_OK;
  }

  // always return the master stub for nsISupports
  if (aIID.Equals(NS_GET_IID(nsISupports)))
  {
    *aInstancePtr = master->mXPTCStub;
    NS_ADDREF(master);
    return NS_OK;
  }

  // All Java objects support weak references
  if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference)))
  {
    *aInstancePtr = static_cast<nsISupportsWeakReference*>(master);
    NS_ADDREF(master);
    return NS_OK;
  }

  // does any existing stub support the requested IID?
  nsJavaXPTCStub *stub = master->FindStubSupportingIID(aIID);
  if (stub)
  {
    *aInstancePtr = stub->mXPTCStub;
    NS_ADDREF(stub);
    return NS_OK;
  }

  JNIEnv* env = GetJNIEnv();

  // Query Java object
  LOG(("\tCalling Java object queryInterface\n"));
  jobject javaObject = env->CallObjectMethod(mJavaWeakRef, getReferentMID);

  jmethodID qiMID = 0;
  jclass clazz = env->GetObjectClass(javaObject);
  if (clazz) {
    char* sig = "(Ljava/lang/String;)Lorg/mozilla/interfaces/nsISupports;";
    qiMID = env->GetMethodID(clazz, "queryInterface", sig);
    NS_ASSERTION(qiMID, "Failed to get queryInterface method ID");
  }

  if (qiMID == 0) {
    env->ExceptionClear();
    return NS_NOINTERFACE;
  }

  // construct IID string
  jstring iid_jstr = nsnull;
  char* iid_str = aIID.ToString();
  if (iid_str) {
    iid_jstr = env->NewStringUTF(iid_str);
  }
  if (!iid_str || !iid_jstr) {
    env->ExceptionClear();
    return NS_ERROR_OUT_OF_MEMORY;
  }
  NS_Free(iid_str);

  // call queryInterface method
  jobject obj = env->CallObjectMethod(javaObject, qiMID, iid_jstr);
  if (env->ExceptionCheck()) {
    env->ExceptionClear();
    return NS_ERROR_FAILURE;
  }
  if (!obj)
    return NS_NOINTERFACE;

  // Get interface info for new java object
  nsCOMPtr<nsIInterfaceInfoManager>
    iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIInterfaceInfo> iinfo;
  rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));
  if (NS_FAILED(rv))
    return rv;

  stub = new nsJavaXPTCStub(obj, iinfo, &rv);
  if (!stub)
    return NS_ERROR_OUT_OF_MEMORY;

  if (NS_FAILED(rv)) {
    delete stub;
    return rv;
  }
//.........这里部分代码省略.........
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:101,代码来源:nsJavaXPTCStub.cpp

示例4: NS_ADDREF

NS_IMETHODIMP
nsSyncStreamListener::GetInputStream(nsIInputStream **result)
{
    NS_ADDREF(*result = this);
    return NS_OK;
}
开发者ID:Lynart,项目名称:mozilla-central,代码行数:6,代码来源:nsSyncStreamListener.cpp

示例5: NS_ENSURE_ARG_POINTER

nsresult ImportWMMailImpl::Create(nsIImportMail **aImport) {
  NS_ENSURE_ARG_POINTER(aImport);
  NS_ADDREF(*aImport = new ImportWMMailImpl());
  return NS_OK;
}
开发者ID:mozilla,项目名称:releases-comm-central,代码行数:5,代码来源:nsWMImport.cpp

示例6: NS_ASSERTION


//.........这里部分代码省略.........
        NS_ENSURE_SUCCESS(rv, rv);

        rv = appendMatchingDescendants(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);

        while (!walker.moveToNextSibling()) {
          if (!walker.moveToParent()) {
            cont = false;
            break;
          }
        }
      }
      break;
    }
    case FOLLOWING_SIBLING_AXIS: {
      while (walker.moveToNextSibling()) {
        rv = appendIfMatching(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      break;
    }
    case NAMESPACE_AXIS:  //-- not yet implemented
#if 0
            // XXX DEBUG OUTPUT
            cout << "namespace axis not yet implemented"<<endl;
#endif
      break;
    case PARENT_AXIS: {
      if (walker.moveToParent()) {
        rv = appendIfMatching(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      break;
    }
    case PRECEDING_AXIS: {
      nodes->setReverse();

      bool cont = true;
      while (!walker.moveToPreviousSibling()) {
        if (!walker.moveToParent()) {
          cont = false;
          break;
        }
      }
      while (cont) {
        rv = appendMatchingDescendantsRev(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);

        rv = appendIfMatching(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);

        while (!walker.moveToPreviousSibling()) {
          if (!walker.moveToParent()) {
            cont = false;
            break;
          }
        }
      }
      break;
    }
    case PRECEDING_SIBLING_AXIS: {
      nodes->setReverse();

      while (walker.moveToPreviousSibling()) {
        rv = appendIfMatching(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      break;
    }
    case SELF_AXIS: {
      rv = appendIfMatching(walker, aContext, nodes);
      NS_ENSURE_SUCCESS(rv, rv);
      break;
    }
    default:  // Children Axis
    {
      if (!walker.moveToFirstChild()) {
        break;
      }

      do {
        rv = appendIfMatching(walker, aContext, nodes);
        NS_ENSURE_SUCCESS(rv, rv);
      } while (walker.moveToNextSibling());
      break;
    }
  }

  // Apply predicates
  if (!isEmpty()) {
    rv = evaluatePredicates(nodes, aContext);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nodes->unsetReverse();

  NS_ADDREF(*aResult = nodes);

  return NS_OK;
}
开发者ID:jasonLaster,项目名称:gecko-dev,代码行数:101,代码来源:txLocationStep.cpp

示例7: defined

// wrapper for get_values_len
//
NS_IMETHODIMP 
nsLDAPMessage::GetBinaryValues(const char *aAttr, uint32_t *aCount,
                               nsILDAPBERValue ***aValues)
{
    struct berval **values;

#if defined(DEBUG)
    // We only want this being logged for debug builds so as not to affect performance too much.
    PR_LOG(gLDAPLogModule, PR_LOG_DEBUG,
           ("nsLDAPMessage::GetBinaryValues(): called with aAttr = '%s'", 
            aAttr));
#endif

    values = ldap_get_values_len(mConnectionHandle, mMsgHandle, aAttr);

    // bail out if there was a problem
    //
    if (!values) {
        int32_t lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0);

        if ( lderrno == LDAP_DECODING_ERROR ) {
            // this may not be an error; it could just be that the 
            // caller has asked for an attribute that doesn't exist.
            //
            PR_LOG(gLDAPLogModule, PR_LOG_WARNING, 
                   ("nsLDAPMessage::GetBinaryValues(): ldap_get_values "
                    "returned LDAP_DECODING_ERROR"));
            return NS_ERROR_LDAP_DECODING_ERROR;

        } else if ( lderrno == LDAP_PARAM_ERROR ) {
            NS_ERROR("nsLDAPMessage::GetBinaryValues(): internal error: 1");
            return NS_ERROR_UNEXPECTED;

        } else {
            NS_ERROR("nsLDAPMessage::GetBinaryValues(): internal error: 2");
            return NS_ERROR_UNEXPECTED;
        }
    }

    // count the values
    //
    uint32_t numVals = ldap_count_values_len(values);

    // create the out array
    //
    *aValues = 
        static_cast<nsILDAPBERValue **>(nsMemory::Alloc(numVals * sizeof(nsILDAPBERValue)));
    if (!aValues) {
        ldap_value_free_len(values);
        return NS_ERROR_OUT_OF_MEMORY;
    }

    // clone the array (except for the trailing NULL entry) using the 
    // shared allocator for XPCOM correctness
    //
    uint32_t i;
    nsresult rv;
    for ( i = 0 ; i < numVals ; i++ ) {

        // create an nsBERValue object
        //
        nsCOMPtr<nsILDAPBERValue> berValue = new nsLDAPBERValue();
        if (!berValue) {
            NS_ERROR("nsLDAPMessage::GetBinaryValues(): out of memory"
                     " creating nsLDAPBERValue object");
            NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, aValues);
            ldap_value_free_len(values);
            return NS_ERROR_OUT_OF_MEMORY;
        }

        // copy the value from the struct into the nsBERValue
        //
        rv = berValue->Set(values[i]->bv_len, 
                           reinterpret_cast<uint8_t *>(values[i]->bv_val));
        if (NS_FAILED(rv)) {
            NS_ERROR("nsLDAPMessage::GetBinaryValues(): error setting"
                     " nsBERValue");
            ldap_value_free_len(values);
            return rv == NS_ERROR_OUT_OF_MEMORY ? rv : NS_ERROR_UNEXPECTED;
        }

        // put the nsIBERValue object into the out array
        //
        NS_ADDREF( (*aValues)[i] = berValue.get() );
    }

    *aCount = numVals;
    ldap_value_free_len(values);
    return NS_OK;
}
开发者ID:Type-of-Tool,项目名称:ExMail,代码行数:92,代码来源:nsLDAPMessage.cpp

示例8: NS_ENSURE_ARG_POINTER

NS_IMETHODIMP
nsChromeProtocolHandler::NewChannel(nsIURI *aURI, nsILoadInfo *aLoadInfo,
                                    nsIChannel **aResult) {
  nsresult rv;

  NS_ENSURE_ARG_POINTER(aURI);
  NS_ENSURE_ARG_POINTER(aLoadInfo);

  MOZ_ASSERT(aResult, "Null out param");

#ifdef DEBUG
  // Check that the uri we got is already canonified
  nsresult debug_rv;
  nsCOMPtr<nsIURI> debugURL = aURI;
  debug_rv = nsChromeRegistry::Canonify(debugURL);
  if (NS_SUCCEEDED(debug_rv)) {
    bool same;
    debug_rv = aURI->Equals(debugURL, &same);
    if (NS_SUCCEEDED(debug_rv)) {
      NS_ASSERTION(same,
                   "Non-canonified chrome uri passed to "
                   "nsChromeProtocolHandler::NewChannel!");
    }
  }
#endif

  nsCOMPtr<nsIChannel> result;

  if (!nsChromeRegistry::gChromeRegistry) {
    // We don't actually want this ref, we just want the service to
    // initialize if it hasn't already.
    nsCOMPtr<nsIChromeRegistry> reg =
        mozilla::services::GetChromeRegistryService();
    NS_ENSURE_TRUE(nsChromeRegistry::gChromeRegistry, NS_ERROR_FAILURE);
  }

  nsCOMPtr<nsIURI> resolvedURI;
  rv = nsChromeRegistry::gChromeRegistry->ConvertChromeURL(
      aURI, getter_AddRefs(resolvedURI));
  if (NS_FAILED(rv)) {
#ifdef DEBUG
    printf("Couldn't convert chrome URL: %s\n", aURI->GetSpecOrDefault().get());
#endif
    return rv;
  }

  // We don't want to allow the inner protocol handler modify the result
  // principal URI since we want either |aURI| or anything pre-set by upper
  // layers to prevail.
  nsCOMPtr<nsIURI> savedResultPrincipalURI;
  rv =
      aLoadInfo->GetResultPrincipalURI(getter_AddRefs(savedResultPrincipalURI));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = NS_NewChannelInternal(getter_AddRefs(result), resolvedURI, aLoadInfo);
  NS_ENSURE_SUCCESS(rv, rv);

#ifdef DEBUG
  nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(result));
  if (fileChan) {
    nsCOMPtr<nsIFile> file;
    fileChan->GetFile(getter_AddRefs(file));

    bool exists = false;
    file->Exists(&exists);
    if (!exists) {
      printf("Chrome file doesn't exist: %s\n",
             file->HumanReadablePath().get());
    }
  }
#endif

  // Make sure that the channel remembers where it was
  // originally loaded from.
  rv = aLoadInfo->SetResultPrincipalURI(savedResultPrincipalURI);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = result->SetOriginalURI(aURI);
  if (NS_FAILED(rv)) return rv;

  // Get a system principal for content files and set the owner
  // property of the result
  nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
  nsAutoCString path;
  rv = url->GetPathQueryRef(path);
  if (StringBeginsWith(path, NS_LITERAL_CSTRING("/content/"))) {
    result->SetOwner(nsContentUtils::GetSystemPrincipal());
  }

  // XXX Removed dependency-tracking code from here, because we're not
  // tracking them anyways (with fastload we checked only in DEBUG
  // and with startupcache not at all), but this is where we would start
  // if we need to re-add.
  // See bug 531886, bug 533038.
  result->SetContentCharset(NS_LITERAL_CSTRING("UTF-8"));

  *aResult = result;
  NS_ADDREF(*aResult);
  return NS_OK;
}
开发者ID:davidp3,项目名称:gecko-dev,代码行数:99,代码来源:nsChromeProtocolHandler.cpp

示例9: NS_INIT_ISUPPORTS

nsXPIDLPluginInstance::nsXPIDLPluginInstance( nsIXPIDLPluginInstance *pluginInstance )
{
  NS_INIT_ISUPPORTS();
  this->pluginInstance = pluginInstance;
  NS_ADDREF( pluginInstance );
}
开发者ID:EdgarChen,项目名称:mozilla-cvs-history,代码行数:6,代码来源:nsXPIDLPluginInstance.cpp

示例10: NS_ADDREF

nsresult
txCoreFunctionCall::getNameAtom(nsIAtom** aAtom)
{
    NS_ADDREF(*aAtom = *descriptTable[mType].mName);
    return NS_OK;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:6,代码来源:txCoreFunctionCall.cpp

示例11: switch

/*
 * Evaluates this Expr based on the given context node and processor state
 * @param context the context node for evaluation of this Expr
 * @param ps the ContextState containing the stack information needed
 * for evaluation
 * @return the result of the evaluation
 */
nsresult
txCoreFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
{
    *aResult = nsnull;

    if (!requireParams(descriptTable[mType].mMinParams,
                       descriptTable[mType].mMaxParams,
                       aContext)) {
        return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
    }

    nsresult rv = NS_OK;
    switch (mType) {
        case COUNT:
        {
            nsRefPtr<txNodeSet> nodes;
            rv = evaluateToNodeSet(mParams[0], aContext,
                                   getter_AddRefs(nodes));
            NS_ENSURE_SUCCESS(rv, rv);

            return aContext->recycler()->getNumberResult(nodes->size(),
                                                         aResult);
        }
        case ID:
        {
            nsRefPtr<txAExprResult> exprResult;
            rv = mParams[0]->evaluate(aContext, getter_AddRefs(exprResult));
            NS_ENSURE_SUCCESS(rv, rv);

            nsRefPtr<txNodeSet> resultSet;
            rv = aContext->recycler()->getNodeSet(getter_AddRefs(resultSet));
            NS_ENSURE_SUCCESS(rv, rv);

            txXPathTreeWalker walker(aContext->getContextNode());
            
            if (exprResult->getResultType() == txAExprResult::NODESET) {
                txNodeSet* nodes = static_cast<txNodeSet*>
                                              (static_cast<txAExprResult*>
                                                          (exprResult));
                PRInt32 i;
                for (i = 0; i < nodes->size(); ++i) {
                    nsAutoString idList;
                    txXPathNodeUtils::appendNodeValue(nodes->get(i), idList);
                    nsWhitespaceTokenizer tokenizer(idList);
                    while (tokenizer.hasMoreTokens()) {
                        if (walker.moveToElementById(tokenizer.nextToken())) {
                            resultSet->add(walker.getCurrentPosition());
                        }
                    }
                }
            }
            else {
                nsAutoString idList;
                exprResult->stringValue(idList);
                nsWhitespaceTokenizer tokenizer(idList);
                while (tokenizer.hasMoreTokens()) {
                    if (walker.moveToElementById(tokenizer.nextToken())) {
                        resultSet->add(walker.getCurrentPosition());
                    }
                }
            }

            *aResult = resultSet;
            NS_ADDREF(*aResult);

            return NS_OK;
        }
        case LAST:
        {
            return aContext->recycler()->getNumberResult(aContext->size(),
                                                         aResult);
        }
        case LOCAL_NAME:
        case NAME:
        case NAMESPACE_URI:
        {
            // Check for optional arg
            nsRefPtr<txNodeSet> nodes;
            if (!mParams.IsEmpty()) {
                rv = evaluateToNodeSet(mParams[0], aContext,
                                       getter_AddRefs(nodes));
                NS_ENSURE_SUCCESS(rv, rv);

                if (nodes->isEmpty()) {
                    aContext->recycler()->getEmptyStringResult(aResult);

                    return NS_OK;
                }
            }

            const txXPathNode& node = nodes ? nodes->get(0) :
                                              aContext->getContextNode();
            switch (mType) {
//.........这里部分代码省略.........
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:101,代码来源:txCoreFunctionCall.cpp

示例12: NS_ADDREF

NS_IMETHODIMP
HTMLOutputElement::GetHtmlFor(nsISupports** aResult)
{
  NS_ADDREF(*aResult = HtmlFor());
  return NS_OK;
}
开发者ID:harmattan,项目名称:mozilla-central,代码行数:6,代码来源:HTMLOutputElement.cpp

示例13: NS_ENSURE_SUCCESS

NS_IMETHODIMP
nsXULTemplateQueryProcessorStorage::GetDatasource(nsIArray* aDataSources,
                                                  nsIDOMNode* aRootNode,
                                                  bool aIsTrusted,
                                                  nsIXULTemplateBuilder* aBuilder,
                                                  bool* aShouldDelayBuilding,
                                                  nsISupports** aReturn)
{
    *aReturn = nullptr;
    *aShouldDelayBuilding = false;

    if (!aIsTrusted) {
        return NS_OK;
    }

    uint32_t length;
    nsresult rv = aDataSources->GetLength(&length);
    NS_ENSURE_SUCCESS(rv, rv);

    if (length == 0) {
        return NS_OK;
    }

    // We get only the first uri. This query processor supports
    // only one database at a time.
    nsCOMPtr<nsIURI> uri;
    uri = do_QueryElementAt(aDataSources, 0);

    if (!uri) {
        // No uri in the list of datasources
        return NS_OK;
    }

    nsCOMPtr<mozIStorageService> storage =
        do_GetService("@mozilla.org/storage/service;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIFile> databaseFile;
    nsAutoCString scheme;
    rv = uri->GetScheme(scheme);
    NS_ENSURE_SUCCESS(rv, rv);

    if (scheme.EqualsLiteral("profile")) {

        nsAutoCString path;
        rv = uri->GetPath(path);
        NS_ENSURE_SUCCESS(rv, rv);

        if (path.IsEmpty()) {
            return NS_ERROR_FAILURE;
        }

        rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
                                             getter_AddRefs(databaseFile));
        NS_ENSURE_SUCCESS(rv, rv);

        rv = databaseFile->AppendNative(path);
        NS_ENSURE_SUCCESS(rv, rv);
    }
    else {
        nsCOMPtr<nsIChannel> channel;
        nsCOMPtr<nsINode> node = do_QueryInterface(aRootNode);

        rv = NS_NewChannel(getter_AddRefs(channel),
                           uri,
                           node,
                           nsILoadInfo::SEC_NORMAL,
                           nsIContentPolicy::TYPE_OTHER);
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel, &rv);
        if (NS_FAILED(rv)) { // if it fails, not a file url
            nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_BAD_URI);
            return rv;
        }

        nsCOMPtr<nsIFile> file;
        rv = fileChannel->GetFile(getter_AddRefs(databaseFile));
        NS_ENSURE_SUCCESS(rv, rv);
    }

    // ok now we have an URI of a sqlite file
    nsCOMPtr<mozIStorageConnection> connection;
    rv = storage->OpenDatabase(databaseFile, getter_AddRefs(connection));
    if (NS_FAILED(rv)) {
        nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE);
        return rv;
    }

    NS_ADDREF(*aReturn = connection);
    return NS_OK;
}
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:92,代码来源:nsXULTemplateQueryProcessorStorage.cpp

示例14: GMP_LOG

PChromiumCDMParent* GMPContentParent::AllocPChromiumCDMParent() {
  GMP_LOG("GMPContentParent::AllocPChromiumCDMParent(this=%p)", this);
  ChromiumCDMParent* parent = new ChromiumCDMParent(this, GetPluginId());
  NS_ADDREF(parent);
  return parent;
}
开发者ID:Noctem,项目名称:gecko-dev,代码行数:6,代码来源:GMPContentParent.cpp

示例15: blankDoc

NS_IMETHODIMP
nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup,
                                  nsIPrincipal* aPrincipal,
                                  nsIDocument **aDocument)
{
    NS_TIME_FUNCTION;

    *aDocument = nullptr;

    nsresult rv = NS_ERROR_FAILURE;

    // create a new blank HTML document
    nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));

    if (blankDoc) {
        // initialize
        nsCOMPtr<nsIURI> uri;
        NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
        if (uri) {
            blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
            rv = NS_OK;
        }
    }

    // add some simple content structure
    if (NS_SUCCEEDED(rv)) {
        rv = NS_ERROR_FAILURE;

        nsNodeInfoManager *nim = blankDoc->NodeInfoManager();

        nsCOMPtr<nsINodeInfo> htmlNodeInfo;

        // generate an html html element
        htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_XHTML,
                                        nsIDOMNode::ELEMENT_NODE);
        nsCOMPtr<nsIContent> htmlElement =
            NS_NewHTMLHtmlElement(htmlNodeInfo.forget());

        // generate an html head element
        htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::head, 0, kNameSpaceID_XHTML,
                                        nsIDOMNode::ELEMENT_NODE);
        nsCOMPtr<nsIContent> headElement =
            NS_NewHTMLHeadElement(htmlNodeInfo.forget());

        // generate an html body elemment
        htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::body, 0, kNameSpaceID_XHTML,
                                        nsIDOMNode::ELEMENT_NODE);
        nsCOMPtr<nsIContent> bodyElement =
            NS_NewHTMLBodyElement(htmlNodeInfo.forget());

        // blat in the structure
        if (htmlElement && headElement && bodyElement) {
            NS_ASSERTION(blankDoc->GetChildCount() == 0,
                         "Shouldn't have children");
            rv = blankDoc->AppendChildTo(htmlElement, false);
            if (NS_SUCCEEDED(rv)) {
                rv = htmlElement->AppendChildTo(headElement, false);

                if (NS_SUCCEEDED(rv)) {
                    // XXXbz Why not notifying here?
                    htmlElement->AppendChildTo(bodyElement, false);
                }
            }
        }
    }

    // add a nice bow
    if (NS_SUCCEEDED(rv)) {
        blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
        blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));

        *aDocument = blankDoc;
        NS_ADDREF(*aDocument);
    }
    return rv;
}
开发者ID:houzhenggang,项目名称:ExMail,代码行数:76,代码来源:nsContentDLF.cpp


注:本文中的NS_ADDREF函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。