Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: extensions/browser/api/capture_web_contents_function.h

Issue 522763002: Moving capture_web_contents_function to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Documenting the inheritance of CaptureWebContentsFunction Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
7 7
8 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #include "extensions/common/api/extension_types.h" 8 #include "extensions/common/api/extension_types.h"
10 9
11 class SkBitmap; 10 class SkBitmap;
12 11
13 namespace content { 12 namespace content {
14 class WebContents; 13 class WebContents;
15 } 14 }
16 15
17 namespace extensions { 16 namespace extensions {
18 17
19 // Base class for capturing visibile area of a WebContents. 18 // Base class for capturing visibile area of a WebContents.
20 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab. 19 // This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab.
21 class CaptureWebContentsFunction : public ChromeAsyncExtensionFunction { 20 // The template parameter T should be either AsyncExtensionFunction or
21 // ChromeAsyncExtensionFunction (in the cases the chrome Profile is required)
22 template <typename T>
23 class CaptureWebContentsFunction : public T {
22 public: 24 public:
23 CaptureWebContentsFunction(); 25 CaptureWebContentsFunction() {}
24 26
25 protected: 27 protected:
26 virtual ~CaptureWebContentsFunction(); 28 virtual ~CaptureWebContentsFunction() {}
27 29
28 // ExtensionFunction implementation. 30 // ExtensionFunction implementation.
29 virtual bool HasPermission() OVERRIDE; 31 virtual bool HasPermission() OVERRIDE;
30 virtual bool RunAsync() OVERRIDE; 32 virtual bool RunAsync() OVERRIDE;
31 33
32 virtual bool IsScreenshotEnabled() = 0; 34 virtual bool IsScreenshotEnabled() = 0;
33 virtual content::WebContents* GetWebContentsForID(int context_id) = 0; 35 virtual content::WebContents* GetWebContentsForID(int context_id) = 0;
34 36
35 enum FailureReason { 37 enum FailureReason {
36 FAILURE_REASON_UNKNOWN, 38 FAILURE_REASON_UNKNOWN,
37 FAILURE_REASON_ENCODING_FAILED, 39 FAILURE_REASON_ENCODING_FAILED,
38 FAILURE_REASON_VIEW_INVISIBLE 40 FAILURE_REASON_VIEW_INVISIBLE
39 }; 41 };
40 virtual void OnCaptureFailure(FailureReason reason) = 0; 42 virtual void OnCaptureFailure(FailureReason reason) = 0;
41 43
44 // ValidationFailure override to match RunAsync().
45 static bool ValidationFailure(CaptureWebContentsFunction* function);
46
42 private: 47 private:
43 typedef core_api::extension_types::ImageDetails ImageDetails; 48 typedef core_api::extension_types::ImageDetails ImageDetails;
44 49
45 void CopyFromBackingStoreComplete(bool succeed, const SkBitmap& bitmap); 50 void CopyFromBackingStoreComplete(bool succeed, const SkBitmap& bitmap);
46 void OnCaptureSuccess(const SkBitmap& bitmap); 51 void OnCaptureSuccess(const SkBitmap& bitmap);
47 52
48 // |context_id_| is the ID used to find the relevant WebContents. In the 53 // |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 54 // |tabs.captureVisibleTab()| api, this represents the window-id, and in the
50 // |webview.captureVisibleRegion()| api, this represents the instance-id of 55 // |webview.captureVisibleRegion()| api, this represents the instance-id of
51 // the guest. 56 // the guest.
52 int context_id_; 57 int context_id_;
53 58
54 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync(). 59 // The format (JPEG vs PNG) of the resulting image. Set in RunAsync().
55 ImageDetails::Format image_format_; 60 ImageDetails::Format image_format_;
56 61
57 // Quality setting to use when encoding jpegs. Set in RunAsync(). 62 // Quality setting to use when encoding jpegs. Set in RunAsync().
58 int image_quality_; 63 int image_quality_;
59 64
60 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction); 65 DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction);
61 }; 66 };
62 67
63 } // namespace extensions 68 } // namespace extensions
64 69
65 #endif // CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_ 70 #endif // CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
OLDNEW
« no previous file with comments | « chrome/chrome_browser_extensions.gypi ('k') | extensions/browser/api/capture_web_contents_function_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698