-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feature/request desktop site #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d1c412
First pass at "request desktop site" mode.
CDRussell e5ea895
Tidy up request desktop site feature
CDRussell dc09e26
Fix last few failing tests after refactor
CDRussell 7c5f687
Merge branch 'develop' of github.com:duckduckgo/Android into feature/…
CDRussell baaae01
Change string to "Desktop Site" instead of "Request Desktop Site"
CDRussell 980a36d
Make "userAgent" package lowercase
CDRussell ae1c31e
Fix checkbox UI - tweaking paddings and margins
CDRussell 5786279
Instantiate UserAgentProvider with default user agent string
CDRussell f4b9124
Move url checking around desktop/mobile site to UriExtension.kt
CDRussell aa05e11
Remove unused function
CDRussell d318565
Add better support for responsive websites when toggling desktop mode
CDRussell 3e4204e
Merge branch 'develop' of github.com:duckduckgo/Android into feature/…
CDRussell 8861108
Tweak initial scale value up to 120
CDRussell 686c1c7
Remove use of `setInitialScale` which seems to do more damage than good
CDRussell ffef1ca
Merge branch 'develop' of github.com:duckduckgo/Android into feature/…
CDRussell aa2ad28
Return `loadWithOverviewMode` and `useWideViewPort` to always be true
CDRussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/androidTest/java/com/duckduckgo/app/browser/userAgent/UserAgentProviderTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright (c) 2018 DuckDuckGo | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.duckduckgo.app.browser.useragent | ||
|
|
||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Test | ||
|
|
||
| private const val CHROME_UA_MOBILE = | ||
| "Mozilla/5.0 (Linux; Android 8.1.0; Nexus 6P Build/OPM3.171019.014) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.137 Mobile Safari/537.36" | ||
|
|
||
| // Some values will be dynamic based on OS/Architecture/Software versions, so use Regex to match around dynamic values | ||
| private val CHROME_UA_DESKTOP_REGEX = Regex( | ||
| "Mozilla/5.0 \\(X11; Linux .*?\\) AppleWebKit\\/[.0-9]+ \\(KHTML, like Gecko\\) Chrome\\/[.0-9]+ Safari/[.0-9]+" | ||
| ) | ||
| private val CHROME_UA_MOBILE_REGEX = Regex( | ||
| "Mozilla/5.0 \\(Linux; Android .*?\\) AppleWebKit\\/[.0-9]+ \\(KHTML, like Gecko\\) Chrome\\/[.0-9]+ Mobile Safari/[.0-9]+" | ||
| ) | ||
|
|
||
| private val CHROME_UA_MOBILE_REGEX_MISSING_APPLE_WEBKIT_DETAILS = Regex( | ||
| "Mozilla/5.0 \\(Linux; Android .*?\\)" | ||
| ) | ||
|
|
||
| class UserAgentProviderTest { | ||
|
|
||
| private lateinit var testee: UserAgentProvider | ||
|
|
||
| @Test | ||
| fun whenMobileUaRetrievedThenDeviceStrippedFromReturnedUa() { | ||
| testee = UserAgentProvider(CHROME_UA_MOBILE) | ||
| val actual = testee.getUserAgent(desktopSiteRequested = false) | ||
| assertTrue(CHROME_UA_MOBILE_REGEX.matches(actual)) | ||
| } | ||
|
|
||
| @Test | ||
| fun whenDesktopUaRetrievedThenDeviceStrippedFromReturnedUa() { | ||
| testee = UserAgentProvider(CHROME_UA_MOBILE) | ||
| val actual = testee.getUserAgent(desktopSiteRequested = true) | ||
| assertTrue(CHROME_UA_DESKTOP_REGEX.matches(actual)) | ||
| } | ||
|
|
||
| @Test | ||
| fun whenMissingAppleWebKitStringThenSimplyReturnsNothing() { | ||
| val missingAppleWebKitPart = "Mozilla/5.0 (Linux; Android 8.1.0; Nexus 6P Build/OPM3.171019.014) Chrome/64.0.3282.137 Mobile Safari/537.36" | ||
| testee = UserAgentProvider(missingAppleWebKitPart) | ||
| val actual = testee.getUserAgent(desktopSiteRequested = false) | ||
| assertTrue(CHROME_UA_MOBILE_REGEX_MISSING_APPLE_WEBKIT_DETAILS.matches(actual)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/duckduckgo/app/browser/userAgent/UserAgentProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright (c) 2018 DuckDuckGo | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.duckduckgo.app.browser.useragent | ||
|
|
||
| import android.net.Uri | ||
| import android.os.Build | ||
|
|
||
|
|
||
| /** | ||
| * Example Default User Agent (From Chrome): | ||
| * Mozilla/5.0 (Linux; Android 8.1.0; Nexus 6P Build/OPM3.171019.014) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.137 Mobile Safari/537.36 | ||
| * | ||
| * Example Default Desktop User Agent (From Chrome): | ||
| * Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.137 Safari/537.36 | ||
| */ | ||
| class UserAgentProvider constructor(private val defaultUserAgent: String) { | ||
|
|
||
| /** | ||
| * Returns a modified UA string which omits the user's device make and model | ||
| * If the user is requesting a desktop site, we add generic X11 Linux indicator, but include the real architecture | ||
| * If the user is requesting a mobile site, we add Linux Android indicator, and include the real Android OS version | ||
| * | ||
| * We include everything from the original UA string from AppleWebKit onwards (omitting if missing) | ||
| */ | ||
| fun getUserAgent(desktopSiteRequested: Boolean = false) : String{ | ||
|
|
||
| val platform = if(desktopSiteRequested) desktopUaPrefix() else mobileUaPrefix() | ||
| val userAgentStringSuffix = getWebKitVersionOnwards(desktopSiteRequested) | ||
|
|
||
| return "$MOZILLA_PREFIX ($platform)$userAgentStringSuffix" | ||
| } | ||
|
|
||
| private fun mobileUaPrefix() = "Linux; Android ${Build.VERSION.RELEASE}" | ||
|
|
||
| private fun desktopUaPrefix() = "X11; Linux ${System.getProperty("os.arch")}" | ||
|
|
||
| private fun getWebKitVersionOnwards(desktopSiteRequested: Boolean): String { | ||
| val matches = WEB_KIT_REGEX.find(defaultUserAgent) ?: return "" | ||
| var result = matches.groupValues[0] | ||
| if(desktopSiteRequested) { | ||
| result = result.replace(" Mobile ", " ") | ||
| } | ||
| return " $result" | ||
| } | ||
|
|
||
| companion object { | ||
| private val WEB_KIT_REGEX = Regex("AppleWebKit/.*") | ||
|
|
||
| private const val MOZILLA_PREFIX = "Mozilla/5.0" | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look quite right visually. I'd suggest taking a screenshot and asking Mike to quickly mock it up in zeplin.
If you're keen to get the PR in right now and address design feedback later, I'd be happy to approve the PR if:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅