-
Notifications
You must be signed in to change notification settings - Fork 905
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
Moved from tabs to core option to control opening pages in custom tabs #5199
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser; | ||
|
||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
|
||
import org.chromium.base.ContextUtils; | ||
import org.chromium.chrome.browser.preferences.BravePreferenceKeys; | ||
|
||
public class BraveLaunchIntentDispatcher { | ||
public static boolean isCustomTabIntent(Intent intent) { | ||
if (!useCustomTabs()) { | ||
return false; | ||
} | ||
return LaunchIntentDispatcher.isCustomTabIntent(intent); | ||
} | ||
|
||
public static boolean useCustomTabs() { | ||
SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); | ||
return sharedPreferences.getBoolean(BravePreferenceKeys.BRAVE_USE_CUSTOM_TABS, true); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.settings; | ||
|
||
import android.os.Bundle; | ||
import android.content.SharedPreferences; | ||
import android.support.v7.preference.Preference; | ||
|
||
import org.chromium.base.ContextUtils; | ||
import org.chromium.chrome.browser.BraveLaunchIntentDispatcher; | ||
import org.chromium.chrome.browser.preferences.BravePreferenceKeys; | ||
import org.chromium.chrome.browser.settings.BravePreferenceFragment; | ||
import org.chromium.chrome.R; | ||
|
||
public class BraveCustomTabsPreference extends BravePreferenceFragment | ||
implements Preference.OnPreferenceChangeListener { | ||
public static int getPreferenceSummary() { | ||
return BraveLaunchIntentDispatcher.useCustomTabs() ? R.string.text_on : R.string.text_off; | ||
} | ||
|
||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
getActivity().setTitle(R.string.prefs_use_custom_tabs); | ||
SettingsUtils.addPreferencesFromResource(this, R.xml.use_custom_tabs_brave_preference); | ||
|
||
ChromeSwitchPreference pref = (ChromeSwitchPreference) findPreference( | ||
BravePreferenceKeys.BRAVE_USE_CUSTOM_TABS); | ||
pref.setChecked(BraveLaunchIntentDispatcher.useCustomTabs()); | ||
pref.setOnPreferenceChangeListener(this); | ||
} | ||
|
||
@Override | ||
public boolean onPreferenceChange(Preference preference, Object newValue) { | ||
SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit(); | ||
sharedPreferencesEditor.putBoolean(BravePreferenceKeys.BRAVE_USE_CUSTOM_TABS, (boolean) newValue); | ||
sharedPreferencesEditor.apply(); | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
|
||
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<org.chromium.chrome.browser.settings.ChromeSwitchPreference | ||
android:key="use_custom_tabs" | ||
android:title="@string/prefs_use_custom_tabs" | ||
android:summaryOn="@string/text_on" | ||
android:summaryOff="@string/text_off" /> | ||
</android.support.v7.preference.PreferenceScreen> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,12 @@ public void visitMethodInsn(int opcode, | |
// the method now | ||
opcode = INVOKEVIRTUAL; | ||
} | ||
String newOwner = shouldChangeOwner(owner, name); | ||
if (!newOwner.isEmpty()) { | ||
System.out.println("changing owner for " + mName + "." + name + | ||
" - new owner " + newOwner); | ||
owner = newOwner; | ||
} | ||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); | ||
} | ||
} | ||
|
@@ -87,6 +93,8 @@ public void visitMethodInsn(int opcode, | |
new HashMap<String, ArrayList<String>>(); | ||
private Map<String, ArrayList<String>> mMakePublicMethods = | ||
new HashMap<String, ArrayList<String>>(); | ||
private Map<String, Map<String, String>> mChangeOwnerMethods = | ||
new HashMap<String, Map<String, String>>(); | ||
private Map<String, ArrayList<String>> mMakeProtectedFields = | ||
new HashMap<String, ArrayList<String>>(); | ||
private Map<String, Map<String, ArrayList<String>>> mAddAnnotations = | ||
|
@@ -147,6 +155,28 @@ protected void makePublicMethod(String className, String methodName) { | |
methods.add(methodName); | ||
} | ||
|
||
private String shouldChangeOwner(String owner, String methodName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the semantics of this are slightly different than the making methods public, maybe call it |
||
if (mChangeOwnerMethods.containsKey(owner)) { | ||
Map<String, String> methods = mChangeOwnerMethods.get(owner); | ||
if (methods.containsKey(methodName)) { | ||
String newOwner = methods.get(methodName); | ||
if (!newOwner.equals(mName)) { | ||
return newOwner; | ||
} | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
protected void changeMethodOwner(String currentOwner, String methodName, String newOwner) { | ||
Map methods = mChangeOwnerMethods.get(currentOwner); | ||
if (methods == null) { | ||
methods = new HashMap<String, String>(); | ||
mChangeOwnerMethods.put(currentOwner, methods); | ||
} | ||
methods.put(methodName, newOwner); | ||
} | ||
|
||
private boolean shouldDeleteField(String fieldName) { | ||
for(Map.Entry<String, ArrayList<String>> entry : | ||
mDeleteFields.entrySet()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.brave.bytecode; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public class BraveLaunchIntentDispatcherClassAdapter extends BraveClassVisitor { | ||
static String sLaunchIntentDispatcherClassName = "org/chromium/chrome/browser/LaunchIntentDispatcher"; | ||
static String sBraveLaunchIntentDispatcherClassName = "org/chromium/chrome/browser/BraveLaunchIntentDispatcher"; | ||
|
||
public BraveLaunchIntentDispatcherClassAdapter(ClassVisitor visitor) { | ||
super(visitor); | ||
changeMethodOwner(sLaunchIntentDispatcherClassName, "isCustomTabIntent", sBraveLaunchIntentDispatcherClassName); | ||
} | ||
} |
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.
in other classes I left a comment
// see BraveLaunchIntentDispatcherClassAdapter
so it's easier to track down how this works