| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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" | 5 #include "remoting/host/continue_window.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/scoped_nsautorelease_pool.h" | 11 #include "base/mac/scoped_nsautorelease_pool.h" |
| 12 #include "base/memory/scoped_nsobject.h" | 12 #include "base/memory/scoped_nsobject.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "remoting/host/chromoting_host.h" | 14 #include "remoting/host/chromoting_host.h" |
| 15 | 15 |
| 16 typedef remoting::ContinueWindow::ContinueSessionCallback |
| 17 ContinueSessionCallback; |
| 18 |
| 16 // Handles the ContinueWindow. | 19 // Handles the ContinueWindow. |
| 17 @interface ContinueWindowMacController : NSObject { | 20 @interface ContinueWindowMacController : NSObject { |
| 18 @private | 21 @private |
| 19 scoped_nsobject<NSMutableArray> shades_; | 22 scoped_nsobject<NSMutableArray> shades_; |
| 20 scoped_nsobject<NSAlert> continue_alert_; | 23 scoped_nsobject<NSAlert> continue_alert_; |
| 21 remoting::ChromotingHost* host_; | 24 remoting::ChromotingHost* host_; |
| 25 ContinueSessionCallback callback_; |
| 22 } | 26 } |
| 23 | 27 |
| 24 - (id)initWithHost:(remoting::ChromotingHost*)host; | 28 - (id)initWithHost:(remoting::ChromotingHost*)host |
| 29 callback:(const ContinueSessionCallback&)callback; |
| 25 - (void)show; | 30 - (void)show; |
| 26 - (void)hide; | 31 - (void)hide; |
| 27 - (void)onCancel:(id)sender; | 32 - (void)onCancel:(id)sender; |
| 28 - (void)onContinue:(id)sender; | 33 - (void)onContinue:(id)sender; |
| 29 @end | 34 @end |
| 30 | 35 |
| 31 namespace remoting { | 36 namespace remoting { |
| 32 | 37 |
| 33 // A bridge between C++ and ObjC implementations of ContinueWindow. | 38 // A bridge between C++ and ObjC implementations of ContinueWindow. |
| 34 // Everything important occurs in ContinueWindowMacController. | 39 // Everything important occurs in ContinueWindowMacController. |
| 35 class ContinueWindowMac : public remoting::ContinueWindow { | 40 class ContinueWindowMac : public remoting::ContinueWindow { |
| 36 public: | 41 public: |
| 37 ContinueWindowMac() {} | 42 ContinueWindowMac() {} |
| 38 virtual ~ContinueWindowMac() {} | 43 virtual ~ContinueWindowMac() {} |
| 39 | 44 |
| 40 virtual void Show(remoting::ChromotingHost* host) OVERRIDE; | 45 virtual void Show(remoting::ChromotingHost* host, |
| 46 const ContinueSessionCallback& callback) OVERRIDE; |
| 41 virtual void Hide() OVERRIDE; | 47 virtual void Hide() OVERRIDE; |
| 42 | 48 |
| 43 private: | 49 private: |
| 44 scoped_nsobject<ContinueWindowMacController> controller_; | 50 scoped_nsobject<ContinueWindowMacController> controller_; |
| 51 ContinueSessionCallback callback_; |
| 45 | 52 |
| 46 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); | 53 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); |
| 47 }; | 54 }; |
| 48 | 55 |
| 49 void ContinueWindowMac::Show(remoting::ChromotingHost* host) { | 56 void ContinueWindowMac::Show(remoting::ChromotingHost* host, |
| 57 const ContinueSessionCallback& callback) { |
| 50 base::mac::ScopedNSAutoreleasePool pool; | 58 base::mac::ScopedNSAutoreleasePool pool; |
| 51 controller_.reset([[ContinueWindowMacController alloc] initWithHost:host]); | 59 controller_.reset( |
| 60 [[ContinueWindowMacController alloc] initWithHost:host |
| 61 callback:callback]); |
| 52 [controller_ show]; | 62 [controller_ show]; |
| 53 | |
| 54 } | 63 } |
| 55 | 64 |
| 56 void ContinueWindowMac::Hide() { | 65 void ContinueWindowMac::Hide() { |
| 57 base::mac::ScopedNSAutoreleasePool pool; | 66 base::mac::ScopedNSAutoreleasePool pool; |
| 58 [controller_ hide]; | 67 [controller_ hide]; |
| 59 } | 68 } |
| 60 | 69 |
| 61 ContinueWindow* ContinueWindow::Create() { | 70 ContinueWindow* ContinueWindow::Create() { |
| 62 return new ContinueWindowMac(); | 71 return new ContinueWindowMac(); |
| 63 } | 72 } |
| 64 | 73 |
| 65 } // namespace remoting | 74 } // namespace remoting |
| 66 | 75 |
| 67 @implementation ContinueWindowMacController | 76 @implementation ContinueWindowMacController |
| 68 | 77 |
| 69 - (id)initWithHost:(remoting::ChromotingHost*)host { | 78 - (id)initWithHost:(remoting::ChromotingHost*)host |
| 79 callback:(const ContinueSessionCallback&)callback { |
| 70 if ((self = [super init])) { | 80 if ((self = [super init])) { |
| 71 host_ = host; | 81 host_ = host; |
| 82 callback_ = callback; |
| 72 } | 83 } |
| 73 return self; | 84 return self; |
| 74 } | 85 } |
| 75 | 86 |
| 76 - (void)show { | 87 - (void)show { |
| 77 // Generate window shade | 88 // Generate window shade |
| 78 NSArray* screens = [NSScreen screens]; | 89 NSArray* screens = [NSScreen screens]; |
| 79 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); | 90 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); |
| 80 for (NSScreen *screen in screens) { | 91 for (NSScreen *screen in screens) { |
| 81 NSWindow* shade = | 92 NSWindow* shade = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Remove window shade. | 147 // Remove window shade. |
| 137 for (NSWindow* window in shades_.get()) { | 148 for (NSWindow* window in shades_.get()) { |
| 138 [window close]; | 149 [window close]; |
| 139 } | 150 } |
| 140 shades_.reset(); | 151 shades_.reset(); |
| 141 continue_alert_.reset(); | 152 continue_alert_.reset(); |
| 142 } | 153 } |
| 143 | 154 |
| 144 - (void)onCancel:(id)sender { | 155 - (void)onCancel:(id)sender { |
| 145 [self hide]; | 156 [self hide]; |
| 146 host_->Shutdown(base::Closure()); | 157 callback_.Run(false); |
| 147 host_ = nil; | 158 host_ = nil; |
| 148 } | 159 } |
| 149 | 160 |
| 150 - (void)onContinue:(id)sender { | 161 - (void)onContinue:(id)sender { |
| 151 [self hide]; | 162 [self hide]; |
| 152 host_->PauseSession(false); | 163 callback_.Run(true); |
| 153 host_ = nil; | 164 host_ = nil; |
| 154 } | 165 } |
| 155 | 166 |
| 156 @end | 167 @end |
| OLD | NEW |