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

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

Issue 11886051: Turned UiStrings into a singleton so that the continue window does not depend on ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 11 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
« no previous file with comments | « remoting/host/continue_window_gtk.cc ('k') | remoting/host/continue_window_win.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 // 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" 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/ui_strings.h"
15 15
16 typedef remoting::ContinueWindow::ContinueSessionCallback 16 typedef remoting::ContinueWindow::ContinueSessionCallback
17 ContinueSessionCallback; 17 ContinueSessionCallback;
18 18
19 // Handles the ContinueWindow. 19 // Handles the ContinueWindow.
20 @interface ContinueWindowMacController : NSObject { 20 @interface ContinueWindowMacController : NSObject {
21 @private 21 @private
22 scoped_nsobject<NSMutableArray> shades_; 22 scoped_nsobject<NSMutableArray> shades_;
23 scoped_nsobject<NSAlert> continue_alert_; 23 scoped_nsobject<NSAlert> continue_alert_;
24 remoting::ChromotingHost* host_;
25 ContinueSessionCallback callback_; 24 ContinueSessionCallback callback_;
25 const remoting::UiStrings* ui_strings_;
26 } 26 }
27 27
28 - (id)initWithHost:(remoting::ChromotingHost*)host 28 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings
29 callback:(const ContinueSessionCallback&)callback; 29 callback:(const ContinueSessionCallback&)callback;
30 - (void)show; 30 - (void)show;
31 - (void)hide; 31 - (void)hide;
32 - (void)onCancel:(id)sender; 32 - (void)onCancel:(id)sender;
33 - (void)onContinue:(id)sender; 33 - (void)onContinue:(id)sender;
34 @end 34 @end
35 35
36 namespace remoting { 36 namespace remoting {
37 37
38 // A bridge between C++ and ObjC implementations of ContinueWindow. 38 // A bridge between C++ and ObjC implementations of ContinueWindow.
39 // Everything important occurs in ContinueWindowMacController. 39 // Everything important occurs in ContinueWindowMacController.
40 class ContinueWindowMac : public remoting::ContinueWindow { 40 class ContinueWindowMac : public remoting::ContinueWindow {
41 public: 41 public:
42 ContinueWindowMac() {} 42 explicit ContinueWindowMac(const UiStrings* ui_strings);
43 virtual ~ContinueWindowMac() {} 43 virtual ~ContinueWindowMac();
44 44
45 virtual void Show(remoting::ChromotingHost* host, 45 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE;
46 const ContinueSessionCallback& callback) OVERRIDE;
47 virtual void Hide() OVERRIDE; 46 virtual void Hide() OVERRIDE;
48 47
49 private: 48 private:
50 scoped_nsobject<ContinueWindowMacController> controller_; 49 scoped_nsobject<ContinueWindowMacController> controller_;
51 ContinueSessionCallback callback_; 50 ContinueSessionCallback callback_;
52 51
52 // Points to the localized strings.
53 const UiStrings* ui_strings_;
54
53 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); 55 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac);
54 }; 56 };
55 57
56 void ContinueWindowMac::Show(remoting::ChromotingHost* host, 58 ContinueWindowMac::ContinueWindowMac(const UiStrings* ui_strings)
57 const ContinueSessionCallback& callback) { 59 : ui_strings_(ui_strings) {
60 }
61
62 ContinueWindowMac::~ContinueWindowMac() {}
63
64 void ContinueWindowMac::Show(const ContinueSessionCallback& callback) {
58 base::mac::ScopedNSAutoreleasePool pool; 65 base::mac::ScopedNSAutoreleasePool pool;
59 controller_.reset( 66 controller_.reset(
60 [[ContinueWindowMacController alloc] initWithHost:host 67 [[ContinueWindowMacController alloc] initWithUiStrings:ui_strings_
61 callback:callback]); 68 callback:callback]);
62 [controller_ show]; 69 [controller_ show];
63 } 70 }
64 71
65 void ContinueWindowMac::Hide() { 72 void ContinueWindowMac::Hide() {
66 base::mac::ScopedNSAutoreleasePool pool; 73 base::mac::ScopedNSAutoreleasePool pool;
67 [controller_ hide]; 74 [controller_ hide];
68 } 75 }
69 76
70 scoped_ptr<ContinueWindow> ContinueWindow::Create() { 77 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) {
71 return scoped_ptr<ContinueWindow>(new ContinueWindowMac()); 78 return scoped_ptr<ContinueWindow>(new ContinueWindowMac(ui_strings));
72 } 79 }
73 80
74 } // namespace remoting 81 } // namespace remoting
75 82
76 @implementation ContinueWindowMacController 83 @implementation ContinueWindowMacController
77 84
78 - (id)initWithHost:(remoting::ChromotingHost*)host 85 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings
79 callback:(const ContinueSessionCallback&)callback { 86 callback:(const ContinueSessionCallback&)callback {
80 if ((self = [super init])) { 87 if ((self = [super init])) {
81 host_ = host;
82 callback_ = callback; 88 callback_ = callback;
89 ui_strings_ = ui_strings;
83 } 90 }
84 return self; 91 return self;
85 } 92 }
86 93
87 - (void)show { 94 - (void)show {
88 // Generate window shade 95 // Generate window shade
89 NSArray* screens = [NSScreen screens]; 96 NSArray* screens = [NSScreen screens];
90 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); 97 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]);
91 for (NSScreen *screen in screens) { 98 for (NSScreen *screen in screens) {
92 NSWindow* shade = 99 NSWindow* shade =
93 [[[NSWindow alloc] initWithContentRect:[screen frame] 100 [[[NSWindow alloc] initWithContentRect:[screen frame]
94 styleMask:NSBorderlessWindowMask 101 styleMask:NSBorderlessWindowMask
95 backing:NSBackingStoreBuffered 102 backing:NSBackingStoreBuffered
96 defer:NO 103 defer:NO
97 screen:screen] autorelease]; 104 screen:screen] autorelease];
98 [shade setReleasedWhenClosed:NO]; 105 [shade setReleasedWhenClosed:NO];
99 [shade setAlphaValue:0.8]; 106 [shade setAlphaValue:0.8];
100 [shade setOpaque:NO]; 107 [shade setOpaque:NO];
101 [shade setBackgroundColor:[NSColor blackColor]]; 108 [shade setBackgroundColor:[NSColor blackColor]];
102 // Raise the window shade above just about everything else. 109 // Raise the window shade above just about everything else.
103 // Leave the dock and menu bar exposed so the user has some basic level 110 // Leave the dock and menu bar exposed so the user has some basic level
104 // of control (like they can quit Chromium). 111 // of control (like they can quit Chromium).
105 [shade setLevel:NSModalPanelWindowLevel - 1]; 112 [shade setLevel:NSModalPanelWindowLevel - 1];
106 [shade orderFront:nil]; 113 [shade orderFront:nil];
107 [shades_ addObject:shade]; 114 [shades_ addObject:shade];
108 } 115 }
109 116
110 // Create alert. 117 // Create alert.
111 const remoting::UiStrings& strings = host_->ui_strings(); 118 NSString* message = base::SysUTF16ToNSString(ui_strings_->continue_prompt);
112 NSString* message = base::SysUTF16ToNSString(strings.continue_prompt);
113 NSString* continue_button_string = base::SysUTF16ToNSString( 119 NSString* continue_button_string = base::SysUTF16ToNSString(
114 strings.continue_button_text); 120 ui_strings_->continue_button_text);
115 NSString* cancel_button_string = base::SysUTF16ToNSString( 121 NSString* cancel_button_string = base::SysUTF16ToNSString(
116 strings.stop_sharing_button_text); 122 ui_strings_->stop_sharing_button_text);
117 continue_alert_.reset([[NSAlert alloc] init]); 123 continue_alert_.reset([[NSAlert alloc] init]);
118 [continue_alert_ setMessageText:message]; 124 [continue_alert_ setMessageText:message];
119 125
120 NSButton* continue_button = 126 NSButton* continue_button =
121 [continue_alert_ addButtonWithTitle:continue_button_string]; 127 [continue_alert_ addButtonWithTitle:continue_button_string];
122 [continue_button setAction:@selector(onContinue:)]; 128 [continue_button setAction:@selector(onContinue:)];
123 [continue_button setTarget:self]; 129 [continue_button setTarget:self];
124 130
125 NSButton* cancel_button = 131 NSButton* cancel_button =
126 [continue_alert_ addButtonWithTitle:cancel_button_string]; 132 [continue_alert_ addButtonWithTitle:cancel_button_string];
(...skipping 21 matching lines...) Expand all
148 for (NSWindow* window in shades_.get()) { 154 for (NSWindow* window in shades_.get()) {
149 [window close]; 155 [window close];
150 } 156 }
151 shades_.reset(); 157 shades_.reset();
152 continue_alert_.reset(); 158 continue_alert_.reset();
153 } 159 }
154 160
155 - (void)onCancel:(id)sender { 161 - (void)onCancel:(id)sender {
156 [self hide]; 162 [self hide];
157 callback_.Run(false); 163 callback_.Run(false);
158 host_ = nil;
159 } 164 }
160 165
161 - (void)onContinue:(id)sender { 166 - (void)onContinue:(id)sender {
162 [self hide]; 167 [self hide];
163 callback_.Run(true); 168 callback_.Run(true);
164 host_ = nil;
165 } 169 }
166 170
167 @end 171 @end
OLDNEW
« no previous file with comments | « remoting/host/continue_window_gtk.cc ('k') | remoting/host/continue_window_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698