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 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_ | |
6 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_ | |
7 | |
8 #include "components/sessions/core/session_id.h" | |
9 #include "content/public/browser/web_contents_observer.h" | |
10 #include "content/public/browser/web_contents_user_data.h" | |
11 | |
12 namespace sync_sessions { | |
13 | |
14 class SyncSessionsWebContentsRouter; | |
15 | |
16 // TabHelper class that forwards tab-level WebContentsObserver events to a | |
17 // (per-profile) sessions router. The router is responsible for forwarding | |
18 // these events to sessions sync. This class also tracks the source tab id | |
19 // of its corresponding tab, if available. | |
20 // A TabHelper is a WebContentsObserver tied to the top level WebContents for a | |
21 // browser tab. | |
22 // https://chromium.googlesource.com/chromium/src/+/master/docs/tab_helpers.md | |
23 class SyncSessionsRouterTabHelper | |
24 : public content::WebContentsUserData<SyncSessionsRouterTabHelper>, | |
25 public content::WebContentsObserver { | |
26 public: | |
27 ~SyncSessionsRouterTabHelper() override; | |
28 | |
29 static void CreateForWebContents( | |
30 content::WebContents* web_contents, | |
31 SyncSessionsWebContentsRouter* session_router); | |
32 | |
33 // Get the tab id of the tab responsible for creating the tab this helper | |
34 // corresponds to. Returns -1 if there is no such tab. | |
35 SessionID::id_type source_tab_id() const { return source_tab_id_; } | |
36 | |
37 private: | |
38 friend class content::WebContentsUserData<SyncSessionsRouterTabHelper>; | |
39 | |
40 explicit SyncSessionsRouterTabHelper(content::WebContents* web_contents, | |
41 SyncSessionsWebContentsRouter* router); | |
42 | |
43 // Set the tab id of the tab reponsible for creating the tab this helper | |
44 // corresponds to. | |
45 void set_source_tab_id(const SessionID::id_type id) { source_tab_id_ = id; } | |
46 | |
47 // WebContentsObserver implementation. | |
48 void DidFinishNavigation( | |
49 content::NavigationHandle* navigation_handle) override; | |
50 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; | |
51 void WebContentsDestroyed() override; | |
52 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | |
53 const GURL& validated_url) override; | |
54 void DidOpenRequestedURL(content::WebContents* new_contents, | |
55 content::RenderFrameHost* source_render_frame_host, | |
56 const GURL& url, | |
57 const content::Referrer& referrer, | |
58 WindowOpenDisposition disposition, | |
59 ui::PageTransition transition, | |
60 bool started_from_context_menu, | |
61 bool renderer_initiated) override; | |
62 | |
63 void NotifyRouter(); | |
64 | |
65 // router_ is a KeyedService and is guaranteed to outlive |this|. | |
Nicolas Zea
2017/03/20 18:14:50
nit: "router_" -> "|router_|"
Patrick Noland
2017/03/21 22:54:31
Done.
| |
66 SyncSessionsWebContentsRouter* router_; | |
67 SessionID::id_type source_tab_id_; | |
Nicolas Zea
2017/03/20 18:14:50
Might be good to have a comment explaining this a
Patrick Noland
2017/03/21 22:54:31
Done.
| |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(SyncSessionsRouterTabHelper); | |
70 }; | |
71 | |
72 } // namespace sync_sessions | |
73 | |
74 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_ | |
OLD | NEW |