OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_view_observer.h" | 5 #include "chrome/renderer/chrome_render_view_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 23 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
24 #include "chrome/renderer/translate/translate_helper.h" | 24 #include "chrome/renderer/translate/translate_helper.h" |
25 #include "chrome/renderer/webview_color_overlay.h" | 25 #include "chrome/renderer/webview_color_overlay.h" |
26 #include "content/public/common/bindings_policy.h" | 26 #include "content/public/common/bindings_policy.h" |
27 #include "content/public/renderer/content_renderer_client.h" | 27 #include "content/public/renderer/content_renderer_client.h" |
28 #include "content/public/renderer/render_frame.h" | 28 #include "content/public/renderer/render_frame.h" |
29 #include "content/public/renderer/render_view.h" | 29 #include "content/public/renderer/render_view.h" |
30 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
31 #include "extensions/common/stack_frame.h" | 31 #include "extensions/common/stack_frame.h" |
32 #include "net/base/data_url.h" | 32 #include "net/base/data_url.h" |
33 #include "skia/ext/image_operations.h" | |
34 #include "skia/ext/platform_canvas.h" | 33 #include "skia/ext/platform_canvas.h" |
35 #include "third_party/WebKit/public/platform/WebCString.h" | 34 #include "third_party/WebKit/public/platform/WebCString.h" |
36 #include "third_party/WebKit/public/platform/WebRect.h" | 35 #include "third_party/WebKit/public/platform/WebRect.h" |
37 #include "third_party/WebKit/public/platform/WebSize.h" | 36 #include "third_party/WebKit/public/platform/WebSize.h" |
38 #include "third_party/WebKit/public/platform/WebString.h" | 37 #include "third_party/WebKit/public/platform/WebString.h" |
39 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 38 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
40 #include "third_party/WebKit/public/platform/WebVector.h" | 39 #include "third_party/WebKit/public/platform/WebVector.h" |
41 #include "third_party/WebKit/public/web/WebAXObject.h" | 40 #include "third_party/WebKit/public/web/WebAXObject.h" |
42 #include "third_party/WebKit/public/web/WebDataSource.h" | 41 #include "third_party/WebKit/public/web/WebDataSource.h" |
43 #include "third_party/WebKit/public/web/WebDocument.h" | 42 #include "third_party/WebKit/public/web/WebDocument.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 static const char kTranslateCaptureText[] = "Translate.CaptureText"; | 96 static const char kTranslateCaptureText[] = "Translate.CaptureText"; |
98 | 97 |
99 namespace { | 98 namespace { |
100 | 99 |
101 GURL StripRef(const GURL& url) { | 100 GURL StripRef(const GURL& url) { |
102 GURL::Replacements replacements; | 101 GURL::Replacements replacements; |
103 replacements.ClearRef(); | 102 replacements.ClearRef(); |
104 return url.ReplaceComponents(replacements); | 103 return url.ReplaceComponents(replacements); |
105 } | 104 } |
106 | 105 |
107 // If the source image is null or occupies less area than | |
108 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we | |
109 // scale down the image so that the width and height do not exceed | |
110 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. | |
111 SkBitmap Downscale(blink::WebImage image, | |
112 int thumbnail_min_area_pixels, | |
113 gfx::Size thumbnail_max_size_pixels) { | |
114 if (image.isNull()) | |
115 return SkBitmap(); | |
116 | |
117 gfx::Size image_size = image.size(); | |
118 | |
119 if (image_size.GetArea() < thumbnail_min_area_pixels) | |
120 return image.getSkBitmap(); | |
121 | |
122 if (image_size.width() <= thumbnail_max_size_pixels.width() && | |
123 image_size.height() <= thumbnail_max_size_pixels.height()) | |
124 return image.getSkBitmap(); | |
125 | |
126 gfx::SizeF scaled_size = image_size; | |
127 | |
128 if (scaled_size.width() > thumbnail_max_size_pixels.width()) { | |
129 scaled_size.Scale(thumbnail_max_size_pixels.width() / scaled_size.width()); | |
130 } | |
131 | |
132 if (scaled_size.height() > thumbnail_max_size_pixels.height()) { | |
133 scaled_size.Scale( | |
134 thumbnail_max_size_pixels.height() / scaled_size.height()); | |
135 } | |
136 | |
137 return skia::ImageOperations::Resize(image.getSkBitmap(), | |
138 skia::ImageOperations::RESIZE_GOOD, | |
139 static_cast<int>(scaled_size.width()), | |
140 static_cast<int>(scaled_size.height())); | |
141 } | |
142 | |
143 // The delimiter for a stack trace provided by WebKit. | 106 // The delimiter for a stack trace provided by WebKit. |
144 const char kStackFrameDelimiter[] = "\n at "; | 107 const char kStackFrameDelimiter[] = "\n at "; |
145 | 108 |
146 // Get a stack trace from a WebKit console message. | 109 // Get a stack trace from a WebKit console message. |
147 // There are three possible scenarios: | 110 // There are three possible scenarios: |
148 // 1. WebKit gives us a stack trace in |stack_trace|. | 111 // 1. WebKit gives us a stack trace in |stack_trace|. |
149 // 2. The stack trace is embedded in the error |message| by an internal | 112 // 2. The stack trace is embedded in the error |message| by an internal |
150 // script. This will be more useful than |stack_trace|, since |stack_trace| | 113 // script. This will be more useful than |stack_trace|, since |stack_trace| |
151 // will include the internal bindings trace, instead of a developer's code. | 114 // will include the internal bindings trace, instead of a developer's code. |
152 // 3. No stack trace is included. In this case, we should mock one up from | 115 // 3. No stack trace is included. In this case, we should mock one up from |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { | 231 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
269 bool handled = true; | 232 bool handled = true; |
270 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 233 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
271 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 234 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
272 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, | 235 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, |
273 OnJavaScriptStressTestControl) | 236 OnJavaScriptStressTestControl) |
274 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 237 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
275 OnSetClientSidePhishingDetection) | 238 OnSetClientSidePhishingDetection) |
276 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, | 239 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, |
277 OnSetVisuallyDeemphasized) | 240 OnSetVisuallyDeemphasized) |
278 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, | |
279 OnRequestThumbnailForContextNode) | |
280 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) | 241 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) |
281 #if defined(OS_ANDROID) | 242 #if defined(OS_ANDROID) |
282 IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateTopControlsState, | 243 IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateTopControlsState, |
283 OnUpdateTopControlsState) | 244 OnUpdateTopControlsState) |
284 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveWebappInformation, | 245 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveWebappInformation, |
285 OnRetrieveWebappInformation) | 246 OnRetrieveWebappInformation) |
286 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveMetaTagContent, | 247 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveMetaTagContent, |
287 OnRetrieveMetaTagContent) | 248 OnRetrieveMetaTagContent) |
288 #endif | 249 #endif |
289 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures) | 250 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 if (deemphasized) { | 380 if (deemphasized) { |
420 // 70% opaque grey. | 381 // 70% opaque grey. |
421 SkColor greyish = SkColorSetARGB(178, 0, 0, 0); | 382 SkColor greyish = SkColorSetARGB(178, 0, 0, 0); |
422 dimmed_color_overlay_.reset( | 383 dimmed_color_overlay_.reset( |
423 new WebViewColorOverlay(render_view(), greyish)); | 384 new WebViewColorOverlay(render_view(), greyish)); |
424 } else { | 385 } else { |
425 dimmed_color_overlay_.reset(); | 386 dimmed_color_overlay_.reset(); |
426 } | 387 } |
427 } | 388 } |
428 | 389 |
429 void ChromeRenderViewObserver::OnRequestThumbnailForContextNode( | |
430 int thumbnail_min_area_pixels, gfx::Size thumbnail_max_size_pixels) { | |
431 WebNode context_node = render_view()->GetContextMenuNode(); | |
432 SkBitmap thumbnail; | |
433 gfx::Size original_size; | |
434 if (!context_node.isNull() && context_node.isElementNode()) { | |
435 blink::WebImage image = context_node.to<WebElement>().imageContents(); | |
436 original_size = image.size(); | |
437 thumbnail = Downscale(image, | |
438 thumbnail_min_area_pixels, | |
439 thumbnail_max_size_pixels); | |
440 } | |
441 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( | |
442 routing_id(), thumbnail, original_size)); | |
443 } | |
444 | |
445 void ChromeRenderViewObserver::OnGetFPS() { | 390 void ChromeRenderViewObserver::OnGetFPS() { |
446 float fps = (render_view()->GetFilteredTimePerFrame() > 0.0f)? | 391 float fps = (render_view()->GetFilteredTimePerFrame() > 0.0f)? |
447 1.0f / render_view()->GetFilteredTimePerFrame() : 0.0f; | 392 1.0f / render_view()->GetFilteredTimePerFrame() : 0.0f; |
448 Send(new ChromeViewHostMsg_FPS(routing_id(), fps)); | 393 Send(new ChromeViewHostMsg_FPS(routing_id(), fps)); |
449 } | 394 } |
450 | 395 |
451 void ChromeRenderViewObserver::DidStartLoading() { | 396 void ChromeRenderViewObserver::DidStartLoading() { |
452 if ((render_view()->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) && | 397 if ((render_view()->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) && |
453 webui_javascript_.get()) { | 398 webui_javascript_.get()) { |
454 render_view()->EvaluateScript(webui_javascript_->frame_xpath, | 399 render_view()->EvaluateScript(webui_javascript_->frame_xpath, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 WebElement element = node.to<WebElement>(); | 599 WebElement element = node.to<WebElement>(); |
655 if (!element.hasTagName(tag_name)) | 600 if (!element.hasTagName(tag_name)) |
656 continue; | 601 continue; |
657 WebString value = element.getAttribute(attribute_name); | 602 WebString value = element.getAttribute(attribute_name); |
658 if (value.isNull() || !LowerCaseEqualsASCII(value, "refresh")) | 603 if (value.isNull() || !LowerCaseEqualsASCII(value, "refresh")) |
659 continue; | 604 continue; |
660 return true; | 605 return true; |
661 } | 606 } |
662 return false; | 607 return false; |
663 } | 608 } |
OLD | NEW |