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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 1635513003: Implement webview.captureVisibleRegion() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Save bug number to surface_utils.cc. 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
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | chrome/common/extensions/api/webview_tag.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6924b10f15d888a25bd52c4be268a2a0012d1d69..be01fee7391014e51616fb4ab074c710a598d880 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -1648,6 +1648,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)) {
@@ -1675,6 +1679,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) {
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | chrome/common/extensions/api/webview_tag.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698