| 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/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "chrome/browser/history/history_service.h" | 11 #include "chrome/browser/history/history_service.h" |
| 12 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
| 13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
| 14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 14 #include "chrome/browser/infobars/content_confirm_infobar_delegate.h" |
| 15 #include "chrome/browser/infobars/infobar.h" | 15 #include "chrome/browser/infobars/infobar.h" |
| 16 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 17 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | 17 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| 18 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 18 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
| 19 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 19 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 20 #include "chrome/browser/managed_mode/managed_user_service.h" | 20 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/tab_contents/tab_util.h" | 23 #include "chrome/browser/tab_contents/tab_util.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (browser->tab_strip_model()->count() == 1) | 72 if (browser->tab_strip_model()->count() == 1) |
| 73 chrome::NewEmptyWindow(browser->profile(), browser->host_desktop_type()); | 73 chrome::NewEmptyWindow(browser->profile(), browser->host_desktop_type()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 web_contents->GetDelegate()->CloseContents(web_contents); | 76 web_contents->GetDelegate()->CloseContents(web_contents); |
| 77 } | 77 } |
| 78 #endif | 78 #endif |
| 79 | 79 |
| 80 // ManagedModeWarningInfoBarDelegate ------------------------------------------ | 80 // ManagedModeWarningInfoBarDelegate ------------------------------------------ |
| 81 | 81 |
| 82 class ManagedModeWarningInfoBarDelegate : public ConfirmInfoBarDelegate { | 82 class ManagedModeWarningInfoBarDelegate : public ContentConfirmInfoBarDelegate { |
| 83 public: | 83 public: |
| 84 // Creates a managed mode warning infobar and delegate and adds the infobar to | 84 // Creates a managed mode warning infobar and delegate and adds the infobar to |
| 85 // |infobar_service|. Returns the infobar if it was successfully added. | 85 // |infobar_service|. Returns the infobar if it was successfully added. |
| 86 static InfoBar* Create(InfoBarService* infobar_service); | 86 static InfoBar* Create(InfoBarService* infobar_service); |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 ManagedModeWarningInfoBarDelegate(); | 89 explicit ManagedModeWarningInfoBarDelegate( |
| 90 content::WebContents* web_contents); |
| 90 virtual ~ManagedModeWarningInfoBarDelegate(); | 91 virtual ~ManagedModeWarningInfoBarDelegate(); |
| 91 | 92 |
| 92 // ConfirmInfoBarDelegate: | 93 // ConfirmInfoBarDelegate: |
| 93 virtual bool ShouldExpire( | 94 virtual bool ShouldExpire(const NavigationDetails& details) const OVERRIDE; |
| 94 const content::LoadCommittedDetails& details) const OVERRIDE; | |
| 95 virtual void InfoBarDismissed() OVERRIDE; | 95 virtual void InfoBarDismissed() OVERRIDE; |
| 96 virtual base::string16 GetMessageText() const OVERRIDE; | 96 virtual base::string16 GetMessageText() const OVERRIDE; |
| 97 virtual int GetButtons() const OVERRIDE; | 97 virtual int GetButtons() const OVERRIDE; |
| 98 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 98 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 99 virtual bool Accept() OVERRIDE; | 99 virtual bool Accept() OVERRIDE; |
| 100 | 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfoBarDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(ManagedModeWarningInfoBarDelegate); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 InfoBar* ManagedModeWarningInfoBarDelegate::Create( | 105 InfoBar* ManagedModeWarningInfoBarDelegate::Create( |
| 106 InfoBarService* infobar_service) { | 106 InfoBarService* infobar_service) { |
| 107 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 107 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
| 108 scoped_ptr<ConfirmInfoBarDelegate>( | 108 scoped_ptr<ConfirmInfoBarDelegate>(new ManagedModeWarningInfoBarDelegate( |
| 109 new ManagedModeWarningInfoBarDelegate()))); | 109 infobar_service->web_contents())))); |
| 110 } | 110 } |
| 111 | 111 |
| 112 ManagedModeWarningInfoBarDelegate::ManagedModeWarningInfoBarDelegate() | 112 ManagedModeWarningInfoBarDelegate::ManagedModeWarningInfoBarDelegate( |
| 113 : ConfirmInfoBarDelegate() { | 113 content::WebContents* web_contents) |
| 114 } | 114 : ContentConfirmInfoBarDelegate(web_contents) {} |
| 115 | 115 |
| 116 ManagedModeWarningInfoBarDelegate::~ManagedModeWarningInfoBarDelegate() { | 116 ManagedModeWarningInfoBarDelegate::~ManagedModeWarningInfoBarDelegate() { |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool ManagedModeWarningInfoBarDelegate::ShouldExpire( | 119 bool ManagedModeWarningInfoBarDelegate::ShouldExpire( |
| 120 const content::LoadCommittedDetails& details) const { | 120 const NavigationDetails& details) const { |
| 121 // ManagedModeNavigationObserver removes us below. | 121 // ManagedModeNavigationObserver removes us below. |
| 122 return false; | 122 return false; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void ManagedModeWarningInfoBarDelegate::InfoBarDismissed() { | 125 void ManagedModeWarningInfoBarDelegate::InfoBarDismissed() { |
| 126 ManagedModeNavigationObserver::FromWebContents( | 126 ManagedModeNavigationObserver::FromWebContents( |
| 127 web_contents())->WarnInfoBarDismissed(); | 127 web_contents())->WarnInfoBarDismissed(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 base::string16 ManagedModeWarningInfoBarDelegate::GetMessageText() const { | 130 base::string16 ManagedModeWarningInfoBarDelegate::GetMessageText() const { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 181 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
| 182 const GURL& url, | 182 const GURL& url, |
| 183 content::RenderFrameHost* render_frame_host) { | 183 content::RenderFrameHost* render_frame_host) { |
| 184 ManagedModeURLFilter::FilteringBehavior behavior = | 184 ManagedModeURLFilter::FilteringBehavior behavior = |
| 185 url_filter_->GetFilteringBehaviorForURL(url); | 185 url_filter_->GetFilteringBehaviorForURL(url); |
| 186 | 186 |
| 187 if (behavior == ManagedModeURLFilter::WARN || !warn_infobar_) | 187 if (behavior == ManagedModeURLFilter::WARN || !warn_infobar_) |
| 188 return; | 188 return; |
| 189 | 189 |
| 190 // If we shouldn't have a warn infobar remove it here. | 190 // If we shouldn't have a warn infobar remove it here. |
| 191 InfoBarService::FromWebContents(web_contents())->RemoveInfoBar(warn_infobar_); | 191 InfoBarService::FromWebContents(web_contents()) |
| 192 ->infobar_manager() |
| 193 .RemoveInfoBar(warn_infobar_); |
| 192 warn_infobar_ = NULL; | 194 warn_infobar_ = NULL; |
| 193 } | 195 } |
| 194 | 196 |
| 195 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 197 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
| 196 int64 frame_id, | 198 int64 frame_id, |
| 197 const base::string16& frame_unique_name, | 199 const base::string16& frame_unique_name, |
| 198 bool is_main_frame, | 200 bool is_main_frame, |
| 199 const GURL& url, | 201 const GURL& url, |
| 200 content::PageTransition transition_type, | 202 content::PageTransition transition_type, |
| 201 content::RenderViewHost* render_view_host) { | 203 content::RenderViewHost* render_view_host) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 history_service->AddPage(add_page_args); | 257 history_service->AddPage(add_page_args); |
| 256 | 258 |
| 257 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 259 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
| 258 entry->SetVirtualURL(url); | 260 entry->SetVirtualURL(url); |
| 259 entry->SetTimestamp(timestamp); | 261 entry->SetTimestamp(timestamp); |
| 260 blocked_navigations_.push_back(entry.release()); | 262 blocked_navigations_.push_back(entry.release()); |
| 261 ManagedUserService* managed_user_service = | 263 ManagedUserService* managed_user_service = |
| 262 ManagedUserServiceFactory::GetForProfile(profile); | 264 ManagedUserServiceFactory::GetForProfile(profile); |
| 263 managed_user_service->DidBlockNavigation(web_contents()); | 265 managed_user_service->DidBlockNavigation(web_contents()); |
| 264 } | 266 } |
| OLD | NEW |