import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
+import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.ContentView;
+import org.chromium.content.browser.ContentViewClient;
+import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.ContentViewRenderView;
-import org.chromium.content.browser.LoadUrlParams;
+import org.chromium.content_public.browser.LoadUrlParams;
+import org.chromium.content_public.browser.NavigationController;
+import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid;
/**
}
};
- // TODO(jrg): a mContentView.destroy() call is needed, both upstream and downstream.
- private ContentView mContentView;
+ private ContentViewCore mContentViewCore;
+ private WebContents mWebContents;
+ private NavigationController mNavigationController;
+ private ContentViewClient mContentViewClient;
private EditText mUrlTextView;
private ImageButton mPrevButton;
private ImageButton mNextButton;
+ private ImageButton mStopButton;
+ private ImageButton mReloadButton;
private ClipDrawable mProgressDrawable;
*
* @param nativeShell The pointer to the native Shell object.
* @param window The owning window for this shell.
+ * @param client The {@link ContentViewClient} to be bound to any current or new
+ * {@link ContentViewCore}s associated with this shell.
*/
- public void initialize(long nativeShell, WindowAndroid window) {
+ public void initialize(long nativeShell, WindowAndroid window, ContentViewClient client) {
mNativeShell = nativeShell;
mWindow = window;
+ mContentViewClient = client;
}
/**
private void onNativeDestroyed() {
mWindow = null;
mNativeShell = 0;
- mContentView.destroy();
+ mContentViewCore.destroy();
}
/**
}
loadUrl(mUrlTextView.getText().toString());
setKeyboardVisibilityForUrl(false);
- mContentView.requestFocus();
+ mContentViewCore.getContainerView().requestFocus();
return true;
}
});
mNextButton.setVisibility(hasFocus ? GONE : VISIBLE);
mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE);
if (!hasFocus) {
- mUrlTextView.setText(mContentView.getUrl());
+ mUrlTextView.setText(mWebContents.getUrl());
}
}
});
+ mUrlTextView.setOnKeyListener(new OnKeyListener() {
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ mContentViewCore.getContainerView().requestFocus();
+ return true;
+ }
+ return false;
+ }
+ });
}
/**
public void loadUrl(String url) {
if (url == null) return;
- if (TextUtils.equals(url, mContentView.getUrl())) {
- mContentView.getContentViewCore().reload(true);
+ if (TextUtils.equals(url, mWebContents.getUrl())) {
+ mNavigationController.reload(true);
} else {
- mContentView.loadUrl(new LoadUrlParams(sanitizeUrl(url)));
+ mNavigationController.loadUrl(new LoadUrlParams(sanitizeUrl(url)));
}
mUrlTextView.clearFocus();
// TODO(aurimas): Remove this when crbug.com/174541 is fixed.
- mContentView.clearFocus();
- mContentView.requestFocus();
+ mContentViewCore.getContainerView().clearFocus();
+ mContentViewCore.getContainerView().requestFocus();
}
/**
* @return The sanitized URL.
*/
public static String sanitizeUrl(String url) {
- if (url == null) return url;
+ if (url == null) return null;
if (url.startsWith("www.") || url.indexOf(":") == -1) url = "http://" + url;
return url;
}
mPrevButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- if (mContentView.canGoBack()) mContentView.goBack();
+ if (mNavigationController.canGoBack()) mNavigationController.goBack();
}
});
mNextButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- if (mContentView.canGoForward()) mContentView.goForward();
+ if (mNavigationController.canGoForward()) mNavigationController.goForward();
+ }
+ });
+ mStopButton = (ImageButton) findViewById(R.id.stop);
+ mStopButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mLoading) mWebContents.stop();
+ }
+ });
+ mReloadButton = (ImageButton) findViewById(R.id.reload);
+ mReloadButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mNavigationController.reload(true);
}
});
}
/**
* Initializes the ContentView based on the native tab contents pointer passed in.
- * @param nativeTabContents The pointer to the native tab contents object.
+ * @param nativeWebContents The pointer to the native tab contents object.
*/
@SuppressWarnings("unused")
@CalledByNative
- private void initFromNativeTabContents(long nativeTabContents) {
- mContentView = ContentView.newInstance(getContext(), nativeTabContents, mWindow);
- if (mContentView.getUrl() != null) mUrlTextView.setText(mContentView.getUrl());
- ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentView,
+ private void initFromNativeTabContents(long nativeWebContents) {
+ Context context = getContext();
+ mContentViewCore = new ContentViewCore(context);
+ ContentView cv = ContentView.newInstance(context, mContentViewCore);
+ mContentViewCore.initialize(cv, cv, nativeWebContents, mWindow);
+ mContentViewCore.setContentViewClient(mContentViewClient);
+ mWebContents = mContentViewCore.getWebContents();
+ mNavigationController = mWebContents.getNavigationController();
+ if (getParent() != null) mContentViewCore.onShow();
+ if (mWebContents.getUrl() != null) {
+ mUrlTextView.setText(mWebContents.getUrl());
+ }
+ ((FrameLayout) findViewById(R.id.contentview_holder)).addView(cv,
new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
- mContentView.requestFocus();
- mContentViewRenderView.setCurrentContentView(mContentView);
+ cv.requestFocus();
+ mContentViewRenderView.setCurrentContentViewCore(mContentViewCore);
+ }
+
+ /**
+ * Enable/Disable navigation(Prev/Next) button if navigation is allowed/disallowed
+ * in respective direction.
+ * @param controlId Id of button to update
+ * @param enabled enable/disable value
+ */
+ @CalledByNative
+ private void enableUiControl(int controlId, boolean enabled) {
+ if (controlId == 0) mPrevButton.setEnabled(enabled);
+ else if (controlId == 1) mNextButton.setEnabled(enabled);
+ else if (controlId == 2) {
+ mStopButton.setVisibility(enabled ? VISIBLE : GONE);
+ mReloadButton.setVisibility(enabled ? GONE : VISIBLE);
+ }
+ }
+
+ /**
+ * @return The {@link ViewGroup} currently shown by this Shell.
+ */
+ public ViewGroup getContentView() {
+ return mContentViewCore.getContainerView();
}
/**
- * @return The {@link ContentView} currently shown by this Shell.
+ * @return The {@link ContentViewCore} currently managing the view shown by this Shell.
*/
- public ContentView getContentView() {
- return mContentView;
+ public ContentViewCore getContentViewCore() {
+ return mContentViewCore;
}
private void setKeyboardVisibilityForUrl(boolean visible) {