Chromium Code Reviews| Index: ios/chrome/browser/ui/activity_services/share_to_data_builder.mm |
| diff --git a/ios/chrome/browser/ui/activity_services/share_to_data_builder.mm b/ios/chrome/browser/ui/activity_services/share_to_data_builder.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f56ea6b567871152fc8cf007228745a2d8582090 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/activity_services/share_to_data_builder.mm |
| @@ -0,0 +1,41 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/chrome/browser/ui/activity_services/share_to_data_builder.h" |
| + |
| +#include "base/logging.h" |
| +#include "ios/chrome/browser/tabs/tab.h" |
| +#include "ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.h" |
| +#include "ios/chrome/browser/ui/activity_services/share_to_data.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace activity_services { |
| + |
| +ShareToData* ShareToDataFromTab(Tab* tab) { |
| + // For crash documented in crbug.com/503955, tab.url which is being passed |
| + // as a reference parameter caused a crash due to invalid address which |
| + // which suggests that |tab| may be deallocated along the way. Check that |
| + // tab is still valid by checking webState which would be deallocated if |
| + // tab is being closed. |
| + if (!tab.webState) |
| + return nil; |
| + DCHECK(tab); |
| + // If the original page title exists, it is expected to match the tab title. |
| + // If this ever changes, then a decision has to be made on which one should |
| + // be used for sharing. |
| + DCHECK(!tab.originalTitle || [tab.originalTitle isEqualToString:tab.title]); |
| + BOOL isPagePrintable = [tab viewForPrinting] != nil; |
|
Olivier
2017/01/20 10:14:00
C++ case
jif
2017/01/24 10:29:50
It's an obj-c++ function with no c++ functionality
|
| + ThumbnailGenerator thumbnailGenerator = |
| + activity_services::thumbNailGeneratorForTab(tab); |
| + return [[ShareToData alloc] initWithURL:tab.url |
| + title:tab.title |
| + isOriginalTitle:(tab.originalTitle != nil) |
| + isPagePrintable:isPagePrintable |
| + thumbnailGenerator:thumbnailGenerator]; |
| +} |
| + |
| +} // namespace activity_services |