Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import android.webkit.URLUtil;
import android.widget.Toast;

import org.wordpress.android.BuildConfig;
import org.wordpress.android.Constants;
import org.wordpress.android.JavaScriptException;
import org.wordpress.android.R;
Expand Down Expand Up @@ -2034,6 +2035,7 @@ public void onEditorFragmentInitialized() {
fillContentEditorFields();
// Set the error listener
if (mEditorFragment instanceof EditorFragment) {
mEditorFragment.setDebugModeEnabled(BuildConfig.DEBUG);
((EditorFragment) mEditorFragment).setWebViewErrorListener(new ErrorListener() {
@Override
public void onJavaScriptError(String sourceFile, int lineNumber, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import android.text.SpannableString;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -72,8 +69,6 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
private static final float TOOLBAR_ALPHA_ENABLED = 1;
private static final float TOOLBAR_ALPHA_DISABLED = 0.5f;

protected static final int BUTTON_ID_LOG_HTML = 555;

private String mTitle = "";
private String mContentHtml = "";

Expand Down Expand Up @@ -407,8 +402,6 @@ protected void initJsEditor() {

if (mDebugModeEnabled) {
enableWebDebugging(true);
// Enable the HTML logging button
setHasOptionsMenu(true);
}
}

Expand Down Expand Up @@ -630,38 +623,11 @@ public void run() {

@SuppressLint("NewApi")
private void enableWebDebugging(boolean enable) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AppLog.i(T.EDITOR, "Enabling web debugging");
WebView.setWebContentsDebuggingEnabled(enable);
}
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(0, BUTTON_ID_LOG_HTML, 0, "Log HTML")
.setIcon(R.drawable.ic_log_html)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
super.onCreateOptionsMenu(menu, inflater);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == BUTTON_ID_LOG_HTML) {
if (mDebugModeEnabled) {
// Log the raw html
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("console.log(document.body.innerHTML);");
}
});
} else {
AppLog.d(T.EDITOR, "Could not execute JavaScript - debug mode not enabled");
}
return true;
} else {
return super.onOptionsItemSelected(item);
}
mWebView.setDebugModeEnabled(mDebugModeEnabled);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.HTTPUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.UrlUtils;

import java.io.IOException;
Expand All @@ -40,6 +41,7 @@ public abstract class EditorWebViewAbstract extends WebView {
private AuthHeaderRequestListener mAuthHeaderRequestListener;
private ErrorListener mErrorListener;
private JsCallbackReceiver mJsCallbackReceiver;
private boolean mDebugModeEnabled;

private Map<String, String> mHeaderMap = new HashMap<>();

Expand Down Expand Up @@ -175,6 +177,10 @@ public void setVisibility(int visibility) {
super.setVisibility(visibility);
}

public void setDebugModeEnabled(boolean enabled) {
mDebugModeEnabled = enabled;
}

/**
* Handles events that should be triggered when the WebView is hidden or is shown to the user
*
Expand Down Expand Up @@ -214,6 +220,13 @@ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
mOnImeBackListener.onImeBack();
}
}
if (mDebugModeEnabled && event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
&& event.getAction() == KeyEvent.ACTION_DOWN) {
// Log the raw html
execJavaScriptFromString("console.log(document.body.innerHTML);");
ToastUtils.showToast(getContext(), "Debug: Raw HTML has been logged");
return true;
}
return super.onKeyPreIme(keyCode, event);
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.