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 "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 |
| 192 } // namespace | 198 } // namespace |
| 193 | 199 |
| 194 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) | 200 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver) |
| 195 | 201 |
| 196 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {} | 202 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
| 203 RemoveTemporaryException(); | |
| 204 } | |
| 197 | 205 |
| 198 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 206 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
| 199 content::WebContents* web_contents) | 207 content::WebContents* web_contents) |
| 200 : WebContentsObserver(web_contents), | 208 : WebContentsObserver(web_contents), |
| 201 url_filter_(ManagedMode::GetURLFilterForUIThread()), | 209 url_filter_(ManagedMode::GetURLFilterForUIThread()), |
| 210 state_(RECORDING_URLS_BEFORE_PREVIEW), | |
|
Bernhard Bauer
2012/11/27 18:44:46
Ohhhh! I was assuming that "not recording" is the
Sergiu
2012/11/28 12:53:25
By default we record all the URLs that are blackli
| |
| 202 warn_infobar_delegate_(NULL), | 211 warn_infobar_delegate_(NULL), |
| 203 preview_infobar_delegate_(NULL), | 212 preview_infobar_delegate_(NULL), |
| 204 after_interstitial_(false), | |
| 205 last_allowed_page_(-1) {} | 213 last_allowed_page_(-1) {} |
| 206 | 214 |
| 215 void ManagedModeNavigationObserver::AddTemporaryException() { | |
| 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 217 DCHECK(web_contents()); | |
| 218 | |
| 219 BrowserThread::PostTask( | |
| 220 BrowserThread::IO, | |
| 221 FROM_HERE, | |
| 222 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | |
| 223 web_contents()->GetRenderProcessHost()->GetID(), | |
| 224 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
| 225 navigated_urls_.back().host())); | |
| 226 } | |
| 227 | |
| 228 void ManagedModeNavigationObserver::RemoveTemporaryException() { | |
| 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 230 if (!web_contents()) | |
|
Bernhard Bauer
2012/11/27 18:44:46
Can you add a comment to explain when web_contents
Sergiu
2012/11/28 12:53:25
Done.
| |
| 231 return; | |
| 232 | |
| 233 BrowserThread::PostTask( | |
| 234 BrowserThread::IO, | |
| 235 FROM_HERE, | |
| 236 base::Bind(&ManagedModeResourceThrottle::RemoveTemporaryException, | |
| 237 web_contents()->GetRenderProcessHost()->GetID(), | |
| 238 web_contents()->GetRenderViewHost()->GetRoutingID())); | |
| 239 } | |
| 240 | |
| 207 void ManagedModeNavigationObserver::WarnInfobarDismissed() { | 241 void ManagedModeNavigationObserver::WarnInfobarDismissed() { |
| 208 DCHECK(warn_infobar_delegate_); | 242 DCHECK(warn_infobar_delegate_); |
| 209 warn_infobar_delegate_ = NULL; | 243 warn_infobar_delegate_ = NULL; |
| 210 } | 244 } |
| 211 | 245 |
| 212 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { | 246 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { |
| 213 DCHECK(preview_infobar_delegate_); | 247 DCHECK(preview_infobar_delegate_); |
| 214 preview_infobar_delegate_ = NULL; | 248 preview_infobar_delegate_ = NULL; |
| 215 } | 249 } |
| 216 | 250 |
| 217 void ManagedModeNavigationObserver::AddNavigatedURL(const GURL& url) { | 251 void ManagedModeNavigationObserver::AddSavedURLsToWhitelist() { |
| 218 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) != | 252 // |whitelist| is used to add the URLs to the preference list while |
| 219 navigated_urls_.end()) { | 253 // AddURLPatternToManualWhitelist adds the navigated urls to the URL filter. |
| 220 navigated_urls_.push_back(url); | 254 base::ListValue whitelist; |
| 221 } | 255 std::string pattern_to_add; |
| 222 } | 256 bool added_urls = false; |
| 223 | 257 |
| 224 void ManagedModeNavigationObserver::AddURLList() { | 258 if (!navigated_urls_.empty()) { |
| 225 // Get a copy of the whitelist since it can't be edited in place. | 259 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); |
| 226 // |whitelist| is the preference list while AddStringToManualWhitelist adds | 260 it+1 != navigated_urls_.end(); ++it) { |
| 227 // the navigated urls to the URL filter. | 261 GURL current_url = *it; |
| 228 scoped_ptr<base::ListValue> whitelist( | 262 GURL::Replacements replaced_components; |
| 229 ManagedMode::GetWhitelist()->DeepCopy()); | 263 // Add the . to match the exact host. |
| 230 std::string url_to_add; | 264 replaced_components.SetHostStr("." + it->host()); |
| 231 int added_url_count = 0; | 265 replaced_components.SetRefStr(""); |
| 266 replaced_components.SetSchemeStr(""); | |
| 267 current_url.ReplaceComponents(replaced_components); | |
| 268 pattern_to_add = current_url.spec(); | |
| 269 whitelist.AppendString(pattern_to_add); | |
| 270 } | |
| 232 | 271 |
| 233 for (std::vector<GURL>::const_iterator it = navigated_urls_.begin(); | 272 // Add the protocol as well if the URL uses HTTPS. Also, since this is the |
| 234 it+1 != navigated_urls_.end(); ++it) { | 273 // final destination, add the whole subdomain. |
| 235 url_to_add = it->spec(); | 274 if (navigated_urls_.back().SchemeIs("https")) { |
| 236 if (!IsInList(ManagedMode::GetWhitelist().get(), url_to_add)) { | 275 pattern_to_add = "https://" + navigated_urls_.back().host(); |
| 237 DLOG(ERROR) << "Adding (exact):" << url_to_add; | 276 } else { |
| 238 ManagedMode::AddStringToManualWhitelist(url_to_add); | 277 pattern_to_add = navigated_urls_.back().host(); |
| 239 whitelist->Append(Value::CreateStringValue(url_to_add)); | |
| 240 ++added_url_count; | |
| 241 } | 278 } |
| 279 | |
| 280 whitelist.AppendString(pattern_to_add); | |
| 281 | |
| 282 added_urls = ManagedMode::AddToManualWhitelist(whitelist); | |
| 242 } | 283 } |
| 243 | 284 |
| 244 // If the URL uses https add the protocol as well instead of just the | 285 if ((navigated_urls_.empty() || !added_urls) && |
| 245 // hostname. | 286 state_ != RECORDING_URLS_BEFORE_PREVIEW) { |
|
Bernhard Bauer
2012/11/27 18:44:46
So, IIUC we have multiple entry points to this met
Sergiu
2012/11/28 12:53:25
It should work, yes, I've refactored and simplifie
| |
| 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. | 287 // Tell the user that the site was already present in the whitelist. |
| 260 InfoBarTabHelper* infobar_tab_helper = | 288 InfoBarTabHelper* infobar_tab_helper = |
| 261 InfoBarTabHelper::FromWebContents(web_contents()); | 289 InfoBarTabHelper::FromWebContents(web_contents()); |
| 262 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | 290 infobar_tab_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 263 infobar_tab_helper, | 291 infobar_tab_helper, |
| 264 NULL, | 292 NULL, |
| 265 l10n_util::GetStringFUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE, | 293 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), |
| 266 base::IntToString16(added_url_count)), | |
| 267 true)); | 294 true)); |
| 268 } | 295 } |
| 269 | 296 |
| 270 ManagedMode::SetWhitelist(whitelist.get()); | 297 } |
| 298 void ManagedModeNavigationObserver::SaveNavigatedURL(const GURL& url) { | |
| 299 if (state_ == NOT_RECORDING_URLS) | |
| 300 return; | |
| 301 | |
| 302 if (std::find(navigated_urls_.begin(), navigated_urls_.end(), url) == | |
| 303 navigated_urls_.end()) { | |
| 304 navigated_urls_.push_back(url); | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 | |
| 309 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { | |
| 310 state_ = RECORDING_URLS_AFTER_PREVIEW; | |
| 311 } | |
| 312 | |
| 313 void ManagedModeNavigationObserver::ClearObserverState() { | |
| 314 if (state_ == NOT_RECORDING_URLS && preview_infobar_delegate_) { | |
| 315 InfoBarTabHelper* infobar_tab_helper = | |
| 316 InfoBarTabHelper::FromWebContents(web_contents()); | |
| 317 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); | |
| 318 preview_infobar_delegate_ = NULL; | |
| 319 } | |
| 320 navigated_urls_.clear(); | |
| 321 state_ = RECORDING_URLS_BEFORE_PREVIEW; | |
| 322 RemoveTemporaryException(); | |
| 271 } | 323 } |
| 272 | 324 |
| 273 void ManagedModeNavigationObserver::NavigateToPendingEntry( | 325 void ManagedModeNavigationObserver::NavigateToPendingEntry( |
| 274 const GURL& url, | 326 const GURL& url, |
| 275 content::NavigationController::ReloadType reload_type) { | 327 content::NavigationController::ReloadType reload_type) { |
| 276 DLOG(ERROR) << "NavigateToPendingEntry: " << url; | 328 DLOG(ERROR) << "NavigateToPendingEntry: " << url; |
| 277 // This means that a new navigation was instantiated and the data related to | 329 |
| 278 // the list of URLs needs to be cleared. | 330 // This method gets called first when a user navigates to a (new) URL. |
| 279 navigated_urls_.clear(); | 331 // This means that the data related to the list of URLs needs to be cleared |
| 280 after_interstitial_ = false; | 332 // in certain circumstances. |
| 333 if (web_contents()->GetController().GetCurrentEntryIndex() < | |
| 334 last_allowed_page_ || | |
| 335 navigated_urls_.empty() || | |
| 336 navigated_urls_.back().host() != url.host()) { | |
| 337 ClearObserverState(); | |
| 338 } | |
| 281 } | 339 } |
| 282 | 340 |
| 283 void ManagedModeNavigationObserver::DidNavigateMainFrame( | 341 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
| 284 const content::LoadCommittedDetails& details, | 342 const content::LoadCommittedDetails& details, |
| 285 const content::FrameNavigateParams& params) { | 343 const content::FrameNavigateParams& params) { |
| 286 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; | 344 DLOG(ERROR) << "DidNavigateMainFrame: " << params.url; |
| 287 | 345 |
| 288 ManagedModeURLFilter::FilteringBehavior behavior = | 346 ManagedModeURLFilter::FilteringBehavior behavior = |
| 289 url_filter_->GetFilteringBehaviorForURL(params.url); | 347 url_filter_->GetFilteringBehaviorForURL(params.url); |
| 290 | 348 |
| 291 if (behavior != ManagedModeURLFilter::ALLOW) | 349 if (state_ != NOT_RECORDING_URLS) |
| 292 AddNavigatedURL(params.url); | 350 SaveNavigatedURL(params.url); |
| 293 | 351 |
| 294 if (behavior == ManagedModeURLFilter::ALLOW && after_interstitial_) { | 352 if (behavior == ManagedModeURLFilter::ALLOW && |
| 353 state_ != RECORDING_URLS_BEFORE_PREVIEW) { | |
| 295 // The initial page that triggered the interstitial was blocked but the | 354 // 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 | 355 // 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. | 356 // which lead to the final page to the whitelist as well. |
| 298 AddURLList(); | 357 AddSavedURLsToWhitelist(); |
| 358 } | |
| 359 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
| 360 state_ = NOT_RECORDING_URLS; | |
| 361 AddTemporaryException(); | |
| 299 } | 362 } |
| 300 } | 363 } |
| 301 | 364 |
| 302 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | 365 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( |
| 303 int64 frame_id, | 366 int64 frame_id, |
| 304 int64 parent_frame_id, | 367 int64 parent_frame_id, |
| 305 bool is_main_frame, | 368 bool is_main_frame, |
| 306 const GURL& url, | 369 const GURL& url, |
| 307 bool is_error_page, | 370 bool is_error_page, |
| 308 content::RenderViewHost* render_view_host) { | 371 content::RenderViewHost* render_view_host) { |
| 309 if (!is_main_frame) | 372 if (!is_main_frame) |
| 310 return; | 373 return; |
| 311 | 374 |
| 312 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; | 375 DLOG(ERROR) << "DidStartProvisionalLoadForFrame: " << url; |
| 313 } | 376 } |
| 314 | 377 |
| 315 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 378 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
| 316 const GURL& url, | 379 const GURL& url, |
| 317 const GURL& opener_url, | 380 const GURL& opener_url, |
| 318 content::RenderViewHost* render_view_host) { | 381 content::RenderViewHost* render_view_host) { |
| 319 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; | 382 DLOG(ERROR) << "ProvisionalChangeToMainFrameUrl: " << url; |
| 320 // Mark the fact that an interstitial will be triggered here if the URL | 383 // This function is the last one to be called before the resource throttle |
| 321 // must be blocked. | 384 // shows the interstitial if the URL must be blocked. |
| 322 ManagedModeURLFilter::FilteringBehavior behavior = | 385 ManagedModeURLFilter::FilteringBehavior behavior = |
| 323 url_filter_->GetFilteringBehaviorForURL(url); | 386 url_filter_->GetFilteringBehaviorForURL(url); |
| 324 if (behavior == ManagedModeURLFilter::BLOCK) | 387 |
| 325 after_interstitial_ = true; | 388 if (!navigated_urls_.empty() && state_ == NOT_RECORDING_URLS && |
| 326 if (behavior != ManagedModeURLFilter::ALLOW) | 389 navigated_urls_.back().host() != url.host()) |
| 327 AddNavigatedURL(url); | 390 ClearObserverState(); |
| 391 | |
| 392 if (behavior != ManagedModeURLFilter::ALLOW && state_ != NOT_RECORDING_URLS) | |
| 393 SaveNavigatedURL(url); | |
| 328 } | 394 } |
| 329 | 395 |
| 330 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 396 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
| 331 int64 frame_id, | 397 int64 frame_id, |
| 332 bool is_main_frame, | 398 bool is_main_frame, |
| 333 const GURL& url, | 399 const GURL& url, |
| 334 content::PageTransition transition_type, | 400 content::PageTransition transition_type, |
| 335 content::RenderViewHost* render_view_host) { | 401 content::RenderViewHost* render_view_host) { |
| 336 if (!is_main_frame) | 402 if (!is_main_frame) |
| 337 return; | 403 return; |
| 338 | 404 |
| 339 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; | 405 DLOG(ERROR) << "DidCommitProvisionalLoadForFrame: " << url; |
| 340 ManagedModeURLFilter::FilteringBehavior behavior = | 406 ManagedModeURLFilter::FilteringBehavior behavior = |
| 341 url_filter_->GetFilteringBehaviorForURL(url); | 407 url_filter_->GetFilteringBehaviorForURL(url); |
| 342 | 408 |
| 343 DLOG(ERROR) << "Current behavior: " << behavior; | |
| 344 if (behavior == ManagedModeURLFilter::WARN) { | 409 if (behavior == ManagedModeURLFilter::WARN) { |
| 345 if (!warn_infobar_delegate_) { | 410 if (!warn_infobar_delegate_) { |
| 346 InfoBarTabHelper* infobar_tab_helper = | 411 InfoBarTabHelper* infobar_tab_helper = |
| 347 InfoBarTabHelper::FromWebContents(web_contents()); | 412 InfoBarTabHelper::FromWebContents(web_contents()); |
| 348 warn_infobar_delegate_ = | 413 warn_infobar_delegate_ = |
| 349 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, | 414 new ManagedModeWarningInfobarDelegate(infobar_tab_helper, |
| 350 last_allowed_page_); | 415 last_allowed_page_); |
| 351 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); | 416 infobar_tab_helper->AddInfoBar(warn_infobar_delegate_); |
| 352 } | 417 } |
| 353 } else { | 418 } else { |
| 354 if (warn_infobar_delegate_) { | 419 if (warn_infobar_delegate_) { |
| 355 InfoBarTabHelper* infobar_tab_helper = | 420 InfoBarTabHelper* infobar_tab_helper = |
| 356 InfoBarTabHelper::FromWebContents(web_contents()); | 421 InfoBarTabHelper::FromWebContents(web_contents()); |
| 357 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); | 422 infobar_tab_helper->RemoveInfoBar(warn_infobar_delegate_); |
| 358 warn_infobar_delegate_= NULL; | 423 warn_infobar_delegate_ = NULL; |
| 359 } | 424 } |
| 360 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
| 361 } | 425 } |
| 362 | 426 |
| 363 if (behavior == ManagedModeURLFilter::BLOCK) { | 427 if (state_ != RECORDING_URLS_BEFORE_PREVIEW && |
| 428 behavior == ManagedModeURLFilter::BLOCK) { | |
| 364 if (!preview_infobar_delegate_) { | 429 if (!preview_infobar_delegate_) { |
| 365 InfoBarTabHelper* infobar_tab_helper = | 430 InfoBarTabHelper* infobar_tab_helper = |
| 366 InfoBarTabHelper::FromWebContents(web_contents()); | 431 InfoBarTabHelper::FromWebContents(web_contents()); |
| 367 preview_infobar_delegate_ = | 432 preview_infobar_delegate_ = |
| 368 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); | 433 new ManagedModePreviewInfobarDelegate(infobar_tab_helper); |
| 369 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); | 434 infobar_tab_helper->AddInfoBar(preview_infobar_delegate_); |
| 370 } | 435 } |
| 371 } else { | 436 } else { |
| 372 if (preview_infobar_delegate_) { | 437 if (preview_infobar_delegate_) { |
|
Bernhard Bauer
2012/11/27 18:44:46
Does this actually happen now or do we remove the
Sergiu
2012/11/28 12:53:25
No, it should be already removed every time we cle
| |
| 373 InfoBarTabHelper* infobar_tab_helper = | 438 InfoBarTabHelper* infobar_tab_helper = |
| 374 InfoBarTabHelper::FromWebContents(web_contents()); | 439 InfoBarTabHelper::FromWebContents(web_contents()); |
| 375 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); | 440 infobar_tab_helper->RemoveInfoBar(preview_infobar_delegate_); |
| 376 preview_infobar_delegate_= NULL; | 441 preview_infobar_delegate_ = NULL; |
| 377 } | 442 } |
| 378 } | 443 } |
| 444 | |
| 445 if (behavior == ManagedModeURLFilter::ALLOW) { | |
| 446 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
| 447 } | |
| 379 } | 448 } |
| OLD | NEW |