summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/capture_web_contents_function.h
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-10 01:56:20 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-10 01:56:20 +0000
commit6bd2a7af3f856a032cf25fb8b482a98f1a0d335f (patch)
treed25890354a448ef4a79668db5b8fa85d0b48a893 /chrome/browser/extensions/api/capture_web_contents_function.h
parentc96cab37b194085d2b7e3b220003da4571e24767 (diff)
downloadchromium_src-6bd2a7af3f856a032cf25fb8b482a98f1a0d335f.zip
chromium_src-6bd2a7af3f856a032cf25fb8b482a98f1a0d335f.tar.gz
chromium_src-6bd2a7af3f856a032cf25fb8b482a98f1a0d335f.tar.bz2
<webview>: Add a screenshot capture API.
Introduce webview.captureVisibleRegion() to get a snapshot of the currently visible content in the guest-page. This is modelled around the tabs.captureVisibleTab() api. In order to share code between the two implementation, the core of the capture code is moved into CaptureWebContentsFunction, with appropriate interface so that this is usable for both tabs and webview implementation. This refactoring is modelled around the refactor work that was done for sharing ExecuteScript() implementation between the two api. BUG=326755 R=fsamuel@chromium.org, mpcomplete@chromium.org Review URL: https://codereview.chromium.org/103603003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239642 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/capture_web_contents_function.h')
-rw-r--r--chrome/browser/extensions/api/capture_web_contents_function.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/capture_web_contents_function.h b/chrome/browser/extensions/api/capture_web_contents_function.h
new file mode 100644
index 0000000..0c59bb0
--- /dev/null
+++ b/chrome/browser/extensions/api/capture_web_contents_function.h
@@ -0,0 +1,67 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
+#define CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_
+
+#include "chrome/browser/extensions/chrome_extension_function.h"
+#include "chrome/common/extensions/api/capture_web_contents_private.h"
+
+class SkBitmap;
+
+namespace content {
+class WebContents;
+}
+
+namespace extensions {
+
+// Base class for capturing visibile area of a WebContents.
+// This is used by both webview.captureVisibleRegion and tabs.captureVisibleTab.
+class CaptureWebContentsFunction : public ChromeAsyncExtensionFunction {
+ public:
+ CaptureWebContentsFunction();
+
+ protected:
+ virtual ~CaptureWebContentsFunction();
+
+ // ExtensionFunction implementation.
+ virtual bool HasPermission() OVERRIDE;
+ virtual bool RunImpl() OVERRIDE;
+
+ virtual bool IsScreenshotEnabled() = 0;
+ virtual content::WebContents* GetWebContentsForID(int context_id) = 0;
+
+ enum FailureReason {
+ FAILURE_REASON_UNKNOWN,
+ FAILURE_REASON_CONTENT_NOT_FOUND,
+ FAILURE_REASON_ENCODING_FAILED,
+ FAILURE_REASON_VIEW_INVISIBLE
+ };
+ virtual void OnCaptureFailure(FailureReason reason) = 0;
+
+ private:
+ typedef api::capture_web_contents_private::ImageDetails ImageDetails;
+
+ void CopyFromBackingStoreComplete(bool succeed, const SkBitmap& bitmap);
+ void GetSnapshotFromRendererComplete(bool succeeded, const SkBitmap& bitmap);
+ void OnCaptureSuccess(const SkBitmap& bitmap);
+
+ // |context_id_| is the ID used to find the relevant WebContents. In the
+ // |tabs.captureVisibleTab()| api, this represents the window-id, and in the
+ // |webview.captureVisibleRegion()| api, this represents the instance-id of
+ // the guest.
+ int context_id_;
+
+ // The format (JPEG vs PNG) of the resulting image. Set in RunImpl().
+ ImageDetails::Format image_format_;
+
+ // Quality setting to use when encoding jpegs. Set in RunImpl().
+ int image_quality_;
+
+ DISALLOW_COPY_AND_ASSIGN(CaptureWebContentsFunction);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_CAPTURE_WEB_CONTENTS_FUNCTION_H_