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/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
11 #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" | 12 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
13 #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" | 14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
15 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 15 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
16 #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/managed_mode/managed_user_service.h" |
| 18 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
22 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/common/jstemplate_builder.h" | 26 #include "chrome/common/jstemplate_builder.h" |
25 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 227 |
226 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); | 228 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); |
227 | 229 |
228 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { | 230 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
229 RemoveTemporaryException(); | 231 RemoveTemporaryException(); |
230 } | 232 } |
231 | 233 |
232 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 234 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
233 content::WebContents* web_contents) | 235 content::WebContents* web_contents) |
234 : WebContentsObserver(web_contents), | 236 : WebContentsObserver(web_contents), |
235 url_filter_(ManagedMode::GetURLFilterForUIThread()), | |
236 warn_infobar_delegate_(NULL), | 237 warn_infobar_delegate_(NULL), |
237 preview_infobar_delegate_(NULL), | 238 preview_infobar_delegate_(NULL), |
238 state_(RECORDING_URLS_BEFORE_PREVIEW), | 239 state_(RECORDING_URLS_BEFORE_PREVIEW), |
239 last_allowed_page_(-1) {} | 240 last_allowed_page_(-1) { |
| 241 Profile* profile = |
| 242 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 243 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); |
| 244 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); |
| 245 } |
240 | 246 |
241 void ManagedModeNavigationObserver::AddTemporaryException() { | 247 void ManagedModeNavigationObserver::AddTemporaryException() { |
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
243 DCHECK(web_contents()); | 249 DCHECK(web_contents()); |
244 | 250 |
245 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
246 BrowserThread::IO, | 252 BrowserThread::IO, |
247 FROM_HERE, | 253 FROM_HERE, |
248 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | 254 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, |
249 web_contents()->GetRenderProcessHost()->GetID(), | 255 web_contents()->GetRenderProcessHost()->GetID(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 ++it) { | 289 ++it) { |
284 whitelist.AppendString(it->scheme() + "://." + it->host() + it->path()); | 290 whitelist.AppendString(it->scheme() + "://." + it->host() + it->path()); |
285 } | 291 } |
286 if (last_url_.is_valid()) { | 292 if (last_url_.is_valid()) { |
287 if (last_url_.SchemeIs("https")) { | 293 if (last_url_.SchemeIs("https")) { |
288 whitelist.AppendString("https://" + last_url_.host()); | 294 whitelist.AppendString("https://" + last_url_.host()); |
289 } else { | 295 } else { |
290 whitelist.AppendString(last_url_.host()); | 296 whitelist.AppendString(last_url_.host()); |
291 } | 297 } |
292 } | 298 } |
293 ManagedMode::AddToManualList(true, whitelist); | 299 managed_user_service_->AddToManualList(true, whitelist); |
294 ClearObserverState(); | 300 ClearObserverState(); |
295 } | 301 } |
296 | 302 |
297 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | 303 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
298 DCHECK(state_ != NOT_RECORDING_URLS); | 304 DCHECK(state_ != NOT_RECORDING_URLS); |
299 navigated_urls_.insert(url); | 305 navigated_urls_.insert(url); |
300 } | 306 } |
301 | 307 |
302 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { | 308 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { |
303 DCHECK(state_ != NOT_RECORDING_URLS); | 309 DCHECK(state_ != NOT_RECORDING_URLS); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 case NOT_RECORDING_URLS: | 463 case NOT_RECORDING_URLS: |
458 // Check that the infobar is present. | 464 // Check that the infobar is present. |
459 DCHECK(preview_infobar_delegate_); | 465 DCHECK(preview_infobar_delegate_); |
460 break; | 466 break; |
461 } | 467 } |
462 } | 468 } |
463 | 469 |
464 if (behavior == ManagedModeURLFilter::ALLOW) | 470 if (behavior == ManagedModeURLFilter::ALLOW) |
465 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | 471 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
466 } | 472 } |
OLD | NEW |