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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 12881005: Allow CopyFromBackingStore to fallback to copying from the renderer side if the accelerated surface… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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
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/api/tabs/tabs_api.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 27 matching lines...) Expand all
38 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_commands.h" 39 #include "chrome/browser/ui/browser_commands.h"
40 #include "chrome/browser/ui/browser_finder.h" 40 #include "chrome/browser/ui/browser_finder.h"
41 #include "chrome/browser/ui/browser_iterator.h" 41 #include "chrome/browser/ui/browser_iterator.h"
42 #include "chrome/browser/ui/browser_navigator.h" 42 #include "chrome/browser/ui/browser_navigator.h"
43 #include "chrome/browser/ui/browser_tabstrip.h" 43 #include "chrome/browser/ui/browser_tabstrip.h"
44 #include "chrome/browser/ui/browser_window.h" 44 #include "chrome/browser/ui/browser_window.h"
45 #include "chrome/browser/ui/extensions/shell_window.h" 45 #include "chrome/browser/ui/extensions/shell_window.h"
46 #include "chrome/browser/ui/host_desktop.h" 46 #include "chrome/browser/ui/host_desktop.h"
47 #include "chrome/browser/ui/panels/panel_manager.h" 47 #include "chrome/browser/ui/panels/panel_manager.h"
48 #include "chrome/browser/ui/snapshot_tab_helper.h"
49 #include "chrome/browser/ui/tabs/tab_strip_model.h" 48 #include "chrome/browser/ui/tabs/tab_strip_model.h"
50 #include "chrome/browser/ui/window_sizer/window_sizer.h" 49 #include "chrome/browser/ui/window_sizer/window_sizer.h"
51 #include "chrome/browser/web_applications/web_app.h" 50 #include "chrome/browser/web_applications/web_app.h"
52 #include "chrome/common/chrome_notification_types.h" 51 #include "chrome/common/chrome_notification_types.h"
53 #include "chrome/common/chrome_switches.h" 52 #include "chrome/common/chrome_switches.h"
54 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 53 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
55 #include "chrome/common/extensions/api/tabs.h" 54 #include "chrome/common/extensions/api/tabs.h"
56 #include "chrome/common/extensions/api/windows.h" 55 #include "chrome/common/extensions/api/windows.h"
57 #include "chrome/common/extensions/extension.h" 56 #include "chrome/common/extensions/extension.h"
58 #include "chrome/common/extensions/extension_constants.h" 57 #include "chrome/common/extensions/extension_constants.h"
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 gfx::Rect(), 1736 gfx::Rect(),
1738 view->GetViewBounds().size(), 1737 view->GetViewBounds().size(),
1739 base::Bind(&TabsCaptureVisibleTabFunction::CopyFromBackingStoreComplete, 1738 base::Bind(&TabsCaptureVisibleTabFunction::CopyFromBackingStoreComplete,
1740 this)); 1739 this));
1741 return true; 1740 return true;
1742 } 1741 }
1743 1742
1744 void TabsCaptureVisibleTabFunction::CopyFromBackingStoreComplete( 1743 void TabsCaptureVisibleTabFunction::CopyFromBackingStoreComplete(
1745 bool succeeded, 1744 bool succeeded,
1746 const SkBitmap& bitmap) { 1745 const SkBitmap& bitmap) {
1747 if (succeeded) { 1746 if (!succeeded) {
1748 VLOG(1) << "captureVisibleTab() got image from backing store.";
1749 SendResultFromBitmap(bitmap);
1750 return;
1751 }
1752
1753 WebContents* web_contents = NULL;
1754 if (!GetTabToCapture(&web_contents)) {
1755 error_ = keys::kInternalVisibleTabCaptureError; 1747 error_ = keys::kInternalVisibleTabCaptureError;
1756 SendResponse(false); 1748 SendResponse(false);
1757 return; 1749 return;
1758 } 1750 }
1759 1751
1760 // Ask the renderer for a snapshot of the tab. 1752 VLOG(1) << "captureVisibleTab() got image.";
1761 registrar_.Add(this, 1753 SendResultFromBitmap(bitmap);
Sam Kerner (Chrome) 2013/03/18 13:49:51 It has been a while since I was in this code. Is
1762 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
1763 content::Source<WebContents>(web_contents));
1764 AddRef(); // Balanced in TabsCaptureVisibleTabFunction::Observe().
1765 SnapshotTabHelper::FromWebContents(web_contents)->CaptureSnapshot();
1766 }
1767
1768 // If a backing store was not available in
1769 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a
1770 // snapshot. Listen for a notification that the snapshot is available.
1771 void TabsCaptureVisibleTabFunction::Observe(
1772 int type,
1773 const content::NotificationSource& source,
1774 const content::NotificationDetails& details) {
1775 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN);
1776
1777 const SkBitmap *screen_capture =
1778 content::Details<const SkBitmap>(details).ptr();
1779 const bool error = screen_capture->empty();
1780
1781 if (error) {
1782 error_ = keys::kInternalVisibleTabCaptureError;
1783 SendResponse(false);
1784 } else {
1785 VLOG(1) << "captureVisibleTab() got image from renderer.";
1786 SendResultFromBitmap(*screen_capture);
1787 }
1788
1789 Release(); // Balanced in TabsCaptureVisibleTabFunction::RunImpl().
1790 } 1754 }
1791 1755
1792 // Turn a bitmap of the screen into an image, set that image as the result, 1756 // Turn a bitmap of the screen into an image, set that image as the result,
1793 // and call SendResponse(). 1757 // and call SendResponse().
1794 void TabsCaptureVisibleTabFunction::SendResultFromBitmap( 1758 void TabsCaptureVisibleTabFunction::SendResultFromBitmap(
1795 const SkBitmap& screen_capture) { 1759 const SkBitmap& screen_capture) {
1796 std::vector<unsigned char> data; 1760 std::vector<unsigned char> data;
1797 SkAutoLockPixels screen_capture_lock(screen_capture); 1761 SkAutoLockPixels screen_capture_lock(screen_capture);
1798 bool encoded = false; 1762 bool encoded = false;
1799 std::string mime_type; 1763 std::string mime_type;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2154 extension->id(), 2118 extension->id(),
2155 script_type, 2119 script_type,
2156 code_string, 2120 code_string,
2157 frame_scope, 2121 frame_scope,
2158 run_at, 2122 run_at,
2159 ScriptExecutor::ISOLATED_WORLD, 2123 ScriptExecutor::ISOLATED_WORLD,
2160 false /* is_web_view */, 2124 false /* is_web_view */,
2161 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); 2125 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this));
2162 return true; 2126 return true;
2163 } 2127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698