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

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 2819050: Deal with alpha values when building PNG in chrome.tabs.captureVisibleTab(). (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Rerebase. Created 10 years, 5 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/tabs/capture_visible_tab/red.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 // For example, some uncommon X11 visual modes are not supported by 882 // For example, some uncommon X11 visual modes are not supported by
883 // CopyFromBackingStore(). 883 // CopyFromBackingStore().
884 bool CaptureVisibleTabFunction::CaptureSnapshotFromBackingStore( 884 bool CaptureVisibleTabFunction::CaptureSnapshotFromBackingStore(
885 BackingStore* backing_store) { 885 BackingStore* backing_store) {
886 886
887 skia::PlatformCanvas temp_canvas; 887 skia::PlatformCanvas temp_canvas;
888 if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store->size()), 888 if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store->size()),
889 &temp_canvas)) { 889 &temp_canvas)) {
890 return false; 890 return false;
891 } 891 }
892 LOG(INFO) << "captureVisibleTab() Got image from backing store.";
893
892 SendResultFromBitmap( 894 SendResultFromBitmap(
893 temp_canvas.getTopPlatformDevice().accessBitmap(false)); 895 temp_canvas.getTopPlatformDevice().accessBitmap(false));
894 return true; 896 return true;
895 } 897 }
896 898
897 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, 899 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl,
898 // than the renderer was asked for a snapshot. Listen for a notification 900 // than the renderer was asked for a snapshot. Listen for a notification
899 // that the snapshot is available. 901 // that the snapshot is available.
900 void CaptureVisibleTabFunction::Observe(NotificationType type, 902 void CaptureVisibleTabFunction::Observe(NotificationType type,
901 const NotificationSource& source, 903 const NotificationSource& source,
902 const NotificationDetails& details) { 904 const NotificationDetails& details) {
903 DCHECK(type == NotificationType::TAB_SNAPSHOT_TAKEN); 905 DCHECK(type == NotificationType::TAB_SNAPSHOT_TAKEN);
904 906
905 const SkBitmap *screen_capture = Details<const SkBitmap>(details).ptr(); 907 const SkBitmap *screen_capture = Details<const SkBitmap>(details).ptr();
906 const bool error = screen_capture->empty(); 908 const bool error = screen_capture->empty();
907 909
908 if (error) { 910 if (error) {
909 error_ = keys::kInternalVisibleTabCaptureError; 911 error_ = keys::kInternalVisibleTabCaptureError;
910 SendResponse(false); 912 SendResponse(false);
911 } else { 913 } else {
914 LOG(INFO) << "captureVisibleTab() Got image from renderer.";
912 SendResultFromBitmap(*screen_capture); 915 SendResultFromBitmap(*screen_capture);
913 } 916 }
914 917
915 Release(); // Balanced in CaptureVisibleTabFunction::RunImpl(). 918 Release(); // Balanced in CaptureVisibleTabFunction::RunImpl().
916 } 919 }
917 920
918 // Turn a bitmap of the screen into an image, set that image as the result, 921 // Turn a bitmap of the screen into an image, set that image as the result,
919 // and call SendResponse(). 922 // and call SendResponse().
920 void CaptureVisibleTabFunction::SendResultFromBitmap( 923 void CaptureVisibleTabFunction::SendResultFromBitmap(
921 const SkBitmap& screen_capture) { 924 const SkBitmap& screen_capture) {
922 scoped_refptr<RefCountedBytes> image_data(new RefCountedBytes); 925 scoped_refptr<RefCountedBytes> image_data(new RefCountedBytes);
923 SkAutoLockPixels screen_capture_lock(screen_capture); 926 SkAutoLockPixels screen_capture_lock(screen_capture);
924 bool encoded = false; 927 bool encoded = false;
925 std::string mime_type; 928 std::string mime_type;
926 switch (image_format_) { 929 switch (image_format_) {
927 case FORMAT_JPEG: 930 case FORMAT_JPEG:
928 encoded = gfx::JPEGCodec::Encode( 931 encoded = gfx::JPEGCodec::Encode(
929 reinterpret_cast<unsigned char*>(screen_capture.getAddr32(0, 0)), 932 reinterpret_cast<unsigned char*>(screen_capture.getAddr32(0, 0)),
930 gfx::JPEGCodec::FORMAT_BGRA, 933 gfx::JPEGCodec::FORMAT_BGRA,
931 screen_capture.width(), 934 screen_capture.width(),
932 screen_capture.height(), 935 screen_capture.height(),
933 static_cast<int>(screen_capture.rowBytes()), image_quality_, 936 static_cast<int>(screen_capture.rowBytes()),
937 image_quality_,
934 &image_data->data); 938 &image_data->data);
935 mime_type = keys::kMimeTypeJpeg; 939 mime_type = keys::kMimeTypeJpeg;
936 break; 940 break;
937 case FORMAT_PNG: 941 case FORMAT_PNG:
938 encoded = gfx::PNGCodec::Encode( 942 encoded = gfx::PNGCodec::EncodeBGRASkBitmap(
939 reinterpret_cast<unsigned char*>(screen_capture.getAddr32(0, 0)), 943 screen_capture,
940 gfx::PNGCodec::FORMAT_BGRA, 944 true, // Discard transparency.
941 screen_capture.width(),
942 screen_capture.height(),
943 static_cast<int>(screen_capture.rowBytes()), false,
944 &image_data->data); 945 &image_data->data);
945 mime_type = keys::kMimeTypePng; 946 mime_type = keys::kMimeTypePng;
946 break; 947 break;
947 default: 948 default:
948 NOTREACHED() << "Invalid image format."; 949 NOTREACHED() << "Invalid image format.";
949 } 950 }
950 951
951 if (!encoded) { 952 if (!encoded) {
952 error_ = ExtensionErrorUtils::FormatErrorMessage( 953 error_ = ExtensionErrorUtils::FormatErrorMessage(
953 keys::kInternalVisibleTabCaptureError, ""); 954 keys::kInternalVisibleTabCaptureError, "");
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1095 }
1095 1096
1096 static GURL ResolvePossiblyRelativeURL(std::string url_string, 1097 static GURL ResolvePossiblyRelativeURL(std::string url_string,
1097 Extension* extension) { 1098 Extension* extension) {
1098 GURL url = GURL(url_string); 1099 GURL url = GURL(url_string);
1099 if (!url.is_valid()) 1100 if (!url.is_valid())
1100 url = extension->GetResourceURL(url_string); 1101 url = extension->GetResourceURL(url_string);
1101 1102
1102 return url; 1103 return url;
1103 } 1104 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/tabs/capture_visible_tab/red.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698