wk_back_forward_list_item_holder.mm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015 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. #import "ios/web/navigation/wk_back_forward_list_item_holder.h"
  5. #include "base/memory/ptr_util.h"
  6. #import "ios/web/public/navigation/navigation_item.h"
  7. #if !defined(__has_feature) || !__has_feature(objc_arc)
  8. #error "This file requires ARC support."
  9. #endif
  10. namespace web {
  11. namespace {
  12. // Private key used for safe conversion of base::SupportsUserData to
  13. // web::WKBackForwardListItemHolder in
  14. // web::WKBackForwardListItemHolder::FromNavigationItem.
  15. const char kBackForwardListItemIdentifierKey[] =
  16. "BackForwardListItemIdentifierKey";
  17. }
  18. WKBackForwardListItemHolder::WKBackForwardListItemHolder()
  19. : navigation_type_(WKNavigationTypeOther) {}
  20. WKBackForwardListItemHolder::~WKBackForwardListItemHolder() {}
  21. // static
  22. WKBackForwardListItemHolder* WKBackForwardListItemHolder::FromNavigationItem(
  23. web::NavigationItem* item) {
  24. DCHECK(item);
  25. base::SupportsUserData::Data* user_data =
  26. item->GetUserData(kBackForwardListItemIdentifierKey);
  27. if (!user_data) {
  28. user_data = new WKBackForwardListItemHolder();
  29. item->SetUserData(kBackForwardListItemIdentifierKey,
  30. base::WrapUnique(user_data));
  31. }
  32. return static_cast<WKBackForwardListItemHolder*>(user_data);
  33. }
  34. } // namespace web