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