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 DLOG(ERROR) << "NavigateToPendingEntry: " << url; | |
Bernhard Bauer
2013/01/07 12:34:19
Remove these log statements before committing.
Sergiu
2013/01/07 16:25:05
Done.
| |
319 | |
320 // This method gets called first when a user navigates to a (new) URL. | |
321 // This means that the data related to the list of URLs needs to be cleared | |
322 // in certain circumstances. | |
323 if (web_contents()->GetController().GetCurrentEntryIndex() < | |
324 last_allowed_page_ || !CanTemporarilyNavigateHost(url)) { | |
325 ClearObserverState(); | |
326 } | |
327 } | |
328 | |
329 void ManagedModeNavigationObserver::DidNavigateMainFrame( | |
330 const content::LoadCommittedDetails& details, | |
331 const content::FrameNavigateParams& params) { | |
332 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; | |
333 | |
334 ManagedModeURLFilter::FilteringBehavior behavior = | |
335 url_filter_->GetFilteringBehaviorForURL(params.url); | |
336 | |
337 // If the user just saw an interstitial this is the final URL so it is | |
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 (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
343 AddURLAsLastPattern(params.url); | |
344 | |
345 if (behavior == ManagedModeURLFilter::ALLOW && | |
346 state_ != RECORDING_URLS_BEFORE_PREVIEW) { | |
347 // The initial page that triggered the interstitial was blocked but the | |
348 // final page is already in the whitelist so add the series of URLs | |
349 // which lead to the final page to the whitelist as well. | |
350 AddSavedURLsToWhitelistAndClearState(); | |
351 InfoBarService* infobar_service = | |
352 InfoBarService::FromWebContents(web_contents()); | |
353 infobar_service->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
354 infobar_service, | |
355 NULL, | |
356 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), | |
357 true)); | |
358 return; | |
359 } | |
360 | |
361 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
362 // A temporary exception should be added only if an interstitial was shown, | |
363 // the user clicked preview and the final page was not allowed. This | |
364 // temporary exception stops the interstitial from showing on further | |
365 // navigations to that host so that the user can navigate around to | |
366 // inspect it. | |
367 state_ = NOT_RECORDING_URLS; | |
368 AddTemporaryException(); | |
369 } | |
370 } | |
371 | |
372 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | |
373 int64 frame_id, | |
374 int64 parent_frame_id, | |
375 bool is_main_frame, | |
376 const GURL& url, | |
377 bool is_error_page, | |
378 content::RenderViewHost* render_view_host) { | |
379 if (!is_main_frame) | |
380 return; | |
381 | |
382 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; | |
383 } | |
384 | |
385 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | |
386 const GURL& url, | |
387 content::RenderViewHost* render_view_host) { | |
388 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; | |
389 // This function is the last one to be called before the resource throttle | |
390 // shows the interstitial if the URL must be blocked. | |
391 ManagedModeURLFilter::FilteringBehavior behavior = | |
392 url_filter_->GetFilteringBehaviorForURL(url); | |
393 | |
394 if (state_ == NOT_RECORDING_URLS && !CanTemporarilyNavigateHost(url)) | |
395 ClearObserverState(); | |
396 | |
397 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
398 AddURLToPatternList(url); | |
399 } | |
400 | |
127 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 401 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
128 int64 frame_id, | 402 int64 frame_id, |
129 bool is_main_frame, | 403 bool is_main_frame, |
130 const GURL& url, | 404 const GURL& url, |
131 content::PageTransition transition_type, | 405 content::PageTransition transition_type, |
132 content::RenderViewHost* render_view_host) { | 406 content::RenderViewHost* render_view_host) { |
133 if (!is_main_frame) | 407 if (!is_main_frame) |
134 return; | 408 return; |
135 | 409 |
410 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; | |
136 ManagedModeURLFilter::FilteringBehavior behavior = | 411 ManagedModeURLFilter::FilteringBehavior behavior = |
137 url_filter_->GetFilteringBehaviorForURL(url); | 412 url_filter_->GetFilteringBehaviorForURL(url); |
138 | 413 |
139 if (behavior == ManagedModeURLFilter::WARN) { | 414 if (behavior == ManagedModeURLFilter::WARN) { |
140 if (!warn_infobar_delegate_) { | 415 if (!warn_infobar_delegate_) { |
141 InfoBarService* infobar_service = | 416 InfoBarService* infobar_service = |
142 InfoBarService::FromWebContents(web_contents()); | 417 InfoBarService::FromWebContents(web_contents()); |
143 warn_infobar_delegate_ = | 418 warn_infobar_delegate_ = |
144 new ManagedModeWarningInfobarDelegate(infobar_service); | 419 new ManagedModeWarningInfobarDelegate(infobar_service, |
420 last_allowed_page_); | |
145 infobar_service->AddInfoBar(warn_infobar_delegate_); | 421 infobar_service->AddInfoBar(warn_infobar_delegate_); |
146 } | 422 } |
147 } else { | 423 } else { |
148 if (warn_infobar_delegate_) { | 424 if (warn_infobar_delegate_) { |
149 InfoBarService* infobar_service = | 425 InfoBarService* infobar_service = |
150 InfoBarService::FromWebContents(web_contents()); | 426 InfoBarService::FromWebContents(web_contents()); |
151 infobar_service->RemoveInfoBar(warn_infobar_delegate_); | 427 infobar_service->RemoveInfoBar(warn_infobar_delegate_); |
152 warn_infobar_delegate_= NULL; | 428 warn_infobar_delegate_ = NULL; |
153 } | 429 } |
154 } | 430 } |
155 | 431 |
432 if (behavior == ManagedModeURLFilter::BLOCK) { | |
433 switch (state_) { | |
434 case RECORDING_URLS_BEFORE_PREVIEW: | |
435 // Should not be in this state with a blocked URL. | |
436 NOTREACHED(); | |
437 break; | |
438 case RECORDING_URLS_AFTER_PREVIEW: | |
439 // Add the infobar. | |
440 if (!preview_infobar_delegate_) { | |
441 InfoBarService* infobar_service = | |
442 InfoBarService::FromWebContents(web_contents()); | |
443 preview_infobar_delegate_ = | |
444 new ManagedModePreviewInfobarDelegate(infobar_service); | |
445 infobar_service->AddInfoBar(preview_infobar_delegate_); | |
446 } | |
447 break; | |
448 case NOT_RECORDING_URLS: | |
449 // Check that the infobar is present. | |
450 DCHECK(preview_infobar_delegate_); | |
451 break; | |
452 default: | |
Bernhard Bauer
2013/01/07 12:34:19
The compiler will check for you that you handle al
Sergiu
2013/01/07 16:25:05
Done.
| |
453 NOTREACHED(); | |
454 } | |
455 } | |
456 | |
457 if (behavior == ManagedModeURLFilter::ALLOW) { | |
Bernhard Bauer
2013/01/07 12:34:19
Nit: Braces aren't necessary.
Sergiu
2013/01/07 16:25:05
Done.
| |
458 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
459 } | |
156 } | 460 } |
OLD | NEW |