Index: chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java b/chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a36997b0832a7864020111726931c08e59c2afda |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java |
@@ -0,0 +1,50 @@ |
+// Copyright 2013 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. |
+ |
+package org.chromium.chrome.browser.printing; |
+ |
+import android.text.TextUtils; |
+ |
+import org.chromium.chrome.browser.TabBase; |
+import org.chromium.printing.Printable; |
+ |
+import java.lang.ref.WeakReference; |
+ |
+/** |
+ * Wraps printing related functionality of a Tab object. |
whywhat
2013/11/19 15:39:32
s/Tab/TabBase
nit: maybe even {@link TabBase} ?
cimamoglu1
2013/11/19 17:40:33
Done.
|
+ * |
+ * This class doesn't have any lifetime expectations with regards to Tab, since we keep a week |
bulach
2013/11/19 15:32:22
nit: s/week/weak/
whywhat
2013/11/19 15:39:32
ditto
s/week/weak
cimamoglu1
2013/11/19 17:40:33
Done.
|
+ * reference. |
+ */ |
+public class TabPrinter implements Printable { |
+ private final WeakReference<TabBase> mTab; |
+ |
+ private final String mDefaultTitle; |
+ |
+ public TabPrinter(final TabBase tab, String defaultTitle) { |
+ mTab = new WeakReference<TabBase>(tab); |
+ mDefaultTitle = defaultTitle; |
+ } |
+ |
+ @Override |
+ public boolean print() { |
+ TabBase tab = mTab.get(); |
bulach
2013/11/19 15:32:22
nit: indent
whywhat
2013/11/19 15:39:32
indent
cimamoglu1
2013/11/19 17:40:33
Done.
|
+ if (tab == null) return false; |
+ return tab.print(); |
+ } |
+ |
+ @Override |
+ public String getTitle() { |
+ TabBase tab = mTab.get(); |
bulach
2013/11/19 15:32:22
nit: indent
whywhat
2013/11/19 15:39:32
indent
cimamoglu1
2013/11/19 17:40:33
Done.
|
+ if (tab == null) return mDefaultTitle; |
+ |
+ String title = tab.getTitle(); |
+ if (!TextUtils.isEmpty(title)) return title; |
+ |
+ String url = tab.getUrl(); |
+ if (!TextUtils.isEmpty(url)) return url; |
+ |
+ return mDefaultTitle; |
+ } |
+} |