Commit 2249aeb3 authored by ananta@chromium.org's avatar ananta@chromium.org

Setting the SVN eol style to LF on chrome frame sources

Review URL: http://codereview.chromium.org/344009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30332 0039d316-1c4b-4281-b951-d872f2087c98
parent aab2f54d
// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <windows.h> #include <windows.h>
#include "chrome_frame/chrome_launcher.h" #include "chrome_frame/chrome_launcher.h"
// We want to keep this EXE tiny, so we avoid all dependencies and link to no // We want to keep this EXE tiny, so we avoid all dependencies and link to no
// libraries, and we do not use the C runtime. // libraries, and we do not use the C runtime.
// //
// To catch errors in debug builds, we define an extremely simple assert macro. // To catch errors in debug builds, we define an extremely simple assert macro.
#ifndef NDEBUG #ifndef NDEBUG
#define CLM_ASSERT(x) do { if (!(x)) { ::DebugBreak(); } } while (false) #define CLM_ASSERT(x) do { if (!(x)) { ::DebugBreak(); } } while (false)
#else #else
#define CLM_ASSERT(x) #define CLM_ASSERT(x)
#endif // NDEBUG #endif // NDEBUG
// In release builds, we skip the standard library completely to minimize // In release builds, we skip the standard library completely to minimize
// size. This is more work in debug builds, and unnecessary, hence the // size. This is more work in debug builds, and unnecessary, hence the
// different signatures. // different signatures.
#ifndef NDEBUG #ifndef NDEBUG
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) { int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
#else #else
extern "C" void __cdecl WinMainCRTStartup() { extern "C" void __cdecl WinMainCRTStartup() {
#endif // NDEBUG #endif // NDEBUG
// This relies on the chrome_launcher.exe residing in the same directory // This relies on the chrome_launcher.exe residing in the same directory
// as our DLL. We build a full path to avoid loading it from any other // as our DLL. We build a full path to avoid loading it from any other
// directory in the DLL search path. // directory in the DLL search path.
// //
// The code is a bit verbose because we can't use the standard library. // The code is a bit verbose because we can't use the standard library.
const wchar_t kBaseName[] = L"npchrome_tab.dll"; const wchar_t kBaseName[] = L"npchrome_tab.dll";
wchar_t file_path[MAX_PATH + (sizeof(kBaseName) / sizeof(kBaseName[0])) + 1]; wchar_t file_path[MAX_PATH + (sizeof(kBaseName) / sizeof(kBaseName[0])) + 1];
file_path[0] = L'\0'; file_path[0] = L'\0';
::GetModuleFileName(::GetModuleHandle(NULL), file_path, MAX_PATH); ::GetModuleFileName(::GetModuleHandle(NULL), file_path, MAX_PATH);
// Find index of last slash, and null-terminate the string after it. // Find index of last slash, and null-terminate the string after it.
// //
// Proof for security purposes, since we can't use the safe string // Proof for security purposes, since we can't use the safe string
// manipulation functions from the runtime: // manipulation functions from the runtime:
// - File_path is always null-terminated, by us initially and by // - File_path is always null-terminated, by us initially and by
// ::GetModuleFileName if it puts anything into the buffer. // ::GetModuleFileName if it puts anything into the buffer.
// - If there is no slash in the path then it's a relative path, not an // - If there is no slash in the path then it's a relative path, not an
// absolute one, and the code ends up creating a relative path to // absolute one, and the code ends up creating a relative path to
// npchrome_tab.dll. // npchrome_tab.dll.
// - It's safe to use lstrcatW since we know the maximum length of both // - It's safe to use lstrcatW since we know the maximum length of both
// parts we are concatenating, and we know the buffer will fit them in // parts we are concatenating, and we know the buffer will fit them in
// the worst case. // the worst case.
int slash_index = lstrlenW(file_path); int slash_index = lstrlenW(file_path);
// Invariant: 0 <= slash_index < MAX_PATH // Invariant: 0 <= slash_index < MAX_PATH
CLM_ASSERT(slash_index > 0); CLM_ASSERT(slash_index > 0);
while (slash_index > 0 && file_path[slash_index] != L'\\') while (slash_index > 0 && file_path[slash_index] != L'\\')
--slash_index; --slash_index;
// Invariant: 0 <= slash_index < MAX_PATH and it is either the index of // Invariant: 0 <= slash_index < MAX_PATH and it is either the index of
// the last \ in the path, or 0. // the last \ in the path, or 0.
if (slash_index != 0) if (slash_index != 0)
++slash_index; // don't remove the last '\' ++slash_index; // don't remove the last '\'
file_path[slash_index] = L'\0'; file_path[slash_index] = L'\0';
lstrcatW(file_path, kBaseName); lstrcatW(file_path, kBaseName);
UINT exit_code = ERROR_FILE_NOT_FOUND; UINT exit_code = ERROR_FILE_NOT_FOUND;
HMODULE chrome_tab = ::LoadLibrary(file_path); HMODULE chrome_tab = ::LoadLibrary(file_path);
CLM_ASSERT(chrome_tab); CLM_ASSERT(chrome_tab);
if (chrome_tab) { if (chrome_tab) {
chrome_launcher::CfLaunchChromeProc proc = chrome_launcher::CfLaunchChromeProc proc =
reinterpret_cast<chrome_launcher::CfLaunchChromeProc>( reinterpret_cast<chrome_launcher::CfLaunchChromeProc>(
::GetProcAddress(chrome_tab, "CfLaunchChrome")); ::GetProcAddress(chrome_tab, "CfLaunchChrome"));
CLM_ASSERT(proc); CLM_ASSERT(proc);
if (proc) { if (proc) {
exit_code = proc(); exit_code = proc();
} else { } else {
exit_code = ERROR_INVALID_FUNCTION; exit_code = ERROR_INVALID_FUNCTION;
} }
::FreeLibrary(chrome_tab); ::FreeLibrary(chrome_tab);
} }
::ExitProcess(exit_code); ::ExitProcess(exit_code);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment