1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Implementation of SafeBrowsing for WebSockets. This code runs inside the
// render process, calling the interface defined in safe_browsing.mojom to
// communicate with the SafeBrowsing service.
#ifndef COMPONENTS_SAFE_BROWSING_RENDERER_WEBSOCKET_SB_HANDSHAKE_THROTTLE_H_
#define COMPONENTS_SAFE_BROWSING_RENDERER_WEBSOCKET_SB_HANDSHAKE_THROTTLE_H_
#include <memory>
#include "base/macros.h"
#include "base/time/time.h"
#include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "third_party/blink/public/platform/web_callbacks.h"
#include "third_party/blink/public/platform/websocket_handshake_throttle.h"
#include "url/gurl.h"
namespace safe_browsing {
class WebSocketSBHandshakeThrottle : public blink::WebSocketHandshakeThrottle,
public mojom::UrlCheckNotifier {
public:
WebSocketSBHandshakeThrottle(mojom::SafeBrowsing* safe_browsing,
int render_frame_id);
~WebSocketSBHandshakeThrottle() override;
void ThrottleHandshake(
const blink::WebURL& url,
blink::WebCallbacks<void, const blink::WebString&>* callbacks) override;
private:
// These values are logged to UMA so do not renumber or reuse.
enum class Result {
UNKNOWN = 0,
SAFE = 1,
BLOCKED = 2,
ABANDONED = 3,
NOT_SUPPORTED = 4,
RESULT_COUNT
};
// mojom::UrlCheckNotifier implementation.
void OnCompleteCheck(bool proceed, bool showed_interstitial) override;
void OnCheckResult(mojom::UrlCheckNotifierRequest slow_check_notifier,
bool proceed,
bool showed_interstitial);
void OnConnectionError();
const int render_frame_id_;
GURL url_;
blink::WebCallbacks<void, const blink::WebString&>* callbacks_;
mojom::SafeBrowsingUrlCheckerPtr url_checker_;
mojom::SafeBrowsing* safe_browsing_;
std::unique_ptr<mojo::Binding<mojom::UrlCheckNotifier>> notifier_binding_;
base::TimeTicks start_time_;
Result result_;
base::WeakPtrFactory<WebSocketSBHandshakeThrottle> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(WebSocketSBHandshakeThrottle);
};
} // namespace safe_browsing
#endif // COMPONENTS_SAFE_BROWSING_RENDERER_WEBSOCKET_SB_HANDSHAKE_THROTTLE_H_
|