blob: 2ddc8869af841559dc6d9696fa0d70eb913c9136 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]1d89a82f2009-05-14 05:46:242// 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_ERROR_HANDLER_H_
6#define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]1d89a82f2009-05-14 05:46:248
9#include <string>
10
11#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]5edce1e2009-05-14 08:47:3013#include "chrome/browser/ssl/ssl_manager.h"
[email protected]5de634712011-03-02 00:20:1914#include "content/browser/renderer_host/global_request_id.h"
[email protected]1d89a82f2009-05-14 05:46:2415#include "googleurl/src/gurl.h"
16#include "webkit/glue/resource_type.h"
17
[email protected]92b24c12009-12-10 20:04:3518class ResourceDispatcherHost;
[email protected]1d89a82f2009-05-14 05:46:2419class SSLCertErrorHandler;
[email protected]1d89a82f2009-05-14 05:46:2420class TabContents;
[email protected]edfe7fab2010-11-28 13:11:5221
22namespace net {
[email protected]1d89a82f2009-05-14 05:46:2423class URLRequest;
[email protected]edfe7fab2010-11-28 13:11:5224} // namespace net
[email protected]1d89a82f2009-05-14 05:46:2425
26// An SSLErrorHandler carries information from the IO thread to the UI thread
27// and is dispatched to the appropriate SSLManager when it arrives on the
28// UI thread. Subclasses should override the OnDispatched/OnDispatchFailed
29// methods to implement the actions that should be taken on the UI thread.
30// These methods can call the different convenience methods ContinueRequest/
[email protected]6981d9632010-11-30 21:34:0231// CancelRequest to perform any required action on the net::URLRequest the
[email protected]8a58f9a2010-05-18 18:38:0932// ErrorHandler was created with.
[email protected]1d89a82f2009-05-14 05:46:2433//
34// IMPORTANT NOTE:
35//
36// If you are not doing anything in OnDispatched/OnDispatchFailed, make sure
37// you call TakeNoAction(). This is necessary for ensuring the instance is
38// not leaked.
39//
40class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> {
41 public:
[email protected]e4be2dd2010-12-14 00:44:3942 virtual SSLCertErrorHandler* AsSSLCertErrorHandler();
[email protected]1d89a82f2009-05-14 05:46:2443
[email protected]6981d9632010-11-30 21:34:0244 // Find the appropriate SSLManager for the net::URLRequest and begin handling
[email protected]1d89a82f2009-05-14 05:46:2445 // this error.
46 //
47 // Call on UI thread.
48 void Dispatch();
49
50 // Available on either thread.
51 const GURL& request_url() const { return request_url_; }
52
53 // Available on either thread.
54 ResourceType::Type resource_type() const { return resource_type_; }
55
[email protected]1d89a82f2009-05-14 05:46:2456 // Returns the TabContents this object is associated with. Should be
57 // called from the UI thread.
58 TabContents* GetTabContents();
59
[email protected]6981d9632010-11-30 21:34:0260 // Cancels the associated net::URLRequest.
[email protected]1d89a82f2009-05-14 05:46:2461 // This method can be called from OnDispatchFailed and OnDispatched.
62 void CancelRequest();
63
[email protected]6981d9632010-11-30 21:34:0264 // Continue the net::URLRequest ignoring any previous errors. Note that some
[email protected]1d89a82f2009-05-14 05:46:2465 // errors cannot be ignored, in which case this will result in the request
66 // being canceled.
67 // This method can be called from OnDispatchFailed and OnDispatched.
68 void ContinueRequest();
69
[email protected]6981d9632010-11-30 21:34:0270 // Cancels the associated net::URLRequest and mark it as denied. The renderer
[email protected]1d89a82f2009-05-14 05:46:2471 // processes such request in a special manner, optionally replacing them
72 // with alternate content (typically frames content is replaced with a
73 // warning message).
74 // This method can be called from OnDispatchFailed and OnDispatched.
75 void DenyRequest();
76
[email protected]6981d9632010-11-30 21:34:0277 // Does nothing on the net::URLRequest but ensures the current instance ref
[email protected]1d89a82f2009-05-14 05:46:2478 // count is decremented appropriately. Subclasses that do not want to
79 // take any specific actions in their OnDispatched/OnDispatchFailed should
80 // call this.
81 void TakeNoAction();
82
83 protected:
[email protected]e6e6ba42009-11-07 01:56:1984 friend class base::RefCountedThreadSafe<SSLErrorHandler>;
85
[email protected]1d89a82f2009-05-14 05:46:2486 // Construct on the IO thread.
87 SSLErrorHandler(ResourceDispatcherHost* resource_dispatcher_host,
[email protected]edfe7fab2010-11-28 13:11:5288 net::URLRequest* request,
[email protected]7a8c55e2011-02-15 08:21:1689 ResourceType::Type resource_type);
[email protected]1d89a82f2009-05-14 05:46:2490
[email protected]02d08e02010-10-08 17:50:4691 virtual ~SSLErrorHandler();
[email protected]e6e6ba42009-11-07 01:56:1992
[email protected]1d89a82f2009-05-14 05:46:2493 // The following 2 methods are the methods subclasses should implement.
[email protected]02d08e02010-10-08 17:50:4694 virtual void OnDispatchFailed();
[email protected]1d89a82f2009-05-14 05:46:2495
96 // Can use the manager_ member.
[email protected]02d08e02010-10-08 17:50:4697 virtual void OnDispatched();
[email protected]1d89a82f2009-05-14 05:46:2498
[email protected]1d89a82f2009-05-14 05:46:2499 // Should only be accessed on the UI thread.
100 SSLManager* manager_; // Our manager.
101
[email protected]6981d9632010-11-30 21:34:02102 // The id of the net::URLRequest associated with this object.
[email protected]1d89a82f2009-05-14 05:46:24103 // Should only be accessed from the IO thread.
[email protected]92b24c12009-12-10 20:04:35104 GlobalRequestID request_id_;
[email protected]1d89a82f2009-05-14 05:46:24105
106 // The ResourceDispatcherHost we are associated with.
107 ResourceDispatcherHost* resource_dispatcher_host_;
108
109 private:
110 // Completes the CancelRequest operation on the IO thread.
111 // Call on the IO thread.
112 void CompleteCancelRequest(int error);
113
114 // Completes the ContinueRequest operation on the IO thread.
115 //
116 // Call on the IO thread.
117 void CompleteContinueRequest();
118
[email protected]1d89a82f2009-05-14 05:46:24119 // Derefs this instance.
120 // Call on the IO thread.
121 void CompleteTakeNoAction();
122
123 // We use these members to find the correct SSLManager when we arrive on
124 // the UI thread.
125 int render_process_host_id_;
126 int tab_contents_id_;
127
128 // The URL that we requested.
129 // This read-only member can be accessed on any thread.
130 const GURL request_url_;
131
132 // What kind of resource is associated with the requested that generated
133 // that error.
134 // This read-only member can be accessed on any thread.
135 const ResourceType::Type resource_type_;
136
[email protected]6981d9632010-11-30 21:34:02137 // A flag to make sure we notify the net::URLRequest exactly once.
[email protected]1d89a82f2009-05-14 05:46:24138 // Should only be accessed on the IO thread
139 bool request_has_been_notified_;
140
141 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
142};
143
144#endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_