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/supervised_user/supervised_user_navigation_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "chrome/browser/history/history_service.h" | 11 #include "chrome/browser/history/history_service.h" |
12 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
14 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
15 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | |
16 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | |
17 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | |
18 #include "chrome/browser/managed_mode/managed_user_service.h" | |
19 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | |
20 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" |
| 17 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h" |
| 18 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 19 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
21 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
22 #include "components/infobars/core/confirm_infobar_delegate.h" | 22 #include "components/infobars/core/confirm_infobar_delegate.h" |
23 #include "components/infobars/core/infobar.h" | 23 #include "components/infobars/core/infobar.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 Browser* browser = browser_list->get(0); | 68 Browser* browser = browser_list->get(0); |
69 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); | 69 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); |
70 if (browser->tab_strip_model()->count() == 1) | 70 if (browser->tab_strip_model()->count() == 1) |
71 chrome::NewEmptyWindow(browser->profile(), browser->host_desktop_type()); | 71 chrome::NewEmptyWindow(browser->profile(), browser->host_desktop_type()); |
72 } | 72 } |
73 | 73 |
74 web_contents->GetDelegate()->CloseContents(web_contents); | 74 web_contents->GetDelegate()->CloseContents(web_contents); |
75 } | 75 } |
76 #endif | 76 #endif |
77 | 77 |
78 // ManagedModeWarningInfoBarDelegate ------------------------------------------ | 78 // SupervisedUserWarningInfoBarDelegate --------------------------------------- |
79 | 79 |
80 class ManagedModeWarningInfoBarDelegate : public ConfirmInfoBarDelegate { | 80 class SupervisedUserWarningInfoBarDelegate : public ConfirmInfoBarDelegate { |
81 public: | 81 public: |
82 // Creates a managed mode warning infobar and delegate and adds the infobar to | 82 // Creates a supervised user warning infobar and delegate and adds the infobar |
83 // |infobar_service|. Returns the infobar if it was successfully added. | 83 // to |infobar_service|. Returns the infobar if it was successfully added. |
84 static infobars::InfoBar* Create(InfoBarService* infobar_service); | 84 static infobars::InfoBar* Create(InfoBarService* infobar_service); |
85 | 85 |
86 private: | 86 private: |
87 ManagedModeWarningInfoBarDelegate(); | 87 SupervisedUserWarningInfoBarDelegate(); |
88 virtual ~ManagedModeWarningInfoBarDelegate(); | 88 virtual ~SupervisedUserWarningInfoBarDelegate(); |
89 | 89 |
90 // ConfirmInfoBarDelegate: | 90 // ConfirmInfoBarDelegate: |
91 virtual bool ShouldExpire(const NavigationDetails& details) const OVERRIDE; | 91 virtual bool ShouldExpire(const NavigationDetails& details) const OVERRIDE; |
92 virtual void InfoBarDismissed() OVERRIDE; | 92 virtual void InfoBarDismissed() OVERRIDE; |
93 virtual base::string16 GetMessageText() const OVERRIDE; | 93 virtual base::string16 GetMessageText() const OVERRIDE; |
94 virtual int GetButtons() const OVERRIDE; | 94 virtual int GetButtons() const OVERRIDE; |
95 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 95 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
96 virtual bool Accept() OVERRIDE; | 96 virtual bool Accept() OVERRIDE; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfoBarDelegate); | 98 DISALLOW_COPY_AND_ASSIGN(SupervisedUserWarningInfoBarDelegate); |
99 }; | 99 }; |
100 | 100 |
101 // static | 101 // static |
102 infobars::InfoBar* ManagedModeWarningInfoBarDelegate::Create( | 102 infobars::InfoBar* SupervisedUserWarningInfoBarDelegate::Create( |
103 InfoBarService* infobar_service) { | 103 InfoBarService* infobar_service) { |
104 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 104 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
105 scoped_ptr<ConfirmInfoBarDelegate>( | 105 scoped_ptr<ConfirmInfoBarDelegate>( |
106 new ManagedModeWarningInfoBarDelegate()))); | 106 new SupervisedUserWarningInfoBarDelegate()))); |
107 } | 107 } |
108 | 108 |
109 ManagedModeWarningInfoBarDelegate::ManagedModeWarningInfoBarDelegate() | 109 SupervisedUserWarningInfoBarDelegate::SupervisedUserWarningInfoBarDelegate() |
110 : ConfirmInfoBarDelegate() { | 110 : ConfirmInfoBarDelegate() { |
111 } | 111 } |
112 | 112 |
113 ManagedModeWarningInfoBarDelegate::~ManagedModeWarningInfoBarDelegate() { | 113 SupervisedUserWarningInfoBarDelegate::~SupervisedUserWarningInfoBarDelegate() { |
114 } | 114 } |
115 | 115 |
116 bool ManagedModeWarningInfoBarDelegate::ShouldExpire( | 116 bool SupervisedUserWarningInfoBarDelegate::ShouldExpire( |
117 const NavigationDetails& details) const { | 117 const NavigationDetails& details) const { |
118 // ManagedModeNavigationObserver removes us below. | 118 // SupervisedUserNavigationObserver removes us below. |
119 return false; | 119 return false; |
120 } | 120 } |
121 | 121 |
122 void ManagedModeWarningInfoBarDelegate::InfoBarDismissed() { | 122 void SupervisedUserWarningInfoBarDelegate::InfoBarDismissed() { |
123 content::WebContents* web_contents = | 123 content::WebContents* web_contents = |
124 InfoBarService::WebContentsFromInfoBar(infobar()); | 124 InfoBarService::WebContentsFromInfoBar(infobar()); |
125 ManagedModeNavigationObserver::FromWebContents( | 125 SupervisedUserNavigationObserver::FromWebContents( |
126 web_contents)->WarnInfoBarDismissed(); | 126 web_contents)->WarnInfoBarDismissed(); |
127 } | 127 } |
128 | 128 |
129 base::string16 ManagedModeWarningInfoBarDelegate::GetMessageText() const { | 129 base::string16 SupervisedUserWarningInfoBarDelegate::GetMessageText() const { |
130 return l10n_util::GetStringUTF16(IDS_MANAGED_USER_WARN_INFOBAR_MESSAGE); | 130 return l10n_util::GetStringUTF16(IDS_MANAGED_USER_WARN_INFOBAR_MESSAGE); |
131 } | 131 } |
132 | 132 |
133 int ManagedModeWarningInfoBarDelegate::GetButtons() const { | 133 int SupervisedUserWarningInfoBarDelegate::GetButtons() const { |
134 return BUTTON_OK; | 134 return BUTTON_OK; |
135 } | 135 } |
136 | 136 |
137 base::string16 ManagedModeWarningInfoBarDelegate::GetButtonLabel( | 137 base::string16 SupervisedUserWarningInfoBarDelegate::GetButtonLabel( |
138 InfoBarButton button) const { | 138 InfoBarButton button) const { |
139 DCHECK_EQ(BUTTON_OK, button); | 139 DCHECK_EQ(BUTTON_OK, button); |
140 return l10n_util::GetStringUTF16(IDS_MANAGED_USER_WARN_INFOBAR_GO_BACK); | 140 return l10n_util::GetStringUTF16(IDS_MANAGED_USER_WARN_INFOBAR_GO_BACK); |
141 } | 141 } |
142 | 142 |
143 bool ManagedModeWarningInfoBarDelegate::Accept() { | 143 bool SupervisedUserWarningInfoBarDelegate::Accept() { |
144 #if defined(OS_ANDROID) | 144 #if defined(OS_ANDROID) |
145 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 145 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
146 // http://crbug.com/313377 | 146 // http://crbug.com/313377 |
147 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
148 #else | 148 #else |
149 GoBackToSafety(InfoBarService::WebContentsFromInfoBar(infobar())); | 149 GoBackToSafety(InfoBarService::WebContentsFromInfoBar(infobar())); |
150 #endif | 150 #endif |
151 | 151 |
152 return false; | 152 return false; |
153 } | 153 } |
154 | 154 |
155 | 155 |
156 } // namespace | 156 } // namespace |
157 | 157 |
158 // ManagedModeNavigationObserver ---------------------------------------------- | 158 // SupervisedUserNavigationObserver ------------------------------------------- |
159 | 159 |
160 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); | 160 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SupervisedUserNavigationObserver); |
161 | 161 |
162 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { | 162 SupervisedUserNavigationObserver::~SupervisedUserNavigationObserver() { |
163 } | 163 } |
164 | 164 |
165 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 165 SupervisedUserNavigationObserver::SupervisedUserNavigationObserver( |
166 content::WebContents* web_contents) | 166 content::WebContents* web_contents) |
167 : WebContentsObserver(web_contents), | 167 : WebContentsObserver(web_contents), |
168 warn_infobar_(NULL) { | 168 warn_infobar_(NULL) { |
169 Profile* profile = | 169 Profile* profile = |
170 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 170 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
171 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); | 171 supervised_user_service_ = |
172 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); | 172 SupervisedUserServiceFactory::GetForProfile(profile); |
| 173 url_filter_ = supervised_user_service_->GetURLFilterForUIThread(); |
173 } | 174 } |
174 | 175 |
175 void ManagedModeNavigationObserver::WarnInfoBarDismissed() { | 176 void SupervisedUserNavigationObserver::WarnInfoBarDismissed() { |
176 DCHECK(warn_infobar_); | 177 DCHECK(warn_infobar_); |
177 warn_infobar_ = NULL; | 178 warn_infobar_ = NULL; |
178 } | 179 } |
179 | 180 |
180 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 181 void SupervisedUserNavigationObserver::ProvisionalChangeToMainFrameUrl( |
181 const GURL& url, | 182 const GURL& url, |
182 content::RenderFrameHost* render_frame_host) { | 183 content::RenderFrameHost* render_frame_host) { |
183 ManagedModeURLFilter::FilteringBehavior behavior = | 184 SupervisedUserURLFilter::FilteringBehavior behavior = |
184 url_filter_->GetFilteringBehaviorForURL(url); | 185 url_filter_->GetFilteringBehaviorForURL(url); |
185 | 186 |
186 if (behavior == ManagedModeURLFilter::WARN || !warn_infobar_) | 187 if (behavior == SupervisedUserURLFilter::WARN || !warn_infobar_) |
187 return; | 188 return; |
188 | 189 |
189 // If we shouldn't have a warn infobar remove it here. | 190 // If we shouldn't have a warn infobar remove it here. |
190 InfoBarService::FromWebContents(web_contents())->RemoveInfoBar(warn_infobar_); | 191 InfoBarService::FromWebContents(web_contents())->RemoveInfoBar(warn_infobar_); |
191 warn_infobar_ = NULL; | 192 warn_infobar_ = NULL; |
192 } | 193 } |
193 | 194 |
194 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 195 void SupervisedUserNavigationObserver::DidCommitProvisionalLoadForFrame( |
195 int64 frame_id, | 196 int64 frame_id, |
196 const base::string16& frame_unique_name, | 197 const base::string16& frame_unique_name, |
197 bool is_main_frame, | 198 bool is_main_frame, |
198 const GURL& url, | 199 const GURL& url, |
199 content::PageTransition transition_type, | 200 content::PageTransition transition_type, |
200 content::RenderViewHost* render_view_host) { | 201 content::RenderViewHost* render_view_host) { |
201 if (!is_main_frame) | 202 if (!is_main_frame) |
202 return; | 203 return; |
203 | 204 |
204 DVLOG(1) << "DidCommitProvisionalLoadForFrame " << url.spec(); | 205 DVLOG(1) << "DidCommitProvisionalLoadForFrame " << url.spec(); |
205 ManagedModeURLFilter::FilteringBehavior behavior = | 206 SupervisedUserURLFilter::FilteringBehavior behavior = |
206 url_filter_->GetFilteringBehaviorForURL(url); | 207 url_filter_->GetFilteringBehaviorForURL(url); |
207 | 208 |
208 if (behavior == ManagedModeURLFilter::WARN && !warn_infobar_) { | 209 if (behavior == SupervisedUserURLFilter::WARN && !warn_infobar_) { |
209 warn_infobar_ = ManagedModeWarningInfoBarDelegate::Create( | 210 warn_infobar_ = SupervisedUserWarningInfoBarDelegate::Create( |
210 InfoBarService::FromWebContents(web_contents())); | 211 InfoBarService::FromWebContents(web_contents())); |
211 } | 212 } |
212 } | 213 } |
213 | 214 |
214 // static | 215 // static |
215 void ManagedModeNavigationObserver::OnRequestBlocked( | 216 void SupervisedUserNavigationObserver::OnRequestBlocked( |
216 int render_process_host_id, | 217 int render_process_host_id, |
217 int render_view_id, | 218 int render_view_id, |
218 const GURL& url, | 219 const GURL& url, |
219 const base::Callback<void(bool)>& callback) { | 220 const base::Callback<void(bool)>& callback) { |
220 content::WebContents* web_contents = | 221 content::WebContents* web_contents = |
221 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); | 222 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); |
222 if (!web_contents) { | 223 if (!web_contents) { |
223 content::BrowserThread::PostTask( | 224 content::BrowserThread::PostTask( |
224 content::BrowserThread::IO, FROM_HERE, base::Bind(callback, false)); | 225 content::BrowserThread::IO, FROM_HERE, base::Bind(callback, false)); |
225 return; | 226 return; |
226 } | 227 } |
227 | 228 |
228 ManagedModeNavigationObserver* navigation_observer = | 229 SupervisedUserNavigationObserver* navigation_observer = |
229 ManagedModeNavigationObserver::FromWebContents(web_contents); | 230 SupervisedUserNavigationObserver::FromWebContents(web_contents); |
230 if (navigation_observer) | 231 if (navigation_observer) |
231 navigation_observer->OnRequestBlockedInternal(url); | 232 navigation_observer->OnRequestBlockedInternal(url); |
232 | 233 |
233 // Show the interstitial. | 234 // Show the interstitial. |
234 ManagedModeInterstitial::Show(web_contents, url, callback); | 235 SupervisedUserInterstitial::Show(web_contents, url, callback); |
235 } | 236 } |
236 | 237 |
237 void ManagedModeNavigationObserver::OnRequestBlockedInternal(const GURL& url) { | 238 void SupervisedUserNavigationObserver::OnRequestBlockedInternal( |
| 239 const GURL& url) { |
238 Time timestamp = Time::Now(); // TODO(bauerb): Use SaneTime when available. | 240 Time timestamp = Time::Now(); // TODO(bauerb): Use SaneTime when available. |
239 // Create a history entry for the attempt and mark it as such. | 241 // Create a history entry for the attempt and mark it as such. |
240 history::HistoryAddPageArgs add_page_args( | 242 history::HistoryAddPageArgs add_page_args( |
241 url, timestamp, web_contents(), 0, | 243 url, timestamp, web_contents(), 0, |
242 url, history::RedirectList(), | 244 url, history::RedirectList(), |
243 content::PAGE_TRANSITION_BLOCKED, history::SOURCE_BROWSED, | 245 content::PAGE_TRANSITION_BLOCKED, history::SOURCE_BROWSED, |
244 false); | 246 false); |
245 | 247 |
246 // Add the entry to the history database. | 248 // Add the entry to the history database. |
247 Profile* profile = | 249 Profile* profile = |
248 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 250 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
249 HistoryService* history_service = | 251 HistoryService* history_service = |
250 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); | 252 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); |
251 | 253 |
252 // |history_service| is null if saving history is disabled. | 254 // |history_service| is null if saving history is disabled. |
253 if (history_service) | 255 if (history_service) |
254 history_service->AddPage(add_page_args); | 256 history_service->AddPage(add_page_args); |
255 | 257 |
256 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 258 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
257 entry->SetVirtualURL(url); | 259 entry->SetVirtualURL(url); |
258 entry->SetTimestamp(timestamp); | 260 entry->SetTimestamp(timestamp); |
259 blocked_navigations_.push_back(entry.release()); | 261 blocked_navigations_.push_back(entry.release()); |
260 ManagedUserService* managed_user_service = | 262 SupervisedUserService* supervised_user_service = |
261 ManagedUserServiceFactory::GetForProfile(profile); | 263 SupervisedUserServiceFactory::GetForProfile(profile); |
262 managed_user_service->DidBlockNavigation(web_contents()); | 264 supervised_user_service->DidBlockNavigation(web_contents()); |
263 } | 265 } |
OLD | NEW |