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" | |
| 8 #include "base/i18n/rtl.h" | |
| 9 #include "base/string_number_conversions.h" | |
| 7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| 8 #include "chrome/browser/api/infobars/infobar_service.h" | 11 #include "chrome/browser/api/infobars/infobar_service.h" |
| 12 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" | |
| 9 #include "chrome/browser/managed_mode/managed_mode.h" | 13 #include "chrome/browser/managed_mode/managed_mode.h" |
| 14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | |
| 15 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | |
| 10 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 16 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/common/jstemplate_builder.h" | |
| 24 #include "chrome/common/pref_names.h" | |
| 15 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/browser_thread.h" | |
| 27 #include "content/public/browser/render_process_host.h" | |
| 28 #include "content/public/browser/render_view_host.h" | |
| 16 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
| 17 #include "content/public/common/frame_navigate_params.h" | 30 #include "content/public/common/frame_navigate_params.h" |
| 18 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "grit/locale_settings.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 20 | 34 |
| 35 using content::BrowserThread; | |
| 36 | |
| 21 namespace { | 37 namespace { |
| 22 | 38 |
| 23 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { | 39 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { |
| 24 public: | 40 public: |
| 25 // Creates a managed mode warning delegate and adds it to |infobar_service|. | 41 // Creates a managed mode warning delegate and adds it to |infobar_service|. |
| 26 // Returns the delegate if it was successfully added. | 42 // Returns the delegate if it was successfully added. |
| 27 static InfoBarDelegate* Create(InfoBarService* infobar_service); | 43 static InfoBarDelegate* Create(InfoBarService* infobar_service, |
| 44 int last_allowed_page); | |
| 28 | 45 |
| 29 private: | 46 private: |
| 30 explicit ManagedModeWarningInfobarDelegate(InfoBarService* infobar_service); | 47 explicit ManagedModeWarningInfobarDelegate(InfoBarService* infobar_service, |
| 48 int last_allowed_page); | |
| 31 virtual ~ManagedModeWarningInfobarDelegate(); | 49 virtual ~ManagedModeWarningInfobarDelegate(); |
| 32 | 50 |
| 33 // ConfirmInfoBarDelegate overrides: | 51 // ConfirmInfoBarDelegate overrides: |
| 34 virtual string16 GetMessageText() const OVERRIDE; | 52 virtual string16 GetMessageText() const OVERRIDE; |
| 35 virtual int GetButtons() const OVERRIDE; | 53 virtual int GetButtons() const OVERRIDE; |
| 36 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 54 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 37 virtual bool Accept() OVERRIDE; | 55 virtual bool Accept() OVERRIDE; |
| 38 virtual bool Cancel() OVERRIDE; | 56 virtual bool Cancel() OVERRIDE; |
| 39 | 57 |
| 40 // InfoBarDelegate override: | 58 // InfoBarDelegate override: |
| 41 virtual bool ShouldExpire( | 59 virtual bool ShouldExpire( |
| 42 const content::LoadCommittedDetails& details) const OVERRIDE; | 60 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 43 virtual void InfoBarDismissed() OVERRIDE; | 61 virtual void InfoBarDismissed() OVERRIDE; |
| 44 | 62 |
| 63 int last_allowed_page_; | |
| 64 | |
| 45 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfobarDelegate); | 65 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfobarDelegate); |
| 46 }; | 66 }; |
| 47 | 67 |
| 48 void GoBackToSafety(content::WebContents* web_contents) { | 68 void GoBackToSafety(content::WebContents* web_contents) { |
| 49 // For now, just go back one page (the user didn't retreat from that page, | 69 // For now, just go back one page (the user didn't retreat from that page, |
| 50 // so it should be okay). | 70 // so it should be okay). |
| 51 content::NavigationController* controller = | 71 content::NavigationController* controller = |
| 52 &web_contents->GetController(); | 72 &web_contents->GetController(); |
| 53 if (controller->CanGoBack()) { | 73 if (controller->CanGoBack()) { |
| 54 controller->GoBack(); | 74 controller->GoBack(); |
| 55 return; | 75 return; |
| 56 } | 76 } |
| 57 | 77 |
| 58 // If we can't go back (because we opened a new tab), try to close the tab. | 78 // If we can't go back (because we opened a new tab), try to close the tab. |
| 59 // If this is the last tab, open a new window. | 79 // If this is the last tab, open a new window. |
| 60 if (BrowserList::size() == 1) { | 80 if (BrowserList::size() == 1) { |
| 61 Browser* browser = *(BrowserList::begin()); | 81 Browser* browser = *(BrowserList::begin()); |
| 62 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); | 82 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); |
| 63 if (browser->tab_count() == 1) | 83 if (browser->tab_count() == 1) |
| 64 chrome::NewEmptyWindow(browser->profile()); | 84 chrome::NewEmptyWindow(browser->profile()); |
| 65 } | 85 } |
| 66 | 86 |
| 67 web_contents->GetDelegate()->CloseContents(web_contents); | 87 web_contents->GetDelegate()->CloseContents(web_contents); |
| 68 } | 88 } |
| 69 | 89 |
| 70 // static | 90 // static |
| 71 InfoBarDelegate* ManagedModeWarningInfobarDelegate::Create( | 91 InfoBarDelegate* ManagedModeWarningInfobarDelegate::Create( |
| 72 InfoBarService* infobar_service) { | 92 InfoBarService* infobar_service, int last_allowed_page) { |
| 73 return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 93 return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 74 new ManagedModeWarningInfobarDelegate(infobar_service))); | 94 new ManagedModeWarningInfobarDelegate(infobar_service, |
| 95 last_allowed_page))); | |
|
Pam (message me for reviews)
2013/01/09 12:00:41
nit: Ugh. Could you please use a local variable or
Sergiu
2013/01/09 13:04:23
Done.
| |
| 75 } | 96 } |
| 76 | 97 |
| 77 ManagedModeWarningInfobarDelegate::ManagedModeWarningInfobarDelegate( | 98 ManagedModeWarningInfobarDelegate::ManagedModeWarningInfobarDelegate( |
| 78 InfoBarService* infobar_service) | 99 InfoBarService* infobar_service, |
| 79 : ConfirmInfoBarDelegate(infobar_service) {} | 100 int last_allowed_page) |
| 101 : ConfirmInfoBarDelegate(infobar_service), | |
| 102 last_allowed_page_(last_allowed_page) {} | |
| 80 | 103 |
| 81 ManagedModeWarningInfobarDelegate::~ManagedModeWarningInfobarDelegate() {} | 104 ManagedModeWarningInfobarDelegate::~ManagedModeWarningInfobarDelegate() {} |
| 82 | 105 |
| 83 string16 ManagedModeWarningInfobarDelegate::GetMessageText() const { | 106 string16 ManagedModeWarningInfobarDelegate::GetMessageText() const { |
| 84 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_WARNING_MESSAGE); | 107 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_WARNING_MESSAGE); |
| 85 } | 108 } |
| 86 | 109 |
| 87 int ManagedModeWarningInfobarDelegate::GetButtons() const { | 110 int ManagedModeWarningInfobarDelegate::GetButtons() const { |
| 88 return BUTTON_OK; | 111 return BUTTON_OK; |
| 89 } | 112 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 110 // ManagedModeNavigationObserver removes us below. | 133 // ManagedModeNavigationObserver removes us below. |
| 111 return false; | 134 return false; |
| 112 } | 135 } |
| 113 | 136 |
| 114 void ManagedModeWarningInfobarDelegate::InfoBarDismissed() { | 137 void ManagedModeWarningInfobarDelegate::InfoBarDismissed() { |
| 115 ManagedModeNavigationObserver* observer = | 138 ManagedModeNavigationObserver* observer = |
| 116 ManagedModeNavigationObserver::FromWebContents(owner()->GetWebContents()); | 139 ManagedModeNavigationObserver::FromWebContents(owner()->GetWebContents()); |
| 117 observer->WarnInfobarDismissed(); | 140 observer->WarnInfobarDismissed(); |
| 118 } | 141 } |
| 119 | 142 |
| 143 class ManagedModePreviewInfobarDelegate : public ConfirmInfoBarDelegate { | |
| 144 public: | |
| 145 // Creates a managed mode preview delegate and adds it to |infobar_service|. | |
| 146 // Returns the delegate if it was successfully added. | |
| 147 static InfoBarDelegate* Create(InfoBarService* infobar_service); | |
| 148 | |
| 149 private: | |
| 150 explicit ManagedModePreviewInfobarDelegate(InfoBarService* infobar_service); | |
| 151 virtual ~ManagedModePreviewInfobarDelegate(); | |
| 152 | |
| 153 // ConfirmInfoBarDelegate overrides: | |
| 154 virtual string16 GetMessageText() const OVERRIDE; | |
| 155 virtual int GetButtons() const OVERRIDE; | |
| 156 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 157 virtual bool Accept() OVERRIDE; | |
| 158 virtual bool Cancel() OVERRIDE; | |
| 159 | |
| 160 // InfoBarDelegate override: | |
| 161 virtual bool ShouldExpire( | |
| 162 const content::LoadCommittedDetails& details) const OVERRIDE; | |
| 163 virtual void InfoBarDismissed() OVERRIDE; | |
| 164 | |
| 165 DISALLOW_COPY_AND_ASSIGN(ManagedModePreviewInfobarDelegate); | |
| 166 }; | |
| 167 | |
| 168 // static | |
| 169 InfoBarDelegate* ManagedModePreviewInfobarDelegate::Create( | |
| 170 InfoBarService* infobar_service) { | |
| 171 return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | |
|
Pam (message me for reviews)
2013/01/09 12:00:41
Same here.
Sergiu
2013/01/09 13:04:23
Done.
Sergiu
2013/01/09 13:04:23
Done.
| |
| 172 new ManagedModePreviewInfobarDelegate(infobar_service))); | |
| 173 } | |
| 174 | |
| 175 ManagedModePreviewInfobarDelegate::ManagedModePreviewInfobarDelegate( | |
| 176 InfoBarService* infobar_service) | |
| 177 : ConfirmInfoBarDelegate(infobar_service) {} | |
| 178 | |
| 179 ManagedModePreviewInfobarDelegate::~ManagedModePreviewInfobarDelegate() {} | |
| 180 | |
| 181 string16 ManagedModePreviewInfobarDelegate::GetMessageText() const { | |
| 182 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_PREVIEW_MESSAGE); | |
| 183 } | |
| 184 | |
| 185 int ManagedModePreviewInfobarDelegate::GetButtons() const { | |
| 186 return BUTTON_OK | BUTTON_CANCEL; | |
| 187 } | |
| 188 | |
| 189 string16 ManagedModePreviewInfobarDelegate::GetButtonLabel( | |
| 190 InfoBarButton button) const { | |
| 191 return l10n_util::GetStringUTF16( | |
| 192 (button == BUTTON_OK) ? IDS_MANAGED_MODE_PREVIEW_ACCEPT | |
| 193 : IDS_MANAGED_MODE_GO_BACK_ACTION); | |
| 194 } | |
| 195 | |
| 196 bool ManagedModePreviewInfobarDelegate::Accept() { | |
| 197 ManagedModeNavigationObserver* observer = | |
| 198 ManagedModeNavigationObserver::FromWebContents( | |
| 199 owner()->GetWebContents()); | |
| 200 observer->AddSavedURLsToWhitelistAndClearState(); | |
| 201 return true; | |
| 202 } | |
| 203 | |
| 204 bool ManagedModePreviewInfobarDelegate::Cancel() { | |
| 205 GoBackToSafety(owner()->GetWebContents()); | |
| 206 return false; | |
| 207 } | |
| 208 | |
| 209 bool ManagedModePreviewInfobarDelegate::ShouldExpire( | |
| 210 const content::LoadCommittedDetails& details) const { | |
| 211 // ManagedModeNavigationObserver removes us below. | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 215 void ManagedModePreviewInfobarDelegate::InfoBarDismissed() { | |
| 216 ManagedModeNavigationObserver* observer = | |
| 217 ManagedModeNavigationObserver::FromWebContents( | |
| 218 owner()->GetWebContents()); | |
| 219 observer->PreviewInfobarDismissed(); | |
| 220 } | |
| 221 | |
| 120 } // namespace | 222 } // namespace |
| 121 | 223 |
| 122 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); | 224 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); |
| 123 | 225 |
| 124 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {} | 226 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
| 227 RemoveTemporaryException(); | |
| 228 } | |
| 125 | 229 |
| 126 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 230 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
| 127 content::WebContents* web_contents) | 231 content::WebContents* web_contents) |
| 128 : WebContentsObserver(web_contents), | 232 : WebContentsObserver(web_contents), |
| 129 url_filter_(ManagedMode::GetURLFilterForUIThread()), | 233 url_filter_(ManagedMode::GetURLFilterForUIThread()), |
| 130 warn_infobar_delegate_(NULL) {} | 234 warn_infobar_delegate_(NULL), |
| 235 preview_infobar_delegate_(NULL), | |
| 236 state_(RECORDING_URLS_BEFORE_PREVIEW), | |
| 237 last_allowed_page_(-1) {} | |
| 238 | |
| 239 void ManagedModeNavigationObserver::AddTemporaryException() { | |
| 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 241 DCHECK(web_contents()); | |
| 242 | |
| 243 BrowserThread::PostTask( | |
| 244 BrowserThread::IO, | |
| 245 FROM_HERE, | |
| 246 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | |
| 247 web_contents()->GetRenderProcessHost()->GetID(), | |
| 248 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
| 249 last_url_)); | |
| 250 } | |
| 251 | |
| 252 void ManagedModeNavigationObserver::RemoveTemporaryException() { | |
| 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 254 // When closing the browser web_contents() may return NULL so guard against | |
| 255 // that. | |
| 256 if (!web_contents()) | |
| 257 return; | |
| 258 | |
| 259 BrowserThread::PostTask( | |
| 260 BrowserThread::IO, | |
| 261 FROM_HERE, | |
| 262 base::Bind(&ManagedModeResourceThrottle::RemoveTemporaryException, | |
| 263 web_contents()->GetRenderProcessHost()->GetID(), | |
| 264 web_contents()->GetRenderViewHost()->GetRoutingID())); | |
| 265 } | |
| 131 | 266 |
| 132 void ManagedModeNavigationObserver::WarnInfobarDismissed() { | 267 void ManagedModeNavigationObserver::WarnInfobarDismissed() { |
| 133 DCHECK(warn_infobar_delegate_); | 268 DCHECK(warn_infobar_delegate_); |
| 134 warn_infobar_delegate_ = NULL; | 269 warn_infobar_delegate_ = NULL; |
| 135 } | 270 } |
| 136 | 271 |
| 272 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { | |
| 273 DCHECK(preview_infobar_delegate_); | |
| 274 preview_infobar_delegate_ = NULL; | |
| 275 } | |
| 276 | |
| 277 void ManagedModeNavigationObserver::AddSavedURLsToWhitelistAndClearState() { | |
| 278 ListValue whitelist; | |
| 279 for (std::set<GURL>::const_iterator it = navigated_urls_.begin(); | |
| 280 it != navigated_urls_.end(); | |
| 281 ++it) { | |
| 282 whitelist.AppendString(it->scheme() + "://." + it->host() + it->path()); | |
| 283 } | |
| 284 if (last_url_.is_valid()) { | |
| 285 if (last_url_.SchemeIs("https")) { | |
| 286 whitelist.AppendString("https://" + last_url_.host()); | |
| 287 } else { | |
| 288 whitelist.AppendString(last_url_.host()); | |
| 289 } | |
| 290 } | |
| 291 ManagedMode::AddToManualList(true, whitelist); | |
| 292 ClearObserverState(); | |
| 293 } | |
| 294 | |
| 295 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | |
| 296 DCHECK(state_ != NOT_RECORDING_URLS); | |
| 297 navigated_urls_.insert(url); | |
| 298 } | |
| 299 | |
| 300 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { | |
| 301 DCHECK(state_ != NOT_RECORDING_URLS); | |
| 302 | |
| 303 // Erase the last |url| if it is present in the |navigated_urls_|. This stops | |
| 304 // us from having both http://.www.google.com (exact URL from the pattern | |
| 305 // list) and www.google.com (hostname from the last URL pattern) in the list. | |
| 306 navigated_urls_.erase(url); | |
| 307 last_url_ = url; | |
| 308 } | |
| 309 | |
| 310 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { | |
| 311 state_ = RECORDING_URLS_AFTER_PREVIEW; | |
| 312 } | |
| 313 | |
| 314 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( | |
| 315 const GURL& url) { | |
| 316 if (last_url_.scheme() == "https") { | |
| 317 return url.scheme() == "https" && last_url_.host() == url.host(); | |
| 318 } | |
| 319 return last_url_.host() == url.host(); | |
| 320 } | |
| 321 | |
| 322 void ManagedModeNavigationObserver::ClearObserverState() { | |
| 323 if (state_ == NOT_RECORDING_URLS && preview_infobar_delegate_) { | |
| 324 InfoBarService* infobar_service = | |
| 325 InfoBarService::FromWebContents(web_contents()); | |
| 326 infobar_service->RemoveInfoBar(preview_infobar_delegate_); | |
| 327 preview_infobar_delegate_ = NULL; | |
| 328 } | |
| 329 navigated_urls_.clear(); | |
| 330 last_url_ = GURL(); | |
| 331 state_ = RECORDING_URLS_BEFORE_PREVIEW; | |
| 332 RemoveTemporaryException(); | |
| 333 } | |
| 334 | |
| 335 void ManagedModeNavigationObserver::NavigateToPendingEntry( | |
| 336 const GURL& url, | |
| 337 content::NavigationController::ReloadType reload_type) { | |
| 338 | |
| 339 // This method gets called first when a user navigates to a (new) URL. | |
| 340 // This means that the data related to the list of URLs needs to be cleared | |
| 341 // in certain circumstances. | |
| 342 if (web_contents()->GetController().GetCurrentEntryIndex() < | |
| 343 last_allowed_page_ || !CanTemporarilyNavigateHost(url)) { | |
| 344 ClearObserverState(); | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 void ManagedModeNavigationObserver::DidNavigateMainFrame( | |
| 349 const content::LoadCommittedDetails& details, | |
| 350 const content::FrameNavigateParams& params) { | |
| 351 | |
| 352 ManagedModeURLFilter::FilteringBehavior behavior = | |
| 353 url_filter_->GetFilteringBehaviorForURL(params.url); | |
| 354 | |
| 355 // If the user just saw an interstitial this is the final URL so it is | |
| 356 // recorded. Checking for filtering behavior here isn't useful because | |
| 357 // although this specific URL can be allowed the hostname will be added which | |
| 358 // is more general. The hostname will be checked later when it is | |
| 359 // added to the actual whitelist to see if it is already present. | |
| 360 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
| 361 AddURLAsLastPattern(params.url); | |
| 362 | |
| 363 if (behavior == ManagedModeURLFilter::ALLOW && | |
| 364 state_ != RECORDING_URLS_BEFORE_PREVIEW) { | |
| 365 // The initial page that triggered the interstitial was blocked but the | |
| 366 // final page is already in the whitelist so add the series of URLs | |
| 367 // which lead to the final page to the whitelist as well. | |
| 368 AddSavedURLsToWhitelistAndClearState(); | |
| 369 SimpleAlertInfoBarDelegate::Create( | |
| 370 InfoBarService::FromWebContents(web_contents()), | |
| 371 NULL, | |
| 372 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), | |
| 373 true); | |
| 374 return; | |
| 375 } | |
| 376 | |
| 377 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
| 378 // A temporary exception should be added only if an interstitial was shown, | |
| 379 // the user clicked preview and the final page was not allowed. This | |
| 380 // temporary exception stops the interstitial from showing on further | |
| 381 // navigations to that host so that the user can navigate around to | |
| 382 // inspect it. | |
| 383 state_ = NOT_RECORDING_URLS; | |
| 384 AddTemporaryException(); | |
| 385 } | |
| 386 } | |
| 387 | |
| 388 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | |
| 389 int64 frame_id, | |
| 390 int64 parent_frame_id, | |
| 391 bool is_main_frame, | |
| 392 const GURL& validated_url, | |
| 393 bool is_error_page, | |
| 394 bool is_iframe_srcdoc, | |
| 395 content::RenderViewHost* render_view_host) { | |
| 396 if (!is_main_frame) | |
| 397 return; | |
| 398 } | |
| 399 | |
| 400 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | |
| 401 const GURL& url, | |
| 402 content::RenderViewHost* render_view_host) { | |
| 403 // This function is the last one to be called before the resource throttle | |
| 404 // shows the interstitial if the URL must be blocked. | |
| 405 ManagedModeURLFilter::FilteringBehavior behavior = | |
| 406 url_filter_->GetFilteringBehaviorForURL(url); | |
| 407 | |
| 408 if (state_ == NOT_RECORDING_URLS && !CanTemporarilyNavigateHost(url)) | |
| 409 ClearObserverState(); | |
| 410 | |
| 411 if (behavior == ManagedModeURLFilter::BLOCK && state_ != NOT_RECORDING_URLS) | |
| 412 AddURLToPatternList(url); | |
| 413 } | |
| 414 | |
| 137 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 415 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
| 138 int64 frame_id, | 416 int64 frame_id, |
| 139 bool is_main_frame, | 417 bool is_main_frame, |
| 140 const GURL& url, | 418 const GURL& url, |
| 141 content::PageTransition transition_type, | 419 content::PageTransition transition_type, |
| 142 content::RenderViewHost* render_view_host) { | 420 content::RenderViewHost* render_view_host) { |
| 143 if (!is_main_frame) | 421 if (!is_main_frame) |
| 144 return; | 422 return; |
| 145 | 423 |
| 146 ManagedModeURLFilter::FilteringBehavior behavior = | 424 ManagedModeURLFilter::FilteringBehavior behavior = |
| 147 url_filter_->GetFilteringBehaviorForURL(url); | 425 url_filter_->GetFilteringBehaviorForURL(url); |
| 148 | 426 |
| 149 if (behavior == ManagedModeURLFilter::WARN) { | 427 if (behavior == ManagedModeURLFilter::WARN) { |
| 150 if (!warn_infobar_delegate_) { | 428 if (!warn_infobar_delegate_) { |
| 151 warn_infobar_delegate_ = ManagedModeWarningInfobarDelegate::Create( | 429 warn_infobar_delegate_ = ManagedModeWarningInfobarDelegate::Create( |
| 152 InfoBarService::FromWebContents(web_contents())); | 430 InfoBarService::FromWebContents(web_contents()), last_allowed_page_); |
| 153 } | 431 } |
| 154 } else { | 432 } else { |
| 155 if (warn_infobar_delegate_) { | 433 if (warn_infobar_delegate_) { |
| 156 InfoBarService* infobar_service = | 434 InfoBarService* infobar_service = |
| 157 InfoBarService::FromWebContents(web_contents()); | 435 InfoBarService::FromWebContents(web_contents()); |
| 158 infobar_service->RemoveInfoBar(warn_infobar_delegate_); | 436 infobar_service->RemoveInfoBar(warn_infobar_delegate_); |
| 159 warn_infobar_delegate_= NULL; | 437 warn_infobar_delegate_ = NULL; |
| 160 } | 438 } |
| 161 } | 439 } |
| 162 | 440 |
| 441 if (behavior == ManagedModeURLFilter::BLOCK) { | |
| 442 switch (state_) { | |
| 443 case RECORDING_URLS_BEFORE_PREVIEW: | |
| 444 // Should not be in this state with a blocked URL. | |
| 445 NOTREACHED(); | |
| 446 break; | |
| 447 case RECORDING_URLS_AFTER_PREVIEW: | |
| 448 // Add the infobar. | |
| 449 if (!preview_infobar_delegate_) { | |
| 450 preview_infobar_delegate_ = | |
| 451 ManagedModePreviewInfobarDelegate::Create( | |
| 452 InfoBarService::FromWebContents(web_contents())); | |
| 453 } | |
| 454 break; | |
| 455 case NOT_RECORDING_URLS: | |
| 456 // Check that the infobar is present. | |
| 457 DCHECK(preview_infobar_delegate_); | |
| 458 break; | |
| 459 } | |
| 460 } | |
| 461 | |
| 462 if (behavior == ManagedModeURLFilter::ALLOW) | |
| 463 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | |
| 163 } | 464 } |
| OLD | NEW |