summaryrefslogtreecommitdiffstats
path: root/chrome_frame/module_utils.h
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-05 19:16:07 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-05 19:16:07 +0000
commit8cc419448037675e5742586429bb6c00606ce8f9 (patch)
tree61cd63e10a4c4bd6c4515beb3c0f1489bba0b397 /chrome_frame/module_utils.h
parent39549bf8f876b17f481e753161166370064458bd (diff)
downloadchromium_src-8cc419448037675e5742586429bb6c00606ce8f9.zip
chromium_src-8cc419448037675e5742586429bb6c00606ce8f9.tar.gz
chromium_src-8cc419448037675e5742586429bb6c00606ce8f9.tar.bz2
Implementation of single-module-per-logon-session-per-profile implementation for Chrome Frame.
BUG=61383 TEST=Run IE with version X of CF loaded. Register version Y of CF. Run a second IE process, notice that version Y when loaded defers to version X. Review URL: http://codereview.chromium.org/4144008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/module_utils.h')
-rw-r--r--chrome_frame/module_utils.h79
1 files changed, 64 insertions, 15 deletions
diff --git a/chrome_frame/module_utils.h b/chrome_frame/module_utils.h
index 4cdf4b8..0da5472 100644
--- a/chrome_frame/module_utils.h
+++ b/chrome_frame/module_utils.h
@@ -8,33 +8,82 @@
#include <ObjBase.h>
#include <windows.h>
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "base/shared_memory.h"
+#include "base/singleton.h"
+
+// Forward
+class Version;
+
+// A singleton class that provides a facility to register the version of the
+// current module as the only version that should be loaded system-wide. If
+// this module is not the first instance loaded in the system, then the version
+// that loaded first will be delegated to. This makes a few assumptions:
+// 1) That different versions of the module this code is in reside in
+// neighbouring versioned directories, e.g.
+// C:\foo\bar\1.2.3.4\my_module.dll
+// C:\foo\bar\1.2.3.5\my_module.dll
+// 2) That the instance of this class will outlive the module that may be
+// delegated to. That is to say, that this class only guarantees that the
+// module is loaded as long as this instance is active.
+// 3) The module this is compiled into is built with version info.
class DllRedirector {
public:
- // Attempts to register a window class under a well known name and appends to
- // its extra data a handle to the current module. Will fail if the window
- // class is already registered. This is intended to be called from DllMain
- // under PROCESS_ATTACH.
- static bool DllRedirector::RegisterAsFirstCFModule();
+ virtual ~DllRedirector();
+
+ // Attempts to register this Chrome Frame version as the first loaded version
+ // on the system. If this succeeds, return true. If it fails, it returns
+ // false meaning that there is another version already loaded somewhere and
+ // the caller should delegate to that version instead.
+ bool DllRedirector::RegisterAsFirstCFModule();
// Unregisters the well known window class if we registered it earlier.
// This is intended to be called from DllMain under PROCESS_DETACH.
- static void DllRedirector::UnregisterAsFirstCFModule();
-
- // Helper function that extracts the HMODULE parameter from our well known
- // window class.
- static HMODULE GetFirstCFModule();
+ void DllRedirector::UnregisterAsFirstCFModule();
// Helper function to return the DllGetClassObject function pointer from
// the given module. On success, the return value is non-null and module
// will have had its reference count incremented.
- static LPFNGETCLASSOBJECT GetDllGetClassObjectPtr(HMODULE module);
+ LPFNGETCLASSOBJECT GetDllGetClassObjectPtr();
+
+ protected:
+ DllRedirector();
+ friend struct DefaultSingletonTraits<DllRedirector>;
+
+ // Constructor used for tests.
+ explicit DllRedirector(const char* shared_memory_name);
+
+ // Returns an HMODULE to the version of the module that should be loaded.
+ virtual HMODULE GetFirstModule();
- private:
- // Use this to keep track of whether or not we have registered the window
- // class in this module.
- static ATOM atom_;
+ // Returns the version of the current module or NULL if none can be found.
+ // The caller must free the Version.
+ virtual Version* GetCurrentModuleVersion();
+
+ // Attempt to load the specified version dll. Finds it by walking up one
+ // directory from our current module's location, then appending the newly
+ // found version number. The Version class in base will have ensured that we
+ // actually have a valid version and not e.g. ..\..\..\..\MyEvilFolder\.
+ virtual HMODULE LoadVersionedModule(Version* version);
+
+ // Shared memory segment that contains the version beacon.
+ scoped_ptr<base::SharedMemory> shared_memory_;
+
+ // The current version of the DLL to be loaded.
+ scoped_ptr<Version> dll_version_;
+
+ // The handle to the first version of this module that was loaded. This
+ // may refer to the current module, or another version of the same module
+ // that we go and load.
+ HMODULE first_module_handle_;
+
+ // Used for tests to override the name of the shared memory segment.
+ std::string shared_memory_name_;
friend class ModuleUtilsTest;
+
+ DISALLOW_COPY_AND_ASSIGN(DllRedirector);
};
#endif // CHROME_FRAME_MODULE_UTILS_H_