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