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

Side by Side Diff: chrome_frame/infobars/internal/host_window.cc

Issue 4766003: Preview CL for adding an Infobar facility to Google Chrome Frame.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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_frame/infobars/internal/host_window.h"
6
7 #include "chrome_frame/infobars/internal/displaced_window.h"
8 #include "chrome_frame/utils.h"
9
10 namespace {
11
12 const wchar_t kIeTabContentParentWindowClass[] = L"Shell DocObject View";
13
14 } // namespace
15
16 class HostWindowManager::DisplacedWindowDelegate
17 : public DisplacedWindowManager::Delegate {
18 public:
19 explicit DisplacedWindowDelegate(HostWindowManager* manager);
20 void AdjustDisplacedWindowDimensions(RECT *rect);
21 void OnDisplacedWindowDestroyed();
22 private:
23 HostWindowManager* manager_;
24 DISALLOW_COPY_AND_ASSIGN(DisplacedWindowDelegate);
25 };
26
27
28 // Callback function for EnumChildWindows (looks for a window with class
29 // kIeTabContentParentWindowClass).
30 //
31 // lparam must point to an HWND that is either NULL or the HWND of the displaced
32 // window that is being destroyed. We will ignore that window if we come across
33 // it, and update lparam to point to the new displaced window if it is found.
34 static BOOL CALLBACK FindDisplacedWindowProc(HWND hwnd, LPARAM lparam) {
35 DCHECK(lparam != NULL);
36 HWND* window_handle = reinterpret_cast<HWND*>(lparam);
37
38 if (hwnd == *window_handle)
39 return TRUE; // Skip this, it's the old displaced window.
40
41 // Variable to hold the class name. The size does not matter as long as it
grt (UTC plus 2) 2010/11/25 18:00:13 indent
erikwright (departed) 2010/12/01 20:05:52 Done.
42 // is at least can hold kIeTabContentParentWindowClass.
43 wchar_t class_name[100];
44 if (::GetClassName(hwnd, class_name, arraysize(class_name)) &&
45 lstrcmpi(kIeTabContentParentWindowClass, class_name) == 0) {
46 // We found the window. Return its handle and stop enumeration.
47 *window_handle = hwnd;
48 return FALSE;
49 }
50 return TRUE;
51 }
52
53 HostWindowManager::Delegate* HostWindowManager::GetDelegateForHostHwnd(
54 HWND host_window) {
55 LRESULT result = ::SendMessage(host_window, WM_GET_DELEGATE, NULL, NULL);
56 return reinterpret_cast<Delegate*>(result);
57 }
58
59 HostWindowManager::HostWindowManager() : displaced_window_manager_(NULL) {
60 }
61
62 HostWindowManager::~HostWindowManager() {
63 // If we are holding a displaced_window_manager_, it means that
64 // OnDisplacedWindowManagerDestroyed has not been called yet, and therefore
65 // our DisplacedWindowDelegate might still be around, ready to invoke us.
66 // Fail fast to prevent a call into lala-land.
67 CHECK(displaced_window_manager_ == NULL);
tommi (sloooow) - chröme 2010/11/24 16:08:24 to be clear - CHECK() will kill IE for the user if
erikwright (departed) 2010/12/01 20:05:52 I think we have to. The alternative is to accept a
68 }
69
70 bool HostWindowManager::Initialize(HWND host_window, Delegate* delegate) {
71 DCHECK(delegate != NULL);
72 DCHECK(delegate_ == NULL);
73 delegate_.reset(delegate);
74
75 PinModule();
grt (UTC plus 2) 2010/11/25 18:00:13 Are both calls to PinModule (here and in Displaced
erikwright (departed) 2010/12/01 20:05:52 Only one is required, but for the purposes of deco
76 if (!SubclassWindow(host_window)) {
77 LOG(DFATAL) << "Failed to subclass HWND for infobar installation.";
78 return false;
79 }
80
81 return true;
82 }
83
84 void HostWindowManager::OnFinalMessage(HWND /*hWnd*/) {
tommi (sloooow) - chröme 2010/11/24 16:08:24 remove /* */
erikwright (departed) 2010/12/01 20:05:52 According to coding style we comment parameter nam
85 delete this;
86 }
87
88 LRESULT HostWindowManager::OnGetDelegate(UINT message,
89 WPARAM wparam,
tommi (sloooow) - chröme 2010/11/24 16:08:24 fix indentation
erikwright (departed) 2010/12/01 20:05:52 Done.
90 LPARAM lparam,
91 BOOL& handled) {
92 return reinterpret_cast<LRESULT>(delegate_.get());
93 }
94
95 bool HostWindowManager::UpdateLayout() {
96 if (FindDisplacedWindow(NULL)) {
97 displaced_window_manager_->UpdateLayout();
98 return true;
99 } else {
100 return false;
101 }
102 }
103
104 bool HostWindowManager::FindDisplacedWindow(HWND old_window) {
105 if (displaced_window_manager_ == NULL ||
106 *displaced_window_manager_ == old_window) {
107 if (IsWindow()) {
108 // Find the window which is the container for the HTML view (parent of
109 // the content). When the displaced window is destroyed, the new one might
110 // already exist, so we say "find a displaced window that is not this
111 // (old) one".
112 HWND displaced_window = old_window;
113 ::EnumChildWindows(*this, FindDisplacedWindowProc,
114 reinterpret_cast<LPARAM>(&displaced_window));
115
116 if (displaced_window == old_window) {
117 LOG(DFATAL) << "Failed to locate IE renderer HWND to displace for "
118 << "Infobar installation.";
119 } else {
120 scoped_ptr<DisplacedWindowManager> displaced_window_manager(
121 new DisplacedWindowManager());
122 if (displaced_window_manager->Initialize(
123 displaced_window, new DisplacedWindowDelegate(this))) {
124 displaced_window_manager_ = displaced_window_manager.release();
125 }
126 }
127 }
128 }
129
130 return displaced_window_manager_ != NULL;
131 }
132
133 void HostWindowManager::AdjustDisplacedWindowDimensions(RECT* rect) {
134 if (rect == NULL)
grt (UTC plus 2) 2010/11/25 18:00:13 why not simply: if (rect != NULL) delegate_->Adj
erikwright (departed) 2010/12/01 20:05:52 In fact, I think it's clear from the contract that
135 return;
136 delegate_->AdjustDisplacedWindowDimensions(rect);
137 }
138
139 void HostWindowManager::OnDisplacedWindowDestroyed() {
140 HWND old_window = *displaced_window_manager_;
141 // Will be deleted in its OnFinalMessage
142 displaced_window_manager_ = NULL;
143
144 // Check to see if a new window has already been created.
145 if (FindDisplacedWindow(old_window))
146 UpdateLayout();
147 }
148
149 HostWindowManager::DisplacedWindowDelegate::
150 DisplacedWindowDelegate(HostWindowManager* manager) : manager_(manager) {
151 }
152
153 void HostWindowManager::DisplacedWindowDelegate::
154 AdjustDisplacedWindowDimensions(RECT *rect) {
155 manager_->AdjustDisplacedWindowDimensions(rect);
156 }
157
158 void HostWindowManager::DisplacedWindowDelegate::OnDisplacedWindowDestroyed() {
159 manager_->OnDisplacedWindowDestroyed();
160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698