OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_WEB_CONTENTS_CAPTURE_CLIENT_H_ |
6 #define EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ | 6 #define EXTENSIONS_BROWSER_API_WEB_CONTENTS_CAPTURE_CLIENT_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "content/public/browser/readback_types.h" | 9 #include "content/public/browser/readback_types.h" |
10 #include "extensions/browser/extension_function.h" | 10 #include "extensions/browser/extension_function.h" |
11 #include "extensions/common/api/extension_types.h" | 11 #include "extensions/common/api/extension_types.h" |
12 | 12 |
13 class SkBitmap; | 13 class SkBitmap; |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 class WebContents; | 16 class WebContents; |
17 } | 17 } |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
20 | 20 |
21 // Base class for capturing visibile area of a WebContents. | 21 // Base class for capturing visible area of a WebContents. |
22 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab. | 22 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab. |
23 class CaptureWebContentsFunction : public AsyncExtensionFunction { | 23 class WebContentsCaptureClient { |
24 public: | 24 public: |
25 CaptureWebContentsFunction() {} | 25 WebContentsCaptureClient() {} |
26 | 26 |
27 protected: | 27 protected: |
28 ~CaptureWebContentsFunction() override {} | 28 virtual ~WebContentsCaptureClient() {} |
29 | |
30 // ExtensionFunction implementation. | |
31 bool HasPermission() override; | |
32 bool RunAsync() override; | |
33 | 29 |
34 virtual bool IsScreenshotEnabled() = 0; | 30 virtual bool IsScreenshotEnabled() = 0; |
35 virtual content::WebContents* GetWebContentsForID(int context_id) = 0; | |
36 | 31 |
37 enum FailureReason { | 32 enum FailureReason { |
38 FAILURE_REASON_UNKNOWN, | 33 FAILURE_REASON_UNKNOWN, |
39 FAILURE_REASON_ENCODING_FAILED, | 34 FAILURE_REASON_ENCODING_FAILED, |
40 FAILURE_REASON_VIEW_INVISIBLE | 35 FAILURE_REASON_VIEW_INVISIBLE |
41 }; | 36 }; |
| 37 bool CaptureAsync(content::WebContents* web_contents, |
| 38 const api::extension_types::ImageDetails* image_detail, |
| 39 const content::ReadbackRequestCallback callback); |
| 40 bool EncodeBitmap(const SkBitmap& bitmap, std::string* base64_result); |
42 virtual void OnCaptureFailure(FailureReason reason) = 0; | 41 virtual void OnCaptureFailure(FailureReason reason) = 0; |
| 42 virtual void OnCaptureSuccess(const SkBitmap& bitmap) = 0; |
| 43 void CopyFromBackingStoreComplete(const SkBitmap& bitmap, |
| 44 content::ReadbackResponse response); |
43 | 45 |
44 private: | 46 private: |
45 | |
46 void CopyFromBackingStoreComplete(const SkBitmap& bitmap, | |
47 content::ReadbackResponse response); | |
48 void OnCaptureSuccess(const SkBitmap& bitmap); | |
49 | |
50 // |context_id_| is the ID used to find the relevant WebContents. In the | |
51 // |tabs.captureVisibleTab()| api, this represents the window-id, and in the | |
52 // |webview.captureVisibleRegion()| api, this represents the instance-id of | |
53 // the guest. | |
54 int context_id_; | |
55 | |
56 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync(). | 47 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync(). |
57 api::extension_types::ImageFormat image_format_; | 48 api::extension_types::ImageFormat image_format_; |
58 | 49 |
59 // Quality setting to use when encoding jpegs. Set in RunAsync(). | 50 // Quality setting to use when encoding jpegs. Set in RunAsync(). |
60 int image_quality_; | 51 int image_quality_; |
61 | 52 |
62 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction); | 53 DISALLOW_COPY_AND_ASSIGN(WebContentsCaptureClient); |
63 }; | 54 }; |
64 | 55 |
65 } // namespace extensions | 56 } // namespace extensions |
66 | 57 |
67 #endif // EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ | 58 #endif // EXTENSIONS_BROWSER_API_WEB_CONTENTS_CAPTURE_CLIENT_H_ |
OLD | NEW |