Upstream version 8.36.171.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core_shell / src / org / xwalk / core / xwview / shell / XWalkViewShellActivity.java
index b437b4d..3bcbd11 100644 (file)
@@ -36,11 +36,14 @@ import org.chromium.base.BaseSwitches;
 import org.chromium.base.CommandLine;
 import org.chromium.base.library_loader.LibraryLoader;
 import org.chromium.content.browser.TracingControllerAndroid;
-import org.xwalk.core.XWalkDefaultWebChromeClient;
+import org.xwalk.core.XWalkNavigationHistory;
+import org.xwalk.core.XWalkPreferences;
+import org.xwalk.core.XWalkResourceClient;
+import org.xwalk.core.XWalkUIClient;
 import org.xwalk.core.XWalkView;
 
 public class XWalkViewShellActivity extends FragmentActivity
-        implements ActionBar.TabListener, XWalkViewSectionFragment.OnXWalkViewCreatedListener{
+        implements ActionBar.TabListener, XWalkViewSectionFragment.OnXWalkViewCreatedListener {
     public static final String COMMAND_LINE_FILE = "/data/local/tmp/xwview-shell-command-line";
     private static final String TAG = XWalkViewShellActivity.class.getName();
     public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs";
@@ -98,6 +101,8 @@ public class XWalkViewShellActivity extends FragmentActivity
             getTracingController().unregisterReceiver(this);
         } catch (SecurityException e) {
             Log.w(TAG, "failed to unregister tracing receiver: " + e.getMessage());
+        } catch (IllegalArgumentException e) {
+            Log.w(TAG, "failed to unregister tracing receiver: " + e.getMessage());
         }
     }
 
@@ -157,7 +162,7 @@ public class XWalkViewShellActivity extends FragmentActivity
                 if (bundle.containsKey("url")) {
                     String extra = bundle.getString("url");
                     if (mActiveView != null)
-                        mActiveView.loadUrl(sanitizeUrl(extra));
+                        mActiveView.load(sanitizeUrl(extra), null);
                 }
             }
         };
@@ -165,23 +170,10 @@ public class XWalkViewShellActivity extends FragmentActivity
     }
 
     @Override
-    public void onPause() {
-        super.onPause();
-        mSectionsPagerAdapter.onPause();
-    }
-
-    @Override
-    public void onResume() {
-        super.onResume();
-        mSectionsPagerAdapter.onResume();
-    }
-
-    @Override
     public void onDestroy() {
         super.onDestroy();
         unregisterReceiver(mReceiver);
         unregisterTracingReceiver();
-        mSectionsPagerAdapter.onDestroy();
     }
 
     @Override
@@ -190,14 +182,6 @@ public class XWalkViewShellActivity extends FragmentActivity
     }
 
     @Override
-    public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (mActiveView != null) {
-            return mActiveView.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
-        }
-        return super.onKeyUp(keyCode, event);
-    }
-
-    @Override
     public void onNewIntent(Intent intent) {
         if (mActiveView != null) {
             if (!mActiveView.onNewIntent(intent)) super.onNewIntent(intent);
@@ -234,7 +218,7 @@ public class XWalkViewShellActivity extends FragmentActivity
                 }
 
                 if (mActiveView == null) return true;
-                mActiveView.loadUrl(sanitizeUrl(mUrlTextView.getText().toString()));
+                mActiveView.load(sanitizeUrl(mUrlTextView.getText().toString()), null);
                 mUrlTextView.clearFocus();
                 setKeyboardVisibilityForUrl(false);
                 return true;
@@ -261,8 +245,11 @@ public class XWalkViewShellActivity extends FragmentActivity
         mPrevButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (mActiveView == null) return;
-                if (mActiveView.canGoBack()) mActiveView.goBack();
+                if (mActiveView != null &&
+                        mActiveView.getNavigationHistory().canGoBack()) {
+                    mActiveView.getNavigationHistory().navigate(
+                            XWalkNavigationHistory.Direction.BACKWARD, 1);
+                }
             }
         });
 
@@ -270,8 +257,11 @@ public class XWalkViewShellActivity extends FragmentActivity
         mNextButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (mActiveView == null) return;
-                if (mActiveView.canGoForward()) mActiveView.goForward();
+                if (mActiveView != null &&
+                        mActiveView.getNavigationHistory().canGoForward()) {
+                    mActiveView.getNavigationHistory().navigate(
+                            XWalkNavigationHistory.Direction.FORWARD, 1);
+                }
             }
         });
 
@@ -279,8 +269,7 @@ public class XWalkViewShellActivity extends FragmentActivity
         mStopButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (mActiveView == null) return;
-                mActiveView.stopLoading();
+                if (mActiveView != null) mActiveView.stopLoading();
             }
         });
 
@@ -288,14 +277,14 @@ public class XWalkViewShellActivity extends FragmentActivity
         mReloadButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (mActiveView == null) return;
-                mActiveView.reload();
+                if (mActiveView != null) mActiveView.reload(XWalkView.RELOAD_NORMAL);
             }
         });
     }
 
     private void initializeXWalkViewClients(XWalkView xwalkView) {
-        xwalkView.setXWalkWebChromeClient(new XWalkDefaultWebChromeClient(this, xwalkView) {
+        xwalkView.setResourceClient(new XWalkResourceClient(xwalkView) {
+            @Override
             public void onProgressChanged(XWalkView view, int newProgress) {
                 if (view != mActiveView) return;
                 mToolbar.removeCallbacks(mClearProgressRunnable);
@@ -308,6 +297,10 @@ public class XWalkViewShellActivity extends FragmentActivity
                 }
                 mUrlTextView.setText(mActiveView.getUrl());
             }
+        });
+
+        xwalkView.setUIClient(new XWalkUIClient(xwalkView) {
+            @Override
             public void onReceivedTitle(XWalkView view, String title) {
                 mSectionsPagerAdapter.setPageTitle(view, title);
             }
@@ -364,6 +357,6 @@ public class XWalkViewShellActivity extends FragmentActivity
         }
         initializeXWalkViewClients(view);
         mProgressMap.put(view, 0);
-        view.enableRemoteDebugging();
+        XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
     }
 }