| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.printing; | 5 package org.chromium.chrome.browser.printing; |
| 6 | 6 |
| 7 import android.text.TextUtils; | 7 import android.text.TextUtils; |
| 8 | 8 |
| 9 import org.chromium.chrome.browser.TabBase; | 9 import org.chromium.chrome.browser.Tab; |
| 10 import org.chromium.printing.Printable; | 10 import org.chromium.printing.Printable; |
| 11 | 11 |
| 12 import java.lang.ref.WeakReference; | 12 import java.lang.ref.WeakReference; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Wraps printing related functionality of a {@link TabBase} object. | 15 * Wraps printing related functionality of a {@link Tab} object. |
| 16 * | 16 * |
| 17 * This class doesn't have any lifetime expectations with regards to Tab, since
we keep a weak | 17 * This class doesn't have any lifetime expectations with regards to Tab, since
we keep a weak |
| 18 * reference. | 18 * reference. |
| 19 */ | 19 */ |
| 20 public class TabPrinter implements Printable { | 20 public class TabPrinter implements Printable { |
| 21 private static String sDefaultTitle; | 21 private static String sDefaultTitle; |
| 22 | 22 |
| 23 private final WeakReference<TabBase> mTab; | 23 private final WeakReference<Tab> mTab; |
| 24 | 24 |
| 25 public TabPrinter(TabBase tab) { | 25 public TabPrinter(Tab tab) { |
| 26 mTab = new WeakReference<TabBase>(tab); | 26 mTab = new WeakReference<Tab>(tab); |
| 27 } | 27 } |
| 28 | 28 |
| 29 public static void setDefaultTitle(String defaultTitle) { | 29 public static void setDefaultTitle(String defaultTitle) { |
| 30 sDefaultTitle = defaultTitle; | 30 sDefaultTitle = defaultTitle; |
| 31 } | 31 } |
| 32 | 32 |
| 33 @Override | 33 @Override |
| 34 public boolean print() { | 34 public boolean print() { |
| 35 TabBase tab = mTab.get(); | 35 Tab tab = mTab.get(); |
| 36 return tab != null && tab.print(); | 36 return tab != null && tab.print(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 @Override | 39 @Override |
| 40 public String getTitle() { | 40 public String getTitle() { |
| 41 TabBase tab = mTab.get(); | 41 Tab tab = mTab.get(); |
| 42 if (tab == null) return sDefaultTitle; | 42 if (tab == null) return sDefaultTitle; |
| 43 | 43 |
| 44 String title = tab.getTitle(); | 44 String title = tab.getTitle(); |
| 45 if (!TextUtils.isEmpty(title)) return title; | 45 if (!TextUtils.isEmpty(title)) return title; |
| 46 | 46 |
| 47 String url = tab.getUrl(); | 47 String url = tab.getUrl(); |
| 48 if (!TextUtils.isEmpty(url)) return url; | 48 if (!TextUtils.isEmpty(url)) return url; |
| 49 | 49 |
| 50 return sDefaultTitle; | 50 return sDefaultTitle; |
| 51 } | 51 } |
| 52 } | 52 } |
| OLD | NEW |