Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / extensions / browser / api / capture_web_contents_function.h
blobfadb700c993b400458923af48ea854a21538397f
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 "content/public/browser/readback_types.h"
9 #include "extensions/browser/extension_function.h"
10 #include "extensions/common/api/extension_types.h"
12 class SkBitmap;
14 namespace content {
15 class WebContents;
18 namespace extensions {
20 // Base class for capturing visibile area of a WebContents.
21 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab.
22 class CaptureWebContentsFunction : public AsyncExtensionFunction {
23 public:
24 CaptureWebContentsFunction() {}
26 protected:
27 ~CaptureWebContentsFunction() override {}
29 // ExtensionFunction implementation.
30 bool HasPermission() override;
31 bool RunAsync() override;
33 virtual bool IsScreenshotEnabled() = 0;
34 virtual content::WebContents* GetWebContentsForID(int context_id) = 0;
36 enum FailureReason {
37 FAILURE_REASON_UNKNOWN,
38 FAILURE_REASON_ENCODING_FAILED,
39 FAILURE_REASON_VIEW_INVISIBLE
41 virtual void OnCaptureFailure(FailureReason reason) = 0;
43 private:
45 void CopyFromBackingStoreComplete(const SkBitmap& bitmap,
46 content::ReadbackResponse response);
47 void OnCaptureSuccess(const SkBitmap& bitmap);
49 // |context_id_| is the ID used to find the relevant WebContents. In the
50 // |tabs.captureVisibleTab()| api, this represents the window-id, and in the
51 // |webview.captureVisibleRegion()| api, this represents the instance-id of
52 // the guest.
53 int context_id_;
55 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync().
56 api::extension_types::ImageFormat image_format_;
58 // Quality setting to use when encoding jpegs. Set in RunAsync().
59 int image_quality_;
61 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction);
64 } // namespace extensions
66 #endif // EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_