Commit e60b8dd7 authored by jbauman's avatar jbauman Committed by Commit bot

Remove Windows snapshot code.

This is never used now that aura is enabled.

Review URL: https://codereview.chromium.org/621883004

Cr-Commit-Position: refs/heads/master@{#297755}
parent 78f3331b
......@@ -1811,9 +1811,6 @@
],
}],
['OS=="win"', {
'dependencies': [
'../ui/snapshot/snapshot.gyp:snapshot_test_support',
],
'include_dirs': [
'<(DEPTH)/third_party/wtl/include',
],
......
......@@ -77,7 +77,6 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/size.h"
#include "ui/snapshot/test/snapshot_desktop.h"
#if defined(USE_AURA)
#include "ash/shell.h"
......@@ -98,33 +97,6 @@ namespace ui_test_utils {
namespace {
#if defined(OS_WIN)
const char kSnapshotBaseName[] = "ChromiumSnapshot";
const char kSnapshotExtension[] = ".png";
base::FilePath GetSnapshotFileName(const base::FilePath& snapshot_directory) {
base::Time::Exploded the_time;
base::Time::Now().LocalExplode(&the_time);
std::string filename(base::StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
base::FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
if (base::PathExists(snapshot_file)) {
int index = 0;
std::string suffix;
base::FilePath trial_file;
do {
suffix = base::StringPrintf(" (%d)", ++index);
trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
} while (base::PathExists(trial_file));
snapshot_file = trial_file;
}
return snapshot_file;
}
#endif // defined(OS_WIN)
Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
Browser* new_browser = GetBrowserNotInSet(excluded_browsers);
if (new_browser == NULL) {
......@@ -505,46 +477,6 @@ Browser* BrowserAddedObserver::WaitForSingleNewBrowser() {
return GetBrowserNotInSet(original_browsers_);
}
#if defined(OS_WIN)
bool SaveScreenSnapshotToDirectory(const base::FilePath& directory,
base::FilePath* screenshot_path) {
bool succeeded = false;
base::FilePath out_path(GetSnapshotFileName(directory));
MONITORINFO monitor_info = {};
monitor_info.cbSize = sizeof(monitor_info);
HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
if (GetMonitorInfo(main_monitor, &monitor_info)) {
RECT& rect = monitor_info.rcMonitor;
std::vector<unsigned char> png_data;
gfx::Rect bounds(
gfx::Size(rect.right - rect.left, rect.bottom - rect.top));
if (ui::GrabDesktopSnapshot(bounds, &png_data) &&
png_data.size() <= INT_MAX) {
int bytes = static_cast<int>(png_data.size());
int written = base::WriteFile(
out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
succeeded = (written == bytes);
}
}
if (succeeded && screenshot_path != NULL)
*screenshot_path = out_path;
return succeeded;
}
bool SaveScreenSnapshotToDesktop(base::FilePath* screenshot_path) {
base::FilePath desktop;
return PathService::Get(base::DIR_USER_DESKTOP, &desktop) &&
SaveScreenSnapshotToDirectory(desktop, screenshot_path);
}
#endif // defined(OS_WIN)
void OverrideGeolocation(double latitude, double longitude) {
content::Geoposition position;
position.latitude = latitude;
......
......@@ -270,18 +270,6 @@ class BrowserAddedObserver {
bool TakeEntirePageSnapshot(content::RenderViewHost* rvh,
SkBitmap* bitmap) WARN_UNUSED_RESULT;
#if defined(OS_WIN)
// Saves a snapshot of the entire screen to a file named
// ChromiumSnapshotYYYYMMDDHHMMSS.png to |directory|, returning true on success.
// The path to the file produced is returned in |screenshot_path| if non-NULL.
bool SaveScreenSnapshotToDirectory(const base::FilePath& directory,
base::FilePath* screenshot_path);
// Saves a snapshot of the entire screen as above to the current user's desktop.
// The Chrome path provider must be registered prior to calling this function.
bool SaveScreenSnapshotToDesktop(base::FilePath* screenshot_path);
#endif
// Configures the geolocation provider to always return the given position.
void OverrideGeolocation(double latitude, double longitude);
......
......@@ -14,8 +14,6 @@ component("snapshot") {
"snapshot_export.h",
"snapshot_ios.mm",
"snapshot_mac.mm",
"snapshot_win.cc",
"snapshot_win.h",
]
defines = [ "SNAPSHOT_IMPLEMENTATION" ]
......@@ -83,15 +81,3 @@ test("snapshot_unittests") {
sources -= [ "snapshot_aura_unittest.cc" ]
}
}
if (is_win) {
source_set("test_support") {
sources = [
"test/snapshot_desktop.h",
"test/snapshot_desktop_win.cc",
]
deps = [
":snapshot",
]
}
}
......@@ -29,8 +29,6 @@
'snapshot_export.h',
'snapshot_ios.mm',
'snapshot_mac.mm',
'snapshot_win.cc',
'snapshot_win.h',
],
'include_dirs': [
'..',
......@@ -93,24 +91,4 @@
],
},
],
'conditions': [
['OS=="win"', {
'targets': [
{
'target_name': 'snapshot_test_support',
'type': 'static_library',
'sources': [
'test/snapshot_desktop.h',
'test/snapshot_desktop_win.cc',
],
'dependencies': [
'snapshot',
],
'include_dirs': [
'../..',
],
},
],
}],
],
}
// Copyright (c) 2012 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 "ui/snapshot/snapshot_win.h"
#include "base/callback.h"
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/gdi_util.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/snapshot/snapshot.h"
namespace {
gfx::Rect GetWindowBounds(HWND window_handle) {
RECT content_rect = {0, 0, 0, 0};
if (window_handle) {
::GetWindowRect(window_handle, &content_rect);
} else {
MONITORINFO monitor_info = {};
monitor_info.cbSize = sizeof(monitor_info);
if (GetMonitorInfo(MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY),
&monitor_info)) {
content_rect = monitor_info.rcMonitor;
}
}
content_rect.right++; // Match what PrintWindow wants.
return gfx::Rect(content_rect.right - content_rect.left,
content_rect.bottom - content_rect.top);
}
} // namespace
namespace ui {
namespace internal {
bool GrabHwndSnapshot(HWND window_handle,
const gfx::Rect& snapshot_bounds,
std::vector<unsigned char>* png_representation) {
DCHECK(snapshot_bounds.right() <= GetWindowBounds(window_handle).right());
DCHECK(snapshot_bounds.bottom() <= GetWindowBounds(window_handle).bottom());
// Create a memory DC that's compatible with the window.
HDC window_hdc = GetWindowDC(window_handle);
base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc));
BITMAPINFOHEADER hdr;
gfx::CreateBitmapHeader(snapshot_bounds.width(),
snapshot_bounds.height(),
&hdr);
unsigned char *bit_ptr = NULL;
base::win::ScopedBitmap bitmap(
CreateDIBSection(mem_hdc.Get(),
reinterpret_cast<BITMAPINFO*>(&hdr),
DIB_RGB_COLORS,
reinterpret_cast<void **>(&bit_ptr),
NULL, 0));
base::win::ScopedSelectObject select_bitmap(mem_hdc.Get(), 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.Get(), 0, 0, snapshot_bounds.width(), snapshot_bounds.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). Always BitBlt when grabbing the whole screen.
if (snapshot_bounds.origin() == gfx::Point() && print_window && window_handle)
(*print_window)(window_handle, mem_hdc.Get(), 0);
else
BitBlt(mem_hdc.Get(), 0, 0, snapshot_bounds.width(),
snapshot_bounds.height(), window_hdc, snapshot_bounds.x(),
snapshot_bounds.y(), 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,
snapshot_bounds.size(),
snapshot_bounds.width() * 4, true,
std::vector<gfx::PNGCodec::Comment>(),
png_representation);
ReleaseDC(window_handle, window_hdc);
return true;
}
} // namespace internal
#if !defined(USE_AURA)
bool GrabViewSnapshot(gfx::NativeView view_handle,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
return GrabWindowSnapshot(view_handle, png_representation, snapshot_bounds);
}
bool GrabWindowSnapshot(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
DCHECK(window_handle);
return internal::GrabHwndSnapshot(window_handle, snapshot_bounds,
png_representation);
}
void GrapWindowSnapshotAsync(
gfx::NativeWindow window,
const gfx::Rect& snapshot_bounds,
const gfx::Size& target_size,
scoped_refptr<base::TaskRunner> background_task_runner,
GrabWindowSnapshotAsyncCallback callback) {
callback.Run(gfx::Image());
}
void GrabViewSnapshotAsync(
gfx::NativeView view,
const gfx::Rect& source_rect,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncPNGCallback& callback) {
callback.Run(scoped_refptr<base::RefCountedBytes>());
}
void GrabWindowSnapshotAsync(
gfx::NativeWindow window,
const gfx::Rect& source_rect,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncPNGCallback& callback) {
callback.Run(scoped_refptr<base::RefCountedBytes>());
}
#endif // !defined(USE_AURA)
} // namespace ui
// Copyright 2013 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 UI_SNAPSHOT_SNAPSHOT_WIN_H_
#define UI_SNAPSHOT_SNAPSHOT_WIN_H_
#include <windows.h>
#include <vector>
#include "ui/snapshot/snapshot_export.h"
namespace gfx {
class Rect;
}
namespace ui {
namespace internal {
// Grabs a snapshot of the desktop. No security checks are done. This is
// intended to be used for debugging purposes where no BrowserProcess instance
// is available (ie. tests). DO NOT use in a result of user action.
SNAPSHOT_EXPORT bool GrabHwndSnapshot(
HWND window_handle,
const gfx::Rect& snapshot_bounds,
std::vector<unsigned char>* png_representation);
} // namespace internal
} // namespace ui
#endif // UI_SNAPSHOT_SNAPSHOT_WIN_H_
// Copyright 2013 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 UI_SNAPSHOT_TEST_SNAPSHOT_DESKTOP_H_
#define UI_SNAPSHOT_TEST_SNAPSHOT_DESKTOP_H_
#include <vector>
namespace gfx {
class Rect;
}
namespace ui {
// Grabs a snapshot of the desktop. No security checks are done. This is
// intended to be used for debugging purposes where no BrowserProcess instance
// is available (ie. tests). DO NOT use in a result of user action.
bool GrabDesktopSnapshot(
const gfx::Rect& snapshot_bounds,
std::vector<unsigned char>* png_representation);
} // namespace ui
#endif // UI_SNAPSHOT_TEST_SNAPSHOT_DESKTOP_H_
// Copyright 2013 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 "ui/snapshot/test/snapshot_desktop.h"
#include "ui/snapshot/snapshot_win.h"
namespace ui {
bool GrabDesktopSnapshot(const gfx::Rect& snapshot_bounds,
std::vector<unsigned char>* png_representation) {
return internal::GrabHwndSnapshot(NULL, snapshot_bounds, png_representation);
}
} // namespace ui
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