| OLD | NEW |
| 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" |
| 12 #include "remoting/host/continue_window.h" |
| 14 #include "remoting/host/ui_strings.h" | 13 #include "remoting/host/ui_strings.h" |
| 15 | 14 |
| 16 typedef remoting::ContinueWindow::ContinueSessionCallback | |
| 17 ContinueSessionCallback; | |
| 18 | |
| 19 // Handles the ContinueWindow. | 15 // Handles the ContinueWindow. |
| 20 @interface ContinueWindowMacController : NSObject { | 16 @interface ContinueWindowMacController : NSObject { |
| 21 @private | 17 @private |
| 22 scoped_nsobject<NSMutableArray> shades_; | 18 scoped_nsobject<NSMutableArray> shades_; |
| 23 scoped_nsobject<NSAlert> continue_alert_; | 19 scoped_nsobject<NSAlert> continue_alert_; |
| 24 ContinueSessionCallback callback_; | 20 remoting::ContinueWindow* continue_window_; |
| 25 const remoting::UiStrings* ui_strings_; | 21 const remoting::UiStrings* ui_strings_; |
| 26 } | 22 } |
| 27 | 23 |
| 28 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings | 24 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings |
| 29 callback:(const ContinueSessionCallback&)callback; | 25 continue_window:(remoting::ContinueWindow*)continue_window; |
| 30 - (void)show; | 26 - (void)show; |
| 31 - (void)hide; | 27 - (void)hide; |
| 32 - (void)onCancel:(id)sender; | 28 - (void)onCancel:(id)sender; |
| 33 - (void)onContinue:(id)sender; | 29 - (void)onContinue:(id)sender; |
| 34 @end | 30 @end |
| 35 | 31 |
| 36 namespace remoting { | 32 namespace remoting { |
| 37 | 33 |
| 38 // A bridge between C++ and ObjC implementations of ContinueWindow. | 34 // A bridge between C++ and ObjC implementations of ContinueWindow. |
| 39 // Everything important occurs in ContinueWindowMacController. | 35 // Everything important occurs in ContinueWindowMacController. |
| 40 class ContinueWindowMac : public remoting::ContinueWindow { | 36 class ContinueWindowMac : public ContinueWindow { |
| 41 public: | 37 public: |
| 42 explicit ContinueWindowMac(const UiStrings* ui_strings); | 38 explicit ContinueWindowMac(const UiStrings& ui_strings); |
| 43 virtual ~ContinueWindowMac(); | 39 virtual ~ContinueWindowMac(); |
| 44 | 40 |
| 45 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; | 41 protected: |
| 46 virtual void Hide() OVERRIDE; | 42 // ContinueWindow overrides. |
| 43 virtual void ShowUi() OVERRIDE; |
| 44 virtual void HideUi() OVERRIDE; |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 scoped_nsobject<ContinueWindowMacController> controller_; | 47 scoped_nsobject<ContinueWindowMacController> controller_; |
| 50 ContinueSessionCallback callback_; | |
| 51 | 48 |
| 52 // Points to the localized strings. | 49 // Localized UI strings. |
| 53 const UiStrings* ui_strings_; | 50 UiStrings ui_strings_; |
| 54 | 51 |
| 55 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); | 52 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); |
| 56 }; | 53 }; |
| 57 | 54 |
| 58 ContinueWindowMac::ContinueWindowMac(const UiStrings* ui_strings) | 55 ContinueWindowMac::ContinueWindowMac(const UiStrings& ui_strings) |
| 59 : ui_strings_(ui_strings) { | 56 : ui_strings_(ui_strings) { |
| 60 } | 57 } |
| 61 | 58 |
| 62 ContinueWindowMac::~ContinueWindowMac() {} | 59 ContinueWindowMac::~ContinueWindowMac() { |
| 60 DCHECK(CalledOnValidThread()); |
| 61 } |
| 63 | 62 |
| 64 void ContinueWindowMac::Show(const ContinueSessionCallback& callback) { | 63 void ContinueWindowMac::ShowUi() { |
| 64 DCHECK(CalledOnValidThread()); |
| 65 |
| 65 base::mac::ScopedNSAutoreleasePool pool; | 66 base::mac::ScopedNSAutoreleasePool pool; |
| 66 controller_.reset( | 67 controller_.reset( |
| 67 [[ContinueWindowMacController alloc] initWithUiStrings:ui_strings_ | 68 [[ContinueWindowMacController alloc] initWithUiStrings:&ui_strings_ |
| 68 callback:callback]); | 69 continue_window:this]); |
| 69 [controller_ show]; | 70 [controller_ show]; |
| 70 } | 71 } |
| 71 | 72 |
| 72 void ContinueWindowMac::Hide() { | 73 void ContinueWindowMac::HideUi() { |
| 74 DCHECK(CalledOnValidThread()); |
| 75 |
| 73 base::mac::ScopedNSAutoreleasePool pool; | 76 base::mac::ScopedNSAutoreleasePool pool; |
| 74 [controller_ hide]; | 77 [controller_ hide]; |
| 75 } | 78 } |
| 76 | 79 |
| 77 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { | 80 // static |
| 78 return scoped_ptr<ContinueWindow>(new ContinueWindowMac(ui_strings)); | 81 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow( |
| 82 const UiStrings& ui_strings) { |
| 83 return scoped_ptr<HostWindow>(new ContinueWindowMac(ui_strings)); |
| 79 } | 84 } |
| 80 | 85 |
| 81 } // namespace remoting | 86 } // namespace remoting |
| 82 | 87 |
| 83 @implementation ContinueWindowMacController | 88 @implementation ContinueWindowMacController |
| 84 | 89 |
| 85 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings | 90 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings |
| 86 callback:(const ContinueSessionCallback&)callback { | 91 continue_window:(remoting::ContinueWindow*)continue_window { |
| 87 if ((self = [super init])) { | 92 if ((self = [super init])) { |
| 88 callback_ = callback; | 93 continue_window_ = continue_window; |
| 89 ui_strings_ = ui_strings; | 94 ui_strings_ = ui_strings; |
| 90 } | 95 } |
| 91 return self; | 96 return self; |
| 92 } | 97 } |
| 93 | 98 |
| 94 - (void)show { | 99 - (void)show { |
| 95 // Generate window shade | 100 // Generate window shade |
| 96 NSArray* screens = [NSScreen screens]; | 101 NSArray* screens = [NSScreen screens]; |
| 97 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); | 102 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); |
| 98 for (NSScreen *screen in screens) { | 103 for (NSScreen *screen in screens) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // Remove window shade. | 158 // Remove window shade. |
| 154 for (NSWindow* window in shades_.get()) { | 159 for (NSWindow* window in shades_.get()) { |
| 155 [window close]; | 160 [window close]; |
| 156 } | 161 } |
| 157 shades_.reset(); | 162 shades_.reset(); |
| 158 continue_alert_.reset(); | 163 continue_alert_.reset(); |
| 159 } | 164 } |
| 160 | 165 |
| 161 - (void)onCancel:(id)sender { | 166 - (void)onCancel:(id)sender { |
| 162 [self hide]; | 167 [self hide]; |
| 163 callback_.Run(false); | 168 continue_window_->DisconnectSession(); |
| 164 } | 169 } |
| 165 | 170 |
| 166 - (void)onContinue:(id)sender { | 171 - (void)onContinue:(id)sender { |
| 167 [self hide]; | 172 [self hide]; |
| 168 callback_.Run(true); | 173 continue_window_->ContinueSession(); |
| 169 } | 174 } |
| 170 | 175 |
| 171 @end | 176 @end |
| OLD | NEW |