Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/infobars/infobar_service.cc

Issue 1160443010: More infobar cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS too Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/insecure_content_infobar_delegate.h" 9 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
11 #include "components/content_settings/content/common/content_settings_messages.h " 11 #include "components/content_settings/content/common/content_settings_messages.h "
12 #include "components/infobars/core/infobar.h" 12 #include "components/infobars/core/infobar.h"
13 #include "content/public/browser/navigation_details.h" 13 #include "content/public/browser/navigation_details.h"
14 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "ui/base/page_transition_types.h"
18
17 19
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService); 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService);
19 21
20 using infobars::InfoBar;
21 using infobars::InfoBarDelegate;
22 using infobars::InfoBarManager;
23
24 namespace {
25
26 bool IsReload(const content::LoadCommittedDetails& details) {
27 return ui::PageTransitionStripQualifier(
28 details.entry->GetTransitionType()) == ui::PAGE_TRANSITION_RELOAD;
29
30 }
31
32 } // namespace
33
34 // static 22 // static
35 InfoBarDelegate::NavigationDetails 23 infobars::InfoBarDelegate::NavigationDetails
36 InfoBarService::NavigationDetailsFromLoadCommittedDetails( 24 InfoBarService::NavigationDetailsFromLoadCommittedDetails(
37 const content::LoadCommittedDetails& details) { 25 const content::LoadCommittedDetails& details) {
38 InfoBarDelegate::NavigationDetails navigation_details; 26 infobars::InfoBarDelegate::NavigationDetails navigation_details;
39 navigation_details.entry_id = details.entry->GetUniqueID(); 27 navigation_details.entry_id = details.entry->GetUniqueID();
40 navigation_details.is_navigation_to_different_page = 28 navigation_details.is_navigation_to_different_page =
41 details.is_navigation_to_different_page(); 29 details.is_navigation_to_different_page();
42 navigation_details.did_replace_entry = details.did_replace_entry; 30 navigation_details.did_replace_entry = details.did_replace_entry;
43 navigation_details.is_main_frame = details.is_main_frame;
44
45 const ui::PageTransition transition = details.entry->GetTransitionType();
46 navigation_details.is_reload = IsReload(details);
47 navigation_details.is_redirect = 31 navigation_details.is_redirect =
48 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) != 0; 32 ui::PageTransitionIsRedirect(details.entry->GetTransitionType());
49
50 return navigation_details; 33 return navigation_details;
51 } 34 }
52 35
53 // static 36 // static
54 content::WebContents* InfoBarService::WebContentsFromInfoBar(InfoBar* infobar) { 37 content::WebContents* InfoBarService::WebContentsFromInfoBar(
38 infobars::InfoBar* infobar) {
55 if (!infobar || !infobar->owner()) 39 if (!infobar || !infobar->owner())
56 return NULL; 40 return NULL;
57 InfoBarService* infobar_service = 41 InfoBarService* infobar_service =
58 static_cast<InfoBarService*>(infobar->owner()); 42 static_cast<InfoBarService*>(infobar->owner());
59 return infobar_service->web_contents(); 43 return infobar_service->web_contents();
60 } 44 }
61 45
62 InfoBarService::InfoBarService(content::WebContents* web_contents) 46 InfoBarService::InfoBarService(content::WebContents* web_contents)
63 : content::WebContentsObserver(web_contents), 47 : content::WebContentsObserver(web_contents),
64 ignore_next_reload_(false) { 48 ignore_next_reload_(false) {
65 DCHECK(web_contents); 49 DCHECK(web_contents);
66 } 50 }
67 51
68 InfoBarService::~InfoBarService() { 52 InfoBarService::~InfoBarService() {
69 ShutDown(); 53 ShutDown();
70 } 54 }
71 55
72 int InfoBarService::GetActiveEntryID() { 56 int InfoBarService::GetActiveEntryID() {
73 content::NavigationEntry* active_entry = 57 content::NavigationEntry* active_entry =
74 web_contents()->GetController().GetActiveEntry(); 58 web_contents()->GetController().GetActiveEntry();
75 return active_entry ? active_entry->GetUniqueID() : 0; 59 return active_entry ? active_entry->GetUniqueID() : 0;
76 } 60 }
77 61
78 void InfoBarService::NotifyInfoBarAdded(InfoBar* infobar) { 62 void InfoBarService::NotifyInfoBarAdded(infobars::InfoBar* infobar) {
79 InfoBarManager::NotifyInfoBarAdded(infobar); 63 infobars::InfoBarManager::NotifyInfoBarAdded(infobar);
80 // TODO(droger): Remove the notifications and have listeners change to be 64 // TODO(droger): Remove the notifications and have listeners change to be
81 // InfoBarManager::Observers instead. See http://crbug.com/354380 65 // InfoBarManager::Observers instead. See http://crbug.com/354380
82 content::NotificationService::current()->Notify( 66 content::NotificationService::current()->Notify(
83 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 67 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
84 content::Source<InfoBarService>(this), 68 content::Source<InfoBarService>(this),
85 content::Details<InfoBar::AddedDetails>(infobar)); 69 content::Details<infobars::InfoBar::AddedDetails>(infobar));
86 } 70 }
87 71
88 void InfoBarService::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) { 72 void InfoBarService::NotifyInfoBarRemoved(infobars::InfoBar* infobar,
89 InfoBarManager::NotifyInfoBarRemoved(infobar, animate); 73 bool animate) {
74 infobars::InfoBarManager::NotifyInfoBarRemoved(infobar, animate);
90 // TODO(droger): Remove the notifications and have listeners change to be 75 // TODO(droger): Remove the notifications and have listeners change to be
91 // InfoBarManager::Observers instead. See http://crbug.com/354380 76 // InfoBarManager::Observers instead. See http://crbug.com/354380
92 InfoBar::RemovedDetails removed_details(infobar, animate); 77 infobars::InfoBar::RemovedDetails removed_details(infobar, animate);
93 content::NotificationService::current()->Notify( 78 content::NotificationService::current()->Notify(
94 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 79 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
95 content::Source<InfoBarService>(this), 80 content::Source<InfoBarService>(this),
96 content::Details<InfoBar::RemovedDetails>(&removed_details)); 81 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details));
97 } 82 }
98 83
99 // InfoBarService::CreateConfirmInfoBar() is implemented in platform-specific 84 // InfoBarService::CreateConfirmInfoBar() is implemented in platform-specific
100 // files. 85 // files.
101 86
102 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { 87 void InfoBarService::RenderProcessGone(base::TerminationStatus status) {
103 RemoveAllInfoBars(true); 88 RemoveAllInfoBars(true);
104 } 89 }
105 90
106 void InfoBarService::DidStartNavigationToPendingEntry( 91 void InfoBarService::DidStartNavigationToPendingEntry(
107 const GURL& url, 92 const GURL& url,
108 content::NavigationController::ReloadType reload_type) { 93 content::NavigationController::ReloadType reload_type) {
109 ignore_next_reload_ = false; 94 ignore_next_reload_ = false;
110 } 95 }
111 96
112 void InfoBarService::NavigationEntryCommitted( 97 void InfoBarService::NavigationEntryCommitted(
113 const content::LoadCommittedDetails& load_details) { 98 const content::LoadCommittedDetails& load_details) {
114 const bool ignore = ignore_next_reload_ && IsReload(load_details); 99 const bool ignore = ignore_next_reload_ &&
100 (ui::PageTransitionStripQualifier(
101 load_details.entry->GetTransitionType()) ==
102 ui::PAGE_TRANSITION_RELOAD);
115 ignore_next_reload_ = false; 103 ignore_next_reload_ = false;
116 if (!ignore) 104 if (!ignore)
117 OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details)); 105 OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details));
118 } 106 }
119 107
120 void InfoBarService::WebContentsDestroyed() { 108 void InfoBarService::WebContentsDestroyed() {
121 // The WebContents is going away; be aggressively paranoid and delete 109 // The WebContents is going away; be aggressively paranoid and delete
122 // ourselves lest other parts of the system attempt to add infobars or use 110 // ourselves lest other parts of the system attempt to add infobars or use
123 // us otherwise during the destruction. 111 // us otherwise during the destruction.
124 web_contents()->RemoveUserData(UserDataKey()); 112 web_contents()->RemoveUserData(UserDataKey());
125 // That was the equivalent of "delete this". This object is now destroyed; 113 // That was the equivalent of "delete this". This object is now destroyed;
126 // returning from this function is the only safe thing to do. 114 // returning from this function is the only safe thing to do.
127 } 115 }
128 116
129 bool InfoBarService::OnMessageReceived(const IPC::Message& message) { 117 bool InfoBarService::OnMessageReceived(const IPC::Message& message) {
130 bool handled = true; 118 bool handled = true;
131 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message) 119 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message)
132 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, 120 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent,
133 OnDidBlockDisplayingInsecureContent) 121 OnDidBlockDisplayingInsecureContent)
134 IPC_MESSAGE_UNHANDLED(handled = false) 122 IPC_MESSAGE_UNHANDLED(handled = false)
135 IPC_END_MESSAGE_MAP() 123 IPC_END_MESSAGE_MAP()
136 return handled; 124 return handled;
137 } 125 }
138 126
139 void InfoBarService::OnDidBlockDisplayingInsecureContent() { 127 void InfoBarService::OnDidBlockDisplayingInsecureContent() {
140 InsecureContentInfoBarDelegate::Create(this); 128 InsecureContentInfoBarDelegate::Create(this);
141 } 129 }
OLDNEW
« no previous file with comments | « no previous file | components/infobars/core/infobar_delegate.h » ('j') | ios/chrome/browser/infobars/infobar_manager_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698