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
3 // found in the LICENSE file.
5 package org.chromium.chrome.shell;
7 import android.content.Context;
8 import android.text.TextUtils;
10 import org.chromium.chrome.browser.Tab;
11 import org.chromium.chrome.browser.UrlUtilities;
12 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator;
13 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator;
14 import org.chromium.chrome.browser.infobar.AutoLoginProcessor;
15 import org.chromium.content.browser.ContentViewClient;
16 import org.chromium.content_public.browser.LoadUrlParams;
17 import org.chromium.content_public.browser.NavigationController;
18 import org.chromium.content_public.browser.WebContents;
19 import org.chromium.content_public.common.Referrer;
20 import org.chromium.ui.base.WindowAndroid;
23 * ChromeShell's implementation of a tab. This mirrors how Chrome for Android subclasses
24 * and extends {@link Tab}.
26 public class ChromeShellTab extends Tab {
28 private boolean mIsLoading;
31 * @param context The Context the view is running in.
32 * @param url The URL to start this tab with.
33 * @param window The WindowAndroid should represent this tab.
34 * @param contentViewClient The client for the {@link ContentViewCore}s of this Tab.
36 public ChromeShellTab(Context context, String url, WindowAndroid window,
37 ContentViewClient contentViewClient) {
38 super(false, context, window);
40 initContentViewCore();
41 setContentViewClient(contentViewClient);
42 loadUrlWithSanitization(url);
46 * @return Whether or not the tab is currently loading.
48 public boolean isLoading() {
53 * Navigates this Tab to a sanitized version of {@code url}.
54 * @param url The potentially unsanitized URL to navigate to.
55 * @param postData Optional data to be sent via POST.
57 public void loadUrlWithSanitization(String url, byte[] postData) {
58 if (url == null) return;
61 url = UrlUtilities.fixupUrl(url);
63 // Invalid URLs will just return empty.
64 if (TextUtils.isEmpty(url)) return;
66 WebContents webContents = getWebContents();
67 NavigationController navigationController = webContents.getNavigationController();
68 if (TextUtils.equals(url, webContents.getUrl())) {
69 navigationController.reload(true);
71 if (postData == null) {
72 navigationController.loadUrl(new LoadUrlParams(url));
74 navigationController.loadUrl(LoadUrlParams.createLoadHttpPostParams(url, postData));
80 * Navigates this Tab to a sanitized version of {@code url}.
81 * @param url The potentially unsanitized URL to navigate to.
83 public void loadUrlWithSanitization(String url) {
84 loadUrlWithSanitization(url, null);
88 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() {
89 return new ChromeShellTabChromeWebContentsDelegateAndroid();
93 protected AutoLoginProcessor createAutoLoginProcessor() {
94 return new AutoLoginProcessor() {
96 public void processAutoLoginResult(String accountName,
97 String authToken, boolean success, String result) {
98 getInfoBarContainer().processAutoLogin(accountName, authToken,
105 protected ContextMenuPopulator createContextMenuPopulator() {
106 return new ChromeContextMenuPopulator(new TabChromeContextMenuItemDelegate() {
108 public void onOpenImageUrl(String url, Referrer referrer) {
109 loadUrlWithSanitization(url);
114 private class ChromeShellTabChromeWebContentsDelegateAndroid
115 extends TabChromeWebContentsDelegateAndroid {
117 public void onLoadStarted() {
122 public void onLoadStopped() {