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

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

Powered by Google App Engine
This is Rietveld 408576698