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

Side by Side 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: Fix test Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "chrome/common/extensions/extension_messages.h" 50 #include "chrome/common/extensions/extension_messages.h"
51 #include "chrome/common/extensions/user_script.h" 51 #include "chrome/common/extensions/user_script.h"
52 #include "chrome/common/pref_names.h" 52 #include "chrome/common/pref_names.h"
53 #include "chrome/common/url_constants.h" 53 #include "chrome/common/url_constants.h"
54 #include "content/public/browser/navigation_controller.h" 54 #include "content/public/browser/navigation_controller.h"
55 #include "content/public/browser/navigation_entry.h" 55 #include "content/public/browser/navigation_entry.h"
56 #include "content/public/browser/notification_details.h" 56 #include "content/public/browser/notification_details.h"
57 #include "content/public/browser/notification_source.h" 57 #include "content/public/browser/notification_source.h"
58 #include "content/public/browser/render_view_host.h" 58 #include "content/public/browser/render_view_host.h"
59 #include "content/public/browser/render_view_host_delegate.h" 59 #include "content/public/browser/render_view_host_delegate.h"
60 #include "content/public/browser/render_widget_host_view.h"
60 #include "content/public/browser/web_contents.h" 61 #include "content/public/browser/web_contents.h"
61 #include "content/public/browser/web_contents_view.h" 62 #include "content/public/browser/web_contents_view.h"
62 #include "content/public/common/url_constants.h" 63 #include "content/public/common/url_constants.h"
63 #include "skia/ext/image_operations.h" 64 #include "skia/ext/image_operations.h"
64 #include "skia/ext/platform_canvas.h" 65 #include "skia/ext/platform_canvas.h"
65 #include "third_party/skia/include/core/SkBitmap.h" 66 #include "third_party/skia/include/core/SkBitmap.h"
66 #include "ui/base/ui_base_types.h" 67 #include "ui/base/ui_base_types.h"
67 #include "ui/gfx/codec/jpeg_codec.h" 68 #include "ui/gfx/codec/jpeg_codec.h"
68 #include "ui/gfx/codec/png_codec.h" 69 #include "ui/gfx/codec/png_codec.h"
69 70
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 } 1656 }
1656 } 1657 }
1657 1658
1658 // captureVisibleTab() can return an image containing sensitive information 1659 // captureVisibleTab() can return an image containing sensitive information
1659 // that the browser would otherwise protect. Ensure the extension has 1660 // that the browser would otherwise protect. Ensure the extension has
1660 // permission to do this. 1661 // permission to do this.
1661 if (!GetExtension()->CanCaptureVisiblePage(web_contents->GetURL(), &error_)) 1662 if (!GetExtension()->CanCaptureVisiblePage(web_contents->GetURL(), &error_))
1662 return false; 1663 return false;
1663 1664
1664 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); 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, 1682 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete(
1667 // and it can be copied into a bitmap, then use it to generate the image. 1683 skia::PlatformCanvas* canvas,
1668 // For example, some uncommon X11 visual modes are not supported by 1684 bool succeeded) {
1669 // CopyFromBackingStore(). 1685 if (succeeded) {
1670 skia::PlatformCanvas temp_canvas;
1671 if (render_view_host->CopyFromBackingStore(
1672 gfx::Rect(), gfx::Size(), &temp_canvas)) {
1673 VLOG(1) << "captureVisibleTab() got image from backing store."; 1686 VLOG(1) << "captureVisibleTab() got image from backing store.";
1674 SendResultFromBitmap(skia::GetTopDevice(temp_canvas)->accessBitmap(false)); 1687 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false));
1675 return true; 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 // Ask the renderer for a snapshot of the tab. 1699 // Ask the renderer for a snapshot of the tab.
1679 wrapper->snapshot_tab_helper()->CaptureSnapshot();
1680 registrar_.Add(this, 1700 registrar_.Add(this,
1681 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, 1701 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
1682 content::Source<WebContents>(wrapper->web_contents())); 1702 content::Source<WebContents>(web_contents));
1683 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). 1703 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe().
1684 wrapper->snapshot_tab_helper()->CaptureSnapshot(); 1704 wrapper->snapshot_tab_helper()->CaptureSnapshot();
1685
1686 return true;
1687 } 1705 }
1688 1706
1689 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, 1707 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl,
1690 // than the renderer was asked for a snapshot. Listen for a notification 1708 // than the renderer was asked for a snapshot. Listen for a notification
1691 // that the snapshot is available. 1709 // that the snapshot is available.
1692 void CaptureVisibleTabFunction::Observe( 1710 void CaptureVisibleTabFunction::Observe(
1693 int type, 1711 int type,
1694 const content::NotificationSource& source, 1712 const content::NotificationSource& source,
1695 const content::NotificationDetails& details) { 1713 const content::NotificationDetails& details) {
1696 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); 1714 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 // called for every API call the extension made. 1846 // called for every API call the extension made.
1829 GotLanguage(language); 1847 GotLanguage(language);
1830 } 1848 }
1831 1849
1832 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1850 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1833 result_.reset(Value::CreateStringValue(language.c_str())); 1851 result_.reset(Value::CreateStringValue(language.c_str()));
1834 SendResponse(true); 1852 SendResponse(true);
1835 1853
1836 Release(); // Balanced in Run() 1854 Release(); // Balanced in Run()
1837 } 1855 }
OLDNEW
« 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