Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chrome/browser/ui/web_contents_modal_dialog_manager.cc

Issue 12045037: Refactor modality-specific behavior from ConstrainedWindowViews to WebContentsModalDialogManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Android link error Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
15 15
16 using content::WebContents; 16 using content::WebContents;
17 17
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsModalDialogManager); 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsModalDialogManager);
19 19
20 WebContentsModalDialogManager::~WebContentsModalDialogManager() { 20 WebContentsModalDialogManager::~WebContentsModalDialogManager() {
21 DCHECK(child_dialogs_.empty()); 21 DCHECK(child_dialogs_.empty());
22 } 22 }
23 23
24 void WebContentsModalDialogManager::AddDialog( 24 void WebContentsModalDialogManager::AddDialog(
25 WebContentsModalDialog* dialog) { 25 WebContentsModalDialog* dialog) {
26 child_dialogs_.push_back(dialog); 26 child_dialogs_.push_back(dialog);
27 27
28 if (native_manager_)
29 native_manager_->ManageDialog(dialog->GetNativeWindow());
30
28 if (child_dialogs_.size() == 1) { 31 if (child_dialogs_.size() == 1) {
29 dialog->ShowWebContentsModalDialog(); 32 dialog->ShowWebContentsModalDialog();
30 BlockWebContentsInteraction(true); 33 BlockWebContentsInteraction(true);
31 } 34 }
32 } 35 }
33 36
34 void WebContentsModalDialogManager::WillClose(WebContentsModalDialog* dialog) { 37 void WebContentsModalDialogManager::WillClose(WebContentsModalDialog* dialog) {
35 WebContentsModalDialogList::iterator i( 38 WebContentsModalDialogList::iterator i(
36 std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog)); 39 std::find(child_dialogs_.begin(), child_dialogs_.end(), dialog));
37 bool removed_topmost_dialog = i == child_dialogs_.begin(); 40 bool removed_topmost_dialog = i == child_dialogs_.begin();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 void WebContentsModalDialogManager::FocusTopmostDialog() { 74 void WebContentsModalDialogManager::FocusTopmostDialog() {
72 DCHECK(dialog_count()); 75 DCHECK(dialog_count());
73 WebContentsModalDialog* window = *dialog_begin(); 76 WebContentsModalDialog* window = *dialog_begin();
74 DCHECK(window); 77 DCHECK(window);
75 window->FocusWebContentsModalDialog(); 78 window->FocusWebContentsModalDialog();
76 } 79 }
77 80
78 WebContentsModalDialogManager::WebContentsModalDialogManager( 81 WebContentsModalDialogManager::WebContentsModalDialogManager(
79 content::WebContents* web_contents) 82 content::WebContents* web_contents)
80 : content::WebContentsObserver(web_contents), 83 : content::WebContentsObserver(web_contents),
81 delegate_(NULL) { 84 delegate_(NULL),
85 native_manager_(
86 ALLOW_THIS_IN_INITIALIZER_LIST(CreateNativeManager(this))) {
82 } 87 }
83 88
84 void WebContentsModalDialogManager::CloseAllDialogs() { 89 void WebContentsModalDialogManager::CloseAllDialogs() {
85 // 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
86 // that we iterate over every element in child_dialogs_ we need to use a copy 91 // that we iterate over every element in child_dialogs_ we need to use a copy
87 // of child_dialogs_. Otherwise if dialog->CloseWebContentsModalDialog() 92 // of child_dialogs_. Otherwise if dialog->CloseWebContentsModalDialog()
88 // modifies child_dialogs_ we could end up skipping some elements. 93 // modifies child_dialogs_ we could end up skipping some elements.
89 WebContentsModalDialogList child_dialogs_copy(child_dialogs_); 94 WebContentsModalDialogList child_dialogs_copy(child_dialogs_);
90 for (WebContentsModalDialogList::iterator it = child_dialogs_copy.begin(); 95 for (WebContentsModalDialogList::iterator it = child_dialogs_copy.begin();
91 it != child_dialogs_copy.end(); ++it) { 96 it != child_dialogs_copy.end(); ++it) {
(...skipping 21 matching lines...) Expand all
113 } 118 }
114 } 119 }
115 120
116 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { 121 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) {
117 // First cleanly close all child dialogs. 122 // First cleanly close all child dialogs.
118 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked 123 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
119 // 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
120 // twice before it runs. 125 // twice before it runs.
121 CloseAllDialogs(); 126 CloseAllDialogs();
122 } 127 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/web_contents_modal_dialog_manager.h ('k') | chrome/browser/ui/web_contents_modal_dialog_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698