OLD | NEW |
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 #include "chrome/browser/download/download_request_limiter.h" | 5 #include "chrome/browser/download/download_request_limiter.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "chrome/browser/download/download_request_infobar_delegate.h" | 8 #include "chrome/browser/download/download_request_infobar_delegate.h" |
9 #include "chrome/browser/tab_contents/tab_util.h" | 9 #include "chrome/browser/tab_contents/tab_util.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 DownloadRequestLimiter::TabDownloadState::TabDownloadState( | 24 DownloadRequestLimiter::TabDownloadState::TabDownloadState( |
25 DownloadRequestLimiter* host, | 25 DownloadRequestLimiter* host, |
26 NavigationController* controller, | 26 NavigationController* controller, |
27 NavigationController* originating_controller) | 27 NavigationController* originating_controller) |
28 : host_(host), | 28 : host_(host), |
29 controller_(controller), | 29 controller_(controller), |
30 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), | 30 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), |
31 download_count_(0), | 31 download_count_(0), |
32 infobar_(NULL) { | 32 infobar_(NULL) { |
33 Source<NavigationController> notification_source(controller); | 33 Source<NavigationController> notification_source(controller); |
34 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, | 34 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
35 notification_source); | 35 notification_source); |
36 registrar_.Add(this, NotificationType::TAB_CLOSED, notification_source); | 36 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, notification_source); |
37 | 37 |
38 NavigationEntry* active_entry = originating_controller ? | 38 NavigationEntry* active_entry = originating_controller ? |
39 originating_controller->GetActiveEntry() : controller->GetActiveEntry(); | 39 originating_controller->GetActiveEntry() : controller->GetActiveEntry(); |
40 if (active_entry) | 40 if (active_entry) |
41 initial_page_host_ = active_entry->url().host(); | 41 initial_page_host_ = active_entry->url().host(); |
42 } | 42 } |
43 | 43 |
44 DownloadRequestLimiter::TabDownloadState::~TabDownloadState() { | 44 DownloadRequestLimiter::TabDownloadState::~TabDownloadState() { |
45 // We should only be destroyed after the callbacks have been notified. | 45 // We should only be destroyed after the callbacks have been notified. |
46 DCHECK(callbacks_.empty()); | 46 DCHECK(callbacks_.empty()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 void DownloadRequestLimiter::TabDownloadState::Cancel() { | 85 void DownloadRequestLimiter::TabDownloadState::Cancel() { |
86 NotifyCallbacks(false); | 86 NotifyCallbacks(false); |
87 } | 87 } |
88 | 88 |
89 void DownloadRequestLimiter::TabDownloadState::Accept() { | 89 void DownloadRequestLimiter::TabDownloadState::Accept() { |
90 NotifyCallbacks(true); | 90 NotifyCallbacks(true); |
91 } | 91 } |
92 | 92 |
93 void DownloadRequestLimiter::TabDownloadState::Observe( | 93 void DownloadRequestLimiter::TabDownloadState::Observe( |
94 NotificationType type, | 94 int type, |
95 const NotificationSource& source, | 95 const NotificationSource& source, |
96 const NotificationDetails& details) { | 96 const NotificationDetails& details) { |
97 if ((type != NotificationType::NAV_ENTRY_PENDING && | 97 if ((type != content::NOTIFICATION_NAV_ENTRY_PENDING && |
98 type != NotificationType::TAB_CLOSED) || | 98 type != content::NOTIFICATION_TAB_CLOSED) || |
99 Source<NavigationController>(source).ptr() != controller_) { | 99 Source<NavigationController>(source).ptr() != controller_) { |
100 NOTREACHED(); | 100 NOTREACHED(); |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 switch (type.value) { | 104 switch (type) { |
105 case NotificationType::NAV_ENTRY_PENDING: { | 105 case content::NOTIFICATION_NAV_ENTRY_PENDING: { |
106 // NOTE: resetting state on a pending navigate isn't ideal. In particular | 106 // NOTE: resetting state on a pending navigate isn't ideal. In particular |
107 // it is possible that queued up downloads for the page before the | 107 // it is possible that queued up downloads for the page before the |
108 // pending navigate will be delivered to us after we process this | 108 // pending navigate will be delivered to us after we process this |
109 // request. If this happens we may let a download through that we | 109 // request. If this happens we may let a download through that we |
110 // shouldn't have. But this is rather rare, and it is difficult to get | 110 // shouldn't have. But this is rather rare, and it is difficult to get |
111 // 100% right, so we don't deal with it. | 111 // 100% right, so we don't deal with it. |
112 NavigationEntry* entry = controller_->pending_entry(); | 112 NavigationEntry* entry = controller_->pending_entry(); |
113 if (!entry) | 113 if (!entry) |
114 return; | 114 return; |
115 | 115 |
116 if (PageTransition::IsRedirect(entry->transition_type())) { | 116 if (PageTransition::IsRedirect(entry->transition_type())) { |
117 // Redirects don't count. | 117 // Redirects don't count. |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 if (status_ == DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS || | 121 if (status_ == DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS || |
122 status_ == DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED) { | 122 status_ == DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED) { |
123 // User has either allowed all downloads or canceled all downloads. Only | 123 // User has either allowed all downloads or canceled all downloads. Only |
124 // reset the download state if the user is navigating to a different | 124 // reset the download state if the user is navigating to a different |
125 // host (or host is empty). | 125 // host (or host is empty). |
126 if (!initial_page_host_.empty() && !entry->url().host().empty() && | 126 if (!initial_page_host_.empty() && !entry->url().host().empty() && |
127 entry->url().host() == initial_page_host_) { | 127 entry->url().host() == initial_page_host_) { |
128 return; | 128 return; |
129 } | 129 } |
130 } | 130 } |
131 break; | 131 break; |
132 } | 132 } |
133 | 133 |
134 case NotificationType::TAB_CLOSED: | 134 case content::NOTIFICATION_TAB_CLOSED: |
135 // Tab closed, no need to handle closing the dialog as it's owned by the | 135 // Tab closed, no need to handle closing the dialog as it's owned by the |
136 // TabContents, break so that we get deleted after switch. | 136 // TabContents, break so that we get deleted after switch. |
137 break; | 137 break; |
138 | 138 |
139 default: | 139 default: |
140 NOTREACHED(); | 140 NOTREACHED(); |
141 } | 141 } |
142 | 142 |
143 NotifyCallbacks(false); | 143 NotifyCallbacks(false); |
144 host_->Remove(this); | 144 host_->Remove(this); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 void DownloadRequestLimiter::Remove(TabDownloadState* state) { | 332 void DownloadRequestLimiter::Remove(TabDownloadState* state) { |
333 DCHECK(ContainsKey(state_map_, state->controller())); | 333 DCHECK(ContainsKey(state_map_, state->controller())); |
334 state_map_.erase(state->controller()); | 334 state_map_.erase(state->controller()); |
335 delete state; | 335 delete state; |
336 } | 336 } |
337 | 337 |
338 // static | 338 // static |
339 DownloadRequestLimiter::TestingDelegate* DownloadRequestLimiter::delegate_ = | 339 DownloadRequestLimiter::TestingDelegate* DownloadRequestLimiter::delegate_ = |
340 NULL; | 340 NULL; |
OLD | NEW |