Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } // namespace | 109 } // namespace |
| 110 | 110 |
| 111 ChromeRenderFrameObserver::ChromeRenderFrameObserver( | 111 ChromeRenderFrameObserver::ChromeRenderFrameObserver( |
| 112 content::RenderFrame* render_frame) | 112 content::RenderFrame* render_frame) |
| 113 : content::RenderFrameObserver(render_frame), | 113 : content::RenderFrameObserver(render_frame), |
| 114 translate_helper_(nullptr), | 114 translate_helper_(nullptr), |
| 115 phishing_classifier_(nullptr) { | 115 phishing_classifier_(nullptr) { |
| 116 render_frame->GetInterfaceRegistry()->AddInterface( | 116 render_frame->GetInterfaceRegistry()->AddInterface( |
| 117 base::Bind(&ChromeRenderFrameObserver::OnImageContextMenuRendererRequest, | 117 base::Bind(&ChromeRenderFrameObserver::OnImageContextMenuRendererRequest, |
| 118 base::Unretained(this))); | 118 base::Unretained(this))); |
| 119 render_frame->GetInterfaceRegistry()->AddInterface( | |
| 120 base::Bind(&ChromeRenderFrameObserver::OnThumbnailCapturerRequest, | |
| 121 base::Unretained(this))); | |
| 119 | 122 |
| 120 // Don't do anything else for subframes. | 123 // Don't do anything else for subframes. |
| 121 if (!render_frame->IsMainFrame()) | 124 if (!render_frame->IsMainFrame()) |
| 122 return; | 125 return; |
| 123 | 126 |
| 124 const base::CommandLine& command_line = | 127 const base::CommandLine& command_line = |
| 125 *base::CommandLine::ForCurrentProcess(); | 128 *base::CommandLine::ForCurrentProcess(); |
| 126 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) | 129 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) |
| 127 OnSetClientSidePhishingDetection(true); | 130 OnSetClientSidePhishingDetection(true); |
| 128 translate_helper_ = new translate::TranslateHelper( | 131 translate_helper_ = new translate::TranslateHelper( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 142 IPC_END_MESSAGE_MAP() | 145 IPC_END_MESSAGE_MAP() |
| 143 if (handled) | 146 if (handled) |
| 144 return false; | 147 return false; |
| 145 | 148 |
| 146 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) | 149 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) |
| 147 // TODO(nigeltao): delete the | 150 // TODO(nigeltao): delete the |
| 148 // ChromeViewMsg_RequestReloadImageForContextNode handler when | 151 // ChromeViewMsg_RequestReloadImageForContextNode handler when |
| 149 // tab_android.cc's use is converted to Mojo. | 152 // tab_android.cc's use is converted to Mojo. |
| 150 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, | 153 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, |
| 151 RequestReloadImageForContextNode) | 154 RequestReloadImageForContextNode) |
| 152 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, | |
| 153 OnRequestThumbnailForContextNode) | |
| 154 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 155 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
| 155 OnSetClientSidePhishingDetection) | 156 OnSetClientSidePhishingDetection) |
| 156 #if BUILDFLAG(ENABLE_PRINTING) | 157 #if BUILDFLAG(ENABLE_PRINTING) |
| 157 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, | 158 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, |
| 158 OnPrintNodeUnderContextMenu) | 159 OnPrintNodeUnderContextMenu) |
| 159 #endif | 160 #endif |
| 160 IPC_MESSAGE_UNHANDLED(handled = false) | 161 IPC_MESSAGE_UNHANDLED(handled = false) |
| 161 IPC_END_MESSAGE_MAP() | 162 IPC_END_MESSAGE_MAP() |
| 162 | 163 |
| 163 return handled; | 164 return handled; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 182 void ChromeRenderFrameObserver::RequestReloadImageForContextNode() { | 183 void ChromeRenderFrameObserver::RequestReloadImageForContextNode() { |
| 183 WebLocalFrame* frame = render_frame()->GetWebFrame(); | 184 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 184 // TODO(dglazkov): This code is clearly in the wrong place. Need | 185 // TODO(dglazkov): This code is clearly in the wrong place. Need |
| 185 // to investigate what it is doing and fix (http://crbug.com/606164). | 186 // to investigate what it is doing and fix (http://crbug.com/606164). |
| 186 WebNode context_node = frame->contextMenuNode(); | 187 WebNode context_node = frame->contextMenuNode(); |
| 187 if (!context_node.isNull() && context_node.isElementNode()) { | 188 if (!context_node.isNull() && context_node.isElementNode()) { |
| 188 frame->reloadImage(context_node); | 189 frame->reloadImage(context_node); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( | 193 void ChromeRenderFrameObserver::RequestThumbnailForContextNode( |
| 193 int thumbnail_min_area_pixels, | 194 int32_t thumbnail_min_area_pixels, |
| 194 const gfx::Size& thumbnail_max_size_pixels, | 195 const gfx::Size& thumbnail_max_size_pixels, |
| 195 int callback_id) { | 196 const RequestThumbnailForContextNodeCallback& callback) { |
| 196 WebNode context_node = render_frame()->GetWebFrame()->contextMenuNode(); | 197 WebNode context_node = render_frame()->GetWebFrame()->contextMenuNode(); |
| 197 SkBitmap thumbnail; | 198 SkBitmap thumbnail; |
| 198 gfx::Size original_size; | 199 gfx::Size original_size; |
| 199 if (!context_node.isNull() && context_node.isElementNode()) { | 200 if (!context_node.isNull() && context_node.isElementNode()) { |
| 200 blink::WebImage image = context_node.to<WebElement>().imageContents(); | 201 blink::WebImage image = context_node.to<WebElement>().imageContents(); |
| 201 original_size = image.size(); | 202 original_size = image.size(); |
| 202 thumbnail = Downscale(image, | 203 thumbnail = |
| 203 thumbnail_min_area_pixels, | 204 Downscale(image, thumbnail_min_area_pixels, thumbnail_max_size_pixels); |
| 204 thumbnail_max_size_pixels); | |
| 205 } | 205 } |
| 206 | 206 |
| 207 SkBitmap bitmap; | 207 SkBitmap bitmap; |
| 208 if (thumbnail.colorType() == kN32_SkColorType) | 208 if (thumbnail.colorType() == kN32_SkColorType) |
| 209 bitmap = thumbnail; | 209 bitmap = thumbnail; |
| 210 else | 210 else |
| 211 thumbnail.copyTo(&bitmap, kN32_SkColorType); | 211 thumbnail.copyTo(&bitmap, kN32_SkColorType); |
| 212 | 212 |
| 213 std::string thumbnail_data; | 213 std::vector<uint8_t> thumbnail_data; |
| 214 SkAutoLockPixels lock(bitmap); | 214 SkAutoLockPixels lock(bitmap); |
| 215 if (bitmap.getPixels()) { | 215 if (bitmap.getPixels()) { |
| 216 const int kDefaultQuality = 90; | 216 const int kDefaultQuality = 90; |
| 217 std::vector<unsigned char> data; | 217 std::vector<unsigned char> data; |
| 218 if (gfx::JPEGCodec::Encode( | 218 if (gfx::JPEGCodec::Encode( |
| 219 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 219 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 220 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | 220 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), |
| 221 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) | 221 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) { |
| 222 thumbnail_data = std::string(data.begin(), data.end()); | 222 std::swap(thumbnail_data, data); |
|
dcheng
2017/03/13 07:49:29
The standard mechanism for using swap is:
using s
watk
2017/03/13 23:34:04
Ah thanks, I wasn't aware. I just like how the non
| |
| 223 } | |
| 223 } | 224 } |
| 224 | 225 |
| 225 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( | 226 callback.Run(thumbnail_data, original_size); |
| 226 routing_id(), thumbnail_data, original_size, callback_id)); | |
| 227 } | 227 } |
| 228 | 228 |
| 229 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { | 229 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { |
| 230 #if BUILDFLAG(ENABLE_PRINTING) | 230 #if BUILDFLAG(ENABLE_PRINTING) |
| 231 printing::PrintWebViewHelper* helper = | 231 printing::PrintWebViewHelper* helper = |
| 232 printing::PrintWebViewHelper::Get(render_frame()); | 232 printing::PrintWebViewHelper::Get(render_frame()); |
| 233 if (helper) | 233 if (helper) |
| 234 helper->PrintNode(render_frame()->GetWebFrame()->contextMenuNode()); | 234 helper->PrintNode(render_frame()->GetWebFrame()->contextMenuNode()); |
| 235 #endif | 235 #endif |
| 236 } | 236 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 } | 353 } |
| 354 | 354 |
| 355 void ChromeRenderFrameObserver::OnDestruct() { | 355 void ChromeRenderFrameObserver::OnDestruct() { |
| 356 delete this; | 356 delete this; |
| 357 } | 357 } |
| 358 | 358 |
| 359 void ChromeRenderFrameObserver::OnImageContextMenuRendererRequest( | 359 void ChromeRenderFrameObserver::OnImageContextMenuRendererRequest( |
| 360 chrome::mojom::ImageContextMenuRendererRequest request) { | 360 chrome::mojom::ImageContextMenuRendererRequest request) { |
| 361 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); | 361 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); |
| 362 } | 362 } |
| 363 | |
| 364 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( | |
| 365 chrome::mojom::ThumbnailCapturerRequest request) { | |
| 366 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); | |
| 367 } | |
| OLD | NEW |