Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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(); |
|
Sam Kerner (Chrome)
2013/03/18 22:08:46
Indent should be two spaces.
| |
| 1756 SendResponse(false); | 1755 return; |
| 1756 } | |
| 1757 | |
| 1758 // Ask the renderer for a snapshot of the tab. | |
| 1759 content::RenderWidgetHost* render_view_host = | |
| 1760 web_contents->GetRenderViewHost(); | |
| 1761 if (!render_view_host) { | |
| 1762 SendInternalError(); | |
| 1763 return; | |
| 1764 } | |
| 1765 | |
| 1766 content::RenderWidgetHostView* view = render_view_host->GetView(); | |
| 1767 if (!view) { | |
| 1768 SendInternalError(); | |
| 1757 return; | 1769 return; |
| 1758 } | 1770 } |
| 1759 | 1771 |
| 1760 // Ask the renderer for a snapshot of the tab. | 1772 render_view_host->GetSnapshotFromRenderer( |
| 1761 registrar_.Add(this, | 1773 gfx::Rect(), |
| 1762 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 1774 view->GetViewBounds().size(), |
| 1763 content::Source<WebContents>(web_contents)); | 1775 base::Bind( |
| 1764 AddRef(); // Balanced in TabsCaptureVisibleTabFunction::Observe(). | 1776 &TabsCaptureVisibleTabFunction::GetSnapshotFromRendererComplete, |
| 1765 SnapshotTabHelper::FromWebContents(web_contents)->CaptureSnapshot(); | 1777 this)); |
| 1766 } | 1778 } |
| 1767 | 1779 |
| 1768 // If a backing store was not available in | 1780 // If a backing store was not available in |
| 1769 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a | 1781 // TabsCaptureVisibleTabFunction::RunImpl, than the renderer was asked for a |
| 1770 // snapshot. Listen for a notification that the snapshot is available. | 1782 // snapshot. |
| 1771 void TabsCaptureVisibleTabFunction::Observe( | 1783 void TabsCaptureVisibleTabFunction::GetSnapshotFromRendererComplete( |
| 1772 int type, | 1784 bool succeeded, |
| 1773 const content::NotificationSource& source, | 1785 const SkBitmap& bitmap) { |
| 1774 const content::NotificationDetails& details) { | 1786 if (!succeeded) { |
| 1775 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); | 1787 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 { | 1788 } else { |
| 1785 VLOG(1) << "captureVisibleTab() got image from renderer."; | 1789 VLOG(1) << "captureVisibleTab() got image from renderer."; |
| 1786 SendResultFromBitmap(*screen_capture); | 1790 SendResultFromBitmap(bitmap); |
| 1787 } | 1791 } |
| 1792 } | |
| 1788 | 1793 |
| 1789 Release(); // Balanced in TabsCaptureVisibleTabFunction::RunImpl(). | 1794 void TabsCaptureVisibleTabFunction::SendInternalError() { |
| 1795 error_ = keys::kInternalVisibleTabCaptureError; | |
| 1796 SendResponse(false); | |
| 1790 } | 1797 } |
| 1791 | 1798 |
| 1792 // Turn a bitmap of the screen into an image, set that image as the result, | 1799 // Turn a bitmap of the screen into an image, set that image as the result, |
| 1793 // and call SendResponse(). | 1800 // and call SendResponse(). |
| 1794 void TabsCaptureVisibleTabFunction::SendResultFromBitmap( | 1801 void TabsCaptureVisibleTabFunction::SendResultFromBitmap( |
| 1795 const SkBitmap& screen_capture) { | 1802 const SkBitmap& screen_capture) { |
| 1796 std::vector<unsigned char> data; | 1803 std::vector<unsigned char> data; |
| 1797 SkAutoLockPixels screen_capture_lock(screen_capture); | 1804 SkAutoLockPixels screen_capture_lock(screen_capture); |
| 1798 bool encoded = false; | 1805 bool encoded = false; |
| 1799 std::string mime_type; | 1806 std::string mime_type; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2154 extension->id(), | 2161 extension->id(), |
| 2155 script_type, | 2162 script_type, |
| 2156 code_string, | 2163 code_string, |
| 2157 frame_scope, | 2164 frame_scope, |
| 2158 run_at, | 2165 run_at, |
| 2159 ScriptExecutor::ISOLATED_WORLD, | 2166 ScriptExecutor::ISOLATED_WORLD, |
| 2160 false /* is_web_view */, | 2167 false /* is_web_view */, |
| 2161 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); | 2168 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); |
| 2162 return true; | 2169 return true; |
| 2163 } | 2170 } |
| OLD | NEW |