Skip to content

Commit ee26e52

Browse files
authored
Merge pull request #9667 from wordpress-mobile/issue/view-site-internal-browser
Open sites in the internal browser
2 parents 0db2c2f + cfc7271 commit ee26e52

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,18 @@ public static void viewCurrentSite(Context context, SiteModel site, boolean open
461461
ToastUtils.showToast(context, R.string.blog_not_found, ToastUtils.Duration.SHORT);
462462
AppLog.w(AppLog.T.UTILS, "Site URL is null. Login URL: " + site.getLoginUrl());
463463
} else {
464-
openUrlExternal(context, site.getUrl());
464+
String siteUrl = site.getUrl();
465+
if (site.isWPCom()) {
466+
// Show wp.com sites authenticated
467+
WPWebViewActivity.openUrlByUsingGlobalWPCOMCredentials(context, siteUrl);
468+
} else if (!TextUtils.isEmpty(site.getUsername()) && !TextUtils.isEmpty(site.getPassword())) {
469+
// Show self-hosted sites as authenticated since we should have the username & password
470+
WPWebViewActivity.openUrlByUsingBlogCredentials(context, site, null, siteUrl, new String[]{}, false);
471+
} else {
472+
// Show non-wp.com sites without a password unauthenticated. These would be Jetpack sites that are
473+
// connected through REST API.
474+
WPWebViewActivity.openURL(context, siteUrl);
475+
}
465476
}
466477
}
467478

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

WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.view.View;
1212
import android.view.View.OnClickListener;
1313
import android.view.ViewGroup;
14+
import android.webkit.CookieManager;
1415
import android.webkit.WebViewClient;
1516
import android.widget.ProgressBar;
1617

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

196197
// Note: The webview has links disabled (excepted for urls in the whitelist: listOfAllowedURLs)
197198
public static void openUrlByUsingBlogCredentials(Context context, SiteModel site, PostModel post, String url,
198-
String[] listOfAllowedURLs) {
199+
String[] listOfAllowedURLs, boolean disableLinks) {
199200
if (context == null) {
200201
AppLog.e(AppLog.T.UTILS, "Context is null");
201202
return;
@@ -219,7 +220,7 @@ public static void openUrlByUsingBlogCredentials(Context context, SiteModel site
219220
intent.putExtra(WPWebViewActivity.URL_TO_LOAD, url);
220221
intent.putExtra(WPWebViewActivity.AUTHENTICATION_URL, authURL);
221222
intent.putExtra(WPWebViewActivity.LOCAL_BLOG_ID, site.getId());
222-
intent.putExtra(WPWebViewActivity.DISABLE_LINKS_ON_PAGE, true);
223+
intent.putExtra(WPWebViewActivity.DISABLE_LINKS_ON_PAGE, disableLinks);
223224
intent.putExtra(ALLOWED_URLS, listOfAllowedURLs);
224225
if (post != null) {
225226
intent.putExtra(WPWebViewActivity.SHAREABLE_URL, post.getLink());
@@ -291,6 +292,8 @@ private static void openWPCOMURL(Context context, String url, String shareableUr
291292
protected void configureWebView() {
292293
mWebView.getSettings().setJavaScriptEnabled(true);
293294
mWebView.getSettings().setDomStorageEnabled(true);
295+
CookieManager cookieManager = CookieManager.getInstance();
296+
cookieManager.setAcceptThirdPartyCookies(mWebView, true);
294297

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

WordPress/src/main/java/org/wordpress/android/util/URLFilteredWebViewClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
4747
return true;
4848
}
4949

50-
if (isAllURLsAllowed() || mAllowedURLs.contains(url)) {
50+
if (isAllURLsAllowed() || mAllowedURLs.contains(url)
51+
// If a url is allowed without the trailing `/`, it should be allowed with it as well
52+
|| mAllowedURLs.contains(StringUtils.removeTrailingSlash(url))) {
5153
view.loadUrl(url);
5254
} else {
5355
// show "links are disabled" message.

0 commit comments

Comments
 (0)