1 // Copyright 2018 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 #ifndef CONTENT_BROWSER_SCOPED_ACTIVE_URL_H_
6 #define CONTENT_BROWSER_SCOPED_ACTIVE_URL_H_
7 
8 #include "base/macros.h"
9 
10 class GURL;
11 
12 namespace url {
13 class Origin;
14 }  // namespace url
15 
16 namespace content {
17 
18 class FrameTreeNode;
19 class RenderFrameHost;
20 class RenderFrameProxyHost;
21 class RenderViewHost;
22 
23 // ScopedActiveURL calls ContentClient::SetActiveURL when constructed
24 // and calls it again with empty arguments when destructed.
25 class ScopedActiveURL {
26  public:
27   // Calls ContentClient::SetActiveURL with |active_url| and |top_origin| (to
28   // set the crash keys).
29   ScopedActiveURL(const GURL& active_url, const url::Origin& top_origin);
30 
31   // Convenience constructor, calculating |active_url| and |top_origin| based on
32   // |frame|'s last committed origin and main frame.
33   explicit ScopedActiveURL(RenderFrameHost* frame);
34 
35   // Convenience constructor, calculating |active_url| and |top_origin| based on
36   // |proxy|'s last committed origin and main frame.
37   explicit ScopedActiveURL(RenderFrameProxyHost* proxy);
38 
39   // Convenience constructor, calculating |active_url| and |top_origin| based on
40   // the frame tree node of |view|'s main frame.
41   explicit ScopedActiveURL(RenderViewHost* view);
42 
43   // Calls ContentClient::SetActiveURL with empty arguments (to reset the crash
44   // keys).
45   ~ScopedActiveURL();
46 
47  private:
48   explicit ScopedActiveURL(FrameTreeNode* node);
49 
50   DISALLOW_COPY_AND_ASSIGN(ScopedActiveURL);
51 };
52 
53 }  // namespace content
54 
55 #endif  // CONTENT_BROWSER_SCOPED_ACTIVE_URL_H_
56