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_CAPTURE_WEB_CONTENTS_FUNCTION_H_ |
6 #define EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ | 6 #define EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ |
7 | 7 |
| 8 #include "extensions/browser/extension_function.h" |
8 #include "extensions/common/api/extension_types.h" | 9 #include "extensions/common/api/extension_types.h" |
9 | 10 |
10 class SkBitmap; | 11 class SkBitmap; |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 class WebContents; | 14 class WebContents; |
14 } | 15 } |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
18 // Base class for capturing visibile area of a WebContents. | 19 // Base class for capturing visibile area of a WebContents. |
19 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab. | 20 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab. |
20 // The template parameter T should be either AsyncExtensionFunction or | 21 class CaptureWebContentsFunction : public AsyncExtensionFunction { |
21 // ChromeAsyncExtensionFunction (in the cases the chrome Profile is required) | |
22 template <typename T> | |
23 class CaptureWebContentsFunction : public T { | |
24 public: | 22 public: |
25 CaptureWebContentsFunction() {} | 23 CaptureWebContentsFunction() {} |
26 | 24 |
27 protected: | 25 protected: |
28 virtual ~CaptureWebContentsFunction() {} | 26 virtual ~CaptureWebContentsFunction() {} |
29 | 27 |
30 // ExtensionFunction implementation. | 28 // ExtensionFunction implementation. |
31 virtual bool HasPermission() OVERRIDE; | 29 virtual bool HasPermission() OVERRIDE; |
32 virtual bool RunAsync() OVERRIDE; | 30 virtual bool RunAsync() OVERRIDE; |
33 | 31 |
34 virtual bool IsScreenshotEnabled() = 0; | 32 virtual bool IsScreenshotEnabled() = 0; |
35 virtual content::WebContents* GetWebContentsForID(int context_id) = 0; | 33 virtual content::WebContents* GetWebContentsForID(int context_id) = 0; |
36 | 34 |
37 enum FailureReason { | 35 enum FailureReason { |
38 FAILURE_REASON_UNKNOWN, | 36 FAILURE_REASON_UNKNOWN, |
39 FAILURE_REASON_ENCODING_FAILED, | 37 FAILURE_REASON_ENCODING_FAILED, |
40 FAILURE_REASON_VIEW_INVISIBLE | 38 FAILURE_REASON_VIEW_INVISIBLE |
41 }; | 39 }; |
42 virtual void OnCaptureFailure(FailureReason reason) = 0; | 40 virtual void OnCaptureFailure(FailureReason reason) = 0; |
43 | 41 |
44 // ValidationFailure override to match RunAsync(). | |
45 static bool ValidationFailure(CaptureWebContentsFunction* function); | |
46 | |
47 private: | 42 private: |
48 typedef core_api::extension_types::ImageDetails ImageDetails; | 43 typedef core_api::extension_types::ImageDetails ImageDetails; |
49 | 44 |
50 void CopyFromBackingStoreComplete(bool succeed, const SkBitmap& bitmap); | 45 void CopyFromBackingStoreComplete(bool succeed, const SkBitmap& bitmap); |
51 void OnCaptureSuccess(const SkBitmap& bitmap); | 46 void OnCaptureSuccess(const SkBitmap& bitmap); |
52 | 47 |
53 // |context_id_| is the ID used to find the relevant WebContents. In the | 48 // |context_id_| is the ID used to find the relevant WebContents. In the |
54 // |tabs.captureVisibleTab()| api, this represents the window-id, and in the | 49 // |tabs.captureVisibleTab()| api, this represents the window-id, and in the |
55 // |webview.captureVisibleRegion()| api, this represents the instance-id of | 50 // |webview.captureVisibleRegion()| api, this represents the instance-id of |
56 // the guest. | 51 // the guest. |
57 int context_id_; | 52 int context_id_; |
58 | 53 |
59 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync(). | 54 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync(). |
60 ImageDetails::Format image_format_; | 55 ImageDetails::Format image_format_; |
61 | 56 |
62 // Quality setting to use when encoding jpegs. Set in RunAsync(). | 57 // Quality setting to use when encoding jpegs. Set in RunAsync(). |
63 int image_quality_; | 58 int image_quality_; |
64 | 59 |
65 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction); | 60 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction); |
66 }; | 61 }; |
67 | 62 |
68 } // namespace extensions | 63 } // namespace extensions |
69 | 64 |
70 #endif // EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ | 65 #endif // EXTENSIONS_BROWSER_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ |
OLD | NEW |