| 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 "chrome/browser/ui/web_contents_modal_dialog_manager.h" | 5 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/web_contents_modal_dialog.h" | 7 #include "chrome/browser/ui/web_contents_modal_dialog.h" |
| 8 #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h" | 8 #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 if (native_manager_) | 28 if (native_manager_) |
| 29 native_manager_->ManageDialog(dialog->GetNativeDialog()); | 29 native_manager_->ManageDialog(dialog->GetNativeDialog()); |
| 30 | 30 |
| 31 if (child_dialogs_.size() == 1) { | 31 if (child_dialogs_.size() == 1) { |
| 32 dialog->ShowWebContentsModalDialog(); | 32 dialog->ShowWebContentsModalDialog(); |
| 33 BlockWebContentsInteraction(true); | 33 BlockWebContentsInteraction(true); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 void WebContentsModalDialogManager::WillClose(WebContentsModalDialog* dialog) { | |
| 38 WebContentsModalDialogList::iterator i( | |
| 39 std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog)); | |
| 40 bool removed_topmost_dialog = i == child_dialogs_.begin(); | |
| 41 if (i != child_dialogs_.end()) | |
| 42 child_dialogs_.erase(i); | |
| 43 if (child_dialogs_.empty()) { | |
| 44 BlockWebContentsInteraction(false); | |
| 45 } else { | |
| 46 if (removed_topmost_dialog) | |
| 47 child_dialogs_[0]->ShowWebContentsModalDialog(); | |
| 48 BlockWebContentsInteraction(true); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { | 37 void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { |
| 53 WebContents* contents = web_contents(); | 38 WebContents* contents = web_contents(); |
| 54 if (!contents) { | 39 if (!contents) { |
| 55 // The WebContents has already disconnected. | 40 // The WebContents has already disconnected. |
| 56 return; | 41 return; |
| 57 } | 42 } |
| 58 | 43 |
| 59 // RenderViewHost may be NULL during shutdown. | 44 // RenderViewHost may be NULL during shutdown. |
| 60 content::RenderViewHost* host = contents->GetRenderViewHost(); | 45 content::RenderViewHost* host = contents->GetRenderViewHost(); |
| 61 if (host) { | 46 if (host) { |
| 62 host->SetIgnoreInputEvents(blocked); | 47 host->SetIgnoreInputEvents(blocked); |
| 63 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( | 48 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( |
| 64 host->GetRoutingID(), blocked)); | 49 host->GetRoutingID(), blocked)); |
| 65 } | 50 } |
| 66 if (delegate_) | 51 if (delegate_) |
| 67 delegate_->SetWebContentsBlocked(contents, blocked); | 52 delegate_->SetWebContentsBlocked(contents, blocked); |
| 68 } | 53 } |
| 69 | 54 |
| 70 bool WebContentsModalDialogManager::IsShowingDialog() const { | 55 bool WebContentsModalDialogManager::IsShowingDialog() const { |
| 71 return dialog_count() > 0; | 56 return dialog_count() > 0; |
| 72 } | 57 } |
| 73 | 58 |
| 74 void WebContentsModalDialogManager::FocusTopmostDialog() { | 59 void WebContentsModalDialogManager::FocusTopmostDialog() { |
| 75 DCHECK(dialog_count()); | 60 DCHECK(dialog_count()); |
| 76 WebContentsModalDialog* window = *dialog_begin(); | 61 WebContentsModalDialog* window = *dialog_begin(); |
| 77 DCHECK(window); | 62 DCHECK(window); |
| 78 window->FocusWebContentsModalDialog(); | 63 window->FocusWebContentsModalDialog(); |
| 79 } | 64 } |
| 80 | 65 |
| 66 void WebContentsModalDialogManager::WillClose(WebContentsModalDialog* dialog) { |
| 67 WebContentsModalDialogList::iterator i( |
| 68 std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog)); |
| 69 bool removed_topmost_dialog = i == child_dialogs_.begin(); |
| 70 if (i != child_dialogs_.end()) |
| 71 child_dialogs_.erase(i); |
| 72 if (child_dialogs_.empty()) { |
| 73 BlockWebContentsInteraction(false); |
| 74 } else { |
| 75 if (removed_topmost_dialog) |
| 76 child_dialogs_[0]->ShowWebContentsModalDialog(); |
| 77 BlockWebContentsInteraction(true); |
| 78 } |
| 79 } |
| 80 |
| 81 WebContentsModalDialogManager::WebContentsModalDialogManager( | 81 WebContentsModalDialogManager::WebContentsModalDialogManager( |
| 82 content::WebContents* web_contents) | 82 content::WebContents* web_contents) |
| 83 : content::WebContentsObserver(web_contents), | 83 : content::WebContentsObserver(web_contents), |
| 84 delegate_(NULL), | 84 delegate_(NULL), |
| 85 native_manager_( | 85 native_manager_( |
| 86 ALLOW_THIS_IN_INITIALIZER_LIST(CreateNativeManager(this))) { | 86 ALLOW_THIS_IN_INITIALIZER_LIST(CreateNativeManager(this))) { |
| 87 } | 87 } |
| 88 | 88 |
| 89 void WebContentsModalDialogManager::CloseAllDialogs() { | 89 void WebContentsModalDialogManager::CloseAllDialogs() { |
| 90 // Clear out any dialogs since we are leaving this page entirely. To ensure | 90 // Clear out any dialogs since we are leaving this page entirely. To ensure |
| (...skipping 27 matching lines...) Expand all Loading... |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { | 121 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { |
| 122 // First cleanly close all child dialogs. | 122 // First cleanly close all child dialogs. |
| 123 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 123 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
| 124 // some of these to close. CloseAllDialogs is async, so it might get called | 124 // some of these to close. CloseAllDialogs is async, so it might get called |
| 125 // twice before it runs. | 125 // twice before it runs. |
| 126 CloseAllDialogs(); | 126 CloseAllDialogs(); |
| 127 } | 127 } |
| OLD | NEW |