Add testing/scripts/OWNERS
[chromium-blink-merge.git] / extensions / browser / api / capture_web_contents_function.h
blob7effacd8f46fb2b82277224a911e4b29e8a397ae
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
6 #define EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
8 #include "extensions/browser/extension_function.h"
9 #include "extensions/common/api/extension_types.h"
11 class SkBitmap;
13 namespace content {
14 class WebContents;
17 namespace extensions {
19 // Base class for capturing visibile area of a WebContents.
20 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab.
21 class CaptureWebContentsFunction : public AsyncExtensionFunction {
22 public:
23 CaptureWebContentsFunction() {}
25 protected:
26 ~CaptureWebContentsFunction() override {}
28 // ExtensionFunction implementation.
29 bool HasPermission() override;
30 bool RunAsync() override;
32 virtual bool IsScreenshotEnabled() = 0;
33 virtual content::WebContents* GetWebContentsForID(int context_id) = 0;
35 enum FailureReason {
36 FAILURE_REASON_UNKNOWN,
37 FAILURE_REASON_ENCODING_FAILED,
38 FAILURE_REASON_VIEW_INVISIBLE
40 virtual void OnCaptureFailure(FailureReason reason) = 0;
42 private:
43 typedef core_api::extension_types::ImageDetails ImageDetails;
45 void CopyFromBackingStoreComplete(bool succeed, const SkBitmap& bitmap);
46 void OnCaptureSuccess(const SkBitmap& bitmap);
48 // |context_id_| is the ID used to find the relevant WebContents. In the
49 // |tabs.captureVisibleTab()| api, this represents the window-id, and in the
50 // |webview.captureVisibleRegion()| api, this represents the instance-id of
51 // the guest.
52 int context_id_;
54 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync().
55 ImageDetails::Format image_format_;
57 // Quality setting to use when encoding jpegs. Set in RunAsync().
58 int image_quality_;
60 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction);
63 } // namespace extensions
65 #endif // EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_