| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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_ERROR_HANDLER_H_ |
| 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/ref_counted.h" |
| 12 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 13 #include "chrome/common/filter_policy.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 #include "webkit/glue/resource_type.h" |
| 16 |
| 17 class MessageLoop; |
| 18 class SSLCertErrorHandler; |
| 19 class SSLManager; |
| 20 class TabContents; |
| 21 class URLRequest; |
| 22 |
| 23 // An SSLErrorHandler carries information from the IO thread to the UI thread |
| 24 // and is dispatched to the appropriate SSLManager when it arrives on the |
| 25 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed |
| 26 // methods to implement the actions that should be taken on the UI thread. |
| 27 // These methods can call the different convenience methods ContinueRequest/ |
| 28 // CancelRequest/StartRequest to perform any required action on the URLRequest |
| 29 // the ErrorHandler was created with. |
| 30 // |
| 31 // IMPORTANT NOTE: |
| 32 // |
| 33 // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure |
| 34 // you call TakeNoAction(). This is necessary for ensuring the instance is |
| 35 // not leaked. |
| 36 // |
| 37 class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { |
| 38 public: |
| 39 virtual ~SSLErrorHandler() { } |
| 40 |
| 41 virtual SSLCertErrorHandler* AsSSLCertErrorHandler() { return NULL; } |
| 42 |
| 43 // Find the appropriate SSLManager for the URLRequest and begin handling |
| 44 // this error. |
| 45 // |
| 46 // Call on UI thread. |
| 47 void Dispatch(); |
| 48 |
| 49 // Available on either thread. |
| 50 const GURL& request_url() const { return request_url_; } |
| 51 |
| 52 // Available on either thread. |
| 53 ResourceType::Type resource_type() const { return resource_type_; } |
| 54 |
| 55 // Available on either thread. |
| 56 const std::string& frame_origin() const { return frame_origin_; } |
| 57 |
| 58 // Available on either thread. |
| 59 const std::string& main_frame_origin() const { return main_frame_origin_; } |
| 60 |
| 61 // Call on the UI thread. |
| 62 SSLManager* manager() const { return manager_; } |
| 63 |
| 64 // Returns the TabContents this object is associated with. Should be |
| 65 // called from the UI thread. |
| 66 TabContents* GetTabContents(); |
| 67 |
| 68 // Cancels the associated URLRequest. |
| 69 // This method can be called from OnDispatchFailed and OnDispatched. |
| 70 void CancelRequest(); |
| 71 |
| 72 // Continue the URLRequest ignoring any previous errors. Note that some |
| 73 // errors cannot be ignored, in which case this will result in the request |
| 74 // being canceled. |
| 75 // This method can be called from OnDispatchFailed and OnDispatched. |
| 76 void ContinueRequest(); |
| 77 |
| 78 // Cancels the associated URLRequest and mark it as denied. The renderer |
| 79 // processes such request in a special manner, optionally replacing them |
| 80 // with alternate content (typically frames content is replaced with a |
| 81 // warning message). |
| 82 // This method can be called from OnDispatchFailed and OnDispatched. |
| 83 void DenyRequest(); |
| 84 |
| 85 // Starts the associated URLRequest. |filter_policy| specifies whether the |
| 86 // ResourceDispatcher should attempt to filter the loaded content in order |
| 87 // to make it secure (ex: images are made slightly transparent and are |
| 88 // stamped). |
| 89 // Should only be called when the URLRequest has not already been started. |
| 90 // This method can be called from OnDispatchFailed and OnDispatched. |
| 91 void StartRequest(FilterPolicy::Type filter_policy); |
| 92 |
| 93 // Does nothing on the URLRequest but ensures the current instance ref |
| 94 // count is decremented appropriately. Subclasses that do not want to |
| 95 // take any specific actions in their OnDispatched/OnDispatchFailed should |
| 96 // call this. |
| 97 void TakeNoAction(); |
| 98 |
| 99 protected: |
| 100 // Construct on the IO thread. |
| 101 SSLErrorHandler(ResourceDispatcherHost* resource_dispatcher_host, |
| 102 URLRequest* request, |
| 103 ResourceType::Type resource_type, |
| 104 const std::string& frame_origin, |
| 105 const std::string& main_frame_origin, |
| 106 MessageLoop* ui_loop); |
| 107 |
| 108 // The following 2 methods are the methods subclasses should implement. |
| 109 virtual void OnDispatchFailed() { TakeNoAction(); } |
| 110 |
| 111 // Can use the manager_ member. |
| 112 virtual void OnDispatched() { TakeNoAction(); } |
| 113 |
| 114 // We cache the message loops to be able to proxy events across the thread |
| 115 // boundaries. |
| 116 MessageLoop* ui_loop_; |
| 117 MessageLoop* io_loop_; |
| 118 |
| 119 // Should only be accessed on the UI thread. |
| 120 SSLManager* manager_; // Our manager. |
| 121 |
| 122 // The id of the URLRequest associated with this object. |
| 123 // Should only be accessed from the IO thread. |
| 124 ResourceDispatcherHost::GlobalRequestID request_id_; |
| 125 |
| 126 // The ResourceDispatcherHost we are associated with. |
| 127 ResourceDispatcherHost* resource_dispatcher_host_; |
| 128 |
| 129 private: |
| 130 // Completes the CancelRequest operation on the IO thread. |
| 131 // Call on the IO thread. |
| 132 void CompleteCancelRequest(int error); |
| 133 |
| 134 // Completes the ContinueRequest operation on the IO thread. |
| 135 // |
| 136 // Call on the IO thread. |
| 137 void CompleteContinueRequest(); |
| 138 |
| 139 // Completes the StartRequest operation on the IO thread. |
| 140 // Call on the IO thread. |
| 141 void CompleteStartRequest(FilterPolicy::Type filter_policy); |
| 142 |
| 143 // Derefs this instance. |
| 144 // Call on the IO thread. |
| 145 void CompleteTakeNoAction(); |
| 146 |
| 147 // We use these members to find the correct SSLManager when we arrive on |
| 148 // the UI thread. |
| 149 int render_process_host_id_; |
| 150 int tab_contents_id_; |
| 151 |
| 152 // The URL that we requested. |
| 153 // This read-only member can be accessed on any thread. |
| 154 const GURL request_url_; |
| 155 |
| 156 // What kind of resource is associated with the requested that generated |
| 157 // that error. |
| 158 // This read-only member can be accessed on any thread. |
| 159 const ResourceType::Type resource_type_; |
| 160 |
| 161 // The origin of the frame associated with this request. |
| 162 // This read-only member can be accessed on any thread. |
| 163 const std::string frame_origin_; |
| 164 |
| 165 // The origin of the main frame associated with this request. |
| 166 // This read-only member can be accessed on any thread. |
| 167 const std::string main_frame_origin_; |
| 168 |
| 169 // A flag to make sure we notify the URLRequest exactly once. |
| 170 // Should only be accessed on the IO thread |
| 171 bool request_has_been_notified_; |
| 172 |
| 173 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 174 }; |
| 175 |
| 176 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |