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) { | |
51 return infobar_manager_.AddInfoBar(infobar.Pass()); | |
52 } | |
53 | |
54 InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar, | |
55 scoped_ptr<InfoBar> new_infobar) { | |
56 return infobar_manager_.ReplaceInfoBar(old_infobar, new_infobar.Pass()); | |
57 } | |
58 | |
59 InfoBarService::InfoBarService(content::WebContents* web_contents) | 50 InfoBarService::InfoBarService(content::WebContents* web_contents) |
60 : content::WebContentsObserver(web_contents), | 51 : InfoBarManager(web_contents), |
61 infobar_manager_(web_contents) { | 52 content::WebContentsObserver(web_contents) { |
62 DCHECK(web_contents); | 53 DCHECK(web_contents); |
63 infobar_manager_.AddObserver(this); | |
64 } | 54 } |
65 | 55 |
66 InfoBarService::~InfoBarService() {} | 56 InfoBarService::~InfoBarService() {} |
67 | 57 |
| 58 void InfoBarService::NotifyInfoBarAdded(InfoBar* infobar) { |
| 59 InfoBarManager::NotifyInfoBarAdded(infobar); |
| 60 // TODO(droger): Remove the notifications and have listeners change to be |
| 61 // NavigationManager::Observers instead. See http://crbug.com/354380 |
| 62 content::NotificationService::current()->Notify( |
| 63 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 64 content::Source<InfoBarService>(this), |
| 65 content::Details<InfoBar::AddedDetails>(infobar)); |
| 66 } |
| 67 |
| 68 void InfoBarService::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) { |
| 69 InfoBarManager::NotifyInfoBarRemoved(infobar, animate); |
| 70 // TODO(droger): Remove the notifications and have listeners change to be |
| 71 // NavigationManager::Observers instead. See http://crbug.com/354380 |
| 72 InfoBar::RemovedDetails removed_details(infobar, animate); |
| 73 content::NotificationService::current()->Notify( |
| 74 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 75 content::Source<InfoBarService>(this), |
| 76 content::Details<InfoBar::RemovedDetails>(&removed_details)); |
| 77 } |
| 78 |
| 79 void InfoBarService::NotifyInfoBarReplaced(InfoBar* old_infobar, |
| 80 InfoBar* new_infobar) { |
| 81 InfoBarManager::NotifyInfoBarReplaced(old_infobar, new_infobar); |
| 82 // TODO(droger): Remove the notifications and have listeners change to be |
| 83 // NavigationManager::Observers instead. See http://crbug.com/354380 |
| 84 InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar); |
| 85 content::NotificationService::current()->Notify( |
| 86 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
| 87 content::Source<InfoBarService>(this), |
| 88 content::Details<InfoBar::ReplacedDetails>(&replaced_details)); |
| 89 } |
| 90 |
68 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { | 91 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { |
69 infobar_manager_.RemoveAllInfoBars(true); | 92 RemoveAllInfoBars(true); |
70 } | 93 } |
71 | 94 |
72 void InfoBarService::NavigationEntryCommitted( | 95 void InfoBarService::NavigationEntryCommitted( |
73 const content::LoadCommittedDetails& load_details) { | 96 const content::LoadCommittedDetails& load_details) { |
74 infobar_manager_.OnNavigation( | 97 OnNavigation( |
75 NavigationDetailsFromLoadCommittedDetails(load_details)); | 98 NavigationDetailsFromLoadCommittedDetails(load_details)); |
76 } | 99 } |
77 | 100 |
78 void InfoBarService::WebContentsDestroyed(content::WebContents* web_contents) { | 101 void InfoBarService::WebContentsDestroyed(content::WebContents* web_contents) { |
79 infobar_manager_.OnWebContentsDestroyed(); | 102 OnWebContentsDestroyed(); |
80 | 103 |
81 // The WebContents is going away; be aggressively paranoid and delete | 104 // The WebContents is going away; be aggressively paranoid and delete |
82 // ourselves lest other parts of the system attempt to add infobars or use | 105 // ourselves lest other parts of the system attempt to add infobars or use |
83 // us otherwise during the destruction. | 106 // us otherwise during the destruction. |
84 web_contents->RemoveUserData(UserDataKey()); | 107 web_contents->RemoveUserData(UserDataKey()); |
85 // That was the equivalent of "delete this". This object is now destroyed; | 108 // That was the equivalent of "delete this". This object is now destroyed; |
86 // returning from this function is the only safe thing to do. | 109 // returning from this function is the only safe thing to do. |
87 } | 110 } |
88 | 111 |
89 bool InfoBarService::OnMessageReceived(const IPC::Message& message) { | 112 bool InfoBarService::OnMessageReceived(const IPC::Message& message) { |
90 bool handled = true; | 113 bool handled = true; |
91 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message) | 114 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message) |
92 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, | 115 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, |
93 OnDidBlockDisplayingInsecureContent) | 116 OnDidBlockDisplayingInsecureContent) |
94 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, | 117 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, |
95 OnDidBlockRunningInsecureContent) | 118 OnDidBlockRunningInsecureContent) |
96 IPC_MESSAGE_UNHANDLED(handled = false) | 119 IPC_MESSAGE_UNHANDLED(handled = false) |
97 IPC_END_MESSAGE_MAP() | 120 IPC_END_MESSAGE_MAP() |
98 return handled; | 121 return handled; |
99 } | 122 } |
100 | 123 |
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() { | 124 void InfoBarService::OnDidBlockDisplayingInsecureContent() { |
136 InsecureContentInfoBarDelegate::Create( | 125 InsecureContentInfoBarDelegate::Create( |
137 this, InsecureContentInfoBarDelegate::DISPLAY); | 126 this, InsecureContentInfoBarDelegate::DISPLAY); |
138 } | 127 } |
139 | 128 |
140 void InfoBarService::OnDidBlockRunningInsecureContent() { | 129 void InfoBarService::OnDidBlockRunningInsecureContent() { |
141 InsecureContentInfoBarDelegate::Create(this, | 130 InsecureContentInfoBarDelegate::Create(this, |
142 InsecureContentInfoBarDelegate::RUN); | 131 InsecureContentInfoBarDelegate::RUN); |
143 } | 132 } |
OLD | NEW |