Commit 27420bcb authored by sfiera's avatar sfiera Committed by Commit bot

Add helper to open URL in new activity

BUG=675561

Review-Url: https://codereview.chromium.org/2586293002
Cr-Commit-Position: refs/heads/master@{#439779}
parent 18c57323
// Copyright 2016 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.
package org.chromium.chrome.browser.ntp;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Browser;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
/**
* Provides functionality needed for content suggestion notifications.
*
* Exposes helper functions to native C++ code.
*/
public class ContentSuggestionsNotificationHelper {
private ContentSuggestionsNotificationHelper() {} // Prevent instantiation
@CalledByNative
private static void openUrl(String url) {
Context context = ContextUtils.getApplicationContext();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.setClass(context, ChromeLauncherActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
intent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
IntentHandler.addTrustedIntentExtras(intent, context);
context.startActivity(intent);
}
}
......@@ -550,6 +550,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/notifications/NotificationSystemStatusUtil.java",
"java/src/org/chromium/chrome/browser/notifications/StandardNotificationBuilder.java",
"java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java",
"java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java",
"java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java",
"java/src/org/chromium/chrome/browser/ntp/CurrentlyOpenTab.java",
"java/src/org/chromium/chrome/browser/ntp/DisplayStyleObserver.java",
......
......@@ -3099,6 +3099,8 @@ split_static_library("browser") {
"android/mojo/chrome_interface_registrar_android.h",
"android/net/external_estimate_provider_android.cc",
"android/net/external_estimate_provider_android.h",
"android/ntp/content_suggestions_notification_helper.cc",
"android/ntp/content_suggestions_notification_helper.h",
"android/ntp/most_visited_sites_bridge.cc",
"android/ntp/most_visited_sites_bridge.h",
"android/ntp/new_tab_page_prefs.cc",
......@@ -3972,6 +3974,7 @@ if (android_java_ui) {
"../android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java",
"../android/java/src/org/chromium/chrome/browser/notifications/ActionInfo.java",
"../android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java",
"../android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java",
"../android/java/src/org/chromium/chrome/browser/ntp/ForeignSessionHelper.java",
"../android/java/src/org/chromium/chrome/browser/ntp/LogoBridge.java",
"../android/java/src/org/chromium/chrome/browser/ntp/NewTabPagePrefs.java",
......
// Copyright 2016 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.
#include "chrome/browser/android/ntp/content_suggestions_notification_helper.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "jni/ContentSuggestionsNotificationHelper_jni.h"
namespace ntp_snippets {
void ContentSuggestionsNotificationHelper::OpenURL(const GURL& url) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_ContentSuggestionsNotificationHelper_openUrl(
env, base::android::ConvertUTF8ToJavaString(env, url.spec()));
}
} // namespace ntp_snippets
// Copyright 2016 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.
#ifndef CHROME_BROWSER_ANDROID_NTP_CONTENT_SUGGESTIONS_NOTIFICATION_HELPER_H_
#define CHROME_BROWSER_ANDROID_NTP_CONTENT_SUGGESTIONS_NOTIFICATION_HELPER_H_
#include "base/macros.h"
#include "url/gurl.h"
namespace ntp_snippets {
class ContentSuggestionsNotificationHelper {
public:
static void OpenURL(const GURL& url);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSuggestionsNotificationHelper);
};
} // namespace ntp_snippets
#endif // CHROME_BROWSER_ANDROID_NTP_CONTENT_SUGGESTIONS_NOTIFICATION_HELPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment