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 #include "ios/chrome/browser/ui/activity_services/share_to_data_builder.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ios/chrome/browser/tabs/tab.h" |
| 9 #include "ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail
_generator.h" |
| 10 #include "ios/chrome/browser/ui/activity_services/share_to_data.h" |
| 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 16 namespace activity_services { |
| 17 |
| 18 ShareToData* ShareToDataForTab(Tab* tab) { |
| 19 // For crash documented in crbug.com/503955, tab.url which is being passed |
| 20 // as a reference parameter caused a crash due to invalid address which |
| 21 // which suggests that |tab| may be deallocated along the way. Check that |
| 22 // tab is still valid by checking webState which would be deallocated if |
| 23 // tab is being closed. |
| 24 if (!tab.webState) |
| 25 return nil; |
| 26 DCHECK(tab); |
| 27 // If the original page title exists, it is expected to match the tab title. |
| 28 // If this ever changes, then a decision has to be made on which one should |
| 29 // be used for sharing. |
| 30 DCHECK(!tab.originalTitle || [tab.originalTitle isEqualToString:tab.title]); |
| 31 BOOL isPagePrintable = [tab viewForPrinting] != nil; |
| 32 ThumbnailGeneratorBlock thumbnailGenerator = |
| 33 activity_services::ThumbnailGeneratorForTab(tab); |
| 34 return [[ShareToData alloc] initWithURL:tab.url |
| 35 title:tab.title |
| 36 isOriginalTitle:(tab.originalTitle != nil) |
| 37 isPagePrintable:isPagePrintable |
| 38 thumbnailGenerator:thumbnailGenerator]; |
| 39 } |
| 40 |
| 41 } // namespace activity_services |
OLD | NEW |