Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / remoting / host / setup / me2me_native_messaging_host.cc
index a2a2707..72076db 100644 (file)
@@ -38,6 +38,7 @@ namespace {
 const DWORD kBufferSize = 0;
 const int kTimeOutMilliseconds = 2000;
 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome_remote_desktop.";
+const int kElevatedHostTimeoutSeconds = 300;
 #endif  // defined(OS_WIN)
 
 // redirect_uri to use when authenticating service accounts (service account
@@ -70,11 +71,13 @@ namespace remoting {
 
 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost(
     bool needs_elevation,
+    intptr_t parent_window_handle,
     scoped_ptr<NativeMessagingChannel> channel,
     scoped_refptr<DaemonController> daemon_controller,
     scoped_refptr<protocol::PairingRegistry> pairing_registry,
     scoped_ptr<OAuthClient> oauth_client)
     : needs_elevation_(needs_elevation),
+      parent_window_handle_(parent_window_handle),
       channel_(channel.Pass()),
       daemon_controller_(daemon_controller),
       pairing_registry_(pairing_registry),
@@ -534,7 +537,7 @@ void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
   // Create a security descriptor that gives full access to the caller and
   // denies access by anyone else.
   std::string security_descriptor = base::StringPrintf(
-      "O:%1$sG:%1$sD:(A;;GA;;;%1$s)", WideToASCII(user_sid).c_str());
+      "O:%1$sG:%1$sD:(A;;GA;;;%1$s)", base::UTF16ToASCII(user_sid).c_str());
 
   ScopedSd sd = ConvertSddlToSd(security_descriptor);
   if (!sd) {
@@ -620,10 +623,11 @@ void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
   SHELLEXECUTEINFO info;
   memset(&info, 0, sizeof(info));
   info.cbSize = sizeof(info);
+  info.hwnd = reinterpret_cast<HWND>(parent_window_handle_);
   info.lpVerb = L"runas";
   info.lpFile = binary.value().c_str();
   info.lpParameters = parameters.c_str();
-  info.nShow = SW_SHOWNORMAL;
+  info.nShow = SW_HIDE;
 
   if (!ShellExecuteEx(&info)) {
     DWORD error = ::GetLastError();
@@ -657,11 +661,16 @@ void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
   // Set up the native messaging channel to talk to the elevated host.
   // Note that input for the elevate channel is output forthe elevated host.
   elevated_channel_.reset(new NativeMessagingChannel(
-      delegate_read_handle.Take(), delegate_write_handle.Take()));
+      base::File(delegate_read_handle.Take()),
+      base::File(delegate_write_handle.Take())));
 
   elevated_channel_->Start(
       base::Bind(&Me2MeNativeMessagingHost::ProcessDelegateResponse, weak_ptr_),
       base::Bind(&Me2MeNativeMessagingHost::Stop, weak_ptr_));
+
+  elevated_host_timer_.Start(
+      FROM_HERE, base::TimeDelta::FromSeconds(kElevatedHostTimeoutSeconds),
+      this, &Me2MeNativeMessagingHost::DisconnectElevatedHost);
 }
 
 void Me2MeNativeMessagingHost::ProcessDelegateResponse(
@@ -672,6 +681,13 @@ void Me2MeNativeMessagingHost::ProcessDelegateResponse(
   channel_->SendMessage(message.Pass());
 }
 
+void Me2MeNativeMessagingHost::DisconnectElevatedHost() {
+  DCHECK(thread_checker_.CalledOnValidThread());
+
+  // This will send an EOF to the elevated host, triggering its shutdown.
+  elevated_channel_.reset();
+}
+
 #else  // defined(OS_WIN)
 
 bool Me2MeNativeMessagingHost::DelegateToElevatedHost(