OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.Color; | 10 import android.graphics.Color; |
| 11 import android.util.Log; |
11 import android.view.ContextMenu; | 12 import android.view.ContextMenu; |
12 import android.view.View; | 13 import android.view.View; |
13 | 14 |
14 import org.chromium.base.CalledByNative; | 15 import org.chromium.base.CalledByNative; |
15 import org.chromium.base.ObserverList; | 16 import org.chromium.base.ObserverList; |
16 import org.chromium.base.TraceEvent; | 17 import org.chromium.base.TraceEvent; |
17 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
18 import org.chromium.chrome.R; | 19 import org.chromium.chrome.R; |
19 import org.chromium.chrome.browser.banners.AppBannerManager; | 20 import org.chromium.chrome.browser.banners.AppBannerManager; |
20 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItemDelegate; | 21 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItemDelegate; |
21 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; | 22 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; |
22 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; | 23 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; |
23 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; | 24 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; |
24 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulatorWrapper; | 25 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulatorWrapper; |
25 import org.chromium.chrome.browser.contextmenu.EmptyChromeContextMenuItemDelegat
e; | 26 import org.chromium.chrome.browser.contextmenu.EmptyChromeContextMenuItemDelegat
e; |
26 import org.chromium.chrome.browser.dom_distiller.DomDistillerFeedbackReporter; | 27 import org.chromium.chrome.browser.dom_distiller.DomDistillerFeedbackReporter; |
27 import org.chromium.chrome.browser.infobar.AutoLoginProcessor; | 28 import org.chromium.chrome.browser.infobar.AutoLoginProcessor; |
28 import org.chromium.chrome.browser.infobar.InfoBarContainer; | 29 import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| 30 import org.chromium.chrome.browser.printing.TabPrinter; |
29 import org.chromium.chrome.browser.profiles.Profile; | 31 import org.chromium.chrome.browser.profiles.Profile; |
30 import org.chromium.chrome.browser.toolbar.ToolbarModel; | 32 import org.chromium.chrome.browser.toolbar.ToolbarModel; |
31 import org.chromium.content.browser.ContentView; | 33 import org.chromium.content.browser.ContentView; |
32 import org.chromium.content.browser.ContentViewClient; | 34 import org.chromium.content.browser.ContentViewClient; |
33 import org.chromium.content.browser.ContentViewCore; | 35 import org.chromium.content.browser.ContentViewCore; |
34 import org.chromium.content.browser.WebContentsObserver; | 36 import org.chromium.content.browser.WebContentsObserver; |
35 import org.chromium.content_public.browser.LoadUrlParams; | 37 import org.chromium.content_public.browser.LoadUrlParams; |
36 import org.chromium.content_public.browser.WebContents; | 38 import org.chromium.content_public.browser.WebContents; |
| 39 import org.chromium.printing.PrintManagerDelegateImpl; |
| 40 import org.chromium.printing.PrintingController; |
| 41 import org.chromium.printing.PrintingControllerImpl; |
37 import org.chromium.ui.base.Clipboard; | 42 import org.chromium.ui.base.Clipboard; |
38 import org.chromium.ui.base.WindowAndroid; | 43 import org.chromium.ui.base.WindowAndroid; |
39 import org.chromium.ui.gfx.DeviceDisplayInfo; | 44 import org.chromium.ui.gfx.DeviceDisplayInfo; |
40 | 45 |
41 import java.util.concurrent.atomic.AtomicInteger; | 46 import java.util.concurrent.atomic.AtomicInteger; |
42 | 47 |
43 /** | 48 /** |
44 * The basic Java representation of a tab. Contains and manages a {@link Conten
tView}. | 49 * The basic Java representation of a tab. Contains and manages a {@link Conten
tView}. |
45 * | 50 * |
46 * Tab provides common functionality for ChromeShell Tab as well as Chrome on An
droid's | 51 * Tab provides common functionality for ChromeShell Tab as well as Chrome on An
droid's |
(...skipping 20 matching lines...) Expand all Loading... |
67 * Some {@link Activity}s will not call this because they do not persist stat
e, which means those | 72 * Some {@link Activity}s will not call this because they do not persist stat
e, which means those |
68 * ids can potentially conflict with the ones restored from persisted state dep
ending on which | 73 * ids can potentially conflict with the ones restored from persisted state dep
ending on which |
69 * {@link Activity} runs first on process start. If {@link Tab}s are ever shar
ed across | 74 * {@link Activity} runs first on process start. If {@link Tab}s are ever shar
ed across |
70 * {@link Activity}s or mixed with {@link Tab}s from other {@link Activity}s co
nflicts can occur | 75 * {@link Activity}s or mixed with {@link Tab}s from other {@link Activity}s co
nflicts can occur |
71 * unless special care is taken to make sure {@link Tab#incrementIdCounterTo(in
t)} is called with | 76 * unless special care is taken to make sure {@link Tab#incrementIdCounterTo(in
t)} is called with |
72 * the correct value across all affected {@link Activity}s. | 77 * the correct value across all affected {@link Activity}s. |
73 */ | 78 */ |
74 public class Tab { | 79 public class Tab { |
75 public static final int INVALID_TAB_ID = -1; | 80 public static final int INVALID_TAB_ID = -1; |
76 | 81 |
| 82 /** Tag used for logging */ |
| 83 private static final String TAG = "Tab"; |
| 84 |
77 /** Used for automatically generating tab ids. */ | 85 /** Used for automatically generating tab ids. */ |
78 private static final AtomicInteger sIdCounter = new AtomicInteger(); | 86 private static final AtomicInteger sIdCounter = new AtomicInteger(); |
79 | 87 |
| 88 private final boolean mDebug = true; |
| 89 |
80 private long mNativeTabAndroid; | 90 private long mNativeTabAndroid; |
81 | 91 |
82 /** Unique id of this tab (within its container). */ | 92 /** Unique id of this tab (within its container). */ |
83 private final int mId; | 93 private final int mId; |
84 | 94 |
85 /** Whether or not this tab is an incognito tab. */ | 95 /** Whether or not this tab is an incognito tab. */ |
86 private final boolean mIncognito; | 96 private final boolean mIncognito; |
87 | 97 |
88 /** An Application {@link Context}. Unlike {@link #mContext}, this is the o
nly one that is | 98 /** An Application {@link Context}. Unlike {@link #mContext}, this is the o
nly one that is |
89 * publicly exposed to help prevent leaking the {@link Activity}. */ | 99 * publicly exposed to help prevent leaking the {@link Activity}. */ |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 /** | 546 /** |
537 * Prints the current page. | 547 * Prints the current page. |
538 * | 548 * |
539 * @return Whether the printing process is started successfully. | 549 * @return Whether the printing process is started successfully. |
540 **/ | 550 **/ |
541 public boolean print() { | 551 public boolean print() { |
542 assert mNativeTabAndroid != 0; | 552 assert mNativeTabAndroid != 0; |
543 return nativePrint(mNativeTabAndroid); | 553 return nativePrint(mNativeTabAndroid); |
544 } | 554 } |
545 | 555 |
| 556 @CalledByNative |
| 557 public void showPrintDialog() { |
| 558 // TODO Is that considered private data and should not be logged? |
| 559 if (mDebug) Log.d(TAG, "Showing print dialog for tab " + this.getTitle() |
| 560 + " (" + this.getUrl() + ")"); |
| 561 PrintingController printingController = PrintingControllerImpl.getInstan
ce(); |
| 562 if (printingController != null) { |
| 563 printingController.startPrint(new TabPrinter(this), |
| 564 new PrintManagerDelegateImpl(mContext)); |
| 565 } |
| 566 } |
| 567 |
546 /** | 568 /** |
547 * Reloads the current page content. | 569 * Reloads the current page content. |
548 */ | 570 */ |
549 public void reload() { | 571 public void reload() { |
550 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz
en? | 572 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz
en? |
551 if (getWebContents() != null) getWebContents().getNavigationController()
.reload(true); | 573 if (getWebContents() != null) getWebContents().getNavigationController()
.reload(true); |
552 } | 574 } |
553 | 575 |
554 /** | 576 /** |
555 * Reloads the current page content. | 577 * Reloads the current page content. |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 private native void nativeDestroyWebContents(long nativeTabAndroid, boolean
deleteNative); | 1242 private native void nativeDestroyWebContents(long nativeTabAndroid, boolean
deleteNative); |
1221 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); | 1243 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); |
1222 private native int nativeLoadUrl(long nativeTabAndroid, String url, String e
xtraHeaders, | 1244 private native int nativeLoadUrl(long nativeTabAndroid, String url, String e
xtraHeaders, |
1223 byte[] postData, int transition, String referrerUrl, int referrerPol
icy, | 1245 byte[] postData, int transition, String referrerUrl, int referrerPol
icy, |
1224 boolean isRendererInitiated); | 1246 boolean isRendererInitiated); |
1225 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab
Android, String url, | 1247 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab
Android, String url, |
1226 String title); | 1248 String title); |
1227 private native boolean nativePrint(long nativeTabAndroid); | 1249 private native boolean nativePrint(long nativeTabAndroid); |
1228 private native Bitmap nativeGetDefaultFavicon(long nativeTabAndroid); | 1250 private native Bitmap nativeGetDefaultFavicon(long nativeTabAndroid); |
1229 } | 1251 } |
OLD | NEW |