#ifndef UI_SNAPSHOT_SCREENSHOT_GRABBER_H_
#define UI_SNAPSHOT_SCREENSHOT_GRABBER_H_
#include <memory>
#include <string>
#include "base/functional/callback.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_ui_types.h"
#include "ui/snapshot/snapshot_export.h"
namespace ui {
enum class ScreenshotResult {
SUCCESS,
GRABWINDOW_PARTIAL_FAILED,
GRABWINDOW_FULL_FAILED,
CREATE_DIR_FAILED,
GET_DIR_FAILED,
CHECK_DIR_FAILED,
CREATE_FILE_FAILED,
WRITE_FILE_FAILED,
DISABLED,
DISABLED_BY_DLP
};
class SNAPSHOT_EXPORT ScreenshotGrabber {
public:
ScreenshotGrabber();
ScreenshotGrabber(const ScreenshotGrabber&) = delete;
ScreenshotGrabber& operator=(const ScreenshotGrabber&) = delete;
~ScreenshotGrabber();
using ScreenshotCallback =
base::OnceCallback<void(ui::ScreenshotResult screenshot_result,
scoped_refptr<base::RefCountedMemory> png_data)>;
void TakeScreenshot(gfx::NativeWindow window,
const gfx::Rect& rect,
ScreenshotCallback callback);
bool CanTakeScreenshot();
private:
#if defined(USE_AURA)
class ScopedCursorHider;
#endif
void GrabSnapshotImageCallback(
const std::string& window_identifier,
bool is_partial,
ScreenshotCallback callback,
scoped_refptr<base::RefCountedMemory> png_data);
base::TimeTicks last_screenshot_timestamp_;
#if defined(USE_AURA)
std::unique_ptr<ScopedCursorHider> cursor_hider_;
#endif
base::WeakPtrFactory<ScreenshotGrabber> factory_{this};
};
}
#endif