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

Side by Side Diff: remoting/host/continue_window_mac.mm

Issue 13461029: The continue window is owned by the desktop environment now. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac. Created 7 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/continue_window.h"
6
7 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
8 6
9 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
10 #include "base/logging.h" 8 #include "base/logging.h"
11 #include "base/mac/scoped_nsautorelease_pool.h" 9 #include "base/mac/scoped_nsautorelease_pool.h"
12 #include "base/memory/scoped_nsobject.h" 10 #include "base/memory/scoped_nsobject.h"
13 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
14 #include "remoting/host/ui_strings.h" 12 #include "remoting/host/continue_window.h"
15
16 typedef remoting::ContinueWindow::ContinueSessionCallback
17 ContinueSessionCallback;
18 13
19 // Handles the ContinueWindow. 14 // Handles the ContinueWindow.
20 @interface ContinueWindowMacController : NSObject { 15 @interface ContinueWindowMacController : NSObject {
21 @private 16 @private
22 scoped_nsobject<NSMutableArray> shades_; 17 scoped_nsobject<NSMutableArray> shades_;
23 scoped_nsobject<NSAlert> continue_alert_; 18 scoped_nsobject<NSAlert> continue_alert_;
24 ContinueSessionCallback callback_; 19 remoting::ContinueWindow* continue_window_;
25 const remoting::UiStrings* ui_strings_; 20 const remoting::UiStrings* ui_strings_;
26 } 21 }
27 22
28 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings 23 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings
29 callback:(const ContinueSessionCallback&)callback; 24 continue_window:(remoting::ContinueWindow*)continue_window;
30 - (void)show; 25 - (void)show;
31 - (void)hide; 26 - (void)hide;
32 - (void)onCancel:(id)sender; 27 - (void)onCancel:(id)sender;
33 - (void)onContinue:(id)sender; 28 - (void)onContinue:(id)sender;
34 @end 29 @end
35 30
36 namespace remoting { 31 namespace remoting {
37 32
38 // A bridge between C++ and ObjC implementations of ContinueWindow. 33 // A bridge between C++ and ObjC implementations of ContinueWindow.
39 // Everything important occurs in ContinueWindowMacController. 34 // Everything important occurs in ContinueWindowMacController.
40 class ContinueWindowMac : public remoting::ContinueWindow { 35 class ContinueWindowMac : public ContinueWindow {
41 public: 36 public:
42 explicit ContinueWindowMac(const UiStrings* ui_strings); 37 explicit ContinueWindowMac(const UiStrings& ui_strings);
43 virtual ~ContinueWindowMac(); 38 virtual ~ContinueWindowMac();
44 39
45 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; 40 protected:
46 virtual void Hide() OVERRIDE; 41 // ContinueWindow overrides.
42 virtual void ShowUi() OVERRIDE;
43 virtual void HideUi() OVERRIDE;
47 44
48 private: 45 private:
49 scoped_nsobject<ContinueWindowMacController> controller_; 46 scoped_nsobject<ContinueWindowMacController> controller_;
50 ContinueSessionCallback callback_;
51
52 // Points to the localized strings.
53 const UiStrings* ui_strings_;
54 47
55 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); 48 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac);
56 }; 49 };
57 50
58 ContinueWindowMac::ContinueWindowMac(const UiStrings* ui_strings) 51 ContinueWindowMac::ContinueWindowMac(const UiStrings& ui_strings)
59 : ui_strings_(ui_strings) { 52 : ContinueWindow(ui_strings) {
60 } 53 }
61 54
62 ContinueWindowMac::~ContinueWindowMac() {} 55 ContinueWindowMac::~ContinueWindowMac() {
56 DCHECK(CalledOnValidThread());
57 }
63 58
64 void ContinueWindowMac::Show(const ContinueSessionCallback& callback) { 59 void ContinueWindowMac::ShowUi() {
60 DCHECK(CalledOnValidThread());
61
65 base::mac::ScopedNSAutoreleasePool pool; 62 base::mac::ScopedNSAutoreleasePool pool;
66 controller_.reset( 63 controller_.reset(
67 [[ContinueWindowMacController alloc] initWithUiStrings:ui_strings_ 64 [[ContinueWindowMacController alloc] initWithUiStrings:&ui_strings()
68 callback:callback]); 65 continue_window:this]);
69 [controller_ show]; 66 [controller_ show];
70 } 67 }
71 68
72 void ContinueWindowMac::Hide() { 69 void ContinueWindowMac::HideUi() {
70 DCHECK(CalledOnValidThread());
71
73 base::mac::ScopedNSAutoreleasePool pool; 72 base::mac::ScopedNSAutoreleasePool pool;
74 [controller_ hide]; 73 [controller_ hide];
75 } 74 }
76 75
77 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { 76 // static
78 return scoped_ptr<ContinueWindow>(new ContinueWindowMac(ui_strings)); 77 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow(
78 const UiStrings& ui_strings) {
79 return scoped_ptr<HostWindow>(new ContinueWindowMac(ui_strings));
79 } 80 }
80 81
81 } // namespace remoting 82 } // namespace remoting
82 83
83 @implementation ContinueWindowMacController 84 @implementation ContinueWindowMacController
84 85
85 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings 86 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings
86 callback:(const ContinueSessionCallback&)callback { 87 continue_window:(remoting::ContinueWindow*)continue_window {
87 if ((self = [super init])) { 88 if ((self = [super init])) {
88 callback_ = callback; 89 continue_window_ = continue_window;
89 ui_strings_ = ui_strings; 90 ui_strings_ = ui_strings;
90 } 91 }
91 return self; 92 return self;
92 } 93 }
93 94
94 - (void)show { 95 - (void)show {
95 // Generate window shade 96 // Generate window shade
96 NSArray* screens = [NSScreen screens]; 97 NSArray* screens = [NSScreen screens];
97 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); 98 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]);
98 for (NSScreen *screen in screens) { 99 for (NSScreen *screen in screens) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Remove window shade. 154 // Remove window shade.
154 for (NSWindow* window in shades_.get()) { 155 for (NSWindow* window in shades_.get()) {
155 [window close]; 156 [window close];
156 } 157 }
157 shades_.reset(); 158 shades_.reset();
158 continue_alert_.reset(); 159 continue_alert_.reset();
159 } 160 }
160 161
161 - (void)onCancel:(id)sender { 162 - (void)onCancel:(id)sender {
162 [self hide]; 163 [self hide];
163 callback_.Run(false); 164 continue_window_->DisconnectSession();
164 } 165 }
165 166
166 - (void)onContinue:(id)sender { 167 - (void)onContinue:(id)sender {
167 [self hide]; 168 [self hide];
168 callback_.Run(true); 169 continue_window_->ContinueSession();
169 } 170 }
170 171
171 @end 172 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698