[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 1 | // Copyright 2013 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 | #include "chrome/browser/android/foreign_session_helper.h" |
| 6 | |
| 7 | #include <jni.h> |
| 8 | |
| 9 | #include "base/android/jni_string.h" |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 10 | #include "base/prefs/pref_service.h" |
[email protected] | 9eec53fe | 2013-10-30 20:21:17 | [diff] [blame] | 11 | #include "base/prefs/scoped_user_pref_update.h" |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 12 | #include "chrome/browser/android/tab_android.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 13 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile_android.h" |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 15 | #include "chrome/browser/sessions/session_restore.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 16 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 17 | #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 18 | #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 19 | #include "chrome/common/pref_names.h" |
| 20 | #include "chrome/common/url_constants.h" |
blundell | 7282b51 | 2015-11-09 07:21:11 | [diff] [blame] | 21 | #include "components/browser_sync/browser/profile_sync_service.h" |
maxbogue | 8ef2508 | 2015-11-16 19:09:58 | [diff] [blame] | 22 | #include "components/sync_sessions/open_tabs_ui_delegate.h" |
maxbogue | 5c8d0e2 | 2014-11-06 01:00:01 | [diff] [blame] | 23 | #include "content/public/browser/notification_details.h" |
| 24 | #include "content/public/browser/notification_service.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 25 | #include "content/public/browser/notification_source.h" |
| 26 | #include "content/public/browser/web_contents.h" |
| 27 | #include "jni/ForeignSessionHelper_jni.h" |
| 28 | |
| 29 | using base::android::ScopedJavaGlobalRef; |
| 30 | using base::android::ScopedJavaLocalRef; |
| 31 | using base::android::AttachCurrentThread; |
| 32 | using base::android::ConvertUTF16ToJavaString; |
| 33 | using base::android::ConvertUTF8ToJavaString; |
| 34 | using base::android::ConvertJavaStringToUTF8; |
droger | 6a11863 | 2015-06-23 17:59:45 | [diff] [blame] | 35 | using sync_driver::OpenTabsUIDelegate; |
| 36 | using sync_driver::SyncedSession; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 37 | |
| 38 | namespace { |
| 39 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 40 | OpenTabsUIDelegate* GetOpenTabsUIDelegate(Profile* profile) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 41 | ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 42 | GetForProfile(profile); |
| 43 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 44 | // Only return the delegate if it exists and it is done syncing sessions. |
maxbogue | 192b360 | 2015-06-04 00:33:55 | [diff] [blame] | 45 | if (!service || !service->IsSyncActive()) |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 46 | return NULL; |
| 47 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 48 | return service->GetOpenTabsUIDelegate(); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 49 | } |
| 50 | |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 51 | bool ShouldSkipTab(const sessions::SessionTab& session_tab) { |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 52 | if (session_tab.navigations.empty()) |
| 53 | return true; |
| 54 | |
maxbogue | 4157d2b | 2014-08-27 21:56:48 | [diff] [blame] | 55 | int selected_index = session_tab.normalized_navigation_index(); |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 56 | const sessions::SerializedNavigationEntry& current_navigation = |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 57 | session_tab.navigations.at(selected_index); |
| 58 | |
| 59 | if (current_navigation.virtual_url().is_empty()) |
| 60 | return true; |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 65 | bool ShouldSkipWindow(const sessions::SessionWindow& window) { |
| 66 | for (std::vector<sessions::SessionTab*>::const_iterator tab_it = |
| 67 | window.tabs.begin(); tab_it != window.tabs.end(); ++tab_it) { |
| 68 | const sessions::SessionTab &session_tab = **tab_it; |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 69 | if (!ShouldSkipTab(session_tab)) |
| 70 | return false; |
| 71 | } |
| 72 | return true; |
| 73 | } |
| 74 | |
droger | 6a11863 | 2015-06-23 17:59:45 | [diff] [blame] | 75 | bool ShouldSkipSession(const sync_driver::SyncedSession& session) { |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 76 | for (SyncedSession::SyncedWindowMap::const_iterator it = |
| 77 | session.windows.begin(); it != session.windows.end(); ++it) { |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 78 | const sessions::SessionWindow &window = *(it->second); |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 79 | if (!ShouldSkipWindow(window)) |
| 80 | return false; |
| 81 | } |
| 82 | return true; |
| 83 | } |
| 84 | |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 85 | void CopyTabToJava( |
| 86 | JNIEnv* env, |
| 87 | const sessions::SessionTab& tab, |
| 88 | ScopedJavaLocalRef<jobject>& j_window) { |
| 89 | int selected_index = tab.normalized_navigation_index(); |
| 90 | DCHECK_GE(selected_index, 0); |
| 91 | DCHECK_LT(selected_index, static_cast<int>(tab.navigations.size())); |
| 92 | |
| 93 | const sessions::SerializedNavigationEntry& current_navigation = |
| 94 | tab.navigations.at(selected_index); |
| 95 | |
| 96 | GURL tab_url = current_navigation.virtual_url(); |
| 97 | |
| 98 | Java_ForeignSessionHelper_pushTab( |
| 99 | env, j_window.obj(), |
| 100 | ConvertUTF8ToJavaString(env, tab_url.spec()).obj(), |
| 101 | ConvertUTF16ToJavaString(env, current_navigation.title()).obj(), |
| 102 | tab.timestamp.ToJavaTime(), |
| 103 | tab.tab_id.id()); |
| 104 | } |
| 105 | |
| 106 | void CopyWindowToJava( |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 107 | JNIEnv* env, |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 108 | const sessions::SessionWindow& window, |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 109 | ScopedJavaLocalRef<jobject>& j_window) { |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 110 | for (std::vector<sessions::SessionTab*>::const_iterator tab_it = |
| 111 | window.tabs.begin(); tab_it != window.tabs.end(); ++tab_it) { |
| 112 | const sessions::SessionTab &session_tab = **tab_it; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 113 | |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 114 | if (ShouldSkipTab(session_tab)) |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 115 | return; |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 116 | |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 117 | CopyTabToJava(env, session_tab, j_window); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 121 | void CopySessionToJava( |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 122 | JNIEnv* env, |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 123 | const SyncedSession& session, |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 124 | ScopedJavaLocalRef<jobject>& j_session) { |
| 125 | for (SyncedSession::SyncedWindowMap::const_iterator it = |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 126 | session.windows.begin(); it != session.windows.end(); ++it) { |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 127 | const sessions::SessionWindow &window = *(it->second); |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 128 | |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 129 | if (ShouldSkipWindow(window)) |
| 130 | continue; |
| 131 | |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 132 | ScopedJavaLocalRef<jobject> last_pushed_window; |
| 133 | last_pushed_window.Reset( |
| 134 | Java_ForeignSessionHelper_pushWindow( |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 135 | env, j_session.obj(), |
| 136 | window.timestamp.ToJavaTime(), |
| 137 | window.window_id.id())); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 138 | |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 139 | CopyWindowToJava(env, window, last_pushed_window); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
| 143 | } // namespace |
| 144 | |
torne | 89cc5d9 | 2015-09-04 11:16:35 | [diff] [blame] | 145 | static jlong Init(JNIEnv* env, |
| 146 | const JavaParamRef<jclass>& clazz, |
| 147 | const JavaParamRef<jobject>& profile) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 148 | ForeignSessionHelper* foreign_session_helper = new ForeignSessionHelper( |
| 149 | ProfileAndroid::FromProfileAndroid(profile)); |
[email protected] | d557b604 | 2013-11-21 16:34:31 | [diff] [blame] | 150 | return reinterpret_cast<intptr_t>(foreign_session_helper); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | ForeignSessionHelper::ForeignSessionHelper(Profile* profile) |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 154 | : profile_(profile), scoped_observer_(this) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 155 | ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 156 | GetForProfile(profile); |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 157 | |
| 158 | // NOTE: The ProfileSyncService can be null in tests. |
| 159 | if (service) |
| 160 | scoped_observer_.Add(service); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | ForeignSessionHelper::~ForeignSessionHelper() { |
| 164 | } |
| 165 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 166 | void ForeignSessionHelper::Destroy(JNIEnv* env, |
| 167 | const JavaParamRef<jobject>& obj) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 168 | delete this; |
| 169 | } |
| 170 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 171 | jboolean ForeignSessionHelper::IsTabSyncEnabled( |
| 172 | JNIEnv* env, |
| 173 | const JavaParamRef<jobject>& obj) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 174 | ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 175 | GetForProfile(profile_); |
| 176 | return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); |
| 177 | } |
| 178 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 179 | void ForeignSessionHelper::TriggerSessionSync( |
| 180 | JNIEnv* env, |
| 181 | const JavaParamRef<jobject>& obj) { |
blundell | 0631ab03 | 2015-10-29 09:28:02 | [diff] [blame] | 182 | ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 183 | GetForProfile(profile_); |
| 184 | if (!service) |
| 185 | return; |
| 186 | |
maxbogue | 5c8d0e2 | 2014-11-06 01:00:01 | [diff] [blame] | 187 | const syncer::ModelTypeSet types(syncer::SESSIONS); |
blundell | 0631ab03 | 2015-10-29 09:28:02 | [diff] [blame] | 188 | service->TriggerRefresh(types); |
maxbogue | 5c8d0e2 | 2014-11-06 01:00:01 | [diff] [blame] | 189 | } |
| 190 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 191 | void ForeignSessionHelper::SetOnForeignSessionCallback( |
| 192 | JNIEnv* env, |
| 193 | const JavaParamRef<jobject>& obj, |
| 194 | const JavaParamRef<jobject>& callback) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 195 | callback_.Reset(env, callback); |
| 196 | } |
| 197 | |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 198 | void ForeignSessionHelper::FireForeignSessionCallback() { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 199 | if (callback_.is_null()) |
| 200 | return; |
| 201 | |
| 202 | JNIEnv* env = AttachCurrentThread(); |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 203 | Java_ForeignSessionCallback_onUpdated(env, callback_.obj()); |
| 204 | } |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 205 | |
blundell | fc39f9aa | 2015-10-30 08:25:54 | [diff] [blame] | 206 | void ForeignSessionHelper::OnSyncConfigurationCompleted() { |
| 207 | FireForeignSessionCallback(); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 208 | } |
| 209 | |
blundell | fc39f9aa | 2015-10-30 08:25:54 | [diff] [blame] | 210 | void ForeignSessionHelper::OnForeignSessionUpdated() { |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 211 | FireForeignSessionCallback(); |
| 212 | } |
| 213 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 214 | jboolean ForeignSessionHelper::GetForeignSessions( |
| 215 | JNIEnv* env, |
| 216 | const JavaParamRef<jobject>& obj, |
| 217 | const JavaParamRef<jobject>& result) { |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 218 | OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 219 | if (!open_tabs) |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 220 | return false; |
| 221 | |
droger | 6a11863 | 2015-06-23 17:59:45 | [diff] [blame] | 222 | std::vector<const sync_driver::SyncedSession*> sessions; |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 223 | if (!open_tabs->GetAllForeignSessions(&sessions)) |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 224 | return false; |
| 225 | |
| 226 | // Use a pref to keep track of sessions that were collapsed by the user. |
| 227 | // To prevent the pref from accumulating stale sessions, clear it each time |
| 228 | // and only add back sessions that are still current. |
| 229 | DictionaryPrefUpdate pref_update(profile_->GetPrefs(), |
| 230 | prefs::kNtpCollapsedForeignSessions); |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 231 | base::DictionaryValue* pref_collapsed_sessions = pref_update.Get(); |
| 232 | scoped_ptr<base::DictionaryValue> collapsed_sessions( |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 233 | pref_collapsed_sessions->DeepCopy()); |
| 234 | pref_collapsed_sessions->Clear(); |
| 235 | |
| 236 | ScopedJavaLocalRef<jobject> last_pushed_session; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 237 | |
| 238 | // Note: we don't own the SyncedSessions themselves. |
| 239 | for (size_t i = 0; i < sessions.size(); ++i) { |
droger | 6a11863 | 2015-06-23 17:59:45 | [diff] [blame] | 240 | const sync_driver::SyncedSession& session = *(sessions[i]); |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 241 | if (ShouldSkipSession(session)) |
| 242 | continue; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 243 | |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 244 | const bool is_collapsed = collapsed_sessions->HasKey(session.session_tag); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 245 | |
| 246 | if (is_collapsed) |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 247 | pref_collapsed_sessions->SetBoolean(session.session_tag, true); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 248 | |
| 249 | last_pushed_session.Reset( |
| 250 | Java_ForeignSessionHelper_pushSession( |
| 251 | env, |
| 252 | result, |
[email protected] | c2a6ac3 | 2014-04-27 00:18:09 | [diff] [blame] | 253 | ConvertUTF8ToJavaString(env, session.session_tag).obj(), |
| 254 | ConvertUTF8ToJavaString(env, session.session_name).obj(), |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 255 | session.device_type, |
| 256 | session.modified_time.ToJavaTime())); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 257 | |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 258 | const std::string group_name = |
| 259 | base::FieldTrialList::FindFullName("TabSyncByRecency"); |
| 260 | if (group_name == "Enabled") { |
| 261 | // Create a custom window with tabs from all windows included and ordered |
| 262 | // by recency (GetForeignSessionTabs will do ordering automatically). |
| 263 | std::vector<const sessions::SessionTab*> tabs; |
| 264 | open_tabs->GetForeignSessionTabs(session.session_tag, &tabs); |
| 265 | ScopedJavaLocalRef<jobject> last_pushed_window( |
| 266 | Java_ForeignSessionHelper_pushWindow( |
| 267 | env, last_pushed_session.obj(), |
| 268 | session.modified_time.ToJavaTime(), 0)); |
| 269 | for (const sessions::SessionTab* tab : tabs) { |
| 270 | if (ShouldSkipTab(*tab)) |
| 271 | continue; |
| 272 | CopyTabToJava(env, *tab, last_pushed_window); |
| 273 | } |
| 274 | } else { |
| 275 | // Push the full session, with tabs ordered by visual position. |
| 276 | CopySessionToJava(env, session, last_pushed_session); |
| 277 | } |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | return true; |
| 281 | } |
| 282 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 283 | jboolean ForeignSessionHelper::OpenForeignSessionTab( |
| 284 | JNIEnv* env, |
| 285 | const JavaParamRef<jobject>& obj, |
| 286 | const JavaParamRef<jobject>& j_tab, |
| 287 | const JavaParamRef<jstring>& session_tag, |
| 288 | jint session_tab_id, |
| 289 | jint j_disposition) { |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 290 | OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 291 | if (!open_tabs) { |
| 292 | LOG(ERROR) << "Null OpenTabsUIDelegate returned."; |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 293 | return false; |
| 294 | } |
| 295 | |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 296 | const sessions::SessionTab* session_tab; |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 297 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 298 | if (!open_tabs->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), |
| 299 | session_tab_id, |
| 300 | &session_tab)) { |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 301 | LOG(ERROR) << "Failed to load foreign tab."; |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | if (session_tab->navigations.empty()) { |
| 306 | LOG(ERROR) << "Foreign tab no longer has valid navigations."; |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | TabAndroid* tab_android = TabAndroid::GetNativeTab(env, j_tab); |
| 311 | if (!tab_android) |
| 312 | return false; |
| 313 | content::WebContents* web_contents = tab_android->web_contents(); |
| 314 | if (!web_contents) |
| 315 | return false; |
| 316 | |
| 317 | WindowOpenDisposition disposition = |
| 318 | static_cast<WindowOpenDisposition>(j_disposition); |
| 319 | SessionRestore::RestoreForeignSessionTab(web_contents, |
| 320 | *session_tab, |
| 321 | disposition); |
| 322 | |
| 323 | return true; |
| 324 | } |
| 325 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame^] | 326 | void ForeignSessionHelper::DeleteForeignSession( |
| 327 | JNIEnv* env, |
| 328 | const JavaParamRef<jobject>& obj, |
| 329 | const JavaParamRef<jstring>& session_tag) { |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 330 | OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 331 | if (open_tabs) |
| 332 | open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | // static |
| 336 | bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { |
| 337 | return RegisterNativesImpl(env); |
| 338 | } |