[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> |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 8 | #include <stddef.h> |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 9 | |
| 10 | #include "base/android/jni_string.h" |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 11 | #include "chrome/browser/android/tab_android.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 12 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 13 | #include "chrome/browser/profiles/profile_android.h" |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 14 | #include "chrome/browser/sessions/session_restore.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 15 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 16 | #include "chrome/browser/sync/session_sync_service_factory.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 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" |
maxbogue | 26f4022 | 2016-09-16 20:22:18 | [diff] [blame] | 21 | #include "components/browser_sync/profile_sync_service.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 22 | #include "components/prefs/pref_service.h" |
| 23 | #include "components/prefs/scoped_user_pref_update.h" |
maxbogue | 8ef2508 | 2015-11-16 19:09:58 | [diff] [blame] | 24 | #include "components/sync_sessions/open_tabs_ui_delegate.h" |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 25 | #include "components/sync_sessions/session_sync_service.h" |
maxbogue | 5c8d0e2 | 2014-11-06 01:00:01 | [diff] [blame] | 26 | #include "content/public/browser/notification_details.h" |
| 27 | #include "content/public/browser/notification_service.h" |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 28 | #include "content/public/browser/notification_source.h" |
| 29 | #include "content/public/browser/web_contents.h" |
| 30 | #include "jni/ForeignSessionHelper_jni.h" |
| 31 | |
torne | 8656011 | 2016-08-04 15:59:04 | [diff] [blame] | 32 | using base::android::JavaParamRef; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 33 | using base::android::ScopedJavaGlobalRef; |
| 34 | using base::android::ScopedJavaLocalRef; |
| 35 | using base::android::AttachCurrentThread; |
| 36 | using base::android::ConvertUTF16ToJavaString; |
| 37 | using base::android::ConvertUTF8ToJavaString; |
| 38 | using base::android::ConvertJavaStringToUTF8; |
maxbogue | a79d99b7 | 2016-09-15 15:59:16 | [diff] [blame] | 39 | using sync_sessions::OpenTabsUIDelegate; |
| 40 | using sync_sessions::SyncedSession; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 41 | |
| 42 | namespace { |
| 43 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 44 | OpenTabsUIDelegate* GetOpenTabsUIDelegate(Profile* profile) { |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 45 | sync_sessions::SessionSyncService* service = |
| 46 | SessionSyncServiceFactory::GetInstance()->GetForProfile(profile); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 47 | |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 48 | // Only return the delegate if it exists. |
| 49 | if (!service) |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 50 | return NULL; |
| 51 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 52 | return service->GetOpenTabsUIDelegate(); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 53 | } |
| 54 | |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 55 | bool ShouldSkipTab(const sessions::SessionTab& session_tab) { |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 56 | if (session_tab.navigations.empty()) |
| 57 | return true; |
| 58 | |
maxbogue | 4157d2b | 2014-08-27 21:56:48 | [diff] [blame] | 59 | int selected_index = session_tab.normalized_navigation_index(); |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 60 | const sessions::SerializedNavigationEntry& current_navigation = |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 61 | session_tab.navigations.at(selected_index); |
| 62 | |
| 63 | if (current_navigation.virtual_url().is_empty()) |
| 64 | return true; |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 69 | bool ShouldSkipWindow(const sessions::SessionWindow& window) { |
avi | 498cabca | 2016-09-21 19:03:50 | [diff] [blame] | 70 | for (const auto& tab_ptr : window.tabs) { |
| 71 | const sessions::SessionTab& session_tab = *(tab_ptr.get()); |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 72 | if (!ShouldSkipTab(session_tab)) |
| 73 | return false; |
| 74 | } |
| 75 | return true; |
| 76 | } |
| 77 | |
maxbogue | a79d99b7 | 2016-09-15 15:59:16 | [diff] [blame] | 78 | bool ShouldSkipSession(const SyncedSession& session) { |
avi | 498cabca | 2016-09-21 19:03:50 | [diff] [blame] | 79 | for (const auto& window_pair : session.windows) { |
zea | 325508e | 2017-03-29 20:11:22 | [diff] [blame] | 80 | const sessions::SessionWindow& window = window_pair.second->wrapped_window; |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 81 | if (!ShouldSkipWindow(window)) |
| 82 | return false; |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 87 | void JNI_ForeignSessionHelper_CopyTabToJava( |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 88 | JNIEnv* env, |
| 89 | const sessions::SessionTab& tab, |
| 90 | ScopedJavaLocalRef<jobject>& j_window) { |
| 91 | int selected_index = tab.normalized_navigation_index(); |
| 92 | DCHECK_GE(selected_index, 0); |
| 93 | DCHECK_LT(selected_index, static_cast<int>(tab.navigations.size())); |
| 94 | |
| 95 | const sessions::SerializedNavigationEntry& current_navigation = |
| 96 | tab.navigations.at(selected_index); |
| 97 | |
| 98 | GURL tab_url = current_navigation.virtual_url(); |
| 99 | |
| 100 | Java_ForeignSessionHelper_pushTab( |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 101 | env, j_window, ConvertUTF8ToJavaString(env, tab_url.spec()), |
| 102 | ConvertUTF16ToJavaString(env, current_navigation.title()), |
| 103 | tab.timestamp.ToJavaTime(), tab.tab_id.id()); |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 104 | } |
| 105 | |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 106 | void JNI_ForeignSessionHelper_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) { |
avi | 498cabca | 2016-09-21 19:03:50 | [diff] [blame] | 110 | for (const auto& tab_ptr : window.tabs) { |
| 111 | const sessions::SessionTab& session_tab = *(tab_ptr.get()); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 112 | |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 113 | if (ShouldSkipTab(session_tab)) |
zea | e8f0c131d | 2015-08-04 23:20:27 | [diff] [blame] | 114 | return; |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 115 | |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 116 | JNI_ForeignSessionHelper_CopyTabToJava(env, session_tab, j_window); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 120 | void JNI_ForeignSessionHelper_CopySessionToJava( |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 121 | JNIEnv* env, |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 122 | const SyncedSession& session, |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 123 | ScopedJavaLocalRef<jobject>& j_session) { |
avi | 498cabca | 2016-09-21 19:03:50 | [diff] [blame] | 124 | for (const auto& window_pair : session.windows) { |
zea | 325508e | 2017-03-29 20:11:22 | [diff] [blame] | 125 | const sessions::SessionWindow& window = window_pair.second->wrapped_window; |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 126 | |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 127 | if (ShouldSkipWindow(window)) |
| 128 | continue; |
| 129 | |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 130 | ScopedJavaLocalRef<jobject> last_pushed_window; |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 131 | last_pushed_window.Reset(Java_ForeignSessionHelper_pushWindow( |
| 132 | env, j_session, window.timestamp.ToJavaTime(), window.window_id.id())); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 133 | |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 134 | JNI_ForeignSessionHelper_CopyWindowToJava(env, window, last_pushed_window); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | } // namespace |
| 139 | |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 140 | static jlong JNI_ForeignSessionHelper_Init( |
| 141 | JNIEnv* env, |
| 142 | const JavaParamRef<jclass>& clazz, |
| 143 | const JavaParamRef<jobject>& profile) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 144 | ForeignSessionHelper* foreign_session_helper = new ForeignSessionHelper( |
| 145 | ProfileAndroid::FromProfileAndroid(profile)); |
[email protected] | d557b604 | 2013-11-21 16:34:31 | [diff] [blame] | 146 | return reinterpret_cast<intptr_t>(foreign_session_helper); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | ForeignSessionHelper::ForeignSessionHelper(Profile* profile) |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 150 | : profile_(profile) { |
| 151 | sync_sessions::SessionSyncService* service = |
| 152 | SessionSyncServiceFactory::GetInstance()->GetForProfile(profile); |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 153 | |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 154 | // NOTE: The SessionSyncService can be null in tests. |
| 155 | if (service) { |
| 156 | // base::Unretained() is safe below because the subscription itself is a |
| 157 | // class member field and handles destruction well. |
| 158 | foreign_session_updated_subscription_ = |
| 159 | service->SubscribeToForeignSessionsChanged(base::BindRepeating( |
| 160 | &ForeignSessionHelper::FireForeignSessionCallback, |
| 161 | base::Unretained(this))); |
| 162 | } |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | ForeignSessionHelper::~ForeignSessionHelper() { |
| 166 | } |
| 167 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 168 | void ForeignSessionHelper::Destroy(JNIEnv* env, |
| 169 | const JavaParamRef<jobject>& obj) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 170 | delete this; |
| 171 | } |
| 172 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 173 | jboolean ForeignSessionHelper::IsTabSyncEnabled( |
| 174 | JNIEnv* env, |
| 175 | const JavaParamRef<jobject>& obj) { |
Mikel Astiz | 0dd1e66b | 2018-11-12 10:08:57 | [diff] [blame^] | 176 | sync_sessions::SessionSyncService* service = |
| 177 | SessionSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 178 | return service && service->GetOpenTabsUIDelegate(); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 179 | } |
| 180 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 181 | void ForeignSessionHelper::TriggerSessionSync( |
| 182 | JNIEnv* env, |
| 183 | const JavaParamRef<jobject>& obj) { |
maxbogue | 0a37945 | 2016-09-22 21:35:05 | [diff] [blame] | 184 | browser_sync::ProfileSyncService* service = |
| 185 | ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
blundell | 0631ab03 | 2015-10-29 09:28:02 | [diff] [blame] | 186 | if (!service) |
| 187 | return; |
| 188 | |
maxbogue | 5c8d0e2 | 2014-11-06 01:00:01 | [diff] [blame] | 189 | const syncer::ModelTypeSet types(syncer::SESSIONS); |
blundell | 0631ab03 | 2015-10-29 09:28:02 | [diff] [blame] | 190 | service->TriggerRefresh(types); |
maxbogue | 5c8d0e2 | 2014-11-06 01:00:01 | [diff] [blame] | 191 | } |
| 192 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 193 | void ForeignSessionHelper::SetOnForeignSessionCallback( |
| 194 | JNIEnv* env, |
| 195 | const JavaParamRef<jobject>& obj, |
| 196 | const JavaParamRef<jobject>& callback) { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 197 | callback_.Reset(env, callback); |
| 198 | } |
| 199 | |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 200 | void ForeignSessionHelper::FireForeignSessionCallback() { |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 201 | if (callback_.is_null()) |
| 202 | return; |
| 203 | |
| 204 | JNIEnv* env = AttachCurrentThread(); |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 205 | Java_ForeignSessionCallback_onUpdated(env, callback_); |
blundell | bbdc8a8 | 2015-10-28 15:47:20 | [diff] [blame] | 206 | } |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 207 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 208 | jboolean ForeignSessionHelper::GetForeignSessions( |
| 209 | JNIEnv* env, |
| 210 | const JavaParamRef<jobject>& obj, |
| 211 | const JavaParamRef<jobject>& result) { |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 212 | OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 213 | if (!open_tabs) |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 214 | return false; |
| 215 | |
maxbogue | a79d99b7 | 2016-09-15 15:59:16 | [diff] [blame] | 216 | std::vector<const SyncedSession*> sessions; |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 217 | if (!open_tabs->GetAllForeignSessions(&sessions)) |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 218 | return false; |
| 219 | |
| 220 | // Use a pref to keep track of sessions that were collapsed by the user. |
| 221 | // To prevent the pref from accumulating stale sessions, clear it each time |
| 222 | // and only add back sessions that are still current. |
| 223 | DictionaryPrefUpdate pref_update(profile_->GetPrefs(), |
| 224 | prefs::kNtpCollapsedForeignSessions); |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 225 | base::DictionaryValue* pref_collapsed_sessions = pref_update.Get(); |
dcheng | aeceb05e | 2016-04-07 23:41:10 | [diff] [blame] | 226 | std::unique_ptr<base::DictionaryValue> collapsed_sessions( |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 227 | pref_collapsed_sessions->DeepCopy()); |
| 228 | pref_collapsed_sessions->Clear(); |
| 229 | |
| 230 | ScopedJavaLocalRef<jobject> last_pushed_session; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 231 | |
| 232 | // Note: we don't own the SyncedSessions themselves. |
| 233 | for (size_t i = 0; i < sessions.size(); ++i) { |
maxbogue | a79d99b7 | 2016-09-15 15:59:16 | [diff] [blame] | 234 | const SyncedSession& session = *(sessions[i]); |
[email protected] | 48bf157 | 2014-08-12 01:31:09 | [diff] [blame] | 235 | if (ShouldSkipSession(session)) |
| 236 | continue; |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 237 | |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 238 | const bool is_collapsed = collapsed_sessions->HasKey(session.session_tag); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 239 | |
| 240 | if (is_collapsed) |
[email protected] | 9744a15e | 2013-09-23 20:59:08 | [diff] [blame] | 241 | pref_collapsed_sessions->SetBoolean(session.session_tag, true); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 242 | |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 243 | last_pushed_session.Reset(Java_ForeignSessionHelper_pushSession( |
| 244 | env, result, ConvertUTF8ToJavaString(env, session.session_tag), |
| 245 | ConvertUTF8ToJavaString(env, session.session_name), session.device_type, |
| 246 | session.modified_time.ToJavaTime())); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 247 | |
Mikel Astiz | b1513e6 | 2018-04-05 16:38:13 | [diff] [blame] | 248 | // Push the full session, with tabs ordered by visual position. |
| 249 | JNI_ForeignSessionHelper_CopySessionToJava(env, session, |
| 250 | last_pushed_session); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | return true; |
| 254 | } |
| 255 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 256 | jboolean ForeignSessionHelper::OpenForeignSessionTab( |
| 257 | JNIEnv* env, |
| 258 | const JavaParamRef<jobject>& obj, |
| 259 | const JavaParamRef<jobject>& j_tab, |
| 260 | const JavaParamRef<jstring>& session_tag, |
| 261 | jint session_tab_id, |
| 262 | jint j_disposition) { |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 263 | OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 264 | if (!open_tabs) { |
| 265 | LOG(ERROR) << "Null OpenTabsUIDelegate returned."; |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 266 | return false; |
| 267 | } |
| 268 | |
skuhne | b7409dcf | 2014-11-14 04:06:55 | [diff] [blame] | 269 | const sessions::SessionTab* session_tab; |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 270 | |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 271 | if (!open_tabs->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), |
Mikel Astiz | e023c57 | 2018-03-28 07:56:56 | [diff] [blame] | 272 | SessionID::FromSerializedValue(session_tab_id), |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 273 | &session_tab)) { |
[email protected] | 816939d | 2013-11-13 00:57:39 | [diff] [blame] | 274 | LOG(ERROR) << "Failed to load foreign tab."; |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | if (session_tab->navigations.empty()) { |
| 279 | LOG(ERROR) << "Foreign tab no longer has valid navigations."; |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | TabAndroid* tab_android = TabAndroid::GetNativeTab(env, j_tab); |
| 284 | if (!tab_android) |
| 285 | return false; |
| 286 | content::WebContents* web_contents = tab_android->web_contents(); |
| 287 | if (!web_contents) |
| 288 | return false; |
| 289 | |
| 290 | WindowOpenDisposition disposition = |
| 291 | static_cast<WindowOpenDisposition>(j_disposition); |
| 292 | SessionRestore::RestoreForeignSessionTab(web_contents, |
| 293 | *session_tab, |
| 294 | disposition); |
| 295 | |
| 296 | return true; |
| 297 | } |
| 298 | |
torne | e621a27 | 2015-11-30 18:40:53 | [diff] [blame] | 299 | void ForeignSessionHelper::DeleteForeignSession( |
| 300 | JNIEnv* env, |
| 301 | const JavaParamRef<jobject>& obj, |
| 302 | const JavaParamRef<jstring>& session_tag) { |
[email protected] | a9f5662 | 2013-11-21 19:37:06 | [diff] [blame] | 303 | OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 304 | if (open_tabs) |
| 305 | open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
[email protected] | 5365e52c | 2013-07-31 23:07:17 | [diff] [blame] | 306 | } |