Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Closes #762 - Address feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuche committed Apr 23, 2018
1 parent dee12b8 commit e335195
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ internal class FirefoxAmazonWebView(
// called by webview when clicking on a link, and not when opening a new page for the
// first time using loadUrl().
if (!client.shouldOverrideUrlLoading(this, url)) {
callback?.shouldInterceptRequest(url)
super.loadUrl(url, mapOf("X-Requested-With" to ""))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ public void onLoadResource(AmazonWebView view, String url) {
// WebResourceRequest was added in API21 and there is no equivalent AmazonWebResourceRequest
@Override
public AmazonWebResourceResponse shouldInterceptRequest(AmazonWebView view, String request) {
if ((request != null && request.startsWith(APP_URL_PREFIX))) {
if (request != null && request.startsWith(APP_URL_PREFIX)) {
switch (request) {
case APP_URL_HOME:
// Home screen should show a blank webview behind the overlay, but keep the url.
callback.shouldInterceptRequest(request);
final ByteArrayInputStream homeDataStream = makeEmptyDataStream();
callback.onShouldInterceptRequest(request);
final ByteArrayInputStream homeDataStream = getBlankPageStream();
return new AmazonWebResourceResponse("text/html", "utf-8", homeDataStream);
}
}

return super.shouldInterceptRequest(view, request);
}

private ByteArrayInputStream makeEmptyDataStream() {
private ByteArrayInputStream getBlankPageStream() {
// ByteArrayInputStream doesn't need to be closed.
return new ByteArrayInputStream("<html></html>".getBytes());
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/mozilla/focus/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class MainActivity : LocaleAwareAppCompatActivity(), OnUrlEnteredListener {
public override fun onValueChanged(sessions: List<Session>) {
if (sessions.isEmpty()) {
// There's no active session. Start a new session with "homepage".
sessionManager.createSession(Source.USER_ENTERED, APP_URL_HOME)
ScreenController.showBrowserScreenForUrl(supportFragmentManager, APP_URL_HOME, Source.NONE)
} else {
ScreenController.showBrowserScreenForCurrentSession(supportFragmentManager, sessionManager)
}
ScreenController.showBrowserScreenForCurrentSession(supportFragmentManager, sessionManager)

if (Settings.getInstance(this@MainActivity).shouldShowOnboarding()) {
val onboardingIntent = Intent(this@MainActivity, OnboardingActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class BrowserFragment : IWebViewLifecycleFragment() {
companion object {
const val FRAGMENT_TAG = "browser"
const val APP_URL_PREFIX = "firefox:"
const val HOME_SUFFIX = "home"
const val APP_URL_HOME = APP_URL_PREFIX + HOME_SUFFIX
const val APP_URL_HOME = "${APP_URL_PREFIX}home"

@JvmStatic
fun createForSession(session: Session) = BrowserFragment().apply {
Expand Down Expand Up @@ -288,7 +287,8 @@ private class BrowserIWebViewCallback(
override fun onBlockingStateChanged(isBlockingEnabled: Boolean) {}

override fun onLongPress(hitTarget: IWebView.HitTarget) {}
override fun shouldInterceptRequest(url: String) {
override fun onShouldInterceptRequest(url: String) {
// This might not be called from the UI thread but needs to be, so we use launch.
launch(UI) {
when (url) {
APP_URL_HOME -> browserFragment.browserOverlay?.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onProgress(int progress) {
public void onLongPress(IWebView.HitTarget hitTarget) {}

@Override
public void shouldInterceptRequest(String url) {}
public void onShouldInterceptRequest(String url) {}

@Override
public void onURLChanged(String url) {}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/focus/iwebview/IWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ interface IWebView {
fun onRequest(isTriggeredByUserGesture: Boolean)

fun onLongPress(hitTarget: HitTarget)
fun shouldInterceptRequest(url: String)
fun onShouldInterceptRequest(url: String)

/**
* Notify the host application that the current page has entered full screen mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void onLongPress(@NonNull IWebView.HitTarget hitTarget) {
}

@Override
public void shouldInterceptRequest(String url) {
delegate.shouldInterceptRequest(url);
public void onShouldInterceptRequest(String url) {
delegate.onShouldInterceptRequest(url);
}

@Override
Expand Down

0 comments on commit e335195

Please sign in to comment.