• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 // This file defines utility functions that can report details about the
6 // host operating environment.
7 
8 #ifndef CHROME_APP_CLIENT_UTIL_H_
9 #define CHROME_APP_CLIENT_UTIL_H_
10 
11 #include <windows.h>
12 
13 #include <string>
14 #include "base/strings/string16.h"
15 
16 namespace sandbox {
17   struct SandboxInterfaceInfo;
18 }
19 
20 // Gets the path of the current exe with a trailing backslash.
21 base::string16 GetExecutablePath();
22 
23 // Returns the version in the current module's version resource or the empty
24 // string if none found.
25 base::string16 GetCurrentModuleVersion();
26 
27 // Implements the common aspects of loading the main dll for both chrome and
28 // chromium scenarios, which are in charge of implementing two abstract
29 // methods: GetRegistryPath() and OnBeforeLaunch().
30 class MainDllLoader {
31  public:
32   MainDllLoader();
33   virtual ~MainDllLoader();
34 
35   // Loads and calls the entry point of chrome.dll. |instance| is the exe
36   // instance retrieved from wWinMain.
37   // The return value is what the main entry point of chrome.dll returns
38   // upon termination.
39   int Launch(HINSTANCE instance);
40 
41   // Launches a new instance of the browser if the current instance in
42   // persistent mode an upgrade is detected.
43   void RelaunchChromeBrowserWithNewCommandLineIfNeeded();
44 
45  protected:
46   // Called after chrome.dll has been loaded but before the entry point
47   // is invoked. Derived classes can implement custom actions here.
48   // |dll_path| refers to the path of the Chrome dll being loaded.
49   virtual void OnBeforeLaunch(const base::string16& dll_path) = 0;
50 
51   // Called after the chrome.dll entry point returns and before terminating
52   // this process. The return value will be used as the process return code.
53   // |dll_path| refers to the path of the Chrome dll being loaded.
54   virtual int OnBeforeExit(int return_code, const base::string16& dll_path) = 0;
55 
56  private:
57   HMODULE Load(base::string16* version, base::string16* out_file);
58 
59  private:
60   HMODULE dll_;
61   std::string process_type_;
62   const bool metro_mode_;
63 };
64 
65 // Factory for the MainDllLoader. Caller owns the pointer and should call
66 // delete to free it.
67 MainDllLoader* MakeMainDllLoader();
68 
69 #endif  // CHROME_APP_CLIENT_UTIL_H_
70