diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-30 22:13:32 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-30 22:13:32 +0000 |
commit | b99603ceb9cbec4a3b1ca9ac535f6b1cbc951bb8 (patch) | |
tree | 2f9074d5ad8acf95156fc9c390646eca935d232e /app | |
parent | 004f2cf5d5eb19764260b1f513738be15ae77d47 (diff) | |
download | chromium_src-b99603ceb9cbec4a3b1ca9ac535f6b1cbc951bb8.zip chromium_src-b99603ceb9cbec4a3b1ca9ac535f6b1cbc951bb8.tar.gz chromium_src-b99603ceb9cbec4a3b1ca9ac535f6b1cbc951bb8.tar.bz2 |
Move some functions out of win_util and into hwnd_util, and into a new win/shell file.
This also moves two functions that were only called once from win_util and inwo window_win and download_util, respectively.
TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/6035011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70321 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/app_base.gypi | 2 | ||||
-rw-r--r-- | app/win/hwnd_util.cc | 124 | ||||
-rw-r--r-- | app/win/hwnd_util.h | 20 | ||||
-rw-r--r-- | app/win/shell.cc | 112 | ||||
-rw-r--r-- | app/win/shell.h | 41 | ||||
-rw-r--r-- | app/win_util.cc | 283 | ||||
-rw-r--r-- | app/win_util.h | 52 |
7 files changed, 299 insertions, 335 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi index f2be9f1..2581bdb 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -240,6 +240,8 @@ 'win/iat_patch_function.h', 'win/scoped_prop.cc', 'win/scoped_prop.h', + 'win/shell.cc', + 'win/shell.h', 'win/window_impl.cc', 'win/window_impl.h', 'x11_util.cc', diff --git a/app/win/hwnd_util.cc b/app/win/hwnd_util.cc index b0be404..30b7395 100644 --- a/app/win/hwnd_util.cc +++ b/app/win/hwnd_util.cc @@ -4,11 +4,49 @@ #include "app/win/hwnd_util.h" +#include <dwmapi.h> + #include "base/string_util.h" +#include "base/win/windows_version.h" +#include "gfx/rect.h" +#include "gfx/size.h" + +#pragma comment(lib, "dwmapi.lib") namespace app { namespace win { +namespace { + +// Adjust the window to fit, returning true if the window was resized or moved. +bool AdjustWindowToFit(HWND hwnd, const RECT& bounds) { + // Get the monitor. + HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); + if (!hmon) { + NOTREACHED() << "Unable to find default monitor"; + // No monitor available. + return false; + } + + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(hmon, &mi); + gfx::Rect window_rect(bounds); + gfx::Rect monitor_rect(mi.rcWork); + gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); + if (!new_window_rect.Equals(window_rect)) { + // Window doesn't fit on monitor, move and possibly resize. + SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), + new_window_rect.width(), new_window_rect.height(), + SWP_NOACTIVATE | SWP_NOZORDER); + return true; + } else { + return false; + } +} + +} // namespace + string16 GetClassName(HWND window) { // GetClassNameW will return a truncated result (properly null terminated) if // the given buffer is not large enough. So, it is not possible to determine @@ -55,5 +93,91 @@ void* GetWindowUserData(HWND hwnd) { #pragma warning(pop) +bool DoesWindowBelongToActiveWindow(HWND window) { + DCHECK(window); + HWND top_window = ::GetAncestor(window, GA_ROOT); + if (!top_window) + return false; + + HWND active_top_window = ::GetAncestor(::GetForegroundWindow(), GA_ROOT); + return (top_window == active_top_window); +} + +void CenterAndSizeWindow(HWND parent, + HWND window, + const gfx::Size& pref, + bool pref_is_client) { + DCHECK(window && pref.width() > 0 && pref.height() > 0); + + // Calculate the ideal bounds. + RECT window_bounds; + RECT center_bounds = {0}; + if (parent) { + // If there is a parent, center over the parents bounds. + ::GetWindowRect(parent, ¢er_bounds); + } else { + // No parent. Center over the monitor the window is on. + HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); + if (monitor) { + MONITORINFO mi = {0}; + mi.cbSize = sizeof(mi); + GetMonitorInfo(monitor, &mi); + center_bounds = mi.rcWork; + } else { + NOTREACHED() << "Unable to get default monitor"; + } + } + window_bounds.left = center_bounds.left + + (center_bounds.right - center_bounds.left - pref.width()) / 2; + window_bounds.right = window_bounds.left + pref.width(); + window_bounds.top = center_bounds.top + + (center_bounds.bottom - center_bounds.top - pref.height()) / 2; + window_bounds.bottom = window_bounds.top + pref.height(); + + // If we're centering a child window, we are positioning in client + // coordinates, and as such we need to offset the target rectangle by the + // position of the parent window. + if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) { + DCHECK(parent && ::GetParent(window) == parent); + POINT topleft = { window_bounds.left, window_bounds.top }; + ::MapWindowPoints(HWND_DESKTOP, parent, &topleft, 1); + window_bounds.left = topleft.x; + window_bounds.top = topleft.y; + window_bounds.right = window_bounds.left + pref.width(); + window_bounds.bottom = window_bounds.top + pref.height(); + } + + // Get the WINDOWINFO for window. We need the style to calculate the size + // for the window. + WINDOWINFO win_info = {0}; + win_info.cbSize = sizeof(WINDOWINFO); + GetWindowInfo(window, &win_info); + + // Calculate the window size needed for the content size. + + if (!pref_is_client || + AdjustWindowRectEx(&window_bounds, win_info.dwStyle, FALSE, + win_info.dwExStyle)) { + if (!AdjustWindowToFit(window, window_bounds)) { + // The window fits, reset the bounds. + SetWindowPos(window, 0, window_bounds.left, window_bounds.top, + window_bounds.right - window_bounds.left, + window_bounds.bottom - window_bounds.top, + SWP_NOACTIVATE | SWP_NOZORDER); + } // else case, AdjustWindowToFit set the bounds for us. + } else { + NOTREACHED() << "Unable to adjust window to fit"; + } +} + +bool ShouldUseVistaFrame() { + if (base::win::GetVersion() < base::win::VERSION_VISTA) + return false; + // If composition is not enabled, we behave like on XP. + BOOL f; + DwmIsCompositionEnabled(&f); + return !!f; +} + } // namespace win } // namespace app diff --git a/app/win/hwnd_util.h b/app/win/hwnd_util.h index f8ae37e..bace47e 100644 --- a/app/win/hwnd_util.h +++ b/app/win/hwnd_util.h @@ -10,6 +10,10 @@ #include "base/string16.h" +namespace gfx { +class Size; +} + namespace app { namespace win { @@ -25,6 +29,22 @@ WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc); void* SetWindowUserData(HWND hwnd, void* user_data); void* GetWindowUserData(HWND hwnd); +// Returns true if the specified window is the current active top window or one +// of its children. +bool DoesWindowBelongToActiveWindow(HWND window); + +// Sizes the window to have a client or window size (depending on the value of +// |pref_is_client|) of pref, then centers the window over parent, ensuring the +// window fits on screen. +void CenterAndSizeWindow(HWND parent, + HWND window, + const gfx::Size& pref, + bool pref_is_client); + +// Returns true if we are on Windows Vista or greater and composition is +// enabled. +bool ShouldUseVistaFrame(); + } // namespace win } // namespace app diff --git a/app/win/shell.cc b/app/win/shell.cc new file mode 100644 index 0000000..a3c7331 --- /dev/null +++ b/app/win/shell.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "app/win/shell.h" + +#include <shellapi.h> +#include <shlobj.h> + +#include "base/file_path.h" +#include "base/native_library.h" +#include "base/string_util.h" +#include "base/win/scoped_comptr.h" +#include "base/win/windows_version.h" +#include "base/win_util.h" + +namespace app { +namespace win { + +namespace { + +const wchar_t kShell32[] = L"shell32.dll"; +const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; + +// Define the type of SHGetPropertyStoreForWindow is SHGPSFW. +typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, + REFIID riid, + void** ppv); + +} // namespace + +// Open an item via a shell execute command. Error code checking and casting +// explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx +bool OpenItemViaShell(const FilePath& full_path) { + HINSTANCE h = ::ShellExecuteW( + NULL, NULL, full_path.value().c_str(), NULL, + full_path.DirName().value().c_str(), SW_SHOWNORMAL); + + LONG_PTR error = reinterpret_cast<LONG_PTR>(h); + if (error > 32) + return true; + + if ((error == SE_ERR_NOASSOC)) + return OpenItemWithExternalApp(full_path.value()); + + return false; +} + +bool OpenItemViaShellNoZoneCheck(const FilePath& full_path) { + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.fMask = SEE_MASK_NOZONECHECKS | SEE_MASK_FLAG_DDEWAIT; + sei.nShow = SW_SHOWNORMAL; + sei.lpVerb = NULL; + sei.lpFile = full_path.value().c_str(); + if (::ShellExecuteExW(&sei)) + return true; + LONG_PTR error = reinterpret_cast<LONG_PTR>(sei.hInstApp); + if ((error == SE_ERR_NOASSOC)) + return OpenItemWithExternalApp(full_path.value()); + return false; +} + +// Show the Windows "Open With" dialog box to ask the user to pick an app to +// open the file with. +bool OpenItemWithExternalApp(const string16& full_path) { + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.fMask = SEE_MASK_FLAG_DDEWAIT; + sei.nShow = SW_SHOWNORMAL; + sei.lpVerb = L"openas"; + sei.lpFile = full_path.c_str(); + return (TRUE == ::ShellExecuteExW(&sei)); +} + +void SetAppIdForWindow(const string16& app_id, HWND hwnd) { + // This functionality is only available on Win7+. + if (base::win::GetVersion() < base::win::VERSION_WIN7) + return; + + // Load Shell32.dll into memory. + // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. + std::wstring shell32_filename(kShell32); + FilePath shell32_filepath(shell32_filename); + base::NativeLibrary shell32_library = base::LoadNativeLibrary( + shell32_filepath); + + if (!shell32_library) + return; + + // Get the function pointer for SHGetPropertyStoreForWindow. + void* function = base::GetFunctionPointerFromNativeLibrary( + shell32_library, + kSHGetPropertyStoreForWindow); + + if (!function) { + base::UnloadNativeLibrary(shell32_library); + return; + } + + // Set the application's name. + base::win::ScopedComPtr<IPropertyStore> pps; + SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); + HRESULT result = SHGetPropertyStoreForWindow( + hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); + if (S_OK == result) + win_util::SetAppIdForPropertyStore(pps, app_id.c_str()); + + // Cleanup. + base::UnloadNativeLibrary(shell32_library); +} + +} // namespace win +} // namespace app diff --git a/app/win/shell.h b/app/win/shell.h new file mode 100644 index 0000000..44ee3ba7 --- /dev/null +++ b/app/win/shell.h @@ -0,0 +1,41 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APP_WIN_SHELL_H_ +#define APP_WIN_SHELL_H_ + +#include <windows.h> + +#include "base/string16.h" + +class FilePath; + +namespace app { +namespace win { + +// Open or run a file via the Windows shell. In the event that there is no +// default application registered for the file specified by 'full_path', +// ask the user, via the Windows "Open With" dialog. +// Returns 'true' on successful open, 'false' otherwise. +bool OpenItemViaShell(const FilePath& full_path); + +// The download manager now writes the alternate data stream with the +// zone on all downloads. This function is equivalent to OpenItemViaShell +// without showing the zone warning dialog. +bool OpenItemViaShellNoZoneCheck(const FilePath& full_path); + +// Ask the user, via the Windows "Open With" dialog, for an application to use +// to open the file specified by 'full_path'. +// Returns 'true' on successful open, 'false' otherwise. +bool OpenItemWithExternalApp(const string16& full_path); + +// Sets the application id given as the Application Model ID for the window +// specified. This method is used to insure that different web applications +// do not group together on the Win7 task bar. +void SetAppIdForWindow(const string16& app_id, HWND hwnd); + +} // namespace win +} // namespace app + +#endif // APP_WIN_SHELL_H_ diff --git a/app/win_util.cc b/app/win_util.cc index 0bbe391..31137e9 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -5,9 +5,7 @@ #include "app/win_util.h" #include <commdlg.h> -#include <dwmapi.h> #include <shellapi.h> -#include <shlobj.h> #include <algorithm> @@ -18,35 +16,18 @@ #include "base/file_util.h" #include "base/i18n/rtl.h" #include "base/logging.h" -#include "base/native_library.h" -#include "base/scoped_comptr_win.h" #include "base/scoped_handle.h" #include "base/scoped_handle_win.h" #include "base/string_util.h" #include "base/win_util.h" #include "base/win/scoped_gdi_object.h" -#include "base/win/windows_version.h" #include "gfx/codec/png_codec.h" #include "gfx/gdi_util.h" -// Ensure that we pick up this link library. -#pragma comment(lib, "dwmapi.lib") - namespace win_util { const int kAutoHideTaskbarThicknessPx = 2; -namespace { - -const wchar_t kShell32[] = L"shell32.dll"; -const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; - -// Define the type of SHGetPropertyStoreForWindow is SHGPSFW. -typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, - REFIID riid, - void** ppv); -} // namespace - std::wstring FormatSystemTime(const SYSTEMTIME& time, const std::wstring& format) { // If the format string is empty, just use the default format. @@ -100,155 +81,6 @@ bool IsDrag(const POINT& origin, const POINT& current) { (abs(current.y - origin.y) > (GetSystemMetrics(SM_CYDRAG) / 2)); } -bool ShouldUseVistaFrame() { - if (base::win::GetVersion() < base::win::VERSION_VISTA) - return false; - // If composition is not enabled, we behave like on XP. - BOOL f; - DwmIsCompositionEnabled(&f); - return !!f; -} - -// Open an item via a shell execute command. Error code checking and casting -// explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx -bool OpenItemViaShell(const FilePath& full_path) { - HINSTANCE h = ::ShellExecuteW( - NULL, NULL, full_path.value().c_str(), NULL, - full_path.DirName().value().c_str(), SW_SHOWNORMAL); - - LONG_PTR error = reinterpret_cast<LONG_PTR>(h); - if (error > 32) - return true; - - if ((error == SE_ERR_NOASSOC)) - return OpenItemWithExternalApp(full_path.value()); - - return false; -} - -bool OpenItemViaShellNoZoneCheck(const FilePath& full_path) { - SHELLEXECUTEINFO sei = { sizeof(sei) }; - sei.fMask = SEE_MASK_NOZONECHECKS | SEE_MASK_FLAG_DDEWAIT; - sei.nShow = SW_SHOWNORMAL; - sei.lpVerb = NULL; - sei.lpFile = full_path.value().c_str(); - if (::ShellExecuteExW(&sei)) - return true; - LONG_PTR error = reinterpret_cast<LONG_PTR>(sei.hInstApp); - if ((error == SE_ERR_NOASSOC)) - return OpenItemWithExternalApp(full_path.value()); - return false; -} - -// Show the Windows "Open With" dialog box to ask the user to pick an app to -// open the file with. -bool OpenItemWithExternalApp(const std::wstring& full_path) { - SHELLEXECUTEINFO sei = { sizeof(sei) }; - sei.fMask = SEE_MASK_FLAG_DDEWAIT; - sei.nShow = SW_SHOWNORMAL; - sei.lpVerb = L"openas"; - sei.lpFile = full_path.c_str(); - return (TRUE == ::ShellExecuteExW(&sei)); -} - -// Adjust the window to fit, returning true if the window was resized or moved. -static bool AdjustWindowToFit(HWND hwnd, const RECT& bounds) { - // Get the monitor. - HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); - if (!hmon) { - NOTREACHED() << "Unable to find default monitor"; - // No monitor available. - return false; - } - - MONITORINFO mi; - mi.cbSize = sizeof(mi); - GetMonitorInfo(hmon, &mi); - gfx::Rect window_rect(bounds); - gfx::Rect monitor_rect(mi.rcWork); - gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); - if (!new_window_rect.Equals(window_rect)) { - // Window doesn't fit on monitor, move and possibly resize. - SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), - new_window_rect.width(), new_window_rect.height(), - SWP_NOACTIVATE | SWP_NOZORDER); - return true; - } else { - return false; - } -} - -void AdjustWindowToFit(HWND hwnd) { - // Get the window bounds. - RECT r; - GetWindowRect(hwnd, &r); - AdjustWindowToFit(hwnd, r); -} - -void CenterAndSizeWindow(HWND parent, HWND window, const SIZE& pref, - bool pref_is_client) { - DCHECK(window && pref.cx > 0 && pref.cy > 0); - // Calculate the ideal bounds. - RECT window_bounds; - RECT center_bounds = {0}; - if (parent) { - // If there is a parent, center over the parents bounds. - ::GetWindowRect(parent, ¢er_bounds); - } else { - // No parent. Center over the monitor the window is on. - HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); - if (monitor) { - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - GetMonitorInfo(monitor, &mi); - center_bounds = mi.rcWork; - } else { - NOTREACHED() << "Unable to get default monitor"; - } - } - window_bounds.left = center_bounds.left + - (center_bounds.right - center_bounds.left - pref.cx) / 2; - window_bounds.right = window_bounds.left + pref.cx; - window_bounds.top = center_bounds.top + - (center_bounds.bottom - center_bounds.top - pref.cy) / 2; - window_bounds.bottom = window_bounds.top + pref.cy; - - // If we're centering a child window, we are positioning in client - // coordinates, and as such we need to offset the target rectangle by the - // position of the parent window. - if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) { - DCHECK(parent && ::GetParent(window) == parent); - POINT topleft = { window_bounds.left, window_bounds.top }; - ::MapWindowPoints(HWND_DESKTOP, parent, &topleft, 1); - window_bounds.left = topleft.x; - window_bounds.top = topleft.y; - window_bounds.right = window_bounds.left + pref.cx; - window_bounds.bottom = window_bounds.top + pref.cy; - } - - // Get the WINDOWINFO for window. We need the style to calculate the size - // for the window. - WINDOWINFO win_info = {0}; - win_info.cbSize = sizeof(WINDOWINFO); - GetWindowInfo(window, &win_info); - - // Calculate the window size needed for the content size. - - if (!pref_is_client || - AdjustWindowRectEx(&window_bounds, win_info.dwStyle, FALSE, - win_info.dwExStyle)) { - if (!AdjustWindowToFit(window, window_bounds)) { - // The window fits, reset the bounds. - SetWindowPos(window, 0, window_bounds.left, window_bounds.top, - window_bounds.right - window_bounds.left, - window_bounds.bottom - window_bounds.top, - SWP_NOACTIVATE | SWP_NOZORDER); - } // else case, AdjustWindowToFit set the bounds for us. - } else { - NOTREACHED() << "Unable to adjust window to fit"; - } -} - bool EdgeHasTopmostAutoHideTaskbar(UINT edge, HMONITOR monitor) { APPBARDATA taskbar_data = { 0 }; taskbar_data.cbSize = sizeof APPBARDATA; @@ -280,16 +112,6 @@ HANDLE GetSectionForProcess(HANDLE section, HANDLE process, bool read_only) { return valid_section; } -bool DoesWindowBelongToActiveWindow(HWND window) { - DCHECK(window); - HWND top_window = ::GetAncestor(window, GA_ROOT); - if (!top_window) - return false; - - HWND active_top_window = ::GetAncestor(::GetForegroundWindow(), GA_ROOT); - return (top_window == active_top_window); -} - void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, gfx::Rect* child_rect, int padding) { @@ -327,48 +149,6 @@ void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, child_rect->set_x(parent_rect.right() - child_rect->width() - padding); } -void SetChildBounds(HWND child_window, HWND parent_window, - HWND insert_after_window, const gfx::Rect& bounds, - int padding, unsigned long flags) { - DCHECK(IsWindow(child_window)); - - // First figure out the bounds of the parent. - RECT parent_rect = {0}; - if (parent_window) { - GetClientRect(parent_window, &parent_rect); - } else { - // If there is no parent, we consider the bounds of the monitor the window - // is on to be the parent bounds. - - // If the child_window isn't visible yet and we've been given a valid, - // visible insert after window, use that window to locate the correct - // monitor instead. - HWND window = child_window; - if (!IsWindowVisible(window) && IsWindow(insert_after_window) && - IsWindowVisible(insert_after_window)) - window = insert_after_window; - - POINT window_point = { bounds.x(), bounds.y() }; - HMONITOR monitor = MonitorFromPoint(window_point, - MONITOR_DEFAULTTONEAREST); - if (monitor) { - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - GetMonitorInfo(monitor, &mi); - parent_rect = mi.rcWork; - } else { - NOTREACHED() << "Unable to get default monitor"; - } - } - - gfx::Rect actual_bounds = bounds; - EnsureRectIsVisibleInRect(gfx::Rect(parent_rect), &actual_bounds, padding); - - SetWindowPos(child_window, insert_after_window, actual_bounds.x(), - actual_bounds.y(), actual_bounds.width(), - actual_bounds.height(), flags); -} - gfx::Rect GetMonitorBoundsForRect(const gfx::Rect& rect) { RECT p_rect = rect.ToRECT(); HMONITOR monitor = MonitorFromRect(&p_rect, MONITOR_DEFAULTTONEAREST); @@ -495,31 +275,6 @@ bool IsReservedName(const std::wstring& filename) { return false; } -bool IsShellIntegratedExtension(const std::wstring& extension) { - std::wstring extension_lower = StringToLowerASCII(extension); - - static const wchar_t* const integrated_extensions[] = { - // See <http://msdn.microsoft.com/en-us/library/ms811694.aspx>. - L"local", - // Right-clicking on shortcuts can be magical. - L"lnk", - }; - - for (int i = 0; i < arraysize(integrated_extensions); ++i) { - if (extension_lower == integrated_extensions[i]) - return true; - } - - // See <http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html>. - // That vulnerability report is not exactly on point, but files become magical - // if their end in a CLSID. Here we block extensions that look like CLSIDs. - if (extension_lower.size() > 0 && extension_lower.at(0) == L'{' && - extension_lower.at(extension_lower.length() - 1) == L'}') - return true; - - return false; -} - // In addition to passing the RTL flags to ::MessageBox if we are running in an // RTL locale, we need to make sure that LTR strings are rendered correctly by // adding the appropriate Unicode directionality marks. @@ -553,42 +308,4 @@ gfx::Font GetWindowTitleFont() { return gfx::Font(caption_font); } -void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { - // This functionality is only available on Win7+. - if (base::win::GetVersion() < base::win::VERSION_WIN7) - return; - - // Load Shell32.dll into memory. - // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. - std::wstring shell32_filename(kShell32); - FilePath shell32_filepath(shell32_filename); - base::NativeLibrary shell32_library = base::LoadNativeLibrary( - shell32_filepath); - - if (!shell32_library) - return; - - // Get the function pointer for SHGetPropertyStoreForWindow. - void* function = base::GetFunctionPointerFromNativeLibrary( - shell32_library, - kSHGetPropertyStoreForWindow); - - if (!function) { - base::UnloadNativeLibrary(shell32_library); - return; - } - - // Set the application's name. - ScopedComPtr<IPropertyStore> pps; - SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); - HRESULT result = SHGetPropertyStoreForWindow( - hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); - if (S_OK == result) { - SetAppIdForPropertyStore(pps, app_id.c_str()); - } - - // Cleanup. - base::UnloadNativeLibrary(shell32_library); -} - } // namespace win_util diff --git a/app/win_util.h b/app/win_util.h index ab5cbc3..4f98e63 100644 --- a/app/win_util.h +++ b/app/win_util.h @@ -111,35 +111,6 @@ bool IsDoubleClick(const POINT& origin, // would be considered a drag. bool IsDrag(const POINT& origin, const POINT& current); -// Returns true if we are on Windows Vista and composition is enabled -bool ShouldUseVistaFrame(); - -// Open or run a file via the Windows shell. In the event that there is no -// default application registered for the file specified by 'full_path', -// ask the user, via the Windows "Open With" dialog. -// Returns 'true' on successful open, 'false' otherwise. -bool OpenItemViaShell(const FilePath& full_path); - -// The download manager now writes the alternate data stream with the -// zone on all downloads. This function is equivalent to OpenItemViaShell -// without showing the zone warning dialog. -bool OpenItemViaShellNoZoneCheck(const FilePath& full_path); - -// Ask the user, via the Windows "Open With" dialog, for an application to use -// to open the file specified by 'full_path'. -// Returns 'true' on successful open, 'false' otherwise. -bool OpenItemWithExternalApp(const std::wstring& full_path); - -// If the window does not fit on the default monitor, it is moved and possibly -// resized appropriately. -void AdjustWindowToFit(HWND hwnd); - -// Sizes the window to have a client or window size (depending on the value of -// |pref_is_client|) of pref, then centers the window over parent, ensuring the -// window fits on screen. -void CenterAndSizeWindow(HWND parent, HWND window, const SIZE& pref, - bool pref_is_client); - // Returns true if edge |edge| (one of ABE_LEFT, TOP, RIGHT, or BOTTOM) of // monitor |monitor| has an auto-hiding taskbar that's always-on-top. bool EdgeHasTopmostAutoHideTaskbar(UINT edge, HMONITOR monitor); @@ -152,26 +123,12 @@ HANDLE GetSectionFromProcess(HANDLE section, HANDLE process, bool read_only); // process. Returns the new valid handle or NULL on failure. HANDLE GetSectionForProcess(HANDLE section, HANDLE process, bool read_only); -// Returns true if the specified window is the current active top window or one -// of its children. -bool DoesWindowBelongToActiveWindow(HWND window); - // Adjusts the value of |child_rect| if necessary to ensure that it is // completely visible within |parent_rect|. void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, gfx::Rect* child_rect, int padding); -// Ensures that the child window stays within the boundaries of the parent -// before setting its bounds. If |parent_window| is NULL, the bounds of the -// parent are assumed to be the bounds of the monitor that |child_window| is -// nearest to. If |child_window| isn't visible yet and |insert_after_window| -// is non-NULL and visible, the monitor |insert_after_window| is on is used -// as the parent bounds instead. -void SetChildBounds(HWND child_window, HWND parent_window, - HWND insert_after_window, const gfx::Rect& bounds, - int padding, unsigned long flags); - // Returns the bounds for the monitor that contains the largest area of // intersection with the specified rectangle. gfx::Rect GetMonitorBoundsForRect(const gfx::Rect& rect); @@ -195,10 +152,6 @@ bool IsWindowActive(HWND hwnd); // desktop.ini and thumbs.db which have special meaning to the windows shell. bool IsReservedName(const std::wstring& filename); -// Returns whether the specified extension is automatically integrated into the -// windows shell. -bool IsShellIntegratedExtension(const std::wstring& eextension); - // A wrapper around Windows' MessageBox function. Using a Chrome specific // MessageBox function allows us to control certain RTL locale flags so that // callers don't have to worry about adding these flags when running in a @@ -214,11 +167,6 @@ gfx::Font GetWindowTitleFont(); // The thickness of an auto-hide taskbar in pixels. extern const int kAutoHideTaskbarThicknessPx; -// Sets the application id given as the Application Model ID for the window -// specified. This method is used to insure that different web applications -// do not group together on the Win7 task bar. -void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd); - } // namespace win_util #endif // APP_WIN_UTIL_H_ |