[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / browser / infobars / infobar_service.cc
blob556086be5f1418ee60b9c14400b5cc2626b0b4e9
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
3 // found in the LICENSE file.
5 #include "chrome/browser/infobars/infobar_service.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h"
10 #include "chrome/common/render_messages.h"
11 #include "components/content_settings/content/common/content_settings_messages.h"
12 #include "components/infobars/core/infobar.h"
13 #include "content/public/browser/navigation_details.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/web_contents.h"
17 #include "ui/base/page_transition_types.h"
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService);
22 // static
23 infobars::InfoBarDelegate::NavigationDetails
24 InfoBarService::NavigationDetailsFromLoadCommittedDetails(
25 const content::LoadCommittedDetails& details) {
26 infobars::InfoBarDelegate::NavigationDetails navigation_details;
27 navigation_details.entry_id = details.entry->GetUniqueID();
28 navigation_details.is_navigation_to_different_page =
29 details.is_navigation_to_different_page();
30 navigation_details.did_replace_entry = details.did_replace_entry;
31 navigation_details.is_redirect =
32 ui::PageTransitionIsRedirect(details.entry->GetTransitionType());
33 return navigation_details;
36 // static
37 content::WebContents* InfoBarService::WebContentsFromInfoBar(
38 infobars::InfoBar* infobar) {
39 if (!infobar || !infobar->owner())
40 return NULL;
41 InfoBarService* infobar_service =
42 static_cast<InfoBarService*>(infobar->owner());
43 return infobar_service->web_contents();
46 InfoBarService::InfoBarService(content::WebContents* web_contents)
47 : content::WebContentsObserver(web_contents),
48 ignore_next_reload_(false) {
49 DCHECK(web_contents);
52 InfoBarService::~InfoBarService() {
53 ShutDown();
56 int InfoBarService::GetActiveEntryID() {
57 content::NavigationEntry* active_entry =
58 web_contents()->GetController().GetActiveEntry();
59 return active_entry ? active_entry->GetUniqueID() : 0;
62 void InfoBarService::NotifyInfoBarAdded(infobars::InfoBar* infobar) {
63 infobars::InfoBarManager::NotifyInfoBarAdded(infobar);
64 // TODO(droger): Remove the notifications and have listeners change to be
65 // InfoBarManager::Observers instead. See http://crbug.com/354380
66 content::NotificationService::current()->Notify(
67 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
68 content::Source<InfoBarService>(this),
69 content::Details<infobars::InfoBar::AddedDetails>(infobar));
72 void InfoBarService::NotifyInfoBarRemoved(infobars::InfoBar* infobar,
73 bool animate) {
74 infobars::InfoBarManager::NotifyInfoBarRemoved(infobar, animate);
75 // TODO(droger): Remove the notifications and have listeners change to be
76 // InfoBarManager::Observers instead. See http://crbug.com/354380
77 infobars::InfoBar::RemovedDetails removed_details(infobar, animate);
78 content::NotificationService::current()->Notify(
79 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
80 content::Source<InfoBarService>(this),
81 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details));
84 // InfoBarService::CreateConfirmInfoBar() is implemented in platform-specific
85 // files.
87 void InfoBarService::RenderProcessGone(base::TerminationStatus status) {
88 RemoveAllInfoBars(true);
91 void InfoBarService::DidStartNavigationToPendingEntry(
92 const GURL& url,
93 content::NavigationController::ReloadType reload_type) {
94 ignore_next_reload_ = false;
97 void InfoBarService::NavigationEntryCommitted(
98 const content::LoadCommittedDetails& load_details) {
99 const bool ignore = ignore_next_reload_ &&
100 (ui::PageTransitionStripQualifier(
101 load_details.entry->GetTransitionType()) ==
102 ui::PAGE_TRANSITION_RELOAD);
103 ignore_next_reload_ = false;
104 if (!ignore)
105 OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details));
108 void InfoBarService::WebContentsDestroyed() {
109 // The WebContents is going away; be aggressively paranoid and delete
110 // ourselves lest other parts of the system attempt to add infobars or use
111 // us otherwise during the destruction.
112 web_contents()->RemoveUserData(UserDataKey());
113 // That was the equivalent of "delete this". This object is now destroyed;
114 // returning from this function is the only safe thing to do.
117 bool InfoBarService::OnMessageReceived(const IPC::Message& message) {
118 bool handled = true;
119 IPC_BEGIN_MESSAGE_MAP(InfoBarService, message)
120 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent,
121 OnDidBlockDisplayingInsecureContent)
122 IPC_MESSAGE_UNHANDLED(handled = false)
123 IPC_END_MESSAGE_MAP()
124 return handled;
127 void InfoBarService::OnDidBlockDisplayingInsecureContent() {
128 InsecureContentInfoBarDelegate::Create(this);