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

Side by Side Diff: components/web_modal/web_contents_modal_dialog_manager.cc

Issue 14969012: components: Create web_modal component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-before-land Created 7 years, 7 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 "components/web_modal/web_contents_modal_dialog_manager.h"
6 6
7 #include "chrome/browser/platform_util.h" 7 #include "components/web_modal/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"
10 #include "content/public/browser/navigation_details.h" 8 #include "content/public/browser/navigation_details.h"
11 #include "content/public/browser/navigation_entry.h" 9 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/notification_details.h" 10 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_source.h" 11 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 15 #include "content/public/browser/web_contents_view.h"
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
19 17
20 using content::WebContents; 18 using content::WebContents;
21 19
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebContentsModalDialogManager); 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(web_modal::WebContentsModalDialogManager);
21
22 namespace web_modal {
23 23
24 WebContentsModalDialogManager::~WebContentsModalDialogManager() { 24 WebContentsModalDialogManager::~WebContentsModalDialogManager() {
25 DCHECK(child_dialogs_.empty()); 25 DCHECK(child_dialogs_.empty());
26 } 26 }
27 27
28 void WebContentsModalDialogManager::ShowDialog( 28 void WebContentsModalDialogManager::ShowDialog(
29 NativeWebContentsModalDialog dialog) { 29 NativeWebContentsModalDialog dialog) {
30 child_dialogs_.push_back(dialog); 30 child_dialogs_.push_back(dialog);
31 31
32 native_manager_->ManageDialog(dialog); 32 native_manager_->ManageDialog(dialog);
33 33
34 if (child_dialogs_.size() == 1) { 34 if (child_dialogs_.size() == 1) {
35 if (IsWebContentsVisible()) 35 if (delegate_ && delegate_->IsWebContentsVisible(web_contents()))
36 native_manager_->ShowDialog(dialog); 36 native_manager_->ShowDialog(dialog);
37 BlockWebContentsInteraction(true); 37 BlockWebContentsInteraction(true);
38 } 38 }
39 } 39 }
40 40
41 bool WebContentsModalDialogManager::IsShowingDialog() const { 41 bool WebContentsModalDialogManager::IsShowingDialog() const {
42 return !child_dialogs_.empty(); 42 return !child_dialogs_.empty();
43 } 43 }
44 44
45 void WebContentsModalDialogManager::FocusTopmostDialog() { 45 void WebContentsModalDialogManager::FocusTopmostDialog() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) { 101 void WebContentsModalDialogManager::BlockWebContentsInteraction(bool blocked) {
102 WebContents* contents = web_contents(); 102 WebContents* contents = web_contents();
103 if (!contents) { 103 if (!contents) {
104 // The WebContents has already disconnected. 104 // The WebContents has already disconnected.
105 return; 105 return;
106 } 106 }
107 107
108 // RenderViewHost may be NULL during shutdown. 108 // RenderViewHost may be NULL during shutdown.
109 content::RenderViewHost* host = contents->GetRenderViewHost(); 109 content::RenderViewHost* host = contents->GetRenderViewHost();
110 if (host) { 110 if (host)
111 host->SetIgnoreInputEvents(blocked); 111 host->SetIgnoreInputEvents(blocked);
112 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(
113 host->GetRoutingID(), blocked));
114 }
115 if (delegate_) 112 if (delegate_)
116 delegate_->SetWebContentsBlocked(contents, blocked); 113 delegate_->SetWebContentsBlocked(contents, blocked);
117 } 114 }
118 115
119 bool WebContentsModalDialogManager::IsWebContentsVisible() const {
120 return platform_util::IsVisible(web_contents()->GetView()->GetNativeView());
121 }
122
123 void WebContentsModalDialogManager::CloseAllDialogs() { 116 void WebContentsModalDialogManager::CloseAllDialogs() {
124 closing_all_dialogs_ = true; 117 closing_all_dialogs_ = true;
125 118
126 // Clear out any dialogs since we are leaving this page entirely. 119 // Clear out any dialogs since we are leaving this page entirely.
127 while (!child_dialogs_.empty()) 120 while (!child_dialogs_.empty())
128 native_manager_->CloseDialog(child_dialogs_.front()); 121 native_manager_->CloseDialog(child_dialogs_.front());
129 122
130 closing_all_dialogs_ = false; 123 closing_all_dialogs_ = false;
131 } 124 }
132 125
(...skipping 12 matching lines...) Expand all
145 native_manager_->FocusDialog(child_dialogs_.front()); 138 native_manager_->FocusDialog(child_dialogs_.front());
146 } 139 }
147 140
148 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) { 141 void WebContentsModalDialogManager::WebContentsDestroyed(WebContents* tab) {
149 // First cleanly close all child dialogs. 142 // First cleanly close all child dialogs.
150 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked 143 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
151 // some of these to close. CloseAllDialogs is async, so it might get called 144 // some of these to close. CloseAllDialogs is async, so it might get called
152 // twice before it runs. 145 // twice before it runs.
153 CloseAllDialogs(); 146 CloseAllDialogs();
154 } 147 }
148
149 } // namespace web_modal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698