Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: chrome/browser/download/download_request_limiter.h

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 16
17 class DownloadRequestInfoBarDelegate; 17 class DownloadRequestInfoBarDelegate;
18 class NavigationController;
19 class TabContents; 18 class TabContents;
20 class TabContentsWrapper; 19 class TabContentsWrapper;
21 20
22 namespace content { 21 namespace content {
22 class NavigationController;
23 class WebContents; 23 class WebContents;
24 } 24 }
25 25
26 // DownloadRequestLimiter is responsible for determining whether a download 26 // DownloadRequestLimiter is responsible for determining whether a download
27 // should be allowed or not. It is designed to keep pages from downloading 27 // should be allowed or not. It is designed to keep pages from downloading
28 // multiple files without user interaction. DownloadRequestLimiter is invoked 28 // multiple files without user interaction. DownloadRequestLimiter is invoked
29 // from ResourceDispatcherHost any time a download begins 29 // from ResourceDispatcherHost any time a download begins
30 // (CanDownloadOnIOThread). The request is processed on the UI thread, and the 30 // (CanDownloadOnIOThread). The request is processed on the UI thread, and the
31 // request is notified (back on the IO thread) as to whether the download should 31 // request is notified (back on the IO thread) as to whether the download should
32 // be allowed or denied. 32 // be allowed or denied.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // DownloadRequestLimiter::Remove) as necessary. 75 // DownloadRequestLimiter::Remove) as necessary.
76 class TabDownloadState : public content::NotificationObserver { 76 class TabDownloadState : public content::NotificationObserver {
77 public: 77 public:
78 // Creates a new TabDownloadState. |controller| is the controller the 78 // Creates a new TabDownloadState. |controller| is the controller the
79 // TabDownloadState tracks the state of and is the host for any dialogs that 79 // TabDownloadState tracks the state of and is the host for any dialogs that
80 // are displayed. |originating_controller| is used to determine the host of 80 // are displayed. |originating_controller| is used to determine the host of
81 // the initial download. If |originating_controller| is null, |controller| 81 // the initial download. If |originating_controller| is null, |controller|
82 // is used. |originating_controller| is typically null, but differs from 82 // is used. |originating_controller| is typically null, but differs from
83 // |controller| in the case of a constrained popup requesting the download. 83 // |controller| in the case of a constrained popup requesting the download.
84 TabDownloadState(DownloadRequestLimiter* host, 84 TabDownloadState(DownloadRequestLimiter* host,
85 NavigationController* controller, 85 content::NavigationController* controller,
86 NavigationController* originating_controller); 86 content::NavigationController* originating_controller);
87 virtual ~TabDownloadState(); 87 virtual ~TabDownloadState();
88 88
89 // Status of the download. 89 // Status of the download.
90 void set_download_status(DownloadRequestLimiter::DownloadStatus status) { 90 void set_download_status(DownloadRequestLimiter::DownloadStatus status) {
91 status_ = status; 91 status_ = status;
92 } 92 }
93 DownloadRequestLimiter::DownloadStatus download_status() const { 93 DownloadRequestLimiter::DownloadStatus download_status() const {
94 return status_; 94 return status_;
95 } 95 }
96 96
(...skipping 12 matching lines...) Expand all
109 // Asks the user if they really want to allow the download. 109 // Asks the user if they really want to allow the download.
110 // See description above CanDownloadOnIOThread for details on lifetime of 110 // See description above CanDownloadOnIOThread for details on lifetime of
111 // callback. 111 // callback.
112 void PromptUserForDownload(TabContents* tab, 112 void PromptUserForDownload(TabContents* tab,
113 DownloadRequestLimiter::Callback* callback); 113 DownloadRequestLimiter::Callback* callback);
114 114
115 // Are we showing a prompt to the user? 115 // Are we showing a prompt to the user?
116 bool is_showing_prompt() const { return (infobar_ != NULL); } 116 bool is_showing_prompt() const { return (infobar_ != NULL); }
117 117
118 // NavigationController we're tracking. 118 // NavigationController we're tracking.
119 NavigationController* controller() const { return controller_; } 119 content::NavigationController* controller() const { return controller_; }
120 120
121 // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and 121 // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and
122 // changes the status appropriately. Virtual for testing. 122 // changes the status appropriately. Virtual for testing.
123 virtual void Cancel(); 123 virtual void Cancel();
124 virtual void Accept(); 124 virtual void Accept();
125 125
126 protected: 126 protected:
127 // Used for testing. 127 // Used for testing.
128 TabDownloadState() 128 TabDownloadState()
129 : host_(NULL), 129 : host_(NULL),
130 controller_(NULL), 130 controller_(NULL),
131 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), 131 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD),
132 download_count_(0), 132 download_count_(0),
133 infobar_(NULL) { 133 infobar_(NULL) {
134 } 134 }
135 135
136 private: 136 private:
137 // content::NotificationObserver method. 137 // content::NotificationObserver method.
138 virtual void Observe(int type, 138 virtual void Observe(int type,
139 const content::NotificationSource& source, 139 const content::NotificationSource& source,
140 const content::NotificationDetails& details) OVERRIDE; 140 const content::NotificationDetails& details) OVERRIDE;
141 141
142 // Notifies the callbacks as to whether the download is allowed or not. 142 // Notifies the callbacks as to whether the download is allowed or not.
143 // Updates status_ appropriately. 143 // Updates status_ appropriately.
144 void NotifyCallbacks(bool allow); 144 void NotifyCallbacks(bool allow);
145 145
146 DownloadRequestLimiter* host_; 146 DownloadRequestLimiter* host_;
147 147
148 NavigationController* controller_; 148 content::NavigationController* controller_;
149 149
150 // Host of the first page the download started on. This may be empty. 150 // Host of the first page the download started on. This may be empty.
151 std::string initial_page_host_; 151 std::string initial_page_host_;
152 152
153 DownloadRequestLimiter::DownloadStatus status_; 153 DownloadRequestLimiter::DownloadStatus status_;
154 154
155 size_t download_count_; 155 size_t download_count_;
156 156
157 // Callbacks we need to notify. This is only non-empty if we're showing a 157 // Callbacks we need to notify. This is only non-empty if we're showing a
158 // dialog. 158 // dialog.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 static void SetTestingDelegate(TestingDelegate* delegate); 208 static void SetTestingDelegate(TestingDelegate* delegate);
209 209
210 // Gets the download state for the specified controller. If the 210 // Gets the download state for the specified controller. If the
211 // TabDownloadState does not exist and |create| is true, one is created. 211 // TabDownloadState does not exist and |create| is true, one is created.
212 // See TabDownloadState's constructor description for details on the two 212 // See TabDownloadState's constructor description for details on the two
213 // controllers. 213 // controllers.
214 // 214 //
215 // The returned TabDownloadState is owned by the DownloadRequestLimiter and 215 // The returned TabDownloadState is owned by the DownloadRequestLimiter and
216 // deleted when no longer needed (the Remove method is invoked). 216 // deleted when no longer needed (the Remove method is invoked).
217 TabDownloadState* GetDownloadState( 217 TabDownloadState* GetDownloadState(
218 NavigationController* controller, 218 content::NavigationController* controller,
219 NavigationController* originating_controller, 219 content::NavigationController* originating_controller,
220 bool create); 220 bool create);
221 221
222 // CanDownloadOnIOThread invokes this on the UI thread. This determines the 222 // CanDownloadOnIOThread invokes this on the UI thread. This determines the
223 // tab and invokes CanDownloadImpl. 223 // tab and invokes CanDownloadImpl.
224 void CanDownload(int render_process_host_id, 224 void CanDownload(int render_process_host_id,
225 int render_view_id, 225 int render_view_id,
226 int request_id, 226 int request_id,
227 Callback* callback); 227 Callback* callback);
228 228
229 // Does the work of updating the download status on the UI thread and 229 // Does the work of updating the download status on the UI thread and
(...skipping 11 matching lines...) Expand all
241 241
242 // Removes the specified TabDownloadState from the internal map and deletes 242 // Removes the specified TabDownloadState from the internal map and deletes
243 // it. This has the effect of resetting the status for the tab to 243 // it. This has the effect of resetting the status for the tab to
244 // ALLOW_ONE_DOWNLOAD. 244 // ALLOW_ONE_DOWNLOAD.
245 void Remove(TabDownloadState* state); 245 void Remove(TabDownloadState* state);
246 246
247 // Maps from tab to download state. The download state for a tab only exists 247 // Maps from tab to download state. The download state for a tab only exists
248 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state 248 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state
249 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD 249 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD
250 // the TabDownloadState is removed and deleted (by way of Remove). 250 // the TabDownloadState is removed and deleted (by way of Remove).
251 typedef std::map<NavigationController*, TabDownloadState*> StateMap; 251 typedef std::map<content::NavigationController*, TabDownloadState*> StateMap;
252 StateMap state_map_; 252 StateMap state_map_;
253 253
254 static TestingDelegate* delegate_; 254 static TestingDelegate* delegate_;
255 255
256 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); 256 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter);
257 }; 257 };
258 258
259 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 259 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698