| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/prerender_messages.h" | 14 #include "chrome/common/prerender_messages.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/renderer/prerender/prerender_helper.h" | 16 #include "chrome/renderer/prerender/prerender_helper.h" |
| 17 #include "components/printing/common/print_messages.h" | 17 #include "components/printing/common/print_messages.h" |
| 18 #include "components/printing/renderer/print_web_view_helper.h" | 18 #include "components/printing/renderer/print_web_view_helper.h" |
| 19 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
| 20 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
| 21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 #include "skia/ext/image_operations.h" | 22 #include "skia/ext/image_operations.h" |
| 23 #include "third_party/WebKit/public/platform/WebImage.h" | 23 #include "third_party/WebKit/public/platform/WebImage.h" |
| 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/WebElement.h" | 26 #include "third_party/WebKit/public/web/WebElement.h" |
| 27 #include "third_party/WebKit/public/web/WebFrame.h" | 27 #include "third_party/WebKit/public/web/WebFrame.h" |
| 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 29 #include "third_party/WebKit/public/web/WebNode.h" | 29 #include "third_party/WebKit/public/web/WebNode.h" |
| 30 #include "third_party/WebKit/public/web/WebView.h" |
| 30 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 31 #include "ui/gfx/codec/jpeg_codec.h" | 32 #include "ui/gfx/codec/jpeg_codec.h" |
| 32 | 33 |
| 33 using blink::WebDataSource; | 34 using blink::WebDataSource; |
| 34 using blink::WebElement; | 35 using blink::WebElement; |
| 35 using blink::WebNode; | 36 using blink::WebNode; |
| 36 using content::SSLStatus; | 37 using content::SSLStatus; |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Filter only. | 88 // Filter only. |
| 88 bool handled = true; | 89 bool handled = true; |
| 89 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) | 90 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) |
| 90 IPC_MESSAGE_HANDLER(PrerenderMsg_SetIsPrerendering, OnSetIsPrerendering) | 91 IPC_MESSAGE_HANDLER(PrerenderMsg_SetIsPrerendering, OnSetIsPrerendering) |
| 91 IPC_MESSAGE_UNHANDLED(handled = false) | 92 IPC_MESSAGE_UNHANDLED(handled = false) |
| 92 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
| 93 if (handled) | 94 if (handled) |
| 94 return false; | 95 return false; |
| 95 | 96 |
| 96 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) | 97 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) |
| 98 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, |
| 99 OnRequestReloadImageForContextNode) |
| 97 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, | 100 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, |
| 98 OnRequestThumbnailForContextNode) | 101 OnRequestThumbnailForContextNode) |
| 99 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, | 102 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, |
| 100 OnPrintNodeUnderContextMenu) | 103 OnPrintNodeUnderContextMenu) |
| 101 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerPromptRequest, | 104 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerPromptRequest, |
| 102 OnAppBannerPromptRequest) | 105 OnAppBannerPromptRequest) |
| 103 IPC_MESSAGE_UNHANDLED(handled = false) | 106 IPC_MESSAGE_UNHANDLED(handled = false) |
| 104 IPC_END_MESSAGE_MAP() | 107 IPC_END_MESSAGE_MAP() |
| 105 | 108 |
| 106 return handled; | 109 return handled; |
| 107 } | 110 } |
| 108 | 111 |
| 109 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { | 112 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { |
| 110 if (is_prerendering) { | 113 if (is_prerendering) { |
| 111 // If the PrerenderHelper for this frame already exists, don't create it. It | 114 // If the PrerenderHelper for this frame already exists, don't create it. It |
| 112 // can already be created for subframes during handling of | 115 // can already be created for subframes during handling of |
| 113 // RenderFrameCreated, if the parent frame was prerendering at time of | 116 // RenderFrameCreated, if the parent frame was prerendering at time of |
| 114 // subframe creation. | 117 // subframe creation. |
| 115 if (prerender::PrerenderHelper::Get(render_frame())) | 118 if (prerender::PrerenderHelper::Get(render_frame())) |
| 116 return; | 119 return; |
| 117 | 120 |
| 118 // The PrerenderHelper will destroy itself either after recording histograms | 121 // The PrerenderHelper will destroy itself either after recording histograms |
| 119 // or on destruction of the RenderView. | 122 // or on destruction of the RenderView. |
| 120 new prerender::PrerenderHelper(render_frame()); | 123 new prerender::PrerenderHelper(render_frame()); |
| 121 } | 124 } |
| 122 } | 125 } |
| 123 | 126 |
| 127 void ChromeRenderFrameObserver::OnRequestReloadImageForContextNode() { |
| 128 WebNode context_node = render_frame()->GetContextMenuNode(); |
| 129 if (!context_node.isNull() && context_node.isElementNode() && |
| 130 render_frame()->GetWebFrame()) { |
| 131 render_frame()->GetWebFrame()->reloadImage(context_node); |
| 132 } |
| 133 } |
| 134 |
| 124 void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( | 135 void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( |
| 125 int thumbnail_min_area_pixels, | 136 int thumbnail_min_area_pixels, |
| 126 const gfx::Size& thumbnail_max_size_pixels) { | 137 const gfx::Size& thumbnail_max_size_pixels) { |
| 127 WebNode context_node = render_frame()->GetContextMenuNode(); | 138 WebNode context_node = render_frame()->GetContextMenuNode(); |
| 128 SkBitmap thumbnail; | 139 SkBitmap thumbnail; |
| 129 gfx::Size original_size; | 140 gfx::Size original_size; |
| 130 if (!context_node.isNull() && context_node.isElementNode()) { | 141 if (!context_node.isNull() && context_node.isElementNode()) { |
| 131 blink::WebImage image = context_node.to<WebElement>().imageContents(); | 142 blink::WebImage image = context_node.to<WebElement>().imageContents(); |
| 132 original_size = image.size(); | 143 original_size = image.size(); |
| 133 thumbnail = Downscale(image, | 144 thumbnail = Downscale(image, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 int request_id, const std::string& platform) { | 209 int request_id, const std::string& platform) { |
| 199 blink::WebAppBannerPromptReply reply = blink::WebAppBannerPromptReply::None; | 210 blink::WebAppBannerPromptReply reply = blink::WebAppBannerPromptReply::None; |
| 200 blink::WebString web_platform(base::UTF8ToUTF16(platform)); | 211 blink::WebString web_platform(base::UTF8ToUTF16(platform)); |
| 201 blink::WebVector<blink::WebString> web_platforms(&web_platform, 1); | 212 blink::WebVector<blink::WebString> web_platforms(&web_platform, 1); |
| 202 render_frame()->GetWebFrame()->willShowInstallBannerPrompt( | 213 render_frame()->GetWebFrame()->willShowInstallBannerPrompt( |
| 203 web_platforms, &reply); | 214 web_platforms, &reply); |
| 204 | 215 |
| 205 Send(new ChromeViewHostMsg_AppBannerPromptReply( | 216 Send(new ChromeViewHostMsg_AppBannerPromptReply( |
| 206 routing_id(), request_id, reply)); | 217 routing_id(), request_id, reply)); |
| 207 } | 218 } |
| OLD | NEW |