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/simple_alert_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
11 #include "chrome/browser/infobars/infobar_tab_helper.h" | 11 #include "chrome/browser/infobars/infobar_tab_helper.h" |
12 #include "chrome/browser/managed_mode/managed_mode.h" | 12 #include "chrome/browser/managed_mode/managed_mode.h" |
13 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | 13 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
14 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | |
14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 15 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
18 #include "chrome/common/jstemplate_builder.h" | 19 #include "chrome/common/jstemplate_builder.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/browser_thread.h" | |
23 #include "content/public/browser/render_process_host.h" | |
24 #include "content/public/browser/render_view_host.h" | |
21 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
22 #include "content/public/common/frame_navigate_params.h" | 26 #include "content/public/common/frame_navigate_params.h" |
23 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
24 #include "grit/locale_settings.h" | 28 #include "grit/locale_settings.h" |
25 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
26 | 30 |
31 using content::BrowserThread; | |
32 | |
27 namespace { | 33 namespace { |
28 | 34 |
29 bool IsInList(const ListValue *list, const std::string& url_to_add) { | |
30 return list->Find(*Value::CreateStringValue(url_to_add)) != list->end(); | |
31 } | |
32 | |
33 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { | 35 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { |
34 public: | 36 public: |
35 explicit ManagedModeWarningInfobarDelegate( | 37 explicit ManagedModeWarningInfobarDelegate( |
36 InfoBarTabHelper* infobar_tab_helper, | 38 InfoBarTabHelper* infobar_tab_helper, |
37 int last_allowed_page); | 39 int last_allowed_page); |
38 | 40 |
39 private: | 41 private: |
40 virtual ~ManagedModeWarningInfobarDelegate(); | 42 virtual ~ManagedModeWarningInfobarDelegate(); |
41 | 43 |
42 // ConfirmInfoBarDelegate overrides: | 44 // ConfirmInfoBarDelegate overrides: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } | 152 } |
151 | 153 |
152 int ManagedModePreviewInfobarDelegate::GetButtons() const { | 154 int ManagedModePreviewInfobarDelegate::GetButtons() const { |
153 return BUTTON_OK | BUTTON_CANCEL; | 155 return BUTTON_OK | BUTTON_CANCEL; |
154 } | 156 } |
155 | 157 |
156 string16 ManagedModePreviewInfobarDelegate::GetButtonLabel( | 158 string16 ManagedModePreviewInfobarDelegate::GetButtonLabel( |
157 InfoBarButton button) const { | 159 InfoBarButton button) const { |
158 return l10n_util::GetStringUTF16( | 160 return l10n_util::GetStringUTF16( |
159 (button == BUTTON_OK) ? IDS_MANAGED_MODE_PREVIEW_ACCEPT | 161 (button == BUTTON_OK) ? IDS_MANAGED_MODE_PREVIEW_ACCEPT |
160 : IDS_MANAGED_MODE_PREVIEW_CANCEL); | 162 : IDS_MANAGED_MODE_GO_BACK_ACTION); |
161 } | 163 } |
162 | 164 |
163 bool ManagedModePreviewInfobarDelegate::Accept() { | 165 bool ManagedModePreviewInfobarDelegate::Accept() { |
164 ManagedModeNavigationObserver* observer = | 166 ManagedModeNavigationObserver* observer = |
165 ManagedModeNavigationObserver::FromWebContents( | 167 ManagedModeNavigationObserver::FromWebContents( |
166 owner()->GetWebContents()); | 168 owner()->GetWebContents()); |
167 observer->AddURLList(); | 169 observer->AddSavedURLsToWhitelist(); |
168 // Clear the pointer as the infobar was closed. | 170 // Notify the navigation observer that the infobar was dismissed. |
169 observer->PreviewInfobarDismissed(); | 171 observer->ClearObserverState(); |
170 | 172 |
171 return true; | 173 return true; |
172 } | 174 } |
173 | 175 |
174 bool ManagedModePreviewInfobarDelegate::Cancel() { | 176 bool ManagedModePreviewInfobarDelegate::Cancel() { |
175 // TODO(bauerb): Go back to the last page. | 177 // TODO(bauerb): Go back to the last page. |
178 ManagedModeNavigationObserver* observer = | |
179 ManagedModeNavigationObserver::FromWebContents( | |
180 owner()->GetWebContents()); | |
181 observer->ClearObserverState(); | |
176 return false; | 182 return false; |
177 } | 183 } |
178 | 184 |
179 bool ManagedModePreviewInfobarDelegate::ShouldExpire( | 185 bool ManagedModePreviewInfobarDelegate::ShouldExpire( |
180 const content::LoadCommittedDetails& details) const { | 186 const content::LoadCommittedDetails& details) const { |
181 // ManagedModeNavigationObserver removes us below. | 187 // ManagedModeNavigationObserver removes us below. |
182 return false; | 188 return false; |
183 } | 189 } |
184 | 190 |
185 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { | 191 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { |
186 ManagedModeNavigationObserver* observer = | 192 ManagedModeNavigationObserver* observer = |
187 ManagedModeNavigationObserver::FromWebContents( | 193 ManagedModeNavigationObserver::FromWebContents( |
188 owner()->GetWebContents()); | 194 owner()->GetWebContents()); |
189 observer->PreviewInfobarDismissed(); | 195 observer->PreviewInfobarDismissed(); |
190 } | 196 } |
191 | 197 |
198 // Taken from shill_manager_client.cc as ListValue returns a const_iterator | |
199 // in its Find method. | |
200 struct ValueEquals { | |
201 explicit ValueEquals(const Value* first) : first_(first) {} | |
202 bool operator()(const Value* second) const { | |
203 return first_->Equals(second); | |
204 } | |
205 const Value* first_; | |
206 }; | |
207 | |
192 } // namespace | 208 } // namespace |
193 | 209 |
194 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) | 210 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) |
195 | 211 |
196 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {} | 212 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
213 RemoveTemporaryException(); | |
214 } | |
197 | 215 |
198 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 216 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
199 content::WebContents* web_contents) | 217 content::WebContents* web_contents) |
200 : WebContentsObserver(web_contents), | 218 : WebContentsObserver(web_contents), |
201 url_filter_(ManagedMode::GetURLFilterForUIThread()), | 219 url_filter_(ManagedMode::GetURLFilterForUIThread()), |
202 warn_infobar_delegate_(NULL), | 220 warn_infobar_delegate_(NULL), |
203 preview_infobar_delegate_(NULL), | 221 preview_infobar_delegate_(NULL), |
204 after_interstitial_(false), | 222 state_(RECORDING_URLS_BEFORE_PREVIEW), |
205 last_allowed_page_(-1) {} | 223 last_allowed_page_(-1) {} |
206 | 224 |
225 void ManagedModeNavigationObserver::AddTemporaryException() { | |
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
227 DCHECK(web_contents()); | |
228 | |
229 BrowserThread::PostTask( | |
230 BrowserThread::IO, | |
231 FROM_HERE, | |
232 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | |
233 web_contents()->GetRenderProcessHost()->GetID(), | |
234 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
235 last_url_pattern_)); | |
236 } | |
237 | |
238 void ManagedModeNavigationObserver::RemoveTemporaryException() { | |
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
240 // When closing the browser web_contents() may return NULL so guard against | |
241 // that. | |
242 if (!web_contents()) | |
243 return; | |
244 | |
245 BrowserThread::PostTask( | |
246 BrowserThread::IO, | |
247 FROM_HERE, | |
248 base::Bind(&ManagedModeResourceThrottle::RemoveTemporaryException, | |
249 web_contents()->GetRenderProcessHost()->GetID(), | |
250 web_contents()->GetRenderViewHost()->GetRoutingID())); | |
251 } | |
252 | |
207 void ManagedModeNavigationObserver::WarnInfobarDismissed() { | 253 void ManagedModeNavigationObserver::WarnInfobarDismissed() { |
208 DCHECK(warn_infobar_delegate_); | 254 DCHECK(warn_infobar_delegate_); |
209 warn_infobar_delegate_ = NULL; | 255 warn_infobar_delegate_ = NULL; |
210 } | 256 } |
211 | 257 |
212 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { | 258 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { |
213 DCHECK(preview_infobar_delegate_); | 259 DCHECK(preview_infobar_delegate_); |
214 preview_infobar_delegate_ = NULL; | 260 preview_infobar_delegate_ = NULL; |
215 } | 261 } |
216 | 262 |
217 void ManagedModeNavigationObserver::AddNavigatedURL(const GURL& url) { | 263 void ManagedModeNavigationObserver::AddSavedURLsToWhitelist() { |
218 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) != | 264 if (!url_patterns_.empty()) |
219 navigated_urls_.end()) { | 265 ManagedMode::AddToManualWhitelist(url_patterns_); |
220 navigated_urls_.push_back(url); | 266 ListValue whitelist; |
267 whitelist.AppendString(last_url_pattern_); | |
Bernhard Bauer
2012/12/03 10:23:37
Append all the url_patterns_ to |whitelist|, then
Sergiu
2012/12/04 14:02:31
Refactored with GURLs now.
| |
268 ManagedMode::AddToManualWhitelist(whitelist); | |
269 } | |
270 | |
271 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | |
272 DCHECK(state_ != NOT_RECORDING_URLS); | |
273 | |
274 std::string current_url = url.scheme() + "://." + url.host(); | |
275 | |
276 url_patterns_.AppendIfNotPresent(new StringValue(current_url)); | |
277 } | |
278 | |
279 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { | |
280 DCHECK(state_ != NOT_RECORDING_URLS); | |
281 | |
282 // Search for the last |url| to see if present in the |url_patterns_| | |
Bernhard Bauer
2012/12/03 10:23:37
Nit: "[…] to see if it is present […]"
Sergiu
2012/12/04 14:02:31
Done.
| |
283 // and remove it from there if it is. |url| has to be converted to the | |
284 // |url_patterns_| format first. This stops us from having both | |
285 // http://.www.google.com (exact URL from the pattern list) and | |
286 // www.google.com (hostname from the last URL pattern) in the list. | |
287 base::StringValue value_to_find(url.scheme() + "://." + url.host()); | |
Bernhard Bauer
2012/12/03 10:23:37
It might be worth it to extract this to a method.
Sergiu
2012/12/04 14:02:31
Refactored, see new version.
| |
288 base::ListValue::iterator it = | |
289 std::find_if(url_patterns_.begin(), url_patterns_.end(), | |
Bernhard Bauer
2012/12/03 10:23:37
I think this would be a lot easier if you'd store
Sergiu
2012/12/04 14:02:31
Done, back to set<GURL> now which I think is bette
| |
290 ValueEquals(&value_to_find)); | |
291 if (it != url_patterns_.end()) | |
292 url_patterns_.Erase(it, NULL); | |
293 | |
294 if (url.SchemeIs("https")) { | |
295 last_url_pattern_ = "https://" + url.host(); | |
296 } else { | |
297 last_url_pattern_ = url.host(); | |
221 } | 298 } |
222 } | 299 } |
223 | 300 |
224 void ManagedModeNavigationObserver::AddURLList() { | 301 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { |
225 // Get a copy of the whitelist since it can't be edited in place. | 302 state_ = RECORDING_URLS_AFTER_PREVIEW; |
226 // |whitelist| is the preference list while AddStringToManualWhitelist adds | 303 } |
227 // the navigated urls to the URL filter. | |
228 scoped_ptr<base::ListValue> whitelist( | |
229 ManagedMode::GetWhitelist()->DeepCopy()); | |
230 std::string url_to_add; | |
231 int added_url_count = 0; | |
232 | 304 |
233 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); | 305 void ManagedModeNavigationObserver::ClearObserverState() { |
234 it+1 != navigated_urls_.end(); ++it) { | 306 if (state_ == NOT_RECORDING_URLS && preview_infobar_delegate_) { |
235 url_to_add = it->spec(); | |
236 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { | |
237 DLOG(ERROR) << "Adding (exact):" << url_to_add; | |
238 ManagedMode::AddStringToManualWhitelist(url_to_add); | |
239 whitelist->Append(Value::CreateStringValue(url_to_add)); | |
240 ++added_url_count; | |
241 } | |
242 } | |
243 | |
244 // If the URL uses https add the protocol as well instead of just the | |
245 // hostname. | |
246 if (navigated_urls_.back().SchemeIs("https")) { | |
247 url_to_add = navigated_urls_.back().GetOrigin().spec(); | |
248 } else { | |
249 url_to_add = navigated_urls_.back().host(); | |
250 } | |
251 | |
252 // Use the local whitelist to see if this last URL is already there. | |
253 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { | |
254 DLOG(ERROR) << "Adding (hostname): " << url_to_add; | |
255 ManagedMode::AddStringToManualWhitelist(url_to_add); | |
256 whitelist->Append(Value::CreateStringValue(url_to_add)); | |
257 ++added_url_count; | |
258 } else { | |
259 // Tell the user that the site was already present in the whitelist. | |
260 InfoBarTabHelper* infobar_tab_helper = | 307 InfoBarTabHelper* infobar_tab_helper = |
261 InfoBarTabHelper::FromWebContents(web_contents()); | 308 InfoBarTabHelper::FromWebContents(web_contents()); |
262 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | 309 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); |
263 infobar_tab_helper, | 310 preview_infobar_delegate_ = NULL; |
264 NULL, | |
265 l10n_util::GetStringFUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE, | |
266 base::IntToString16(added_url_count)), | |
267 true)); | |
268 } | 311 } |
269 | 312 url_patterns_.Clear(); |
270 ManagedMode::SetWhitelist(whitelist.get()); | 313 last_url_pattern_ = ""; |
314 state_ = RECORDING_URLS_BEFORE_PREVIEW; | |
315 RemoveTemporaryException(); | |
271 } | 316 } |
272 | 317 |
273 void ManagedModeNavigationObserver::NavigateToPendingEntry( | 318 void ManagedModeNavigationObserver::NavigateToPendingEntry( |
274 const GURL& url, | 319 const GURL& url, |
275 content::NavigationController::ReloadType reload_type) { | 320 content::NavigationController::ReloadType reload_type) { |
276 DLOG(ERROR) << "NavigateToPendingEntry: " << url; | 321 DLOG(ERROR) << "NavigateToPendingEntry: " << url; |
277 // This means that a new navigation was instantiated and the data related to | 322 |
278 // the list of URLs needs to be cleared. | 323 // This method gets called first when a user navigates to a (new) URL. |
279 navigated_urls_.clear(); | 324 // This means that the data related to the list of URLs needs to be cleared |
280 after_interstitial_ = false; | 325 // in certain circumstances. |
326 if (web_contents()->GetController().GetCurrentEntryIndex() < | |
327 last_allowed_page_ || | |
Bernhard Bauer
2012/12/03 10:23:37
Nit: Indent this four more spaces?
Sergiu
2012/12/04 14:02:31
Done.
| |
328 last_url_pattern_ != url.host()) { | |
Bernhard Bauer
2012/12/03 10:23:37
If url is HTTPS, this check won't be correct, I th
Sergiu
2012/12/04 14:02:31
Nice catch, done.
| |
329 ClearObserverState(); | |
330 } | |
281 } | 331 } |
282 | 332 |
283 void ManagedModeNavigationObserver::DidNavigateMainFrame( | 333 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
284 const content::LoadCommittedDetails& details, | 334 const content::LoadCommittedDetails& details, |
285 const content::FrameNavigateParams& params) { | 335 const content::FrameNavigateParams& params) { |
286 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; | 336 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; |
287 | 337 |
288 ManagedModeURLFilter::FilteringBehavior behavior = | 338 ManagedModeURLFilter::FilteringBehavior behavior = |
289 url_filter_->GetFilteringBehaviorForURL(params.url); | 339 url_filter_->GetFilteringBehaviorForURL(params.url); |
290 | 340 |
291 if (behavior != ManagedModeURLFilter::ALLOW) | 341 // If the user just saw an interstitial this is the final URL so it is |
292 AddNavigatedURL(params.url); | 342 // recorded. Checking for filtering behavior here isn't useful because |
343 // although this specific URL can be allowed the hostname will be added which | |
344 // is more general. The hostname will be checked later when it is | |
345 // added to the actual whitelist to see if it is already present. | |
346 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
347 AddURLAsLastPattern(params.url); | |
293 | 348 |
294 if (behavior == ManagedModeURLFilter::ALLOW && after_interstitial_) { | 349 if (behavior == ManagedModeURLFilter::ALLOW && |
350 state_ != RECORDING_URLS_BEFORE_PREVIEW) { | |
295 // The initial page that triggered the interstitial was blocked but the | 351 // The initial page that triggered the interstitial was blocked but the |
296 // final page is already in the whitelist so add the series of URLs | 352 // final page is already in the whitelist so add the series of URLs |
297 // which lead to the final page to the whitelist as well. | 353 // which lead to the final page to the whitelist as well. |
298 AddURLList(); | 354 AddSavedURLsToWhitelist(); |
Bernhard Bauer
2012/12/03 10:23:37
Should we also reset the state here (or do that in
Sergiu
2012/12/04 14:02:31
Done, clearing the state in the AddSavedTo[...]
| |
355 InfoBarTabHelper* infobar_tab_helper = | |
356 InfoBarTabHelper::FromWebContents(web_contents()); | |
357 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
358 infobar_tab_helper, | |
359 NULL, | |
360 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), | |
361 true)); | |
Bernhard Bauer
2012/12/03 10:23:37
Nit: I think doing an early-return in this case wo
Sergiu
2012/12/04 14:02:31
Done.
| |
362 } else if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
363 // Only add an exception when the final page is not allowed. | |
Bernhard Bauer
2012/12/03 10:23:37
OK, I can infer that behavior != ALLOW if I think
Sergiu
2012/12/04 14:02:31
Done.
| |
364 state_ = NOT_RECORDING_URLS; | |
365 AddTemporaryException(); | |
299 } | 366 } |
300 } | 367 } |
301 | 368 |
302 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | 369 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( |
303 int64 frame_id, | 370 int64 frame_id, |
304 int64 parent_frame_id, | 371 int64 parent_frame_id, |
305 bool is_main_frame, | 372 bool is_main_frame, |
306 const GURL& url, | 373 const GURL& url, |
307 bool is_error_page, | 374 bool is_error_page, |
308 content::RenderViewHost* render_view_host) { | 375 content::RenderViewHost* render_view_host) { |
309 if (!is_main_frame) | 376 if (!is_main_frame) |
310 return; | 377 return; |
311 | 378 |
312 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; | 379 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; |
313 } | 380 } |
314 | 381 |
315 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 382 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
316 const GURL& url, | 383 const GURL& url, |
317 const GURL& opener_url, | 384 const GURL& opener_url, |
318 content::RenderViewHost* render_view_host) { | 385 content::RenderViewHost* render_view_host) { |
319 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; | 386 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; |
320 // Mark the fact that an interstitial will be triggered here if the URL | 387 // This function is the last one to be called before the resource throttle |
321 // must be blocked. | 388 // shows the interstitial if the URL must be blocked. |
322 ManagedModeURLFilter::FilteringBehavior behavior = | 389 ManagedModeURLFilter::FilteringBehavior behavior = |
323 url_filter_->GetFilteringBehaviorForURL(url); | 390 url_filter_->GetFilteringBehaviorForURL(url); |
324 if (behavior == ManagedModeURLFilter::BLOCK) | 391 |
325 after_interstitial_ = true; | 392 if (state_ == NOT_RECORDING_URLS && last_url_pattern_ != url.host()) |
326 if (behavior != ManagedModeURLFilter::ALLOW) | 393 ClearObserverState(); |
327 AddNavigatedURL(url); | 394 |
395 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
396 AddURLToPatternList(url); | |
328 } | 397 } |
329 | 398 |
330 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 399 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
331 int64 frame_id, | 400 int64 frame_id, |
332 bool is_main_frame, | 401 bool is_main_frame, |
333 const GURL& url, | 402 const GURL& url, |
334 content::PageTransition transition_type, | 403 content::PageTransition transition_type, |
335 content::RenderViewHost* render_view_host) { | 404 content::RenderViewHost* render_view_host) { |
336 if (!is_main_frame) | 405 if (!is_main_frame) |
337 return; | 406 return; |
338 | 407 |
339 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; | 408 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; |
340 ManagedModeURLFilter::FilteringBehavior behavior = | 409 ManagedModeURLFilter::FilteringBehavior behavior = |
341 url_filter_->GetFilteringBehaviorForURL(url); | 410 url_filter_->GetFilteringBehaviorForURL(url); |
342 | 411 |
343 DLOG(ERROR) << "Current behavior: " << behavior; | |
344 if (behavior == ManagedModeURLFilter::WARN) { | 412 if (behavior == ManagedModeURLFilter::WARN) { |
345 if (!warn_infobar_delegate_) { | 413 if (!warn_infobar_delegate_) { |
346 InfoBarTabHelper* infobar_tab_helper = | 414 InfoBarTabHelper* infobar_tab_helper = |
347 InfoBarTabHelper::FromWebContents(web_contents()); | 415 InfoBarTabHelper::FromWebContents(web_contents()); |
348 warn_infobar_delegate_ = | 416 warn_infobar_delegate_ = |
349 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, | 417 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, |
350 last_allowed_page_); | 418 last_allowed_page_); |
351 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); | 419 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); |
352 } | 420 } |
353 } else { | 421 } else { |
354 if (warn_infobar_delegate_) { | 422 if (warn_infobar_delegate_) { |
355 InfoBarTabHelper* infobar_tab_helper = | 423 InfoBarTabHelper* infobar_tab_helper = |
356 InfoBarTabHelper::FromWebContents(web_contents()); | 424 InfoBarTabHelper::FromWebContents(web_contents()); |
357 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); | 425 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); |
358 warn_infobar_delegate_= NULL; | 426 warn_infobar_delegate_ = NULL; |
359 } | 427 } |
360 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
361 } | 428 } |
362 | 429 |
363 if (behavior == ManagedModeURLFilter::BLOCK) { | 430 if (state_ != RECORDING_URLS_BEFORE_PREVIEW && |
431 behavior == ManagedModeURLFilter::BLOCK) { | |
Bernhard Bauer
2012/12/03 10:23:37
Hm, we committed a load for a site that should be
Sergiu
2012/12/04 14:02:31
Actually checking that we're in AFTER_PREVIEW shou
Bernhard Bauer
2012/12/04 14:25:00
What I meant was that if we commit a navigation fo
Sergiu
2012/12/04 15:45:46
Done.
| |
364 if (!preview_infobar_delegate_) { | 432 if (!preview_infobar_delegate_) { |
365 InfoBarTabHelper* infobar_tab_helper = | 433 InfoBarTabHelper* infobar_tab_helper = |
366 InfoBarTabHelper::FromWebContents(web_contents()); | 434 InfoBarTabHelper::FromWebContents(web_contents()); |
367 preview_infobar_delegate_ = | 435 preview_infobar_delegate_ = |
368 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); | 436 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); |
369 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); | 437 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); |
370 } | 438 } |
371 } else { | 439 } |
372 if (preview_infobar_delegate_) { | 440 |
373 InfoBarTabHelper* infobar_tab_helper = | 441 if (behavior == ManagedModeURLFilter::ALLOW) { |
374 InfoBarTabHelper::FromWebContents(web_contents()); | 442 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
375 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); | |
376 preview_infobar_delegate_= NULL; | |
377 } | |
378 } | 443 } |
379 } | 444 } |
OLD | NEW |