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 @@ -461,7 +461,18 @@ public static void viewCurrentSite(Context context, SiteModel site, boolean open
ToastUtils.showToast(context, R.string.blog_not_found, ToastUtils.Duration.SHORT);
AppLog.w(AppLog.T.UTILS, "Site URL is null. Login URL: " + site.getLoginUrl());
} else {
openUrlExternal(context, site.getUrl());
String siteUrl = site.getUrl();
if (site.isWPCom()) {
// Show wp.com sites authenticated
WPWebViewActivity.openUrlByUsingGlobalWPCOMCredentials(context, siteUrl);
} else if (!TextUtils.isEmpty(site.getUsername()) && !TextUtils.isEmpty(site.getPassword())) {
// Show self-hosted sites as authenticated since we should have the username & password
WPWebViewActivity.openUrlByUsingBlogCredentials(context, site, null, siteUrl, new String[]{}, false);
} else {
// Show non-wp.com sites without a password unauthenticated. These would be Jetpack sites that are
// connected through REST API.
WPWebViewActivity.openURL(context, siteUrl);
}
}
}

Expand Down Expand Up @@ -574,7 +585,8 @@ public static void browsePostOrPage(Context context, SiteModel site, PostModel p
// from the passed URL, and internally redirects to it. EX:Published posts on a site with Plain
// permalink structure settings.
// Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/4873
WPWebViewActivity.openUrlByUsingBlogCredentials(context, site, post, url, new String[]{post.getLink()});
WPWebViewActivity
.openUrlByUsingBlogCredentials(context, site, post, url, new String[]{post.getLink()}, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

Expand Down Expand Up @@ -195,7 +196,7 @@ public static void openJetpackBlogPostPreview(Context context, String url, Strin

// Note: The webview has links disabled (excepted for urls in the whitelist: listOfAllowedURLs)
public static void openUrlByUsingBlogCredentials(Context context, SiteModel site, PostModel post, String url,
String[] listOfAllowedURLs) {
String[] listOfAllowedURLs, boolean disableLinks) {
if (context == null) {
AppLog.e(AppLog.T.UTILS, "Context is null");
return;
Expand All @@ -219,7 +220,7 @@ public static void openUrlByUsingBlogCredentials(Context context, SiteModel site
intent.putExtra(WPWebViewActivity.URL_TO_LOAD, url);
intent.putExtra(WPWebViewActivity.AUTHENTICATION_URL, authURL);
intent.putExtra(WPWebViewActivity.LOCAL_BLOG_ID, site.getId());
intent.putExtra(WPWebViewActivity.DISABLE_LINKS_ON_PAGE, true);
intent.putExtra(WPWebViewActivity.DISABLE_LINKS_ON_PAGE, disableLinks);
intent.putExtra(ALLOWED_URLS, listOfAllowedURLs);
if (post != null) {
intent.putExtra(WPWebViewActivity.SHAREABLE_URL, post.getLink());
Expand Down Expand Up @@ -291,6 +292,8 @@ private static void openWPCOMURL(Context context, String url, String shareableUr
protected void configureWebView() {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(mWebView, true);

final Bundle extras = getIntent().getExtras();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}

if (isAllURLsAllowed() || mAllowedURLs.contains(url)) {
if (isAllURLsAllowed() || mAllowedURLs.contains(url)
// If a url is allowed without the trailing `/`, it should be allowed with it as well
|| mAllowedURLs.contains(StringUtils.removeTrailingSlash(url))) {
view.loadUrl(url);
} else {
// show "links are disabled" message.
Expand Down