Attachment #8409830: part_1_backend_stubs_v2.patch for bug #951457

View | Details | Raw Unified | Return to bug 951457
Collapse All | Expand All

(-)a/content/base/public/nsIContentSecurityPolicy.idl (-5 / +11 lines)
Line     Link Here 
 Lines 1-48    Link Here 
1
/* This Source Code Form is subject to the terms of the Mozilla Public
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
#include "nsISerializable.idl"
5
#include "nsISerializable.idl"
6
#include "nsIContentPolicy.idl"
6
7
7
interface nsIURI;
8
interface nsIURI;
8
interface nsIChannel;
9
interface nsIChannel;
9
interface nsIDocShell;
10
interface nsIDocShell;
10
interface nsIPrincipal;
11
interface nsIPrincipal;
11
12
12
/**
13
/**
13
 * nsIContentSecurityPolicy
14
 * nsIContentSecurityPolicy
14
 * Describes an XPCOM component used to model and enforce CSPs.  Instances of
15
 * Describes an XPCOM component used to model and enforce CSPs.  Instances of
15
 * this class may have multiple policies within them, but there should only be
16
 * this class may have multiple policies within them, but there should only be
16
 * one of these per document/principal.
17
 * one of these per document/principal.
17
 */
18
 */
18
19
19
[scriptable, uuid(8b91f829-b1bf-4327-8ece-4000aa823394)]
20
[scriptable, uuid(1ae83090-e1e1-4272-b0c4-0fbd751c1e27)]
20
interface nsIContentSecurityPolicy : nsISerializable
21
interface nsIContentSecurityPolicy : nsISerializable
21
{
22
{
22
23
23
  /**
24
  /**
24
   * Set to true when the CSP has been read in and parsed and is ready to
25
   * Set to true when the CSP has been read in and parsed and is ready to
25
   * enforce.  This is a barrier for the nsDocument so it doesn't load any
26
   * enforce.  This is a barrier for the nsDocument so it doesn't load any
26
   * sub-content until either it knows that a CSP is ready or will not be used.
27
   * sub-content until either it knows that a CSP is ready or will not be used.
27
   */
28
   */
28
  attribute boolean isInitialized;
29
  readonly attribute boolean isInitialized;
29
30
30
  /**
31
  /**
31
   * Accessor method for a read-only string version of the policy at a given
32
   * Accessor method for a read-only string version of the policy at a given
32
   * index.
33
   * index.
33
   */
34
   */
34
  AString getPolicy(in unsigned long index);
35
  AString getPolicy(in unsigned long index);
35
36
36
  /**
37
  /**
37
   * Returns the number of policies attached to this CSP instance.  Useful with
38
   * Returns the number of policies attached to this CSP instance.  Useful with
38
   * getPolicy().
39
   * getPolicy().
39
   */
40
   */
40
  attribute long policyCount;
41
  readonly attribute unsigned long policyCount;
41
42
42
  /**
43
  /**
43
   * Remove a policy associated with this CSP context.
44
   * Remove a policy associated with this CSP context.
44
   * @throws NS_ERROR_FAILURE if the index is out of bounds or invalid.
45
   * @throws NS_ERROR_FAILURE if the index is out of bounds or invalid.
45
   */
46
   */
46
  void removePolicy(in unsigned long index);
47
  void removePolicy(in unsigned long index);
47
48
48
  /**
49
  /**
 Lines 212-239   interface nsIContentSecurityPolicy : nsI Link Here 
212
  /**
213
  /**
213
   * Delegate method called by the service when sub-elements of the protected
214
   * Delegate method called by the service when sub-elements of the protected
214
   * document are being loaded.  Given a bit of information about the request,
215
   * document are being loaded.  Given a bit of information about the request,
215
   * decides whether or not the policy is satisfied.
216
   * decides whether or not the policy is satisfied.
216
   *
217
   *
217
   * Calls to this may trigger violation reports when queried, so
218
   * Calls to this may trigger violation reports when queried, so
218
   * this value should not be cached.
219
   * this value should not be cached.
219
   */
220
   */
220
  short shouldLoad(in unsigned long   aContentType,
221
  short shouldLoad(in nsContentPolicyType aContentType,
221
                   in nsIURI          aContentLocation,
222
                   in nsIURI          aContentLocation,
222
                   in nsIURI          aRequestOrigin,
223
                   in nsIURI          aRequestOrigin,
223
                   in nsISupports     aContext,
224
                   in nsISupports     aContext,
224
                   in ACString        aMimeTypeGuess,
225
                   in ACString        aMimeTypeGuess,
225
                   in nsISupports     aExtra);
226
                   in nsISupports     aExtra);
226
227
227
  /**
228
  /**
228
   * Delegate method called by the service when sub-elements of the protected
229
   * Delegate method called by the service when sub-elements of the protected
229
   * document are being processed.  Given a bit of information about the request,
230
   * document are being processed.  Given a bit of information about the request,
230
   * decides whether or not the policy is satisfied.
231
   * decides whether or not the policy is satisfied.
231
   */
232
   */
232
  short shouldProcess(in unsigned long   aContentType,
233
  short shouldProcess(in nsContentPolicyType   aContentType,
233
                      in nsIURI          aContentLocation,
234
                      in nsIURI          aContentLocation,
234
                      in nsIURI          aRequestOrigin,
235
                      in nsIURI          aRequestOrigin,
235
                      in nsISupports     aContext,
236
                      in nsISupports     aContext,
236
                      in ACString        aMimeType,
237
                      in ACString        aMimeType,
237
                      in nsISupports     aExtra);
238
                      in nsISupports     aExtra);
238
239
240
%{ C++
241
// nsIObserver topic to fire when the policy encounters a violation.
242
#define CSP_VIOLATION_TOPIC "csp-on-violate-policy"
243
%}
244
239
};
245
};
(-)a/content/base/src/moz.build (+1 lines)
Line     Link Here 
 Lines 104-119   UNIFIED_SOURCES += [ Link Here 
104
    'nsChannelPolicy.cpp',
104
    'nsChannelPolicy.cpp',
105
    'nsContentAreaDragDrop.cpp',
105
    'nsContentAreaDragDrop.cpp',
106
    'nsContentIterator.cpp',
106
    'nsContentIterator.cpp',
107
    'nsContentList.cpp',
107
    'nsContentList.cpp',
108
    'nsContentPolicy.cpp',
108
    'nsContentPolicy.cpp',
109
    'nsContentSink.cpp',
109
    'nsContentSink.cpp',
110
    'nsCopySupport.cpp',
110
    'nsCopySupport.cpp',
111
    'nsCrossSiteListenerProxy.cpp',
111
    'nsCrossSiteListenerProxy.cpp',
112
    'nsCSPContext.cpp',
112
    'nsCSPParser.cpp',
113
    'nsCSPParser.cpp',
113
    'nsCSPService.cpp',
114
    'nsCSPService.cpp',
114
    'nsCSPUtils.cpp',
115
    'nsCSPUtils.cpp',
115
    'nsDataDocumentContentPolicy.cpp',
116
    'nsDataDocumentContentPolicy.cpp',
116
    'nsDocumentEncoder.cpp',
117
    'nsDocumentEncoder.cpp',
117
    'nsDOMAttributeMap.cpp',
118
    'nsDOMAttributeMap.cpp',
118
    'nsDOMBlobBuilder.cpp',
119
    'nsDOMBlobBuilder.cpp',
119
    'nsDOMCaretPosition.cpp',
120
    'nsDOMCaretPosition.cpp',
(-)a/content/base/src/nsCSPContext.cpp (+206 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "mozilla/Preferences.h"
7
#include "nsAsyncRedirectVerifyHelper.h"
8
#include "nsChannelProperties.h"
9
#include "nsCOMPtr.h"
10
#include "nsContentPolicyUtils.h"
11
#include "nsContentUtils.h"
12
#include "nsCSPContext.h"
13
#include "nsCSPParser.h"
14
#include "nsCSPService.h"
15
#include "nsError.h"
16
#include "nsIAsyncVerifyRedirectCallback.h"
17
#include "nsIChannelEventSink.h"
18
#include "nsIChannelPolicy.h"
19
#include "nsIDocShell.h"
20
#include "nsIDocShellTreeItem.h"
21
#include "nsIHttpChannel.h"
22
#include "nsIInterfaceRequestorUtils.h"
23
#include "nsIObserver.h"
24
#include "nsIObserverService.h"
25
#include "nsIPrincipal.h"
26
#include "nsIPropertyBag2.h"
27
#include "nsIScriptError.h"
28
#include "nsIWritablePropertyBag2.h"
29
#include "nsString.h"
30
#include "prlog.h"
31
32
using namespace mozilla;
33
34
/* =====  nsIContentSecurityPolicy impl ====== */
35
36
NS_IMETHODIMP
37
nsCSPContext::ShouldLoad(nsContentPolicyType aContentType,
38
                         nsIURI*             aContentLocation,
39
                         nsIURI*             aRequestOrigin,
40
                         nsISupports*        aRequestContext,
41
                         const nsACString&   aMimeTypeGuess,
42
                         nsISupports*        aExtra,
43
                         int16_t*            outDecision)
44
{
45
  *outDecision = nsIContentPolicy::ACCEPT;
46
  return NS_OK;
47
}
48
49
NS_IMETHODIMP
50
nsCSPContext::ShouldProcess(nsContentPolicyType aContentType,
51
                            nsIURI*             aContentLocation,
52
                            nsIURI*             aRequestOrigin,
53
                            nsISupports*        aRequestContext,
54
                            const nsACString&   aMimeType,
55
                            nsISupports*        aExtra,
56
                            int16_t*            outDecision)
57
{
58
  *outDecision = nsIContentPolicy::ACCEPT;
59
  return NS_OK;
60
}
61
62
/* ===== nsISupports implementation ========== */
63
64
NS_IMPL_ISUPPORTS2(nsCSPContext,
65
                   nsIContentSecurityPolicy,
66
                   nsISerializable)
67
68
nsCSPContext::nsCSPContext()
69
{
70
}
71
72
nsCSPContext::~nsCSPContext()
73
{
74
  for (uint32_t i = 0; i < mPolicies.Length(); i++) {
75
    if (mPolicies[i]) {
76
      delete mPolicies[i];
77
    }
78
  }
79
}
80
81
NS_IMETHODIMP
82
nsCSPContext::GetIsInitialized(bool *outIsInitialized)
83
{
84
  return NS_ERROR_NOT_IMPLEMENTED;
85
}
86
87
NS_IMETHODIMP
88
nsCSPContext::GetPolicy(uint32_t aIndex, nsAString& outStr)
89
{
90
  if (aIndex >= mPolicies.Length()) {
91
    return NS_ERROR_FAILURE;
92
  }
93
  mPolicies[aIndex]->toString(outStr);
94
  return NS_OK;
95
}
96
97
NS_IMETHODIMP
98
nsCSPContext::GetPolicyCount(uint32_t *outPolicyCount)
99
{
100
  *outPolicyCount = mPolicies.Length();
101
  return NS_OK;
102
}
103
104
NS_IMETHODIMP
105
nsCSPContext::RemovePolicy(uint32_t aIndex)
106
{
107
  if (aIndex >= mPolicies.Length()) {
108
    return NS_ERROR_ILLEGAL_VALUE;
109
  }
110
  mPolicies.RemoveElementAt(aIndex);
111
  return NS_OK;
112
}
113
114
NS_IMETHODIMP
115
nsCSPContext::AppendPolicy(const nsAString& aPolicyString,
116
                           nsIURI* aSelfURI,
117
                           bool aReportOnly,
118
                           bool aSpecCompliant)
119
{
120
  NS_ASSERTION(aSelfURI, "aSelfURI required for AppendPolicy");
121
  nsCSPPolicy* policy = nsCSPParser::parseContentSecurityPolicy(aPolicyString, aSelfURI, aReportOnly, 0);
122
  if (policy) {
123
    mPolicies.AppendElement(policy);
124
  }
125
  return NS_OK;
126
}
127
128
NS_IMETHODIMP
129
nsCSPContext::GetAllowsInlineScript(bool* outShouldReportViolations,
130
                                    bool* outAllowsInlineScript)
131
{
132
  return NS_ERROR_NOT_IMPLEMENTED;
133
}
134
135
NS_IMETHODIMP
136
nsCSPContext::GetAllowsEval(bool* outShouldReportViolations,
137
                            bool* outAllowsEval)
138
{
139
  return NS_ERROR_NOT_IMPLEMENTED;
140
}
141
142
NS_IMETHODIMP
143
nsCSPContext::GetAllowsInlineStyle(bool* outShouldReportViolations,
144
                                   bool* outAllowsInlineStyle)
145
{
146
  return NS_ERROR_NOT_IMPLEMENTED;
147
}
148
149
NS_IMETHODIMP
150
nsCSPContext::GetAllowsNonce(const nsAString& aNonce,
151
                             uint32_t aContentType,
152
                             bool* outShouldReportViolation,
153
                             bool* outAllowsNonce)
154
{
155
  return NS_ERROR_NOT_IMPLEMENTED;
156
}
157
158
NS_IMETHODIMP
159
nsCSPContext::GetAllowsHash(const nsAString& aContent,
160
                            uint16_t aContentType,
161
                            bool* outShouldReportViolation,
162
                            bool* outAllowsHash)
163
{
164
  return NS_ERROR_NOT_IMPLEMENTED;
165
}
166
167
NS_IMETHODIMP
168
nsCSPContext::LogViolationDetails(uint16_t aViolationType,
169
                                  const nsAString& aSourceFile,
170
                                  const nsAString& aScriptSample,
171
                                  int32_t aLineNum,
172
                                  const nsAString& aNonce,
173
                                  const nsAString& aContent)
174
{
175
  return NS_ERROR_NOT_IMPLEMENTED;
176
}
177
178
NS_IMETHODIMP
179
nsCSPContext::SetRequestContext(nsIURI* aSelfURI,
180
                                nsIURI* aReferrer,
181
                                nsIPrincipal* aDocumentPrincipal,
182
                                nsIChannel* aChannel)
183
{
184
  return NS_ERROR_NOT_IMPLEMENTED;
185
}
186
187
NS_IMETHODIMP
188
nsCSPContext::PermitsAncestry(nsIDocShell* aDocShell, bool* outPermitsAncestry)
189
{
190
  // For now, we allows permitsAncestry, this will be fixed in Bug 994320
191
  *outPermitsAncestry = true;
192
  return NS_OK;
193
}
194
195
/* ===== nsISerializable implementation ====== */
196
NS_IMETHODIMP
197
nsCSPContext::Read(nsIObjectInputStream* aStream)
198
{
199
  return NS_ERROR_NOT_IMPLEMENTED;
200
}
201
202
NS_IMETHODIMP
203
nsCSPContext::Write(nsIObjectOutputStream* aStream)
204
{
205
  return NS_ERROR_NOT_IMPLEMENTED;
206
}
(-)a/content/base/src/nsCSPContext.h (+39 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef nsCSPContext_h___
7
#define nsCSPContext_h___
8
9
#include "nsCSPUtils.h"
10
#include "nsIChannel.h"
11
#include "nsIContentSecurityPolicy.h"
12
#include "nsISerializable.h"
13
#include "nsXPCOM.h"
14
15
class nsIObjectInputStream;
16
class nsIObjectOutputStream;
17
18
#define NS_CSPCONTEXT_CONTRACTID "@mozilla.org/cspcontext;1"
19
 // 09d9ed1a-e5d4-4004-bfe0-27ceb923d9ac
20
#define NS_CSPCONTEXT_CID \
21
{ 0x09d9ed1a, 0xe5d4, 0x4004, \
22
  { 0xbf, 0xe0, 0x27, 0xce, 0xb9, 0x23, 0xd9, 0xac } }
23
24
class nsCSPContext : public nsIContentSecurityPolicy
25
{
26
  public:
27
    NS_DECL_ISUPPORTS
28
    NS_DECL_NSICONTENTSECURITYPOLICY
29
    NS_DECL_NSISERIALIZABLE
30
31
    nsCSPContext();
32
    virtual ~nsCSPContext();
33
34
  private:
35
    nsTArray<nsCSPPolicy*> mPolicies;
36
    nsCOMPtr<nsIURI>       mSelfURI;
37
};
38
39
#endif /* nsCSPContext_h___ */
(-)a/content/base/src/nsCSPService.cpp (-4 / +6 lines)
Line     Link Here 
 Lines 23-46    Link Here 
23
#include "mozilla/Preferences.h"
23
#include "mozilla/Preferences.h"
24
#include "nsIScriptError.h"
24
#include "nsIScriptError.h"
25
#include "nsContentUtils.h"
25
#include "nsContentUtils.h"
26
26
27
using namespace mozilla;
27
using namespace mozilla;
28
28
29
/* Keeps track of whether or not CSP is enabled */
29
/* Keeps track of whether or not CSP is enabled */
30
bool CSPService::sCSPEnabled = true;
30
bool CSPService::sCSPEnabled = true;
31
bool CSPService::sNewBackendEnabled = true;
31
32
32
#ifdef PR_LOGGING
33
#ifdef PR_LOGGING
33
static PRLogModuleInfo* gCspPRLog;
34
static PRLogModuleInfo* gCspPRLog;
34
#endif
35
#endif
35
36
36
CSPService::CSPService()
37
CSPService::CSPService()
37
{
38
{
38
  Preferences::AddBoolVarCache(&sCSPEnabled, "security.csp.enable");
39
  Preferences::AddBoolVarCache(&sCSPEnabled, "security.csp.enable");
40
  Preferences::AddBoolVarCache(&sNewBackendEnabled, "security.csp.newbackend.enable");
39
41
40
#ifdef PR_LOGGING
42
#ifdef PR_LOGGING
41
  if (!gCspPRLog)
43
  if (!gCspPRLog)
42
    gCspPRLog = PR_NewLogModule("CSP");
44
    gCspPRLog = PR_NewLogModule("CSP");
43
#endif
45
#endif
44
}
46
}
45
47
46
CSPService::~CSPService()
48
CSPService::~CSPService()
 Lines 162-181   CSPService::ShouldLoad(uint32_t aContent Link Here 
162
  nsCOMPtr<nsIContentSecurityPolicy> csp;
164
  nsCOMPtr<nsIContentSecurityPolicy> csp;
163
  if (node) {
165
  if (node) {
164
    principal = node->NodePrincipal();
166
    principal = node->NodePrincipal();
165
    principal->GetCsp(getter_AddRefs(csp));
167
    principal->GetCsp(getter_AddRefs(csp));
166
168
167
    if (csp) {
169
    if (csp) {
168
#ifdef PR_LOGGING
170
#ifdef PR_LOGGING
169
      {
171
      {
170
        int numPolicies = 0;
172
        uint32_t numPolicies = 0;
171
        nsresult rv = csp->GetPolicyCount(&numPolicies);
173
        nsresult rv = csp->GetPolicyCount(&numPolicies);
172
        if (NS_SUCCEEDED(rv)) {
174
        if (NS_SUCCEEDED(rv)) {
173
          for (int i=0; i<numPolicies; i++) {
175
          for (uint32_t i=0; i<numPolicies; i++) {
174
            nsAutoString policy;
176
            nsAutoString policy;
175
            csp->GetPolicy(i, policy);
177
            csp->GetPolicy(i, policy);
176
            PR_LOG(gCspPRLog, PR_LOG_DEBUG,
178
            PR_LOG(gCspPRLog, PR_LOG_DEBUG,
177
                   ("Document has CSP[%d]: %s", i,
179
                   ("Document has CSP[%d]: %s", i,
178
                   NS_ConvertUTF16toUTF8(policy).get()));
180
                   NS_ConvertUTF16toUTF8(policy).get()));
179
          }
181
          }
180
        }
182
        }
181
      }
183
      }
 Lines 230-249   CSPService::ShouldProcess(uint32_t Link Here 
230
  nsCOMPtr<nsIContentSecurityPolicy> csp;
232
  nsCOMPtr<nsIContentSecurityPolicy> csp;
231
  if (node) {
233
  if (node) {
232
    principal = node->NodePrincipal();
234
    principal = node->NodePrincipal();
233
    principal->GetCsp(getter_AddRefs(csp));
235
    principal->GetCsp(getter_AddRefs(csp));
234
236
235
    if (csp) {
237
    if (csp) {
236
#ifdef PR_LOGGING
238
#ifdef PR_LOGGING
237
      {
239
      {
238
        int numPolicies = 0;
240
        uint32_t numPolicies = 0;
239
        nsresult rv = csp->GetPolicyCount(&numPolicies);
241
        nsresult rv = csp->GetPolicyCount(&numPolicies);
240
        if (NS_SUCCEEDED(rv)) {
242
        if (NS_SUCCEEDED(rv)) {
241
          for (int i=0; i<numPolicies; i++) {
243
          for (uint32_t i=0; i<numPolicies; i++) {
242
            nsAutoString policy;
244
            nsAutoString policy;
243
            csp->GetPolicy(i, policy);
245
            csp->GetPolicy(i, policy);
244
            PR_LOG(gCspPRLog, PR_LOG_DEBUG,
246
            PR_LOG(gCspPRLog, PR_LOG_DEBUG,
245
                   ("shouldProcess - document has policy[%d]: %s", i,
247
                   ("shouldProcess - document has policy[%d]: %s", i,
246
                   NS_ConvertUTF16toUTF8(policy).get()));
248
                   NS_ConvertUTF16toUTF8(policy).get()));
247
          }
249
          }
248
        }
250
        }
249
      }
251
      }
(-)a/content/base/src/nsCSPService.h (+5 lines)
Line     Link Here 
 Lines 1-13    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
5
6
#ifndef nsCSPService_h___
7
#define nsCSPService_h___
8
6
#include "nsXPCOM.h"
9
#include "nsXPCOM.h"
7
#include "nsIContentPolicy.h"
10
#include "nsIContentPolicy.h"
8
#include "nsIChannel.h"
11
#include "nsIChannel.h"
9
#include "nsIChannelEventSink.h"
12
#include "nsIChannelEventSink.h"
10
13
11
#define CSPSERVICE_CONTRACTID "@mozilla.org/cspservice;1"
14
#define CSPSERVICE_CONTRACTID "@mozilla.org/cspservice;1"
12
#define CSPSERVICE_CID \
15
#define CSPSERVICE_CID \
13
  { 0x8d2f40b2, 0x4875, 0x4c95, \
16
  { 0x8d2f40b2, 0x4875, 0x4c95, \
 Lines 18-29   class CSPService : public nsIContentPoli Link Here 
18
public:
21
public:
19
  NS_DECL_ISUPPORTS
22
  NS_DECL_ISUPPORTS
20
  NS_DECL_NSICONTENTPOLICY
23
  NS_DECL_NSICONTENTPOLICY
21
  NS_DECL_NSICHANNELEVENTSINK
24
  NS_DECL_NSICHANNELEVENTSINK
22
25
23
  CSPService();
26
  CSPService();
24
  virtual ~CSPService();
27
  virtual ~CSPService();
25
  static bool sCSPEnabled;
28
  static bool sCSPEnabled;
29
  static bool sNewBackendEnabled;
26
private:
30
private:
27
  // Maps origins to app status.
31
  // Maps origins to app status.
28
  nsDataHashtable<nsCStringHashKey, uint16_t> mAppStatusCache;
32
  nsDataHashtable<nsCStringHashKey, uint16_t> mAppStatusCache;
29
};
33
};
34
#endif /* nsCSPService_h___ */
(-)a/content/base/src/nsDocument.cpp (-2 / +20 lines)
Line     Link Here 
 Lines 2788-2805   nsDocument::InitCSP(nsIChannel* aChannel Link Here 
2788
           "This document is sharing principal with another document.",
2788
           "This document is sharing principal with another document.",
2789
           "Since the document is an app, CSP was already set.",
2789
           "Since the document is an app, CSP was already set.",
2790
           "Skipping attempt to set CSP."));
2790
           "Skipping attempt to set CSP."));
2791
#endif
2791
#endif
2792
      return NS_OK;
2792
      return NS_OK;
2793
    }
2793
    }
2794
  }
2794
  }
2795
2795
2796
  // create new CSP object
2796
  // Create new CSP object - if we're using the new CSP implementation and backend,
2797
  csp = do_CreateInstance("@mozilla.org/contentsecuritypolicy;1", &rv);
2797
  // use the new contract ID (same interface, but use C++ implementation).
2798
  if (CSPService::sNewBackendEnabled) {
2799
    if (oldHeaderIsPresent && !newHeaderIsPresent) {
2800
      // New CSP implementation doesn't support old header!  ABORT CSP INIT!
2801
      // (Not a problem if newHeaderIsPresent because the old header will be
2802
      // ignored).  This check will get removed when x- header support is
2803
      // removed (see bug 949533)
2804
#ifdef PR_LOGGING
2805
      PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("%s %s %s",
2806
           "This document has an old, x-content-security-policy",
2807
           "header and the new parser doesn't support the non-standard",
2808
           "CSP.  Skipping CSP initialization."));
2809
#endif
2810
      return NS_OK;
2811
    }
2812
    csp = do_CreateInstance("@mozilla.org/cspcontext;1", &rv);
2813
  } else {
2814
    csp = do_CreateInstance("@mozilla.org/contentsecuritypolicy;1", &rv);
2815
  }
2798
2816
2799
  if (NS_FAILED(rv)) {
2817
  if (NS_FAILED(rv)) {
2800
#ifdef PR_LOGGING
2818
#ifdef PR_LOGGING
2801
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("Failed to create CSP object: %x", rv));
2819
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("Failed to create CSP object: %x", rv));
2802
#endif
2820
#endif
2803
    return rv;
2821
    return rv;
2804
  }
2822
  }
2805
2823
(-)a/layout/build/nsLayoutModule.cpp (+5 lines)
Line     Link Here 
 Lines 210-225   NS_NewXULTreeBuilder(nsISupports* aOuter Link Here 
210
static void Shutdown();
210
static void Shutdown();
211
211
212
#include "nsGeolocation.h"
212
#include "nsGeolocation.h"
213
#include "nsDeviceSensors.h"
213
#include "nsDeviceSensors.h"
214
#ifdef MOZ_GAMEPAD
214
#ifdef MOZ_GAMEPAD
215
#include "mozilla/dom/GamepadService.h"
215
#include "mozilla/dom/GamepadService.h"
216
#endif
216
#endif
217
#include "nsCSPService.h"
217
#include "nsCSPService.h"
218
#include "nsCSPContext.h"
218
#include "nsISmsService.h"
219
#include "nsISmsService.h"
219
#include "nsIMmsService.h"
220
#include "nsIMmsService.h"
220
#include "nsIMobileMessageService.h"
221
#include "nsIMobileMessageService.h"
221
#include "nsIMobileMessageDatabaseService.h"
222
#include "nsIMobileMessageDatabaseService.h"
222
#include "mozilla/dom/mobilemessage/MobileMessageService.h"
223
#include "mozilla/dom/mobilemessage/MobileMessageService.h"
223
#include "mozilla/dom/mobilemessage/SmsServicesFactory.h"
224
#include "mozilla/dom/mobilemessage/SmsServicesFactory.h"
224
#include "nsIPowerManagerService.h"
225
#include "nsIPowerManagerService.h"
225
#include "nsIAlarmHalService.h"
226
#include "nsIAlarmHalService.h"
 Lines 583-598   NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(Geol Link Here 
583
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsGeolocationService, nsGeolocationService::GetGeolocationService)
584
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsGeolocationService, nsGeolocationService::GetGeolocationService)
584
585
585
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AudioChannelService, AudioChannelService::GetAudioChannelService)
586
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AudioChannelService, AudioChannelService::GetAudioChannelService)
586
587
587
#ifdef MOZ_WEBSPEECH
588
#ifdef MOZ_WEBSPEECH
588
NS_GENERIC_FACTORY_CONSTRUCTOR(FakeSpeechRecognitionService)
589
NS_GENERIC_FACTORY_CONSTRUCTOR(FakeSpeechRecognitionService)
589
#endif
590
#endif
590
591
592
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCSPContext)
591
NS_GENERIC_FACTORY_CONSTRUCTOR(CSPService)
593
NS_GENERIC_FACTORY_CONSTRUCTOR(CSPService)
592
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMixedContentBlocker)
594
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMixedContentBlocker)
593
595
594
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrincipal)
596
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrincipal)
595
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet)
597
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet)
596
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal,
598
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal,
597
    nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
599
    nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
598
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNullPrincipal, Init)
600
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNullPrincipal, Init)
 Lines 727-742   NS_DEFINE_NAMED_CID(NS_EDITINGCONTROLLER Link Here 
727
NS_DEFINE_NAMED_CID(NS_EDITORCOMMANDTABLE_CID);
729
NS_DEFINE_NAMED_CID(NS_EDITORCOMMANDTABLE_CID);
728
NS_DEFINE_NAMED_CID(NS_EDITINGCOMMANDTABLE_CID);
730
NS_DEFINE_NAMED_CID(NS_EDITINGCOMMANDTABLE_CID);
729
NS_DEFINE_NAMED_CID(NS_TEXTSERVICESDOCUMENT_CID);
731
NS_DEFINE_NAMED_CID(NS_TEXTSERVICESDOCUMENT_CID);
730
NS_DEFINE_NAMED_CID(NS_GEOLOCATION_SERVICE_CID);
732
NS_DEFINE_NAMED_CID(NS_GEOLOCATION_SERVICE_CID);
731
NS_DEFINE_NAMED_CID(NS_GEOLOCATION_CID);
733
NS_DEFINE_NAMED_CID(NS_GEOLOCATION_CID);
732
NS_DEFINE_NAMED_CID(NS_AUDIOCHANNEL_SERVICE_CID);
734
NS_DEFINE_NAMED_CID(NS_AUDIOCHANNEL_SERVICE_CID);
733
NS_DEFINE_NAMED_CID(NS_FOCUSMANAGER_CID);
735
NS_DEFINE_NAMED_CID(NS_FOCUSMANAGER_CID);
734
NS_DEFINE_NAMED_CID(CSPSERVICE_CID);
736
NS_DEFINE_NAMED_CID(CSPSERVICE_CID);
737
NS_DEFINE_NAMED_CID(NS_CSPCONTEXT_CID);
735
NS_DEFINE_NAMED_CID(NS_MIXEDCONTENTBLOCKER_CID);
738
NS_DEFINE_NAMED_CID(NS_MIXEDCONTENTBLOCKER_CID);
736
NS_DEFINE_NAMED_CID(NS_EVENTLISTENERSERVICE_CID);
739
NS_DEFINE_NAMED_CID(NS_EVENTLISTENERSERVICE_CID);
737
NS_DEFINE_NAMED_CID(NS_GLOBALMESSAGEMANAGER_CID);
740
NS_DEFINE_NAMED_CID(NS_GLOBALMESSAGEMANAGER_CID);
738
NS_DEFINE_NAMED_CID(NS_PARENTPROCESSMESSAGEMANAGER_CID);
741
NS_DEFINE_NAMED_CID(NS_PARENTPROCESSMESSAGEMANAGER_CID);
739
NS_DEFINE_NAMED_CID(NS_CHILDPROCESSMESSAGEMANAGER_CID);
742
NS_DEFINE_NAMED_CID(NS_CHILDPROCESSMESSAGEMANAGER_CID);
740
NS_DEFINE_NAMED_CID(NSCHANNELPOLICY_CID);
743
NS_DEFINE_NAMED_CID(NSCHANNELPOLICY_CID);
741
NS_DEFINE_NAMED_CID(NS_SCRIPTSECURITYMANAGER_CID);
744
NS_DEFINE_NAMED_CID(NS_SCRIPTSECURITYMANAGER_CID);
742
NS_DEFINE_NAMED_CID(NS_PRINCIPAL_CID);
745
NS_DEFINE_NAMED_CID(NS_PRINCIPAL_CID);
 Lines 1016-1031   static const mozilla::Module::CIDEntry k Link Here 
1016
  { &kNS_GEOLOCATION_CID, false, nullptr, GeolocationConstructor },
1019
  { &kNS_GEOLOCATION_CID, false, nullptr, GeolocationConstructor },
1017
  { &kNS_AUDIOCHANNEL_SERVICE_CID, false, nullptr, AudioChannelServiceConstructor },
1020
  { &kNS_AUDIOCHANNEL_SERVICE_CID, false, nullptr, AudioChannelServiceConstructor },
1018
  { &kNS_FOCUSMANAGER_CID, false, nullptr, CreateFocusManager },
1021
  { &kNS_FOCUSMANAGER_CID, false, nullptr, CreateFocusManager },
1019
#ifdef MOZ_WEBSPEECH
1022
#ifdef MOZ_WEBSPEECH
1020
  { &kNS_FAKE_SPEECH_RECOGNITION_SERVICE_CID, false, nullptr, FakeSpeechRecognitionServiceConstructor },
1023
  { &kNS_FAKE_SPEECH_RECOGNITION_SERVICE_CID, false, nullptr, FakeSpeechRecognitionServiceConstructor },
1021
  { &kNS_SYNTHVOICEREGISTRY_CID, true, nullptr, nsSynthVoiceRegistryConstructor },
1024
  { &kNS_SYNTHVOICEREGISTRY_CID, true, nullptr, nsSynthVoiceRegistryConstructor },
1022
#endif
1025
#endif
1023
  { &kCSPSERVICE_CID, false, nullptr, CSPServiceConstructor },
1026
  { &kCSPSERVICE_CID, false, nullptr, CSPServiceConstructor },
1027
  { &kNS_CSPCONTEXT_CID, false, nullptr, nsCSPContextConstructor },
1024
  { &kNS_MIXEDCONTENTBLOCKER_CID, false, nullptr, nsMixedContentBlockerConstructor },
1028
  { &kNS_MIXEDCONTENTBLOCKER_CID, false, nullptr, nsMixedContentBlockerConstructor },
1025
  { &kNS_EVENTLISTENERSERVICE_CID, false, nullptr, CreateEventListenerService },
1029
  { &kNS_EVENTLISTENERSERVICE_CID, false, nullptr, CreateEventListenerService },
1026
  { &kNS_GLOBALMESSAGEMANAGER_CID, false, nullptr, CreateGlobalMessageManager },
1030
  { &kNS_GLOBALMESSAGEMANAGER_CID, false, nullptr, CreateGlobalMessageManager },
1027
  { &kNS_PARENTPROCESSMESSAGEMANAGER_CID, false, nullptr, CreateParentMessageManager },
1031
  { &kNS_PARENTPROCESSMESSAGEMANAGER_CID, false, nullptr, CreateParentMessageManager },
1028
  { &kNS_CHILDPROCESSMESSAGEMANAGER_CID, false, nullptr, CreateChildMessageManager },
1032
  { &kNS_CHILDPROCESSMESSAGEMANAGER_CID, false, nullptr, CreateChildMessageManager },
1029
  { &kNSCHANNELPOLICY_CID, false, nullptr, nsChannelPolicyConstructor },
1033
  { &kNSCHANNELPOLICY_CID, false, nullptr, nsChannelPolicyConstructor },
1030
  { &kNS_SCRIPTSECURITYMANAGER_CID, false, nullptr, Construct_nsIScriptSecurityManager },
1034
  { &kNS_SCRIPTSECURITYMANAGER_CID, false, nullptr, Construct_nsIScriptSecurityManager },
1031
  { &kNS_PRINCIPAL_CID, false, nullptr, nsPrincipalConstructor },
1035
  { &kNS_PRINCIPAL_CID, false, nullptr, nsPrincipalConstructor },
 Lines 1169-1184   static const mozilla::Module::ContractID Link Here 
1169
  { "@mozilla.org/geolocation;1", &kNS_GEOLOCATION_CID },
1173
  { "@mozilla.org/geolocation;1", &kNS_GEOLOCATION_CID },
1170
  { "@mozilla.org/audiochannel/service;1", &kNS_AUDIOCHANNEL_SERVICE_CID },
1174
  { "@mozilla.org/audiochannel/service;1", &kNS_AUDIOCHANNEL_SERVICE_CID },
1171
  { "@mozilla.org/focus-manager;1", &kNS_FOCUSMANAGER_CID },
1175
  { "@mozilla.org/focus-manager;1", &kNS_FOCUSMANAGER_CID },
1172
#ifdef MOZ_WEBSPEECH
1176
#ifdef MOZ_WEBSPEECH
1173
  { NS_SPEECH_RECOGNITION_SERVICE_CONTRACTID_PREFIX "fake", &kNS_FAKE_SPEECH_RECOGNITION_SERVICE_CID },
1177
  { NS_SPEECH_RECOGNITION_SERVICE_CONTRACTID_PREFIX "fake", &kNS_FAKE_SPEECH_RECOGNITION_SERVICE_CID },
1174
  { NS_SYNTHVOICEREGISTRY_CONTRACTID, &kNS_SYNTHVOICEREGISTRY_CID },
1178
  { NS_SYNTHVOICEREGISTRY_CONTRACTID, &kNS_SYNTHVOICEREGISTRY_CID },
1175
#endif
1179
#endif
1176
  { CSPSERVICE_CONTRACTID, &kCSPSERVICE_CID },
1180
  { CSPSERVICE_CONTRACTID, &kCSPSERVICE_CID },
1181
  { NS_CSPCONTEXT_CONTRACTID, &kNS_CSPCONTEXT_CID },
1177
  { NS_MIXEDCONTENTBLOCKER_CONTRACTID, &kNS_MIXEDCONTENTBLOCKER_CID },
1182
  { NS_MIXEDCONTENTBLOCKER_CONTRACTID, &kNS_MIXEDCONTENTBLOCKER_CID },
1178
  { NS_EVENTLISTENERSERVICE_CONTRACTID, &kNS_EVENTLISTENERSERVICE_CID },
1183
  { NS_EVENTLISTENERSERVICE_CONTRACTID, &kNS_EVENTLISTENERSERVICE_CID },
1179
  { NS_GLOBALMESSAGEMANAGER_CONTRACTID, &kNS_GLOBALMESSAGEMANAGER_CID },
1184
  { NS_GLOBALMESSAGEMANAGER_CONTRACTID, &kNS_GLOBALMESSAGEMANAGER_CID },
1180
  { NS_PARENTPROCESSMESSAGEMANAGER_CONTRACTID, &kNS_PARENTPROCESSMESSAGEMANAGER_CID },
1185
  { NS_PARENTPROCESSMESSAGEMANAGER_CONTRACTID, &kNS_PARENTPROCESSMESSAGEMANAGER_CID },
1181
  { NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID, &kNS_CHILDPROCESSMESSAGEMANAGER_CID },
1186
  { NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID, &kNS_CHILDPROCESSMESSAGEMANAGER_CID },
1182
  { NSCHANNELPOLICY_CONTRACTID, &kNSCHANNELPOLICY_CID },
1187
  { NSCHANNELPOLICY_CONTRACTID, &kNSCHANNELPOLICY_CID },
1183
  { NS_SCRIPTSECURITYMANAGER_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
1188
  { NS_SCRIPTSECURITYMANAGER_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
1184
  { NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
1189
  { NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
(-)a/modules/libpref/src/init/all.js (+1 lines)
Line     Link Here 
 Lines 1539-1554   pref("security.checkloaduri", true); Link Here 
1539
pref("security.xpconnect.plugin.unrestricted", true);
1539
pref("security.xpconnect.plugin.unrestricted", true);
1540
// security-sensitive dialogs should delay button enabling. In milliseconds.
1540
// security-sensitive dialogs should delay button enabling. In milliseconds.
1541
pref("security.dialog_enable_delay", 1000);
1541
pref("security.dialog_enable_delay", 1000);
1542
pref("security.notification_enable_delay", 500);
1542
pref("security.notification_enable_delay", 500);
1543
1543
1544
pref("security.csp.enable", true);
1544
pref("security.csp.enable", true);
1545
pref("security.csp.debug", false);
1545
pref("security.csp.debug", false);
1546
pref("security.csp.experimentalEnabled", false);
1546
pref("security.csp.experimentalEnabled", false);
1547
pref("security.csp.newbackend.enable", true);
1547
1548
1548
// Mixed content blocking
1549
// Mixed content blocking
1549
pref("security.mixed_content.block_active_content", false);
1550
pref("security.mixed_content.block_active_content", false);
1550
pref("security.mixed_content.block_display_content", false);
1551
pref("security.mixed_content.block_display_content", false);
1551
1552
1552
// Modifier key prefs: default to Windows settings,
1553
// Modifier key prefs: default to Windows settings,
1553
// menu access key = alt, accelerator key = control.
1554
// menu access key = alt, accelerator key = control.
1554
// Use 17 for Ctrl, 18 for Alt, 224 for Meta, 91 for Win, 0 for none. Mac settings in macprefs.js
1555
// Use 17 for Ctrl, 18 for Alt, 224 for Meta, 91 for Win, 0 for none. Mac settings in macprefs.js

Return to bug 951457