OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/web_modal/web_contents_modal_dialog_manager.h" | 5 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
6 | 6 |
7 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 7 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
8 #include "content/public/browser/navigation_details.h" | 8 #include "content/public/browser/navigation_details.h" |
9 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
10 #include "content/public/browser/notification_details.h" | 10 #include "content/public/browser/notification_details.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 !closing_all_dialogs_) | 67 !closing_all_dialogs_) |
68 native_manager_->ShowDialog(child_dialogs_.front()); | 68 native_manager_->ShowDialog(child_dialogs_.front()); |
69 | 69 |
70 BlockWebContentsInteraction(!child_dialogs_.empty()); | 70 BlockWebContentsInteraction(!child_dialogs_.empty()); |
71 } | 71 } |
72 | 72 |
73 void WebContentsModalDialogManager::Observe( | 73 void WebContentsModalDialogManager::Observe( |
74 int type, | 74 int type, |
75 const content::NotificationSource& source, | 75 const content::NotificationSource& source, |
76 const content::NotificationDetails& details) { | 76 const content::NotificationDetails& details) { |
77 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED); | 77 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
| 78 if (child_dialogs_.empty()) |
| 79 return; |
78 | 80 |
79 if (child_dialogs_.empty()) | 81 bool visible = *content::Details<bool>(details).ptr(); |
80 return; | 82 if (visible) |
81 | 83 native_manager_->ShowDialog(child_dialogs_.front()); |
82 bool visible = *content::Details<bool>(details).ptr(); | 84 else |
83 if (visible) | 85 native_manager_->HideDialog(child_dialogs_.front()); |
84 native_manager_->ShowDialog(child_dialogs_.front()); | 86 } else if (type == content::NOTIFICATION_LOAD_START) { |
85 else | 87 if (!child_dialogs_.empty()) |
86 native_manager_->HideDialog(child_dialogs_.front()); | 88 native_manager_->CloseDialog(child_dialogs_.front()); |
| 89 } |
87 } | 90 } |
88 | 91 |
89 WebContentsModalDialogManager::WebContentsModalDialogManager( | 92 WebContentsModalDialogManager::WebContentsModalDialogManager( |
90 content::WebContents* web_contents) | 93 content::WebContents* web_contents) |
91 : content::WebContentsObserver(web_contents), | 94 : content::WebContentsObserver(web_contents), |
92 delegate_(NULL), | 95 delegate_(NULL), |
93 native_manager_(CreateNativeManager(this)), | 96 native_manager_(CreateNativeManager(this)), |
94 closing_all_dialogs_(false) { | 97 closing_all_dialogs_(false) { |
95 DCHECK(native_manager_); | 98 DCHECK(native_manager_); |
| 99 content::NavigationController* controller = |
| 100 &GetWebContents()->GetController(); |
| 101 registrar_.Add(this, |
| 102 content::NOTIFICATION_LOAD_START, |
| 103 content::Source<content::NavigationController>(controller)); |
96 registrar_.Add(this, | 104 registrar_.Add(this, |
97 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 105 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
98 content::Source<content::WebContents>(web_contents)); | 106 content::Source<content::WebContents>(web_contents)); |
99 } | 107 } |
100 | 108 |
101 void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { | 109 void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { |
102 WebContents* contents = web_contents(); | 110 WebContents* contents = web_contents(); |
103 if (!contents) { | 111 if (!contents) { |
104 // The WebContents has already disconnected. | 112 // The WebContents has already disconnected. |
105 return; | 113 return; |
(...skipping 10 matching lines...) Expand all Loading... |
116 void WebContentsModalDialogManager::CloseAllDialogs() { | 124 void WebContentsModalDialogManager::CloseAllDialogs() { |
117 closing_all_dialogs_ = true; | 125 closing_all_dialogs_ = true; |
118 | 126 |
119 // Clear out any dialogs since we are leaving this page entirely. | 127 // Clear out any dialogs since we are leaving this page entirely. |
120 while (!child_dialogs_.empty()) | 128 while (!child_dialogs_.empty()) |
121 native_manager_->CloseDialog(child_dialogs_.front()); | 129 native_manager_->CloseDialog(child_dialogs_.front()); |
122 | 130 |
123 closing_all_dialogs_ = false; | 131 closing_all_dialogs_ = false; |
124 } | 132 } |
125 | 133 |
126 void WebContentsModalDialogManager::DidNavigateMainFrame( | |
127 const content::LoadCommittedDetails& details, | |
128 const content::FrameNavigateParams& params) { | |
129 // Close constrained windows if necessary. | |
130 if (!net::registry_controlled_domains::SameDomainOrHost( | |
131 details.previous_url, details.entry->GetURL(), | |
132 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)) | |
133 CloseAllDialogs(); | |
134 } | |
135 | |
136 void WebContentsModalDialogManager::DidGetIgnoredUIEvent() { | 134 void WebContentsModalDialogManager::DidGetIgnoredUIEvent() { |
137 if (!child_dialogs_.empty()) | 135 if (!child_dialogs_.empty()) |
138 native_manager_->FocusDialog(child_dialogs_.front()); | 136 native_manager_->FocusDialog(child_dialogs_.front()); |
139 } | 137 } |
140 | 138 |
141 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { | 139 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { |
142 // First cleanly close all child dialogs. | 140 // First cleanly close all child dialogs. |
143 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 141 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
144 // some of these to close. CloseAllDialogs is async, so it might get called | 142 // some of these to close. CloseAllDialogs is async, so it might get called |
145 // twice before it runs. | 143 // twice before it runs. |
146 CloseAllDialogs(); | 144 CloseAllDialogs(); |
147 } | 145 } |
148 | 146 |
149 } // namespace web_modal | 147 } // namespace web_modal |
OLD | NEW |