Home | History | Annotate | Download | only in app
      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 "base/strings/string16.h"
     14 
     15 namespace sandbox {
     16   struct SandboxInterfaceInfo;
     17 }
     18 
     19 // Gets the path of the current exe with a trailing backslash.
     20 string16 GetExecutablePath();
     21 
     22 // Returns the version in the current module's version resource or the empty
     23 // string if none found.
     24 string16 GetCurrentModuleVersion();
     25 
     26 // Implements the common aspects of loading chrome.dll for both chrome and
     27 // chromium scenarios, which are in charge of implementing two abstract
     28 // methods: GetRegistryPath() and OnBeforeLaunch().
     29 class MainDllLoader {
     30  public:
     31   MainDllLoader();
     32   virtual ~MainDllLoader();
     33 
     34   // Loads and calls the entry point of chrome.dll. |instance| is the exe
     35   // instance retrieved from wWinMain and the |sbox_info| is the broker or
     36   // target services interface pointer.
     37   // The return value is what the main entry point of chrome.dll returns
     38   // upon termination.
     39   int Launch(HINSTANCE instance, sandbox::SandboxInterfaceInfo* sbox_info);
     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   // Called after chrome.dll has been loaded but before the entry point
     46   // is invoked. Derived classes can implement custom actions here.
     47   // |dll_path| refers to the path of the Chrome dll being loaded.
     48   virtual void OnBeforeLaunch(const string16& dll_path) {}
     49 
     50   // Called after the chrome.dll entry point returns and before terminating
     51   // this process. The return value will be used as the process return code.
     52   // |dll_path| refers to the path of the Chrome dll being loaded.
     53   virtual int OnBeforeExit(int return_code, const string16& dll_path) {
     54     return return_code;
     55   }
     56 
     57  protected:
     58   // Derived classes must return the relative registry path that holds the
     59   // most current version of chrome.dll.
     60   virtual string16 GetRegistryPath() = 0;
     61 
     62   HMODULE Load(string16* out_version, string16* out_file);
     63 
     64  private:
     65   // Chrome.dll handle.
     66   HMODULE dll_;
     67 };
     68 
     69 // Factory for the MainDllLoader. Caller owns the pointer and should call
     70 // delete to free it.
     71 MainDllLoader* MakeMainDllLoader();
     72 
     73 #endif  // CHROME_APP_CLIENT_UTIL_H_
     74