diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-16 20:30:07 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-16 20:30:07 +0000 |
commit | b47049a6e55ec20778869fd596694addb307aa75 (patch) | |
tree | c574c8db1a2851cec65dd0c559d79a6153033395 | |
parent | 5b5dc341eeaf170ad4aa6d6ba98f8e97c47211dd (diff) | |
download | chromium_src-b47049a6e55ec20778869fd596694addb307aa75.zip chromium_src-b47049a6e55ec20778869fd596694addb307aa75.tar.gz chromium_src-b47049a6e55ec20778869fd596694addb307aa75.tar.bz2 |
Moved the localized strings from ChromotinHost to HostUserInterface, closer to the UI objects that consume them. Removed a dependency on ChromotingHost from the continue window UI wrapper.
BUG=104544
Review URL: https://chromiumcodereview.appspot.com/11886051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177207 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 179 insertions, 186 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 9ac490b..51d50aa 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -380,13 +380,6 @@ void ChromotingHost::DisconnectAllClients() { } } -void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { - DCHECK(network_task_runner_->BelongsToCurrentThread()); - DCHECK_EQ(state_, kInitial); - - ui_strings_ = ui_strings; -} - void ChromotingHost::ShutdownFinish() { DCHECK(network_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kStopping); diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h index a62da33..31b8bba 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -17,7 +17,6 @@ #include "remoting/host/host_key_pair.h" #include "remoting/host/host_status_observer.h" #include "remoting/host/mouse_move_observer.h" -#include "remoting/host/ui_strings.h" #include "remoting/protocol/authenticator.h" #include "remoting/protocol/session_manager.h" #include "remoting/protocol/connection_to_client.h" @@ -151,11 +150,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // clients that were not connected when this method is called. void DisconnectAllClients(); - const UiStrings& ui_strings() { return ui_strings_; } - - // Set localized strings. Must be called before host is started. - void SetUiStrings(const UiStrings& ui_strings); - private: friend class base::RefCountedThreadSafe<ChromotingHost>; friend class ChromotingHostTest; @@ -213,10 +207,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // shutdown. Used only while |state_| is set to kStopping. std::vector<base::Closure> shutdown_tasks_; - // TODO(sergeyu): The following members do not belong to - // ChromotingHost and should be moved elsewhere. - UiStrings ui_strings_; - // The maximum duration of any session. base::TimeDelta max_session_duration_; diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 56a0b0a..4d1f00d 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -82,7 +82,7 @@ class MockIt2MeHostUserInterface : public It2MeHostUserInterface { MockIt2MeHostUserInterface::MockIt2MeHostUserInterface( scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) - : It2MeHostUserInterface(network_task_runner, ui_task_runner) { + : It2MeHostUserInterface(network_task_runner, ui_task_runner, UiStrings()) { } void MockIt2MeHostUserInterface::InitFrom( diff --git a/remoting/host/continue_window.h b/remoting/host/continue_window.h index 98e5347..fa1ae25 100644 --- a/remoting/host/continue_window.h +++ b/remoting/host/continue_window.h @@ -9,7 +9,7 @@ namespace remoting { -class ChromotingHost; +struct UiStrings; class ContinueWindow { public: @@ -23,13 +23,12 @@ class ContinueWindow { // Show the continuation window requesting that the user approve continuing // the session. - virtual void Show(ChromotingHost* host, - const ContinueSessionCallback& callback) = 0; + virtual void Show(const ContinueSessionCallback& callback) = 0; // Hide the continuation window if it is visible. virtual void Hide() = 0; - static scoped_ptr<ContinueWindow> Create(); + static scoped_ptr<ContinueWindow> Create(const UiStrings* ui_strings); }; } // namespace remoting diff --git a/remoting/host/continue_window_gtk.cc b/remoting/host/continue_window_gtk.cc index 2dc3f43..906e50f 100644 --- a/remoting/host/continue_window_gtk.cc +++ b/remoting/host/continue_window_gtk.cc @@ -9,7 +9,6 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "remoting/host/chromoting_host.h" #include "remoting/host/ui_strings.h" #include "ui/base/gtk/gtk_signal.h" @@ -17,43 +16,45 @@ namespace remoting { class ContinueWindowGtk : public remoting::ContinueWindow { public: - ContinueWindowGtk(); + explicit ContinueWindowGtk(const UiStrings* ui_strings); virtual ~ContinueWindowGtk(); - virtual void Show(remoting::ChromotingHost* host, - const ContinueSessionCallback& callback) OVERRIDE; + virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; virtual void Hide() OVERRIDE; private: CHROMEGTK_CALLBACK_1(ContinueWindowGtk, void, OnResponse, int); - void CreateWindow(const UiStrings& ui_strings); + void CreateWindow(); - ChromotingHost* host_; ContinueSessionCallback callback_; GtkWidget* continue_window_; + // Points to the localized strings. + const UiStrings* ui_strings_; + DISALLOW_COPY_AND_ASSIGN(ContinueWindowGtk); }; -ContinueWindowGtk::ContinueWindowGtk() - : host_(NULL), - continue_window_(NULL) { +ContinueWindowGtk::ContinueWindowGtk(const UiStrings* ui_strings) + : continue_window_(NULL), + ui_strings_(ui_strings) { } ContinueWindowGtk::~ContinueWindowGtk() { } -void ContinueWindowGtk::CreateWindow(const UiStrings& ui_strings) { - if (continue_window_) return; +void ContinueWindowGtk::CreateWindow() { + if (continue_window_) + return; continue_window_ = gtk_dialog_new_with_buttons( - UTF16ToUTF8(ui_strings.product_name).c_str(), + UTF16ToUTF8(ui_strings_->product_name).c_str(), NULL, static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), - UTF16ToUTF8(ui_strings.stop_sharing_button_text).c_str(), + UTF16ToUTF8(ui_strings_->stop_sharing_button_text).c_str(), GTK_RESPONSE_CANCEL, - UTF16ToUTF8(ui_strings.continue_button_text).c_str(), + UTF16ToUTF8(ui_strings_->continue_button_text).c_str(), GTK_RESPONSE_OK, NULL); @@ -72,7 +73,7 @@ void ContinueWindowGtk::CreateWindow(const UiStrings& ui_strings) { gtk_dialog_get_content_area(GTK_DIALOG(continue_window_)); GtkWidget* text_label = - gtk_label_new(UTF16ToUTF8(ui_strings.continue_prompt).c_str()); + gtk_label_new(UTF16ToUTF8(ui_strings_->continue_prompt).c_str()); gtk_label_set_line_wrap(GTK_LABEL(text_label), TRUE); // TODO(lambroslambrou): Fix magic numbers, as in disconnect_window_gtk.cc. gtk_misc_set_padding(GTK_MISC(text_label), 12, 12); @@ -81,11 +82,9 @@ void ContinueWindowGtk::CreateWindow(const UiStrings& ui_strings) { gtk_widget_show_all(content_area); } -void ContinueWindowGtk::Show(remoting::ChromotingHost* host, - const ContinueSessionCallback& callback) { - host_ = host; +void ContinueWindowGtk::Show(const ContinueSessionCallback& callback) { callback_ = callback; - CreateWindow(host->ui_strings()); + CreateWindow(); gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE); gtk_window_present(GTK_WINDOW(continue_window_)); } @@ -102,8 +101,8 @@ void ContinueWindowGtk::OnResponse(GtkWidget* dialog, int response_id) { Hide(); } -scoped_ptr<ContinueWindow> ContinueWindow::Create() { - return scoped_ptr<ContinueWindow>(new ContinueWindowGtk()); +scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { + return scoped_ptr<ContinueWindow>(new ContinueWindowGtk(ui_strings)); } } // namespace remoting diff --git a/remoting/host/continue_window_mac.mm b/remoting/host/continue_window_mac.mm index c42cf91..9265e44 100644 --- a/remoting/host/continue_window_mac.mm +++ b/remoting/host/continue_window_mac.mm @@ -11,7 +11,7 @@ #include "base/mac/scoped_nsautorelease_pool.h" #include "base/memory/scoped_nsobject.h" #include "base/sys_string_conversions.h" -#include "remoting/host/chromoting_host.h" +#include "remoting/host/ui_strings.h" typedef remoting::ContinueWindow::ContinueSessionCallback ContinueSessionCallback; @@ -21,12 +21,12 @@ typedef remoting::ContinueWindow::ContinueSessionCallback @private scoped_nsobject<NSMutableArray> shades_; scoped_nsobject<NSAlert> continue_alert_; - remoting::ChromotingHost* host_; ContinueSessionCallback callback_; + const remoting::UiStrings* ui_strings_; } -- (id)initWithHost:(remoting::ChromotingHost*)host - callback:(const ContinueSessionCallback&)callback; +- (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings + callback:(const ContinueSessionCallback&)callback; - (void)show; - (void)hide; - (void)onCancel:(id)sender; @@ -39,26 +39,33 @@ namespace remoting { // Everything important occurs in ContinueWindowMacController. class ContinueWindowMac : public remoting::ContinueWindow { public: - ContinueWindowMac() {} - virtual ~ContinueWindowMac() {} + explicit ContinueWindowMac(const UiStrings* ui_strings); + virtual ~ContinueWindowMac(); - virtual void Show(remoting::ChromotingHost* host, - const ContinueSessionCallback& callback) OVERRIDE; + virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; virtual void Hide() OVERRIDE; private: scoped_nsobject<ContinueWindowMacController> controller_; ContinueSessionCallback callback_; + // Points to the localized strings. + const UiStrings* ui_strings_; + DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); }; -void ContinueWindowMac::Show(remoting::ChromotingHost* host, - const ContinueSessionCallback& callback) { +ContinueWindowMac::ContinueWindowMac(const UiStrings* ui_strings) + : ui_strings_(ui_strings) { +} + +ContinueWindowMac::~ContinueWindowMac() {} + +void ContinueWindowMac::Show(const ContinueSessionCallback& callback) { base::mac::ScopedNSAutoreleasePool pool; controller_.reset( - [[ContinueWindowMacController alloc] initWithHost:host - callback:callback]); + [[ContinueWindowMacController alloc] initWithUiStrings:ui_strings_ + callback:callback]); [controller_ show]; } @@ -67,19 +74,19 @@ void ContinueWindowMac::Hide() { [controller_ hide]; } -scoped_ptr<ContinueWindow> ContinueWindow::Create() { - return scoped_ptr<ContinueWindow>(new ContinueWindowMac()); +scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { + return scoped_ptr<ContinueWindow>(new ContinueWindowMac(ui_strings)); } } // namespace remoting @implementation ContinueWindowMacController -- (id)initWithHost:(remoting::ChromotingHost*)host - callback:(const ContinueSessionCallback&)callback { +- (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings + callback:(const ContinueSessionCallback&)callback { if ((self = [super init])) { - host_ = host; callback_ = callback; + ui_strings_ = ui_strings; } return self; } @@ -108,12 +115,11 @@ scoped_ptr<ContinueWindow> ContinueWindow::Create() { } // Create alert. - const remoting::UiStrings& strings = host_->ui_strings(); - NSString* message = base::SysUTF16ToNSString(strings.continue_prompt); + NSString* message = base::SysUTF16ToNSString(ui_strings_->continue_prompt); NSString* continue_button_string = base::SysUTF16ToNSString( - strings.continue_button_text); + ui_strings_->continue_button_text); NSString* cancel_button_string = base::SysUTF16ToNSString( - strings.stop_sharing_button_text); + ui_strings_->stop_sharing_button_text); continue_alert_.reset([[NSAlert alloc] init]); [continue_alert_ setMessageText:message]; @@ -155,13 +161,11 @@ scoped_ptr<ContinueWindow> ContinueWindow::Create() { - (void)onCancel:(id)sender { [self hide]; callback_.Run(false); - host_ = nil; } - (void)onContinue:(id)sender { [self hide]; callback_.Run(true); - host_ = nil; } @end diff --git a/remoting/host/continue_window_win.cc b/remoting/host/continue_window_win.cc index 8e81439..76cc42b 100644 --- a/remoting/host/continue_window_win.cc +++ b/remoting/host/continue_window_win.cc @@ -9,8 +9,8 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "remoting/host/chromoting_host.h" #include "remoting/host/host_ui_resource.h" +#include "remoting/host/ui_strings.h" // TODO(garykac): Lots of duplicated code in this file and // disconnect_window_win.cc. These global floating windows are temporary so @@ -27,11 +27,10 @@ namespace remoting { class ContinueWindowWin : public ContinueWindow { public: - ContinueWindowWin(); + explicit ContinueWindowWin(const UiStrings* ui_strings); virtual ~ContinueWindowWin(); - virtual void Show(remoting::ChromotingHost* host, - const ContinueSessionCallback& callback) OVERRIDE; + virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; virtual void Hide() OVERRIDE; private: @@ -41,18 +40,20 @@ class ContinueWindowWin : public ContinueWindow { BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void EndDialog(); - void SetStrings(const UiStrings& strings); + void SetStrings(); - remoting::ChromotingHost* host_; ContinueSessionCallback callback_; HWND hwnd_; + // Points to the localized strings. + const UiStrings* ui_strings_; + DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); }; -ContinueWindowWin::ContinueWindowWin() - : host_(NULL), - hwnd_(NULL) { +ContinueWindowWin::ContinueWindowWin(const UiStrings* ui_strings) + : hwnd_(NULL), + ui_strings_(ui_strings) { } ContinueWindowWin::~ContinueWindowWin() { @@ -102,9 +103,7 @@ BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, return FALSE; } -void ContinueWindowWin::Show(ChromotingHost* host, - const ContinueSessionCallback& callback) { - host_ = host; +void ContinueWindowWin::Show(const ContinueSessionCallback& callback) { callback_ = callback; CHECK(!hwnd_); @@ -115,7 +114,7 @@ void ContinueWindowWin::Show(ChromotingHost* host, return; } - SetStrings(host->ui_strings()); + SetStrings(); ShowWindow(hwnd_, SW_SHOW); } @@ -130,24 +129,24 @@ void ContinueWindowWin::EndDialog() { } } -void ContinueWindowWin::SetStrings(const UiStrings& strings) { - SetWindowText(hwnd_, strings.product_name.c_str()); +void ContinueWindowWin::SetStrings() { + SetWindowText(hwnd_, ui_strings_->product_name.c_str()); HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE); CHECK(hwndMessage); - SetWindowText(hwndMessage, strings.continue_prompt.c_str()); + SetWindowText(hwndMessage, ui_strings_->continue_prompt.c_str()); HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT); CHECK(hwndDefault); - SetWindowText(hwndDefault, strings.continue_button_text.c_str()); + SetWindowText(hwndDefault, ui_strings_->continue_button_text.c_str()); HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL); CHECK(hwndCancel); - SetWindowText(hwndCancel, strings.stop_sharing_button_text.c_str()); + SetWindowText(hwndCancel, ui_strings_->stop_sharing_button_text.c_str()); } -scoped_ptr<ContinueWindow> ContinueWindow::Create() { - return scoped_ptr<ContinueWindow>(new ContinueWindowWin()); +scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { + return scoped_ptr<ContinueWindow>(new ContinueWindowWin(ui_strings)); } } // namespace remoting diff --git a/remoting/host/desktop_session_agent.cc b/remoting/host/desktop_session_agent.cc index a09e643..39a2aec 100644 --- a/remoting/host/desktop_session_agent.cc +++ b/remoting/host/desktop_session_agent.cc @@ -195,9 +195,9 @@ void DesktopSessionAgent::OnStartSessionAgent( base::Bind(&DesktopSessionAgent::DisconnectSession, this); // Create the disconnect window. - disconnect_window_ = DisconnectWindow::Create(); + disconnect_window_ = DisconnectWindow::Create(&ui_strings_); disconnect_window_->Show( - ui_strings_, disconnect_session, + disconnect_session, authenticated_jid.substr(0, authenticated_jid.find('/'))); // Start monitoring local input. diff --git a/remoting/host/disconnect_window.h b/remoting/host/disconnect_window.h index 1bc053b..7c38bfa 100644 --- a/remoting/host/disconnect_window.h +++ b/remoting/host/disconnect_window.h @@ -23,20 +23,20 @@ class DisconnectWindow { virtual ~DisconnectWindow() {} // Shows the disconnect window, allowing the user to disconnect the session. - // The window will display text from |ui_strings| and |username|. // |disconnect_callback| will be invoked on the calling UI thread when the // user chooses to disconnect, or if the window is closed by any means other // than Hide(), or deletion of the DisconnectWindow instance. // Show returns false if the window cannot be shown, in which case the // callback will not be invoked. - virtual bool Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, + virtual bool Show(const base::Closure& disconnect_callback, const std::string& username) = 0; // Hides the disconnect window. The disconnect callback will not be invoked. virtual void Hide() = 0; - static scoped_ptr<DisconnectWindow> Create(); + // |ui_strings| specifies localized strings to be used by the window. + // |ui_strings| must outlive the returned object. + static scoped_ptr<DisconnectWindow> Create(const UiStrings* ui_strings); }; } // namespace remoting diff --git a/remoting/host/disconnect_window_gtk.cc b/remoting/host/disconnect_window_gtk.cc index 4f818b1..3cdf58d 100644 --- a/remoting/host/disconnect_window_gtk.cc +++ b/remoting/host/disconnect_window_gtk.cc @@ -18,11 +18,10 @@ namespace remoting { class DisconnectWindowGtk : public DisconnectWindow { public: - DisconnectWindowGtk(); + explicit DisconnectWindowGtk(const UiStrings* ui_strings); virtual ~DisconnectWindowGtk(); - virtual bool Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, + virtual bool Show(const base::Closure& disconnect_callback, const std::string& username) OVERRIDE; virtual void Hide() OVERRIDE; @@ -34,7 +33,7 @@ class DisconnectWindowGtk : public DisconnectWindow { CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnButtonPress, GdkEventButton*); - void CreateWindow(const UiStrings& ui_strings); + void CreateWindow(); base::Closure disconnect_callback_; GtkWidget* disconnect_window_; @@ -46,28 +45,33 @@ class DisconnectWindowGtk : public DisconnectWindow { int current_width_; int current_height_; + // Points to the localized strings. + const UiStrings* ui_strings_; + DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk); }; -DisconnectWindowGtk::DisconnectWindowGtk() +DisconnectWindowGtk::DisconnectWindowGtk(const UiStrings* ui_strings) : disconnect_window_(NULL), current_width_(0), - current_height_(0) { + current_height_(0), + ui_strings_(ui_strings) { } DisconnectWindowGtk::~DisconnectWindowGtk() { Hide(); } -void DisconnectWindowGtk::CreateWindow(const UiStrings& ui_strings) { - if (disconnect_window_) return; +void DisconnectWindowGtk::CreateWindow() { + if (disconnect_window_) + return; disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); GtkWindow* window = GTK_WINDOW(disconnect_window_); g_signal_connect(disconnect_window_, "delete-event", G_CALLBACK(OnDeleteThunk), this); - gtk_window_set_title(window, UTF16ToUTF8(ui_strings.product_name).c_str()); + gtk_window_set_title(window, UTF16ToUTF8(ui_strings_->product_name).c_str()); gtk_window_set_resizable(window, FALSE); // Try to keep the window always visible. @@ -111,7 +115,7 @@ void DisconnectWindowGtk::CreateWindow(const UiStrings& ui_strings) { gtk_container_add(GTK_CONTAINER(align), button_row); button_ = gtk_button_new_with_label( - UTF16ToUTF8(ui_strings.disconnect_button_text).c_str()); + UTF16ToUTF8(ui_strings_->disconnect_button_text).c_str()); gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0); g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this); @@ -129,18 +133,17 @@ void DisconnectWindowGtk::CreateWindow(const UiStrings& ui_strings) { gtk_widget_show_all(disconnect_window_); } -bool DisconnectWindowGtk::Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, +bool DisconnectWindowGtk::Show(const base::Closure& disconnect_callback, const std::string& username) { DCHECK(disconnect_callback_.is_null()); DCHECK(!disconnect_callback.is_null()); DCHECK(!disconnect_window_); disconnect_callback_ = disconnect_callback; - CreateWindow(ui_strings); + CreateWindow(); string16 text = ReplaceStringPlaceholders( - ui_strings.disconnect_message, UTF8ToUTF16(username), NULL); + ui_strings_->disconnect_message, UTF8ToUTF16(username), NULL); gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str()); gtk_window_present(GTK_WINDOW(disconnect_window_)); return true; @@ -279,8 +282,9 @@ gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget, return FALSE; } -scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { - return scoped_ptr<DisconnectWindow>(new DisconnectWindowGtk()); +scoped_ptr<DisconnectWindow> DisconnectWindow::Create( + const UiStrings* ui_strings) { + return scoped_ptr<DisconnectWindow>(new DisconnectWindowGtk(ui_strings)); } } // namespace remoting diff --git a/remoting/host/disconnect_window_mac.h b/remoting/host/disconnect_window_mac.h index c5e1db9..a490aec 100644 --- a/remoting/host/disconnect_window_mac.h +++ b/remoting/host/disconnect_window_mac.h @@ -19,16 +19,14 @@ struct UiStrings; // quickly disconnect a session. @interface DisconnectWindowController : NSWindowController { @private - bool rtl_; - string16 disconnect_message_; - string16 disconnect_button_text_; + const remoting::UiStrings* ui_strings_; base::Closure disconnect_callback_; string16 username_; IBOutlet NSTextField* connectedToField_; IBOutlet NSButton* disconnectButton_; } -- (id)initWithUiStrings:(const remoting::UiStrings&)ui_strings +- (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings callback:(const base::Closure&)disconnect_callback username:(const std::string&)username; - (IBAction)stopSharing:(id)sender; diff --git a/remoting/host/disconnect_window_mac.mm b/remoting/host/disconnect_window_mac.mm index 1f504a3..dfd4ca4 100644 --- a/remoting/host/disconnect_window_mac.mm +++ b/remoting/host/disconnect_window_mac.mm @@ -21,36 +21,38 @@ namespace remoting { class DisconnectWindowMac : public remoting::DisconnectWindow { public: - DisconnectWindowMac(); + explicit DisconnectWindowMac(const UiStrings* ui_strings); virtual ~DisconnectWindowMac(); - virtual bool Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, + virtual bool Show(const base::Closure& disconnect_callback, const std::string& username) OVERRIDE; virtual void Hide() OVERRIDE; private: DisconnectWindowController* window_controller_; + // Points to the localized strings. + const UiStrings* ui_strings_; + DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); }; -DisconnectWindowMac::DisconnectWindowMac() - : window_controller_(nil) { +DisconnectWindowMac::DisconnectWindowMac(const UiStrings* ui_strings) + : window_controller_(nil), + ui_strings_(ui_strings) { } DisconnectWindowMac::~DisconnectWindowMac() { Hide(); } -bool DisconnectWindowMac::Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, +bool DisconnectWindowMac::Show(const base::Closure& disconnect_callback, const std::string& username) { DCHECK(!disconnect_callback.is_null()); DCHECK(window_controller_ == nil); window_controller_ = - [[DisconnectWindowController alloc] initWithUiStrings:ui_strings + [[DisconnectWindowController alloc] initWithUiStrings:ui_strings_ callback:disconnect_callback username:username]; [window_controller_ showWindow:nil]; @@ -64,21 +66,20 @@ void DisconnectWindowMac::Hide() { window_controller_ = nil; } -scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { - return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac()); +scoped_ptr<DisconnectWindow> DisconnectWindow::Create( + const UiStrings* ui_strings) { + return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac(ui_strings)); } } // namespace remoting @implementation DisconnectWindowController -- (id)initWithUiStrings:(const remoting::UiStrings&)ui_strings +- (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings callback:(const base::Closure&)disconnect_callback username:(const std::string&)username { self = [super initWithWindowNibName:@"disconnect_window"]; if (self) { - rtl_ = (ui_strings.direction == remoting::UiStrings::RTL); - disconnect_message_ = ui_strings.disconnect_message; - disconnect_button_text_ = ui_strings.disconnect_button_text; + ui_strings_ = ui_strings; disconnect_callback_ = disconnect_callback; username_ = UTF8ToUTF16(username); } @@ -96,7 +97,7 @@ scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { } - (BOOL)isRToL { - return rtl_; + return ui_strings_->direction == remoting::UiStrings::RTL; } - (void)Hide { @@ -105,12 +106,12 @@ scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { } - (void)windowDidLoad { - string16 text = ReplaceStringPlaceholders(disconnect_message_, username_, - NULL); + string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message, + username_, NULL); [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; [disconnectButton_ setTitle:base::SysUTF16ToNSString( - disconnect_button_text_)]; + ui_strings_->disconnect_button_text)]; // Resize the window dynamically based on the content. CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); diff --git a/remoting/host/disconnect_window_win.cc b/remoting/host/disconnect_window_win.cc index c07ed25..ff41c67 100644 --- a/remoting/host/disconnect_window_win.cc +++ b/remoting/host/disconnect_window_win.cc @@ -38,12 +38,11 @@ namespace remoting { class DisconnectWindowWin : public DisconnectWindow { public: - DisconnectWindowWin(); + explicit DisconnectWindowWin(const UiStrings* ui_strings); virtual ~DisconnectWindowWin(); // DisconnectWindow interface. - virtual bool Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, + virtual bool Show(const base::Closure& disconnect_callback, const std::string& username) OVERRIDE; virtual void Hide() OVERRIDE; @@ -54,8 +53,7 @@ private: BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); // Creates the dialog window and registers the disconnect hot key. - bool BeginDialog(const UiStrings& ui_strings, - const std::string& username); + bool BeginDialog(const std::string& username); // Closes the dialog, unregisters the hot key and invokes the disconnect // callback, if set. @@ -65,13 +63,16 @@ private: void SetDialogPosition(); // Applies localization string and resizes the dialog. - bool SetStrings(const UiStrings& strings, const string16& username); + bool SetStrings(const string16& username); base::Closure disconnect_callback_; HWND hwnd_; bool has_hotkey_; base::win::ScopedGDIObject<HPEN> border_pen_; + // Points to the localized strings. + const UiStrings* ui_strings_; + DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); }; @@ -88,26 +89,26 @@ static int GetControlTextWidth(HWND control) { return rect.right; } -DisconnectWindowWin::DisconnectWindowWin() +DisconnectWindowWin::DisconnectWindowWin(const UiStrings* ui_strings) : hwnd_(NULL), has_hotkey_(false), border_pen_(CreatePen(PS_SOLID, 5, - RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { + RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))), + ui_strings_(ui_strings) { } DisconnectWindowWin::~DisconnectWindowWin() { Hide(); } -bool DisconnectWindowWin::Show(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, +bool DisconnectWindowWin::Show(const base::Closure& disconnect_callback, const std::string& username) { DCHECK(disconnect_callback_.is_null()); DCHECK(!disconnect_callback.is_null()); disconnect_callback_ = disconnect_callback; - if (BeginDialog(ui_strings, username)) { + if (BeginDialog(username)) { return true; } else { Hide(); @@ -209,8 +210,7 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message, return FALSE; } -bool DisconnectWindowWin::BeginDialog(const UiStrings& ui_strings, - const std::string& username) { +bool DisconnectWindowWin::BeginDialog(const std::string& username) { DCHECK(!hwnd_); // Load the dialog resource so that we can modify the RTL flags if necessary. @@ -233,7 +233,7 @@ bool DisconnectWindowWin::BeginDialog(const UiStrings& ui_strings, // standard headers, so we treat it as a generic pointer and manipulate the // correct offsets explicitly. scoped_array<unsigned char> rtl_dialog_template; - if (ui_strings.direction == UiStrings::RTL) { + if (ui_strings_->direction == UiStrings::RTL) { unsigned long dialog_template_size = SizeofResource(module, dialog_resource); rtl_dialog_template.reset(new unsigned char[dialog_template_size]); @@ -254,7 +254,7 @@ bool DisconnectWindowWin::BeginDialog(const UiStrings& ui_strings, has_hotkey_ = true; } - if (!SetStrings(ui_strings, UTF8ToUTF16(username))) + if (!SetStrings(UTF8ToUTF16(username))) return false; SetDialogPosition(); @@ -297,9 +297,8 @@ void DisconnectWindowWin::SetDialogPosition() { } } -bool DisconnectWindowWin::SetStrings(const UiStrings& ui_strings, - const string16& username) { - if (!SetWindowText(hwnd_, ui_strings.product_name.c_str())) +bool DisconnectWindowWin::SetStrings(const string16& username) { + if (!SetWindowText(hwnd_, ui_strings_->product_name.c_str())) return false; // Localize the disconnect button text and measure length of the old and new @@ -309,7 +308,7 @@ bool DisconnectWindowWin::SetStrings(const UiStrings& ui_strings, return false; int button_old_required_width = GetControlTextWidth(disconnect_button); if (!SetWindowText(disconnect_button, - ui_strings.disconnect_button_text.c_str())) { + ui_strings_->disconnect_button_text.c_str())) { return false; } int button_new_required_width = GetControlTextWidth(disconnect_button); @@ -317,7 +316,7 @@ bool DisconnectWindowWin::SetStrings(const UiStrings& ui_strings, button_new_required_width - button_old_required_width; // Format and truncate "Your desktop is shared with ..." message. - string16 text = ReplaceStringPlaceholders(ui_strings.disconnect_message, + string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message, username, NULL); if (text.length() > kMaxSharingWithTextLength) text.erase(kMaxSharingWithTextLength); @@ -386,8 +385,9 @@ bool DisconnectWindowWin::SetStrings(const UiStrings& ui_strings, return true; } -scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { - return scoped_ptr<DisconnectWindow>(new DisconnectWindowWin()); +scoped_ptr<DisconnectWindow> DisconnectWindow::Create( + const UiStrings* ui_strings) { + return scoped_ptr<DisconnectWindow>(new DisconnectWindowWin(ui_strings)); } } // namespace remoting diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc index 2fa3d8f..881683d 100644 --- a/remoting/host/host_mock_objects.cc +++ b/remoting/host/host_mock_objects.cc @@ -64,7 +64,8 @@ MockDisconnectWindow::MockDisconnectWindow() {} MockDisconnectWindow::~MockDisconnectWindow() {} -scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { +scoped_ptr<DisconnectWindow> DisconnectWindow::Create( + const UiStrings* ui_strings) { return scoped_ptr<DisconnectWindow>(new MockDisconnectWindow()); } @@ -72,7 +73,7 @@ MockContinueWindow::MockContinueWindow() {} MockContinueWindow::~MockContinueWindow() {} -scoped_ptr<ContinueWindow> ContinueWindow::Create() { +scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { return scoped_ptr<ContinueWindow>(new MockContinueWindow()); } diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h index 93ef0d6..4ca939d 100644 --- a/remoting/host/host_mock_objects.h +++ b/remoting/host/host_mock_objects.h @@ -14,7 +14,6 @@ #include "remoting/host/event_executor.h" #include "remoting/host/host_status_observer.h" #include "remoting/host/local_input_monitor.h" -#include "remoting/host/ui_strings.h" #include "remoting/proto/control.pb.h" #include "testing/gmock/include/gmock/gmock.h" @@ -55,8 +54,7 @@ class MockDisconnectWindow : public DisconnectWindow { MockDisconnectWindow(); virtual ~MockDisconnectWindow(); - MOCK_METHOD3(Show, bool(const UiStrings& ui_strings, - const base::Closure& disconnect_callback, + MOCK_METHOD2(Show, bool(const base::Closure& disconnect_callback, const std::string& username)); MOCK_METHOD0(Hide, void()); }; @@ -76,8 +74,7 @@ class MockContinueWindow : public ContinueWindow { MockContinueWindow(); virtual ~MockContinueWindow(); - MOCK_METHOD2(Show, void( - remoting::ChromotingHost* host, + MOCK_METHOD1(Show, void( const remoting::ContinueWindow::ContinueSessionCallback& callback)); MOCK_METHOD0(Hide, void()); }; diff --git a/remoting/host/host_user_interface.cc b/remoting/host/host_user_interface.cc index 71f6b07..7a4894a 100644 --- a/remoting/host/host_user_interface.cc +++ b/remoting/host/host_user_interface.cc @@ -13,11 +13,13 @@ namespace remoting { HostUserInterface::HostUserInterface( scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, - scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + const UiStrings& ui_strings) : host_(NULL), network_task_runner_(network_task_runner), ui_task_runner_(ui_task_runner), is_monitoring_local_inputs_(false), + ui_strings_(ui_strings), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), weak_ptr_(weak_factory_.GetWeakPtr()) { DCHECK(ui_task_runner_->BelongsToCurrentThread()); @@ -33,7 +35,7 @@ HostUserInterface::~HostUserInterface() { void HostUserInterface::Init() { DCHECK(ui_task_runner_->BelongsToCurrentThread()); - disconnect_window_ = DisconnectWindow::Create(); + disconnect_window_ = DisconnectWindow::Create(&ui_strings()); local_input_monitor_ = LocalInputMonitor::Create(); } @@ -107,7 +109,6 @@ void HostUserInterface::ProcessOnClientAuthenticated( DCHECK(ui_task_runner_->BelongsToCurrentThread()); if (!disconnect_window_->Show( - host_->ui_strings(), base::Bind(&HostUserInterface::OnDisconnectCallback, weak_ptr_), username)) { LOG(ERROR) << "Failed to show the disconnect window."; diff --git a/remoting/host/host_user_interface.h b/remoting/host/host_user_interface.h index 3a89a06..d22cb61 100644 --- a/remoting/host/host_user_interface.h +++ b/remoting/host/host_user_interface.h @@ -14,6 +14,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "remoting/host/host_status_observer.h" +#include "remoting/host/ui_strings.h" namespace base { class SingleThreadTaskRunner; @@ -29,7 +30,8 @@ class HostUserInterface : public HostStatusObserver { public: HostUserInterface( scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, - scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + const UiStrings& ui_strings); virtual ~HostUserInterface(); // Initialize the OS-specific UI objects. @@ -56,6 +58,8 @@ class HostUserInterface : public HostStatusObserver { } ChromotingHost* get_host() const { return host_; } + const UiStrings& ui_strings() const { return ui_strings_; } + base::SingleThreadTaskRunner* network_task_runner() const; base::SingleThreadTaskRunner* ui_task_runner() const; @@ -97,6 +101,9 @@ class HostUserInterface : public HostStatusObserver { bool is_monitoring_local_inputs_; + // TODO(alexeypa): move |ui_strings_| to DesktopEnvironmentFactory. + UiStrings ui_strings_; + // WeakPtr used to avoid tasks accessing the client after it is deleted. base::WeakPtrFactory<HostUserInterface> weak_factory_; base::WeakPtr<HostUserInterface> weak_ptr_; diff --git a/remoting/host/it2me_host_user_interface.cc b/remoting/host/it2me_host_user_interface.cc index 3f0653b..119143e 100644 --- a/remoting/host/it2me_host_user_interface.cc +++ b/remoting/host/it2me_host_user_interface.cc @@ -25,8 +25,9 @@ namespace remoting { It2MeHostUserInterface::It2MeHostUserInterface( scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, - scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) - : HostUserInterface(network_task_runner, ui_task_runner), + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + const UiStrings& ui_strings) + : HostUserInterface(network_task_runner, ui_task_runner, ui_strings), ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) { DCHECK(ui_task_runner->BelongsToCurrentThread()); } @@ -41,7 +42,7 @@ void It2MeHostUserInterface::Init() { DCHECK(ui_task_runner()->BelongsToCurrentThread()); HostUserInterface::Init(); - continue_window_ = ContinueWindow::Create(); + continue_window_ = ContinueWindow::Create(&ui_strings()); } void It2MeHostUserInterface::ProcessOnClientAuthenticated( @@ -97,7 +98,7 @@ void It2MeHostUserInterface::ShowContinueWindow(bool show) { DCHECK(ui_task_runner()->BelongsToCurrentThread()); if (show) { - continue_window_->Show(get_host(), base::Bind( + continue_window_->Show(base::Bind( &It2MeHostUserInterface::ContinueSession, base::Unretained(this))); } else { continue_window_->Hide(); diff --git a/remoting/host/it2me_host_user_interface.h b/remoting/host/it2me_host_user_interface.h index 7471aa0..119d072 100644 --- a/remoting/host/it2me_host_user_interface.h +++ b/remoting/host/it2me_host_user_interface.h @@ -26,7 +26,8 @@ class It2MeHostUserInterface : public HostUserInterface { public: It2MeHostUserInterface( scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, - scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + const UiStrings& ui_strings); virtual ~It2MeHostUserInterface(); // HostUserInterface overrides. diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index 2133b60..b5c3618 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -86,15 +86,15 @@ class HostNPScriptObject::It2MeImpl It2MeImpl( scoped_ptr<ChromotingHostContext> context, scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, - base::WeakPtr<HostNPScriptObject> script_object, - const UiStrings& ui_strings); + base::WeakPtr<HostNPScriptObject> script_object); // Methods called by the script object, from the plugin thread. // Creates It2Me host structures and starts the host. void Connect(const std::string& uid, const std::string& auth_token, - const std::string& auth_service); + const std::string& auth_service, + const UiStrings& ui_strings); // Disconnects the host, ready for tear-down. // Also called internally, from the network thread. @@ -148,7 +148,6 @@ class HostNPScriptObject::It2MeImpl scoped_ptr<ChromotingHostContext> host_context_; scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; base::WeakPtr<HostNPScriptObject> script_object_; - UiStrings ui_strings_; State state_; @@ -188,12 +187,10 @@ class HostNPScriptObject::It2MeImpl HostNPScriptObject::It2MeImpl::It2MeImpl( scoped_ptr<ChromotingHostContext> host_context, scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, - base::WeakPtr<HostNPScriptObject> script_object, - const UiStrings& ui_strings) + base::WeakPtr<HostNPScriptObject> script_object) : host_context_(host_context.Pass()), plugin_task_runner_(plugin_task_runner), script_object_(script_object), - ui_strings_(ui_strings), state_(kDisconnected), failed_login_attempts_(0), nat_traversal_enabled_(false), @@ -204,12 +201,14 @@ HostNPScriptObject::It2MeImpl::It2MeImpl( void HostNPScriptObject::It2MeImpl::Connect( const std::string& uid, const std::string& auth_token, - const std::string& auth_service) { + const std::string& auth_service, + const UiStrings& ui_strings) { if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { DCHECK(plugin_task_runner_->BelongsToCurrentThread()); host_context_->ui_task_runner()->PostTask( FROM_HERE, - base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service)); + base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service, + ui_strings)); return; } @@ -225,7 +224,7 @@ void HostNPScriptObject::It2MeImpl::Connect( // The UserInterface object needs to be created on the UI thread. it2me_host_user_interface_.reset( new It2MeHostUserInterface(host_context_->network_task_runner(), - host_context_->ui_task_runner())); + host_context_->ui_task_runner(), ui_strings)); it2me_host_user_interface_->Init(); // Switch to the network thread to start the actual connection. @@ -381,9 +380,6 @@ void HostNPScriptObject::It2MeImpl::FinishConnect( protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); host_->set_protocol_config(protocol_config.Pass()); - // Provide localization strings to the host. - host_->SetUiStrings(ui_strings_); - // Create user interface. it2me_host_user_interface_->Start(host_.get(), base::Bind(&It2MeImpl::Disconnect, this)); @@ -954,8 +950,8 @@ bool HostNPScriptObject::Connect(const NPVariant* args, // Create the It2Me host implementation and start connecting. it2me_impl_ = new It2MeImpl( - host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_); - it2me_impl_->Connect(uid, auth_token, auth_service); + host_context.Pass(), plugin_task_runner_, weak_ptr_); + it2me_impl_->Connect(uid, auth_token, auth_service, ui_strings_); return true; } diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index 01a9175..741a1d2 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -62,6 +62,7 @@ #include "remoting/host/resizing_host_observer.h" #include "remoting/host/session_manager_factory.h" #include "remoting/host/signaling_connector.h" +#include "remoting/host/ui_strings.h" #include "remoting/host/usage_stats_consent.h" #include "remoting/jingle_glue/xmpp_signal_strategy.h" #include "remoting/protocol/me2me_host_authenticator_factory.h" @@ -602,9 +603,10 @@ void HostProcess::StartOnUiThread() { #endif // OS_MACOSX if (want_user_interface) { + UiStrings ui_strings; host_user_interface_.reset( new HostUserInterface(context_->network_task_runner(), - context_->ui_task_runner())); + context_->ui_task_runner(), ui_strings)); host_user_interface_->Init(); } diff --git a/remoting/host/ui_strings.cc b/remoting/host/ui_strings.cc index 1c0c4c3..f8cb639 100644 --- a/remoting/host/ui_strings.cc +++ b/remoting/host/ui_strings.cc @@ -29,6 +29,6 @@ UiStrings::UiStrings() : stop_sharing_button_text(ASCIIToUTF16("Stop Sharing")) { } -UiStrings::~UiStrings() { } +UiStrings::~UiStrings() {} -} +} // namespace remoting |