1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998-2001
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Hubbie Shaw
24 : * Doug Turner <dougt@netscape.com>
25 : * Brian Ryner <bryner@brianryner.com>
26 : * Kai Engert <kaie@netscape.com>
27 : *
28 : * Alternatively, the contents of this file may be used under the terms of
29 : * either the GNU General Public License Version 2 or later (the "GPL"), or
30 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 : * in which case the provisions of the GPL or the LGPL are applicable instead
32 : * of those above. If you wish to allow use of your version of this file only
33 : * under the terms of either the GPL or the LGPL, and not to allow others to
34 : * use your version of this file under the terms of the MPL, indicate your
35 : * decision by deleting the provisions above and replace them with the notice
36 : * and other provisions required by the GPL or the LGPL. If you do not delete
37 : * the provisions above, a recipient may use your version of this file under
38 : * the terms of any one of the MPL, the GPL or the LGPL.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : #ifndef nsSecureBrowserUIImpl_h_
43 : #define nsSecureBrowserUIImpl_h_
44 :
45 : #include "mozilla/ReentrantMonitor.h"
46 : #include "nsCOMPtr.h"
47 : #include "nsXPIDLString.h"
48 : #include "nsString.h"
49 : #include "nsIObserver.h"
50 : #include "nsIDOMElement.h"
51 : #include "nsIDOMWindow.h"
52 : #include "nsIDOMHTMLFormElement.h"
53 : #include "nsIStringBundle.h"
54 : #include "nsISecureBrowserUI.h"
55 : #include "nsIDocShell.h"
56 : #include "nsIWebProgressListener.h"
57 : #include "nsIFormSubmitObserver.h"
58 : #include "nsIURI.h"
59 : #include "nsISecurityEventSink.h"
60 : #include "nsWeakReference.h"
61 : #include "nsISSLStatusProvider.h"
62 : #include "nsIAssociatedContentSecurity.h"
63 : #include "pldhash.h"
64 : #include "nsINetUtil.h"
65 :
66 : class nsISSLStatus;
67 : class nsITransportSecurityInfo;
68 : class nsISecurityWarningDialogs;
69 : class nsIChannel;
70 : class nsIInterfaceRequestor;
71 :
72 : #define NS_SECURE_BROWSER_UI_CID \
73 : { 0xcc75499a, 0x1dd1, 0x11b2, {0x8a, 0x82, 0xca, 0x41, 0x0a, 0xc9, 0x07, 0xb8}}
74 :
75 :
76 : class nsSecureBrowserUIImpl : public nsISecureBrowserUI,
77 : public nsIWebProgressListener,
78 : public nsIFormSubmitObserver,
79 : public nsIObserver,
80 : public nsSupportsWeakReference,
81 : public nsISSLStatusProvider
82 : {
83 : public:
84 :
85 : nsSecureBrowserUIImpl();
86 : virtual ~nsSecureBrowserUIImpl();
87 :
88 : NS_DECL_ISUPPORTS
89 : NS_DECL_NSIWEBPROGRESSLISTENER
90 : NS_DECL_NSISECUREBROWSERUI
91 :
92 : // nsIObserver
93 : NS_DECL_NSIOBSERVER
94 : NS_DECL_NSISSLSTATUSPROVIDER
95 :
96 : NS_IMETHOD Notify(nsIDOMHTMLFormElement* formNode, nsIDOMWindow* window,
97 : nsIURI *actionURL, bool* cancelSubmit);
98 0 : NS_IMETHOD NotifyInvalidSubmit(nsIDOMHTMLFormElement* formNode,
99 0 : nsIArray* invalidElements) { return NS_OK; };
100 :
101 : protected:
102 : mozilla::ReentrantMonitor mReentrantMonitor;
103 :
104 : nsWeakPtr mWindow;
105 : nsCOMPtr<nsINetUtil> mIOService;
106 : nsCOMPtr<nsIStringBundle> mStringBundle;
107 : nsCOMPtr<nsIURI> mCurrentURI;
108 : nsCOMPtr<nsISecurityEventSink> mToplevelEventSink;
109 :
110 : enum lockIconState {
111 : lis_no_security,
112 : lis_broken_security,
113 : lis_mixed_security,
114 : lis_low_security,
115 : lis_high_security
116 : };
117 :
118 : lockIconState mNotifiedSecurityState;
119 : bool mNotifiedToplevelIsEV;
120 :
121 : void ResetStateTracking();
122 : PRUint32 mNewToplevelSecurityState;
123 : bool mNewToplevelIsEV;
124 : bool mNewToplevelSecurityStateKnown;
125 : bool mIsViewSource;
126 :
127 : nsXPIDLString mInfoTooltip;
128 : PRInt32 mDocumentRequestsInProgress;
129 : PRInt32 mSubRequestsHighSecurity;
130 : PRInt32 mSubRequestsLowSecurity;
131 : PRInt32 mSubRequestsBrokenSecurity;
132 : PRInt32 mSubRequestsNoSecurity;
133 : bool mRestoreSubrequests;
134 : #ifdef DEBUG
135 : /* related to mReentrantMonitor */
136 : PRInt32 mOnStateLocationChangeReentranceDetection;
137 : #endif
138 :
139 : static already_AddRefed<nsISupports> ExtractSecurityInfo(nsIRequest* aRequest);
140 : static nsresult MapInternalToExternalState(PRUint32* aState, lockIconState lock, bool ev);
141 : nsresult UpdateSecurityState(nsIRequest* aRequest, bool withNewLocation,
142 : bool withUpdateStatus, bool withUpdateTooltip);
143 : bool UpdateMyFlags(bool &showWarning, lockIconState &warnSecurityState);
144 : nsresult TellTheWorld(bool showWarning,
145 : lockIconState warnSecurityState,
146 : nsIRequest* aRequest);
147 :
148 : nsresult EvaluateAndUpdateSecurityState(nsIRequest* aRequest, nsISupports *info,
149 : bool withNewLocation);
150 : void UpdateSubrequestMembers(nsISupports *securityInfo);
151 :
152 : void ObtainEventSink(nsIChannel *channel,
153 : nsCOMPtr<nsISecurityEventSink> &sink);
154 :
155 : nsCOMPtr<nsISSLStatus> mSSLStatus;
156 : nsCOMPtr<nsISupports> mCurrentToplevelSecurityInfo;
157 :
158 : void GetBundleString(const PRUnichar* name, nsAString &outString);
159 :
160 : nsresult CheckPost(nsIURI *formURI, nsIURI *actionURL, bool *okayToPost);
161 : nsresult IsURLHTTPS(nsIURI* aURL, bool *value);
162 : nsresult IsURLJavaScript(nsIURI* aURL, bool *value);
163 :
164 : bool ConfirmEnteringSecure();
165 : bool ConfirmEnteringWeak();
166 : bool ConfirmLeavingSecure();
167 : bool ConfirmMixedMode();
168 : bool ConfirmPostToInsecure();
169 : bool ConfirmPostToInsecureFromSecure();
170 :
171 : bool GetNSSDialogs(nsCOMPtr<nsISecurityWarningDialogs> & dialogs,
172 : nsCOMPtr<nsIInterfaceRequestor> & window);
173 :
174 : PLDHashTable mTransferringRequests;
175 : };
176 :
177 :
178 : #endif /* nsSecureBrowserUIImpl_h_ */
|