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->AddSavedURLsToWhitelist(); |
168 // Clear the pointer as the infobar was closed. | 170 // Notify the navigation observer that the infobar was dismissed. |
169 observer->PreviewInfobarDismissed(); | 171 observer->ClearObserverState(); |
170 | 172 |
171 return true; | 173 return true; |
172 } | 174 } |
173 | 175 |
174 bool ManagedModePreviewInfobarDelegate::Cancel() { | 176 bool ManagedModePreviewInfobarDelegate::Cancel() { |
175 // TODO(bauerb): Go back to the last page. | 177 // TODO(bauerb): Go back to the last page. |
178 ManagedModeNavigationObserver* observer = | |
179 ManagedModeNavigationObserver::FromWebContents( | |
180 owner()->GetWebContents()); | |
181 observer->ClearObserverState(); | |
176 return false; | 182 return false; |
177 } | 183 } |
178 | 184 |
179 bool ManagedModePreviewInfobarDelegate::ShouldExpire( | 185 bool ManagedModePreviewInfobarDelegate::ShouldExpire( |
180 const content::LoadCommittedDetails& details) const { | 186 const content::LoadCommittedDetails& details) const { |
181 // ManagedModeNavigationObserver removes us below. | 187 // ManagedModeNavigationObserver removes us below. |
182 return false; | 188 return false; |
183 } | 189 } |
184 | 190 |
185 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { | 191 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { |
186 ManagedModeNavigationObserver* observer = | 192 ManagedModeNavigationObserver* observer = |
187 ManagedModeNavigationObserver::FromWebContents( | 193 ManagedModeNavigationObserver::FromWebContents( |
188 owner()->GetWebContents()); | 194 owner()->GetWebContents()); |
189 observer->PreviewInfobarDismissed(); | 195 observer->PreviewInfobarDismissed(); |
190 } | 196 } |
191 | 197 |
192 } // namespace | 198 } // namespace |
193 | 199 |
194 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) | 200 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) |
195 | 201 |
196 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {} | 202 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
203 RemoveTemporaryException(); | |
204 } | |
197 | 205 |
198 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 206 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
199 content::WebContents* web_contents) | 207 content::WebContents* web_contents) |
200 : WebContentsObserver(web_contents), | 208 : WebContentsObserver(web_contents), |
201 url_filter_(ManagedMode::GetURLFilterForUIThread()), | 209 url_filter_(ManagedMode::GetURLFilterForUIThread()), |
202 warn_infobar_delegate_(NULL), | 210 warn_infobar_delegate_(NULL), |
203 preview_infobar_delegate_(NULL), | 211 preview_infobar_delegate_(NULL), |
204 after_interstitial_(false), | 212 state_(RECORDING_URLS_BEFORE_PREVIEW), |
205 last_allowed_page_(-1) {} | 213 last_allowed_page_(-1) {} |
206 | 214 |
215 void ManagedModeNavigationObserver::AddTemporaryException() { | |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
217 DCHECK(web_contents()); | |
218 | |
219 BrowserThread::PostTask( | |
220 BrowserThread::IO, | |
221 FROM_HERE, | |
222 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | |
223 web_contents()->GetRenderProcessHost()->GetID(), | |
224 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
225 navigated_urls_.back().host())); | |
226 } | |
227 | |
228 void ManagedModeNavigationObserver::RemoveTemporaryException() { | |
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
230 // When closing the browser web_contents() may return NULL so guard against | |
231 // that. | |
232 if (!web_contents()) | |
233 return; | |
234 | |
235 BrowserThread::PostTask( | |
236 BrowserThread::IO, | |
237 FROM_HERE, | |
238 base::Bind(&ManagedModeResourceThrottle::RemoveTemporaryException, | |
239 web_contents()->GetRenderProcessHost()->GetID(), | |
240 web_contents()->GetRenderViewHost()->GetRoutingID())); | |
241 } | |
242 | |
207 void ManagedModeNavigationObserver::WarnInfobarDismissed() { | 243 void ManagedModeNavigationObserver::WarnInfobarDismissed() { |
208 DCHECK(warn_infobar_delegate_); | 244 DCHECK(warn_infobar_delegate_); |
209 warn_infobar_delegate_ = NULL; | 245 warn_infobar_delegate_ = NULL; |
210 } | 246 } |
211 | 247 |
212 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { | 248 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { |
213 DCHECK(preview_infobar_delegate_); | 249 DCHECK(preview_infobar_delegate_); |
214 preview_infobar_delegate_ = NULL; | 250 preview_infobar_delegate_ = NULL; |
215 } | 251 } |
216 | 252 |
217 void ManagedModeNavigationObserver::AddNavigatedURL(const GURL& url) { | 253 void ManagedModeNavigationObserver::AddSavedURLsToWhitelist() { |
218 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) != | 254 // |whitelist| is used to add the URLs to the preference list while |
255 // AddURLPatternToManualWhitelist adds the navigated urls to the URL filter. | |
256 base::ListValue whitelist; | |
257 std::string pattern_to_add; | |
258 | |
259 if (!navigated_urls_.empty()) { | |
260 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); | |
261 it+1 != navigated_urls_.end(); ++it) { | |
262 GURL current_url = *it; | |
263 GURL::Replacements replaced_components; | |
264 // Add the . to match the exact host. | |
265 replaced_components.SetHostStr("." + it->host()); | |
266 replaced_components.SetRefStr(""); | |
267 replaced_components.SetSchemeStr(""); | |
268 current_url.ReplaceComponents(replaced_components); | |
269 pattern_to_add = current_url.spec(); | |
270 whitelist.AppendString(pattern_to_add); | |
271 } | |
272 | |
273 // Add the protocol as well if the URL uses HTTPS. Also, since this is the | |
274 // final destination, add the whole subdomain. | |
275 if (navigated_urls_.back().SchemeIs("https")) { | |
276 pattern_to_add = "https://" + navigated_urls_.back().host(); | |
277 } else { | |
278 pattern_to_add = navigated_urls_.back().host(); | |
279 } | |
280 | |
281 whitelist.AppendString(pattern_to_add); | |
282 | |
283 ManagedMode::AddToManualWhitelist(whitelist); | |
284 } | |
285 } | |
286 void ManagedModeNavigationObserver::SaveNavigatedURL(const GURL& url) { | |
287 if (state_ == NOT_RECORDING_URLS) | |
Bernhard Bauer
2012/11/28 14:21:05
This check is unnecessary (or should be converted
Sergiu
2012/11/29 12:00:17
Done.
| |
288 return; | |
289 | |
290 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) == | |
219 navigated_urls_.end()) { | 291 navigated_urls_.end()) { |
220 navigated_urls_.push_back(url); | 292 navigated_urls_.push_back(url); |
221 } | 293 } |
222 } | 294 } |
223 | 295 |
224 void ManagedModeNavigationObserver::AddURLList() { | |
225 // Get a copy of the whitelist since it can't be edited in place. | |
226 // |whitelist| is the preference list while AddStringToManualWhitelist adds | |
227 // the navigated urls to the URL filter. | |
228 scoped_ptr<base::ListValue> whitelist( | |
229 ManagedMode::GetWhitelist()->DeepCopy()); | |
230 std::string url_to_add; | |
231 int added_url_count = 0; | |
232 | 296 |
233 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); | 297 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { |
234 it+1 != navigated_urls_.end(); ++it) { | 298 state_ = RECORDING_URLS_AFTER_PREVIEW; |
235 url_to_add = it->spec(); | 299 } |
236 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { | |
237 DLOG(ERROR) << "Adding (exact):" << url_to_add; | |
238 ManagedMode::AddStringToManualWhitelist(url_to_add); | |
239 whitelist->Append(Value::CreateStringValue(url_to_add)); | |
240 ++added_url_count; | |
241 } | |
242 } | |
243 | 300 |
244 // If the URL uses https add the protocol as well instead of just the | 301 void ManagedModeNavigationObserver::ClearObserverState() { |
245 // hostname. | 302 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 = | 303 InfoBarTabHelper* infobar_tab_helper = |
261 InfoBarTabHelper::FromWebContents(web_contents()); | 304 InfoBarTabHelper::FromWebContents(web_contents()); |
262 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | 305 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); |
263 infobar_tab_helper, | 306 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 } | 307 } |
269 | 308 navigated_urls_.clear(); |
270 ManagedMode::SetWhitelist(whitelist.get()); | 309 state_ = RECORDING_URLS_BEFORE_PREVIEW; |
310 RemoveTemporaryException(); | |
271 } | 311 } |
272 | 312 |
273 void ManagedModeNavigationObserver::NavigateToPendingEntry( | 313 void ManagedModeNavigationObserver::NavigateToPendingEntry( |
274 const GURL& url, | 314 const GURL& url, |
275 content::NavigationController::ReloadType reload_type) { | 315 content::NavigationController::ReloadType reload_type) { |
276 DLOG(ERROR) << "NavigateToPendingEntry: " << url; | 316 DLOG(ERROR) << "NavigateToPendingEntry: " << url; |
277 // This means that a new navigation was instantiated and the data related to | 317 |
278 // the list of URLs needs to be cleared. | 318 // This method gets called first when a user navigates to a (new) URL. |
279 navigated_urls_.clear(); | 319 // This means that the data related to the list of URLs needs to be cleared |
280 after_interstitial_ = false; | 320 // in certain circumstances. |
321 if (web_contents()->GetController().GetCurrentEntryIndex() < | |
322 last_allowed_page_ || | |
323 navigated_urls_.empty() || | |
324 navigated_urls_.back().host() != url.host()) { | |
325 ClearObserverState(); | |
326 } | |
281 } | 327 } |
282 | 328 |
283 void ManagedModeNavigationObserver::DidNavigateMainFrame( | 329 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
284 const content::LoadCommittedDetails& details, | 330 const content::LoadCommittedDetails& details, |
285 const content::FrameNavigateParams& params) { | 331 const content::FrameNavigateParams& params) { |
286 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; | 332 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; |
287 | 333 |
288 ManagedModeURLFilter::FilteringBehavior behavior = | 334 ManagedModeURLFilter::FilteringBehavior behavior = |
289 url_filter_->GetFilteringBehaviorForURL(params.url); | 335 url_filter_->GetFilteringBehaviorForURL(params.url); |
290 | 336 |
291 if (behavior != ManagedModeURLFilter::ALLOW) | 337 // If the user just saw an interstitial this is the final URL so it is |
292 AddNavigatedURL(params.url); | 338 // recorded. Checking for filtering behavior here isn't useful because |
339 // although this specific URL can be allowed the hostname will be added which | |
340 // is more general. The hostname will be checked later when it is | |
341 // added to the actual whitelist to see if it is already present. | |
342 if (state_ == RECORDING_URLS_AFTER_PREVIEW) | |
343 SaveNavigatedURL(params.url); | |
293 | 344 |
294 if (behavior == ManagedModeURLFilter::ALLOW && after_interstitial_) { | 345 if (behavior == ManagedModeURLFilter::ALLOW && |
346 state_ != RECORDING_URLS_BEFORE_PREVIEW) { | |
295 // The initial page that triggered the interstitial was blocked but the | 347 // 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 | 348 // 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. | 349 // which lead to the final page to the whitelist as well. |
298 AddURLList(); | 350 AddSavedURLsToWhitelist(); |
351 InfoBarTabHelper* infobar_tab_helper = | |
352 InfoBarTabHelper::FromWebContents(web_contents()); | |
353 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
354 infobar_tab_helper, | |
355 NULL, | |
356 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), | |
357 true)); | |
358 } | |
359 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
360 state_ = NOT_RECORDING_URLS; | |
361 AddTemporaryException(); | |
299 } | 362 } |
300 } | 363 } |
301 | 364 |
302 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | 365 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( |
303 int64 frame_id, | 366 int64 frame_id, |
304 int64 parent_frame_id, | 367 int64 parent_frame_id, |
305 bool is_main_frame, | 368 bool is_main_frame, |
306 const GURL& url, | 369 const GURL& url, |
307 bool is_error_page, | 370 bool is_error_page, |
308 content::RenderViewHost* render_view_host) { | 371 content::RenderViewHost* render_view_host) { |
309 if (!is_main_frame) | 372 if (!is_main_frame) |
310 return; | 373 return; |
311 | 374 |
312 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; | 375 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; |
313 } | 376 } |
314 | 377 |
315 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 378 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
316 const GURL& url, | 379 const GURL& url, |
317 const GURL& opener_url, | 380 const GURL& opener_url, |
318 content::RenderViewHost* render_view_host) { | 381 content::RenderViewHost* render_view_host) { |
319 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; | 382 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; |
320 // Mark the fact that an interstitial will be triggered here if the URL | 383 // This function is the last one to be called before the resource throttle |
321 // must be blocked. | 384 // shows the interstitial if the URL must be blocked. |
322 ManagedModeURLFilter::FilteringBehavior behavior = | 385 ManagedModeURLFilter::FilteringBehavior behavior = |
323 url_filter_->GetFilteringBehaviorForURL(url); | 386 url_filter_->GetFilteringBehaviorForURL(url); |
324 if (behavior == ManagedModeURLFilter::BLOCK) | 387 |
325 after_interstitial_ = true; | 388 if (!navigated_urls_.empty() && state_ == NOT_RECORDING_URLS && |
326 if (behavior != ManagedModeURLFilter::ALLOW) | 389 navigated_urls_.back().host() != url.host()) |
327 AddNavigatedURL(url); | 390 ClearObserverState(); |
391 | |
392 if (behavior != ManagedModeURLFilter::ALLOW && state_ != NOT_RECORDING_URLS) | |
393 SaveNavigatedURL(url); | |
328 } | 394 } |
329 | 395 |
330 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 396 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
331 int64 frame_id, | 397 int64 frame_id, |
332 bool is_main_frame, | 398 bool is_main_frame, |
333 const GURL& url, | 399 const GURL& url, |
334 content::PageTransition transition_type, | 400 content::PageTransition transition_type, |
335 content::RenderViewHost* render_view_host) { | 401 content::RenderViewHost* render_view_host) { |
336 if (!is_main_frame) | 402 if (!is_main_frame) |
337 return; | 403 return; |
338 | 404 |
339 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; | 405 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; |
340 ManagedModeURLFilter::FilteringBehavior behavior = | 406 ManagedModeURLFilter::FilteringBehavior behavior = |
341 url_filter_->GetFilteringBehaviorForURL(url); | 407 url_filter_->GetFilteringBehaviorForURL(url); |
342 | 408 |
343 DLOG(ERROR) << "Current behavior: " << behavior; | |
344 if (behavior == ManagedModeURLFilter::WARN) { | 409 if (behavior == ManagedModeURLFilter::WARN) { |
345 if (!warn_infobar_delegate_) { | 410 if (!warn_infobar_delegate_) { |
346 InfoBarTabHelper* infobar_tab_helper = | 411 InfoBarTabHelper* infobar_tab_helper = |
347 InfoBarTabHelper::FromWebContents(web_contents()); | 412 InfoBarTabHelper::FromWebContents(web_contents()); |
348 warn_infobar_delegate_ = | 413 warn_infobar_delegate_ = |
349 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, | 414 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, |
350 last_allowed_page_); | 415 last_allowed_page_); |
351 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); | 416 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); |
352 } | 417 } |
353 } else { | 418 } else { |
354 if (warn_infobar_delegate_) { | 419 if (warn_infobar_delegate_) { |
355 InfoBarTabHelper* infobar_tab_helper = | 420 InfoBarTabHelper* infobar_tab_helper = |
356 InfoBarTabHelper::FromWebContents(web_contents()); | 421 InfoBarTabHelper::FromWebContents(web_contents()); |
357 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); | 422 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); |
358 warn_infobar_delegate_= NULL; | 423 warn_infobar_delegate_ = NULL; |
359 } | 424 } |
360 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
361 } | 425 } |
362 | 426 |
363 if (behavior == ManagedModeURLFilter::BLOCK) { | 427 if (state_ != RECORDING_URLS_BEFORE_PREVIEW && |
428 behavior == ManagedModeURLFilter::BLOCK) { | |
364 if (!preview_infobar_delegate_) { | 429 if (!preview_infobar_delegate_) { |
365 InfoBarTabHelper* infobar_tab_helper = | 430 InfoBarTabHelper* infobar_tab_helper = |
366 InfoBarTabHelper::FromWebContents(web_contents()); | 431 InfoBarTabHelper::FromWebContents(web_contents()); |
367 preview_infobar_delegate_ = | 432 preview_infobar_delegate_ = |
368 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); | 433 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); |
369 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); | 434 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); |
370 } | 435 } |
371 } else { | 436 } |
372 if (preview_infobar_delegate_) { | 437 |
373 InfoBarTabHelper* infobar_tab_helper = | 438 if (behavior == ManagedModeURLFilter::ALLOW) { |
374 InfoBarTabHelper::FromWebContents(web_contents()); | 439 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
375 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); | |
376 preview_infobar_delegate_= NULL; | |
377 } | |
378 } | 440 } |
379 } | 441 } |
OLD | NEW |