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

Unified Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 10294003: Use the asynchronous version of CopyFromBackingStore in CaptureVisibleTabFunction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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/extension_tabs_module.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_tabs_module.cc
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 054c58e8c36eb20be6150066abf8bcb835bbcc2e..c5bbb39cf47bb1f8745a96ed6affc562d5145933 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -57,6 +57,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_view_host_delegate.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/url_constants.h"
@@ -1662,27 +1663,17 @@ bool CaptureVisibleTabFunction::RunImpl() {
return false;
RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
-
- // If a backing store is cached for the tab we want to capture,
- // and it can be copied into a bitmap, then use it to generate the image.
- // For example, some uncommon X11 visual modes are not supported by
- // CopyFromBackingStore().
- skia::PlatformCanvas temp_canvas;
- if (render_view_host->CopyFromBackingStore(
- gfx::Rect(), gfx::Size(), &temp_canvas)) {
- VLOG(1) << "captureVisibleTab() got image from backing store.";
- SendResultFromBitmap(skia::GetTopDevice(temp_canvas)->accessBitmap(false));
- return true;
- }
-
- // Ask the renderer for a snapshot of the tab.
- wrapper->snapshot_tab_helper()->CaptureSnapshot();
mazda 2012/05/02 01:23:25 This line looks redundant and I copied the code wi
Sam Kerner (Chrome) 2012/05/02 03:26:09 It looks redundant to me, but the code has changed
- registrar_.Add(this,
- chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
- content::Source<WebContents>(wrapper->web_contents()));
- AddRef(); // Balanced in CaptureVisibleTabFunction::Observe().
- wrapper->snapshot_tab_helper()->CaptureSnapshot();
-
+ content::RenderWidgetHostView* view = render_view_host->GetView();
+ if (!view)
+ return false;
+ skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas;
+ render_view_host->AsyncCopyFromBackingStore(
+ gfx::Rect(),
+ view->GetViewBounds().size(),
+ temp_canvas,
+ base::Bind(&CaptureVisibleTabFunction::CopyFromBackingStoreComplete,
+ this,
+ base::Owned(temp_canvas)));
return true;
}
@@ -1758,6 +1749,33 @@ void CaptureVisibleTabFunction::SendResultFromBitmap(
SendResponse(true);
}
+void CaptureVisibleTabFunction::CopyFromBackingStoreComplete(
Sam Kerner (Chrome) 2012/05/02 03:47:14 In this file, the functions are in the same order
mazda 2012/05/02 06:07:39 Done.
+ skia::PlatformCanvas* canvas,
+ bool succeeded) {
+ if (succeeded) {
+ VLOG(1) << "captureVisibleTab() got image from backing store.";
+ SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false));
+ return;
+ }
+
+ // TODO(mazda): Remove the following code once AsyncCopyFromBackingStore is
Sam Kerner (Chrome) 2012/05/02 03:47:14 It has been two years since I looked at this in de
mazda 2012/05/02 06:07:39 Thanks for the useful comment. I think your commen
+ // supported on all platforms.
+ WebContents* web_contents = NULL;
+ TabContentsWrapper* wrapper = NULL;
+ if (!GetTabToCapture(&web_contents, &wrapper)) {
+ error_ = keys::kInternalVisibleTabCaptureError;
+ return;
+ }
+
+ // Ask the renderer for a snapshot of the tab.
+ registrar_.Add(this,
+ chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
+ content::Source<WebContents>(web_contents));
+ AddRef(); // Balanced in CaptureVisibleTabFunction::Observe().
+ wrapper->snapshot_tab_helper()->CaptureSnapshot();
+ return;
+}
+
bool DetectTabLanguageFunction::RunImpl() {
int tab_id = 0;
Browser* browser = NULL;
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698