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/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/infobars/core/infobar.h" | 11 #include "components/infobars/core/infobar.h" |
12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 | 16 |
17 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService); | 17 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService); |
18 | 18 |
19 using infobars::InfoBar; | 19 using infobars::InfoBar; |
20 using infobars::InfoBarDelegate; | 20 using infobars::InfoBarDelegate; |
21 using infobars::InfoBarManager; | 21 using infobars::InfoBarManager; |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 bool IsReload(const content::LoadCommittedDetails& details) { |
| 26 return content::PageTransitionStripQualifier( |
| 27 details.entry->GetTransitionType()) == content::PAGE_TRANSITION_RELOAD; |
| 28 |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
23 // static | 33 // static |
24 InfoBarDelegate::NavigationDetails | 34 InfoBarDelegate::NavigationDetails |
25 InfoBarService::NavigationDetailsFromLoadCommittedDetails( | 35 InfoBarService::NavigationDetailsFromLoadCommittedDetails( |
26 const content::LoadCommittedDetails& details) { | 36 const content::LoadCommittedDetails& details) { |
27 InfoBarDelegate::NavigationDetails navigation_details; | 37 InfoBarDelegate::NavigationDetails navigation_details; |
28 navigation_details.entry_id = details.entry->GetUniqueID(); | 38 navigation_details.entry_id = details.entry->GetUniqueID(); |
29 navigation_details.is_navigation_to_different_page = | 39 navigation_details.is_navigation_to_different_page = |
30 details.is_navigation_to_different_page(); | 40 details.is_navigation_to_different_page(); |
31 navigation_details.did_replace_entry = details.did_replace_entry; | 41 navigation_details.did_replace_entry = details.did_replace_entry; |
32 navigation_details.is_main_frame = details.is_main_frame; | 42 navigation_details.is_main_frame = details.is_main_frame; |
33 | 43 |
34 const content::PageTransition transition = details.entry->GetTransitionType(); | 44 const content::PageTransition transition = details.entry->GetTransitionType(); |
35 navigation_details.is_reload = | 45 navigation_details.is_reload = IsReload(details); |
36 content::PageTransitionStripQualifier(transition) == | |
37 content::PAGE_TRANSITION_RELOAD; | |
38 navigation_details.is_redirect = | 46 navigation_details.is_redirect = |
39 (transition & content::PAGE_TRANSITION_IS_REDIRECT_MASK) != 0; | 47 (transition & content::PAGE_TRANSITION_IS_REDIRECT_MASK) != 0; |
40 | 48 |
41 return navigation_details; | 49 return navigation_details; |
42 } | 50 } |
43 | 51 |
44 // static | 52 // static |
45 content::WebContents* InfoBarService::WebContentsFromInfoBar(InfoBar* infobar) { | 53 content::WebContents* InfoBarService::WebContentsFromInfoBar(InfoBar* infobar) { |
46 if (!infobar || !infobar->owner()) | 54 if (!infobar || !infobar->owner()) |
47 return NULL; | 55 return NULL; |
48 InfoBarService* infobar_service = | 56 InfoBarService* infobar_service = |
49 static_cast<InfoBarService*>(infobar->owner()); | 57 static_cast<InfoBarService*>(infobar->owner()); |
50 return infobar_service->web_contents(); | 58 return infobar_service->web_contents(); |
51 } | 59 } |
52 | 60 |
53 InfoBarService::InfoBarService(content::WebContents* web_contents) | 61 InfoBarService::InfoBarService(content::WebContents* web_contents) |
54 : content::WebContentsObserver(web_contents) { | 62 : content::WebContentsObserver(web_contents), |
| 63 ignore_next_reload_(false) { |
55 DCHECK(web_contents); | 64 DCHECK(web_contents); |
56 } | 65 } |
57 | 66 |
58 InfoBarService::~InfoBarService() { | 67 InfoBarService::~InfoBarService() { |
59 ShutDown(); | 68 ShutDown(); |
60 } | 69 } |
61 | 70 |
62 int InfoBarService::GetActiveEntryID() { | 71 int InfoBarService::GetActiveEntryID() { |
63 content::NavigationEntry* active_entry = | 72 content::NavigationEntry* active_entry = |
64 web_contents()->GetController().GetActiveEntry(); | 73 web_contents()->GetController().GetActiveEntry(); |
(...skipping 18 matching lines...) Expand all Loading... |
83 content::NotificationService::current()->Notify( | 92 content::NotificationService::current()->Notify( |
84 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 93 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
85 content::Source<InfoBarService>(this), | 94 content::Source<InfoBarService>(this), |
86 content::Details<InfoBar::RemovedDetails>(&removed_details)); | 95 content::Details<InfoBar::RemovedDetails>(&removed_details)); |
87 } | 96 } |
88 | 97 |
89 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { | 98 void InfoBarService::RenderProcessGone(base::TerminationStatus status) { |
90 RemoveAllInfoBars(true); | 99 RemoveAllInfoBars(true); |
91 } | 100 } |
92 | 101 |
| 102 void InfoBarService::DidStartNavigationToPendingEntry( |
| 103 const GURL& url, |
| 104 content::NavigationController::ReloadType reload_type) { |
| 105 ignore_next_reload_ = false; |
| 106 } |
| 107 |
93 void InfoBarService::NavigationEntryCommitted( | 108 void InfoBarService::NavigationEntryCommitted( |
94 const content::LoadCommittedDetails& load_details) { | 109 const content::LoadCommittedDetails& load_details) { |
95 OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details)); | 110 const bool ignore = ignore_next_reload_ && IsReload(load_details); |
| 111 ignore_next_reload_ = false; |
| 112 if (!ignore) |
| 113 OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details)); |
96 } | 114 } |
97 | 115 |
98 void InfoBarService::WebContentsDestroyed() { | 116 void InfoBarService::WebContentsDestroyed() { |
99 // The WebContents is going away; be aggressively paranoid and delete | 117 // The WebContents is going away; be aggressively paranoid and delete |
100 // ourselves lest other parts of the system attempt to add infobars or use | 118 // ourselves lest other parts of the system attempt to add infobars or use |
101 // us otherwise during the destruction. | 119 // us otherwise during the destruction. |
102 web_contents()->RemoveUserData(UserDataKey()); | 120 web_contents()->RemoveUserData(UserDataKey()); |
103 // That was the equivalent of "delete this". This object is now destroyed; | 121 // That was the equivalent of "delete this". This object is now destroyed; |
104 // returning from this function is the only safe thing to do. | 122 // returning from this function is the only safe thing to do. |
105 } | 123 } |
(...skipping 12 matching lines...) Expand all Loading... |
118 | 136 |
119 void InfoBarService::OnDidBlockDisplayingInsecureContent() { | 137 void InfoBarService::OnDidBlockDisplayingInsecureContent() { |
120 InsecureContentInfoBarDelegate::Create( | 138 InsecureContentInfoBarDelegate::Create( |
121 this, InsecureContentInfoBarDelegate::DISPLAY); | 139 this, InsecureContentInfoBarDelegate::DISPLAY); |
122 } | 140 } |
123 | 141 |
124 void InfoBarService::OnDidBlockRunningInsecureContent() { | 142 void InfoBarService::OnDidBlockRunningInsecureContent() { |
125 InsecureContentInfoBarDelegate::Create(this, | 143 InsecureContentInfoBarDelegate::Create(this, |
126 InsecureContentInfoBarDelegate::RUN); | 144 InsecureContentInfoBarDelegate::RUN); |
127 } | 145 } |
OLD | NEW |