List of usage examples for android.webkit ConsoleMessage messageLevel
public MessageLevel messageLevel()
From source file:com.msopentech.thali.utilities.android.AndroidXmlHttpRequestTestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); webView = new WebView(this); //TODO: Oh, this is all a huge security hole. webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setDatabaseEnabled(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setLoadsImagesAutomatically(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); }//from ww w .ja va 2 s. com webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e("xmlhttptest", "errorCode: " + errorCode + ", description: " + description + ", failingUrl: " + failingUrl); super.onReceivedError(view, errorCode, description, failingUrl); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { Log.e("xmlhttptest", consoleMessage.message() + " - " + consoleMessage.messageLevel().toString() + " - " + consoleMessage.lineNumber() + " - " + consoleMessage.sourceId()); return false; } }); bridgeManager = new AndroidBridgeManager(this, webView); }
From source file:com.irccloud.android.activity.PastebinViewerActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override//from ww w. ja v a 2 s .c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(ColorScheme.getDialogWhenLargeTheme(ColorScheme.getUserTheme())); onMultiWindowModeChanged(isMultiWindow()); if (savedInstanceState == null && (getWindowManager().getDefaultDisplay().getWidth() < TypedValue .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 800, getResources().getDisplayMetrics()) || isMultiWindow())) overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out); setContentView(R.layout.activity_pastebin); mSpinner = findViewById(R.id.spinner); toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setNavigationIcon(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_material); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); getSupportActionBar().setTitle(""); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mWebView = findViewById(R.id.image); mWebView.setBackgroundColor(ColorScheme.getInstance().contentBackgroundColor); mWebView.getSettings().setBuiltInZoomControls(true); if (Integer.parseInt(Build.VERSION.SDK) >= 19) mWebView.getSettings() .setDisplayZoomControls(!getPackageManager().hasSystemFeature("android.hardware.touchscreen")); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.addJavascriptInterface(new JSInterface(), "Android"); mWebView.getSettings().setLoadWithOverviewMode(false); mWebView.getSettings().setUseWideViewPort(false); mWebView.getSettings().setAppCacheEnabled(false); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { fail(); } @Override public void onLoadResource(WebView view, String url) { } }); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { Crashlytics.log( consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR ? Log.ERROR : Log.WARN, "IRCCloud", "Javascript error - line: " + consoleMessage.lineNumber() + " message: " + consoleMessage.message()); return super.onConsoleMessage(consoleMessage); } }); if (savedInstanceState != null && savedInstanceState.containsKey("url")) { url = savedInstanceState.getString("url"); html = savedInstanceState.getString("html"); mWebView.loadDataWithBaseURL(url, html, "text/html", "UTF-8", null); } else { if (getIntent() != null && getIntent().getDataString() != null) { url = getIntent().getDataString().replace(getResources().getString(R.string.PASTE_SCHEME), "https"); if (!url.contains("?")) url += "?"; try { url += "&mobile=android&version=" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName + "&theme=" + ColorScheme.getUserTheme(); } catch (PackageManager.NameNotFoundException e) { } new FetchPastebinTask().execute(); Answers.getInstance().logContentView(new ContentViewEvent().putContentType("Pastebin")); } else { finish(); } } }
From source file:com.muzima.view.forms.FormWebViewActivity.java
private WebChromeClient createWebChromeClient() { return new WebChromeClient() { @Override/* ww w .ja v a 2s .c om*/ public void onProgressChanged(WebView view, int progress) { FormWebViewActivity.this.setProgress(progress * 1000); if (progress == 100) { progressDialog.dismiss(); } } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = format("Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}", consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId()); if (consoleMessage.messageLevel() == ERROR) { Log.e(TAG, message); } else { Log.d(TAG, message); } return true; } }; }
From source file:com.muzima.view.forms.HTMLFormWebViewActivity.java
private WebChromeClient createWebChromeClient() { return new WebChromeClient() { @Override//from www. java 2 s . c o m public void onProgressChanged(WebView view, int progress) { HTMLFormWebViewActivity.this.setProgress(progress * 1000); if (progress == 100) { progressDialog.dismiss(); } } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = format("Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}", consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId()); if (consoleMessage.messageLevel() == ERROR) { Log.e(TAG, message); } else { Log.d(TAG, message); } return true; } }; }
From source file:com.chatwingsdk.activities.CommunicationActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w.ja va 2 s . co m*/ public void ensureWebViewAndSubscribeToChannels() { if (mCurrentCommunicationMode == null) return; // Check whether the web view is available or not. // If not, init it and load faye client. When loading finished, // this method will be recursively called. At that point, // the actual subscribe code will be executed. if (mWebView == null) { mNotSubscribeToChannels = true; mWebView = new WebView(this); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.addJavascriptInterface(mFayeJsInterface, ChatWingJSInterface.CHATWING_JS_NAME); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { LogUtils.v(consoleMessage.message() + " -- level " + consoleMessage.messageLevel() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId()); //This workaround tries to fix issue webview is not subscribe successfully //when the screen is off, we cant listen for otto event since it's dead before that //this likely happens on development or very rare case in production if (consoleMessage.messageLevel().equals(ConsoleMessage.MessageLevel.ERROR)) { mWebView = null; mNotSubscribeToChannels = true; } return true; } }); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (url.equals(Constants.FAYE_CLIENT_URL)) { // Recursively call this method, // to execute subscribe code. ensureWebViewAndSubscribeToChannels(); } } }); mWebView.loadUrl(Constants.FAYE_CLIENT_URL); return; } if (mNotSubscribeToChannels) { mNotSubscribeToChannels = false; mCurrentCommunicationMode.subscribeToChannels(mWebView); } }
From source file:com.android.mail.ui.ConversationViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.conversation_view, container, false); mConversationContainer = (ConversationContainer) rootView.findViewById(R.id.conversation_container); mConversationContainer.setAccountController(this); mTopmostOverlay = (ViewGroup) mConversationContainer.findViewById(R.id.conversation_topmost_overlay); mTopmostOverlay.setOnKeyListener(this); inflateSnapHeader(mTopmostOverlay, inflater); mConversationContainer.setupSnapHeader(); setupNewMessageBar();/*from w w w . ja v a 2 s. c o m*/ mProgressController = new ConversationViewProgressController(this, getHandler()); mProgressController.instantiateProgressIndicators(rootView); mWebView = (ConversationWebView) mConversationContainer.findViewById(R.id.conversation_webview); mWebView.addJavascriptInterface(mJsBridge, "mail"); // On JB or newer, we use the 'webkitAnimationStart' DOM event to signal load complete // Below JB, try to speed up initial render by having the webview do supplemental draws to // custom a software canvas. // TODO(mindyp): //PAGE READINESS SIGNAL FOR JELLYBEAN AND NEWER // Notify the app on 'webkitAnimationStart' of a simple dummy element with a simple no-op // animation that immediately runs on page load. The app uses this as a signal that the // content is loaded and ready to draw, since WebView delays firing this event until the // layers are composited and everything is ready to draw. // This signal does not seem to be reliable, so just use the old method for now. final boolean isJBOrLater = Utils.isRunningJellybeanOrLater(); final boolean isUserVisible = isUserVisible(); mWebView.setUseSoftwareLayer(!isJBOrLater); mEnableContentReadySignal = isJBOrLater && isUserVisible; mWebView.onUserVisibilityChanged(isUserVisible); mWebView.setWebViewClient(mWebViewClient); final WebChromeClient wcc = new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) { LogUtils.e(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), consoleMessage.sourceId(), consoleMessage.lineNumber(), ConversationViewFragment.this); } else { LogUtils.i(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), consoleMessage.sourceId(), consoleMessage.lineNumber(), ConversationViewFragment.this); } return true; } }; mWebView.setWebChromeClient(wcc); final WebSettings settings = mWebView.getSettings(); final ScrollIndicatorsView scrollIndicators = (ScrollIndicatorsView) rootView .findViewById(R.id.scroll_indicators); scrollIndicators.setSourceView(mWebView); settings.setJavaScriptEnabled(true); ConversationViewUtils.setTextZoom(getResources(), settings); if (Utils.isRunningLOrLater()) { CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true /* accept */); } mViewsCreated = true; mWebViewLoadedData = false; return rootView; }
From source file:com.tct.mail.ui.ConversationViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //TS: chao-zhang 2015-12-10 EMAIL BUGFIX_1121860 MOD_S 544 //NOTE: when infalte conversationView which is implements from WebView,webview.jar is not exist //or not found,NameNotFoundException exception thrown,and InflateException thrown in Email,BAD!!! View rootView;/*from w w w . ja v a 2 s. c o m*/ try { rootView = inflater.inflate(R.layout.conversation_view, container, false); } catch (InflateException e) { LogUtils.e(LOG_TAG, e, "InflateException happen during inflate conversationView"); //TS: xing.zhao 2016-4-1 EMAIL BUGFIX_1892015 MOD_S if (getActivity() == null) { return null; } else { rootView = new View(getActivity().getApplicationContext()); return rootView; } //TS: xing.zhao 2016-4-1 EMAIL BUGFIX_1892015 MOD_E } //TS: chao-zhang 2015-12-10 EMAIL BUGFIX_1121860 MOD_E //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_S //Here we romve the imagebutton and then add it ,to make it show on the top level. //Because we can't add the fab button at last on the layout xml. mFabButton = (ConversationReplyFabView) rootView.findViewById(R.id.conversation_view_fab); FrameLayout framelayout = (FrameLayout) rootView.findViewById(R.id.conversation_view_framelayout); framelayout.removeView(mFabButton); framelayout.addView(mFabButton); //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_E mConversationContainer = (ConversationContainer) rootView.findViewById(R.id.conversation_container); mConversationContainer.setAccountController(this); mTopmostOverlay = (ViewGroup) mConversationContainer.findViewById(R.id.conversation_topmost_overlay); mTopmostOverlay.setOnKeyListener(this); inflateSnapHeader(mTopmostOverlay, inflater); mConversationContainer.setupSnapHeader(); setupNewMessageBar(); mProgressController = new ConversationViewProgressController(this, getHandler()); mProgressController.instantiateProgressIndicators(rootView); mWebView = (ConversationWebView) mConversationContainer.findViewById(R.id.conversation_webview); //TS: junwei-xu 2015-3-25 EMAIL BUGFIX_919767 ADD_S if (mWebView != null) { mWebView.setActivity(getActivity()); } //TS: junwei-xu 2015-3-25 EMAIL BUGFIX_919767 ADD_E //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_S mWebView.setFabButton(mFabButton); //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_E mWebView.addJavascriptInterface(mJsBridge, "mail"); // On JB or newer, we use the 'webkitAnimationStart' DOM event to signal load complete // Below JB, try to speed up initial render by having the webview do supplemental draws to // custom a software canvas. // TODO(mindyp): //PAGE READINESS SIGNAL FOR JELLYBEAN AND NEWER // Notify the app on 'webkitAnimationStart' of a simple dummy element with a simple no-op // animation that immediately runs on page load. The app uses this as a signal that the // content is loaded and ready to draw, since WebView delays firing this event until the // layers are composited and everything is ready to draw. // This signal does not seem to be reliable, so just use the old method for now. final boolean isJBOrLater = Utils.isRunningJellybeanOrLater(); final boolean isUserVisible = isUserVisible(); mWebView.setUseSoftwareLayer(!isJBOrLater); mEnableContentReadySignal = isJBOrLater && isUserVisible; mWebView.onUserVisibilityChanged(isUserVisible); mWebView.setWebViewClient(mWebViewClient); final WebChromeClient wcc = new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) { //TS: wenggangjin 2015-01-29 EMAIL BUGFIX_-917007 MOD_S // LogUtils.wtf(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), LogUtils.w(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), consoleMessage.sourceId(), consoleMessage.lineNumber(), ConversationViewFragment.this); //TS: wenggangjin 2015-01-29 EMAIL BUGFIX_-917007 MOD_E } else { LogUtils.i(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), consoleMessage.sourceId(), consoleMessage.lineNumber(), ConversationViewFragment.this); } return true; } }; mWebView.setWebChromeClient(wcc); final WebSettings settings = mWebView.getSettings(); final ScrollIndicatorsView scrollIndicators = (ScrollIndicatorsView) rootView .findViewById(R.id.scroll_indicators); scrollIndicators.setSourceView(mWebView); settings.setJavaScriptEnabled(true); ConversationViewUtils.setTextZoom(getResources(), settings); //Enable third-party cookies. b/16014255 if (Utils.isRunningLOrLater()) { CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true /* accept */); } mViewsCreated = true; mWebViewLoadedData = false; return rootView; }
From source file:android.webkit.cts.WebViewTest.java
public void testLoadData() throws Throwable { if (!NullWebViewUtils.isWebViewAvailable()) { return;/*from w ww . j ava2 s . c om*/ } final String HTML_CONTENT = "<html><head><title>Hello,World!</title></head><body></body>" + "</html>"; mOnUiThread.loadDataAndWaitForCompletion(HTML_CONTENT, "text/html", null); assertEquals("Hello,World!", mOnUiThread.getTitle()); startWebServer(false); final ChromeClient webChromeClient = new ChromeClient(mOnUiThread); final String crossOriginUrl = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL); runTestOnUiThread(new Runnable() { @Override public void run() { mWebView.getSettings().setJavaScriptEnabled(true); mOnUiThread.setWebChromeClient(webChromeClient); mOnUiThread.loadDataAndWaitForCompletion( "<html><head></head><body onload=\"" + "document.title = " + "document.getElementById('frame').contentWindow.location.href;" + "\"><iframe id=\"frame\" src=\"" + crossOriginUrl + "\"></body></html>", "text/html", null); } }); assertEquals(ConsoleMessage.MessageLevel.ERROR, webChromeClient.getMessageLevel(10000)); }