summaryrefslogtreecommitdiff
path: root/dom/security/nsMixedContentBlocker.h
blob: 539c3ebbb7f009d0bdacf782bc043012acfebe61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 nsMixedContentBlocker_h___
#define nsMixedContentBlocker_h___

#define NS_MIXEDCONTENTBLOCKER_CONTRACTID "@mozilla.org/mixedcontentblocker;1"
/* daf1461b-bf29-4f88-8d0e-4bcdf332c862 */
#define NS_MIXEDCONTENTBLOCKER_CID \
{ 0xdaf1461b, 0xbf29, 0x4f88, \
  { 0x8d, 0x0e, 0x4b, 0xcd, 0xf3, 0x32, 0xc8, 0x62 } }

// This enum defines type of content that is detected when an
// nsMixedContentEvent fires
enum MixedContentTypes {
  // "Active" content, such as fonts, plugin content, JavaScript, stylesheets,
  // iframes, WebSockets, and XHR
  eMixedScript,
  // "Display" content, such as images, audio, video, and <a ping>
  eMixedDisplay
};

#include "nsIContentPolicy.h"
#include "nsIChannel.h"
#include "nsIChannelEventSink.h"
#include "imgRequest.h"

class nsILoadInfo; // forward declaration

class nsMixedContentBlocker : public nsIContentPolicy,
                              public nsIChannelEventSink
{
private:
  virtual ~nsMixedContentBlocker();

public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSICONTENTPOLICY
  NS_DECL_NSICHANNELEVENTSINK

  nsMixedContentBlocker();

  /* Static version of ShouldLoad() that contains all the Mixed Content Blocker
   * logic.  Called from non-static ShouldLoad().
   * Called directly from imageLib when an insecure redirect exists in a cached
   * image load.
   * @param aHadInsecureImageRedirect
   *        boolean flag indicating that an insecure redirect through http
   *        occured when this image was initially loaded and cached.
   * Remaining parameters are from nsIContentPolicy::ShouldLoad().
   */
  static nsresult ShouldLoad(bool aHadInsecureImageRedirect,
                             uint32_t aContentType,
                             nsIURI* aContentLocation,
                             nsIURI* aRequestingLocation,
                             nsISupports* aRequestingContext,
                             const nsACString& aMimeGuess,
                             nsISupports* aExtra,
                             nsIPrincipal* aRequestPrincipal,
                             int16_t* aDecision);
  static void AccumulateMixedContentHSTS(nsIURI* aURI,
                                         bool aActive,
                                         bool aHasHSTSPriming);
  /* If the document associated with aRequestingContext requires priming for
   * aURI, propagate that to the LoadInfo so the HttpChannel will find out about
   * it.
   *
   * @param aURI The URI associated with the load
   * @param aRequestingContext the requesting context passed to ShouldLoad
   * @param aLoadInfo the LoadInfo for the load
   */
  static nsresult MarkLoadInfoForPriming(nsIURI* aURI,
                                         nsISupports* aRequestingContext,
                                         nsILoadInfo* aLoadInfo);

  /* Given a context, return whether HSTS was marked on the document associated
   * with the load for the given URI. This is used by MarkLoadInfoForPriming and
   * directly by the image loader to determine whether to allow a load to occur
   * from the cache.
   *
   * @param aURI The URI associated with the load
   * @param aRequestingContext the requesting context passed to ShouldLoad
   * @param aSendPrimingRequest out true if priming is required on the channel
   * @param aMixedContentWouldBlock out true if mixed content would block
   */
  static nsresult GetHSTSPrimingFromRequestingContext(nsIURI* aURI,
                                                      nsISupports* aRequestingContext,
                                                      bool* aSendPrimingRequest,
                                                      bool* aMixedContentWouldBlock);


  static bool sBlockMixedScript;
  static bool sBlockMixedDisplay;
  // Do we move HSTS before mixed-content
  static bool sUseHSTS;
  // Do we send an HSTS priming request
  static bool sSendHSTSPriming;
  // Default HSTS Priming failure timeout in seconds
  static uint32_t sHSTSPrimingCacheTimeout;
};

#endif /* nsMixedContentBlocker_h___ */