OLD | NEW |
(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 #import "ios/chrome/browser/web/tab_id_tab_helper.h" |
| 6 |
| 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 #import "ios/web/public/serializable_user_data_manager.h" |
| 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 15 DEFINE_WEB_STATE_USER_DATA_KEY(TabIdTabHelper); |
| 16 |
| 17 namespace { |
| 18 // The key under which the tab ID is stored in the WebState's serializable user |
| 19 // data. |
| 20 NSString* const kTabIdKey = @"TabId"; |
| 21 } |
| 22 |
| 23 TabIdTabHelper::TabIdTabHelper(web::WebState* web_state) { |
| 24 web::SerializableUserDataManager* user_data_manager = |
| 25 web::SerializableUserDataManager::FromWebState(web_state); |
| 26 NSString* unique_id = base::mac::ObjCCast<NSString>( |
| 27 user_data_manager->GetValueForSerializationKey(kTabIdKey)); |
| 28 if (![unique_id length]) { |
| 29 unique_id = [[NSUUID UUID] UUIDString]; |
| 30 user_data_manager->AddSerializableData(unique_id, kTabIdKey); |
| 31 } |
| 32 tab_id_ = [unique_id copy]; |
| 33 } |
| 34 |
| 35 TabIdTabHelper::~TabIdTabHelper() = default; |
OLD | NEW |