#534 enable support for WEB_SEARCH intent
This commit is contained in:
@@ -12,19 +12,19 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
||||
---
|
||||
chrome/android/chrome_java_resources.gni | 1 +
|
||||
chrome/android/chrome_java_sources.gni | 1 +
|
||||
chrome/android/java/AndroidManifest.xml | 24 +++-
|
||||
.../res/layout/sharing_intent_content.xml | 87 ++++++++++++
|
||||
.../chrome/browser/IntentHandler.java | 16 ++-
|
||||
.../browser/LaunchIntentDispatcher.java | 2 +-
|
||||
chrome/android/java/AndroidManifest.xml | 28 +++-
|
||||
.../res/layout/sharing_intent_content.xml | 88 ++++++++++
|
||||
.../chrome/browser/IntentHandler.java | 16 +-
|
||||
.../browser/LaunchIntentDispatcher.java | 14 +-
|
||||
.../init/ProcessInitializationHandler.java | 3 +
|
||||
.../SharedIntentShareActivity.java | 127 ++++++++++++++++++
|
||||
.../SharedIntentShareActivity.java | 158 ++++++++++++++++++
|
||||
.../flags/android/chrome_feature_list.cc | 1 +
|
||||
.../browser/flags/ChromeFeatureList.java | 1 +
|
||||
.../strings/android_chrome_strings.grd | 13 ++
|
||||
.../about_flags_cc/Enable-share-intent.inc | 12 ++
|
||||
.../Enable-share-intent.inc | 3 +
|
||||
.../Enable-share-intent.inc | 1 +
|
||||
14 files changed, 284 insertions(+), 8 deletions(-)
|
||||
14 files changed, 332 insertions(+), 8 deletions(-)
|
||||
create mode 100644 chrome/android/java/res/layout/sharing_intent_content.xml
|
||||
create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/sharing/shared_intent/SharedIntentShareActivity.java
|
||||
create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Enable-share-intent.inc
|
||||
@@ -69,7 +69,18 @@ diff --git a/chrome/android/java/AndroidManifest.xml b/chrome/android/java/Andro
|
||||
<!-- content URI support. -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
@@ -362,6 +356,24 @@ by a child template that "extends" this file.
|
||||
@@ -326,6 +320,10 @@ by a child template that "extends" this file.
|
||||
<action android:name="android.intent.action.MEDIA_SEARCH" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
+ <intent-filter>
|
||||
+ <action android:name="android.intent.action.WEB_SEARCH" />
|
||||
+ <category android:name="android.intent.category.DEFAULT" />
|
||||
+ </intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
@@ -362,6 +360,24 @@ by a child template that "extends" this file.
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@@ -98,7 +109,7 @@ diff --git a/chrome/android/java/res/layout/sharing_intent_content.xml b/chrome/
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/chrome/android/java/res/layout/sharing_intent_content.xml
|
||||
@@ -0,0 +1,87 @@
|
||||
@@ -0,0 +1,88 @@
|
||||
+<?xml version="1.0" encoding="utf-8"?>
|
||||
+<!-- Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
+ Use of this source code is governed by a BSD-style license that can be
|
||||
@@ -106,6 +117,7 @@ new file mode 100644
|
||||
+<LinearLayout
|
||||
+ xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
+ xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
+ android:id="@+id/share_content"
|
||||
+ android:layout_width="match_parent"
|
||||
+ android:layout_height="match_parent"
|
||||
+ android:orientation="vertical">
|
||||
@@ -229,7 +241,38 @@ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.j
|
||||
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
|
||||
--- a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
|
||||
+++ b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
|
||||
@@ -431,8 +431,8 @@ public class LaunchIntentDispatcher {
|
||||
@@ -44,6 +44,7 @@ import org.chromium.chrome.browser.intents.BrowserIntentUtils;
|
||||
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
|
||||
import org.chromium.chrome.browser.notifications.NotificationPlatformBridge;
|
||||
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
|
||||
+import org.chromium.chrome.browser.sharing.shared_intent.SharedIntentShareActivity;
|
||||
import org.chromium.chrome.browser.searchwidget.SearchActivity;
|
||||
import org.chromium.chrome.browser.tab.Tab;
|
||||
import org.chromium.chrome.browser.util.AndroidTaskUtils;
|
||||
@@ -205,11 +206,22 @@ public class LaunchIntentDispatcher {
|
||||
|
||||
String query = null;
|
||||
final String action = intent.getAction();
|
||||
+ boolean isWebSearch = Intent.ACTION_WEB_SEARCH.equals(action);
|
||||
if (Intent.ACTION_SEARCH.equals(action)
|
||||
+ || isWebSearch
|
||||
|| MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
|
||||
query = IntentUtils.safeGetStringExtra(intent, SearchManager.QUERY);
|
||||
}
|
||||
if (TextUtils.isEmpty(query)) return false;
|
||||
+ if (isWebSearch) {
|
||||
+ Intent i = new Intent(Intent.ACTION_SEND);
|
||||
+ i.putExtra(Intent.EXTRA_TEXT, query);
|
||||
+ i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
+ i.setClass(ContextUtils.getApplicationContext(),
|
||||
+ SharedIntentShareActivity.class);
|
||||
+ ContextUtils.getApplicationContext().startActivity(i);
|
||||
+ return true;
|
||||
+ }
|
||||
|
||||
// Only the ChromeLauncherActivity can handle search intents. Drop the intent and abort the
|
||||
// launch.
|
||||
@@ -431,8 +443,8 @@ public class LaunchIntentDispatcher {
|
||||
/*incognito*/true);
|
||||
newIntent.setData(mIntent.getData());
|
||||
newIntent.setPackage(applicationContext.getPackageName());
|
||||
@@ -263,7 +306,7 @@ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sharing/shared_
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sharing/shared_intent/SharedIntentShareActivity.java
|
||||
@@ -0,0 +1,127 @@
|
||||
@@ -0,0 +1,158 @@
|
||||
+// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
+// Use of this source code is governed by a BSD-style license that can be
|
||||
+// found in the LICENSE file.
|
||||
@@ -296,6 +339,9 @@ new file mode 100644
|
||||
+import org.chromium.chrome.browser.IntentHandler;
|
||||
+import org.chromium.chrome.browser.profiles.ProfileProvider;
|
||||
+import org.chromium.ui.widget.ButtonCompat;
|
||||
+import org.chromium.chrome.browser.profiles.Profile;
|
||||
+import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
|
||||
+import org.chromium.chrome.browser.privacy.settings.PrivacySettings;
|
||||
+
|
||||
+/**
|
||||
+ * Activity to display device targets to share text.
|
||||
@@ -303,6 +349,8 @@ new file mode 100644
|
||||
+public class SharedIntentShareActivity
|
||||
+ extends AsyncInitializationActivity {
|
||||
+
|
||||
+ String linkUrl;
|
||||
+
|
||||
+ @Override
|
||||
+ protected OneshotSupplier<ProfileProvider> createProfileProvider() {
|
||||
+ return new ActivityProfileProvider(getLifecycleDispatcher());
|
||||
@@ -342,12 +390,10 @@ new file mode 100644
|
||||
+ @Override
|
||||
+ protected void triggerLayoutInflation() {
|
||||
+ setContentView(R.layout.sharing_intent_content);
|
||||
+ linkUrl = IntentUtils.safeGetStringExtra(getIntent(), Intent.EXTRA_TEXT);
|
||||
+ updateTextLink();
|
||||
+
|
||||
+ String linkUrl = IntentUtils.safeGetStringExtra(getIntent(), Intent.EXTRA_TEXT);
|
||||
+ Resources resources = ContextUtils.getApplicationContext().getResources();
|
||||
+ TextView share_message_text = findViewById(R.id.share_message_text);
|
||||
+ share_message_text.setText(
|
||||
+ resources.getString(R.string.shared_intent_share_activity_text, linkUrl));
|
||||
+ findViewById(R.id.share_content).setVisibility(View.GONE);
|
||||
+
|
||||
+ View mask = findViewById(R.id.mask);
|
||||
+ mask.setOnClickListener(v -> finish());
|
||||
@@ -367,17 +413,7 @@ new file mode 100644
|
||||
+ ButtonCompat open_url_incognito_button = findViewById(R.id.open_url_incognito_button);
|
||||
+ open_url_incognito_button.setVisibility(View.VISIBLE);
|
||||
+ open_url_incognito_button.setOnClickListener(view -> {
|
||||
+ Context applicationContext = ContextUtils.getApplicationContext();
|
||||
+ Intent chromeIntent = IntentHandler.createTrustedOpenNewTabIntent(applicationContext,
|
||||
+ /*incognito*/true);
|
||||
+
|
||||
+ chromeIntent.setData(Uri.parse(linkUrl));
|
||||
+ chromeIntent.setPackage(applicationContext.getPackageName());
|
||||
+ chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
+ IntentHandler.setForceIncognitoMode(chromeIntent);
|
||||
+
|
||||
+ LaunchIntentDispatcher.dispatch(this, chromeIntent);
|
||||
+ finish();
|
||||
+ OpenLinkInIncognito();
|
||||
+ });
|
||||
+
|
||||
+ if (AlwaysIncognitoLinkInterceptor.isAlwaysIncognito())
|
||||
@@ -387,6 +423,44 @@ new file mode 100644
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void finishNativeInitialization() {
|
||||
+ String scheme = Uri.parse(linkUrl).getScheme();
|
||||
+ if (scheme == null) {
|
||||
+ linkUrl =
|
||||
+ TemplateUrlServiceFactory.getForProfile(Profile.getLastUsedRegularProfile())
|
||||
+ .getUrlForSearchQuery(linkUrl);
|
||||
+ }
|
||||
+ updateTextLink();
|
||||
+ if (ContextUtils.getAppSharedPreferences()
|
||||
+ .getBoolean(PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false)) {
|
||||
+ OpenLinkInIncognito();
|
||||
+ } else {
|
||||
+ findViewById(R.id.share_content).setVisibility(View.VISIBLE);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void updateTextLink() {
|
||||
+ Resources resources = ContextUtils.getApplicationContext().getResources();
|
||||
+ TextView share_message_text = findViewById(R.id.share_message_text);
|
||||
+ share_message_text.setText(
|
||||
+ resources.getString(R.string.shared_intent_share_activity_text, linkUrl));
|
||||
+ }
|
||||
+
|
||||
+ private void OpenLinkInIncognito() {
|
||||
+ Context applicationContext = ContextUtils.getApplicationContext();
|
||||
+ Intent chromeIntent = IntentHandler.createTrustedOpenNewTabIntent(applicationContext,
|
||||
+ /*incognito*/true);
|
||||
+
|
||||
+ chromeIntent.setData(Uri.parse(linkUrl));
|
||||
+ chromeIntent.setPackage(applicationContext.getPackageName());
|
||||
+ chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
+ IntentHandler.setForceIncognitoMode(chromeIntent);
|
||||
+
|
||||
+ LaunchIntentDispatcher.dispatch(this, chromeIntent);
|
||||
+ finish();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean shouldStartGpuProcess() {
|
||||
+ return false;
|
||||
+ }
|
||||
|
||||
Reference in New Issue
Block a user