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

Side by Side Diff: chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h

Issue 2753753005: [sync] WebContentsObserver based sessions notifications (Closed)
Patch Set: use base:MakeUnique, alphabetize Created 3 years, 9 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 #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|.
66 SyncSessionsWebContentsRouter* router_;
67 // Tab id of the tab from which this tab was created. Example events that
68 // create this relationship:
69 // * From context menu, "Open link in new tab".
70 // * From context menu, "Open link in new window".
71 // * Ctrl-click.
72 // * Click on a link with target='_blank'.
73 SessionID::id_type source_tab_id_;
74
75 DISALLOW_COPY_AND_ASSIGN(SyncSessionsRouterTabHelper);
76 };
77
78 } // namespace sync_sessions
79
80 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698