OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/safe_browsing/renderer/websocket_sb_handshake_throttle.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 #include "content/public/common/resource_type.h" |
| 13 #include "content/public/renderer/render_frame.h" |
| 14 #include "ipc/ipc_message.h" |
| 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 #include "third_party/WebKit/public/platform/WebURL.h" |
| 18 |
| 19 namespace safe_browsing { |
| 20 |
| 21 WebSocketSBHandshakeThrottle::WebSocketSBHandshakeThrottle( |
| 22 mojom::SafeBrowsing* safe_browsing) |
| 23 : callbacks_(nullptr), safe_browsing_(safe_browsing), weak_factory_(this) {} |
| 24 |
| 25 WebSocketSBHandshakeThrottle::~WebSocketSBHandshakeThrottle() {} |
| 26 |
| 27 void WebSocketSBHandshakeThrottle::ThrottleHandshake( |
| 28 const blink::WebURL& url, |
| 29 blink::WebLocalFrame* web_local_frame, |
| 30 blink::WebCallbacks<void, const blink::WebString&>* callbacks) { |
| 31 DCHECK(!callbacks_); |
| 32 DCHECK(!url_checker_); |
| 33 callbacks_ = callbacks; |
| 34 url_ = url; |
| 35 int render_frame_id = MSG_ROUTING_NONE; |
| 36 if (web_local_frame) { |
| 37 render_frame_id = |
| 38 content::RenderFrame::FromWebFrame(web_local_frame)->GetRoutingID(); |
| 39 } |
| 40 int load_flags = 0; |
| 41 safe_browsing_->CreateCheckerAndCheck( |
| 42 render_frame_id, mojo::MakeRequest(&url_checker_), url, load_flags, |
| 43 content::RESOURCE_TYPE_SUB_RESOURCE, |
| 44 base::BindOnce(&WebSocketSBHandshakeThrottle::OnCheckResult, |
| 45 weak_factory_.GetWeakPtr())); |
| 46 } |
| 47 |
| 48 void WebSocketSBHandshakeThrottle::OnCheckResult(bool safe) { |
| 49 if (safe) { |
| 50 callbacks_->OnSuccess(); |
| 51 } else { |
| 52 callbacks_->OnError(blink::WebString::FromUTF8(base::StringPrintf( |
| 53 "WebSocket connection to %s failed safe browsing check", |
| 54 url_.spec().c_str()))); |
| 55 } |
| 56 // |this| is destroyed here. |
| 57 } |
| 58 |
| 59 } // namespace safe_browsing |
OLD | NEW |