Bug 1511129 - Add Request Desktop Site to GVE. r=droeh
authorAgi Sferro <agi@sferro.dev>
Wed, 14 Aug 2019 23:40:18 +0000
changeset 488160 9611e788e39a9f7c468748f1f0e6d9fb19ea5518
parent 488159 61dc2ad51719c1f2a00eb5d08d925cf59bb4d0bb
child 488161 a3480699468f683ae6f045828ccf54c6590e9815
push id36437
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:33:18 +0000
treeherdermozilla-central@44aac6fc3352 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh
bugs1511129
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1511129 - Add Request Desktop Site to GVE. r=droeh Differential Revision: https://phabricator.services.mozilla.com/D42045
mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
mobile/android/geckoview_example/src/main/res/menu/actions.xml
mobile/android/geckoview_example/src/main/res/values/strings.xml
--- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
+++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
@@ -74,16 +74,17 @@ public class GeckoViewActivity extends A
     private TabSessionManager mTabSessionManager;
     private GeckoView mGeckoView;
     private boolean mUseMultiprocess;
     private boolean mFullAccessibilityTree;
     private boolean mUseTrackingProtection;
     private boolean mUsePrivateBrowsing;
     private boolean mEnableRemoteDebugging;
     private boolean mKillProcessOnDestroy;
+    private boolean mDesktopMode;
 
     private boolean mShowNotificationsRejected;
     private ArrayList<String> mAcceptedPersistentStorage = new ArrayList<String>();
 
     private ToolbarLayout mToolbarView;
     private String mCurrentUri;
     private boolean mCanGoBack;
     private boolean mCanGoForward;
@@ -221,16 +222,22 @@ public class GeckoViewActivity extends A
     }
     
     private TabSession createSession() {
         TabSession session = mTabSessionManager.newSession(new GeckoSessionSettings.Builder()
                 .useMultiprocess(mUseMultiprocess)
                 .usePrivateMode(mUsePrivateBrowsing)
                 .useTrackingProtection(mUseTrackingProtection)
                 .fullAccessibilityTree(mFullAccessibilityTree)
+                .viewportMode(mDesktopMode
+                        ? GeckoSessionSettings.VIEWPORT_MODE_DESKTOP
+                        : GeckoSessionSettings.VIEWPORT_MODE_MOBILE)
+                .userAgentMode(mDesktopMode
+                        ? GeckoSessionSettings.USER_AGENT_MODE_DESKTOP
+                        : GeckoSessionSettings.USER_AGENT_MODE_MOBILE)
                 .build());
         connectSession(session);
 
         return session;
     }
 
     private void connectSession(GeckoSession session) {
         session.setContentDelegate(new ExampleContentDelegate());
@@ -248,16 +255,17 @@ public class GeckoViewActivity extends A
         permission.androidPermissionRequestCode = REQUEST_PERMISSIONS;
         session.setPermissionDelegate(permission);
 
         session.setMediaDelegate(new ExampleMediaDelegate(this));
 
         session.setSelectionActionDelegate(new BasicSelectionActionDelegate(this));
 
         updateTrackingProtection(session);
+        updateDesktopMode(session);
     }
 
     private void recreateSession() {
         recreateSession(mTabSessionManager.getCurrentSession());
     }
 
     private void recreateSession(TabSession session) {
         if(session != null) {
@@ -278,16 +286,25 @@ public class GeckoViewActivity extends A
         super.onRestoreInstanceState(savedInstanceState);
         if(savedInstanceState != null) {
             mTabSessionManager.setCurrentSession((TabSession)mGeckoView.getSession());
         } else {
             recreateSession();
         }
     }
 
+    private void updateDesktopMode(GeckoSession session) {
+        session.getSettings().setViewportMode(mDesktopMode
+                ? GeckoSessionSettings.VIEWPORT_MODE_DESKTOP
+                : GeckoSessionSettings.VIEWPORT_MODE_MOBILE);
+        session.getSettings().setUserAgentMode(mDesktopMode
+                ? GeckoSessionSettings.USER_AGENT_MODE_DESKTOP
+                : GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
+    }
+
     private void updateTrackingProtection(GeckoSession session) {
         session.getSettings().setUseTrackingProtection(mUseTrackingProtection);
     }
 
     @Override
     public void onBackPressed() {
         GeckoSession session = mTabSessionManager.getCurrentSession();
         if (mFullScreen && session != null) {
@@ -310,16 +327,17 @@ public class GeckoViewActivity extends A
         return true;
     }
 
     @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
         menu.findItem(R.id.action_e10s).setChecked(mUseMultiprocess);
         menu.findItem(R.id.action_tp).setChecked(mUseTrackingProtection);
         menu.findItem(R.id.action_pb).setChecked(mUsePrivateBrowsing);
+        menu.findItem(R.id.desktop_mode).setChecked(mDesktopMode);
         menu.findItem(R.id.action_remote_debugging).setChecked(mEnableRemoteDebugging);
         menu.findItem(R.id.action_forward).setEnabled(mCanGoForward);
         return true;
     }
 
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         GeckoSession session = mTabSessionManager.getCurrentSession();
@@ -334,16 +352,21 @@ public class GeckoViewActivity extends A
                 mUseMultiprocess = !mUseMultiprocess;
                 recreateSession();
                 break;
             case R.id.action_tp:
                 mUseTrackingProtection = !mUseTrackingProtection;
                 updateTrackingProtection(session);
                 session.reload();
                 break;
+            case R.id.desktop_mode:
+                mDesktopMode = !mDesktopMode;
+                updateDesktopMode(session);
+                session.reload();
+                break;
             case R.id.action_pb:
                 mUsePrivateBrowsing = !mUsePrivateBrowsing;
                 recreateSession();
                 break;
             case R.id.action_new_tab:
                 createNewTab();
                 break;
             case R.id.action_close_tab:
--- a/mobile/android/geckoview_example/src/main/res/menu/actions.xml
+++ b/mobile/android/geckoview_example/src/main/res/menu/actions.xml
@@ -1,13 +1,15 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
     <item android:title="@string/multiprocess" android:id="@+id/action_e10s" android:checkable="true"
         app:showAsAction="never"/>
     <item android:title="@string/tracking_protection" android:id="@+id/action_tp" app:showAsAction="never"
           android:checkable="true"/>
+    <item android:title="@string/desktop_mode" android:id="@+id/desktop_mode" android:checkable="true"
+          app:showAsAction="never" />
     <item android:title="@string/private_browsing" android:checkable="true" android:id="@+id/action_pb"/>
     <item android:title="@string/remote_debugging" android:checkable="true" android:id="@+id/action_remote_debugging"/>
     <item android:title="@string/new_tab" android:id="@+id/action_new_tab"/>
     <item android:title="@string/close_tab" android:id="@+id/action_close_tab"/>
     <item android:title="@string/forward" android:id="@+id/action_forward"/>
     <item android:title="@string/reload" android:id="@+id/action_reload"/>
 </menu>
\ No newline at end of file
--- a/mobile/android/geckoview_example/src/main/res/values/strings.xml
+++ b/mobile/android/geckoview_example/src/main/res/values/strings.xml
@@ -28,9 +28,10 @@
     <string name="crashed_title">GeckoView Example Crashed</string>
     <string name="crashed_text">Tap to report to Mozilla.</string>
     <string name="crashed_ignore">Ignore</string>
     <string name="device_sharing_microphone">Microphone is on</string>
     <string name="device_sharing_camera">Camera is on</string>
     <string name="device_sharing_camera_and_mic">Camera and microphone are on</string>
     <string name="new_tab">New tab</string>
     <string name="close_tab">Close tab</string>
+    <string name="desktop_mode">Desktop site</string>
 </resources>