Chromium Code Reviews| 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.h" | 5 #include "chrome/browser/managed_mode/managed_mode.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/public/pref_change_registrar.h" | 8 #include "base/prefs/public/pref_change_registrar.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | 13 #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
| 14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 15 #include "chrome/browser/policy/url_blacklist_manager.h" | |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/extensions/extension_set.h" | 24 #include "chrome/common/extensions/extension_set.h" |
| 23 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 56 | 58 |
| 57 void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists) { | 59 void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 59 task_runner_->PostTask(FROM_HERE, | 61 task_runner_->PostTask(FROM_HERE, |
| 60 base::Bind(&ManagedModeURLFilter::LoadWhitelists, | 62 base::Bind(&ManagedModeURLFilter::LoadWhitelists, |
| 61 base::Unretained(&url_filter_), | 63 base::Unretained(&url_filter_), |
| 62 base::Passed(&site_lists), | 64 base::Passed(&site_lists), |
| 63 base::Bind(&base::DoNothing))); | 65 base::Bind(&base::DoNothing))); |
| 64 } | 66 } |
| 65 | 67 |
| 68 void LoadManualLists(scoped_ptr<ListValue> whitelist, | |
|
Bernhard Bauer
2013/01/07 12:34:19
Can you name this SetManualLists? It's in line wit
Sergiu
2013/01/07 16:25:05
Done.
| |
| 69 scoped_ptr<ListValue> blacklist) { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 71 task_runner_->PostTask(FROM_HERE, | |
| 72 base::Bind(&ManagedModeURLFilter::SetManualLists, | |
| 73 base::Unretained(&url_filter_), | |
| 74 base::Passed(&whitelist), | |
| 75 base::Passed(&blacklist), | |
| 76 base::Bind(&base::DoNothing))); | |
| 77 } | |
| 78 | |
| 79 void AddURLPatternToManualList(const bool isWhitelist, | |
| 80 const std::string& url) { | |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 82 task_runner_->PostTask(FROM_HERE, | |
| 83 base::Bind(&ManagedModeURLFilter::AddURLPatternToManualList, | |
| 84 base::Unretained(&url_filter_), | |
| 85 isWhitelist, | |
| 86 url, | |
| 87 base::Bind(&base::DoNothing))); | |
| 88 } | |
| 89 | |
| 66 void ShutdownOnUIThread() { | 90 void ShutdownOnUIThread() { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 68 bool result = task_runner_->DeleteSoon(FROM_HERE, this); | 92 bool result = task_runner_->DeleteSoon(FROM_HERE, this); |
| 69 DCHECK(result); | 93 DCHECK(result); |
| 70 } | 94 } |
| 71 | 95 |
| 72 private: | 96 private: |
| 73 ManagedModeURLFilter url_filter_; | 97 ManagedModeURLFilter url_filter_; |
| 74 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 98 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 75 | 99 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 230 } |
| 207 | 231 |
| 208 const ManagedModeURLFilter* ManagedMode::GetURLFilterForIOThreadImpl() { | 232 const ManagedModeURLFilter* ManagedMode::GetURLFilterForIOThreadImpl() { |
| 209 return io_url_filter_context_->url_filter(); | 233 return io_url_filter_context_->url_filter(); |
| 210 } | 234 } |
| 211 | 235 |
| 212 const ManagedModeURLFilter* ManagedMode::GetURLFilterForUIThreadImpl() { | 236 const ManagedModeURLFilter* ManagedMode::GetURLFilterForUIThreadImpl() { |
| 213 return ui_url_filter_context_->url_filter(); | 237 return ui_url_filter_context_->url_filter(); |
| 214 } | 238 } |
| 215 | 239 |
| 240 // static | |
| 241 void ManagedMode::AddToManualList(const bool isWhitelist, | |
| 242 const URLPatternList& list) { | |
| 243 GetInstance()->AddToManualListImpl(isWhitelist, list); | |
| 244 } | |
| 245 | |
| 246 void ManagedMode::AddToManualListImpl(const bool isWhitelist, | |
| 247 const URLPatternList& list) { | |
| 248 if (!managed_profile_) | |
| 249 return; | |
| 250 | |
| 251 ListPrefUpdate pref_update(managed_profile_->GetPrefs(), | |
| 252 isWhitelist ? prefs::kManagedModeWhitelist : | |
| 253 prefs::kManagedModeBlacklist); | |
| 254 ListValue* pref_list = pref_update.Get(); | |
| 255 | |
| 256 for (size_t i = 0; i < list.GetSize(); ++i) { | |
| 257 std::string url_pattern; | |
| 258 list.GetString(i, &url_pattern); | |
| 259 | |
| 260 if (!IsInManualList(isWhitelist, url_pattern)) { | |
| 261 pref_list->AppendString(url_pattern); | |
| 262 AddURLPatternToManualList(isWhitelist, url_pattern); | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 // static | |
| 268 void ManagedMode::RemoveFromManualList(const bool isWhitelist, | |
| 269 const URLPatternList& list) { | |
| 270 GetInstance()->RemoveFromManualListImpl(isWhitelist, list); | |
| 271 } | |
| 272 | |
| 273 void ManagedMode::RemoveFromManualListImpl(const bool isWhitelist, | |
| 274 const URLPatternList& list) { | |
| 275 ListPrefUpdate pref_update(managed_profile_->GetPrefs(), | |
| 276 isWhitelist ? prefs::kManagedModeWhitelist : | |
| 277 prefs::kManagedModeBlacklist); | |
| 278 ListValue* pref_list = pref_update.Get(); | |
| 279 | |
| 280 for (size_t i = 0; i < list.GetSize(); ++i) { | |
| 281 std::string pattern; | |
| 282 size_t out_index; | |
| 283 list.GetString(i, &pattern); | |
| 284 StringValue value_to_remove(pattern); | |
| 285 DLOG(ERROR) << "Removing " << pattern; | |
| 286 | |
| 287 pref_list->Remove(value_to_remove, &out_index); | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 // static | |
| 292 bool ManagedMode::IsInManualList(const bool isWhitelist, | |
| 293 const std::string& url_pattern) { | |
| 294 return GetInstance()->IsInManualListImpl(isWhitelist, url_pattern); | |
| 295 } | |
| 296 | |
| 297 bool ManagedMode::IsInManualListImpl(const bool isWhitelist, | |
| 298 const std::string& url_pattern) { | |
| 299 StringValue pattern(url_pattern); | |
| 300 const ListValue* list = managed_profile_->GetPrefs()->GetList( | |
| 301 isWhitelist ? prefs::kManagedModeWhitelist : | |
| 302 prefs::kManagedModeBlacklist); | |
| 303 return list->Find(pattern) != list->end(); | |
| 304 } | |
| 305 | |
| 306 // static | |
| 307 scoped_ptr<ManagedMode::URLPatternList> ManagedMode::GetBlacklist() { | |
| 308 return scoped_ptr<URLPatternList>( | |
| 309 GetInstance()->managed_profile_->GetPrefs()->GetList( | |
| 310 prefs::kManagedModeBlacklist)->DeepCopy()).Pass(); | |
| 311 } | |
| 312 | |
| 216 std::string ManagedMode::GetDebugPolicyProviderName() const { | 313 std::string ManagedMode::GetDebugPolicyProviderName() const { |
| 217 // Save the string space in official builds. | 314 // Save the string space in official builds. |
| 218 #ifdef NDEBUG | 315 #ifdef NDEBUG |
| 219 NOTREACHED(); | 316 NOTREACHED(); |
| 220 return std::string(); | 317 return std::string(); |
| 221 #else | 318 #else |
| 222 return "Managed Mode"; | 319 return "Managed Mode"; |
| 223 #endif | 320 #endif |
| 224 } | 321 } |
| 225 | 322 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 if (in_managed_mode) { | 475 if (in_managed_mode) { |
| 379 int behavior_value = managed_profile_->GetPrefs()->GetInteger( | 476 int behavior_value = managed_profile_->GetPrefs()->GetInteger( |
| 380 prefs::kDefaultManagedModeFilteringBehavior); | 477 prefs::kDefaultManagedModeFilteringBehavior); |
| 381 behavior = ManagedModeURLFilter::BehaviorFromInt(behavior_value); | 478 behavior = ManagedModeURLFilter::BehaviorFromInt(behavior_value); |
| 382 } | 479 } |
| 383 io_url_filter_context_->SetDefaultFilteringBehavior(behavior); | 480 io_url_filter_context_->SetDefaultFilteringBehavior(behavior); |
| 384 ui_url_filter_context_->SetDefaultFilteringBehavior(behavior); | 481 ui_url_filter_context_->SetDefaultFilteringBehavior(behavior); |
| 385 g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode, | 482 g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode, |
| 386 in_managed_mode); | 483 in_managed_mode); |
| 387 if (in_managed_mode) | 484 if (in_managed_mode) |
| 388 UpdateWhitelist(); | 485 UpdateWhitelistImpl(); |
| 389 | 486 |
| 390 // This causes the avatar and the profile menu to get updated. | 487 // This causes the avatar and the profile menu to get updated. |
| 391 content::NotificationService::current()->Notify( | 488 content::NotificationService::current()->Notify( |
| 392 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 489 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 393 content::NotificationService::AllBrowserContextsAndSources(), | 490 content::NotificationService::AllBrowserContextsAndSources(), |
| 394 content::NotificationService::NoDetails()); | 491 content::NotificationService::NoDetails()); |
| 395 } | 492 } |
| 396 | 493 |
| 397 ScopedVector<ManagedModeSiteList> ManagedMode::GetActiveSiteLists() { | 494 ScopedVector<ManagedModeSiteList> ManagedMode::GetActiveSiteLists() { |
| 398 DCHECK(managed_profile_); | 495 DCHECK(managed_profile_); |
| 399 ScopedVector<ManagedModeSiteList> site_lists; | 496 ScopedVector<ManagedModeSiteList> site_lists; |
| 400 // TODO(bauerb): Get site lists from all extensions. | 497 // TODO(bauerb): Get site lists from all extensions. |
| 401 return site_lists.Pass(); | 498 return site_lists.Pass(); |
| 402 } | 499 } |
| 403 | 500 |
| 404 void ManagedMode::OnDefaultFilteringBehaviorChanged() { | 501 void ManagedMode::OnDefaultFilteringBehaviorChanged() { |
| 405 DCHECK(IsInManagedModeImpl()); | 502 DCHECK(IsInManagedModeImpl()); |
| 406 | 503 |
| 407 int behavior_value = managed_profile_->GetPrefs()->GetInteger( | 504 int behavior_value = managed_profile_->GetPrefs()->GetInteger( |
| 408 prefs::kDefaultManagedModeFilteringBehavior); | 505 prefs::kDefaultManagedModeFilteringBehavior); |
| 409 ManagedModeURLFilter::FilteringBehavior behavior = | 506 ManagedModeURLFilter::FilteringBehavior behavior = |
| 410 ManagedModeURLFilter::BehaviorFromInt(behavior_value); | 507 ManagedModeURLFilter::BehaviorFromInt(behavior_value); |
| 411 io_url_filter_context_->SetDefaultFilteringBehavior(behavior); | 508 io_url_filter_context_->SetDefaultFilteringBehavior(behavior); |
| 412 ui_url_filter_context_->SetDefaultFilteringBehavior(behavior); | 509 ui_url_filter_context_->SetDefaultFilteringBehavior(behavior); |
| 413 } | 510 } |
| 414 | 511 |
| 512 // Static | |
| 415 void ManagedMode::UpdateWhitelist() { | 513 void ManagedMode::UpdateWhitelist() { |
| 514 GetInstance()->UpdateWhitelistImpl(); | |
| 515 } | |
| 516 | |
| 517 void ManagedMode::UpdateWhitelistImpl() { | |
| 416 io_url_filter_context_->LoadWhitelists(GetActiveSiteLists()); | 518 io_url_filter_context_->LoadWhitelists(GetActiveSiteLists()); |
| 417 ui_url_filter_context_->LoadWhitelists(GetActiveSiteLists()); | 519 ui_url_filter_context_->LoadWhitelists(GetActiveSiteLists()); |
| 520 io_url_filter_context_->LoadManualLists(GetWhitelist(), GetBlacklist()); | |
| 521 ui_url_filter_context_->LoadManualLists(GetWhitelist(), GetBlacklist()); | |
| 418 } | 522 } |
| 523 | |
| 524 scoped_ptr<ManagedMode::URLPatternList> ManagedMode::GetWhitelist() { | |
| 525 return make_scoped_ptr( | |
| 526 managed_profile_->GetPrefs()->GetList( | |
| 527 prefs::kManagedModeWhitelist)->DeepCopy()); | |
| 528 } | |
| 529 | |
| 530 void ManagedMode::AddURLPatternToManualList( | |
|
Bernhard Bauer
2013/01/07 12:34:19
Please keep this method consistent with the style
Sergiu
2013/01/07 16:25:05
You were right, sorry.. it doesn't need to be stat
| |
| 531 const bool isWhitelist, | |
| 532 const std::string& url_pattern) { | |
| 533 GetInstance()->io_url_filter_context_->AddURLPatternToManualList( | |
| 534 true, url_pattern); | |
| 535 GetInstance()->ui_url_filter_context_->AddURLPatternToManualList( | |
| 536 true, url_pattern); | |
| 537 } | |
| OLD | NEW |