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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_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: chrome/browser/extensions/api/tabs/tabs_api.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc
index a1176106d3158048a3183e4271ae5551fbd71235..ad2a7920d3da5de11b7c7a98facbbd3115118904 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -1641,6 +1641,10 @@ TabsCaptureVisibleTabFunction::TabsCaptureVisibleTabFunction()
: chrome_details_(this) {
}
+bool TabsCaptureVisibleTabFunction::HasPermission() {
+ return true;
+}
+
bool TabsCaptureVisibleTabFunction::IsScreenshotEnabled() {
PrefService* service = chrome_details_.GetProfile()->GetPrefs();
if (service->GetBoolean(prefs::kDisableScreenshots)) {
@@ -1668,6 +1672,40 @@ WebContents* TabsCaptureVisibleTabFunction::GetWebContentsForID(int window_id) {
return contents;
}
+bool TabsCaptureVisibleTabFunction::RunAsync() {
+ using api::extension_types::ImageDetails;
+
+ EXTENSION_FUNCTION_VALIDATE(args_);
+
+ int context_id = extension_misc::kCurrentWindowId;
+ args_->GetInteger(0, &context_id);
+
+ 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);
+ }
+
+ WebContents* contents = GetWebContentsForID(context_id);
+
+ return CaptureAsync(
+ contents, image_details.get(),
+ base::Bind(&TabsCaptureVisibleTabFunction::CopyFromBackingStoreComplete,
+ this));
+}
+
+void TabsCaptureVisibleTabFunction::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 TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) {
const char* reason_description = "internal error";
switch (reason) {

Powered by Google App Engine
This is Rietveld 408576698