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/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 Loading... | |
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 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1651 | 1652 |
1652 if (options->HasKey(keys::kQualityKey)) { | 1653 if (options->HasKey(keys::kQualityKey)) { |
1653 EXTENSION_FUNCTION_VALIDATE( | 1654 EXTENSION_FUNCTION_VALIDATE( |
1654 options->GetInteger(keys::kQualityKey, &image_quality_)); | 1655 options->GetInteger(keys::kQualityKey, &image_quality_)); |
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_)) { |
1663 error_ = keys::kInternalVisibleTabCaptureError; | |
mazda
2012/05/03 22:24:50
It looks we should not set error here. Adding this
Sam Kerner (Chrome)
2012/05/04 04:29:59
Looks like Extension::CanCaptureVisiblePage(.., &e
| |
1662 return false; | 1664 return false; |
1665 } | |
1663 | 1666 |
1664 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | 1667 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
1668 content::RenderWidgetHostView* view = render_view_host->GetView(); | |
1669 if (!view) { | |
1670 error_ = keys::kInternalVisibleTabCaptureError; | |
1671 return false; | |
1672 } | |
1673 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; | |
1674 render_view_host->AsyncCopyFromBackingStore( | |
1675 gfx::Rect(), | |
1676 view->GetViewBounds().size(), | |
1677 temp_canvas, | |
1678 base::Bind(&CaptureVisibleTabFunction::CopyFromBackingStoreComplete, | |
1679 this, | |
1680 base::Owned(temp_canvas))); | |
1681 return true; | |
1682 } | |
1665 | 1683 |
1666 // If a backing store is cached for the tab we want to capture, | 1684 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete( |
1667 // and it can be copied into a bitmap, then use it to generate the image. | 1685 skia::PlatformCanvas* canvas, |
1668 // For example, some uncommon X11 visual modes are not supported by | 1686 bool succeeded) { |
1669 // CopyFromBackingStore(). | 1687 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."; | 1688 VLOG(1) << "captureVisibleTab() got image from backing store."; |
1674 SendResultFromBitmap(skia::GetTopDevice(temp_canvas)->accessBitmap(false)); | 1689 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false)); |
1675 return true; | 1690 return; |
1691 } | |
1692 | |
1693 WebContents* web_contents = NULL; | |
1694 TabContentsWrapper* wrapper = NULL; | |
1695 if (!GetTabToCapture(&web_contents, &wrapper)) { | |
1696 error_ = keys::kInternalVisibleTabCaptureError; | |
1697 SendResponse(false); | |
1698 return; | |
1676 } | 1699 } |
1677 | 1700 |
1678 // Ask the renderer for a snapshot of the tab. | 1701 // Ask the renderer for a snapshot of the tab. |
1679 wrapper->snapshot_tab_helper()->CaptureSnapshot(); | |
1680 registrar_.Add(this, | 1702 registrar_.Add(this, |
1681 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 1703 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, |
1682 content::Source<WebContents>(wrapper->web_contents())); | 1704 content::Source<WebContents>(web_contents)); |
1683 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). | 1705 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). |
1684 wrapper->snapshot_tab_helper()->CaptureSnapshot(); | 1706 wrapper->snapshot_tab_helper()->CaptureSnapshot(); |
1685 | |
1686 return true; | |
1687 } | 1707 } |
1688 | 1708 |
1689 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, | 1709 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, |
1690 // than the renderer was asked for a snapshot. Listen for a notification | 1710 // than the renderer was asked for a snapshot. Listen for a notification |
1691 // that the snapshot is available. | 1711 // that the snapshot is available. |
1692 void CaptureVisibleTabFunction::Observe( | 1712 void CaptureVisibleTabFunction::Observe( |
1693 int type, | 1713 int type, |
1694 const content::NotificationSource& source, | 1714 const content::NotificationSource& source, |
1695 const content::NotificationDetails& details) { | 1715 const content::NotificationDetails& details) { |
1696 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); | 1716 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1828 // called for every API call the extension made. | 1848 // called for every API call the extension made. |
1829 GotLanguage(language); | 1849 GotLanguage(language); |
1830 } | 1850 } |
1831 | 1851 |
1832 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1852 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1833 result_.reset(Value::CreateStringValue(language.c_str())); | 1853 result_.reset(Value::CreateStringValue(language.c_str())); |
1834 SendResponse(true); | 1854 SendResponse(true); |
1835 | 1855 |
1836 Release(); // Balanced in Run() | 1856 Release(); // Balanced in Run() |
1837 } | 1857 } |
OLD | NEW |