docshell/base/nsDSURIContentListener.h
author Ed Morley <emorley@mozilla.com>
Fri, 28 Feb 2014 15:31:07 +0000
changeset 182275 10992841577e4869f91c328f3ae7bf4aeda9bb8e
parent 153389 f4858cb48e2d3799e31a9771bed84a64aca910fa
child 212259 3b9a7943dce2e73822fc33c3109d03a1d54d3a2b
permissions -rw-r--r--
Backed out changeset 5056b4811257 (bug 976648) for errors during configure; CLOSED TREE

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsDSURIContentListener_h__
#define nsDSURIContentListener_h__

#include "nsCOMPtr.h"
#include "nsIURIContentListener.h"
#include "nsWeakReference.h"

class nsDocShell;
class nsIWebNavigationInfo;
class nsIHttpChannel;
class nsAString;

class nsDSURIContentListener :
    public nsIURIContentListener,
    public nsSupportsWeakReference

{
friend class nsDocShell;
public:
    NS_DECL_THREADSAFE_ISUPPORTS
    NS_DECL_NSIURICONTENTLISTENER

    nsresult Init();

protected:
    nsDSURIContentListener(nsDocShell* aDocShell);
    virtual ~nsDSURIContentListener();

    void DropDocShellreference() {
        mDocShell = nullptr;
    }

    // Determine if X-Frame-Options allows content to be framed
    // as a subdocument
    bool CheckFrameOptions(nsIRequest* request);
    bool CheckOneFrameOptionsPolicy(nsIHttpChannel* httpChannel,
                                    const nsAString& policy);

    enum XFOHeader {
      eDENY,
      eSAMEORIGIN,
      eALLOWFROM
    };

    void ReportXFOViolation(nsIDocShellTreeItem* aTopDocShellItem,
                            nsIURI* aThisURI,
                            XFOHeader aHeader);
protected:
    nsDocShell*                      mDocShell;

    // Store the parent listener in either of these depending on
    // if supports weak references or not. Proper weak refs are
    // preferred and encouraged!
    nsWeakPtr                        mWeakParentContentListener;
    nsIURIContentListener*           mParentContentListener;

    nsCOMPtr<nsIWebNavigationInfo>   mNavInfo;
};

#endif /* nsDSURIContentListener_h__ */