1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_ 6 #define CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_ 7 #pragma once 8 9 #include <string> 10 #include <vector> 11 12 #include "base/string16.h" 13 #include "chrome/browser/ssl/ssl_error_info.h" 14 #include "content/browser/tab_contents/interstitial_page.h" 15 16 class DictionaryValue; 17 class SSLCertErrorHandler; 18 19 // This class is responsible for showing/hiding the interstitial page that is 20 // shown when a certificate error happens. 21 // It deletes itself when the interstitial page is closed. 22 class SSLBlockingPage : public InterstitialPage { 23 public: 24 // An interface that classes that want to interact with the SSLBlockingPage 25 // should implement. 26 class Delegate { 27 public: 28 // Should return the information about the error that causes this blocking 29 // page. 30 virtual SSLErrorInfo GetSSLErrorInfo(SSLCertErrorHandler* handler) = 0; 31 32 // Notification that the user chose to reject the certificate. 33 virtual void OnDenyCertificate(SSLCertErrorHandler* handler) = 0; 34 35 // Notification that the user chose to accept the certificate. 36 virtual void OnAllowCertificate(SSLCertErrorHandler* handler) = 0; 37 38 protected: 39 virtual ~Delegate() {} 40 }; 41 42 // The severity of the certificate error. 43 enum ErrorLevel { 44 ERROR_OVERRIDABLE, // The interstitial page has a "Proceed anyway" button. 45 ERROR_FATAL, // The interstitial page doesn't allow the user to 46 // proceed to the site. 47 }; 48 49 SSLBlockingPage(SSLCertErrorHandler* handler, Delegate* delegate, 50 ErrorLevel error_level); 51 virtual ~SSLBlockingPage(); 52 53 // A method that sets strings in the specified dictionary from the passed 54 // vector so that they can be used to resource the ssl_roadblock.html/ 55 // ssl_error.html files. 56 // Note: there can be up to 5 strings in |extra_info|. 57 static void SetExtraInfo(DictionaryValue* strings, 58 const std::vector<string16>& extra_info); 59 60 protected: 61 // InterstitialPage implementation. 62 virtual std::string GetHTMLContents(); 63 virtual void CommandReceived(const std::string& command); 64 virtual void UpdateEntry(NavigationEntry* entry); 65 virtual void Proceed(); 66 virtual void DontProceed(); 67 68 private: 69 void NotifyDenyCertificate(); 70 void NotifyAllowCertificate(); 71 72 // The error we represent. We will either call CancelRequest() or 73 // ContinueRequest() on this object. 74 scoped_refptr<SSLCertErrorHandler> handler_; 75 76 // Our delegate. It provides useful information, like the title and details 77 // about this error. 78 Delegate* delegate_; 79 80 // A flag to indicate if we've notified |delegate_| of the user's decision. 81 bool delegate_has_been_notified_; 82 83 // Is the certificate error overridable or fatal? 84 ErrorLevel error_level_; 85 86 DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage); 87 }; 88 89 #endif // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_ 90