ssl_blocking_page.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
13842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// Copyright (c) 2012 The Chromium Authors. All rights reserved. 23842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// Use of this source code is governed by a BSD-style license that can be 33842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// found in the LICENSE file. 43842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 53842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#ifndef CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_ 63842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_ 73842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 83842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include <string> 93842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include <vector> 103842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 113842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "base/callback.h" 123842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "base/strings/string16.h" 133842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "base/time/time.h" 143842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "chrome/browser/history/history_service.h" 153842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "content/public/browser/interstitial_page_delegate.h" 163842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "net/ssl/ssl_info.h" 173842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "url/gurl.h" 183842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 193842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitznamespace base { 203842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzclass DictionaryValue; 213842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz} 223842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 233842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitznamespace content { 243842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzclass InterstitialPage; 253842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzclass WebContents; 263842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz} 273842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 283842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// This class is responsible for showing/hiding the interstitial page that is 293842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// shown when a certificate error happens. 303842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// It deletes itself when the interstitial page is closed. 313842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// 323842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// This class should only be used on the UI thread because its implementation 333842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// uses captive_portal::CaptivePortalService which can only be accessed on the 343842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz// UI thread. 357d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferrisclass SSLBlockingPage : public content::InterstitialPageDelegate, 367d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris public content::NotificationObserver { 377d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris public: 383842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // These represent the commands sent from the interstitial JavaScript. They 393842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // are defined in chrome/browser/resources/ssl/ssl_errors_common.js. 40ffc474b8c8972200642acaef3e5aa10ee853609aZachary T Welch // DO NOT reorder or change these without also changing the JavaScript! 413842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz enum SSLBlockingPageCommands { 425f38f35d5d6c78aafa6da20845d9ceff74af00f8Lassi Tuura CMD_DONT_PROCEED = 0, 435f38f35d5d6c78aafa6da20845d9ceff74af00f8Lassi Tuura CMD_PROCEED = 1, 445f38f35d5d6c78aafa6da20845d9ceff74af00f8Lassi Tuura CMD_MORE = 2, 455f38f35d5d6c78aafa6da20845d9ceff74af00f8Lassi Tuura CMD_RELOAD = 3, 465f38f35d5d6c78aafa6da20845d9ceff74af00f8Lassi Tuura CMD_HELP = 4 475f38f35d5d6c78aafa6da20845d9ceff74af00f8Lassi Tuura }; 483842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 493842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz SSLBlockingPage( 503842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz content::WebContents* web_contents, 513842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz int cert_error, 523842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz const net::SSLInfo& ssl_info, 533842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz const GURL& request_url, 543842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool overridable, 553842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool strict_enforcement, 563842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz const base::Callback<void(bool)>& callback); 573842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz virtual ~SSLBlockingPage(); 583842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 593842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // A method that sets strings in the specified dictionary from the passed 603842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // vector so that they can be used to resource the ssl_roadblock.html/ 613842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // ssl_error.html files. 627d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris // Note: there can be up to 5 strings in |extra_info|. 637d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris static void SetExtraInfo(base::DictionaryValue* strings, 647d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris const std::vector<base::string16>& extra_info); 653842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 663842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz protected: 673842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // InterstitialPageDelegate implementation. 683842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz virtual std::string GetHTMLContents() OVERRIDE; 693842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz virtual void CommandReceived(const std::string& command) OVERRIDE; 7036511d3d1f040bbf778094e907725ad0617326c8Ken Werner virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE; 7136511d3d1f040bbf778094e907725ad0617326c8Ken Werner virtual void OverrideRendererPrefs( 7236511d3d1f040bbf778094e907725ad0617326c8Ken Werner content::RendererPreferences* prefs) OVERRIDE; 7336511d3d1f040bbf778094e907725ad0617326c8Ken Werner virtual void OnProceed() OVERRIDE; 7436511d3d1f040bbf778094e907725ad0617326c8Ken Werner virtual void OnDontProceed() OVERRIDE; 7536511d3d1f040bbf778094e907725ad0617326c8Ken Werner 7636511d3d1f040bbf778094e907725ad0617326c8Ken Werner private: 7736511d3d1f040bbf778094e907725ad0617326c8Ken Werner void NotifyDenyCertificate(); 7836511d3d1f040bbf778094e907725ad0617326c8Ken Werner void NotifyAllowCertificate(); 793842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 8036511d3d1f040bbf778094e907725ad0617326c8Ken Werner // These fetch the appropriate HTML page, depending on the 8136511d3d1f040bbf778094e907725ad0617326c8Ken Werner // SSLInterstitialVersion Finch trial. 823842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz std::string GetHTMLContentsV1(); 833842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz std::string GetHTMLContentsV2(); 843842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 853842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // Used to query the HistoryService to see if the URL is in history. For UMA. 863842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz void OnGotHistoryCount(HistoryService::Handle handle, 873842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool success, 883842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz int num_visits, 893842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz base::Time first_visit); 903842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 913842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // content::NotificationObserver: 923842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz virtual void Observe( 933842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz int type, 943842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz const content::NotificationSource& source, 953842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz const content::NotificationDetails& details) OVERRIDE; 963842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 973842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz base::Callback<void(bool)> callback_; 983842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 993842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz content::WebContents* web_contents_; 100f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris int cert_error_; 101f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris const net::SSLInfo ssl_info_; 102f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris GURL request_url_; 1033842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // Could the user successfully override the error? 104f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris bool overridable_; 105f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris // Has the site requested strict enforcement of certificate errors? 1063842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool strict_enforcement_; 107f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris content::InterstitialPage* interstitial_page_; // Owns us. 1083842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // Is the hostname for an internal network? 1093842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool internal_; 1103842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // How many times is this same URL in history? 1113842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz int num_visits_; 1123842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // Used for getting num_visits_. 113f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris CancelableRequestConsumer request_consumer_; 114f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris // Is captive portal detection enabled? 115f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris bool captive_portal_detection_enabled_; 1163842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // Did the probe complete before the interstitial was closed? 117f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris bool captive_portal_probe_completed_; 118f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris // Did the captive portal probe receive an error or get a non-HTTP response? 1193842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool captive_portal_no_response_; 120f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris // Was a captive portal detected? 1213842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz bool captive_portal_detected_; 1223842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 1233842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz // For the FieldTrial: this contains the name of the condition. 1243842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz std::string trialCondition_; 1253842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 126f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris content::NotificationRegistrar registrar_; 1273842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz 1283842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage); 129f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris}; 130f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris 131f622936d6c5239b3d5ccafdf38189cec8bca55c0Christopher Ferris#endif // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_ 1323842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz