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 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | 5 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
11 #include "chrome/browser/infobars/infobar_tab_helper.h" | 11 #include "chrome/browser/infobars/infobar_tab_helper.h" |
12 #include "chrome/browser/managed_mode/managed_mode.h" | 12 #include "chrome/browser/managed_mode/managed_mode.h" |
13 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | 13 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
14 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | |
14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 15 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
18 #include "chrome/common/jstemplate_builder.h" | 19 #include "chrome/common/jstemplate_builder.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/browser_thread.h" | |
23 #include "content/public/browser/render_process_host.h" | |
24 #include "content/public/browser/render_view_host.h" | |
21 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
22 #include "content/public/common/frame_navigate_params.h" | 26 #include "content/public/common/frame_navigate_params.h" |
23 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
24 #include "grit/locale_settings.h" | 28 #include "grit/locale_settings.h" |
25 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
26 | 30 |
31 using content::BrowserThread; | |
32 | |
27 namespace { | 33 namespace { |
28 | 34 |
29 bool IsInList(const ListValue *list, const std::string& url_to_add) { | |
30 return list->Find(*Value::CreateStringValue(url_to_add)) != list->end(); | |
31 } | |
32 | |
33 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { | 35 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { |
34 public: | 36 public: |
35 explicit ManagedModeWarningInfobarDelegate( | 37 explicit ManagedModeWarningInfobarDelegate( |
36 InfoBarTabHelper* infobar_tab_helper, | 38 InfoBarTabHelper* infobar_tab_helper, |
37 int last_allowed_page); | 39 int last_allowed_page); |
38 | 40 |
39 private: | 41 private: |
40 virtual ~ManagedModeWarningInfobarDelegate(); | 42 virtual ~ManagedModeWarningInfobarDelegate(); |
41 | 43 |
42 // ConfirmInfoBarDelegate overrides: | 44 // ConfirmInfoBarDelegate overrides: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } | 152 } |
151 | 153 |
152 int ManagedModePreviewInfobarDelegate::GetButtons() const { | 154 int ManagedModePreviewInfobarDelegate::GetButtons() const { |
153 return BUTTON_OK | BUTTON_CANCEL; | 155 return BUTTON_OK | BUTTON_CANCEL; |
154 } | 156 } |
155 | 157 |
156 string16 ManagedModePreviewInfobarDelegate::GetButtonLabel( | 158 string16 ManagedModePreviewInfobarDelegate::GetButtonLabel( |
157 InfoBarButton button) const { | 159 InfoBarButton button) const { |
158 return l10n_util::GetStringUTF16( | 160 return l10n_util::GetStringUTF16( |
159 (button == BUTTON_OK) ? IDS_MANAGED_MODE_PREVIEW_ACCEPT | 161 (button == BUTTON_OK) ? IDS_MANAGED_MODE_PREVIEW_ACCEPT |
160 : IDS_MANAGED_MODE_PREVIEW_CANCEL); | 162 : IDS_MANAGED_MODE_GO_BACK_ACTION); |
161 } | 163 } |
162 | 164 |
163 bool ManagedModePreviewInfobarDelegate::Accept() { | 165 bool ManagedModePreviewInfobarDelegate::Accept() { |
164 ManagedModeNavigationObserver* observer = | 166 ManagedModeNavigationObserver* observer = |
165 ManagedModeNavigationObserver::FromWebContents( | 167 ManagedModeNavigationObserver::FromWebContents( |
166 owner()->GetWebContents()); | 168 owner()->GetWebContents()); |
167 observer->AddURLList(); | 169 observer->AddSavedURLsToWhitelistAndClearState(); |
168 // Clear the pointer as the infobar was closed. | |
169 observer->PreviewInfobarDismissed(); | |
170 | |
171 return true; | 170 return true; |
172 } | 171 } |
173 | 172 |
174 bool ManagedModePreviewInfobarDelegate::Cancel() { | 173 bool ManagedModePreviewInfobarDelegate::Cancel() { |
175 // TODO(bauerb): Go back to the last page. | 174 // TODO(bauerb): Go back to the last page. |
175 ManagedModeNavigationObserver* observer = | |
176 ManagedModeNavigationObserver::FromWebContents( | |
177 owner()->GetWebContents()); | |
178 observer->ClearObserverState(); | |
176 return false; | 179 return false; |
177 } | 180 } |
178 | 181 |
179 bool ManagedModePreviewInfobarDelegate::ShouldExpire( | 182 bool ManagedModePreviewInfobarDelegate::ShouldExpire( |
180 const content::LoadCommittedDetails& details) const { | 183 const content::LoadCommittedDetails& details) const { |
181 // ManagedModeNavigationObserver removes us below. | 184 // ManagedModeNavigationObserver removes us below. |
182 return false; | 185 return false; |
183 } | 186 } |
184 | 187 |
185 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { | 188 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { |
186 ManagedModeNavigationObserver* observer = | 189 ManagedModeNavigationObserver* observer = |
187 ManagedModeNavigationObserver::FromWebContents( | 190 ManagedModeNavigationObserver::FromWebContents( |
188 owner()->GetWebContents()); | 191 owner()->GetWebContents()); |
189 observer->PreviewInfobarDismissed(); | 192 observer->PreviewInfobarDismissed(); |
190 } | 193 } |
191 | 194 |
195 // Taken from shill_manager_client.cc as ListValue returns a const_iterator | |
Pam (message me for reviews)
2012/12/06 15:11:56
Not sure what file you mean, but there's a typo in
Sergiu
2013/01/04 15:44:07
Removed, not needed anymore.
| |
196 // in its Find method. | |
197 struct ValueEquals { | |
198 explicit ValueEquals(const Value* first) : first_(first) {} | |
199 bool operator()(const Value* second) const { | |
200 return first_->Equals(second); | |
201 } | |
202 const Value* first_; | |
203 }; | |
204 | |
192 } // namespace | 205 } // namespace |
193 | 206 |
194 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) | 207 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) |
195 | 208 |
196 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {} | 209 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
210 RemoveTemporaryException(); | |
211 } | |
197 | 212 |
198 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 213 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
199 content::WebContents* web_contents) | 214 content::WebContents* web_contents) |
200 : WebContentsObserver(web_contents), | 215 : WebContentsObserver(web_contents), |
201 url_filter_(ManagedMode::GetURLFilterForUIThread()), | 216 url_filter_(ManagedMode::GetURLFilterForUIThread()), |
202 warn_infobar_delegate_(NULL), | 217 warn_infobar_delegate_(NULL), |
203 preview_infobar_delegate_(NULL), | 218 preview_infobar_delegate_(NULL), |
204 after_interstitial_(false), | 219 state_(RECORDING_URLS_BEFORE_PREVIEW), |
205 last_allowed_page_(-1) {} | 220 last_allowed_page_(-1) {} |
206 | 221 |
222 void ManagedModeNavigationObserver::AddTemporaryException() { | |
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
224 DCHECK(web_contents()); | |
225 | |
226 BrowserThread::PostTask( | |
227 BrowserThread::IO, | |
228 FROM_HERE, | |
229 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | |
230 web_contents()->GetRenderProcessHost()->GetID(), | |
231 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
232 last_url_)); | |
233 } | |
234 | |
235 void ManagedModeNavigationObserver::RemoveTemporaryException() { | |
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
237 // When closing the browser web_contents() may return NULL so guard against | |
238 // that. | |
239 if (!web_contents()) | |
240 return; | |
241 | |
242 BrowserThread::PostTask( | |
243 BrowserThread::IO, | |
244 FROM_HERE, | |
245 base::Bind(&ManagedModeResourceThrottle::RemoveTemporaryException, | |
246 web_contents()->GetRenderProcessHost()->GetID(), | |
247 web_contents()->GetRenderViewHost()->GetRoutingID())); | |
248 } | |
249 | |
207 void ManagedModeNavigationObserver::WarnInfobarDismissed() { | 250 void ManagedModeNavigationObserver::WarnInfobarDismissed() { |
208 DCHECK(warn_infobar_delegate_); | 251 DCHECK(warn_infobar_delegate_); |
209 warn_infobar_delegate_ = NULL; | 252 warn_infobar_delegate_ = NULL; |
210 } | 253 } |
211 | 254 |
212 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { | 255 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { |
213 DCHECK(preview_infobar_delegate_); | 256 DCHECK(preview_infobar_delegate_); |
214 preview_infobar_delegate_ = NULL; | 257 preview_infobar_delegate_ = NULL; |
215 } | 258 } |
216 | 259 |
217 void ManagedModeNavigationObserver::AddNavigatedURL(const GURL& url) { | 260 void ManagedModeNavigationObserver::AddSavedURLsToWhitelistAndClearState() { |
218 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) != | 261 ListValue whitelist; |
219 navigated_urls_.end()) { | 262 for (std::set<GURL>::const_iterator it = navigated_urls_.begin(); |
220 navigated_urls_.push_back(url); | 263 it != navigated_urls_.end(); |
264 ++it) { | |
265 whitelist.AppendString(it->scheme() + "://." + it->host()); | |
221 } | 266 } |
267 if (last_url_.is_valid()) { | |
268 if (last_url_.SchemeIs("https")) { | |
269 whitelist.AppendString("https://" + last_url_.host()); | |
270 } else { | |
271 whitelist.AppendString(last_url_.host()); | |
272 } | |
273 } | |
274 ManagedMode::AddToManualWhitelist(whitelist); | |
275 ClearObserverState(); | |
222 } | 276 } |
223 | 277 |
224 void ManagedModeNavigationObserver::AddURLList() { | 278 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
225 // Get a copy of the whitelist since it can't be edited in place. | 279 DCHECK(state_ != NOT_RECORDING_URLS); |
226 // |whitelist| is the preference list while AddStringToManualWhitelist adds | 280 navigated_urls_.insert(url); |
227 // the navigated urls to the URL filter. | 281 } |
228 scoped_ptr<base::ListValue> whitelist( | |
229 ManagedMode::GetWhitelist()->DeepCopy()); | |
230 std::string url_to_add; | |
231 int added_url_count = 0; | |
232 | 282 |
233 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); | 283 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { |
234 it+1 != navigated_urls_.end(); ++it) { | 284 DCHECK(state_ != NOT_RECORDING_URLS); |
235 url_to_add = it->spec(); | 285 |
236 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { | 286 // Erase the last |url| if it is present in the |navigated_urls_|. This stops |
237 DLOG(ERROR) << "Adding (exact):" << url_to_add; | 287 // us from having both http://.www.google.com (exact URL from the pattern |
238 ManagedMode::AddStringToManualWhitelist(url_to_add); | 288 // list) and www.google.com (hostname from the last URL pattern) in the list. |
239 whitelist->Append(Value::CreateStringValue(url_to_add)); | 289 navigated_urls_.erase(url); |
240 ++added_url_count; | 290 last_url_ = url; |
241 } | 291 } |
292 | |
293 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { | |
294 state_ = RECORDING_URLS_AFTER_PREVIEW; | |
295 } | |
296 | |
297 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( | |
298 const GURL& url) { | |
299 if (last_url_.scheme() == "https") { | |
300 return url.scheme() == "https" && last_url_.host() == url.host(); | |
242 } | 301 } |
302 return last_url_.host() == url.host(); | |
303 } | |
243 | 304 |
244 // If the URL uses https add the protocol as well instead of just the | 305 void ManagedModeNavigationObserver::ClearObserverState() { |
245 // hostname. | 306 if (state_ == NOT_RECORDING_URLS && preview_infobar_delegate_) { |
246 if (navigated_urls_.back().SchemeIs("https")) { | |
247 url_to_add = navigated_urls_.back().GetOrigin().spec(); | |
248 } else { | |
249 url_to_add = navigated_urls_.back().host(); | |
250 } | |
251 | |
252 // Use the local whitelist to see if this last URL is already there. | |
253 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { | |
254 DLOG(ERROR) << "Adding (hostname): " << url_to_add; | |
255 ManagedMode::AddStringToManualWhitelist(url_to_add); | |
256 whitelist->Append(Value::CreateStringValue(url_to_add)); | |
257 ++added_url_count; | |
258 } else { | |
259 // Tell the user that the site was already present in the whitelist. | |
260 InfoBarTabHelper* infobar_tab_helper = | 307 InfoBarTabHelper* infobar_tab_helper = |
261 InfoBarTabHelper::FromWebContents(web_contents()); | 308 InfoBarTabHelper::FromWebContents(web_contents()); |
262 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | 309 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); |
263 infobar_tab_helper, | 310 preview_infobar_delegate_ = NULL; |
264 NULL, | |
265 l10n_util::GetStringFUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE, | |
266 base::IntToString16(added_url_count)), | |
267 true)); | |
268 } | 311 } |
269 | 312 navigated_urls_.clear(); |
270 ManagedMode::SetWhitelist(whitelist.get()); | 313 last_url_ = GURL(); |
314 state_ = RECORDING_URLS_BEFORE_PREVIEW; | |
315 RemoveTemporaryException(); | |
271 } | 316 } |
272 | 317 |
273 void ManagedModeNavigationObserver::NavigateToPendingEntry( | 318 void ManagedModeNavigationObserver::NavigateToPendingEntry( |
274 const GURL& url, | 319 const GURL& url, |
275 content::NavigationController::ReloadType reload_type) { | 320 content::NavigationController::ReloadType reload_type) { |
276 DLOG(ERROR) << "NavigateToPendingEntry: " << url; | 321 DLOG(ERROR) << "NavigateToPendingEntry: " << url; |
277 // This means that a new navigation was instantiated and the data related to | 322 |
278 // the list of URLs needs to be cleared. | 323 // This method gets called first when a user navigates to a (new) URL. |
279 navigated_urls_.clear(); | 324 // This means that the data related to the list of URLs needs to be cleared |
280 after_interstitial_ = false; | 325 // in certain circumstances. |
326 if (web_contents()->GetController().GetCurrentEntryIndex() < | |
327 last_allowed_page_ || !CanTemporarilyNavigateHost(url)) { | |
328 ClearObserverState(); | |
329 } | |
281 } | 330 } |
282 | 331 |
283 void ManagedModeNavigationObserver::DidNavigateMainFrame( | 332 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
284 const content::LoadCommittedDetails& details, | 333 const content::LoadCommittedDetails& details, |
285 const content::FrameNavigateParams& params) { | 334 const content::FrameNavigateParams& params) { |
286 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; | 335 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; |
287 | 336 |
288 ManagedModeURLFilter::FilteringBehavior behavior = | 337 ManagedModeURLFilter::FilteringBehavior behavior = |
289 url_filter_->GetFilteringBehaviorForURL(params.url); | 338 url_filter_->GetFilteringBehaviorForURL(params.url); |
290 | 339 |
291 if (behavior != ManagedModeURLFilter::ALLOW) | 340 // If the user just saw an interstitial this is the final URL so it is |
292 AddNavigatedURL(params.url); | 341 // recorded. Checking for filtering behavior here isn't useful because |
342 // although this specific URL can be allowed the hostname will be added which | |
343 // is more general. The hostname will be checked later when it is | |
344 // added to the actual whitelist to see if it is already present. | |
345 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
346 AddURLAsLastPattern(params.url); | |
293 | 347 |
294 if (behavior == ManagedModeURLFilter::ALLOW && after_interstitial_) { | 348 if (behavior == ManagedModeURLFilter::ALLOW && |
349 state_ != RECORDING_URLS_BEFORE_PREVIEW) { | |
295 // The initial page that triggered the interstitial was blocked but the | 350 // The initial page that triggered the interstitial was blocked but the |
296 // final page is already in the whitelist so add the series of URLs | 351 // final page is already in the whitelist so add the series of URLs |
297 // which lead to the final page to the whitelist as well. | 352 // which lead to the final page to the whitelist as well. |
298 AddURLList(); | 353 AddSavedURLsToWhitelistAndClearState(); |
354 InfoBarTabHelper* infobar_tab_helper = | |
355 InfoBarTabHelper::FromWebContents(web_contents()); | |
356 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
357 infobar_tab_helper, | |
358 NULL, | |
359 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), | |
360 true)); | |
361 return; | |
362 } | |
363 | |
364 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
365 // A temporary exception should be added only if an interstitial was shown, | |
366 // the user clicked preview and the final page was not allowed. This | |
367 // temporary exception stops the interstitial from showing on further | |
368 // navigations to that host so that the user can navigate around to | |
369 // inspect it. | |
370 state_ = NOT_RECORDING_URLS; | |
371 AddTemporaryException(); | |
299 } | 372 } |
300 } | 373 } |
301 | 374 |
302 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | 375 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( |
303 int64 frame_id, | 376 int64 frame_id, |
304 int64 parent_frame_id, | 377 int64 parent_frame_id, |
305 bool is_main_frame, | 378 bool is_main_frame, |
306 const GURL& url, | 379 const GURL& url, |
307 bool is_error_page, | 380 bool is_error_page, |
308 content::RenderViewHost* render_view_host) { | 381 content::RenderViewHost* render_view_host) { |
309 if (!is_main_frame) | 382 if (!is_main_frame) |
310 return; | 383 return; |
311 | 384 |
312 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; | 385 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; |
313 } | 386 } |
314 | 387 |
315 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 388 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
316 const GURL& url, | 389 const GURL& url, |
317 const GURL& opener_url, | 390 const GURL& opener_url, |
318 content::RenderViewHost* render_view_host) { | 391 content::RenderViewHost* render_view_host) { |
319 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; | 392 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; |
320 // Mark the fact that an interstitial will be triggered here if the URL | 393 // This function is the last one to be called before the resource throttle |
321 // must be blocked. | 394 // shows the interstitial if the URL must be blocked. |
322 ManagedModeURLFilter::FilteringBehavior behavior = | 395 ManagedModeURLFilter::FilteringBehavior behavior = |
323 url_filter_->GetFilteringBehaviorForURL(url); | 396 url_filter_->GetFilteringBehaviorForURL(url); |
324 if (behavior == ManagedModeURLFilter::BLOCK) | 397 |
325 after_interstitial_ = true; | 398 if (state_ == NOT_RECORDING_URLS && !CanTemporarilyNavigateHost(url)) |
326 if (behavior != ManagedModeURLFilter::ALLOW) | 399 ClearObserverState(); |
327 AddNavigatedURL(url); | 400 |
401 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
402 AddURLToPatternList(url); | |
328 } | 403 } |
329 | 404 |
330 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 405 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
331 int64 frame_id, | 406 int64 frame_id, |
332 bool is_main_frame, | 407 bool is_main_frame, |
333 const GURL& url, | 408 const GURL& url, |
334 content::PageTransition transition_type, | 409 content::PageTransition transition_type, |
335 content::RenderViewHost* render_view_host) { | 410 content::RenderViewHost* render_view_host) { |
336 if (!is_main_frame) | 411 if (!is_main_frame) |
337 return; | 412 return; |
338 | 413 |
339 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; | 414 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; |
340 ManagedModeURLFilter::FilteringBehavior behavior = | 415 ManagedModeURLFilter::FilteringBehavior behavior = |
341 url_filter_->GetFilteringBehaviorForURL(url); | 416 url_filter_->GetFilteringBehaviorForURL(url); |
342 | 417 |
343 DLOG(ERROR) << "Current behavior: " << behavior; | |
344 if (behavior == ManagedModeURLFilter::WARN) { | 418 if (behavior == ManagedModeURLFilter::WARN) { |
345 if (!warn_infobar_delegate_) { | 419 if (!warn_infobar_delegate_) { |
346 InfoBarTabHelper* infobar_tab_helper = | 420 InfoBarTabHelper* infobar_tab_helper = |
347 InfoBarTabHelper::FromWebContents(web_contents()); | 421 InfoBarTabHelper::FromWebContents(web_contents()); |
348 warn_infobar_delegate_ = | 422 warn_infobar_delegate_ = |
349 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, | 423 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, |
350 last_allowed_page_); | 424 last_allowed_page_); |
351 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); | 425 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); |
352 } | 426 } |
353 } else { | 427 } else { |
354 if (warn_infobar_delegate_) { | 428 if (warn_infobar_delegate_) { |
355 InfoBarTabHelper* infobar_tab_helper = | 429 InfoBarTabHelper* infobar_tab_helper = |
356 InfoBarTabHelper::FromWebContents(web_contents()); | 430 InfoBarTabHelper::FromWebContents(web_contents()); |
357 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); | 431 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); |
358 warn_infobar_delegate_= NULL; | 432 warn_infobar_delegate_ = NULL; |
359 } | 433 } |
360 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
361 } | 434 } |
362 | 435 |
363 if (behavior == ManagedModeURLFilter::BLOCK) { | 436 if (behavior == ManagedModeURLFilter::BLOCK) { |
364 if (!preview_infobar_delegate_) { | 437 switch (state_) { |
365 InfoBarTabHelper* infobar_tab_helper = | 438 case RECORDING_URLS_BEFORE_PREVIEW: |
366 InfoBarTabHelper::FromWebContents(web_contents()); | 439 // Should not be in this state with a blocked URL. |
367 preview_infobar_delegate_ = | 440 NOTREACHED(); |
368 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); | 441 break; |
369 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); | 442 case RECORDING_URLS_AFTER_PREVIEW: |
370 } | 443 // Add the infobar. |
371 } else { | 444 if (!preview_infobar_delegate_) { |
372 if (preview_infobar_delegate_) { | 445 InfoBarTabHelper* infobar_tab_helper = |
373 InfoBarTabHelper* infobar_tab_helper = | 446 InfoBarTabHelper::FromWebContents(web_contents()); |
374 InfoBarTabHelper::FromWebContents(web_contents()); | 447 preview_infobar_delegate_ = |
375 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); | 448 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); |
376 preview_infobar_delegate_= NULL; | 449 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); |
450 } | |
451 break; | |
452 case NOT_RECORDING_URLS: | |
453 // Check that the infobar is present. | |
454 DCHECK(preview_infobar_delegate_); | |
455 break; | |
377 } | 456 } |
378 } | 457 } |
458 | |
459 if (behavior == ManagedModeURLFilter::ALLOW) { | |
460 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
461 } | |
379 } | 462 } |
OLD | NEW |