OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/infobars/infobar_service.h" | 5 #include "chrome/browser/infobars/infobar_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/infobars/infobar.h" | 9 #include "chrome/browser/infobars/infobar.h" |
10 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" | 10 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 const content::PageTransition transition = details.entry->GetTransitionType(); | 40 const content::PageTransition transition = details.entry->GetTransitionType(); |
41 navigation_details.is_reload = | 41 navigation_details.is_reload = |
42 content::PageTransitionStripQualifier(transition) == | 42 content::PageTransitionStripQualifier(transition) == |
43 content::PAGE_TRANSITION_RELOAD; | 43 content::PAGE_TRANSITION_RELOAD; |
44 navigation_details.is_redirect = | 44 navigation_details.is_redirect = |
45 (transition & content::PAGE_TRANSITION_IS_REDIRECT_MASK) != 0; | 45 (transition & content::PAGE_TRANSITION_IS_REDIRECT_MASK) != 0; |
46 | 46 |
47 return navigation_details; | 47 return navigation_details; |
48 } | 48 } |
49 | 49 |
50 InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) { | 50 InfoBarService::InfoBarService(content::WebContents* web_contents) |
51 return infobar_manager_.AddInfoBar(infobar.Pass()); | 51 : InfoBarManager(web_contents), |
| 52 content::WebContentsObserver(web_contents) { |
| 53 DCHECK(web_contents); |
52 } | 54 } |
53 | 55 |
54 InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar, | 56 InfoBarService::~InfoBarService() { |
55 scoped_ptr<InfoBar> new_infobar) { | 57 ShutDown(); |
56 return infobar_manager_.ReplaceInfoBar(old_infobar, new_infobar.Pass()); | |
57 } | 58 } |
58 | 59 |
59 InfoBarService::InfoBarService(content::WebContents* web_contents) | 60 void InfoBarService::NotifyInfoBarAdded(InfoBar* infobar) { |
60 : content::WebContentsObserver(web_contents), | 61 InfoBarManager::NotifyInfoBarAdded(infobar); |
61 infobar_manager_(web_contents) { | 62 // TODO(droger): Remove the notifications and have listeners change to be |
62 DCHECK(web_contents); | 63 // NavigationManager::Observers instead. See http://crbug.com/354380 |
63 infobar_manager_.AddObserver(this); | 64 content::NotificationService::current()->Notify( |
| 65 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 66 content::Source<InfoBarService>(this), |
| 67 content::Details<InfoBar::AddedDetails>(infobar)); |
64 } | 68 } |
65 | 69 |
66 InfoBarService::~InfoBarService() {} | 70 void InfoBarService::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) { |
| 71 InfoBarManager::NotifyInfoBarRemoved(infobar, animate); |
| 72 // TODO(droger): Remove the notifications and have listeners change to be |
| 73 // NavigationManager::Observers instead. See http://crbug.com/354380 |
| 74 InfoBar::RemovedDetails removed_details(infobar, animate); |
| 75 content::NotificationService::current()->Notify( |
| 76 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 77 content::Source<InfoBarService>(this), |
| 78 content::Details<InfoBar::RemovedDetails>(&removed_details)); |
| 79 } |
| 80 |
| 81 void InfoBarService::NotifyInfoBarReplaced(InfoBar* old_infobar, |
| 82 InfoBar* new_infobar) { |
| 83 InfoBarManager::NotifyInfoBarReplaced(old_infobar, new_infobar); |
| 84 // TODO(droger): Remove the notifications and have listeners change to be |
| 85 // NavigationManager::Observers instead. See http://crbug.com/354380 |
| 86 InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar); |
| 87 content::NotificationService::current()->Notify( |
| 88 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
| 89 content::Source<InfoBarService>(this), |
| 90 content::Details<InfoBar::ReplacedDetails>(&replaced_details)); |
| 91 } |
67 | 92 |
68 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { | 93 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { |
69 infobar_manager_.RemoveAllInfoBars(true); | 94 RemoveAllInfoBars(true); |
70 } | 95 } |
71 | 96 |
72 void InfoBarService::NavigationEntryCommitted( | 97 void InfoBarService::NavigationEntryCommitted( |
73 const content::LoadCommittedDetails& load_details) { | 98 const content::LoadCommittedDetails& load_details) { |
74 infobar_manager_.OnNavigation( | 99 OnNavigation( |
75 NavigationDetailsFromLoadCommittedDetails(load_details)); | 100 NavigationDetailsFromLoadCommittedDetails(load_details)); |
76 } | 101 } |
77 | 102 |
78 void InfoBarService::WebContentsDestroyed(content::WebContents* web_contents) { | 103 void InfoBarService::WebContentsDestroyed(content::WebContents* web_contents) { |
79 infobar_manager_.OnWebContentsDestroyed(); | 104 OnWebContentsDestroyed(); |
80 | 105 |
81 // The WebContents is going away; be aggressively paranoid and delete | 106 // The WebContents is going away; be aggressively paranoid and delete |
82 // ourselves lest other parts of the system attempt to add infobars or use | 107 // ourselves lest other parts of the system attempt to add infobars or use |
83 // us otherwise during the destruction. | 108 // us otherwise during the destruction. |
84 web_contents->RemoveUserData(UserDataKey()); | 109 web_contents->RemoveUserData(UserDataKey()); |
85 // That was the equivalent of "delete this". This object is now destroyed; | 110 // That was the equivalent of "delete this". This object is now destroyed; |
86 // returning from this function is the only safe thing to do. | 111 // returning from this function is the only safe thing to do. |
87 } | 112 } |
88 | 113 |
89 bool InfoBarService::OnMessageReceived(const IPC::Message& message) { | 114 bool InfoBarService::OnMessageReceived(const IPC::Message& message) { |
90 bool handled = true; | 115 bool handled = true; |
91 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message) | 116 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message) |
92 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, | 117 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, |
93 OnDidBlockDisplayingInsecureContent) | 118 OnDidBlockDisplayingInsecureContent) |
94 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, | 119 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, |
95 OnDidBlockRunningInsecureContent) | 120 OnDidBlockRunningInsecureContent) |
96 IPC_MESSAGE_UNHANDLED(handled = false) | 121 IPC_MESSAGE_UNHANDLED(handled = false) |
97 IPC_END_MESSAGE_MAP() | 122 IPC_END_MESSAGE_MAP() |
98 return handled; | 123 return handled; |
99 } | 124 } |
100 | 125 |
101 void InfoBarService::OnInfoBarAdded(InfoBar* infobar) { | |
102 // TODO(droger): Remove the notifications and have listeners change to be | |
103 // NavigationManager::Observers instead. See http://crbug.com/354380 | |
104 content::NotificationService::current()->Notify( | |
105 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
106 content::Source<InfoBarService>(this), | |
107 content::Details<InfoBar::AddedDetails>(infobar)); | |
108 } | |
109 | |
110 void InfoBarService::OnInfoBarReplaced(InfoBar* old_infobar, | |
111 InfoBar* new_infobar) { | |
112 // TODO(droger): Remove the notifications and have listeners change to be | |
113 // NavigationManager::Observers instead. See http://crbug.com/354380 | |
114 InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar); | |
115 content::NotificationService::current()->Notify( | |
116 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, | |
117 content::Source<InfoBarService>(this), | |
118 content::Details<InfoBar::ReplacedDetails>(&replaced_details)); | |
119 } | |
120 | |
121 void InfoBarService::OnInfoBarRemoved(InfoBar* infobar, bool animate) { | |
122 // TODO(droger): Remove the notifications and have listeners change to be | |
123 // NavigationManager::Observers instead. See http://crbug.com/354380 | |
124 InfoBar::RemovedDetails removed_details(infobar, animate); | |
125 content::NotificationService::current()->Notify( | |
126 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | |
127 content::Source<InfoBarService>(this), | |
128 content::Details<InfoBar::RemovedDetails>(&removed_details)); | |
129 } | |
130 | |
131 void InfoBarService::OnManagerShuttingDown(InfoBarManager* manager) { | |
132 infobar_manager_.RemoveObserver(this); | |
133 } | |
134 | |
135 void InfoBarService::OnDidBlockDisplayingInsecureContent() { | 126 void InfoBarService::OnDidBlockDisplayingInsecureContent() { |
136 InsecureContentInfoBarDelegate::Create( | 127 InsecureContentInfoBarDelegate::Create( |
137 this, InsecureContentInfoBarDelegate::DISPLAY); | 128 this, InsecureContentInfoBarDelegate::DISPLAY); |
138 } | 129 } |
139 | 130 |
140 void InfoBarService::OnDidBlockRunningInsecureContent() { | 131 void InfoBarService::OnDidBlockRunningInsecureContent() { |
141 InsecureContentInfoBarDelegate::Create(this, | 132 InsecureContentInfoBarDelegate::Create(this, |
142 InsecureContentInfoBarDelegate::RUN); | 133 InsecureContentInfoBarDelegate::RUN); |
143 } | 134 } |
OLD | NEW |