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

Side by Side Diff: webrtc/base/macwindowpicker.cc

Issue 2299633002: Remove all reference to carbon api (Closed)
Patch Set: Fix chromium build errors Created 4 years, 3 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
« no previous file with comments | « webrtc/base/macutils_unittest.cc ('k') | webrtc/base/proxydetect.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2010 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include "webrtc/base/macwindowpicker.h" 10 #include "webrtc/base/macwindowpicker.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool visible = false; 99 bool visible = false;
100 if (is_visible != NULL) { 100 if (is_visible != NULL) {
101 visible = CFBooleanGetValue(is_visible); 101 visible = CFBooleanGetValue(is_visible);
102 } 102 }
103 CFRelease(window_id_array); 103 CFRelease(window_id_array);
104 CFRelease(window_array); 104 CFRelease(window_array);
105 return visible; 105 return visible;
106 } 106 }
107 107
108 bool MacWindowPicker::MoveToFront(const WindowId& id) { 108 bool MacWindowPicker::MoveToFront(const WindowId& id) {
109 // Init if we're not already initialized. 109 return false;
110 if (get_window_list_desc_ == NULL && !Init()) {
111 return false;
112 }
113 CGWindowID ids[1];
114 ids[0] = id.id();
115 CFArrayRef window_id_array =
116 CFArrayCreate(NULL, reinterpret_cast<const void **>(&ids), 1, NULL);
117
118 CFArrayRef window_array =
119 reinterpret_cast<CGWindowListCreateDescriptionFromArrayProc>(
120 get_window_list_desc_)(window_id_array);
121 if (window_array == NULL || 0 == CFArrayGetCount(window_array)) {
122 // Could not find the window. It might have been closed.
123 LOG(LS_INFO) << "Window not found";
124 CFRelease(window_id_array);
125 return false;
126 }
127
128 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
129 CFArrayGetValueAtIndex(window_array, 0));
130 CFStringRef window_name_ref = reinterpret_cast<CFStringRef>(
131 CFDictionaryGetValue(window, kCGWindowName));
132 CFNumberRef application_pid = reinterpret_cast<CFNumberRef>(
133 CFDictionaryGetValue(window, kCGWindowOwnerPID));
134
135 int pid_val;
136 CFNumberGetValue(application_pid, kCFNumberIntType, &pid_val);
137 std::string window_name;
138 ToUtf8(window_name_ref, &window_name);
139
140 // Build an applescript that sets the selected window to front
141 // within the application. Then set the application to front.
142 bool result = true;
143 std::stringstream ss;
144 ss << "tell application \"System Events\"\n"
145 << "set proc to the first item of (every process whose unix id is "
146 << pid_val
147 << ")\n"
148 << "tell proc to perform action \"AXRaise\" of window \""
149 << window_name
150 << "\"\n"
151 << "set the frontmost of proc to true\n"
152 << "end tell";
153 if (!RunAppleScript(ss.str())) {
154 // This might happen to for example X applications where the X
155 // server spawns of processes with their own PID but the X server
156 // is still registered as owner to the application windows. As a
157 // workaround, we put the X server process to front, meaning that
158 // all X applications will show up. The drawback with this
159 // workaround is that the application that we really wanted to set
160 // to front might be behind another X application.
161 ProcessSerialNumber psn;
162 pid_t pid = pid_val;
163 int res = GetProcessForPID(pid, &psn);
164 if (res != 0) {
165 LOG(LS_ERROR) << "Failed getting process for pid";
166 result = false;
167 }
168 res = SetFrontProcess(&psn);
169 if (res != 0) {
170 LOG(LS_ERROR) << "Failed setting process to front";
171 result = false;
172 }
173 }
174 CFRelease(window_id_array);
175 CFRelease(window_array);
176 return result;
177 } 110 }
178 111
179 bool MacWindowPicker::GetDesktopList(DesktopDescriptionList* descriptions) { 112 bool MacWindowPicker::GetDesktopList(DesktopDescriptionList* descriptions) {
180 const uint32_t kMaxDisplays = 128; 113 const uint32_t kMaxDisplays = 128;
181 CGDirectDisplayID active_displays[kMaxDisplays]; 114 CGDirectDisplayID active_displays[kMaxDisplays];
182 uint32_t display_count = 0; 115 uint32_t display_count = 0;
183 116
184 CGError err = CGGetActiveDisplayList(kMaxDisplays, 117 CGError err = CGGetActiveDisplayList(kMaxDisplays,
185 active_displays, 118 active_displays,
186 &display_count); 119 &display_count);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 descriptions->push_back(desc); 180 descriptions->push_back(desc);
248 } 181 }
249 } 182 }
250 } 183 }
251 184
252 CFRelease(window_array); 185 CFRelease(window_array);
253 return true; 186 return true;
254 } 187 }
255 188
256 } // namespace rtc 189 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/macutils_unittest.cc ('k') | webrtc/base/proxydetect.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698