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_interstitial.h" | 5 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/base/webui/jstemplate_builder.h" | 31 #include "ui/base/webui/jstemplate_builder.h" |
| 32 #include "ui/base/webui/web_ui_util.h" | 32 #include "ui/base/webui/web_ui_util.h" |
| 33 | 33 |
| 34 using content::BrowserThread; | 34 using content::BrowserThread; |
| 35 | 35 |
| 36 ManagedModeInterstitial::~ManagedModeInterstitial() {} | |
| 37 | |
| 38 // static | |
| 39 void ManagedModeInterstitial::Show(content::WebContents* web_contents, | |
| 40 const GURL& url, | |
| 41 const base::Callback<void(bool)>& callback) { | |
| 42 ManagedModeInterstitial* interstitial = | |
| 43 new ManagedModeInterstitial(web_contents, url, callback); | |
| 44 | |
| 45 // If Init() does not complete fully, immediately delete the interstitial. | |
| 46 if (!interstitial->Init()) | |
| 47 delete interstitial; | |
| 48 // Else |interstitial_page_| is responsible for deleting it. | |
|
Bernhard Bauer
2014/04/25 11:10:18
Nit: "Otherwise" instead of "else".
Marc Treib
2014/04/25 12:02:19
Done.
| |
| 49 } | |
| 50 | |
| 36 ManagedModeInterstitial::ManagedModeInterstitial( | 51 ManagedModeInterstitial::ManagedModeInterstitial( |
| 37 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
| 38 const GURL& url, | 53 const GURL& url, |
| 39 const base::Callback<void(bool)>& callback) | 54 const base::Callback<void(bool)>& callback) |
| 40 : web_contents_(web_contents), | 55 : web_contents_(web_contents), |
| 41 interstitial_page_(NULL), | 56 interstitial_page_(NULL), |
| 42 url_(url), | 57 url_(url), |
| 43 callback_(callback) { | 58 callback_(callback) {} |
| 59 | |
| 60 bool ManagedModeInterstitial::Init() { | |
| 44 if (ShouldProceed()) { | 61 if (ShouldProceed()) { |
| 45 // It can happen that the site was only allowed very recently and the URL | 62 // It can happen that the site was only allowed very recently and the URL |
| 46 // filter on the IO thread had not been updated yet. Proceed with the | 63 // filter on the IO thread had not been updated yet. Proceed with the |
| 47 // request without showing the interstitial. | 64 // request without showing the interstitial. |
| 48 DispatchContinueRequest(true); | 65 DispatchContinueRequest(true); |
| 49 delete this; | 66 return false; |
| 50 return; | |
| 51 } | 67 } |
| 52 | 68 |
| 53 InfoBarService* service = InfoBarService::FromWebContents(web_contents); | 69 InfoBarService* service = InfoBarService::FromWebContents(web_contents_); |
| 54 if (service) { | 70 if (service) { |
| 55 // Remove all the infobars which are attached to |web_contents| and for | 71 // Remove all the infobars which are attached to |web_contents_| and for |
| 56 // which ShouldExpire() returns true. | 72 // which ShouldExpire() returns true. |
| 57 content::LoadCommittedDetails details; | 73 content::LoadCommittedDetails details; |
| 58 // |details.is_in_page| is default false, and |details.is_main_frame| is | 74 // |details.is_in_page| is default false, and |details.is_main_frame| is |
| 59 // default true. This results in is_navigation_to_different_page() returning | 75 // default true. This results in is_navigation_to_different_page() returning |
| 60 // true. | 76 // true. |
| 61 DCHECK(details.is_navigation_to_different_page()); | 77 DCHECK(details.is_navigation_to_different_page()); |
| 62 const content::NavigationController& controller = | 78 const content::NavigationController& controller = |
| 63 web_contents->GetController(); | 79 web_contents_->GetController(); |
| 64 details.entry = controller.GetActiveEntry(); | 80 details.entry = controller.GetActiveEntry(); |
| 65 if (controller.GetLastCommittedEntry()) { | 81 if (controller.GetLastCommittedEntry()) { |
| 66 details.previous_entry_index = controller.GetLastCommittedEntryIndex(); | 82 details.previous_entry_index = controller.GetLastCommittedEntryIndex(); |
| 67 details.previous_url = controller.GetLastCommittedEntry()->GetURL(); | 83 details.previous_url = controller.GetLastCommittedEntry()->GetURL(); |
| 68 } | 84 } |
| 69 details.type = content::NAVIGATION_TYPE_NEW_PAGE; | 85 details.type = content::NAVIGATION_TYPE_NEW_PAGE; |
| 70 for (int i = service->infobar_count() - 1; i >= 0; --i) { | 86 for (int i = service->infobar_count() - 1; i >= 0; --i) { |
| 71 infobars::InfoBar* infobar = service->infobar_at(i); | 87 infobars::InfoBar* infobar = service->infobar_at(i); |
| 72 if (infobar->delegate()->ShouldExpire( | 88 if (infobar->delegate()->ShouldExpire( |
| 73 InfoBarService::NavigationDetailsFromLoadCommittedDetails( | 89 InfoBarService::NavigationDetailsFromLoadCommittedDetails( |
| 74 details))) | 90 details))) |
| 75 service->RemoveInfoBar(infobar); | 91 service->RemoveInfoBar(infobar); |
| 76 } | 92 } |
| 77 } | 93 } |
| 78 | 94 |
| 79 // TODO(bauerb): Extract an observer callback on ManagedUserService for this. | 95 // TODO(bauerb): Extract an observer callback on ManagedUserService for this. |
| 80 Profile* profile = | 96 Profile* profile = |
| 81 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 97 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 82 PrefService* prefs = profile->GetPrefs(); | 98 PrefService* prefs = profile->GetPrefs(); |
| 83 pref_change_registrar_.Init(prefs); | 99 pref_change_registrar_.Init(prefs); |
| 84 pref_change_registrar_.Add( | 100 pref_change_registrar_.Add( |
| 85 prefs::kDefaultManagedModeFilteringBehavior, | 101 prefs::kDefaultManagedModeFilteringBehavior, |
| 86 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, | 102 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, |
| 87 base::Unretained(this))); | 103 base::Unretained(this))); |
| 88 pref_change_registrar_.Add( | 104 pref_change_registrar_.Add( |
| 89 prefs::kManagedModeManualHosts, | 105 prefs::kManagedModeManualHosts, |
| 90 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, | 106 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, |
| 91 base::Unretained(this))); | 107 base::Unretained(this))); |
| 92 pref_change_registrar_.Add( | 108 pref_change_registrar_.Add( |
| 93 prefs::kManagedModeManualURLs, | 109 prefs::kManagedModeManualURLs, |
| 94 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, | 110 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, |
| 95 base::Unretained(this))); | 111 base::Unretained(this))); |
| 96 | 112 |
| 97 languages_ = prefs->GetString(prefs::kAcceptLanguages); | 113 languages_ = prefs->GetString(prefs::kAcceptLanguages); |
| 98 interstitial_page_ = | 114 interstitial_page_ = |
| 99 content::InterstitialPage::Create(web_contents, true, url_, this); | 115 content::InterstitialPage::Create(web_contents_, true, url_, this); |
| 100 interstitial_page_->Show(); | 116 interstitial_page_->Show(); |
| 117 | |
| 118 return true; | |
| 101 } | 119 } |
| 102 | 120 |
| 103 ManagedModeInterstitial::~ManagedModeInterstitial() {} | |
| 104 | |
| 105 std::string ManagedModeInterstitial::GetHTMLContents() { | 121 std::string ManagedModeInterstitial::GetHTMLContents() { |
| 106 base::DictionaryValue strings; | 122 base::DictionaryValue strings; |
| 107 strings.SetString("blockPageTitle", | 123 strings.SetString("blockPageTitle", |
| 108 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); | 124 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); |
| 109 | 125 |
| 110 Profile* profile = | 126 Profile* profile = |
| 111 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 127 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 112 ManagedUserService* managed_user_service = | 128 ManagedUserService* managed_user_service = |
| 113 ManagedUserServiceFactory::GetForProfile(profile); | 129 ManagedUserServiceFactory::GetForProfile(profile); |
| 114 | 130 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 220 |
| 205 void ManagedModeInterstitial::OnFilteringPrefsChanged() { | 221 void ManagedModeInterstitial::OnFilteringPrefsChanged() { |
| 206 if (ShouldProceed()) | 222 if (ShouldProceed()) |
| 207 interstitial_page_->Proceed(); | 223 interstitial_page_->Proceed(); |
| 208 } | 224 } |
| 209 | 225 |
| 210 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { | 226 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { |
| 211 BrowserThread::PostTask( | 227 BrowserThread::PostTask( |
| 212 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); | 228 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
| 213 } | 229 } |
| OLD | NEW |