Attachment #287901: first stab for bug #369814

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

(-)a/docshell/base/nsDocShell.cpp (-1 / +19 lines)
Line     Link Here 
 Lines 151-156    Link Here 
151
#include "nsICacheVisitor.h"
151
#include "nsICacheVisitor.h"
152
#include "nsIMultiPartChannel.h"
152
#include "nsIMultiPartChannel.h"
153
#include "nsIWyciwygChannel.h"
153
#include "nsIWyciwygChannel.h"
154
#include "nsIAllowScriptsChannel.h"
154
155
155
// The following are for bug #13871: Prevent frameset spoofing
156
// The following are for bug #13871: Prevent frameset spoofing
156
#include "nsIHTMLDocument.h"
157
#include "nsIHTMLDocument.h"
 Lines 1314-1320   nsDocShell::GetAllowJavascript(PRBool * Link Here 
1314
    NS_ENSURE_ARG_POINTER(aAllowJavascript);
1315
    NS_ENSURE_ARG_POINTER(aAllowJavascript);
1315
1316
1316
    *aAllowJavascript = mAllowJavascript;
1317
    *aAllowJavascript = mAllowJavascript;
1317
    return NS_OK;
1318
1319
    if (!mAllowJavascript) {
1320
        return NS_OK;
1321
    }
1322
1323
    // Disallow javascript when requested by the loading channel.
1324
    nsCOMPtr<nsIChannel> channel;
1325
    GetCurrentDocumentChannel(getter_AddRefs(channel));
1326
    if (!channel) {
1327
        return NS_OK;
1328
    }
1329
1330
    nsCOMPtr<nsIAllowScriptsChannel> allowChannel = do_QueryInterface(channel);
1331
    if (!allowChannel) {
1332
        return NS_OK;
1333
    }
1334
1335
    return allowChannel->GetAllowScripts(aAllowJavascript);
1318
}
1336
}
1319
1337
1320
NS_IMETHODIMP
1338
NS_IMETHODIMP
(-)a/modules/libjar/nsJARChannel.cpp (-4 / +27 lines)
Line     Link Here 
 Lines 222-227   nsJARChannel::nsJARChannel() Link Here 
222
    , mLoadFlags(LOAD_NORMAL)
222
    , mLoadFlags(LOAD_NORMAL)
223
    , mStatus(NS_OK)
223
    , mStatus(NS_OK)
224
    , mIsPending(PR_FALSE)
224
    , mIsPending(PR_FALSE)
225
    , mAllowScripts(PR_FALSE)
225
    , mJarInput(nsnull)
226
    , mJarInput(nsnull)
226
{
227
{
227
#if defined(PR_LOGGING)
228
#if defined(PR_LOGGING)
 Lines 243-255   nsJARChannel::~nsJARChannel() Link Here 
243
    NS_RELEASE(handler); // NULL parameter
244
    NS_RELEASE(handler); // NULL parameter
244
}
245
}
245
246
246
NS_IMPL_ISUPPORTS6(nsJARChannel,
247
NS_IMPL_ISUPPORTS7(nsJARChannel,
247
                   nsIRequest,
248
                   nsIRequest,
248
                   nsIChannel,
249
                   nsIChannel,
249
                   nsIStreamListener,
250
                   nsIStreamListener,
250
                   nsIRequestObserver,
251
                   nsIRequestObserver,
251
                   nsIDownloadObserver,
252
                   nsIDownloadObserver,
252
                   nsIJARChannel)
253
                   nsIJARChannel,
254
                   nsIAllowScriptsChannel)
253
255
254
nsresult 
256
nsresult 
255
nsJARChannel::Init(nsIURI *uri)
257
nsJARChannel::Init(nsIURI *uri)
 Lines 323-328   nsJARChannel::EnsureJarInput(PRBool bloc Link Here 
323
    }
325
    }
324
326
325
    if (mJarFile) {
327
    if (mJarFile) {
328
        mAllowScripts = PR_TRUE;
329
326
        // NOTE: we do not need to deal with mSecurityInfo here,
330
        // NOTE: we do not need to deal with mSecurityInfo here,
327
        // because we're loading from a local file
331
        // because we're loading from a local file
328
        rv = CreateJarInput(gJarHandler->JarCache());
332
        rv = CreateJarInput(gJarHandler->JarCache());
 Lines 691-696   nsJARChannel::AsyncOpen(nsIStreamListene Link Here 
691
}
695
}
692
696
693
//-----------------------------------------------------------------------------
697
//-----------------------------------------------------------------------------
698
// nsIAllowScriptsChannel
699
//-----------------------------------------------------------------------------
700
NS_IMETHODIMP
701
nsJARChannel::GetAllowScripts(PRBool *allowScripts)
702
{
703
    *allowScripts = mAllowScripts;
704
    return PR_TRUE;
705
}
706
707
//-----------------------------------------------------------------------------
694
// nsIDownloadObserver
708
// nsIDownloadObserver
695
//-----------------------------------------------------------------------------
709
//-----------------------------------------------------------------------------
696
710
 Lines 703-711   nsJARChannel::OnDownloadComplete(nsIDown Link Here 
703
{
717
{
704
    // Grab the security info from our base channel
718
    // Grab the security info from our base channel
705
    nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
719
    nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
706
    if (channel)
720
    if (channel) {
721
        nsCAutoString contentType;
722
        channel->GetContentType(contentType);
723
724
        if (contentType == NS_LITERAL_CSTRING("application/java-archive") ||
725
            contentType == NS_LITERAL_CSTRING("application/x-jar")) {
726
            mAllowScripts = PR_TRUE;
727
        }
728
707
        channel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
729
        channel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
708
    
730
    }
731
709
    if (NS_SUCCEEDED(status)) {
732
    if (NS_SUCCEEDED(status)) {
710
        mJarFile = file;
733
        mJarFile = file;
711
    
734
    
(-)a/modules/libjar/nsJARChannel.h (+4 lines)
Line     Link Here 
 Lines 49-54    Link Here 
49
#include "nsILoadGroup.h"
49
#include "nsILoadGroup.h"
50
#include "nsIFile.h"
50
#include "nsIFile.h"
51
#include "nsIURI.h"
51
#include "nsIURI.h"
52
#include "nsIAllowScriptsChannel.h"
52
#include "nsCOMPtr.h"
53
#include "nsCOMPtr.h"
53
#include "nsString.h"
54
#include "nsString.h"
54
#include "prlog.h"
55
#include "prlog.h"
 Lines 60-65   class nsJARChannel : public nsIJARChanne Link Here 
60
class nsJARChannel : public nsIJARChannel
61
class nsJARChannel : public nsIJARChannel
61
                   , public nsIDownloadObserver
62
                   , public nsIDownloadObserver
62
                   , public nsIStreamListener
63
                   , public nsIStreamListener
64
                   , public nsIAllowScriptsChannel
63
{
65
{
64
public:
66
public:
65
    NS_DECL_ISUPPORTS
67
    NS_DECL_ISUPPORTS
 Lines 69-74   public: Link Here 
69
    NS_DECL_NSIDOWNLOADOBSERVER
71
    NS_DECL_NSIDOWNLOADOBSERVER
70
    NS_DECL_NSIREQUESTOBSERVER
72
    NS_DECL_NSIREQUESTOBSERVER
71
    NS_DECL_NSISTREAMLISTENER
73
    NS_DECL_NSISTREAMLISTENER
74
    NS_DECL_NSIALLOWSCRIPTSCHANNEL
72
75
73
    nsJARChannel();
76
    nsJARChannel();
74
    virtual ~nsJARChannel();
77
    virtual ~nsJARChannel();
 Lines 98-103   private: Link Here 
98
    PRUint32                        mLoadFlags;
101
    PRUint32                        mLoadFlags;
99
    nsresult                        mStatus;
102
    nsresult                        mStatus;
100
    PRBool                          mIsPending;
103
    PRBool                          mIsPending;
104
    PRBool                          mAllowScripts;
101
105
102
    nsJARInputThunk                *mJarInput;
106
    nsJARInputThunk                *mJarInput;
103
    nsCOMPtr<nsIStreamListener>     mDownloader;
107
    nsCOMPtr<nsIStreamListener>     mDownloader;
(-)a/netwerk/base/public/Makefile.in (+1 lines)
Line     Link Here 
 Lines 61-66   SDK_XPIDLSRCS = \ Link Here 
61
		$(NULL)
61
		$(NULL)
62
62
63
XPIDLSRCS	= \
63
XPIDLSRCS	= \
64
		nsIAllowScriptsChannel.idl \
64
		nsIAuthInformation.idl \
65
		nsIAuthInformation.idl \
65
		nsIAuthPrompt.idl \
66
		nsIAuthPrompt.idl \
66
		nsIAuthPrompt2.idl \
67
		nsIAuthPrompt2.idl \
(-)a/netwerk/base/public/nsIAllowScriptsChannel.idl (+44 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is mozilla.org code.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * Mozilla Corporation.
19
 * Portions created by the Initial Developer are Copyright (C) 2007
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#include "nsISupports.idl"
39
40
[scriptable, uuid(b8b50310-a009-4fca-b575-38a5f46c5463)]
41
interface nsIAllowScriptsChannel : nsISupports
42
{
43
    readonly attribute boolean allowScripts;
44
};

Return to bug 369814