Skip to content

Commit 09a48a1

Browse files
Use the asynchronous version of CopyFromBackingStore in CaptureVisibleTabFunction.
BUG=120003 TEST=Take Screenshot Extension with site permission modified (http://code.google.com/chrome/extensions/samples.html#e1697cacebad05218798bf3e8a0f724517f0e8c3) worked properly. Review URL: http://codereview.chromium.org/10294003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135254 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 4ec6406 commit 09a48a1

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

chrome/browser/extensions/extension_tabs_module.cc

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "content/public/browser/notification_source.h"
5858
#include "content/public/browser/render_view_host.h"
5959
#include "content/public/browser/render_view_host_delegate.h"
60+
#include "content/public/browser/render_widget_host_view.h"
6061
#include "content/public/browser/web_contents.h"
6162
#include "content/public/browser/web_contents_view.h"
6263
#include "content/public/common/url_constants.h"
@@ -1662,28 +1663,45 @@ bool CaptureVisibleTabFunction::RunImpl() {
16621663
return false;
16631664

16641665
RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
1666+
content::RenderWidgetHostView* view = render_view_host->GetView();
1667+
if (!view) {
1668+
error_ = keys::kInternalVisibleTabCaptureError;
1669+
return false;
1670+
}
1671+
skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas;
1672+
render_view_host->AsyncCopyFromBackingStore(
1673+
gfx::Rect(),
1674+
view->GetViewBounds().size(),
1675+
temp_canvas,
1676+
base::Bind(&CaptureVisibleTabFunction::CopyFromBackingStoreComplete,
1677+
this,
1678+
base::Owned(temp_canvas)));
1679+
return true;
1680+
}
16651681

1666-
// If a backing store is cached for the tab we want to capture,
1667-
// and it can be copied into a bitmap, then use it to generate the image.
1668-
// For example, some uncommon X11 visual modes are not supported by
1669-
// CopyFromBackingStore().
1670-
skia::PlatformCanvas temp_canvas;
1671-
if (render_view_host->CopyFromBackingStore(
1672-
gfx::Rect(), gfx::Size(), &temp_canvas)) {
1682+
void CaptureVisibleTabFunction::CopyFromBackingStoreComplete(
1683+
skia::PlatformCanvas* canvas,
1684+
bool succeeded) {
1685+
if (succeeded) {
16731686
VLOG(1) << "captureVisibleTab() got image from backing store.";
1674-
SendResultFromBitmap(skia::GetTopDevice(temp_canvas)->accessBitmap(false));
1675-
return true;
1687+
SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false));
1688+
return;
1689+
}
1690+
1691+
WebContents* web_contents = NULL;
1692+
TabContentsWrapper* wrapper = NULL;
1693+
if (!GetTabToCapture(&web_contents, &wrapper)) {
1694+
error_ = keys::kInternalVisibleTabCaptureError;
1695+
SendResponse(false);
1696+
return;
16761697
}
16771698

16781699
// Ask the renderer for a snapshot of the tab.
1679-
wrapper->snapshot_tab_helper()->CaptureSnapshot();
16801700
registrar_.Add(this,
16811701
chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
1682-
content::Source<WebContents>(wrapper->web_contents()));
1702+
content::Source<WebContents>(web_contents));
16831703
AddRef(); // Balanced in CaptureVisibleTabFunction::Observe().
16841704
wrapper->snapshot_tab_helper()->CaptureSnapshot();
1685-
1686-
return true;
16871705
}
16881706

16891707
// If a backing store was not available in CaptureVisibleTabFunction::RunImpl,

chrome/browser/extensions/extension_tabs_module.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class DictionaryValue;
2727
namespace content {
2828
class WebContents;
2929
} // namespace content
30+
namespace skia {
31+
class PlatformCanvas;
32+
} // namespace skia
3033

3134
// Windows
3235
class GetWindowFunction : public SyncExtensionFunction {
@@ -181,6 +184,10 @@ class CaptureVisibleTabFunction : public AsyncExtensionFunction,
181184
const content::NotificationDetails& details) OVERRIDE;
182185
void SendResultFromBitmap(const SkBitmap& screen_capture);
183186

187+
private:
188+
void CopyFromBackingStoreComplete(skia::PlatformCanvas* canvas,
189+
bool succeeded);
190+
184191
content::NotificationRegistrar registrar_;
185192

186193
// The format (JPEG vs PNG) of the resulting image. Set in RunImpl().

0 commit comments

Comments
 (0)