| 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/app_modal/app_modal_dialog_queue.h" | 5 #include "components/app_modal/app_modal_dialog_queue.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "components/app_modal/app_modal_dialog.h" | 8 #include "components/app_modal/javascript_app_modal_dialog.h" |
| 9 | 9 |
| 10 namespace app_modal { | 10 namespace app_modal { |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 AppModalDialogQueue* AppModalDialogQueue::GetInstance() { | 13 AppModalDialogQueue* AppModalDialogQueue::GetInstance() { |
| 14 return base::Singleton<AppModalDialogQueue>::get(); | 14 return base::Singleton<AppModalDialogQueue>::get(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 void AppModalDialogQueue::AddDialog(AppModalDialog* dialog) { | 17 void AppModalDialogQueue::AddDialog(JavaScriptAppModalDialog* dialog) { |
| 18 if (!active_dialog_) { | 18 if (!active_dialog_) { |
| 19 ShowModalDialog(dialog); | 19 ShowModalDialog(dialog); |
| 20 return; | 20 return; |
| 21 } | 21 } |
| 22 app_modal_dialog_queue_.push_back(dialog); | 22 app_modal_dialog_queue_.push_back(dialog); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void AppModalDialogQueue::ShowNextDialog() { | 25 void AppModalDialogQueue::ShowNextDialog() { |
| 26 AppModalDialog* dialog = GetNextDialog(); | 26 JavaScriptAppModalDialog* dialog = GetNextDialog(); |
| 27 if (dialog) | 27 if (dialog) |
| 28 ShowModalDialog(dialog); | 28 ShowModalDialog(dialog); |
| 29 else | 29 else |
| 30 active_dialog_ = NULL; | 30 active_dialog_ = nullptr; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void AppModalDialogQueue::ActivateModalDialog() { | 33 void AppModalDialogQueue::ActivateModalDialog() { |
| 34 if (showing_modal_dialog_) { | 34 if (showing_modal_dialog_) { |
| 35 // As part of showing a modal dialog we may end up back in this method | 35 // As part of showing a modal dialog we may end up back in this method |
| 36 // (showing a dialog activates the WebContents, which can trigger a call | 36 // (showing a dialog activates the WebContents, which can trigger a call |
| 37 // to ActivateModalDialog). We ignore such a request as after the call to | 37 // to ActivateModalDialog). We ignore such a request as after the call to |
| 38 // activate the tab contents the dialog is shown. | 38 // activate the tab contents the dialog is shown. |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 if (active_dialog_) | 41 if (active_dialog_) |
| 42 active_dialog_->ActivateModalDialog(); | 42 active_dialog_->ActivateModalDialog(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool AppModalDialogQueue::HasActiveDialog() const { | 45 bool AppModalDialogQueue::HasActiveDialog() const { |
| 46 return active_dialog_ != NULL; | 46 return active_dialog_ != nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 AppModalDialogQueue::AppModalDialogQueue() | 49 AppModalDialogQueue::AppModalDialogQueue() |
| 50 : active_dialog_(NULL), | 50 : active_dialog_(NULL), |
| 51 showing_modal_dialog_(false) { | 51 showing_modal_dialog_(false) { |
| 52 } | 52 } |
| 53 | 53 |
| 54 AppModalDialogQueue::~AppModalDialogQueue() { | 54 AppModalDialogQueue::~AppModalDialogQueue() { |
| 55 } | 55 } |
| 56 | 56 |
| 57 void AppModalDialogQueue::ShowModalDialog(AppModalDialog* dialog) { | 57 void AppModalDialogQueue::ShowModalDialog(JavaScriptAppModalDialog* dialog) { |
| 58 // Be sure and set the active_dialog_ field first, otherwise if | 58 // Be sure and set the active_dialog_ field first, otherwise if |
| 59 // ShowModalDialog triggers a call back to the queue they'll get the old | 59 // ShowModalDialog triggers a call back to the queue they'll get the old |
| 60 // dialog. Also, if the dialog calls |ShowNextDialog()| before returning, that | 60 // dialog. Also, if the dialog calls |ShowNextDialog()| before returning, that |
| 61 // would write NULL into |active_dialog_| and this function would then undo | 61 // would write nullptr into |active_dialog_| and this function would then undo |
| 62 // that. | 62 // that. |
| 63 active_dialog_ = dialog; | 63 active_dialog_ = dialog; |
| 64 showing_modal_dialog_ = true; | 64 showing_modal_dialog_ = true; |
| 65 dialog->ShowModalDialog(); | 65 dialog->ShowModalDialog(); |
| 66 showing_modal_dialog_ = false; | 66 showing_modal_dialog_ = false; |
| 67 } | 67 } |
| 68 | 68 |
| 69 AppModalDialog* AppModalDialogQueue::GetNextDialog() { | 69 JavaScriptAppModalDialog* AppModalDialogQueue::GetNextDialog() { |
| 70 while (!app_modal_dialog_queue_.empty()) { | 70 while (!app_modal_dialog_queue_.empty()) { |
| 71 AppModalDialog* dialog = app_modal_dialog_queue_.front(); | 71 JavaScriptAppModalDialog* dialog = app_modal_dialog_queue_.front(); |
| 72 app_modal_dialog_queue_.pop_front(); | 72 app_modal_dialog_queue_.pop_front(); |
| 73 if (dialog->IsValid()) | 73 if (dialog->IsValid()) |
| 74 return dialog; | 74 return dialog; |
| 75 delete dialog; | 75 delete dialog; |
| 76 } | 76 } |
| 77 return NULL; | 77 return nullptr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace app_modal | 80 } // namespace app_modal |
| OLD | NEW |