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