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

Unified Diff: extensions/browser/api/guest_view/web_view/web_view_internal_api.cc

Issue 1582053002: Implement webview.captureVisibleRegion() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test so it waits for the first frame to be generated. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/guest_view/web_view/web_view_internal_api.cc
diff --git a/extensions/browser/api/guest_view/web_view/web_view_internal_api.cc b/extensions/browser/api/guest_view/web_view/web_view_internal_api.cc
index bba531d6535a157057fb941fe521b783bf474961..3e3a8ed5360f34a1721cd7b0433178fc61c79e01 100644
--- a/extensions/browser/api/guest_view/web_view/web_view_internal_api.cc
+++ b/extensions/browser/api/guest_view/web_view/web_view_internal_api.cc
@@ -259,6 +259,62 @@ bool WebViewInternalExtensionFunction::RunAsync() {
return RunAsyncSafe(guest);
}
+bool WebViewInternalCaptureVisibleRegionFunction::RunAsyncSafe(
+ WebViewGuest* guest) {
+ using api::extension_types::ImageDetails;
+
+ scoped_ptr<web_view_internal::CaptureVisibleRegion::Params> params(
+ web_view_internal::CaptureVisibleRegion::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ scoped_ptr<ImageDetails> image_details;
+ if (args_->GetSize() > 1) {
+ base::Value* spec = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &spec) && spec);
+ image_details = ImageDetails::FromValue(*spec);
+ }
+
+ return CaptureAsync(guest->web_contents(), image_details.get(),
+ base::Bind(&WebViewInternalCaptureVisibleRegionFunction::
+ CopyFromBackingStoreComplete,
+ this));
+}
+bool WebViewInternalCaptureVisibleRegionFunction::IsScreenshotEnabled() {
+ // TODO(wjmaclean): Is it ok to always return true here?
+ return true;
+}
+
+void WebViewInternalCaptureVisibleRegionFunction::OnCaptureSuccess(
+ const SkBitmap& bitmap) {
+ std::string base64_result;
+ if (!EncodeBitmap(bitmap, &base64_result)) {
+ OnCaptureFailure(FAILURE_REASON_ENCODING_FAILED);
+ return;
+ }
+
+ SetResult(new base::StringValue(base64_result));
+ SendResponse(true);
+}
+
+void WebViewInternalCaptureVisibleRegionFunction::OnCaptureFailure(
+ FailureReason reason) {
+ const char* reason_description = "internal error";
+ switch (reason) {
+ case FAILURE_REASON_UNKNOWN:
+ reason_description = "unknown error";
+ break;
+ case FAILURE_REASON_ENCODING_FAILED:
+ reason_description = "encoding failed";
+ break;
+ case FAILURE_REASON_VIEW_INVISIBLE:
+ reason_description = "view is invisible";
+ break;
+ }
+ error_ = ErrorUtils::FormatErrorMessage("Failed to capture webview: *",
+ reason_description);
+ SendResponse(false);
+}
+
bool WebViewInternalNavigateFunction::RunAsyncSafe(WebViewGuest* guest) {
scoped_ptr<web_view_internal::Navigate::Params> params(
web_view_internal::Navigate::Params::Create(*args_));

Powered by Google App Engine
This is Rietveld 408576698