15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <atldef.h> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace base { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CommandLine; 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace delegate_execute { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Parses a portion of the DelegateExecute handler's command line to determine 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the desired operation. The operation type is decided by looking at the 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// command line. The operations are: 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DELEGATE_EXECUTE: 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// When the delegate_execute.exe is invoked by windows when a chrome 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// activation via the shell, possibly using ShellExecute. Control must 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be given to ATLs WinMain. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RELAUNCH_CHROME: 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// When the delegate_execute.exe is launched by chrome, when chrome needs 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to re-launch itself. The required command line parameters are: 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --relaunch-shortcut=<PathToShortcut> 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --wait-for-mutex=<MutexNamePid> 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The PathToShortcut must be the fully qualified file name to the chrome 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// shortcut that has the appId and other 'metro ready' parameters. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The MutexNamePid is a mutex name that also encodes the process id and 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// must follow the format <A>.<B>.<pid> where A and B are arbitray strings 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (usually chrome.relaunch) and pid is the process id of chrome. 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DelegateExecuteOperation { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum OperationType { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DELEGATE_EXECUTE, 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RELAUNCH_CHROME, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DelegateExecuteOperation(); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~DelegateExecuteOperation(); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool Init(const base::CommandLine* cmd_line); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OperationType operation_type() const { 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return operation_type_; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& relaunch_flags() const { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return relaunch_flags_; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& mutex() const { 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return mutex_; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the process id of the parent or 0 on failure. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DWORD GetParentPid() const; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& shortcut() const { 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return relaunch_shortcut_; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OperationType operation_type_; 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 relaunch_flags_; 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relaunch_shortcut_; 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 mutex_; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DelegateExecuteOperation); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace delegate_execute 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_ 81