Commit a6bae051 authored by qfel@google.com's avatar qfel@google.com

Support calling GrabWindowSnapshot when no BrowserProcess instance is avaliable (eg. tests)


BUG=139694


Review URL: https://chromiumcodereview.appspot.com/10821104

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149604 0039d316-1c4b-4281-b951-d872f2087c98
parent f84128b4
......@@ -7,22 +7,17 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
#include "ui/window_snapshot/window_snapshot.h"
namespace chrome {
// Like GrabWindowSnapshot, but does not check if policy settings allow taking
// screenshots. Implemented in a platform-specific way.
bool GrabWindowSnapshotImpl(gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds);
bool GrabWindowSnapshot(
gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
if (g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots))
return false;
return GrabWindowSnapshotImpl(window, png_representation, snapshot_bounds);
return ui::GrabWindowSnapshot(window, png_representation, snapshot_bounds);
}
void RegisterScreenshotPrefs(PrefService* service) {
......
......@@ -20,7 +20,11 @@ namespace chrome {
// Grabs a snapshot of the rectangle area |snapshot_bounds| with respect to the
// top left corner of the designated window and stores a PNG representation
// into a byte vector. On Windows, |window| may be NULL to grab a snapshot of
// the primary monitor. Returns true if the operation is successful.
// the primary monitor. This checks policy settings if taking screenshots is
// allowed, and is intended to by used by browser code. If you need to take a
// screenshot for debugging purposes, use ui::GrabWindowSnapshot
// (ui/window_snapshot/window_snapshot.h).
// Returns true if the operation is successful (ie. permitted).
bool GrabWindowSnapshot(
gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
......
......@@ -4249,10 +4249,6 @@
'browser/ui/window_sizer/window_sizer_win.cc',
'browser/ui/window_snapshot/window_snapshot.cc',
'browser/ui/window_snapshot/window_snapshot.h',
'browser/ui/window_snapshot/window_snapshot_aura.cc',
'browser/ui/window_snapshot/window_snapshot_gtk.cc',
'browser/ui/window_snapshot/window_snapshot_mac.mm',
'browser/ui/window_snapshot/window_snapshot_win.cc',
'browser/ui/zoom/zoom_controller.cc',
'browser/ui/zoom/zoom_controller.h',
'browser/ui/zoom/zoom_observer.h',
......
......@@ -1864,7 +1864,6 @@
'browser/ui/webui/web_ui_unittest.cc',
'browser/ui/window_sizer/window_sizer_ash_unittest.cc',
'browser/ui/window_sizer/window_sizer_unittest.cc',
'browser/ui/window_snapshot/window_snapshot_mac_unittest.mm',
'browser/chrome_to_mobile_service_unittest.cc',
'browser/user_style_sheet_watcher_unittest.cc',
'browser/value_store/leveldb_value_store_unittest.cc',
......@@ -2057,6 +2056,7 @@
'../ui/views/test/test_views_delegate.h',
'../ui/views/test/views_test_base.cc',
'../ui/views/test/views_test_base.h',
'../ui/window_snapshot/window_snapshot_mac_unittest.mm',
'../webkit/glue/web_intent_service_data_unittest.cc',
'../webkit/quota/mock_storage_client.cc',
'../webkit/quota/mock_storage_client.h',
......
......@@ -14,11 +14,12 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
#include "chrome/common/chrome_paths.h"
#include "ui/base/win/foreground_helper.h"
#include "ui/ui_controls/ui_controls.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/window_snapshot/window_snapshot.h"
namespace ui_test_utils {
......@@ -124,9 +125,9 @@ bool SaveScreenSnapshotToDirectory(const FilePath& directory,
RECT& rect = monitor_info.rcMonitor;
std::vector<unsigned char> png_data;
if (chrome::GrabWindowSnapshot(NULL, &png_data,
gfx::Rect(rect.right - rect.left,
rect.bottom - rect.top)) &&
if (ui::GrabWindowSnapshot(NULL, &png_data,
gfx::Rect(rect.right - rect.left,
rect.bottom - rect.top)) &&
png_data.size() <= INT_MAX) {
int bytes = static_cast<int>(png_data.size());
int written = file_util::WriteFile(
......
......@@ -697,8 +697,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_XHRTest) {
const wchar_t kInstallFlowTestUrl[] =
L"install_flow_test.html";
// crbug.com/139694
TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_InstallFlowTest) {
TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_InstallFlowTest) {
if (base::win::GetVersion() < base::win::VERSION_VISTA) {
ScopedChromeFrameRegistrar::UnregisterAtPath(
GetChromeFrameBuildPath().value(),
......@@ -902,8 +901,7 @@ class UaTemplateFileResponse : public test_server::FileResponse {
//
// This test currently fails because GCF does not add the chromeframe header
// to requests that mshtml initiates via IInternetSession::CreateBinding.
// crbug.com/139694
TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_RefreshMshtmlTest) {
TEST_F(ChromeFrameTestWithWebServer, FAILS_FullTabModeIE_RefreshMshtmlTest) {
const wchar_t* kPages[] = {
L"mshtml_refresh_test.html",
L"mshtml_refresh_test_popup.html",
......
......@@ -467,6 +467,10 @@
'ui_controls/ui_controls_gtk.cc',
'ui_controls/ui_controls_mac.mm',
'ui_controls/ui_controls_win.cc',
'window_snapshot/window_snapshot_aura.cc',
'window_snapshot/window_snapshot_gtk.cc',
'window_snapshot/window_snapshot_mac.mm',
'window_snapshot/window_snapshot_win.cc',
],
'conditions': [
['OS!="ios"', {
......@@ -508,6 +512,7 @@
['exclude', 'base/x/work_area_watcher_x.cc'],
['exclude', 'base/x/work_area_watcher_x.h'],
['exclude', 'ui_controls_win.cc'],
['exclude', 'window_snapshot/window_snapshot_win.cc'],
],
}, { # use_aura!=1
'sources!': [
......
// 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.
#ifndef UI_WINDOW_SNAPSHOT_WINDOW_SNAPSHOT_H_
#define UI_WINDOW_SNAPSHOT_WINDOW_SNAPSHOT_H_
#include <vector>
#include "ui/base/ui_export.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class Rect;
}
namespace ui {
// Grabs a snapshot of the rectangle area |snapshot_bounds| with respect to the
// top left corner of the designated window and stores a PNG representation
// into a byte vector. On Windows, |window| may be NULL to grab a snapshot of
// the primary monitor. DO NOT use in browser code. Screenshots initiated by
// user action should be taken with chrome::GrabWindowSnapshot
// (chrome/browser/ui/window_snapshot/window_snapshot.cc), so user context is
// taken into account (eg. policy settings are checked).
// Returns true if the operation is successful.
UI_EXPORT bool GrabWindowSnapshot(
gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds);
} // namespace chrome
#endif // UI_WINDOW_SNAPSHOT_WINDOW_SNAPSHOT_H_
......@@ -2,7 +2,7 @@
// 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 "ui/window_snapshot/window_snapshot.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
......@@ -13,11 +13,11 @@
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/rect.h"
namespace chrome {
namespace ui {
bool GrabWindowSnapshotImpl(gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
bool GrabWindowSnapshot(gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
ui::Compositor* compositor = window->layer()->GetCompositor();
gfx::Rect read_pixels_bounds = snapshot_bounds;
......@@ -48,4 +48,4 @@ bool GrabWindowSnapshotImpl(gfx::NativeWindow window,
return true;
}
} // namespace chrome
} // namespace ui
......@@ -2,7 +2,7 @@
// 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 "ui/window_snapshot/window_snapshot.h"
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
......@@ -27,11 +27,11 @@ cairo_status_t SnapshotCallback(void* closure,
} // namespace
namespace chrome {
namespace ui {
bool GrabWindowSnapshotImpl(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
bool GrabWindowSnapshot(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_handle));
Display* display = GDK_WINDOW_XDISPLAY(gdk_window);
XID win = GDK_WINDOW_XID(gdk_window);
......@@ -75,4 +75,4 @@ bool GrabWindowSnapshotImpl(gfx::NativeWindow window_handle,
return true;
}
} // namespace chrome
} // namespace ui
......@@ -2,7 +2,7 @@
// 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 "ui/window_snapshot/window_snapshot.h"
#import <Cocoa/Cocoa.h>
......@@ -11,11 +11,11 @@
#include "base/memory/scoped_nsobject.h"
#include "ui/gfx/rect.h"
namespace chrome {
namespace ui {
bool GrabWindowSnapshotImpl(gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
bool GrabWindowSnapshot(gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame]));
gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame]));
......@@ -58,4 +58,4 @@ bool GrabWindowSnapshotImpl(gfx::NativeWindow window,
return true;
}
} // namespace chrome
} // namespace ui
......@@ -2,28 +2,21 @@
// 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 "ui/window_snapshot/window_snapshot.h"
#import <Cocoa/Cocoa.h>
#include "base/memory/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
#include "testing/platform_test.h"
#include "ui/gfx/rect.h"
namespace chrome {
namespace ui {
namespace {
typedef PlatformTest GrabWindowSnapshotTest;
TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) {
// GrabWindowSnapshot reads local state, so set it up
ScopedTestingLocalState local_state(
static_cast<TestingBrowserProcess*>(g_browser_process));
// Launch a test window so we can take a snapshot.
NSRect frame = NSMakeRect(0, 0, 400, 400);
scoped_nsobject<NSWindow> window(
......@@ -53,4 +46,4 @@ TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) {
}
} // namespace
} // namespace chrome
} // namespace ui
......@@ -2,7 +2,7 @@
// 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 "ui/window_snapshot/window_snapshot.h"
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
......@@ -34,11 +34,11 @@ gfx::Rect GetWindowBounds(gfx::NativeWindow window_handle) {
} // namespace
namespace chrome {
namespace ui {
bool GrabWindowSnapshotImpl(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
bool GrabWindowSnapshot(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
DCHECK(snapshot_bounds.right() <= GetWindowBounds(window_handle).right());
DCHECK(snapshot_bounds.bottom() <= GetWindowBounds(window_handle).bottom());
......@@ -97,4 +97,4 @@ bool GrabWindowSnapshotImpl(gfx::NativeWindow window_handle,
return true;
}
} // namespace chrome
} // 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