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 "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
8 #include "chrome/browser/api/infobars/infobar_service.h" | 8 #include "chrome/browser/api/infobars/infobar_service.h" |
9 #include "chrome/browser/managed_mode/managed_mode.h" | 9 #include "chrome/browser/managed_mode/managed_mode.h" |
10 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 10 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 16 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/common/frame_navigate_params.h" | 17 #include "content/public/common/frame_navigate_params.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { | 23 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { |
24 public: | 24 public: |
25 explicit ManagedModeWarningInfobarDelegate(InfoBarService* infobar_service); | 25 // Creates a managed mode warning delegate and adds it to |infobar_service|. |
| 26 // Returns the delegate if it was successfully added. |
| 27 static InfoBarDelegate* Create(InfoBarService* infobar_service); |
26 | 28 |
27 private: | 29 private: |
| 30 explicit ManagedModeWarningInfobarDelegate(InfoBarService* infobar_service); |
28 virtual ~ManagedModeWarningInfobarDelegate(); | 31 virtual ~ManagedModeWarningInfobarDelegate(); |
29 | 32 |
30 // ConfirmInfoBarDelegate overrides: | 33 // ConfirmInfoBarDelegate overrides: |
31 virtual string16 GetMessageText() const OVERRIDE; | 34 virtual string16 GetMessageText() const OVERRIDE; |
32 virtual int GetButtons() const OVERRIDE; | 35 virtual int GetButtons() const OVERRIDE; |
33 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 36 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
34 virtual bool Accept() OVERRIDE; | 37 virtual bool Accept() OVERRIDE; |
35 virtual bool Cancel() OVERRIDE; | 38 virtual bool Cancel() OVERRIDE; |
36 | 39 |
37 // InfoBarDelegate override: | 40 // InfoBarDelegate override: |
(...skipping 19 matching lines...) Expand all Loading... |
57 if (BrowserList::size() == 1) { | 60 if (BrowserList::size() == 1) { |
58 Browser* browser = *(BrowserList::begin()); | 61 Browser* browser = *(BrowserList::begin()); |
59 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); | 62 DCHECK(browser == chrome::FindBrowserWithWebContents(web_contents)); |
60 if (browser->tab_count() == 1) | 63 if (browser->tab_count() == 1) |
61 chrome::NewEmptyWindow(browser->profile()); | 64 chrome::NewEmptyWindow(browser->profile()); |
62 } | 65 } |
63 | 66 |
64 web_contents->GetDelegate()->CloseContents(web_contents); | 67 web_contents->GetDelegate()->CloseContents(web_contents); |
65 } | 68 } |
66 | 69 |
| 70 // static |
| 71 InfoBarDelegate* ManagedModeWarningInfobarDelegate::Create( |
| 72 InfoBarService* infobar_service) { |
| 73 return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 74 new ManagedModeWarningInfobarDelegate(infobar_service))); |
| 75 } |
| 76 |
67 ManagedModeWarningInfobarDelegate::ManagedModeWarningInfobarDelegate( | 77 ManagedModeWarningInfobarDelegate::ManagedModeWarningInfobarDelegate( |
68 InfoBarService* infobar_service) | 78 InfoBarService* infobar_service) |
69 : ConfirmInfoBarDelegate(infobar_service) {} | 79 : ConfirmInfoBarDelegate(infobar_service) {} |
70 | 80 |
71 ManagedModeWarningInfobarDelegate::~ManagedModeWarningInfobarDelegate() {} | 81 ManagedModeWarningInfobarDelegate::~ManagedModeWarningInfobarDelegate() {} |
72 | 82 |
73 string16 ManagedModeWarningInfobarDelegate::GetMessageText() const { | 83 string16 ManagedModeWarningInfobarDelegate::GetMessageText() const { |
74 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_WARNING_MESSAGE); | 84 return l10n_util::GetStringUTF16(IDS_MANAGED_MODE_WARNING_MESSAGE); |
75 } | 85 } |
76 | 86 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 content::PageTransition transition_type, | 141 content::PageTransition transition_type, |
132 content::RenderViewHost* render_view_host) { | 142 content::RenderViewHost* render_view_host) { |
133 if (!is_main_frame) | 143 if (!is_main_frame) |
134 return; | 144 return; |
135 | 145 |
136 ManagedModeURLFilter::FilteringBehavior behavior = | 146 ManagedModeURLFilter::FilteringBehavior behavior = |
137 url_filter_->GetFilteringBehaviorForURL(url); | 147 url_filter_->GetFilteringBehaviorForURL(url); |
138 | 148 |
139 if (behavior == ManagedModeURLFilter::WARN) { | 149 if (behavior == ManagedModeURLFilter::WARN) { |
140 if (!warn_infobar_delegate_) { | 150 if (!warn_infobar_delegate_) { |
141 InfoBarService* infobar_service = | 151 warn_infobar_delegate_ = ManagedModeWarningInfobarDelegate::Create( |
142 InfoBarService::FromWebContents(web_contents()); | 152 InfoBarService::FromWebContents(web_contents())); |
143 warn_infobar_delegate_ = | |
144 new ManagedModeWarningInfobarDelegate(infobar_service); | |
145 infobar_service->AddInfoBar(warn_infobar_delegate_); | |
146 } | 153 } |
147 } else { | 154 } else { |
148 if (warn_infobar_delegate_) { | 155 if (warn_infobar_delegate_) { |
149 InfoBarService* infobar_service = | 156 InfoBarService* infobar_service = |
150 InfoBarService::FromWebContents(web_contents()); | 157 InfoBarService::FromWebContents(web_contents()); |
151 infobar_service->RemoveInfoBar(warn_infobar_delegate_); | 158 infobar_service->RemoveInfoBar(warn_infobar_delegate_); |
152 warn_infobar_delegate_= NULL; | 159 warn_infobar_delegate_= NULL; |
153 } | 160 } |
154 } | 161 } |
155 | 162 |
156 } | 163 } |
OLD | NEW |