Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/safe_browsing/renderer/websocket_sb_handshake_throttle.cc

Issue 2952583002: SafeBrowsing support for WebSocket (post-network-servicification) (Closed)
Patch Set: Fix compile on Windows Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/command_line.h"
11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/public/common/resource_type.h"
16 #include "content/public/common/service_names.mojom.h"
17 #include "content/public/renderer/render_frame.h"
18 #include "content/public/renderer/render_thread.h"
19 #include "ipc/ipc_message.h"
20 #include "mojo/public/cpp/bindings/interface_request.h"
21 #include "services/service_manager/public/cpp/connector.h"
22 #include "third_party/WebKit/public/platform/WebString.h"
23 #include "third_party/WebKit/public/platform/WebURL.h"
24
25 namespace safe_browsing {
26
27 // static
28 std::unique_ptr<WebSocketSBHandshakeThrottle>
29 WebSocketSBHandshakeThrottle::MaybeCreate() {
30 // TODO(ricea): Is there some way to avoid doing a string lookup every time
31 // here?
32 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
33 switches::kEnableNetworkService)) {
34 return nullptr;
35 }
36 mojom::SafeBrowsingPtr safe_browsing;
37 content::RenderThread::Get()->GetConnector()->BindInterface(
yzshen1 2017/06/20 19:52:19 You could consider passing in a (not-owned) SafeBr
Adam Rice 2017/06/21 06:08:35 Done. I realised I can share the same interface po
yzshen1 2017/06/21 16:55:06 I think it may make more sense to initialize safe_
Adam Rice 2017/06/22 13:42:44 Done. I factored the shared code out into a new me
38 content::mojom::kBrowserServiceName, &safe_browsing);
39 return base::MakeUnique<WebSocketSBHandshakeThrottle>(
40 std::move(safe_browsing));
41 }
42
43 WebSocketSBHandshakeThrottle::WebSocketSBHandshakeThrottle(
44 mojom::SafeBrowsingPtr safe_browsing)
45 : callbacks_(nullptr), safe_browsing_(std::move(safe_browsing)) {}
46
47 WebSocketSBHandshakeThrottle::~WebSocketSBHandshakeThrottle() {}
48
49 void WebSocketSBHandshakeThrottle::ThrottleHandshake(
50 const blink::WebURL& url,
51 blink::WebLocalFrame* web_local_frame,
52 blink::WebCallbacks<void, const blink::WebString&>* callbacks) {
53 DCHECK(!callbacks_);
54 DCHECK(!url_checker_);
55 callbacks_ = callbacks;
56 url_ = url;
57 int render_frame_id = MSG_ROUTING_NONE;
58 if (web_local_frame) {
59 render_frame_id =
60 content::RenderFrame::FromWebFrame(web_local_frame)->GetRoutingID();
61 }
62 int load_flags = 0;
63 // This use of Unretained() is safe because this object will not be called
64 // back after |safe_browsing_| is destroyed.
65 safe_browsing_->CreateCheckerAndCheck(
66 render_frame_id, mojo::MakeRequest(&url_checker_), url, load_flags,
67 content::RESOURCE_TYPE_SUB_RESOURCE,
68 base::BindOnce(&WebSocketSBHandshakeThrottle::OnCheckResult,
69 base::Unretained(this)));
70 }
71
72 void WebSocketSBHandshakeThrottle::OnCheckResult(bool safe) {
73 if (safe) {
74 callbacks_->OnSuccess();
75 } else {
76 callbacks_->OnError(blink::WebString::FromUTF8(base::StringPrintf(
77 "WebSocket connection to %s failed safe browsing check",
78 url_.spec().c_str())));
79 }
80 // |this| is destroyed here.
81 }
82
83 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698