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/web_contents_capture_client.h" | 5 #include "extensions/browser/api/web_contents_capture_client.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" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "extensions/browser/extension_function.h" | 12 #include "extensions/browser/extension_function.h" |
13 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
| 14 #include "ui/display/display.h" |
| 15 #include "ui/display/screen.h" |
14 #include "ui/gfx/codec/jpeg_codec.h" | 16 #include "ui/gfx/codec/jpeg_codec.h" |
15 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
16 #include "ui/gfx/display.h" | |
17 #include "ui/gfx/geometry/size_conversions.h" | 18 #include "ui/gfx/geometry/size_conversions.h" |
18 #include "ui/gfx/screen.h" | |
19 | 19 |
20 using content::RenderWidgetHost; | 20 using content::RenderWidgetHost; |
21 using content::RenderWidgetHostView; | 21 using content::RenderWidgetHostView; |
22 using content::WebContents; | 22 using content::WebContents; |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 using api::extension_types::ImageDetails; | 26 using api::extension_types::ImageDetails; |
27 | 27 |
28 bool WebContentsCaptureClient::CaptureAsync( | 28 bool WebContentsCaptureClient::CaptureAsync( |
(...skipping 28 matching lines...) Expand all Loading... |
57 OnCaptureFailure(FAILURE_REASON_VIEW_INVISIBLE); | 57 OnCaptureFailure(FAILURE_REASON_VIEW_INVISIBLE); |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 // By default, the requested bitmap size is the view size in screen | 61 // By default, the requested bitmap size is the view size in screen |
62 // coordinates. However, if there's more pixel detail available on the | 62 // coordinates. However, if there's more pixel detail available on the |
63 // current system, increase the requested bitmap size to capture it all. | 63 // current system, increase the requested bitmap size to capture it all. |
64 const gfx::Size view_size = view->GetViewBounds().size(); | 64 const gfx::Size view_size = view->GetViewBounds().size(); |
65 gfx::Size bitmap_size = view_size; | 65 gfx::Size bitmap_size = view_size; |
66 const gfx::NativeView native_view = view->GetNativeView(); | 66 const gfx::NativeView native_view = view->GetNativeView(); |
67 gfx::Screen* const screen = gfx::Screen::GetScreen(); | 67 display::Screen* const screen = display::Screen::GetScreen(); |
68 const float scale = | 68 const float scale = |
69 screen->GetDisplayNearestWindow(native_view).device_scale_factor(); | 69 screen->GetDisplayNearestWindow(native_view).device_scale_factor(); |
70 if (scale > 1.0f) | 70 if (scale > 1.0f) |
71 bitmap_size = gfx::ScaleToCeiledSize(view_size, scale); | 71 bitmap_size = gfx::ScaleToCeiledSize(view_size, scale); |
72 | 72 |
73 host->CopyFromBackingStore(gfx::Rect(view_size), bitmap_size, callback, | 73 host->CopyFromBackingStore(gfx::Rect(view_size), bitmap_size, callback, |
74 kN32_SkColorType); | 74 kN32_SkColorType); |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 data.size()); | 134 data.size()); |
135 | 135 |
136 base::Base64Encode(stream_as_string, base64_result); | 136 base::Base64Encode(stream_as_string, base64_result); |
137 base64_result->insert( | 137 base64_result->insert( |
138 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); | 138 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); |
139 | 139 |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
143 } // namespace extensions | 143 } // namespace extensions |
OLD | NEW |