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

Side by Side Diff: chrome/browser/ui/sync/tab_contents_synced_tab_delegate.cc

Issue 1408643002: [Sync] Componentize synced_tab_delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN, self review Created 5 years, 2 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" 5 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sessions/session_tab_helper.h" 9 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "components/sessions/content/content_serialized_navigation_builder.h"
10 #include "components/sync_driver/glue/synced_window_delegate.h" 11 #include "components/sync_driver/glue/synced_window_delegate.h"
12 #include "content/public/browser/favicon_status.h"
11 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
14 16
15 #if defined(ENABLE_EXTENSIONS) 17 #if defined(ENABLE_EXTENSIONS)
16 #include "chrome/browser/extensions/tab_helper.h" 18 #include "chrome/browser/extensions/tab_helper.h"
17 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
18 #endif 20 #endif
19 21
20 #if defined(ENABLE_SUPERVISED_USERS) 22 #if defined(ENABLE_SUPERVISED_USERS)
21 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" 23 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
22 #endif 24 #endif
23 25
24 using content::NavigationEntry; 26 using content::NavigationEntry;
25 27
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate); 28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabContentsSyncedTabDelegate);
27 29
30 namespace {
31
32 // Helper to access the correct NavigationEntry, accounting for pending entries.
33 NavigationEntry* GetPossiblyPendingEntryAtIndex(
34 content::WebContents* web_contents,
35 int i) {
36 int pending_index = web_contents->GetController().GetPendingEntryIndex();
37 return (pending_index == i)
38 ? web_contents->GetController().GetPendingEntry()
39 : web_contents->GetController().GetEntryAtIndex(i);
40 }
41
42 } // namespace
43
28 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate( 44 TabContentsSyncedTabDelegate::TabContentsSyncedTabDelegate(
29 content::WebContents* web_contents) 45 content::WebContents* web_contents)
30 : web_contents_(web_contents), sync_session_id_(0) {} 46 : web_contents_(web_contents), sync_session_id_(0) {}
31 47
32 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {} 48 TabContentsSyncedTabDelegate::~TabContentsSyncedTabDelegate() {}
33 49
34 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const { 50 SessionID::id_type TabContentsSyncedTabDelegate::GetWindowId() const {
35 return SessionTabHelper::FromWebContents(web_contents_)->window_id().id(); 51 return SessionTabHelper::FromWebContents(web_contents_)->window_id().id();
36 } 52 }
37 53
38 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const { 54 SessionID::id_type TabContentsSyncedTabDelegate::GetSessionId() const {
39 return SessionTabHelper::FromWebContents(web_contents_)->session_id().id(); 55 return SessionTabHelper::FromWebContents(web_contents_)->session_id().id();
40 } 56 }
41 57
42 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const { 58 bool TabContentsSyncedTabDelegate::IsBeingDestroyed() const {
43 return web_contents_->IsBeingDestroyed(); 59 return web_contents_->IsBeingDestroyed();
44 } 60 }
45 61
46 Profile* TabContentsSyncedTabDelegate::profile() const {
47 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
48 }
49
50 std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const { 62 std::string TabContentsSyncedTabDelegate::GetExtensionAppId() const {
51 #if defined(ENABLE_EXTENSIONS) 63 #if defined(ENABLE_EXTENSIONS)
52 const scoped_refptr<const extensions::Extension> extension_app( 64 const scoped_refptr<const extensions::Extension> extension_app(
53 extensions::TabHelper::FromWebContents(web_contents_)->extension_app()); 65 extensions::TabHelper::FromWebContents(web_contents_)->extension_app());
54 if (extension_app.get()) 66 if (extension_app.get())
55 return extension_app->id(); 67 return extension_app->id();
56 #endif 68 #endif
57 return std::string(); 69 return std::string();
58 } 70 }
59 71
60 bool TabContentsSyncedTabDelegate::IsInitialBlankNavigation() const { 72 bool TabContentsSyncedTabDelegate::IsInitialBlankNavigation() const {
61 return web_contents_->GetController().IsInitialBlankNavigation(); 73 return web_contents_->GetController().IsInitialBlankNavigation();
62 } 74 }
63 75
64 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const { 76 int TabContentsSyncedTabDelegate::GetCurrentEntryIndex() const {
65 return web_contents_->GetController().GetCurrentEntryIndex(); 77 return web_contents_->GetController().GetCurrentEntryIndex();
66 } 78 }
67 79
68 int TabContentsSyncedTabDelegate::GetEntryCount() const { 80 int TabContentsSyncedTabDelegate::GetEntryCount() const {
69 return web_contents_->GetController().GetEntryCount(); 81 return web_contents_->GetController().GetEntryCount();
70 } 82 }
71 83
72 int TabContentsSyncedTabDelegate::GetPendingEntryIndex() const { 84 GURL TabContentsSyncedTabDelegate::GetVirtualURLAtIndex(int i) const {
73 return web_contents_->GetController().GetPendingEntryIndex(); 85 NavigationEntry* entry = GetPossiblyPendingEntryAtIndex(web_contents_, i);
86 return entry->GetVirtualURL();
74 } 87 }
75 88
76 NavigationEntry* TabContentsSyncedTabDelegate::GetPendingEntry() const { 89 GURL TabContentsSyncedTabDelegate::GetFaviconURLAtIndex(int i) const {
77 return web_contents_->GetController().GetPendingEntry(); 90 NavigationEntry* entry = GetPossiblyPendingEntryAtIndex(web_contents_, i);
91 return (entry->GetFavicon().valid ? entry->GetFavicon().url : GURL());
78 } 92 }
79 93
80 NavigationEntry* TabContentsSyncedTabDelegate::GetEntryAtIndex(int i) const { 94 ui::PageTransition TabContentsSyncedTabDelegate::GetTransitionAtIndex(
81 return web_contents_->GetController().GetEntryAtIndex(i); 95 int i) const {
96 NavigationEntry* entry = GetPossiblyPendingEntryAtIndex(web_contents_, i);
97 return entry->GetTransitionType();
82 } 98 }
83 99
84 NavigationEntry* TabContentsSyncedTabDelegate::GetActiveEntry() const { 100 void TabContentsSyncedTabDelegate::GetSerializedNavigationAtIndex(
85 return web_contents_->GetController().GetVisibleEntry(); 101 int i,
102 sessions::SerializedNavigationEntry* serialized_entry) const {
103 NavigationEntry* entry = GetPossiblyPendingEntryAtIndex(web_contents_, i);
104 *serialized_entry =
105 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(i,
106 *entry);
86 } 107 }
87 108
88 bool TabContentsSyncedTabDelegate::ProfileIsSupervised() const { 109 bool TabContentsSyncedTabDelegate::ProfileIsSupervised() const {
89 return profile()->IsSupervised(); 110 return Profile::FromBrowserContext(web_contents_->GetBrowserContext())
111 ->IsSupervised();
90 } 112 }
91 113
92 const std::vector<const content::NavigationEntry*>* 114 const std::vector<const sessions::SerializedNavigationEntry*>*
93 TabContentsSyncedTabDelegate::GetBlockedNavigations() const { 115 TabContentsSyncedTabDelegate::GetBlockedNavigations() const {
94 #if defined(ENABLE_SUPERVISED_USERS) 116 #if defined(ENABLE_SUPERVISED_USERS)
95 SupervisedUserNavigationObserver* navigation_observer = 117 SupervisedUserNavigationObserver* navigation_observer =
96 SupervisedUserNavigationObserver::FromWebContents(web_contents_); 118 SupervisedUserNavigationObserver::FromWebContents(web_contents_);
97 DCHECK(navigation_observer); 119 DCHECK(navigation_observer);
98 return navigation_observer->blocked_navigations(); 120 return navigation_observer->blocked_navigations();
99 #else 121 #else
100 NOTREACHED(); 122 NOTREACHED();
101 return NULL; 123 return NULL;
102 #endif 124 #endif
103 } 125 }
104 126
105 bool TabContentsSyncedTabDelegate::IsPinned() const { 127 bool TabContentsSyncedTabDelegate::IsPinned() const {
106 const browser_sync::SyncedWindowDelegate* window = GetSyncedWindowDelegate(); 128 const browser_sync::SyncedWindowDelegate* window = GetSyncedWindowDelegate();
107 129
108 // We might not have a parent window, e.g. Developer Tools. 130 // We might not have a parent window, e.g. Developer Tools.
109 return window ? window->IsTabPinned(this) : false; 131 return window ? window->IsTabPinned(this) : false;
110 } 132 }
111 133
112 bool TabContentsSyncedTabDelegate::HasWebContents() const { return true; } 134 bool TabContentsSyncedTabDelegate::HasWebContents() const { return true; }
113 135
114 content::WebContents* TabContentsSyncedTabDelegate::GetWebContents() const {
115 return web_contents_;
116 }
117
118 int TabContentsSyncedTabDelegate::GetSyncId() const { 136 int TabContentsSyncedTabDelegate::GetSyncId() const {
119 return sync_session_id_; 137 return sync_session_id_;
120 } 138 }
121 139
122 void TabContentsSyncedTabDelegate::SetSyncId(int sync_id) { 140 void TabContentsSyncedTabDelegate::SetSyncId(int sync_id) {
123 sync_session_id_ = sync_id; 141 sync_session_id_ = sync_id;
124 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698