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/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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_)) |
| 1662 return false; | 1663 return false; |
| 1663 | 1664 |
| 1664 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | 1665 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
| 1666 content::RenderWidgetHostView* view = render_view_host->GetView(); | |
| 1667 if (!view) | |
| 1668 return false; | |
|
Mihai Parparita -not on Chrome
2012/05/03 16:27:30
This should also populate error_ with an error.
mazda
2012/05/03 16:51:53
Done.
Also added code to populate error_ to the re
| |
| 1669 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; | |
| 1670 render_view_host->AsyncCopyFromBackingStore( | |
| 1671 gfx::Rect(), | |
| 1672 view->GetViewBounds().size(), | |
| 1673 temp_canvas, | |
| 1674 base::Bind(&CaptureVisibleTabFunction::CopyFromBackingStoreComplete, | |
| 1675 this, | |
| 1676 base::Owned(temp_canvas))); | |
| 1677 return true; | |
| 1678 } | |
| 1665 | 1679 |
| 1666 // If a backing store is cached for the tab we want to capture, | 1680 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete( |
| 1667 // and it can be copied into a bitmap, then use it to generate the image. | 1681 skia::PlatformCanvas* canvas, |
| 1668 // For example, some uncommon X11 visual modes are not supported by | 1682 bool succeeded) { |
| 1669 // CopyFromBackingStore(). | 1683 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."; | 1684 VLOG(1) << "captureVisibleTab() got image from backing store."; |
| 1674 SendResultFromBitmap(skia::GetTopDevice(temp_canvas)->accessBitmap(false)); | 1685 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false)); |
| 1675 return true; | 1686 return; |
| 1687 } | |
| 1688 | |
| 1689 WebContents* web_contents = NULL; | |
| 1690 TabContentsWrapper* wrapper = NULL; | |
| 1691 if (!GetTabToCapture(&web_contents, &wrapper)) { | |
| 1692 error_ = keys::kInternalVisibleTabCaptureError; | |
| 1693 return; | |
|
Mihai Parparita -not on Chrome
2012/05/03 16:27:30
This also needs a SendResponse(false) call.
mazda
2012/05/03 16:51:53
Done.
| |
| 1676 } | 1694 } |
| 1677 | 1695 |
| 1678 // Ask the renderer for a snapshot of the tab. | 1696 // Ask the renderer for a snapshot of the tab. |
| 1679 wrapper->snapshot_tab_helper()->CaptureSnapshot(); | |
| 1680 registrar_.Add(this, | 1697 registrar_.Add(this, |
| 1681 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 1698 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, |
| 1682 content::Source<WebContents>(wrapper->web_contents())); | 1699 content::Source<WebContents>(web_contents)); |
| 1683 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). | 1700 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). |
| 1684 wrapper->snapshot_tab_helper()->CaptureSnapshot(); | 1701 wrapper->snapshot_tab_helper()->CaptureSnapshot(); |
| 1685 | 1702 return; |
|
Mihai Parparita -not on Chrome
2012/05/03 16:27:30
This can be removed.
mazda
2012/05/03 16:51:53
Done.
| |
| 1686 return true; | |
| 1687 } | 1703 } |
| 1688 | 1704 |
| 1689 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, | 1705 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, |
| 1690 // than the renderer was asked for a snapshot. Listen for a notification | 1706 // than the renderer was asked for a snapshot. Listen for a notification |
| 1691 // that the snapshot is available. | 1707 // that the snapshot is available. |
| 1692 void CaptureVisibleTabFunction::Observe( | 1708 void CaptureVisibleTabFunction::Observe( |
| 1693 int type, | 1709 int type, |
| 1694 const content::NotificationSource& source, | 1710 const content::NotificationSource& source, |
| 1695 const content::NotificationDetails& details) { | 1711 const content::NotificationDetails& details) { |
| 1696 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); | 1712 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. | 1844 // called for every API call the extension made. |
| 1829 GotLanguage(language); | 1845 GotLanguage(language); |
| 1830 } | 1846 } |
| 1831 | 1847 |
| 1832 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1848 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1833 result_.reset(Value::CreateStringValue(language.c_str())); | 1849 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1834 SendResponse(true); | 1850 SendResponse(true); |
| 1835 | 1851 |
| 1836 Release(); // Balanced in Run() | 1852 Release(); // Balanced in Run() |
| 1837 } | 1853 } |
| OLD | NEW |