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

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: unused include 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 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after
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."; 1747 VLOG(1) << "captureVisibleTab() got image from backing store.";
1749 SendResultFromBitmap(bitmap); 1748 SendResultFromBitmap(bitmap);
1750 return; 1749 return;
1751 } 1750 }
1752 1751
1753 WebContents* web_contents = NULL; 1752 WebContents* web_contents = NULL;
1754 if (!GetTabToCapture(&web_contents)) { 1753 if (!GetTabToCapture(&web_contents)) {
1755 error_ = keys::kInternalVisibleTabCaptureError; 1754 SendInternalError();
1756 SendResponse(false);
1757 return; 1755 return;
1758 } 1756 }
1759 1757
1760 // Ask the renderer for a snapshot of the tab. 1758 // Ask the renderer for a snapshot of the tab.
1761 registrar_.Add(this, 1759 content::RenderWidgetHost* render_widget_host =
1762 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, 1760 web_contents->GetRenderViewHost();
1763 content::Source<WebContents>(web_contents)); 1761 if (!render_widget_host) {
1764 AddRef(); // Balanced in TabsCaptureVisibleTabFunction::Observe(). 1762 SendInternalError();
1765 SnapshotTabHelper::FromWebContents(web_contents)->CaptureSnapshot(); 1763 return;
1764 }
1765
1766 render_widget_host->GetSnapshotFromRenderer(
1767 gfx::Rect(),
1768 base::Bind(
1769 &TabsCaptureVisibleTabFunction::GetSnapshotFromRendererComplete,
1770 this));
1766 } 1771 }
1767 1772
1768 // If a backing store was not available in 1773 // If a backing store was not available in
1769 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a 1774 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a
1770 // snapshot. Listen for a notification that the snapshot is available. 1775 // snapshot.
1771 void TabsCaptureVisibleTabFunction::Observe( 1776 void TabsCaptureVisibleTabFunction::GetSnapshotFromRendererComplete(
1772 int type, 1777 bool succeeded,
1773 const content::NotificationSource& source, 1778 const SkBitmap& bitmap) {
1774 const content::NotificationDetails& details) { 1779 if (!succeeded) {
1775 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); 1780 SendInternalError();
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 { 1781 } else {
1785 VLOG(1) << "captureVisibleTab() got image from renderer."; 1782 VLOG(1) << "captureVisibleTab() got image from renderer.";
1786 SendResultFromBitmap(*screen_capture); 1783 SendResultFromBitmap(bitmap);
1787 } 1784 }
1785 }
1788 1786
1789 Release(); // Balanced in TabsCaptureVisibleTabFunction::RunImpl(). 1787 void TabsCaptureVisibleTabFunction::SendInternalError() {
1788 error_ = keys::kInternalVisibleTabCaptureError;
1789 SendResponse(false);
1790 } 1790 }
1791 1791
1792 // Turn a bitmap of the screen into an image, set that image as the result, 1792 // Turn a bitmap of the screen into an image, set that image as the result,
1793 // and call SendResponse(). 1793 // and call SendResponse().
1794 void TabsCaptureVisibleTabFunction::SendResultFromBitmap( 1794 void TabsCaptureVisibleTabFunction::SendResultFromBitmap(
1795 const SkBitmap& screen_capture) { 1795 const SkBitmap& screen_capture) {
1796 std::vector<unsigned char> data; 1796 std::vector<unsigned char> data;
1797 SkAutoLockPixels screen_capture_lock(screen_capture); 1797 SkAutoLockPixels screen_capture_lock(screen_capture);
1798 bool encoded = false; 1798 bool encoded = false;
1799 std::string mime_type; 1799 std::string mime_type;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2154 extension->id(), 2154 extension->id(),
2155 script_type, 2155 script_type,
2156 code_string, 2156 code_string,
2157 frame_scope, 2157 frame_scope,
2158 run_at, 2158 run_at,
2159 ScriptExecutor::ISOLATED_WORLD, 2159 ScriptExecutor::ISOLATED_WORLD,
2160 false /* is_web_view */, 2160 false /* is_web_view */,
2161 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); 2161 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this));
2162 return true; 2162 return true;
2163 } 2163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698