| 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 "chrome/renderer/chrome_render_frame_observer.h" | 5 #include "chrome/renderer/chrome_render_frame_observer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 24 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
| 25 #include "third_party/WebKit/public/web/WebDataSource.h" | 25 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 26 #include "third_party/WebKit/public/web/WebDocument.h" | 26 #include "third_party/WebKit/public/web/WebDocument.h" |
| 27 #include "third_party/WebKit/public/web/WebElement.h" | 27 #include "third_party/WebKit/public/web/WebElement.h" |
| 28 #include "third_party/WebKit/public/web/WebFrame.h" | 28 #include "third_party/WebKit/public/web/WebFrame.h" |
| 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 30 #include "third_party/WebKit/public/web/WebNode.h" | 30 #include "third_party/WebKit/public/web/WebNode.h" |
| 31 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 31 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
| 33 #include "ui/gfx/codec/jpeg_codec.h" | 33 #include "ui/gfx/codec/jpeg_codec.h" |
| 34 #include "ui/gfx/geometry/size_f.h" |
| 34 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 35 | 36 |
| 36 using blink::WebDataSource; | 37 using blink::WebDataSource; |
| 37 using blink::WebElement; | 38 using blink::WebElement; |
| 38 using blink::WebNode; | 39 using blink::WebNode; |
| 39 using content::SSLStatus; | 40 using content::SSLStatus; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 // If the source image is null or occupies less area than | 44 // If the source image is null or occupies less area than |
| 44 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we | 45 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we |
| 45 // scale down the image so that the width and height do not exceed | 46 // scale down the image so that the width and height do not exceed |
| 46 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. | 47 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. |
| 47 SkBitmap Downscale(const blink::WebImage& image, | 48 SkBitmap Downscale(const blink::WebImage& image, |
| 48 int thumbnail_min_area_pixels, | 49 int thumbnail_min_area_pixels, |
| 49 const gfx::Size& thumbnail_max_size_pixels) { | 50 const gfx::Size& thumbnail_max_size_pixels) { |
| 50 if (image.isNull()) | 51 if (image.isNull()) |
| 51 return SkBitmap(); | 52 return SkBitmap(); |
| 52 | 53 |
| 53 gfx::Size image_size = image.size(); | 54 gfx::Size image_size = image.size(); |
| 54 | 55 |
| 55 if (image_size.GetArea() < thumbnail_min_area_pixels) | 56 if (image_size.GetArea() < thumbnail_min_area_pixels) |
| 56 return image.getSkBitmap(); | 57 return image.getSkBitmap(); |
| 57 | 58 |
| 58 if (image_size.width() <= thumbnail_max_size_pixels.width() && | 59 if (image_size.width() <= thumbnail_max_size_pixels.width() && |
| 59 image_size.height() <= thumbnail_max_size_pixels.height()) | 60 image_size.height() <= thumbnail_max_size_pixels.height()) |
| 60 return image.getSkBitmap(); | 61 return image.getSkBitmap(); |
| 61 | 62 |
| 62 gfx::SizeF scaled_size = image_size; | 63 gfx::SizeF scaled_size = gfx::SizeF(image_size); |
| 63 | 64 |
| 64 if (scaled_size.width() > thumbnail_max_size_pixels.width()) { | 65 if (scaled_size.width() > thumbnail_max_size_pixels.width()) { |
| 65 scaled_size.Scale(thumbnail_max_size_pixels.width() / scaled_size.width()); | 66 scaled_size.Scale(thumbnail_max_size_pixels.width() / scaled_size.width()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 if (scaled_size.height() > thumbnail_max_size_pixels.height()) { | 69 if (scaled_size.height() > thumbnail_max_size_pixels.height()) { |
| 69 scaled_size.Scale( | 70 scaled_size.Scale( |
| 70 thumbnail_max_size_pixels.height() / scaled_size.height()); | 71 thumbnail_max_size_pixels.height() / scaled_size.height()); |
| 71 } | 72 } |
| 72 | 73 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 232 |
| 232 Send(new ChromeViewHostMsg_AppBannerPromptReply( | 233 Send(new ChromeViewHostMsg_AppBannerPromptReply( |
| 233 routing_id(), request_id, reply, referrer)); | 234 routing_id(), request_id, reply, referrer)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 void ChromeRenderFrameObserver::OnAppBannerDebugMessageRequest( | 237 void ChromeRenderFrameObserver::OnAppBannerDebugMessageRequest( |
| 237 const std::string& message) { | 238 const std::string& message) { |
| 238 render_frame()->GetWebFrame()->addMessageToConsole(blink::WebConsoleMessage( | 239 render_frame()->GetWebFrame()->addMessageToConsole(blink::WebConsoleMessage( |
| 239 blink::WebConsoleMessage::LevelDebug, base::UTF8ToUTF16(message))); | 240 blink::WebConsoleMessage::LevelDebug, base::UTF8ToUTF16(message))); |
| 240 } | 241 } |
| OLD | NEW |