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

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 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
9 namespace {
10
11 const wchar_t kIeTabContentParentWindowClass[] = L"Shell DocObject View";
12
13 } // namespace
14
15 // Receives notification when the displaced window is destroyed, and forwards
16 // displaced window dimensions on to HostWindowManager::Delegate.
17 class HostWindowManager::DisplacedWindowDelegate
18 : public DisplacedWindowManager::Delegate {
19 public:
20 explicit DisplacedWindowDelegate(HostWindowManager* manager);
21 virtual ~DisplacedWindowDelegate();
22
23 // DisplacedWindowManager::Delegate implementation
24 virtual void AdjustDisplacedWindowDimensions(RECT *rect);
grt (UTC plus 2) 2010/12/02 16:27:52 RECT* rect
25
26 private:
27 HostWindowManager* manager_; // Not owned by this instance
28 DISALLOW_COPY_AND_ASSIGN(DisplacedWindowDelegate);
29 }; // class HostWindowManager::DisplacedWindowDelegate
30
31 HostWindowManager::DisplacedWindowDelegate::
32 DisplacedWindowDelegate(HostWindowManager* manager)
grt (UTC plus 2) 2010/12/02 16:27:52 I think this should wrap after the open paren rath
33 : manager_(manager) {
34 }
35
36 // Called when the displaced window is destroyed. Try to find a new displaced
37 // window.
38 HostWindowManager::DisplacedWindowDelegate::~DisplacedWindowDelegate() {
39 HWND old_window = *manager_->displaced_window_manager_;
40 // Will be deleted in its OnFinalMessage
41 manager_->displaced_window_manager_ = NULL;
42
43 // Check to see if a new window has already been created.
44 if (manager_->FindDisplacedWindow(old_window))
45 manager_->UpdateLayout();
46 }
47
48 // Forward this on to our delegate
49 void HostWindowManager::DisplacedWindowDelegate::
50 AdjustDisplacedWindowDimensions(RECT *rect) {
grt (UTC plus 2) 2010/12/02 16:27:52 RECT* rect and same comment about wrapping
51 manager_->delegate()->AdjustDisplacedWindowDimensions(rect);
52 }
53
54 // Callback function for EnumChildWindows (looks for a window with class
55 // kIeTabContentParentWindowClass).
56 //
57 // lparam must point to an HWND that is either NULL or the HWND of the displaced
58 // window that is being destroyed. We will ignore that window if we come across
59 // it, and update lparam to point to the new displaced window if it is found.
60 static BOOL CALLBACK FindDisplacedWindowProc(HWND hwnd, LPARAM lparam) {
61 DCHECK(lparam != NULL);
62 HWND* window_handle = reinterpret_cast<HWND*>(lparam);
63
64 if (hwnd == *window_handle)
65 return TRUE; // Skip this, it's the old displaced window.
66
67 // Variable to hold the class name. The size does not matter as long as it
68 // is at least can hold kIeTabContentParentWindowClass.
69 wchar_t class_name[100];
70 if (::GetClassName(hwnd, class_name, arraysize(class_name)) &&
71 lstrcmpi(kIeTabContentParentWindowClass, class_name) == 0) {
72 // We found the window. Return its handle and stop enumeration.
73 *window_handle = hwnd;
74 return FALSE;
75 }
76 return TRUE;
77 }
78
79 HostWindowManager::HostWindowManager() : displaced_window_manager_(NULL) {
80 }
81
82 HostWindowManager::~HostWindowManager() {
83 // If we are holding a displaced_window_manager_, it means that
84 // OnDisplacedWindowManagerDestroyed has not been called yet, and therefore
85 // our DisplacedWindowDelegate might still be around, ready to invoke us.
86 // Fail fast to prevent a call into lala-land.
87 CHECK(displaced_window_manager_ == NULL);
88 }
89
90 void HostWindowManager::UpdateLayout() {
91 if (FindDisplacedWindow(NULL))
92 displaced_window_manager_->UpdateLayout();
93 }
94
95 bool HostWindowManager::FindDisplacedWindow(HWND old_window) {
96 if (displaced_window_manager_ == NULL ||
97 *displaced_window_manager_ == old_window) {
98 // Find the window which is the container for the HTML view (parent of
99 // the content). When the displaced window is destroyed, the new one might
100 // already exist, so we say "find a displaced window that is not this
101 // (old) one".
102 HWND displaced_window = old_window;
103 ::EnumChildWindows(*this, FindDisplacedWindowProc,
104 reinterpret_cast<LPARAM>(&displaced_window));
105
106 if (displaced_window == old_window) {
107 LOG(ERROR) << "Failed to locate IE renderer HWND to displace for "
108 << "Infobar installation.";
109 } else {
110 scoped_ptr<DisplacedWindowManager> displaced_window_manager(
111 new DisplacedWindowManager());
112 if (displaced_window_manager->Initialize(
113 displaced_window, new DisplacedWindowDelegate(this))) {
114 displaced_window_manager_ = displaced_window_manager.release();
115 }
116 }
117 }
118
119 return displaced_window_manager_ != NULL;
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698