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/renderer/chrome_render_view_observer.h" | 5 #include "chrome/renderer/chrome_render_view_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT, | 143 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT, |
144 INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT, | 144 INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT, |
145 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL, | 145 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL, |
146 INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL, | 146 INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL, |
147 INSECURE_CONTENT_NUM_EVENTS | 147 INSECURE_CONTENT_NUM_EVENTS |
148 }; | 148 }; |
149 | 149 |
150 // Constants for mixed-content blocking. | 150 // Constants for mixed-content blocking. |
151 static const char kGoogleDotCom[] = "google.com"; | 151 static const char kGoogleDotCom[] = "google.com"; |
152 | 152 |
153 static bool PaintViewIntoCanvas(WebView* view, | |
154 skia::PlatformCanvas& canvas) { | |
155 view->layout(); | |
156 const WebSize& size = view->size(); | |
157 | |
158 if (!canvas.initialize(size.width, size.height, true)) | |
159 return false; | |
160 | |
161 view->paint(webkit_glue::ToWebCanvas(&canvas), | |
162 WebRect(0, 0, size.width, size.height)); | |
163 // TODO: Add a way to snapshot the whole page, not just the currently | |
164 // visible part. | |
165 | |
166 return true; | |
167 } | |
168 | |
169 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { | 153 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { |
170 switch (type) { | 154 switch (type) { |
171 case WebIconURL::TypeFavicon: | 155 case WebIconURL::TypeFavicon: |
172 return FaviconURL::FAVICON; | 156 return FaviconURL::FAVICON; |
173 case WebIconURL::TypeTouch: | 157 case WebIconURL::TypeTouch: |
174 return FaviconURL::TOUCH_ICON; | 158 return FaviconURL::TOUCH_ICON; |
175 case WebIconURL::TypeTouchPrecomposed: | 159 case WebIconURL::TypeTouchPrecomposed: |
176 return FaviconURL::TOUCH_PRECOMPOSED_ICON; | 160 return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
177 case WebIconURL::TypeInvalid: | 161 case WebIconURL::TypeInvalid: |
178 return FaviconURL::INVALID_ICON; | 162 return FaviconURL::INVALID_ICON; |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 if (last_space_index == std::wstring::npos) | 881 if (last_space_index == std::wstring::npos) |
898 return; // don't index if we got a huge block of text with no spaces | 882 return; // don't index if we got a huge block of text with no spaces |
899 contents->resize(last_space_index); | 883 contents->resize(last_space_index); |
900 } | 884 } |
901 } | 885 } |
902 | 886 |
903 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, | 887 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, |
904 SkBitmap* snapshot) { | 888 SkBitmap* snapshot) { |
905 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 889 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
906 | 890 |
907 skia::PlatformCanvas canvas; | 891 view->layout(); |
908 if (!PaintViewIntoCanvas(view, canvas)) | 892 const WebSize& size = view->size(); |
| 893 |
| 894 SkCanvas* canvas = skia::CreatePlatformCanvas(size.width, size.height, true, |
| 895 NULL, skia::RETURN_NULL_ON_FAILURE); |
| 896 if (!canvas) |
909 return false; | 897 return false; |
910 | 898 |
911 SkDevice* device = skia::GetTopDevice(canvas); | 899 SkAutoUnref au(canvas); |
| 900 view->paint(webkit_glue::ToWebCanvas(canvas), |
| 901 WebRect(0, 0, size.width, size.height)); |
| 902 // TODO: Add a way to snapshot the whole page, not just the currently |
| 903 // visible part. |
| 904 |
| 905 SkDevice* device = skia::GetTopDevice(*canvas); |
912 | 906 |
913 const SkBitmap& bitmap = device->accessBitmap(false); | 907 const SkBitmap& bitmap = device->accessBitmap(false); |
914 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) | 908 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
915 return false; | 909 return false; |
916 | 910 |
917 HISTOGRAM_TIMES("Renderer4.Snapshot", | 911 HISTOGRAM_TIMES("Renderer4.Snapshot", |
918 base::TimeTicks::Now() - beginning_time); | 912 base::TimeTicks::Now() - beginning_time); |
919 return true; | 913 return true; |
920 } | 914 } |
921 | 915 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 reinterpret_cast<const unsigned char*>(&data[0]); | 972 reinterpret_cast<const unsigned char*>(&data[0]); |
979 | 973 |
980 return decoder.Decode(src_data, data.size()); | 974 return decoder.Decode(src_data, data.size()); |
981 } | 975 } |
982 return SkBitmap(); | 976 return SkBitmap(); |
983 } | 977 } |
984 | 978 |
985 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 979 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
986 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 980 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
987 } | 981 } |
OLD | NEW |