Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Unified Diff: ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.mm

Issue 2645653003: Expose thumbnails of pages to iOS share extensions. (Closed)
Patch Set: Addressed comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.mm
diff --git a/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.mm b/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.mm
new file mode 100644
index 0000000000000000000000000000000000000000..69cff7c547c863fc989abe1f3b78b44f73f0865c
--- /dev/null
+++ b/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.mm
@@ -0,0 +1,35 @@
+// 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.
+
+#import "ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.h"
+
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#import "ios/chrome/browser/tabs/tab.h"
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace activity_services {
+
+ThumbnailGeneratorBlock ThumbnailGeneratorForTab(Tab* tab) {
+ DCHECK(tab);
+ // Do not generate thumbnails for incognito tabs.
+ if (tab.browserState->IsOffTheRecord()) {
+ return ^UIImage*(CGSize const& size) { return nil; };
+ } else {
+ __weak Tab* weakTab = tab;
+ return ^UIImage*(CGSize const& size) {
+ Tab* strongTab = weakTab;
+ UIImage* snapshot =
+ [strongTab generateSnapshotWithOverlay:NO visibleFrameOnly:YES];
+ UIImage* thumbnail =
+ ResizeImage(snapshot, size, ProjectionMode::kAspectFillAlignTop, YES);
+ return thumbnail;
+ };
+ }
+}
+
+} // namespace activity_services

Powered by Google App Engine
This is Rietveld 408576698