|
57 | 57 | #include "content/public/browser/notification_source.h"
|
58 | 58 | #include "content/public/browser/render_view_host.h"
|
59 | 59 | #include "content/public/browser/render_view_host_delegate.h"
|
| 60 | +#include "content/public/browser/render_widget_host_view.h" |
60 | 61 | #include "content/public/browser/web_contents.h"
|
61 | 62 | #include "content/public/browser/web_contents_view.h"
|
62 | 63 | #include "content/public/common/url_constants.h"
|
@@ -1662,28 +1663,45 @@ bool CaptureVisibleTabFunction::RunImpl() {
|
1662 | 1663 | return false;
|
1663 | 1664 |
|
1664 | 1665 | 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 | +} |
1665 | 1681 |
|
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) { |
1673 | 1686 | 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; |
1676 | 1697 | }
|
1677 | 1698 |
|
1678 | 1699 | // Ask the renderer for a snapshot of the tab.
|
1679 |
| - wrapper->snapshot_tab_helper()->CaptureSnapshot(); |
1680 | 1700 | registrar_.Add(this,
|
1681 | 1701 | chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
|
1682 |
| - content::Source<WebContents>(wrapper->web_contents())); |
| 1702 | + content::Source<WebContents>(web_contents)); |
1683 | 1703 | AddRef(); // Balanced in CaptureVisibleTabFunction::Observe().
|
1684 | 1704 | wrapper->snapshot_tab_helper()->CaptureSnapshot();
|
1685 |
| - |
1686 |
| - return true; |
1687 | 1705 | }
|
1688 | 1706 |
|
1689 | 1707 | // If a backing store was not available in CaptureVisibleTabFunction::RunImpl,
|
|
0 commit comments