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

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

Issue 12746009: Revert 189969 "Add RenderWidgetHost::GetSnapshotFromRenderer met..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1450/src/
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 | Annotate | Revision Log
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"
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" 49 #include "chrome/browser/ui/tabs/tab_strip_model.h"
49 #include "chrome/browser/ui/window_sizer/window_sizer.h" 50 #include "chrome/browser/ui/window_sizer/window_sizer.h"
50 #include "chrome/browser/web_applications/web_app.h" 51 #include "chrome/browser/web_applications/web_app.h"
51 #include "chrome/common/chrome_notification_types.h" 52 #include "chrome/common/chrome_notification_types.h"
52 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 54 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
54 #include "chrome/common/extensions/api/tabs.h" 55 #include "chrome/common/extensions/api/tabs.h"
55 #include "chrome/common/extensions/api/windows.h" 56 #include "chrome/common/extensions/api/windows.h"
56 #include "chrome/common/extensions/extension.h" 57 #include "chrome/common/extensions/extension.h"
57 #include "chrome/common/extensions/extension_constants.h" 58 #include "chrome/common/extensions/extension_constants.h"
(...skipping 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 bool succeeded, 1745 bool succeeded,
1745 const SkBitmap& bitmap) { 1746 const SkBitmap& bitmap) {
1746 if (succeeded) { 1747 if (succeeded) {
1747 VLOG(1) << "captureVisibleTab() got image from backing store."; 1748 VLOG(1) << "captureVisibleTab() got image from backing store.";
1748 SendResultFromBitmap(bitmap); 1749 SendResultFromBitmap(bitmap);
1749 return; 1750 return;
1750 } 1751 }
1751 1752
1752 WebContents* web_contents = NULL; 1753 WebContents* web_contents = NULL;
1753 if (!GetTabToCapture(&web_contents)) { 1754 if (!GetTabToCapture(&web_contents)) {
1754 SendInternalError(); 1755 error_ = keys::kInternalVisibleTabCaptureError;
1756 SendResponse(false);
1755 return; 1757 return;
1756 } 1758 }
1757 1759
1758 // Ask the renderer for a snapshot of the tab. 1760 // Ask the renderer for a snapshot of the tab.
1759 content::RenderWidgetHost* render_widget_host = 1761 registrar_.Add(this,
1760 web_contents->GetRenderViewHost(); 1762 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
1761 if (!render_widget_host) { 1763 content::Source<WebContents>(web_contents));
1762 SendInternalError(); 1764 AddRef(); // Balanced in TabsCaptureVisibleTabFunction::Observe().
1763 return; 1765 SnapshotTabHelper::FromWebContents(web_contents)->CaptureSnapshot();
1764 }
1765
1766 render_widget_host->GetSnapshotFromRenderer(
1767 gfx::Rect(),
1768 base::Bind(
1769 &TabsCaptureVisibleTabFunction::GetSnapshotFromRendererComplete,
1770 this));
1771 } 1766 }
1772 1767
1773 // If a backing store was not available in 1768 // If a backing store was not available in
1774 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a 1769 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a
1775 // snapshot. 1770 // snapshot. Listen for a notification that the snapshot is available.
1776 void TabsCaptureVisibleTabFunction::GetSnapshotFromRendererComplete( 1771 void TabsCaptureVisibleTabFunction::Observe(
1777 bool succeeded, 1772 int type,
1778 const SkBitmap& bitmap) { 1773 const content::NotificationSource& source,
1779 if (!succeeded) { 1774 const content::NotificationDetails& details) {
1780 SendInternalError(); 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);
1781 } else { 1784 } else {
1782 VLOG(1) << "captureVisibleTab() got image from renderer."; 1785 VLOG(1) << "captureVisibleTab() got image from renderer.";
1783 SendResultFromBitmap(bitmap); 1786 SendResultFromBitmap(*screen_capture);
1784 } 1787 }
1785 }
1786 1788
1787 void TabsCaptureVisibleTabFunction::SendInternalError() { 1789 Release(); // Balanced in TabsCaptureVisibleTabFunction::RunImpl().
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
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.h ('k') | chrome/browser/thumbnails/thumbnail_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698