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

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

Issue 7880003: content: Move constrained window code from TabContents to TabContentsWrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac regression now that shutdown timing was changed for views. Created 9 years, 2 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
(Empty)
1 // Copyright (c) 2011 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/tab_contents/tab_contents_wrapper.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
9 #include "content/browser/renderer_host/render_view_host.h"
10 #include "content/browser/renderer_host/render_widget_host_view.h"
11 #include "content/browser/tab_contents/navigation_details.h"
12 #include "net/base/registry_controlled_domain.h"
13
14 ConstrainedWindowTabHelper::ConstrainedWindowTabHelper(
15 TabContentsWrapper* wrapper)
16 : TabContentsObserver(wrapper->tab_contents()),
17 wrapper_(wrapper) {
18 }
19
20 ConstrainedWindowTabHelper::~ConstrainedWindowTabHelper() {
21 DCHECK(child_windows_.empty());
22 }
23
24 void ConstrainedWindowTabHelper::AddConstrainedDialog(
25 ConstrainedWindow* window) {
26 child_windows_.push_back(window);
27
28 if (child_windows_.size() == 1) {
29 window->ShowConstrainedWindow();
30 BlockTabContent(true);
31 }
32 }
33
34 void ConstrainedWindowTabHelper::CloseConstrainedWindows() {
35 // Clear out any constrained windows since we are leaving this page entirely.
36 // To ensure that we iterate over every element in child_windows_ we
37 // need to use a copy of child_windows_. Otherwise if
38 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
39 // skipping some elements.
40 ConstrainedWindowList child_windows_copy(child_windows_);
41 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
42 it != child_windows_copy.end(); ++it) {
43 ConstrainedWindow* window = *it;
44 if (window) {
45 window->CloseConstrainedWindow();
46 BlockTabContent(false);
47 }
48 }
49 }
50
51 void ConstrainedWindowTabHelper::WillClose(ConstrainedWindow* window) {
52 ConstrainedWindowList::iterator i(
53 std::find(child_windows_.begin(), child_windows_.end(), window));
54 bool removed_topmost_window = i == child_windows_.begin();
55 if (i != child_windows_.end())
56 child_windows_.erase(i);
57 if (child_windows_.empty()) {
58 BlockTabContent(false);
59 } else {
60 if (removed_topmost_window)
61 child_windows_[0]->ShowConstrainedWindow();
62 BlockTabContent(true);
63 }
64 }
65
66 void ConstrainedWindowTabHelper::BlockTabContent(bool blocked) {
67 TabContents* contents = tab_contents();
68 if (!contents) {
69 // The TabContents has already disconnected.
70 return;
71 }
72
73 RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView();
74 // 70% opaque grey.
75 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
76 if (rwhv)
77 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
78 // RenderViewHost may be NULL during shutdown.
79 if (contents->render_view_host())
80 contents->render_view_host()->set_ignore_input_events(blocked);
81 if (wrapper_->delegate())
82 wrapper_->delegate()->SetTabContentBlocked(wrapper_, blocked);
83 }
84
85 void ConstrainedWindowTabHelper::DidNavigateMainFramePostCommit(
86 const content::LoadCommittedDetails& details,
87 const ViewHostMsg_FrameNavigate_Params& params) {
88 // Close constrained windows if necessary.
89 if (!net::RegistryControlledDomainService::SameDomainOrHost(
90 details.previous_url, details.entry->url()))
91 CloseConstrainedWindows();
92 }
93
94 void ConstrainedWindowTabHelper::DidGetIgnoredUIEvent() {
95 if (constrained_window_count()) {
96 ConstrainedWindow* window = *constrained_window_begin();
97 window->FocusConstrainedWindow();
98 }
99 }
100
101 void ConstrainedWindowTabHelper::TabContentsDestroyed(TabContents* tab) {
102 // First cleanly close all child windows.
103 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
104 // some of these to close. CloseWindows is async, so it might get called
105 // twice before it runs.
106 CloseConstrainedWindows();
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698