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.browser.ContentViewCore;
17 import org.chromium.content.browser.LoadUrlParams;
18 import org.chromium.content_public.Referrer;
19 import org.chromium.ui.base.WindowAndroid;
22 * ChromeShell's implementation of a tab. This mirrors how Chrome for Android subclasses
23 * and extends {@link Tab}.
25 public class ChromeShellTab extends Tab {
27 private boolean mIsLoading;
30 * @param context The Context the view is running in.
31 * @param url The URL to start this tab with.
32 * @param window The WindowAndroid should represent this tab.
33 * @param contentViewClient The client for the {@link ContentViewCore}s of this Tab.
35 public ChromeShellTab(Context context, String url, WindowAndroid window,
36 ContentViewClient contentViewClient) {
37 super(false, context, window);
40 setContentViewClient(contentViewClient);
41 loadUrlWithSanitization(url);
45 * @return Whether or not the tab is currently loading.
47 public boolean isLoading() {
52 * Navigates this Tab to a sanitized version of {@code url}.
53 * @param url The potentially unsanitized URL to navigate to.
54 * @param postData Optional data to be sent via POST.
56 public void loadUrlWithSanitization(String url, byte[] postData) {
57 if (url == null) return;
60 url = UrlUtilities.fixupUrl(url);
62 // Invalid URLs will just return empty.
63 if (TextUtils.isEmpty(url)) return;
65 ContentViewCore contentViewCore = getContentViewCore();
66 if (TextUtils.equals(url, contentViewCore.getUrl())) {
67 contentViewCore.reload(true);
69 if (postData == null) {
70 contentViewCore.loadUrl(new LoadUrlParams(url));
72 contentViewCore.loadUrl(LoadUrlParams.createLoadHttpPostParams(url, postData));
78 * Navigates this Tab to a sanitized version of {@code url}.
79 * @param url The potentially unsanitized URL to navigate to.
81 public void loadUrlWithSanitization(String url) {
82 loadUrlWithSanitization(url, null);
86 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() {
87 return new ChromeShellTabChromeWebContentsDelegateAndroid();
91 protected AutoLoginProcessor createAutoLoginProcessor() {
92 return new AutoLoginProcessor() {
94 public void processAutoLoginResult(String accountName,
95 String authToken, boolean success, String result) {
96 getInfoBarContainer().processAutoLogin(accountName, authToken,
103 protected ContextMenuPopulator createContextMenuPopulator() {
104 return new ChromeContextMenuPopulator(new TabChromeContextMenuItemDelegate() {
106 public void onOpenImageUrl(String url, Referrer referrer) {
107 loadUrlWithSanitization(url);
112 private class ChromeShellTabChromeWebContentsDelegateAndroid
113 extends TabChromeWebContentsDelegateAndroid {
115 public void onLoadStarted() {
120 public void onLoadStopped() {