| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/crash_keys.h" | 21 #include "chrome/common/crash_keys.h" |
| 22 #include "chrome/common/prerender_messages.h" | 22 #include "chrome/common/prerender_messages.h" |
| 23 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
| 24 #include "chrome/renderer/prerender/prerender_helper.h" | 24 #include "chrome/renderer/prerender/prerender_helper.h" |
| 25 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 25 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
| 26 #include "components/translate/content/renderer/translate_helper.h" | 26 #include "components/translate/content/renderer/translate_helper.h" |
| 27 #include "content/public/renderer/render_frame.h" | 27 #include "content/public/renderer/render_frame.h" |
| 28 #include "content/public/renderer/render_view.h" | 28 #include "content/public/renderer/render_view.h" |
| 29 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
| 30 #include "printing/features/features.h" | 30 #include "printing/features/features.h" |
| 31 #include "services/service_manager/public/cpp/interface_registry.h" |
| 31 #include "skia/ext/image_operations.h" | 32 #include "skia/ext/image_operations.h" |
| 32 #include "third_party/WebKit/public/platform/WebImage.h" | 33 #include "third_party/WebKit/public/platform/WebImage.h" |
| 33 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 34 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 34 #include "third_party/WebKit/public/web/WebDataSource.h" | 35 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 35 #include "third_party/WebKit/public/web/WebDocument.h" | 36 #include "third_party/WebKit/public/web/WebDocument.h" |
| 36 #include "third_party/WebKit/public/web/WebElement.h" | 37 #include "third_party/WebKit/public/web/WebElement.h" |
| 37 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | 38 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
| 38 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 39 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 39 #include "third_party/WebKit/public/web/WebNode.h" | 40 #include "third_party/WebKit/public/web/WebNode.h" |
| 40 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 41 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (!render_frame->IsMainFrame()) | 117 if (!render_frame->IsMainFrame()) |
| 117 return; | 118 return; |
| 118 | 119 |
| 119 const base::CommandLine& command_line = | 120 const base::CommandLine& command_line = |
| 120 *base::CommandLine::ForCurrentProcess(); | 121 *base::CommandLine::ForCurrentProcess(); |
| 121 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) | 122 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) |
| 122 OnSetClientSidePhishingDetection(true); | 123 OnSetClientSidePhishingDetection(true); |
| 123 translate_helper_ = new translate::TranslateHelper( | 124 translate_helper_ = new translate::TranslateHelper( |
| 124 render_frame, chrome::ISOLATED_WORLD_ID_TRANSLATE, | 125 render_frame, chrome::ISOLATED_WORLD_ID_TRANSLATE, |
| 125 extensions::kExtensionScheme); | 126 extensions::kExtensionScheme); |
| 127 |
| 128 render_frame->GetInterfaceRegistry()->AddInterface( |
| 129 base::Bind(&ChromeRenderFrameObserver::OnThumbnailCapturerRequest, |
| 130 base::Unretained(this))); |
| 126 } | 131 } |
| 127 | 132 |
| 128 ChromeRenderFrameObserver::~ChromeRenderFrameObserver() { | 133 ChromeRenderFrameObserver::~ChromeRenderFrameObserver() { |
| 129 } | 134 } |
| 130 | 135 |
| 131 bool ChromeRenderFrameObserver::OnMessageReceived(const IPC::Message& message) { | 136 bool ChromeRenderFrameObserver::OnMessageReceived(const IPC::Message& message) { |
| 132 // Filter only. | 137 // Filter only. |
| 133 bool handled = true; | 138 bool handled = true; |
| 134 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) | 139 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) |
| 135 IPC_MESSAGE_HANDLER(PrerenderMsg_SetIsPrerendering, OnSetIsPrerendering) | 140 IPC_MESSAGE_HANDLER(PrerenderMsg_SetIsPrerendering, OnSetIsPrerendering) |
| 136 IPC_MESSAGE_UNHANDLED(handled = false) | 141 IPC_MESSAGE_UNHANDLED(handled = false) |
| 137 IPC_END_MESSAGE_MAP() | 142 IPC_END_MESSAGE_MAP() |
| 138 if (handled) | 143 if (handled) |
| 139 return false; | 144 return false; |
| 140 | 145 |
| 141 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) | 146 IPC_BEGIN_MESSAGE_MAP(ChromeRenderFrameObserver, message) |
| 142 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, | 147 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, |
| 143 OnRequestReloadImageForContextNode) | 148 OnRequestReloadImageForContextNode) |
| 144 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, | |
| 145 OnRequestThumbnailForContextNode) | |
| 146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 149 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
| 147 OnSetClientSidePhishingDetection) | 150 OnSetClientSidePhishingDetection) |
| 148 #if BUILDFLAG(ENABLE_PRINTING) | 151 #if BUILDFLAG(ENABLE_PRINTING) |
| 149 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, | 152 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, |
| 150 OnPrintNodeUnderContextMenu) | 153 OnPrintNodeUnderContextMenu) |
| 151 #endif | 154 #endif |
| 152 IPC_MESSAGE_UNHANDLED(handled = false) | 155 IPC_MESSAGE_UNHANDLED(handled = false) |
| 153 IPC_END_MESSAGE_MAP() | 156 IPC_END_MESSAGE_MAP() |
| 154 | 157 |
| 155 return handled; | 158 return handled; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 174 void ChromeRenderFrameObserver::OnRequestReloadImageForContextNode() { | 177 void ChromeRenderFrameObserver::OnRequestReloadImageForContextNode() { |
| 175 WebLocalFrame* frame = render_frame()->GetWebFrame(); | 178 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 176 // TODO(dglazkov): This code is clearly in the wrong place. Need | 179 // TODO(dglazkov): This code is clearly in the wrong place. Need |
| 177 // to investigate what it is doing and fix (http://crbug.com/606164). | 180 // to investigate what it is doing and fix (http://crbug.com/606164). |
| 178 WebNode context_node = frame->contextMenuNode(); | 181 WebNode context_node = frame->contextMenuNode(); |
| 179 if (!context_node.isNull() && context_node.isElementNode()) { | 182 if (!context_node.isNull() && context_node.isElementNode()) { |
| 180 frame->reloadImage(context_node); | 183 frame->reloadImage(context_node); |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 | 186 |
| 184 void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( | 187 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( |
| 185 int thumbnail_min_area_pixels, | 188 chrome::mojom::ThumbnailCapturerRequest request) { |
| 189 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); |
| 190 } |
| 191 |
| 192 void ChromeRenderFrameObserver::RequestThumbnailForContextNode( |
| 193 int32_t thumbnail_min_area_pixels, |
| 186 const gfx::Size& thumbnail_max_size_pixels, | 194 const gfx::Size& thumbnail_max_size_pixels, |
| 187 int callback_id) { | 195 const RequestThumbnailForContextNodeCallback& callback) { |
| 188 WebNode context_node = render_frame()->GetWebFrame()->contextMenuNode(); | 196 WebNode context_node = render_frame()->GetWebFrame()->contextMenuNode(); |
| 189 SkBitmap thumbnail; | 197 SkBitmap thumbnail; |
| 190 gfx::Size original_size; | 198 gfx::Size original_size; |
| 191 if (!context_node.isNull() && context_node.isElementNode()) { | 199 if (!context_node.isNull() && context_node.isElementNode()) { |
| 192 blink::WebImage image = context_node.to<WebElement>().imageContents(); | 200 blink::WebImage image = context_node.to<WebElement>().imageContents(); |
| 193 original_size = image.size(); | 201 original_size = image.size(); |
| 194 thumbnail = Downscale(image, | 202 thumbnail = |
| 195 thumbnail_min_area_pixels, | 203 Downscale(image, thumbnail_min_area_pixels, thumbnail_max_size_pixels); |
| 196 thumbnail_max_size_pixels); | |
| 197 } | 204 } |
| 198 | 205 |
| 199 SkBitmap bitmap; | 206 SkBitmap bitmap; |
| 200 if (thumbnail.colorType() == kN32_SkColorType) | 207 if (thumbnail.colorType() == kN32_SkColorType) |
| 201 bitmap = thumbnail; | 208 bitmap = thumbnail; |
| 202 else | 209 else |
| 203 thumbnail.copyTo(&bitmap, kN32_SkColorType); | 210 thumbnail.copyTo(&bitmap, kN32_SkColorType); |
| 204 | 211 |
| 205 std::string thumbnail_data; | 212 std::string thumbnail_data; |
| 206 SkAutoLockPixels lock(bitmap); | 213 SkAutoLockPixels lock(bitmap); |
| 207 if (bitmap.getPixels()) { | 214 if (bitmap.getPixels()) { |
| 208 const int kDefaultQuality = 90; | 215 const int kDefaultQuality = 90; |
| 209 std::vector<unsigned char> data; | 216 std::vector<unsigned char> data; |
| 210 if (gfx::JPEGCodec::Encode( | 217 if (gfx::JPEGCodec::Encode( |
| 211 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 218 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 212 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | 219 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), |
| 213 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) | 220 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) { |
| 214 thumbnail_data = std::string(data.begin(), data.end()); | 221 thumbnail_data = std::string(data.begin(), data.end()); |
| 222 } |
| 215 } | 223 } |
| 216 | 224 |
| 217 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( | 225 callback.Run(thumbnail_data, original_size); |
| 218 routing_id(), thumbnail_data, original_size, callback_id)); | |
| 219 } | 226 } |
| 220 | 227 |
| 221 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { | 228 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { |
| 222 #if BUILDFLAG(ENABLE_PRINTING) | 229 #if BUILDFLAG(ENABLE_PRINTING) |
| 223 printing::PrintWebViewHelper* helper = | 230 printing::PrintWebViewHelper* helper = |
| 224 printing::PrintWebViewHelper::Get(render_frame()); | 231 printing::PrintWebViewHelper::Get(render_frame()); |
| 225 if (helper) | 232 if (helper) |
| 226 helper->PrintNode(render_frame()->GetWebFrame()->contextMenuNode()); | 233 helper->PrintNode(render_frame()->GetWebFrame()->contextMenuNode()); |
| 227 #endif | 234 #endif |
| 228 } | 235 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 CapturePageText(FINAL_CAPTURE); | 347 CapturePageText(FINAL_CAPTURE); |
| 341 break; | 348 break; |
| 342 default: | 349 default: |
| 343 break; | 350 break; |
| 344 } | 351 } |
| 345 } | 352 } |
| 346 | 353 |
| 347 void ChromeRenderFrameObserver::OnDestruct() { | 354 void ChromeRenderFrameObserver::OnDestruct() { |
| 348 delete this; | 355 delete this; |
| 349 } | 356 } |
| OLD | NEW |