コード例 #1
0
NS_IMETHODIMP
nsWebBrowserContentPolicy::ShouldProcess(uint32_t aContentType,
                                         nsIURI* aContentLocation,
                                         nsIURI* aRequestingLocation,
                                         nsISupports* aRequestingContext,
                                         const nsACString& aMimeGuess,
                                         nsISupports* aExtra,
                                         nsIPrincipal* aRequestPrincipal,
                                         int16_t* aShouldProcess)
{
  NS_PRECONDITION(aShouldProcess, "Null out param");

  MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType),
             "We should only see external content policy types here.");

  *aShouldProcess = nsIContentPolicy::ACCEPT;

  // Object tags will always open channels with TYPE_OBJECT, but may end up
  // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
  // actual-plugins at the process stage
  if (aContentType != nsIContentPolicy::TYPE_OBJECT) {
    return NS_OK;
  }

  nsIDocShell* shell = NS_CP_GetDocShellFromContext(aRequestingContext);
  if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
    *aShouldProcess = nsIContentPolicy::REJECT_TYPE;
  }

  return NS_OK;
}
コード例 #2
0
NS_IMETHODIMP
nsWebBrowserContentPolicy::ShouldProcess(uint32_t          contentType,
        nsIURI           *contentLocation,
        nsIURI           *requestingLocation,
        nsISupports      *requestingContext,
        const nsACString &mimeGuess,
        nsISupports      *extra,
        nsIPrincipal     *requestPrincipal,
        int16_t          *shouldProcess)
{
    NS_PRECONDITION(shouldProcess, "Null out param");

    *shouldProcess = nsIContentPolicy::ACCEPT;

    // Object tags will always open channels with TYPE_OBJECT, but may end up
    // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
    // actual-plugins at the process stage
    if (contentType != nsIContentPolicy::TYPE_OBJECT) {
        return NS_OK;
    }

    nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
    if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
        *shouldProcess = nsIContentPolicy::REJECT_TYPE;
    }

    return NS_OK;
}
コード例 #3
0
NS_IMETHODIMP
nsContentBlocker::ShouldProcess(uint32_t          aContentType,
                                nsIURI           *aContentLocation,
                                nsIURI           *aRequestingLocation,
                                nsISupports      *aRequestingContext,
                                const nsACString &aMimeGuess,
                                nsISupports      *aExtra,
                                nsIPrincipal     *aRequestPrincipal,
                                int16_t          *aDecision)
{
  // For loads where aRequestingContext is chrome, we should just
  // accept.  Those are most likely toplevel loads in windows, and
  // chrome generally knows what it's doing anyway.
  nsCOMPtr<nsIDocShellTreeItem> item =
    do_QueryInterface(NS_CP_GetDocShellFromContext(aRequestingContext));

  if (item) {
    int32_t type;
    item->GetItemType(&type);
    if (type == nsIDocShellTreeItem::typeChrome) {
      *aDecision = nsIContentPolicy::ACCEPT;
      return NS_OK;
    }
  }

  // For objects, we only check policy in shouldProcess, as the final type isn't
  // determined until the channel is open -- We don't want to block images in
  // object tags because plugins are disallowed.
  // NOTE that this bypasses the aContentLocation checks in ShouldLoad - this is
  // intentional, as aContentLocation may be null for plugins that load by type
  // (e.g. java)
  if (aContentType == nsIContentPolicy::TYPE_OBJECT) {
    *aDecision = nsIContentPolicy::ACCEPT;

    bool shouldLoad, fromPrefs;
    nsresult rv = TestPermission(aContentLocation, aRequestingLocation,
                                 aContentType, &shouldLoad, &fromPrefs);
    NS_ENSURE_SUCCESS(rv, rv);
    if (!shouldLoad) {
      if (fromPrefs) {
        *aDecision = nsIContentPolicy::REJECT_TYPE;
      } else {
        *aDecision = nsIContentPolicy::REJECT_SERVER;
      }
    }
    return NS_OK;
  }
  
  // This isn't a load from chrome or an object tag - Just do a ShouldLoad()
  // check -- we want the same answer here
  return ShouldLoad(aContentType, aContentLocation, aRequestingLocation,
                    aRequestingContext, aMimeGuess, aExtra, aRequestPrincipal,
                    aDecision);
}
コード例 #4
0
NS_IMETHODIMP
nsWebBrowserContentPolicy::ShouldLoad(uint32_t aContentType,
                                      nsIURI* aContentLocation,
                                      nsIURI* aRequestingLocation,
                                      nsISupports* aRequestingContext,
                                      const nsACString& aMimeGuess,
                                      nsISupports* aExtra,
                                      nsIPrincipal* aRequestPrincipal,
                                      int16_t* aShouldLoad)
{
  NS_PRECONDITION(aShouldLoad, "Null out param");

  MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType),
             "We should only see external content policy types here.");

  *aShouldLoad = nsIContentPolicy::ACCEPT;

  nsIDocShell* shell = NS_CP_GetDocShellFromContext(aRequestingContext);
  /* We're going to dereference shell, so make sure it isn't null */
  if (!shell) {
    return NS_OK;
  }

  nsresult rv;
  bool allowed = true;

  switch (aContentType) {
    case nsIContentPolicy::TYPE_SCRIPT:
      rv = shell->GetAllowJavascript(&allowed);
      break;
    case nsIContentPolicy::TYPE_SUBDOCUMENT:
      rv = shell->GetAllowSubframes(&allowed);
      break;
#if 0
    /* XXXtw: commented out in old code; add during conpol phase 2 */
    case nsIContentPolicy::TYPE_REFRESH:
      rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */
      break;
#endif
    case nsIContentPolicy::TYPE_IMAGE:
    case nsIContentPolicy::TYPE_IMAGESET:
      rv = shell->GetAllowImages(&allowed);
      break;
    default:
      return NS_OK;
  }

  if (NS_SUCCEEDED(rv) && !allowed) {
    *aShouldLoad = nsIContentPolicy::REJECT_TYPE;
  }
  return rv;
}
コード例 #5
0
/**
 * helper routine to get the root docshell for the window requesting the load
 */
nsresult nsMsgContentPolicy::GetRootDocShellForContext(nsISupports * aRequestingContext, nsIDocShell ** aDocShell)
{
    NS_ENSURE_ARG_POINTER(aRequestingContext);
    nsresult rv;

    nsIDocShell *shell = NS_CP_GetDocShellFromContext(aRequestingContext);
    nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(do_QueryInterface(shell, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIDocShellTreeItem> rootItem;
    // we want the app docshell, so don't use GetSameTypeRootTreeItem
    rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem));
    NS_ENSURE_SUCCESS(rv, rv);

    return rootItem->QueryInterface(NS_GET_IID(nsIDocShell), (void**) aDocShell);
}
コード例 #6
0
static nsresult
PerformPolicyCheck(PRUint32     contentType,
                   nsISupports *requestingContext,
                   PRInt16     *decision)
{
    NS_PRECONDITION(decision, "Null out param");

    *decision = nsIContentPolicy::ACCEPT;

    nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
    /* We're going to dereference shell, so make sure it isn't null */
    if (!shell)
        return NS_OK;

    nsresult rv;
    bool allowed = true;

    switch (contentType) {
      case nsIContentPolicy::TYPE_OBJECT:
        rv = shell->GetAllowPlugins(&allowed);
        break;
      case nsIContentPolicy::TYPE_SCRIPT:
        rv = shell->GetAllowJavascript(&allowed);
        break;
      case nsIContentPolicy::TYPE_SUBDOCUMENT:
        rv = shell->GetAllowSubframes(&allowed);
        break;
#if 0
      /* XXXtw: commented out in old code; add during conpol phase 2 */
      case nsIContentPolicy::TYPE_REFRESH:
        rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */
        break;
#endif
      case nsIContentPolicy::TYPE_IMAGE:
        rv = shell->GetAllowImages(&allowed);
        break;
      default:
        return NS_OK;
    }

    if (NS_SUCCEEDED(rv) && !allowed) {
        *decision = nsIContentPolicy::REJECT_TYPE;
    }
    return rv;
}