| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 public: | 76 public: |
| 77 // Creates a new TabDownloadState. |controller| is the controller the | 77 // Creates a new TabDownloadState. |controller| is the controller the |
| 78 // TabDownloadState tracks the state of and is the host for any dialogs that | 78 // TabDownloadState tracks the state of and is the host for any dialogs that |
| 79 // are displayed. |originating_controller| is used to determine the host of | 79 // are displayed. |originating_controller| is used to determine the host of |
| 80 // the initial download. If |originating_controller| is null, |controller| | 80 // the initial download. If |originating_controller| is null, |controller| |
| 81 // is used. |originating_controller| is typically null, but differs from | 81 // is used. |originating_controller| is typically null, but differs from |
| 82 // |controller| in the case of a constrained popup requesting the download. | 82 // |controller| in the case of a constrained popup requesting the download. |
| 83 TabDownloadState(DownloadRequestLimiter* host, | 83 TabDownloadState(DownloadRequestLimiter* host, |
| 84 content::WebContents* web_contents, | 84 content::WebContents* web_contents, |
| 85 content::WebContents* originating_web_contents); | 85 content::WebContents* originating_web_contents); |
| 86 virtual ~TabDownloadState(); | 86 ~TabDownloadState() override; |
| 87 | 87 |
| 88 // Status of the download. | 88 // Status of the download. |
| 89 void set_download_status(DownloadRequestLimiter::DownloadStatus status) { | 89 void set_download_status(DownloadRequestLimiter::DownloadStatus status) { |
| 90 status_ = status; | 90 status_ = status; |
| 91 } | 91 } |
| 92 DownloadRequestLimiter::DownloadStatus download_status() const { | 92 DownloadRequestLimiter::DownloadStatus download_status() const { |
| 93 return status_; | 93 return status_; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Number of "ALLOWED" downloads. | 96 // Number of "ALLOWED" downloads. |
| 97 void increment_download_count() { | 97 void increment_download_count() { |
| 98 download_count_++; | 98 download_count_++; |
| 99 } | 99 } |
| 100 size_t download_count() const { | 100 size_t download_count() const { |
| 101 return download_count_; | 101 return download_count_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // content::WebContentsObserver overrides. | 104 // content::WebContentsObserver overrides. |
| 105 virtual void AboutToNavigateRenderView( | 105 void AboutToNavigateRenderView( |
| 106 content::RenderViewHost* render_view_host) override; | 106 content::RenderViewHost* render_view_host) override; |
| 107 // Invoked when a user gesture occurs (mouse click, enter or space). This | 107 // Invoked when a user gesture occurs (mouse click, enter or space). This |
| 108 // may result in invoking Remove on DownloadRequestLimiter. | 108 // may result in invoking Remove on DownloadRequestLimiter. |
| 109 virtual void DidGetUserGesture() override; | 109 void DidGetUserGesture() override; |
| 110 virtual void WebContentsDestroyed() override; | 110 void WebContentsDestroyed() override; |
| 111 | 111 |
| 112 // Asks the user if they really want to allow the download. | 112 // Asks the user if they really want to allow the download. |
| 113 // See description above CanDownloadOnIOThread for details on lifetime of | 113 // See description above CanDownloadOnIOThread for details on lifetime of |
| 114 // callback. | 114 // callback. |
| 115 void PromptUserForDownload( | 115 void PromptUserForDownload( |
| 116 const DownloadRequestLimiter::Callback& callback); | 116 const DownloadRequestLimiter::Callback& callback); |
| 117 | 117 |
| 118 // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and | 118 // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and |
| 119 // changes the status appropriately. Virtual for testing. | 119 // changes the status appropriately. Virtual for testing. |
| 120 virtual void Cancel(); | 120 virtual void Cancel(); |
| 121 virtual void CancelOnce(); | 121 virtual void CancelOnce(); |
| 122 virtual void Accept(); | 122 virtual void Accept(); |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 // Used for testing. | 125 // Used for testing. |
| 126 TabDownloadState(); | 126 TabDownloadState(); |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 // Are we showing a prompt to the user? Determined by whether | 129 // Are we showing a prompt to the user? Determined by whether |
| 130 // we have an outstanding weak pointer--weak pointers are only | 130 // we have an outstanding weak pointer--weak pointers are only |
| 131 // given to the info bar delegate or permission bubble request. | 131 // given to the info bar delegate or permission bubble request. |
| 132 bool is_showing_prompt() const; | 132 bool is_showing_prompt() const; |
| 133 | 133 |
| 134 // content::NotificationObserver method. | 134 // content::NotificationObserver method. |
| 135 virtual void Observe(int type, | 135 void Observe(int type, |
| 136 const content::NotificationSource& source, | 136 const content::NotificationSource& source, |
| 137 const content::NotificationDetails& details) override; | 137 const content::NotificationDetails& details) override; |
| 138 | 138 |
| 139 // Remember to either block or allow automatic downloads from this origin. | 139 // Remember to either block or allow automatic downloads from this origin. |
| 140 void SetContentSetting(ContentSetting setting); | 140 void SetContentSetting(ContentSetting setting); |
| 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 content::WebContents* web_contents_; | 146 content::WebContents* web_contents_; |
| 147 | 147 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 StateMap state_map_; | 250 StateMap state_map_; |
| 251 | 251 |
| 252 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously | 252 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously |
| 253 // about the download. | 253 // about the download. |
| 254 base::WeakPtrFactory<DownloadRequestLimiter> factory_; | 254 base::WeakPtrFactory<DownloadRequestLimiter> factory_; |
| 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_ |
| OLD | NEW |