OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/icon_messages.h" | 12 #include "chrome/common/icon_messages.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/common/thumbnail_score.h" | 14 #include "chrome/common/thumbnail_score.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "chrome/renderer/about_handler.h" | 16 #include "chrome/renderer/about_handler.h" |
17 #include "chrome/renderer/content_settings_observer.h" | 17 #include "chrome/renderer/content_settings_observer.h" |
18 #include "chrome/renderer/automation/dom_automation_controller.h" | 18 #include "chrome/renderer/automation/dom_automation_controller.h" |
19 #include "chrome/renderer/extensions/extension_dispatcher.h" | 19 #include "chrome/renderer/extensions/extension_dispatcher.h" |
20 #include "chrome/renderer/external_host_bindings.h" | 20 #include "chrome/renderer/external_host_bindings.h" |
21 #include "chrome/renderer/prerender/prerender_helper.h" | 21 #include "chrome/renderer/prerender/prerender_helper.h" |
22 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 22 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
23 #include "chrome/renderer/translate_helper.h" | 23 #include "chrome/renderer/translate_helper.h" |
24 #include "content/common/bindings_policy.h" | 24 #include "content/common/bindings_policy.h" |
25 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
26 #include "content/renderer/content_renderer_client.h" | 26 #include "content/renderer/content_renderer_client.h" |
27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
28 #include "net/base/data_url.h" | 28 #include "net/base/data_url.h" |
29 #include "skia/ext/bitmap_platform_device.h" | |
30 #include "skia/ext/image_operations.h" | 29 #include "skia/ext/image_operations.h" |
31 #include "skia/ext/platform_canvas.h" | 30 #include "skia/ext/platform_canvas.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 SkBitmap* thumbnail, | 587 SkBitmap* thumbnail, |
589 ThumbnailScore* score) { | 588 ThumbnailScore* score) { |
590 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 589 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
591 | 590 |
592 skia::PlatformCanvas canvas; | 591 skia::PlatformCanvas canvas; |
593 | 592 |
594 // Paint |view| into |canvas|. | 593 // Paint |view| into |canvas|. |
595 if (!PaintViewIntoCanvas(view, canvas)) | 594 if (!PaintViewIntoCanvas(view, canvas)) |
596 return false; | 595 return false; |
597 | 596 |
598 skia::BitmapPlatformDevice& device = | 597 SkDevice* device = skia::GetTopDevice(canvas); |
599 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); | |
600 | 598 |
601 const SkBitmap& src_bmp = device.accessBitmap(false); | 599 const SkBitmap& src_bmp = device->accessBitmap(false); |
602 | 600 |
603 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; | 601 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
604 float dest_aspect = dest_rect.width() / dest_rect.height(); | 602 float dest_aspect = dest_rect.width() / dest_rect.height(); |
605 | 603 |
606 // Get the src rect so that we can preserve the aspect ratio while filling | 604 // Get the src rect so that we can preserve the aspect ratio while filling |
607 // the destination. | 605 // the destination. |
608 SkIRect src_rect; | 606 SkIRect src_rect; |
609 if (src_bmp.width() < dest_rect.width() || | 607 if (src_bmp.width() < dest_rect.width() || |
610 src_bmp.height() < dest_rect.height()) { | 608 src_bmp.height() < dest_rect.height()) { |
611 // Source image is smaller: we clip the part of source image within the | 609 // Source image is smaller: we clip the part of source image within the |
(...skipping 14 matching lines...) Expand all Loading... |
626 } else { | 624 } else { |
627 src_rect.set(0, 0, src_bmp.width(), | 625 src_rect.set(0, 0, src_bmp.width(), |
628 static_cast<S16CPU>(src_bmp.width() / dest_aspect)); | 626 static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
629 score->good_clipping = true; | 627 score->good_clipping = true; |
630 } | 628 } |
631 } | 629 } |
632 | 630 |
633 score->at_top = (view->mainFrame()->scrollOffset().height == 0); | 631 score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
634 | 632 |
635 SkBitmap subset; | 633 SkBitmap subset; |
636 device.accessBitmap(false).extractSubset(&subset, src_rect); | 634 device->accessBitmap(false).extractSubset(&subset, src_rect); |
637 | 635 |
638 // First do a fast downsample by powers of two to get close to the final size. | 636 // First do a fast downsample by powers of two to get close to the final size. |
639 SkBitmap downsampled_subset = | 637 SkBitmap downsampled_subset = |
640 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h); | 638 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h); |
641 | 639 |
642 // Do a high-quality resize from the downscaled size to the final size. | 640 // Do a high-quality resize from the downscaled size to the final size. |
643 *thumbnail = skia::ImageOperations::Resize( | 641 *thumbnail = skia::ImageOperations::Resize( |
644 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); | 642 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
645 | 643 |
646 score->boring_score = CalculateBoringScore(thumbnail); | 644 score->boring_score = CalculateBoringScore(thumbnail); |
647 | 645 |
648 HISTOGRAM_TIMES("Renderer4.Thumbnail", | 646 HISTOGRAM_TIMES("Renderer4.Thumbnail", |
649 base::TimeTicks::Now() - beginning_time); | 647 base::TimeTicks::Now() - beginning_time); |
650 | 648 |
651 return true; | 649 return true; |
652 } | 650 } |
653 | 651 |
654 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, | 652 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, |
655 SkBitmap* snapshot) { | 653 SkBitmap* snapshot) { |
656 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 654 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
657 | 655 |
658 skia::PlatformCanvas canvas; | 656 skia::PlatformCanvas canvas; |
659 if (!PaintViewIntoCanvas(view, canvas)) | 657 if (!PaintViewIntoCanvas(view, canvas)) |
660 return false; | 658 return false; |
661 | 659 |
662 skia::BitmapPlatformDevice& device = | 660 SkDevice* device = skia::GetTopDevice(canvas); |
663 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); | |
664 | 661 |
665 const SkBitmap& bitmap = device.accessBitmap(false); | 662 const SkBitmap& bitmap = device->accessBitmap(false); |
666 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) | 663 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
667 return false; | 664 return false; |
668 | 665 |
669 HISTOGRAM_TIMES("Renderer4.Snapshot", | 666 HISTOGRAM_TIMES("Renderer4.Snapshot", |
670 base::TimeTicks::Now() - beginning_time); | 667 base::TimeTicks::Now() - beginning_time); |
671 return true; | 668 return true; |
672 } | 669 } |
673 | 670 |
674 void ChromeRenderViewObserver::BindDOMAutomationController(WebFrame* frame) { | 671 void ChromeRenderViewObserver::BindDOMAutomationController(WebFrame* frame) { |
675 if (!dom_automation_controller_.get()) { | 672 if (!dom_automation_controller_.get()) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 726 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
730 // Decode the favicon using WebKit's image decoder. | 727 // Decode the favicon using WebKit's image decoder. |
731 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); | 728 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); |
732 const unsigned char* src_data = | 729 const unsigned char* src_data = |
733 reinterpret_cast<const unsigned char*>(&data[0]); | 730 reinterpret_cast<const unsigned char*>(&data[0]); |
734 | 731 |
735 return decoder.Decode(src_data, data.size()); | 732 return decoder.Decode(src_data, data.size()); |
736 } | 733 } |
737 return SkBitmap(); | 734 return SkBitmap(); |
738 } | 735 } |
OLD | NEW |