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" |
| 8 #include "base/i18n/rtl.h" |
| 9 #include "base/string_number_conversions.h" |
7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
8 #include "chrome/browser/api/infobars/infobar_service.h" | 11 #include "chrome/browser/api/infobars/infobar_service.h" |
| 12 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
9 #include "chrome/browser/managed_mode/managed_mode.h" | 13 #include "chrome/browser/managed_mode/managed_mode.h" |
| 14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| 15 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
10 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 16 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/common/jstemplate_builder.h" |
| 24 #include "chrome/common/pref_names.h" |
15 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/common/frame_navigate_params.h" | 30 #include "content/public/common/frame_navigate_params.h" |
18 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "grit/locale_settings.h" |
19 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
20 | 34 |
| 35 using content::BrowserThread; |
| 36 |
21 namespace { | 37 namespace { |
22 | 38 |
23 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { | 39 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { |
24 public: | 40 public: |
25 explicit ManagedModeWarningInfobarDelegate(InfoBarService* infobar_service); | 41 explicit ManagedModeWarningInfobarDelegate( |
| 42 InfoBarService* infobar_service, |
| 43 int last_allowed_page); |
26 | 44 |
27 private: | 45 private: |
28 virtual ~ManagedModeWarningInfobarDelegate(); | 46 virtual ~ManagedModeWarningInfobarDelegate(); |
29 | 47 |
30 // ConfirmInfoBarDelegate overrides: | 48 // ConfirmInfoBarDelegate overrides: |
31 virtual string16 GetMessageText() const OVERRIDE; | 49 virtual string16 GetMessageText() const OVERRIDE; |
32 virtual int GetButtons() const OVERRIDE; | 50 virtual int GetButtons() const OVERRIDE; |
33 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 51 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
34 virtual bool Accept() OVERRIDE; | 52 virtual bool Accept() OVERRIDE; |
35 virtual bool Cancel() OVERRIDE; | 53 virtual bool Cancel() OVERRIDE; |
36 | 54 |
37 // InfoBarDelegate override: | 55 // InfoBarDelegate override: |
38 virtual bool ShouldExpire( | 56 virtual bool ShouldExpire( |
39 const content::LoadCommittedDetails& details) const OVERRIDE; | 57 const content::LoadCommittedDetails& details) const OVERRIDE; |
40 virtual void InfoBarDismissed() OVERRIDE; | 58 virtual void InfoBarDismissed() OVERRIDE; |
41 | 59 |
| 60 int last_allowed_page_; |
| 61 |
42 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfobarDelegate); | 62 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfobarDelegate); |
43 }; | 63 }; |
44 | 64 |
45 void GoBackToSafety(content::WebContents* web_contents) { | 65 void GoBackToSafety(content::WebContents* web_contents) { |
46 // For now, just go back one page (the user didn't retreat from that page, | 66 // For now, just go back one page (the user didn't retreat from that page, |
47 // so it should be okay). | 67 // so it should be okay). |
48 content::NavigationController* controller = | 68 content::NavigationController* controller = |
49 &web_contents->GetController(); | 69 &web_contents->GetController(); |
50 if (controller->CanGoBack()) { | 70 if (controller->CanGoBack()) { |
51 controller->GoBack(); | 71 controller->GoBack(); |
52 return; | 72 return; |
53 } | 73 } |
54 | 74 |
55 // If we can't go back (because we opened a new tab), try to close the tab. | 75 // If we can't go back (because we opened a new tab), try to close the tab. |
56 // If this is the last tab, open a new window. | 76 // If this is the last tab, open a new window. |
57 if (BrowserList::size() == 1) { | 77 if (BrowserList::size() == 1) { |
58 Browser* browser = *(BrowserList::begin()); | 78 Browser* browser = *(BrowserList::begin()); |
59 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); | 79 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); |
60 if (browser->tab_count() == 1) | 80 if (browser->tab_count() == 1) |
61 chrome::NewEmptyWindow(browser->profile()); | 81 chrome::NewEmptyWindow(browser->profile()); |
62 } | 82 } |
63 | 83 |
64 web_contents->GetDelegate()->CloseContents(web_contents); | 84 web_contents->GetDelegate()->CloseContents(web_contents); |
65 } | 85 } |
66 | 86 |
67 ManagedModeWarningInfobarDelegate::ManagedModeWarningInfobarDelegate( | 87 ManagedModeWarningInfobarDelegate::ManagedModeWarningInfobarDelegate( |
68 InfoBarService* infobar_service) | 88 InfoBarService* infobar_service, |
69 : ConfirmInfoBarDelegate(infobar_service) {} | 89 int last_allowed_page) |
| 90 : ConfirmInfoBarDelegate(infobar_service), |
| 91 last_allowed_page_(last_allowed_page) {} |
70 | 92 |
71 ManagedModeWarningInfobarDelegate::~ManagedModeWarningInfobarDelegate() {} | 93 ManagedModeWarningInfobarDelegate::~ManagedModeWarningInfobarDelegate() {} |
72 | 94 |
73 string16 ManagedModeWarningInfobarDelegate::GetMessageText() const { | 95 string16 ManagedModeWarningInfobarDelegate::GetMessageText() const { |
74 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_WARNING_MESSAGE); | 96 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_WARNING_MESSAGE); |
75 } | 97 } |
76 | 98 |
77 int ManagedModeWarningInfobarDelegate::GetButtons() const { | 99 int ManagedModeWarningInfobarDelegate::GetButtons() const { |
78 return BUTTON_OK; | 100 return BUTTON_OK; |
79 } | 101 } |
(...skipping 20 matching lines...) Expand all Loading... |
100 // ManagedModeNavigationObserver removes us below. | 122 // ManagedModeNavigationObserver removes us below. |
101 return false; | 123 return false; |
102 } | 124 } |
103 | 125 |
104 void ManagedModeWarningInfobarDelegate::InfoBarDismissed() { | 126 void ManagedModeWarningInfobarDelegate::InfoBarDismissed() { |
105 ManagedModeNavigationObserver* observer = | 127 ManagedModeNavigationObserver* observer = |
106 ManagedModeNavigationObserver::FromWebContents(owner()->GetWebContents()); | 128 ManagedModeNavigationObserver::FromWebContents(owner()->GetWebContents()); |
107 observer->WarnInfobarDismissed(); | 129 observer->WarnInfobarDismissed(); |
108 } | 130 } |
109 | 131 |
| 132 class ManagedModePreviewInfobarDelegate : public ConfirmInfoBarDelegate { |
| 133 public: |
| 134 explicit ManagedModePreviewInfobarDelegate( |
| 135 InfoBarService* infobar_service); |
| 136 |
| 137 private: |
| 138 virtual ~ManagedModePreviewInfobarDelegate(); |
| 139 |
| 140 // ConfirmInfoBarDelegate overrides: |
| 141 virtual string16 GetMessageText() const OVERRIDE; |
| 142 virtual int GetButtons() const OVERRIDE; |
| 143 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 144 virtual bool Accept() OVERRIDE; |
| 145 virtual bool Cancel() OVERRIDE; |
| 146 |
| 147 // InfoBarDelegate override: |
| 148 virtual bool ShouldExpire( |
| 149 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 150 virtual void InfoBarDismissed() OVERRIDE; |
| 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(ManagedModePreviewInfobarDelegate); |
| 153 }; |
| 154 |
| 155 ManagedModePreviewInfobarDelegate::ManagedModePreviewInfobarDelegate( |
| 156 InfoBarService* infobar_service) |
| 157 : ConfirmInfoBarDelegate(infobar_service) {} |
| 158 |
| 159 ManagedModePreviewInfobarDelegate::~ManagedModePreviewInfobarDelegate() {} |
| 160 |
| 161 string16 ManagedModePreviewInfobarDelegate::GetMessageText() const { |
| 162 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_PREVIEW_MESSAGE); |
| 163 } |
| 164 |
| 165 int ManagedModePreviewInfobarDelegate::GetButtons() const { |
| 166 return BUTTON_OK | BUTTON_CANCEL; |
| 167 } |
| 168 |
| 169 string16 ManagedModePreviewInfobarDelegate::GetButtonLabel( |
| 170 InfoBarButton button) const { |
| 171 return l10n_util::GetStringUTF16( |
| 172 (button == BUTTON_OK) ? IDS_MANAGED_MODE_PREVIEW_ACCEPT |
| 173 : IDS_MANAGED_MODE_GO_BACK_ACTION); |
| 174 } |
| 175 |
| 176 bool ManagedModePreviewInfobarDelegate::Accept() { |
| 177 ManagedModeNavigationObserver* observer = |
| 178 ManagedModeNavigationObserver::FromWebContents( |
| 179 owner()->GetWebContents()); |
| 180 observer->AddSavedURLsToWhitelistAndClearState(); |
| 181 return true; |
| 182 } |
| 183 |
| 184 bool ManagedModePreviewInfobarDelegate::Cancel() { |
| 185 GoBackToSafety(owner()->GetWebContents()); |
| 186 return false; |
| 187 } |
| 188 |
| 189 bool ManagedModePreviewInfobarDelegate::ShouldExpire( |
| 190 const content::LoadCommittedDetails& details) const { |
| 191 // ManagedModeNavigationObserver removes us below. |
| 192 return false; |
| 193 } |
| 194 |
| 195 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { |
| 196 ManagedModeNavigationObserver* observer = |
| 197 ManagedModeNavigationObserver::FromWebContents( |
| 198 owner()->GetWebContents()); |
| 199 observer->PreviewInfobarDismissed(); |
| 200 } |
| 201 |
110 } // namespace | 202 } // namespace |
111 | 203 |
112 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) | 204 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) |
113 | 205 |
114 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {} | 206 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
| 207 RemoveTemporaryException(); |
| 208 } |
115 | 209 |
116 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 210 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
117 content::WebContents* web_contents) | 211 content::WebContents* web_contents) |
118 : WebContentsObserver(web_contents), | 212 : WebContentsObserver(web_contents), |
119 url_filter_(ManagedMode::GetURLFilterForUIThread()), | 213 url_filter_(ManagedMode::GetURLFilterForUIThread()), |
120 warn_infobar_delegate_(NULL) {} | 214 warn_infobar_delegate_(NULL), |
| 215 preview_infobar_delegate_(NULL), |
| 216 state_(RECORDING_URLS_BEFORE_PREVIEW), |
| 217 last_allowed_page_(-1) {} |
| 218 |
| 219 void ManagedModeNavigationObserver::AddTemporaryException() { |
| 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 221 DCHECK(web_contents()); |
| 222 |
| 223 BrowserThread::PostTask( |
| 224 BrowserThread::IO, |
| 225 FROM_HERE, |
| 226 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, |
| 227 web_contents()->GetRenderProcessHost()->GetID(), |
| 228 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 229 last_url_)); |
| 230 } |
| 231 |
| 232 void ManagedModeNavigationObserver::RemoveTemporaryException() { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 // When closing the browser web_contents() may return NULL so guard against |
| 235 // that. |
| 236 if (!web_contents()) |
| 237 return; |
| 238 |
| 239 BrowserThread::PostTask( |
| 240 BrowserThread::IO, |
| 241 FROM_HERE, |
| 242 base::Bind(&ManagedModeResourceThrottle::RemoveTemporaryException, |
| 243 web_contents()->GetRenderProcessHost()->GetID(), |
| 244 web_contents()->GetRenderViewHost()->GetRoutingID())); |
| 245 } |
121 | 246 |
122 void ManagedModeNavigationObserver::WarnInfobarDismissed() { | 247 void ManagedModeNavigationObserver::WarnInfobarDismissed() { |
123 DCHECK(warn_infobar_delegate_); | 248 DCHECK(warn_infobar_delegate_); |
124 warn_infobar_delegate_ = NULL; | 249 warn_infobar_delegate_ = NULL; |
125 } | 250 } |
126 | 251 |
| 252 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { |
| 253 DCHECK(preview_infobar_delegate_); |
| 254 preview_infobar_delegate_ = NULL; |
| 255 } |
| 256 |
| 257 void ManagedModeNavigationObserver::AddSavedURLsToWhitelistAndClearState() { |
| 258 ListValue whitelist; |
| 259 for (std::set<GURL>::const_iterator it = navigated_urls_.begin(); |
| 260 it != navigated_urls_.end(); |
| 261 ++it) { |
| 262 whitelist.AppendString(it->scheme() + "://." + it->host() + it->path()); |
| 263 } |
| 264 if (last_url_.is_valid()) { |
| 265 if (last_url_.SchemeIs("https")) { |
| 266 whitelist.AppendString("https://" + last_url_.host()); |
| 267 } else { |
| 268 whitelist.AppendString(last_url_.host()); |
| 269 } |
| 270 } |
| 271 ManagedMode::AddToManualList(true, whitelist); |
| 272 ClearObserverState(); |
| 273 } |
| 274 |
| 275 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
| 276 DCHECK(state_ != NOT_RECORDING_URLS); |
| 277 navigated_urls_.insert(url); |
| 278 } |
| 279 |
| 280 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { |
| 281 DCHECK(state_ != NOT_RECORDING_URLS); |
| 282 |
| 283 // Erase the last |url| if it is present in the |navigated_urls_|. This stops |
| 284 // us from having both http://.www.google.com (exact URL from the pattern |
| 285 // list) and www.google.com (hostname from the last URL pattern) in the list. |
| 286 navigated_urls_.erase(url); |
| 287 last_url_ = url; |
| 288 } |
| 289 |
| 290 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { |
| 291 state_ = RECORDING_URLS_AFTER_PREVIEW; |
| 292 } |
| 293 |
| 294 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( |
| 295 const GURL& url) { |
| 296 if (last_url_.scheme() == "https") { |
| 297 return url.scheme() == "https" && last_url_.host() == url.host(); |
| 298 } |
| 299 return last_url_.host() == url.host(); |
| 300 } |
| 301 |
| 302 void ManagedModeNavigationObserver::ClearObserverState() { |
| 303 if (state_ == NOT_RECORDING_URLS && preview_infobar_delegate_) { |
| 304 InfoBarService* infobar_service = |
| 305 InfoBarService::FromWebContents(web_contents()); |
| 306 infobar_service->RemoveInfoBar(preview_infobar_delegate_); |
| 307 preview_infobar_delegate_ = NULL; |
| 308 } |
| 309 navigated_urls_.clear(); |
| 310 last_url_ = GURL(); |
| 311 state_ = RECORDING_URLS_BEFORE_PREVIEW; |
| 312 RemoveTemporaryException(); |
| 313 } |
| 314 |
| 315 void ManagedModeNavigationObserver::NavigateToPendingEntry( |
| 316 const GURL& url, |
| 317 content::NavigationController::ReloadType reload_type) { |
| 318 |
| 319 // This method gets called first when a user navigates to a (new) URL. |
| 320 // This means that the data related to the list of URLs needs to be cleared |
| 321 // in certain circumstances. |
| 322 if (web_contents()->GetController().GetCurrentEntryIndex() < |
| 323 last_allowed_page_ || !CanTemporarilyNavigateHost(url)) { |
| 324 ClearObserverState(); |
| 325 } |
| 326 } |
| 327 |
| 328 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
| 329 const content::LoadCommittedDetails& details, |
| 330 const content::FrameNavigateParams& params) { |
| 331 |
| 332 ManagedModeURLFilter::FilteringBehavior behavior = |
| 333 url_filter_->GetFilteringBehaviorForURL(params.url); |
| 334 |
| 335 // If the user just saw an interstitial this is the final URL so it is |
| 336 // recorded. Checking for filtering behavior here isn't useful because |
| 337 // although this specific URL can be allowed the hostname will be added which |
| 338 // is more general. The hostname will be checked later when it is |
| 339 // added to the actual whitelist to see if it is already present. |
| 340 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) |
| 341 AddURLAsLastPattern(params.url); |
| 342 |
| 343 if (behavior == ManagedModeURLFilter::ALLOW && |
| 344 state_ != RECORDING_URLS_BEFORE_PREVIEW) { |
| 345 // The initial page that triggered the interstitial was blocked but the |
| 346 // final page is already in the whitelist so add the series of URLs |
| 347 // which lead to the final page to the whitelist as well. |
| 348 AddSavedURLsToWhitelistAndClearState(); |
| 349 InfoBarService* infobar_service = |
| 350 InfoBarService::FromWebContents(web_contents()); |
| 351 infobar_service->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 352 infobar_service, |
| 353 NULL, |
| 354 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), |
| 355 true)); |
| 356 return; |
| 357 } |
| 358 |
| 359 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { |
| 360 // A temporary exception should be added only if an interstitial was shown, |
| 361 // the user clicked preview and the final page was not allowed. This |
| 362 // temporary exception stops the interstitial from showing on further |
| 363 // navigations to that host so that the user can navigate around to |
| 364 // inspect it. |
| 365 state_ = NOT_RECORDING_URLS; |
| 366 AddTemporaryException(); |
| 367 } |
| 368 } |
| 369 |
| 370 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( |
| 371 int64 frame_id, |
| 372 int64 parent_frame_id, |
| 373 bool is_main_frame, |
| 374 const GURL& url, |
| 375 bool is_error_page, |
| 376 content::RenderViewHost* render_view_host) { |
| 377 if (!is_main_frame) |
| 378 return; |
| 379 } |
| 380 |
| 381 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
| 382 const GURL& url, |
| 383 content::RenderViewHost* render_view_host) { |
| 384 // This function is the last one to be called before the resource throttle |
| 385 // shows the interstitial if the URL must be blocked. |
| 386 ManagedModeURLFilter::FilteringBehavior behavior = |
| 387 url_filter_->GetFilteringBehaviorForURL(url); |
| 388 |
| 389 if (state_ == NOT_RECORDING_URLS && !CanTemporarilyNavigateHost(url)) |
| 390 ClearObserverState(); |
| 391 |
| 392 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) |
| 393 AddURLToPatternList(url); |
| 394 } |
| 395 |
127 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 396 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
128 int64 frame_id, | 397 int64 frame_id, |
129 bool is_main_frame, | 398 bool is_main_frame, |
130 const GURL& url, | 399 const GURL& url, |
131 content::PageTransition transition_type, | 400 content::PageTransition transition_type, |
132 content::RenderViewHost* render_view_host) { | 401 content::RenderViewHost* render_view_host) { |
133 if (!is_main_frame) | 402 if (!is_main_frame) |
134 return; | 403 return; |
135 | 404 |
136 ManagedModeURLFilter::FilteringBehavior behavior = | 405 ManagedModeURLFilter::FilteringBehavior behavior = |
137 url_filter_->GetFilteringBehaviorForURL(url); | 406 url_filter_->GetFilteringBehaviorForURL(url); |
138 | 407 |
139 if (behavior == ManagedModeURLFilter::WARN) { | 408 if (behavior == ManagedModeURLFilter::WARN) { |
140 if (!warn_infobar_delegate_) { | 409 if (!warn_infobar_delegate_) { |
141 InfoBarService* infobar_service = | 410 InfoBarService* infobar_service = |
142 InfoBarService::FromWebContents(web_contents()); | 411 InfoBarService::FromWebContents(web_contents()); |
143 warn_infobar_delegate_ = | 412 warn_infobar_delegate_ = |
144 new ManagedModeWarningInfobarDelegate(infobar_service); | 413 new ManagedModeWarningInfobarDelegate(infobar_service, |
| 414 last_allowed_page_); |
145 infobar_service->AddInfoBar(warn_infobar_delegate_); | 415 infobar_service->AddInfoBar(warn_infobar_delegate_); |
146 } | 416 } |
147 } else { | 417 } else { |
148 if (warn_infobar_delegate_) { | 418 if (warn_infobar_delegate_) { |
149 InfoBarService* infobar_service = | 419 InfoBarService* infobar_service = |
150 InfoBarService::FromWebContents(web_contents()); | 420 InfoBarService::FromWebContents(web_contents()); |
151 infobar_service->RemoveInfoBar(warn_infobar_delegate_); | 421 infobar_service->RemoveInfoBar(warn_infobar_delegate_); |
152 warn_infobar_delegate_= NULL; | 422 warn_infobar_delegate_ = NULL; |
153 } | 423 } |
154 } | 424 } |
155 | 425 |
| 426 if (behavior == ManagedModeURLFilter::BLOCK) { |
| 427 switch (state_) { |
| 428 case RECORDING_URLS_BEFORE_PREVIEW: |
| 429 // Should not be in this state with a blocked URL. |
| 430 NOTREACHED(); |
| 431 break; |
| 432 case RECORDING_URLS_AFTER_PREVIEW: |
| 433 // Add the infobar. |
| 434 if (!preview_infobar_delegate_) { |
| 435 InfoBarService* infobar_service = |
| 436 InfoBarService::FromWebContents(web_contents()); |
| 437 preview_infobar_delegate_ = |
| 438 new ManagedModePreviewInfobarDelegate(infobar_service); |
| 439 infobar_service->AddInfoBar(preview_infobar_delegate_); |
| 440 } |
| 441 break; |
| 442 case NOT_RECORDING_URLS: |
| 443 // Check that the infobar is present. |
| 444 DCHECK(preview_infobar_delegate_); |
| 445 break; |
| 446 } |
| 447 } |
| 448 |
| 449 if (behavior == ManagedModeURLFilter::ALLOW) |
| 450 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
156 } | 451 } |
OLD | NEW |