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


C++ PrincipalInfo::get_ContentPrincipalInfo方法代码示例

本文整理汇总了C++中PrincipalInfo::get_ContentPrincipalInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ PrincipalInfo::get_ContentPrincipalInfo方法的具体用法?C++ PrincipalInfo::get_ContentPrincipalInfo怎么用?C++ PrincipalInfo::get_ContentPrincipalInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PrincipalInfo的用法示例。


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

示例1: mService

BroadcastChannelParent::BroadcastChannelParent(
                                            const PrincipalInfo& aPrincipalInfo,
                                            const nsACString& aOrigin,
                                            const nsAString& aChannel,
                                            bool aPrivateBrowsing)
  : mService(BroadcastChannelService::GetOrCreate())
  , mOrigin(aOrigin)
  , mChannel(aChannel)
  , mAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID)
  , mIsInBrowserElement(false)
  , mPrivateBrowsing(aPrivateBrowsing)
{
  AssertIsOnBackgroundThread();
  mService->RegisterActor(this);

  if (aPrincipalInfo.type() ==PrincipalInfo::TContentPrincipalInfo) {
    const ContentPrincipalInfo& info =
      aPrincipalInfo.get_ContentPrincipalInfo();
    mAppId = info.appId();
    mIsInBrowserElement = info.isInBrowserElement();
  }
}
开发者ID:haasn,项目名称:gecko-dev,代码行数:22,代码来源:BroadcastChannelParent.cpp

示例2: switch

already_AddRefed<nsIPrincipal>
PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
                         nsresult* aOptionalResult)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);

  nsresult stackResult;
  nsresult& rv = aOptionalResult ? *aOptionalResult : stackResult;

  nsCOMPtr<nsIScriptSecurityManager> secMan =
    do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return nullptr;
  }

  nsCOMPtr<nsIPrincipal> principal;

  switch (aPrincipalInfo.type()) {
    case PrincipalInfo::TSystemPrincipalInfo: {
      rv = secMan->GetSystemPrincipal(getter_AddRefs(principal));
      if (NS_WARN_IF(NS_FAILED(rv))) {
        return nullptr;
      }

      return principal.forget();
    }

    case PrincipalInfo::TNullPrincipalInfo: {
      const NullPrincipalInfo& info =
        aPrincipalInfo.get_NullPrincipalInfo();
      principal = nsNullPrincipal::Create(info.attrs());

      return principal.forget();
    }

    case PrincipalInfo::TContentPrincipalInfo: {
      const ContentPrincipalInfo& info =
        aPrincipalInfo.get_ContentPrincipalInfo();

      nsCOMPtr<nsIURI> uri;
      rv = NS_NewURI(getter_AddRefs(uri), info.spec());
      if (NS_WARN_IF(NS_FAILED(rv))) {
        return nullptr;
      }

      PrincipalOriginAttributes attrs;
      if (info.attrs().mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
        attrs = info.attrs();
      }
      principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
      rv = principal ? NS_OK : NS_ERROR_FAILURE;
      if (NS_WARN_IF(NS_FAILED(rv))) {
        return nullptr;
      }

      return principal.forget();
    }

    case PrincipalInfo::TExpandedPrincipalInfo: {
      const ExpandedPrincipalInfo& info = aPrincipalInfo.get_ExpandedPrincipalInfo();

      nsTArray<nsCOMPtr<nsIPrincipal>> whitelist;
      nsCOMPtr<nsIPrincipal> wlPrincipal;

      for (uint32_t i = 0; i < info.whitelist().Length(); i++) {
        wlPrincipal = PrincipalInfoToPrincipal(info.whitelist()[i], &rv);
        if (NS_WARN_IF(NS_FAILED(rv))) {
          return nullptr;
        }
        // append that principal to the whitelist
        whitelist.AppendElement(wlPrincipal);
      }

      RefPtr<nsExpandedPrincipal> expandedPrincipal = new nsExpandedPrincipal(whitelist, info.attrs());
      if (!expandedPrincipal) {
        NS_WARNING("could not instantiate expanded principal");
        return nullptr;
      }

      principal = expandedPrincipal;
      return principal.forget();
    }

    default:
      MOZ_CRASH("Unknown PrincipalInfo type!");
  }

  MOZ_CRASH("Should never get here!");
}
开发者ID:cliqz-oss,项目名称:browser-f,代码行数:90,代码来源:BackgroundUtils.cpp


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