diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-03 06:01:16 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-03 06:01:16 +0000 |
commit | 75b6805083c906bb17192a738b311bd21791e9f8 (patch) | |
tree | bce38efec20d50a7ef55a694f58036ae365d5e0a /chrome | |
parent | 2aa8b71eb688aa13a4f745027bcd4bb726bf6663 (diff) | |
download | chromium_src-75b6805083c906bb17192a738b311bd21791e9f8.zip chromium_src-75b6805083c906bb17192a738b311bd21791e9f8.tar.gz chromium_src-75b6805083c906bb17192a738b311bd21791e9f8.tar.bz2 |
Cross-platform CL to remove app/win/win_util.h&cc and related work.
See Issue 70141 for the full move details; see my inline review comments.
Changes significantly different from or beyond those prescribed by the bug:
*Consolidated a lot of GrabWindowSnapshot code.
*Moved EnsureRectIsVisibleInRect to views::internal namespace for test access.
*Moved app/win/win_util_unittest.cc to views/window/window_win_unittest.h
*Named ui/base/message_box_win.h instead of ui/base/message_box.h
*Made WindowWin::GetWindowTitleFont static; needed in static contexts.
*Denoted WindowWin::FrameTypeChanged as a Window override, moved code.
*Moved TestGrabWindowSnapshot into new file: chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm
BUG=70141
TEST=none
Review URL: http://codereview.chromium.org/6386009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73589 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
35 files changed, 435 insertions, 116 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index cca0d08..24a1be0 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -12,7 +12,6 @@ #include <textserv.h> #include "app/win/iat_patch_function.h" -#include "app/win/win_util.h" #include "base/auto_reset.h" #include "base/basictypes.h" #include "base/i18n/rtl.h" @@ -50,6 +49,7 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" +#include "views/controls/textfield/native_textfield_win.h" #include "views/drag_utils.h" #include "views/focus/focus_util_win.h" #include "views/widget/widget.h" @@ -261,6 +261,16 @@ struct AutocompleteEditState { const AutocompleteEditViewWin::State view_state; }; +// Returns true if the current point is far enough from the origin that it +// would be considered a drag. +bool IsDrag(const POINT& origin, const POINT& current) { + // The CXDRAG and CYDRAG system metrics describe the width and height of a + // rectangle around the origin position, inside of which motion is not + // considered a drag. + return (abs(current.x - origin.x) > (GetSystemMetrics(SM_CXDRAG) / 2)) || + (abs(current.y - origin.y) > (GetSystemMetrics(SM_CYDRAG) / 2)); +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -963,7 +973,7 @@ bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( // We don't process ALT + numpad digit as accelerators, they are used for // entering special characters. We do translate alt-home. if (e.IsAltDown() && (key != ui::VKEY_HOME) && - app::win::IsNumPadDigit(key, e.IsExtendedKey())) + views::NativeTextfieldWin::IsNumPadDigit(key, e.IsExtendedKey())) return true; // Skip accelerators for key combinations omnibox wants to crack. This list @@ -1459,8 +1469,8 @@ void AutocompleteEditViewWin::OnLButtonDown(UINT keys, const CPoint& point) { // double_click_time_ from the current message's time even if the timer has // wrapped in between. const bool is_triple_click = tracking_double_click_ && - app::win::IsDoubleClick(double_click_point_, point, - GetCurrentMessage()->time - double_click_time_); + views::NativeTextfieldWin::IsDoubleClick(double_click_point_, point, + GetCurrentMessage()->time - double_click_time_); tracking_double_click_ = false; if (!gaining_focus_.get() && !is_triple_click) @@ -1559,7 +1569,7 @@ void AutocompleteEditViewWin::OnMouseMove(UINT keys, const CPoint& point) { return; } - if (tracking_click_[kLeft] && !app::win::IsDrag(click_point_[kLeft], point)) + if (tracking_click_[kLeft] && !IsDrag(click_point_[kLeft], point)) return; tracking_click_[kLeft] = false; @@ -2380,7 +2390,7 @@ ITextDocument* AutocompleteEditViewWin::GetTextObjectModel() const { } void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { - if (initiated_drag_ || !app::win::IsDrag(click_point_[kLeft], point)) + if (initiated_drag_ || !IsDrag(click_point_[kLeft], point)) return; ui::OSExchangeData data; @@ -2537,7 +2547,7 @@ void AutocompleteEditViewWin::SelectAllIfNecessary(MouseButton button, const CPoint& point) { // When the user has clicked and released to give us focus, select all. if (tracking_click_[button] && - !app::win::IsDrag(click_point_[button], point)) { + !IsDrag(click_point_[button], point)) { // Select all in the reverse direction so as not to scroll the caret // into view and shift the contents jarringly. SelectAll(true); diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index 56b20a4..6616894 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -10,7 +10,6 @@ #include <algorithm> -#include "app/win/win_util.h" #include "base/command_line.h" #include "base/environment.h" #include "base/i18n/rtl.h" @@ -37,6 +36,7 @@ #include "net/socket/ssl_client_socket_nss_factory.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" +#include "ui/base/message_box_win.h" #include "views/focus/accelerator_handler.h" #include "views/window/window.h" @@ -57,8 +57,7 @@ void WarnAboutMinimumSystemRequirements() { const string16 text = l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP); const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); - app::win::MessageBox(NULL, text, caption, - MB_OK | MB_ICONWARNING | MB_TOPMOST); + ui::MessageBox(NULL, text, caption, MB_OK | MB_ICONWARNING | MB_TOPMOST); } } @@ -75,7 +74,7 @@ void ShowCloseBrowserFirstMessageBox() { const string16 text = l10n_util::GetStringUTF16(IDS_UNINSTALL_CLOSE_APP); const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); const UINT flags = MB_OK | MB_ICONWARNING | MB_TOPMOST; - app::win::MessageBox(NULL, text, caption, flags); + ui::MessageBox(NULL, text, caption, flags); } int DoUninstallTasks(bool chrome_still_running) { @@ -167,7 +166,7 @@ int HandleIconsCommands(const CommandLine &parsed_command_line) { l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet); const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST; - if (IDOK == app::win::MessageBox(NULL, msg, caption, flags)) + if (IDOK == ui::MessageBox(NULL, msg, caption, flags)) ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL); return ResultCodes::NORMAL_EXIT; // Exit as we are not launching browser. } @@ -194,7 +193,7 @@ bool CheckMachineLevelInstall() { l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; - app::win::MessageBox(NULL, text, caption, flags); + ui::MessageBox(NULL, text, caption, flags); FilePath uninstall_path(InstallUtil::GetChromeUninstallCmd(false, dist)); CommandLine uninstall_cmd(uninstall_path); if (!uninstall_cmd.GetProgram().value().empty()) { diff --git a/chrome/browser/dom_ui/bug_report_ui.cc b/chrome/browser/dom_ui/bug_report_ui.cc index ffbf29e..c69a2e2 100644 --- a/chrome/browser/dom_ui/bug_report_ui.cc +++ b/chrome/browser/dom_ui/bug_report_ui.cc @@ -25,6 +25,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/window_snapshot/window_snapshot.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" @@ -36,18 +37,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#if defined(USE_X11) -#include "ui/base/x/x11_util.h" -#elif defined(OS_MACOSX) -#include "base/mac/mac_util.h" -#elif defined(OS_WIN) -#include "app/win/win_util.h" -#endif - -#if defined(TOOLKIT_VIEWS) -#include "views/window/window.h" -#endif - #if defined(OS_CHROMEOS) #include "base/file_util.h" #include "base/path_service.h" @@ -148,7 +137,8 @@ void RefreshLastScreenshot(Browser* browser) { else last_screenshot_png = new std::vector<unsigned char>; - screen_size = browser->window()->GrabWindowSnapshot(last_screenshot_png); + gfx::NativeWindow native_window = browser->window()->GetNativeHandle(); + screen_size = browser::GrabWindowSnapshot(native_window, last_screenshot_png); } void ShowHtmlBugReportView(Browser* browser) { diff --git a/chrome/browser/download/base_file.cc b/chrome/browser/download/base_file.cc index ad01086..79f38e9 100644 --- a/chrome/browser/download/base_file.cc +++ b/chrome/browser/download/base_file.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -14,7 +14,6 @@ #include "chrome/browser/download/download_util.h" #if defined(OS_WIN) -#include "app/win/win_util.h" #include "chrome/common/win_safe_util.h" #elif defined(OS_MACOSX) #include "chrome/browser/ui/cocoa/file_metadata.h" diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index f7bf52f..cbc352b 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -69,7 +69,6 @@ #endif // defined(TOOLKIT_USES_GTK) #if defined(OS_WIN) -#include "app/win/win_util.h" #include "base/win/scoped_comptr.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/ui/views/frame/browser_view.h" @@ -119,6 +118,44 @@ bool IsShellIntegratedExtension(const string16& extension) { return false; } + +// Returns whether the specified file name is a reserved name on windows. +// This includes names like "com2.zip" (which correspond to devices) and +// desktop.ini and thumbs.db which have special meaning to the windows shell. +bool IsReservedName(const string16& filename) { + // This list is taken from the MSDN article "Naming a file" + // http://msdn2.microsoft.com/en-us/library/aa365247(VS.85).aspx + // I also added clock$ because GetSaveFileName seems to consider it as a + // reserved name too. + static const wchar_t* const known_devices[] = { + L"con", L"prn", L"aux", L"nul", L"com1", L"com2", L"com3", L"com4", L"com5", + L"com6", L"com7", L"com8", L"com9", L"lpt1", L"lpt2", L"lpt3", L"lpt4", + L"lpt5", L"lpt6", L"lpt7", L"lpt8", L"lpt9", L"clock$" + }; + string16 filename_lower = StringToLowerASCII(filename); + + for (int i = 0; i < arraysize(known_devices); ++i) { + // Exact match. + if (filename_lower == known_devices[i]) + return true; + // Starts with "DEVICE.". + if (filename_lower.find(string16(known_devices[i]) + L".") == 0) + return true; + } + + static const wchar_t* const magic_names[] = { + // These file names are used by the "Customize folder" feature of the shell. + L"desktop.ini", + L"thumbs.db", + }; + + for (int i = 0; i < arraysize(magic_names); ++i) { + if (filename_lower == magic_names[i]) + return true; + } + + return false; +} #endif // OS_WIN } // namespace @@ -251,7 +288,7 @@ void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { // Prepend "_" to the file name if it's a reserved name FilePath::StringType leaf_name = file_name->BaseName().value(); DCHECK(!leaf_name.empty()); - if (app::win::IsReservedName(leaf_name)) { + if (IsReservedName(leaf_name)) { leaf_name = FilePath::StringType(FILE_PATH_LITERAL("_")) + leaf_name; *file_name = file_name->DirName(); if (file_name->value() == FilePath::kCurrentDirectory) { diff --git a/chrome/browser/enumerate_modules_model_win.cc b/chrome/browser/enumerate_modules_model_win.cc index acfed88..bd2cc51 100644 --- a/chrome/browser/enumerate_modules_model_win.cc +++ b/chrome/browser/enumerate_modules_model_win.cc @@ -7,7 +7,6 @@ #include <Tlhelp32.h> #include <wintrust.h> -#include "app/win/win_util.h" #include "base/command_line.h" #include "base/environment.h" #include "base/file_path.h" @@ -75,8 +74,23 @@ struct FindModule { const ModuleEnumerator::Module& module; }; +// Returns the long path name given a short path name. A short path name is a +// path that follows the 8.3 convention and has ~x in it. If the path is already +// a long path name, the function returns the current path without modification. +bool ConvertToLongPath(const string16& short_path, string16* long_path) { + wchar_t long_path_buf[MAX_PATH]; + DWORD return_value = GetLongPathName(short_path.c_str(), long_path_buf, + MAX_PATH); + if (return_value != 0 && return_value < MAX_PATH) { + *long_path = long_path_buf; + return true; + } + + return false; } +} // namespace + // The browser process module blacklist. This lists modules that are known // to cause compatibility issues within the browser process. When adding to this // list, make sure that all paths are lower-case, in long pathname form, end @@ -220,7 +234,7 @@ static void GenerateHash(const std::string& input, std::string* output) { // static void ModuleEnumerator::NormalizeModule(Module* module) { string16 path = module->location; - if (!app::win::ConvertToLongPath(path, &module->location)) + if (!ConvertToLongPath(path, &module->location)) module->location = path; module->location = l10n_util::ToLower(module->location); diff --git a/chrome/browser/extensions/extensions_startup.cc b/chrome/browser/extensions/extensions_startup.cc index b44aade..cd395cf 100644 --- a/chrome/browser/extensions/extensions_startup.cc +++ b/chrome/browser/extensions/extensions_startup.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -12,7 +12,7 @@ #include "chrome/common/chrome_switches.h" #if defined(OS_WIN) -#include "app/win/win_util.h" +#include "ui/base/message_box_win.h" #endif ExtensionsStartupUtil::ExtensionsStartupUtil() : pack_job_succeeded_(false) {} @@ -36,7 +36,7 @@ void ExtensionsStartupUtil::ShowPackExtensionMessage( const std::wstring& caption, const std::wstring& message) { #if defined(OS_WIN) - app::win::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND); + ui::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND); #else // Just send caption & text to stdout on mac & linux. std::string out_text = WideToASCII(caption); diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index b41efef..4651040 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -30,8 +30,8 @@ // TODO(port): Port these files. #if defined(OS_WIN) -#include "app/win/win_util.h" #include "chrome/browser/ui/views/importer_lock_view.h" +#include "ui/base/message_box_win.h" #include "views/window/window.h" #elif defined(OS_MACOSX) #include "chrome/browser/ui/cocoa/importer/importer_lock_dialog.h" @@ -197,7 +197,7 @@ void ImporterHost::StartImportSettings( // credentials. if (profile_info.browser_type == importer::GOOGLE_TOOLBAR5) { if (!toolbar_importer_utils::IsGoogleGAIACookieInstalled()) { - app::win::MessageBox( + ui::MessageBox( NULL, UTF16ToWide(l10n_util::GetStringUTF16( IDS_IMPORTER_GOOGLE_LOGIN_TEXT)).c_str(), diff --git a/chrome/browser/platform_util_win.cc b/chrome/browser/platform_util_win.cc index f03f653..ecd5130 100644 --- a/chrome/browser/platform_util_win.cc +++ b/chrome/browser/platform_util_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -11,7 +11,6 @@ #include "app/win/scoped_co_mem.h" #include "app/win/shell.h" -#include "app/win/win_util.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" @@ -25,6 +24,7 @@ #include "chrome/installer/util/install_util.h" #include "gfx/native_widget_types.h" #include "googleurl/src/gurl.h" +#include "ui/base/message_box_win.h" namespace platform_util { @@ -162,13 +162,13 @@ bool IsVisible(gfx::NativeView view) { void SimpleErrorBox(gfx::NativeWindow parent, const string16& title, const string16& message) { - app::win::MessageBox(parent, message, title, MB_OK | MB_SETFOREGROUND); + ui::MessageBox(parent, message, title, MB_OK | MB_SETFOREGROUND); } bool SimpleYesNoBox(gfx::NativeWindow parent, const string16& title, const string16& message) { - return app::win::MessageBox(parent, message.c_str(), title.c_str(), + return ui::MessageBox(parent, message.c_str(), title.c_str(), MB_YESNO | MB_ICONWARNING | MB_SETFOREGROUND) == IDYES; } diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 5d488cf..89cf36f 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -100,7 +100,7 @@ #if defined(OS_WIN) #include <objbase.h> -#include "app/win/win_util.h" +#include "chrome/common/section_util_win.h" #endif using WebKit::WebCache; @@ -888,7 +888,7 @@ TransportDIB* BrowserRenderProcessHost::MapTransportDIB( TransportDIB::Id dib_id) { #if defined(OS_WIN) // On Windows we need to duplicate the handle from the remote process - HANDLE section = app::win::GetSectionFromProcess( + HANDLE section = chrome::GetSectionFromProcess( dib_id.handle, GetHandle(), false /* read write */); return TransportDIB::Map(section); #elif defined(OS_MACOSX) diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index d30cb4e..3a06bdd 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -31,7 +31,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #if defined(OS_WIN) -#include "app/win/win_util.h" +#include "chrome/common/section_util_win.h" #endif // Overview @@ -268,7 +268,7 @@ void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, // Duplicate the handle to the DIB here because the renderer process does not // have permission. The duplicated handle is owned by the renderer process, // which is responsible for closing it. - TransportDIB::Handle renderer_dib_handle = app::win::GetSectionForProcess( + TransportDIB::Handle renderer_dib_handle = chrome::GetSectionForProcess( thumbnail_dib->handle(), renderer->process()->GetHandle(), false); diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h index 5251502..f7832f3 100644 --- a/chrome/browser/ui/browser_window.h +++ b/chrome/browser/ui/browser_window.h @@ -6,8 +6,6 @@ #define CHROME_BROWSER_UI_BROWSER_WINDOW_H_ #pragma once -#include <vector> - #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/common/content_settings_types.h" #include "gfx/native_widget_types.h" @@ -344,10 +342,6 @@ class BrowserWindow { // Construct a FindBar implementation for the specified |browser|. static FindBar* CreateFindBar(Browser* browser_window); - // Grabs a snapshot of the current browser window and returns the bounds. - virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>* - png_representation) = 0; - protected: friend class BrowserList; friend class BrowserView; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h index 398ba0e..15eebf9 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.h +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h @@ -113,9 +113,6 @@ class BrowserWindowCocoa : public BrowserWindow, virtual void HideInstant(bool instant_is_active); virtual gfx::Rect GetInstantBounds(); - virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>* - png_representation); - // Overridden from NotificationObserver virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index 362e852..e5f813eb 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -7,7 +7,6 @@ #include "base/command_line.h" #include "base/logging.h" #include "base/message_loop.h" -#include "base/mac/mac_util.h" #include "base/sys_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/bookmarks/bookmark_utils.h" @@ -600,13 +599,6 @@ gfx::Rect BrowserWindowCocoa::GetInstantBounds() { return bounds; } -gfx::Rect BrowserWindowCocoa::GrabWindowSnapshot(std::vector<unsigned char>* - png_representation) { - int width = 0, height = 0; - base::mac::GrabWindowSnapshot(window(), png_representation, &width, &height); - return gfx::Rect(width, height); -} - void BrowserWindowCocoa::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/ui/cocoa/bug_report_window_controller.mm b/chrome/browser/ui/cocoa/bug_report_window_controller.mm index c55954c..b323379 100644 --- a/chrome/browser/ui/cocoa/bug_report_window_controller.mm +++ b/chrome/browser/ui/cocoa/bug_report_window_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -9,6 +9,7 @@ #include "chrome/browser/bug_report_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/ui/window_snapshot/window_snapshot.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" @@ -41,6 +42,9 @@ l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_OTHER_PROBLEM), nil]; + pngHeight_ = 0; + pngWidth_ = 0; + if (currentTab_ != NULL) { // Get data from current tab, if one exists. This dialog could be called // from the main menu with no tab contents, so currentTab_ is not @@ -62,18 +66,16 @@ [self setPageURL:base::SysUTF8ToNSString( currentTab_->controller().GetActiveEntry()->url().spec())]; [self setPageTitle:base::SysUTF16ToNSString(currentTab_->GetTitle())]; - base::mac::GrabWindowSnapshot( - currentTab_->view()->GetTopLevelNativeWindow(), &pngData_, - &pngWidth_, &pngHeight_); + gfx::Rect pngRect = browser::GrabWindowSnapshot( + currentTab_->view()->GetTopLevelNativeWindow(), &pngData_); + pngWidth_ = pngRect.width(); + pngHeight_ = pngRect.height(); } else { // If no current tab exists, create a menu without the "broken page" // options, with page URL and title empty, and screenshot disabled. [self setSendScreenshot:NO]; [self setDisableScreenshotCheckbox:YES]; } - - pngHeight_ = 0; - pngWidth_ = 0; } return self; } diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 1a49281..12458d3 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -1120,12 +1120,6 @@ gfx::Rect BrowserWindowGtk::GetInstantBounds() { return gtk_util::GetWidgetScreenBounds(contents_container_->widget()); } -gfx::Rect BrowserWindowGtk::GrabWindowSnapshot(std::vector<unsigned char>* - png_representation) { - ui::GrabWindowSnapshot(window_, png_representation); - return bounds_; -} - void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() { new DownloadInProgressDialogGtk(browser()); } diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h index c8da827..371c107 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.h +++ b/chrome/browser/ui/gtk/browser_window_gtk.h @@ -131,9 +131,6 @@ class BrowserWindowGtk : public BrowserWindow, virtual void HideInstant(bool instant_is_active); virtual gfx::Rect GetInstantBounds(); - virtual gfx::Rect GrabWindowSnapshot( - std::vector<unsigned char>* png_representation); - // Overridden from NotificationObserver: virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/ui/views/constrained_window_win.cc b/chrome/browser/ui/views/constrained_window_win.cc index 92dbcfa..2d4cd1b 100644 --- a/chrome/browser/ui/views/constrained_window_win.cc +++ b/chrome/browser/ui/views/constrained_window_win.cc @@ -6,7 +6,6 @@ #include <algorithm> -#include "app/win/win_util.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -33,6 +32,7 @@ #include "views/window/non_client_view.h" #include "views/window/window_resources.h" #include "views/window/window_shape.h" +#include "views/window/window_win.h" using base::TimeDelta; @@ -545,7 +545,7 @@ void ConstrainedWindowFrameView::InitWindowResources() { void ConstrainedWindowFrameView::InitClass() { static bool initialized = false; if (!initialized) { - title_font_ = new gfx::Font(app::win::GetWindowTitleFont()); + title_font_ = new gfx::Font(views::WindowWin::GetWindowTitleFont()); initialized = true; } } diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 614d6da..1d16015 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -9,7 +9,6 @@ #include <set> -#include "app/win/win_util.h" #include "chrome/browser/accessibility/browser_accessibility_state.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/browser_list.h" @@ -23,6 +22,7 @@ #include "views/screen.h" #include "views/widget/widget_win.h" #include "views/window/window_delegate.h" +#include "views/window/window_win.h" // static static const int kClientEdgeThickness = 3; @@ -41,7 +41,8 @@ BrowserFrame* BrowserFrame::Create(BrowserView* browser_view, // static const gfx::Font& BrowserFrame::GetTitleFont() { - static gfx::Font* title_font = new gfx::Font(app::win::GetWindowTitleFont()); + static gfx::Font* title_font = + new gfx::Font(views::WindowWin::GetWindowTitleFont()); return *title_font; } diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index e6a5f8a..e68c163 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -84,9 +84,9 @@ #include "views/window/window.h" #if defined(OS_WIN) -#include "app/win/win_util.h" #include "chrome/browser/aeropeek_manager.h" #include "chrome/browser/jumplist_win.h" +#include "ui/base/message_box_win.h" #include "ui/base/view_prop.h" #elif defined(OS_LINUX) #include "chrome/browser/ui/views/accelerator_table_gtk.h" @@ -1143,8 +1143,8 @@ void BrowserView::ShowProfileErrorDialog(int message_id) { #if defined(OS_WIN) string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); string16 message = l10n_util::GetStringUTF16(message_id); - app::win::MessageBox(GetNativeHandle(), message, title, - MB_OK | MB_ICONWARNING | MB_TOPMOST); + ui::MessageBox(GetNativeHandle(), message, title, + MB_OK | MB_ICONWARNING | MB_TOPMOST); #elif defined(OS_LINUX) std::string title = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); std::string message = l10n_util::GetStringUTF8(message_id); @@ -1398,19 +1398,6 @@ gfx::Rect BrowserView::GetInstantBounds() { return contents_->GetPreviewBounds(); } -gfx::Rect BrowserView::GrabWindowSnapshot(std::vector<unsigned char>* - png_representation) { - views::Window* window = GetWindow(); - -#if defined(USE_X11) - ui::GrabWindowSnapshot(window->GetNativeWindow(), png_representation); -#elif defined(OS_WIN) - app::win::GrabWindowSnapshot(window->GetNativeWindow(), png_representation); -#endif - - return window->GetBounds(); -} - #if defined(OS_CHROMEOS) void BrowserView::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { KeyboardOverlayDelegate::ShowDialog(owning_window); diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 7bdb7d2..f9dd976 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -328,8 +328,6 @@ class BrowserView : public BrowserBubbleHost, virtual void ShowInstant(TabContents* preview_contents); virtual void HideInstant(bool instant_is_active); virtual gfx::Rect GetInstantBounds(); - virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>* - png_representation); #if defined(OS_CHROMEOS) virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window); diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 4cd155c..bd35488 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -29,7 +29,7 @@ #include "views/window/window.h" #if defined(OS_WIN) -#include "app/win/win_util.h" +#include "views/widget/monitor_win.h" #include "views/widget/widget_win.h" #elif defined(OS_LINUX) #include "views/widget/widget_gtk.h" @@ -682,7 +682,7 @@ gfx::Rect TabStrip::GetDropBounds(int drop_index, // If the rect doesn't fit on the monitor, push the arrow to the bottom. #if defined(OS_WIN) - gfx::Rect monitor_bounds = app::win::GetMonitorBoundsForRect(drop_bounds); + gfx::Rect monitor_bounds = views::GetMonitorBoundsForRect(drop_bounds); *is_beneath = (monitor_bounds.IsEmpty() || !monitor_bounds.Contains(drop_bounds)); #else diff --git a/chrome/browser/ui/window_snapshot/window_snapshot.h b/chrome/browser/ui/window_snapshot/window_snapshot.h new file mode 100755 index 0000000..3372009 --- /dev/null +++ b/chrome/browser/ui/window_snapshot/window_snapshot.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 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 CHROME_BROWSER_UI_WINDOW_SNAPSHOT_WINDOW_SNAPSHOT_H_ +#define CHROME_BROWSER_UI_WINDOW_SNAPSHOT_WINDOW_SNAPSHOT_H_ +#pragma once + +#include <vector> + +#include "gfx/native_widget_types.h" + +namespace gfx { + class Rect; +} + +namespace browser { + +// Grabs a snapshot of the designated window and stores a PNG representation +// into a byte vector. Returns the image bounds. +gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window, + std::vector<unsigned char>* png_representation); + +} // namespace browser + +#endif // CHROME_BROWSER_UI_WINDOW_SNAPSHOT_WINDOW_SNAPSHOT_H_ diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm new file mode 100755 index 0000000..deb7220 --- /dev/null +++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm @@ -0,0 +1,44 @@ +// Copyright (c) 2011 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 "chrome/browser/ui/window_snapshot/window_snapshot.h" + +#import <Cocoa/Cocoa.h> + +#include "base/logging.h" +#include "base/mac/scoped_cftyperef.h" +#include "base/scoped_nsobject.h" +#include "gfx/rect.h" + +namespace browser { + +gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window, + std::vector<unsigned char>* png_representation) { + png_representation->clear(); + + // Make sure to grab the "window frame" view so we get current tab + + // tabstrip. + NSView* view = [[window contentView] superview]; + base::mac::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( + CGRectNull, kCGWindowListOptionIncludingWindow, + [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming)); + if (CGImageGetWidth(windowSnapshot) <= 0) + return gfx::Rect(); + + scoped_nsobject<NSBitmapImageRep> rep( + [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]); + NSData* data = [rep representationUsingType:NSPNGFileType properties:nil]; + const unsigned char* buf = static_cast<const unsigned char*>([data bytes]); + NSUInteger length = [data length]; + if (buf == NULL || length == 0) + return gfx::Rect(); + + png_representation->assign(buf, buf + length); + DCHECK(png_representation->size() > 0); + + return gfx::Rect(static_cast<int>([rep pixelsWide]), + static_cast<int>([rep pixelsHigh])); +} + +} // namespace browser diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm b/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm new file mode 100755 index 0000000..a7a377b --- /dev/null +++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm @@ -0,0 +1,49 @@ +// Copyright (c) 2011 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 "chrome/browser/ui/window_snapshot/window_snapshot.h" + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_nsobject.h" +#include "base/scoped_ptr.h" +#include "base/test/mock_chrome_application_mac.h" +#include "gfx/rect.h" +#include "testing/platform_test.h" + +namespace browser { +namespace { + +typedef PlatformTest GrabWindowSnapshotTest; + +TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) { + // Launch a test window so we can take a snapshot. + NSRect frame = NSMakeRect(0, 0, 400, 400); + scoped_nsobject<NSWindow> window( + [[NSWindow alloc] initWithContentRect:frame + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:NO]); + [window setBackgroundColor:[NSColor whiteColor]]; + [window makeKeyAndOrderFront:NSApp]; + + scoped_ptr<std::vector<unsigned char> > png_representation( + new std::vector<unsigned char>); + browser::GrabWindowSnapshot(window, png_representation.get()); + + // Copy png back into NSData object so we can make sure we grabbed a png. + scoped_nsobject<NSData> image_data( + [[NSData alloc] initWithBytes:&(*png_representation)[0] + length:png_representation->size()]); + NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; + EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); + EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); + NSColor* color = [rep colorAtX:200 y:200]; + CGFloat red = 0, green = 0, blue = 0, alpha = 0; + [color getRed:&red green:&green blue:&blue alpha:&alpha]; + EXPECT_GE(red + green + blue, 3.0); +} + +} // namespace +} // namespace browser diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_win.cc b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc new file mode 100755 index 0000000..66e0071 --- /dev/null +++ b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc @@ -0,0 +1,72 @@ +// Copyright (c) 2011 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 "chrome/browser/ui/window_snapshot/window_snapshot.h" + +#include "base/win/scoped_gdi_object.h" +#include "base/win/scoped_hdc.h" +#include "gfx/codec/png_codec.h" +#include "gfx/gdi_util.h" +#include "gfx/rect.h" + +namespace browser { + +gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle, + std::vector<unsigned char>* png_representation) { + // Create a memory DC that's compatible with the window. + HDC window_hdc = GetWindowDC(window_handle); + base::win::ScopedHDC mem_hdc(CreateCompatibleDC(window_hdc)); + + // Create a DIB that's the same size as the window. + RECT content_rect = {0, 0, 0, 0}; + ::GetWindowRect(window_handle, &content_rect); + content_rect.right++; // Match what PrintWindow wants. + int width = content_rect.right - content_rect.left; + int height = content_rect.bottom - content_rect.top; + BITMAPINFOHEADER hdr; + gfx::CreateBitmapHeader(width, height, &hdr); + unsigned char *bit_ptr = NULL; + base::win::ScopedBitmap bitmap( + CreateDIBSection(mem_hdc, + reinterpret_cast<BITMAPINFO*>(&hdr), + DIB_RGB_COLORS, + reinterpret_cast<void **>(&bit_ptr), + NULL, 0)); + + SelectObject(mem_hdc, bitmap); + // Clear the bitmap to white (so that rounded corners on windows + // show up on a white background, and strangely-shaped windows + // look reasonable). Not capturing an alpha mask saves a + // bit of space. + PatBlt(mem_hdc, 0, 0, width, height, WHITENESS); + // Grab a copy of the window + // First, see if PrintWindow is defined (it's not in Windows 2000). + typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); + PrintWindowPointer print_window = + reinterpret_cast<PrintWindowPointer>( + GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow")); + + // If PrintWindow is defined, use it. It will work on partially + // obscured windows, and works better for out of process sub-windows. + // Otherwise grab the bits we can get with BitBlt; it's better + // than nothing and will work fine in the average case (window is + // completely on screen). + if (print_window) + (*print_window)(window_handle, mem_hdc, 0); + else + BitBlt(mem_hdc, 0, 0, width, height, window_hdc, 0, 0, SRCCOPY); + + // We now have a copy of the window contents in a DIB, so + // encode it into a useful format for posting to the bug report + // server. + gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, + width, height, width * 4, true, + png_representation); + + ReleaseDC(window_handle, window_hdc); + + return gfx::Rect(width, height); +} + +} // namespace browser diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_x.cc b/chrome/browser/ui/window_snapshot/window_snapshot_x.cc new file mode 100755 index 0000000..48f8169 --- /dev/null +++ b/chrome/browser/ui/window_snapshot/window_snapshot_x.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2011 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 "chrome/browser/ui/window_snapshot/window_snapshot.h" + +#include <gdk/gdkx.h> +#include <gtk/gtk.h> + +#include "base/logging.h" +#include "gfx/rect.h" +#include "ui/base/x/x11_util.h" + +namespace browser { + +static cairo_status_t SnapshotCallback( + void *closure, const unsigned char *data, unsigned int length) { + std::vector<unsigned char>* png_representation = + static_cast<std::vector<unsigned char>*>(closure); + + size_t old_size = png_representation->size(); + png_representation->resize(old_size + length); + memcpy(&(*png_representation)[old_size], data, length); + return CAIRO_STATUS_SUCCESS; +} + +gfx::Rect GrabWindowSnapshot(gfx::NativeWindow gtk_window, + std::vector<unsigned char>* png_representation) { + GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window; + Display* display = GDK_WINDOW_XDISPLAY(gdk_window); + XID win = GDK_WINDOW_XID(gdk_window); + XWindowAttributes attr; + if (XGetWindowAttributes(display, win, &attr) == 0) { + LOG(ERROR) << "Couldn't get window attributes"; + return gfx::Rect(); + } + XImage* image = XGetImage( + display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); + if (!image) { + LOG(ERROR) << "Couldn't get image"; + return gfx::Rect(); + } + if (image->depth != 24) { + LOG(ERROR)<< "Unsupported image depth " << image->depth; + return gfx::Rect(); + } + cairo_surface_t* surface = + cairo_image_surface_create_for_data( + reinterpret_cast<unsigned char*>(image->data), + CAIRO_FORMAT_RGB24, + image->width, + image->height, + image->bytes_per_line); + + if (!surface) { + LOG(ERROR) << "Unable to create Cairo surface from XImage data"; + return gfx::Rect(); + } + cairo_surface_write_to_png_stream( + surface, SnapshotCallback, png_representation); + cairo_surface_destroy(surface); + + return gfx::Rect(image->width, image->height); +} + +} // namespace browser diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 6ac0a59..7eded71 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3530,6 +3530,10 @@ 'browser/ui/window_sizer_linux.cc', 'browser/ui/window_sizer_mac.mm', 'browser/ui/window_sizer_win.cc', + 'browser/ui/window_snapshot/window_snapshot.h', + 'browser/ui/window_snapshot/window_snapshot_mac.mm', + 'browser/ui/window_snapshot/window_snapshot_win.cc', + 'browser/ui/window_snapshot/window_snapshot_x.cc', 'browser/upgrade_detector.cc', 'browser/upgrade_detector.h', 'browser/user_style_sheet_watcher.cc', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 354b3fb..390c610 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -159,6 +159,8 @@ 'common/sandbox_mac.mm', 'common/sandbox_policy.cc', 'common/sandbox_policy.h', + 'common/section_util_win.cc', + 'common/section_util_win.h', 'common/serialized_script_value.cc', 'common/serialized_script_value.h', 'common/set_process_title.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index de1baf6..7e00c14 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1638,6 +1638,7 @@ 'browser/ui/views/shell_dialogs_win_unittest.cc', 'browser/ui/views/status_icons/status_tray_win_unittest.cc', 'browser/ui/window_sizer_unittest.cc', + 'browser/ui/window_snapshot/window_snapshot_mac_unittest.mm', 'browser/user_style_sheet_watcher_unittest.cc', 'browser/visitedlink/visitedlink_unittest.cc', 'browser/web_applications/web_app_unittest.cc', diff --git a/chrome/common/sandbox_policy.cc b/chrome/common/sandbox_policy.cc index 501b19f..632d873 100644 --- a/chrome/common/sandbox_policy.cc +++ b/chrome/common/sandbox_policy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -6,7 +6,6 @@ #include <string> -#include "app/win/win_util.h" #include "base/command_line.h" #include "base/debug/debugger.h" #include "base/debug/trace_event.h" diff --git a/chrome/common/section_util_win.cc b/chrome/common/section_util_win.cc new file mode 100755 index 0000000..449151c --- /dev/null +++ b/chrome/common/section_util_win.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2011 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 "chrome/common/section_util_win.h" + +namespace chrome { + +HANDLE GetSectionFromProcess(HANDLE section, HANDLE process, bool read_only) { + HANDLE valid_section = NULL; + DWORD access = STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ; + if (!read_only) + access |= FILE_MAP_WRITE; + DuplicateHandle(process, section, GetCurrentProcess(), &valid_section, access, + FALSE, 0); + return valid_section; +} + +HANDLE GetSectionForProcess(HANDLE section, HANDLE process, bool read_only) { + HANDLE valid_section = NULL; + DWORD access = STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ; + if (!read_only) + access |= FILE_MAP_WRITE; + DuplicateHandle(GetCurrentProcess(), section, process, &valid_section, access, + FALSE, 0); + return valid_section; +} + +} // namespace chrome diff --git a/chrome/common/section_util_win.h b/chrome/common/section_util_win.h new file mode 100755 index 0000000..a3c849e --- /dev/null +++ b/chrome/common/section_util_win.h @@ -0,0 +1,23 @@ +// Copyright (c) 2011 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 CHROME_COMMON_SECTION_UTIL_WIN_H_ +#define CHROME_COMMON_SECTION_UTIL_WIN_H_ +#pragma once + +#include <windows.h> + +namespace chrome { + +// Duplicates a section handle from another process to the current process. +// Returns the new valid handle if the function succeed. NULL otherwise. +HANDLE GetSectionFromProcess(HANDLE section, HANDLE process, bool read_only); + +// Duplicates a section handle from the current process for use in another +// process. Returns the new valid handle or NULL on failure. +HANDLE GetSectionForProcess(HANDLE section, HANDLE process, bool read_only); + +} // namespace chrome + +#endif // CHROME_COMMON_SECTION_UTIL_WIN_H_ diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index de15ce7..8f671b9 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -30,7 +30,7 @@ #endif #if defined(OS_WIN) -#include "app/win/win_util.h" +#include "chrome/common/section_util_win.h" #include "gfx/gdi_util.h" #endif @@ -535,7 +535,7 @@ void WebPluginProxy::SetWindowlessBuffer( window_rect.width(), window_rect.height(), true, - app::win::GetSectionFromProcess(windowless_buffer, + chrome::GetSectionFromProcess(windowless_buffer, channel_->renderer_handle(), false))) { windowless_canvas_.reset(); background_canvas_.reset(); @@ -548,7 +548,7 @@ void WebPluginProxy::SetWindowlessBuffer( window_rect.width(), window_rect.height(), true, - app::win::GetSectionFromProcess(background_buffer, + chrome::GetSectionFromProcess(background_buffer, channel_->renderer_handle(), false))) { windowless_canvas_.reset(); background_canvas_.reset(); diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index cb332db..1e9e99f 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -6,8 +6,6 @@ #define CHROME_TEST_TEST_BROWSER_WINDOW_H_ #pragma once -#include <vector> - #include "chrome/browser/browser_window.h" #include "chrome/test/test_location_bar.h" @@ -111,11 +109,6 @@ class TestBrowserWindow : public BrowserWindow { virtual void HideInstant(bool instant_is_active) {} virtual gfx::Rect GetInstantBounds() { return gfx::Rect(); } - virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>* - png_representation) { - return gfx::Rect(); - } - #if defined(OS_CHROMEOS) virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) {} #endif |