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_HANDLER(ChromeViewMsg_AppBannerDebugMessageRequest, | 106 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerDebugMessageRequest, |
104 OnAppBannerDebugMessageRequest) | 107 OnAppBannerDebugMessageRequest) |
105 IPC_MESSAGE_UNHANDLED(handled = false) | 108 IPC_MESSAGE_UNHANDLED(handled = false) |
106 IPC_END_MESSAGE_MAP() | 109 IPC_END_MESSAGE_MAP() |
107 | 110 |
108 return handled; | 111 return handled; |
109 } | 112 } |
110 | 113 |
111 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { | 114 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { |
112 if (is_prerendering) { | 115 if (is_prerendering) { |
113 // If the PrerenderHelper for this frame already exists, don't create it. It | 116 // If the PrerenderHelper for this frame already exists, don't create it. It |
114 // can already be created for subframes during handling of | 117 // can already be created for subframes during handling of |
115 // RenderFrameCreated, if the parent frame was prerendering at time of | 118 // RenderFrameCreated, if the parent frame was prerendering at time of |
116 // subframe creation. | 119 // subframe creation. |
117 if (prerender::PrerenderHelper::Get(render_frame())) | 120 if (prerender::PrerenderHelper::Get(render_frame())) |
118 return; | 121 return; |
119 | 122 |
120 // The PrerenderHelper will destroy itself either after recording histograms | 123 // The PrerenderHelper will destroy itself either after recording histograms |
121 // or on destruction of the RenderView. | 124 // or on destruction of the RenderView. |
122 new prerender::PrerenderHelper(render_frame()); | 125 new prerender::PrerenderHelper(render_frame()); |
123 } | 126 } |
124 } | 127 } |
125 | 128 |
| 129 void ChromeRenderFrameObserver::OnRequestReloadImageForContextNode() { |
| 130 WebNode context_node = render_frame()->GetContextMenuNode(); |
| 131 if (!context_node.isNull() && context_node.isElementNode() && |
| 132 render_frame()->GetWebFrame()) { |
| 133 render_frame()->GetWebFrame()->reloadImage(context_node); |
| 134 } |
| 135 } |
| 136 |
126 void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( | 137 void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( |
127 int thumbnail_min_area_pixels, | 138 int thumbnail_min_area_pixels, |
128 const gfx::Size& thumbnail_max_size_pixels) { | 139 const gfx::Size& thumbnail_max_size_pixels) { |
129 WebNode context_node = render_frame()->GetContextMenuNode(); | 140 WebNode context_node = render_frame()->GetContextMenuNode(); |
130 SkBitmap thumbnail; | 141 SkBitmap thumbnail; |
131 gfx::Size original_size; | 142 gfx::Size original_size; |
132 if (!context_node.isNull() && context_node.isElementNode()) { | 143 if (!context_node.isNull() && context_node.isElementNode()) { |
133 blink::WebImage image = context_node.to<WebElement>().imageContents(); | 144 blink::WebImage image = context_node.to<WebElement>().imageContents(); |
134 original_size = image.size(); | 145 original_size = image.size(); |
135 thumbnail = Downscale(image, | 146 thumbnail = Downscale(image, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 220 |
210 Send(new ChromeViewHostMsg_AppBannerPromptReply( | 221 Send(new ChromeViewHostMsg_AppBannerPromptReply( |
211 routing_id(), request_id, reply)); | 222 routing_id(), request_id, reply)); |
212 } | 223 } |
213 | 224 |
214 void ChromeRenderFrameObserver::OnAppBannerDebugMessageRequest( | 225 void ChromeRenderFrameObserver::OnAppBannerDebugMessageRequest( |
215 const std::string& message) { | 226 const std::string& message) { |
216 render_frame()->GetWebFrame()->addMessageToConsole(blink::WebConsoleMessage( | 227 render_frame()->GetWebFrame()->addMessageToConsole(blink::WebConsoleMessage( |
217 blink::WebConsoleMessage::LevelDebug, base::UTF8ToUTF16(message))); | 228 blink::WebConsoleMessage::LevelDebug, base::UTF8ToUTF16(message))); |
218 } | 229 } |
OLD | NEW |