OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/api/capture_web_contents_function.h" | 5 #include "extensions/browser/api/capture_web_contents_function.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/public/browser/render_widget_host.h" | 9 #include "content/public/browser/render_widget_host.h" |
10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // By default, the requested bitmap size is the view size in screen | 75 // By default, the requested bitmap size is the view size in screen |
76 // coordinates. However, if there's more pixel detail available on the | 76 // coordinates. However, if there's more pixel detail available on the |
77 // current system, increase the requested bitmap size to capture it all. | 77 // current system, increase the requested bitmap size to capture it all. |
78 const gfx::Size view_size = view->GetViewBounds().size(); | 78 const gfx::Size view_size = view->GetViewBounds().size(); |
79 gfx::Size bitmap_size = view_size; | 79 gfx::Size bitmap_size = view_size; |
80 const gfx::NativeView native_view = view->GetNativeView(); | 80 const gfx::NativeView native_view = view->GetNativeView(); |
81 gfx::Screen* const screen = gfx::Screen::GetScreenFor(native_view); | 81 gfx::Screen* const screen = gfx::Screen::GetScreenFor(native_view); |
82 const float scale = | 82 const float scale = |
83 screen->GetDisplayNearestWindow(native_view).device_scale_factor(); | 83 screen->GetDisplayNearestWindow(native_view).device_scale_factor(); |
84 if (scale > 1.0f) | 84 if (scale > 1.0f) |
85 bitmap_size = gfx::ToCeiledSize(gfx::ScaleSize(view_size, scale)); | 85 bitmap_size = gfx::ScaleToCeiledSize(view_size, scale); |
86 | 86 |
87 host->CopyFromBackingStore( | 87 host->CopyFromBackingStore( |
88 gfx::Rect(view_size), | 88 gfx::Rect(view_size), |
89 bitmap_size, | 89 bitmap_size, |
90 base::Bind(&CaptureWebContentsFunction::CopyFromBackingStoreComplete, | 90 base::Bind(&CaptureWebContentsFunction::CopyFromBackingStoreComplete, |
91 this), | 91 this), |
92 kN32_SkColorType); | 92 kN32_SkColorType); |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 141 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
142 | 142 |
143 base::Base64Encode(stream_as_string, &base64_result); | 143 base::Base64Encode(stream_as_string, &base64_result); |
144 base64_result.insert( | 144 base64_result.insert( |
145 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); | 145 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); |
146 SetResult(new base::StringValue(base64_result)); | 146 SetResult(new base::StringValue(base64_result)); |
147 SendResponse(true); | 147 SendResponse(true); |
148 } | 148 } |
149 | 149 |
150 } // namespace extensions | 150 } // namespace extensions |
OLD | NEW |