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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_navigation_observer.cc

Issue 11299035: Support manual (white|black)list, previewing and allowing after interstitial (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow/block flow which includes preview mode. Created 8 years 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) 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
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->ClearInterstitialState();
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->ClearInterstitialState();
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 RemoveObserverOnIOThread();
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 after_interstitial_(false),
205 last_allowed_page_(-1) {} 213 redirects_completed_(false),
214 last_allowed_page_(-1) {
215 DLOG(ERROR) << "--- New navigation observer";
Bernhard Bauer 2012/11/26 16:06:30 Please remove these log statements before committi
Sergiu 2012/11/27 15:37:34 Done.
216 }
217
218 void ManagedModeNavigationObserver::AddObserverOnIOThread() {
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Bernhard Bauer 2012/11/26 16:06:30 "...OnIOThread()" methods are called on the IO thr
Sergiu 2012/11/27 15:37:34 Renamed.
220 if (web_contents()) {
Bernhard Bauer 2012/11/26 16:06:30 You could early-return if web_contents() is NULL.
Sergiu 2012/11/27 15:37:34 It can happen in the RemoveObserverFunction when t
221 BrowserThread::PostTask(
222 BrowserThread::IO,
223 FROM_HERE,
224 base::Bind(&ManagedModeResourceThrottle::AddObserver,
225 web_contents()->GetRenderProcessHost()->GetID(),
226 web_contents()->GetRenderViewHost()->GetRoutingID(),
227 navigated_urls_.back().host()));
228 }
229 }
230
231 void ManagedModeNavigationObserver::RemoveObserverOnIOThread() {
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
233 if (web_contents())
234 BrowserThread::PostTask(
235 BrowserThread::IO,
236 FROM_HERE,
237 base::Bind(&ManagedModeResourceThrottle::RemoveObserver,
238 web_contents()->GetRenderProcessHost()->GetID(),
239 web_contents()->GetRenderViewHost()->GetRoutingID()));
240 }
206 241
207 void ManagedModeNavigationObserver::WarnInfobarDismissed() { 242 void ManagedModeNavigationObserver::WarnInfobarDismissed() {
208 DCHECK(warn_infobar_delegate_); 243 DCHECK(warn_infobar_delegate_);
209 warn_infobar_delegate_ = NULL; 244 warn_infobar_delegate_ = NULL;
210 } 245 }
211 246
212 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { 247 void ManagedModeNavigationObserver::PreviewInfobarDismissed() {
213 DCHECK(preview_infobar_delegate_); 248 DCHECK(preview_infobar_delegate_);
214 preview_infobar_delegate_ = NULL; 249 preview_infobar_delegate_ = NULL;
215 } 250 }
216 251
217 void ManagedModeNavigationObserver::AddNavigatedURL(const GURL& url) { 252 void ManagedModeNavigationObserver::DismissInfobar(
218 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) != 253 InfoBarDelegate** dismissed_infobar_delegate) {
Bernhard Bauer 2012/11/26 16:06:30 I'm not sure if the saved lines are worth adding a
Sergiu 2012/11/27 15:37:34 Removed the function.
254 if (!*dismissed_infobar_delegate)
255 return;
256
257 InfoBarTabHelper* infobar_tab_helper =
258 InfoBarTabHelper::FromWebContents(web_contents());
259 infobar_tab_helper->RemoveInfoBar(*dismissed_infobar_delegate);
260 *dismissed_infobar_delegate= NULL;
Bernhard Bauer 2012/11/26 16:06:30 Nit: Space before equals sign.
Sergiu 2012/11/27 15:37:34 Done.
261 }
262
263 void ManagedModeNavigationObserver::SaveNavigatedURL(const GURL& url) {
264 if (redirects_completed_)
265 return;
266
267 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) ==
219 navigated_urls_.end()) { 268 navigated_urls_.end()) {
220 navigated_urls_.push_back(url); 269 navigated_urls_.push_back(url);
221 } 270 }
222 } 271 }
223 272
224 void ManagedModeNavigationObserver::AddURLList() { 273 void ManagedModeNavigationObserver::AddSavedURLsToWhitelist() {
225 // Get a copy of the whitelist since it can't be edited in place. 274 // |whitelist| is used to add the URLs to the preference list while
226 // |whitelist| is the preference list while AddStringToManualWhitelist adds 275 // AddURLPatternToManualWhitelist adds the navigated urls to the URL filter.
227 // the navigated urls to the URL filter. 276 base::ListValue whitelist;
228 scoped_ptr<base::ListValue> whitelist( 277 std::string pattern_to_add;
229 ManagedMode::GetWhitelist()->DeepCopy()); 278 bool added_urls = false;
230 std::string url_to_add;
231 int added_url_count = 0;
232 279
233 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); 280 if (!navigated_urls_.empty()) {
234 it+1 != navigated_urls_.end(); ++it) { 281 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin();
235 url_to_add = it->spec(); 282 it+1 != navigated_urls_.end(); ++it) {
236 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { 283 GURL current_url = *it;
237 DLOG(ERROR) << "Adding (exact):" << url_to_add; 284 GURL::Replacements replaced_components;
238 ManagedMode::AddStringToManualWhitelist(url_to_add); 285 // Add the . to match the exact host.
239 whitelist->Append(Value::CreateStringValue(url_to_add)); 286 replaced_components.SetHostStr("."+it->host());
Bernhard Bauer 2012/11/26 16:06:30 Nit: space around plus sign.
Sergiu 2012/11/27 15:37:34 Done.
240 ++added_url_count; 287 replaced_components.SetRefStr("");
288 replaced_components.SetSchemeStr("");
289 current_url.ReplaceComponents(replaced_components);
290 pattern_to_add = current_url.spec();
291 DLOG(ERROR) << "Adding (exact):" << pattern_to_add;
292 whitelist.AppendString(pattern_to_add);
241 } 293 }
294
295 // If the URL uses https add the protocol as well. Also since this is the
Bernhard Bauer 2012/11/26 16:06:30 Nit: HTTPS in upper case please, and commas would
Sergiu 2012/11/27 15:37:34 Done.
296 // final destination add the whole subdomain.
297 // hostname.
Bernhard Bauer 2012/11/26 16:06:30 ?
Sergiu 2012/11/27 15:37:34 Done.
298 if (navigated_urls_.back().SchemeIs("https")) {
299 pattern_to_add = "https://" + navigated_urls_.back().host();
300 } else {
301 pattern_to_add = navigated_urls_.back().host();
302 }
303
304 DLOG(ERROR) << "Adding (hostname): " << pattern_to_add;
305 whitelist.AppendString(pattern_to_add);
306
307 added_urls = ManagedMode::AddToManualWhitelist(whitelist);
242 } 308 }
243 309
244 // If the URL uses https add the protocol as well instead of just the 310 if ((navigated_urls_.empty() || !added_urls) && after_interstitial_) {
245 // hostname.
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. 311 // Tell the user that the site was already present in the whitelist.
260 InfoBarTabHelper* infobar_tab_helper = 312 InfoBarTabHelper* infobar_tab_helper =
261 InfoBarTabHelper::FromWebContents(web_contents()); 313 InfoBarTabHelper::FromWebContents(web_contents());
262 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( 314 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
263 infobar_tab_helper, 315 infobar_tab_helper,
264 NULL, 316 NULL,
265 l10n_util::GetStringFUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE, 317 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE),
266 base::IntToString16(added_url_count)),
267 true)); 318 true));
268 } 319 }
269 320
270 ManagedMode::SetWhitelist(whitelist.get()); 321 }
322
323 void ManagedModeNavigationObserver::MarkShownInterstitial() {
324 after_interstitial_ = true;
325 }
326
327 void ManagedModeNavigationObserver::ClearShownInterstitial() {
328 after_interstitial_ = false;
329 }
330
331 void ManagedModeNavigationObserver::ClearInterstitialState() {
332 DLOG(ERROR) << "Clearing interstitial state";
333 if (after_interstitial_) {
334 DismissInfobar(&preview_infobar_delegate_);
335 }
336 navigated_urls_.clear();
337 after_interstitial_ = false;
338 redirects_completed_ = false;
339 RemoveObserverOnIOThread();
271 } 340 }
272 341
273 void ManagedModeNavigationObserver::NavigateToPendingEntry( 342 void ManagedModeNavigationObserver::NavigateToPendingEntry(
274 const GURL& url, 343 const GURL& url,
275 content::NavigationController::ReloadType reload_type) { 344 content::NavigationController::ReloadType reload_type) {
276 DLOG(ERROR) << "NavigateToPendingEntry: " << url; 345 DLOG(ERROR) << "NavigateToPendingEntry: " << url;
277 // This means that a new navigation was instantiated and the data related to 346
278 // the list of URLs needs to be cleared. 347 // This method gets called first when a user navigates to a (new) URL.
279 navigated_urls_.clear(); 348 // This means that the data related to the list of URLs needs to be cleared
280 after_interstitial_ = false; 349 // in certain circumstances.
350 if (web_contents()->GetController().GetCurrentEntryIndex() <
351 last_allowed_page_ ||
352 navigated_urls_.empty() ||
353 navigated_urls_.back().host() != url.host()) {
354 ClearInterstitialState();
355 }
281 } 356 }
282 357
283 void ManagedModeNavigationObserver::DidNavigateMainFrame( 358 void ManagedModeNavigationObserver::DidNavigateMainFrame(
284 const content::LoadCommittedDetails& details, 359 const content::LoadCommittedDetails& details,
285 const content::FrameNavigateParams& params) { 360 const content::FrameNavigateParams& params) {
286 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; 361 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url;
287 362
288 ManagedModeURLFilter::FilteringBehavior behavior = 363 ManagedModeURLFilter::FilteringBehavior behavior =
289 url_filter_->GetFilteringBehaviorForURL(params.url); 364 url_filter_->GetFilteringBehaviorForURL(params.url);
290 365
291 if (behavior != ManagedModeURLFilter::ALLOW) 366 if (!redirects_completed_)
292 AddNavigatedURL(params.url); 367 SaveNavigatedURL(params.url);
293 368
294 if (behavior == ManagedModeURLFilter::ALLOW && after_interstitial_) { 369 if (behavior == ManagedModeURLFilter::ALLOW && after_interstitial_) {
295 // The initial page that triggered the interstitial was blocked but the 370 // 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 371 // 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. 372 // which lead to the final page to the whitelist as well.
298 AddURLList(); 373 AddSavedURLsToWhitelist();
374 }
375 if (after_interstitial_ && !redirects_completed_) {
376 redirects_completed_ = true;
377 AddObserverOnIOThread();
299 } 378 }
300 } 379 }
301 380
302 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( 381 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame(
303 int64 frame_id, 382 int64 frame_id,
304 int64 parent_frame_id, 383 int64 parent_frame_id,
305 bool is_main_frame, 384 bool is_main_frame,
306 const GURL& url, 385 const GURL& url,
307 bool is_error_page, 386 bool is_error_page,
308 content::RenderViewHost* render_view_host) { 387 content::RenderViewHost* render_view_host) {
309 if (!is_main_frame) 388 if (!is_main_frame)
310 return; 389 return;
311 390
312 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; 391 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url;
313 } 392 }
314 393
315 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( 394 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl(
316 const GURL& url, 395 const GURL& url,
317 const GURL& opener_url, 396 const GURL& opener_url,
318 content::RenderViewHost* render_view_host) { 397 content::RenderViewHost* render_view_host) {
319 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; 398 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url;
320 // Mark the fact that an interstitial will be triggered here if the URL 399 // This function is the last one to be called before the resource throttle
321 // must be blocked. 400 // shows the interstitial if the URL must be blocked.
322 ManagedModeURLFilter::FilteringBehavior behavior = 401 ManagedModeURLFilter::FilteringBehavior behavior =
323 url_filter_->GetFilteringBehaviorForURL(url); 402 url_filter_->GetFilteringBehaviorForURL(url);
324 if (behavior == ManagedModeURLFilter::BLOCK) 403 if (!navigated_urls_.empty() && redirects_completed_ &&
325 after_interstitial_ = true; 404 navigated_urls_.back().host() != url.host())
326 if (behavior != ManagedModeURLFilter::ALLOW) 405 ClearInterstitialState();
Bernhard Bauer 2012/11/26 16:06:30 Nit: newline please. Also, I thought we wanted to
Sergiu 2012/11/27 15:37:34 We set the Observer state from the interstitial an
327 AddNavigatedURL(url); 406 if (behavior != ManagedModeURLFilter::ALLOW && !redirects_completed_)
407 SaveNavigatedURL(url);
328 } 408 }
329 409
330 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( 410 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame(
331 int64 frame_id, 411 int64 frame_id,
332 bool is_main_frame, 412 bool is_main_frame,
333 const GURL& url, 413 const GURL& url,
334 content::PageTransition transition_type, 414 content::PageTransition transition_type,
335 content::RenderViewHost* render_view_host) { 415 content::RenderViewHost* render_view_host) {
336 if (!is_main_frame) 416 if (!is_main_frame)
337 return; 417 return;
338 418
339 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; 419 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url;
340 ManagedModeURLFilter::FilteringBehavior behavior = 420 ManagedModeURLFilter::FilteringBehavior behavior =
341 url_filter_->GetFilteringBehaviorForURL(url); 421 url_filter_->GetFilteringBehaviorForURL(url);
342 422
343 DLOG(ERROR) << "Current behavior: " << behavior;
344 if (behavior == ManagedModeURLFilter::WARN) { 423 if (behavior == ManagedModeURLFilter::WARN) {
345 if (!warn_infobar_delegate_) { 424 if (!warn_infobar_delegate_) {
346 InfoBarTabHelper* infobar_tab_helper = 425 InfoBarTabHelper* infobar_tab_helper =
347 InfoBarTabHelper::FromWebContents(web_contents()); 426 InfoBarTabHelper::FromWebContents(web_contents());
348 warn_infobar_delegate_ = 427 warn_infobar_delegate_ =
349 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, 428 new ManagedModeWarningInfobarDelegate(infobar_tab_helper,
350 last_allowed_page_); 429 last_allowed_page_);
351 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); 430 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_);
352 } 431 }
353 } else { 432 } else {
354 if (warn_infobar_delegate_) { 433 if (warn_infobar_delegate_) {
355 InfoBarTabHelper* infobar_tab_helper = 434 DismissInfobar(&warn_infobar_delegate_);
356 InfoBarTabHelper::FromWebContents(web_contents());
357 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_);
358 warn_infobar_delegate_= NULL;
359 } 435 }
360 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex();
361 } 436 }
362 437
363 if (behavior == ManagedModeURLFilter::BLOCK) { 438 if (after_interstitial_ && behavior == ManagedModeURLFilter::BLOCK) {
364 if (!preview_infobar_delegate_) { 439 if (!preview_infobar_delegate_) {
365 InfoBarTabHelper* infobar_tab_helper = 440 InfoBarTabHelper* infobar_tab_helper =
366 InfoBarTabHelper::FromWebContents(web_contents()); 441 InfoBarTabHelper::FromWebContents(web_contents());
367 preview_infobar_delegate_ = 442 preview_infobar_delegate_ =
368 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); 443 new ManagedModePreviewInfobarDelegate(infobar_tab_helper);
369 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); 444 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_);
370 } 445 }
371 } else { 446 } else {
372 if (preview_infobar_delegate_) { 447 if (preview_infobar_delegate_) {
373 InfoBarTabHelper* infobar_tab_helper = 448 DismissInfobar(&preview_infobar_delegate_);
374 InfoBarTabHelper::FromWebContents(web_contents());
375 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_);
376 preview_infobar_delegate_= NULL;
377 } 449 }
378 } 450 }
451
452 if (behavior == ManagedModeURLFilter::ALLOW) {
453 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex();
454 }
379 } 455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698