External Webpage Embedded Incorrectly (EWEI)

ECn Categories > Browser Embedded Incorrectly (BEI) > External Webpage Embedded Incorrectly (EWEI)

The app redirects the user to an activity with an embedded web page from a external source (url) and it does not works because it has no internet connection.

Amount of Issues App List
17 (A5) Fanfiction reader, (A9) DuckDuckGo, (A10) OsmAnd, (A14) Wikimedia Commons, (A23) Prey, (A25) Twidere para Twitter, (A26) Opengur, (A27) AnkiDroid, (A39) Habitica, (A47) RedReader, (A49) PocketHub for GitHub

Examples

RedReader

Category: News & Magazines
v 1.9.8.2.1
Scenario: To access an article without internet connection
This video shows an example of an external web page embedded incorrectly. At 6th second the user selects a topic and this send at 9th second the event flow to another view with articles of the selected topic. Nevertheless at 12th second when the user select one article an error message is displayed, but this error belongs to a web browser that is embedded.

The following code snippets show the classes and files that are involved in the generation of the previuos issue.

In order to see how this error is generated, we need to review all the flow event. First, we have the method that is called when an article is selected.

src/main/java/org/quantumbadger/redreader/common/LinkHandler.java

    public static void onLinkClicked(
		final AppCompatActivity activity,
		String url,
		final boolean forceNoImage,
		final RedditPost post,
		final ImgurAPI.AlbumInfo albumInfo,
		final int albumImageIndex,
		final boolean fromExternalIntent) {

In this method a validation of the preferences is made in order to know if the user has selected to read the article in an internal browser. In this case the user has selected or the application uses as default the internal browser, so as we can see from line 170 on a new intent is created and it is sent to the “WebViewActivity” at line 174.

src/main/java/org/quantumbadger/redreader/common/LinkHandler.java

    switch(albumViewMode) {

	    case INTERNAL_LIST: {
	    	final Intent intent = new Intent(activity, AlbumListingActivity.class);
	    	intent.setData(Uri.parse(url));
	    	intent.putExtra("post", post);
	    	activity.startActivity(intent);
	    	return;
	    }

170.    case INTERNAL_BROWSER: {
	    	final Intent intent = new Intent(activity, WebViewActivity.class);
	    	intent.putExtra("url", url);
	    	intent.putExtra("post", post);
174.    	activity.startActivity(intent);
	    	return;
	    }

Now that the intent has been started the event lands on the “onCreate” method of the “WebViewActivity”. In this method at line 55 the url that was send in the intent is saved in a variable that will be used at line 62 whent is called the “newInstance” method from WebViewFragment.

src/main/java/org/quantumbadger/redreader/activities/WebViewActivity.java

    public void onCreate(final Bundle savedInstanceState) {

		PrefsUtility.applyTheme(this);

		super.onCreate(savedInstanceState);

		final Intent intent = getIntent();

55. 	String url = intent.getStringExtra("url");
		mPost = intent.getParcelableExtra("post");

		if(url == null) {
			BugReportActivity.handleGlobalError(this, "No URL");
		}

62. 	webView = WebViewFragment.newInstance(url, mPost);

		setBaseActivityContentView(View.inflate(this, R.layout.main_single, null));

		getSupportFragmentManager().beginTransaction().add(R.id.main_single_frame, webView).commit();
	}

From the previous snippet we can see that the “newInstance” is called, in this method the data from the intent is saved in a bundle element, nevertheless at line 78 a new instance of the WebViewFragment is created, in this process when the element is created the “onCreate” method is called.

src/main/java/org/quantumbadger/redreader/fragments/WebViewFragment.java

    public static WebViewFragment newInstance(final String url, final RedditPost post) {

78. 	final WebViewFragment f = new WebViewFragment();

		final Bundle bundle = new Bundle(1);
81. 	bundle.putString("url", url);
		if (post != null) bundle.putParcelable("post", post);
		f.setArguments(bundle);

		return f;
	}

When the event flow lands in the “onCreate” method, the data that was saved in the bundle in the previous bundle is retrieved and saved into variables. As we can see in line 103 the url is saved in the “mUrl” variable

src/main/java/org/quantumbadger/redreader/fragments/WebViewFragment.java

    @Override
	public void onCreate(final Bundle savedInstanceState) {
		// TODO load position/etc?
		super.onCreate(savedInstanceState);
103.	mUrl = getArguments().getString("url");
		html = getArguments().getString("html");
	}

In the other hand, in the “onCreateView” method a varibale is initialized at line 136 using the id “web_view_fragment_webviewfixed” of the webView from the GUI that will display the article.

src/main/java/org/quantumbadger/redreader/fragments/WebViewFragment.java

    public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    ...
136.    webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed);

Once the variable is created, and after some property are set, a condition is evaluated in order to know if the “mURL” variables is not null, for this case we know the variable has a value, so at line 245 the true case is executed and the url is loaded by the webView. At this moment, knowing that the user has no connection the url content will not be retrieved and the error from the webView will be shown.

src/main/java/org/quantumbadger/redreader/fragments/WebViewFragment.java

    if (mUrl != null) {
245.	webView.loadUrl(mUrl);
	} else {
247.	webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null);
	}

Finally, in the following snippet we can see the webView in the xml that defines the layout of the GUI

src/main/res/layout/web_view_fragment.xml

    <org.quantumbadger.redreader.views.webview.WebViewFixed
25. 	android:id="@+id/web_view_fragment_webviewfixed"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>