| 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 12 matching lines...) Expand all Loading... |
| 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 "skia/ext/image_operations.h" | 30 #include "skia/ext/image_operations.h" |
| 31 #include "third_party/WebKit/public/platform/WebImage.h" | 31 #include "third_party/WebKit/public/platform/WebImage.h" |
| 32 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 32 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 33 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | |
| 34 #include "third_party/WebKit/public/web/WebDataSource.h" | 33 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 35 #include "third_party/WebKit/public/web/WebDocument.h" | 34 #include "third_party/WebKit/public/web/WebDocument.h" |
| 36 #include "third_party/WebKit/public/web/WebElement.h" | 35 #include "third_party/WebKit/public/web/WebElement.h" |
| 37 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | 36 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
| 38 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 37 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 39 #include "third_party/WebKit/public/web/WebNode.h" | 38 #include "third_party/WebKit/public/web/WebNode.h" |
| 40 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 39 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 41 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
| 42 #include "ui/gfx/codec/jpeg_codec.h" | 41 #include "ui/gfx/codec/jpeg_codec.h" |
| 43 #include "ui/gfx/geometry/size_f.h" | 42 #include "ui/gfx/geometry/size_f.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 99 } |
| 101 | 100 |
| 102 return skia::ImageOperations::Resize(image.getSkBitmap(), | 101 return skia::ImageOperations::Resize(image.getSkBitmap(), |
| 103 skia::ImageOperations::RESIZE_GOOD, | 102 skia::ImageOperations::RESIZE_GOOD, |
| 104 static_cast<int>(scaled_size.width()), | 103 static_cast<int>(scaled_size.width()), |
| 105 static_cast<int>(scaled_size.height())); | 104 static_cast<int>(scaled_size.height())); |
| 106 } | 105 } |
| 107 | 106 |
| 108 } // namespace | 107 } // namespace |
| 109 | 108 |
| 109 // static |
| 110 void ChromeRenderFrameObserver::BindBannerClient( |
| 111 ChromeRenderFrameObserver* observer, |
| 112 mojo::InterfaceRequest<blink::mojom::AppBannerClient> request) { |
| 113 observer->banner_binding_.reset( |
| 114 new mojo::Binding<blink::mojom::AppBannerClient>(observer, |
| 115 std::move(request))); |
| 116 } |
| 117 |
| 110 ChromeRenderFrameObserver::ChromeRenderFrameObserver( | 118 ChromeRenderFrameObserver::ChromeRenderFrameObserver( |
| 111 content::RenderFrame* render_frame) | 119 content::RenderFrame* render_frame) |
| 112 : content::RenderFrameObserver(render_frame), | 120 : content::RenderFrameObserver(render_frame), |
| 113 translate_helper_(nullptr), | 121 translate_helper_(nullptr), |
| 114 phishing_classifier_(nullptr) { | 122 phishing_classifier_(nullptr) { |
| 115 // Don't do anything for subframes. | 123 // Don't do anything for subframes. |
| 116 if (!render_frame->IsMainFrame()) | 124 if (!render_frame->IsMainFrame()) |
| 117 return; | 125 return; |
| 118 | 126 |
| 119 const base::CommandLine& command_line = | 127 const base::CommandLine& command_line = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 142 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, | 150 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, |
| 143 OnRequestReloadImageForContextNode) | 151 OnRequestReloadImageForContextNode) |
| 144 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, | 152 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, |
| 145 OnRequestThumbnailForContextNode) | 153 OnRequestThumbnailForContextNode) |
| 146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 154 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
| 147 OnSetClientSidePhishingDetection) | 155 OnSetClientSidePhishingDetection) |
| 148 #if defined(ENABLE_PRINTING) | 156 #if defined(ENABLE_PRINTING) |
| 149 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, | 157 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, |
| 150 OnPrintNodeUnderContextMenu) | 158 OnPrintNodeUnderContextMenu) |
| 151 #endif | 159 #endif |
| 152 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerPromptRequest, | |
| 153 OnAppBannerPromptRequest) | |
| 154 IPC_MESSAGE_UNHANDLED(handled = false) | 160 IPC_MESSAGE_UNHANDLED(handled = false) |
| 155 IPC_END_MESSAGE_MAP() | 161 IPC_END_MESSAGE_MAP() |
| 156 | 162 |
| 157 return handled; | 163 return handled; |
| 158 } | 164 } |
| 159 | 165 |
| 160 void ChromeRenderFrameObserver::OnSetIsPrerendering( | 166 void ChromeRenderFrameObserver::OnSetIsPrerendering( |
| 161 prerender::PrerenderMode mode) { | 167 prerender::PrerenderMode mode) { |
| 162 if (mode != prerender::NO_PRERENDER) { | 168 if (mode != prerender::NO_PRERENDER) { |
| 163 // If the PrerenderHelper for this frame already exists, don't create it. It | 169 // If the PrerenderHelper for this frame already exists, don't create it. It |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 bool enable_phishing_detection) { | 239 bool enable_phishing_detection) { |
| 234 #if defined(SAFE_BROWSING_CSD) | 240 #if defined(SAFE_BROWSING_CSD) |
| 235 phishing_classifier_ = | 241 phishing_classifier_ = |
| 236 enable_phishing_detection | 242 enable_phishing_detection |
| 237 ? safe_browsing::PhishingClassifierDelegate::Create(render_frame(), | 243 ? safe_browsing::PhishingClassifierDelegate::Create(render_frame(), |
| 238 nullptr) | 244 nullptr) |
| 239 : nullptr; | 245 : nullptr; |
| 240 #endif | 246 #endif |
| 241 } | 247 } |
| 242 | 248 |
| 243 void ChromeRenderFrameObserver::OnAppBannerPromptRequest( | 249 void ChromeRenderFrameObserver::BannerPromptRequest( |
| 244 int request_id, | 250 int request_id, |
| 245 const std::string& platform) { | 251 const mojo::String& platform, |
| 246 // App banner prompt requests are handled in the general chrome render frame | 252 const BannerPromptRequestCallback& callback) { |
| 247 // observer, not the AppBannerClient, as the AppBannerClient is created lazily | 253 blink::mojom::AppBannerPromptReply reply = |
| 248 // by blink and may not exist when the request is sent. | 254 blink::mojom::AppBannerPromptReply::NONE; |
| 249 blink::WebAppBannerPromptReply reply = blink::WebAppBannerPromptReply::None; | 255 blink::WebString web_platform(base::UTF8ToUTF16(platform.get())); |
| 250 blink::WebString web_platform(base::UTF8ToUTF16(platform)); | |
| 251 blink::WebVector<blink::WebString> web_platforms(&web_platform, 1); | 256 blink::WebVector<blink::WebString> web_platforms(&web_platform, 1); |
| 252 | 257 |
| 253 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); | 258 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 254 frame->willShowInstallBannerPrompt(request_id, web_platforms, &reply); | 259 frame->willShowInstallBannerPrompt(request_id, web_platforms, &reply); |
| 255 | 260 |
| 256 // Extract the referrer header for this site according to its referrer policy. | 261 // Extract the referrer header for this site according to its referrer policy. |
| 257 // Pass in an empty URL as the destination so that it is always treated | 262 // Pass in an empty URL as the destination so that it is always treated |
| 258 // as a cross-origin request. | 263 // as a cross-origin request. |
| 259 std::string referrer = blink::WebSecurityPolicy::generateReferrerHeader( | 264 std::string referrer = blink::WebSecurityPolicy::generateReferrerHeader( |
| 260 frame->document().referrerPolicy(), GURL(), | 265 frame->document().referrerPolicy(), GURL(), |
| 261 frame->document().outgoingReferrer()).utf8(); | 266 frame->document().outgoingReferrer()).utf8(); |
| 262 | 267 |
| 263 Send(new ChromeViewHostMsg_AppBannerPromptReply( | 268 callback.Run(request_id, reply, referrer); |
| 264 routing_id(), request_id, reply, referrer)); | |
| 265 } | 269 } |
| 266 | 270 |
| 267 void ChromeRenderFrameObserver::DidFinishLoad() { | 271 void ChromeRenderFrameObserver::DidFinishLoad() { |
| 268 WebLocalFrame* frame = render_frame()->GetWebFrame(); | 272 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 269 // Don't do anything for subframes. | 273 // Don't do anything for subframes. |
| 270 if (frame->parent()) | 274 if (frame->parent()) |
| 271 return; | 275 return; |
| 272 | 276 |
| 273 GURL osdd_url = frame->document().openSearchDescriptionURL(); | 277 GURL osdd_url = frame->document().openSearchDescriptionURL(); |
| 274 if (!osdd_url.is_empty()) { | 278 if (!osdd_url.is_empty()) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 CapturePageText(FINAL_CAPTURE); | 368 CapturePageText(FINAL_CAPTURE); |
| 365 break; | 369 break; |
| 366 default: | 370 default: |
| 367 break; | 371 break; |
| 368 } | 372 } |
| 369 } | 373 } |
| 370 | 374 |
| 371 void ChromeRenderFrameObserver::OnDestruct() { | 375 void ChromeRenderFrameObserver::OnDestruct() { |
| 372 delete this; | 376 delete this; |
| 373 } | 377 } |
| OLD | NEW |