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

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

Issue 11647017: Rename platform-independent ConstrainedWindow types to WebContentsModalDialog types (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/constrained_window_tab_helper.h"
6
7 #include "chrome/browser/ui/constrained_window.h"
8 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
9 #include "chrome/common/render_messages.h"
10 #include "content/public/browser/navigation_details.h"
11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h"
15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
16
17 using content::WebContents;
18
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ConstrainedWindowTabHelper)
20
21 ConstrainedWindowTabHelper::ConstrainedWindowTabHelper(
22 content::WebContents* web_contents)
23 : content::WebContentsObserver(web_contents),
24 delegate_(NULL) {
25 }
26
27 ConstrainedWindowTabHelper::~ConstrainedWindowTabHelper() {
28 DCHECK(child_windows_.empty());
29 }
30
31 void ConstrainedWindowTabHelper::AddConstrainedDialog(
32 ConstrainedWindow* window) {
33 child_windows_.push_back(window);
34
35 if (child_windows_.size() == 1 && window->CanShowConstrainedWindow()) {
36 window->ShowConstrainedWindow();
37 BlockTabContent(true);
38 }
39 }
40
41 void ConstrainedWindowTabHelper::CloseConstrainedWindows() {
42 // Clear out any constrained windows since we are leaving this page entirely.
43 // To ensure that we iterate over every element in child_windows_ we
44 // need to use a copy of child_windows_. Otherwise if
45 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
46 // skipping some elements.
47 ConstrainedWindowList child_windows_copy(child_windows_);
48 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
49 it != child_windows_copy.end(); ++it) {
50 ConstrainedWindow* window = *it;
51 if (window) {
52 window->CloseConstrainedWindow();
53 BlockTabContent(false);
54 }
55 }
56 }
57
58 void ConstrainedWindowTabHelper::WillClose(ConstrainedWindow* window) {
59 ConstrainedWindowList::iterator i(
60 std::find(child_windows_.begin(), child_windows_.end(), window));
61 bool removed_topmost_window = i == child_windows_.begin();
62 if (i != child_windows_.end())
63 child_windows_.erase(i);
64 if (child_windows_.empty()) {
65 BlockTabContent(false);
66 } else {
67 if (removed_topmost_window)
68 child_windows_[0]->ShowConstrainedWindow();
69 BlockTabContent(true);
70 }
71 }
72
73 void ConstrainedWindowTabHelper::BlockTabContent(bool blocked) {
74 WebContents* contents = web_contents();
75 if (!contents) {
76 // The WebContents has already disconnected.
77 return;
78 }
79
80 // RenderViewHost may be NULL during shutdown.
81 content::RenderViewHost* host = contents->GetRenderViewHost();
82 if (host) {
83 host->SetIgnoreInputEvents(blocked);
84 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(
85 host->GetRoutingID(), blocked));
86 }
87 if (delegate_)
88 delegate_->SetTabContentBlocked(contents, blocked);
89 }
90
91 void ConstrainedWindowTabHelper::DidNavigateMainFrame(
92 const content::LoadCommittedDetails& details,
93 const content::FrameNavigateParams& params) {
94 // Close constrained windows if necessary.
95 if (!net::RegistryControlledDomainService::SameDomainOrHost(
96 details.previous_url, details.entry->GetURL()))
97 CloseConstrainedWindows();
98 }
99
100 void ConstrainedWindowTabHelper::DidGetIgnoredUIEvent() {
101 if (constrained_window_count()) {
102 ConstrainedWindow* window = *constrained_window_begin();
103 window->FocusConstrainedWindow();
104 }
105 }
106
107 void ConstrainedWindowTabHelper::WebContentsDestroyed(WebContents* tab) {
108 // First cleanly close all child windows.
109 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
110 // some of these to close. CloseWindows is async, so it might get called
111 // twice before it runs.
112 CloseConstrainedWindows();
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698