Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / shell / android / java / src / org / chromium / content_shell / Shell.java
index 99caca8..cb8c995 100644 (file)
@@ -26,7 +26,9 @@ 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;
 
 /**
@@ -44,12 +46,15 @@ public class Shell extends LinearLayout {
         }
     };
 
-    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;
 
@@ -150,7 +155,7 @@ public class Shell extends LinearLayout {
                 }
                 loadUrl(mUrlTextView.getText().toString());
                 setKeyboardVisibilityForUrl(false);
-                mContentView.requestFocus();
+                mContentViewCore.getContainerView().requestFocus();
                 return true;
             }
         });
@@ -161,10 +166,20 @@ public class Shell extends LinearLayout {
                 mNextButton.setVisibility(hasFocus ? GONE : VISIBLE);
                 mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE);
                 if (!hasFocus) {
-                    mUrlTextView.setText(mContentViewCore.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;
+            }
+        });
     }
 
     /**
@@ -176,15 +191,15 @@ public class Shell extends LinearLayout {
     public void loadUrl(String url) {
         if (url == null) return;
 
-        if (TextUtils.equals(url, mContentViewCore.getUrl())) {
-            mContentViewCore.reload(true);
+        if (TextUtils.equals(url, mWebContents.getUrl())) {
+            mNavigationController.reload(true);
         } else {
-            mContentViewCore.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();
     }
 
     /**
@@ -193,7 +208,7 @@ public class Shell extends LinearLayout {
      * @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;
     }
@@ -203,7 +218,7 @@ public class Shell extends LinearLayout {
         mPrevButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (mContentViewCore.canGoBack()) mContentViewCore.goBack();
+                if (mNavigationController.canGoBack()) mNavigationController.goBack();
             }
         });
 
@@ -211,7 +226,21 @@ public class Shell extends LinearLayout {
         mNextButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (mContentViewCore.canGoForward()) mContentViewCore.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);
             }
         });
     }
@@ -247,30 +276,51 @@ public class Shell extends LinearLayout {
 
     /**
      * 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);
-        mContentViewCore = mContentView.getContentViewCore();
+    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 (mContentViewCore.getUrl() != null) mUrlTextView.setText(mContentViewCore.getUrl());
-        ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentView,
+        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();
+        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 mContentView;
+        return mContentViewCore.getContainerView();
     }
 
     /**