-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
679 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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
79 changes: 79 additions & 0 deletions
79
android/java/org/chromium/chrome/browser/ntp/SponsoredBackgroundWebView.java
This file contains 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,79 @@ | ||
/* Copyright (c) 2025 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.ntp; | ||
|
||
import android.app.Activity; | ||
import android.net.Uri; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.FrameLayout; | ||
import org.chromium.base.version_info.VersionInfo; | ||
import org.chromium.chrome.browser.content.WebContentsFactory; | ||
import org.chromium.chrome.browser.ntp_background_images.model.SponsoredRichMedia; | ||
import org.chromium.chrome.browser.profiles.Profile; | ||
import org.chromium.components.embedder_support.view.ContentView; | ||
import org.chromium.components.thinwebview.ThinWebView; | ||
import org.chromium.components.thinwebview.ThinWebViewConstraints; | ||
import org.chromium.components.thinwebview.ThinWebViewFactory; | ||
import org.chromium.content_public.browser.LoadUrlParams; | ||
import org.chromium.content_public.browser.WebContents; | ||
import org.chromium.net.NetId; | ||
import org.chromium.ui.base.IntentRequestTracker; | ||
import org.chromium.ui.base.ViewAndroidDelegate; | ||
import org.chromium.ui.base.WindowAndroid; | ||
|
||
public class SponsoredBackgroundWebView { | ||
private WebContents mSponsoredBackgroundWebContents; | ||
private ThinWebView mSponsoredBackgroundWebView; | ||
|
||
public SponsoredBackgroundWebView(Activity activity, WindowAndroid windowAndroid, Profile profile) { | ||
mSponsoredBackgroundWebContents = | ||
WebContentsFactory.createWebContentsWithWarmRenderer( | ||
profile, | ||
/* initiallyHidden= */ false, | ||
/* targetNetwork= */ NetId.INVALID); | ||
|
||
final ContentView webContentView = | ||
ContentView.createContentView(activity, mSponsoredBackgroundWebContents); | ||
final ViewAndroidDelegate delegate = | ||
ViewAndroidDelegate.createBasicDelegate(webContentView); | ||
mSponsoredBackgroundWebContents.setDelegates( | ||
VersionInfo.getProductVersion(), | ||
delegate, | ||
webContentView, | ||
windowAndroid, | ||
WebContents.createDefaultInternalsHolder()); | ||
|
||
final IntentRequestTracker intentRequestTracker = windowAndroid.getIntentRequestTracker(); | ||
mSponsoredBackgroundWebView = | ||
ThinWebViewFactory.create( | ||
activity, new ThinWebViewConstraints(), intentRequestTracker); | ||
mSponsoredBackgroundWebView | ||
.getView() | ||
.setLayoutParams( | ||
new FrameLayout.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT)); | ||
mSponsoredBackgroundWebView.attachWebContents(mSponsoredBackgroundWebContents, | ||
webContentView, | ||
null); | ||
} | ||
|
||
public void loadSponsoredRichMedia(SponsoredRichMedia sponsoredRichMedia) { | ||
Uri.Builder builder = Uri.parse("chrome://new-tab-takeover").buildUpon(); | ||
builder.appendQueryParameter("wallpaperUrl", sponsoredRichMedia.getWallpaperUrl()); | ||
builder.appendQueryParameter("creativeInstanceId", sponsoredRichMedia.getCreativeInstanceId()); | ||
builder.appendQueryParameter("placementId", sponsoredRichMedia.getPlacementId()); | ||
builder.appendQueryParameter("targetUrl", sponsoredRichMedia.getTargetUrl()); | ||
|
||
mSponsoredBackgroundWebContents.getNavigationController().loadUrl( | ||
new LoadUrlParams(builder.build().toString())); | ||
} | ||
|
||
public View getView() { | ||
return mSponsoredBackgroundWebView.getView(); | ||
} | ||
} |
This file contains 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
52 changes: 52 additions & 0 deletions
52
android/java/org/chromium/chrome/browser/ntp_background_images/model/SponsoredRichMedia.java
This file contains 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,52 @@ | ||
/* Copyright (c) 2025 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.ntp_background_images.model; | ||
|
||
public class SponsoredRichMedia extends NTPImage { | ||
private String mWallpaperUrl; | ||
private String mCreativeInstanceId; | ||
private String mPlacementId; | ||
private String mTargetUrl; | ||
|
||
public SponsoredRichMedia(String wallpaperUrl, String creativeInstanceId, String placementId, String targetUrl) { | ||
mWallpaperUrl = wallpaperUrl; | ||
mCreativeInstanceId = creativeInstanceId; | ||
mPlacementId = placementId; | ||
mTargetUrl = targetUrl; | ||
} | ||
|
||
public String getWallpaperUrl() { | ||
return mWallpaperUrl; | ||
} | ||
|
||
public void setWallpaperUrl(String wallpaperUrl) { | ||
mWallpaperUrl = wallpaperUrl; | ||
} | ||
|
||
public String getCreativeInstanceId() { | ||
return mCreativeInstanceId; | ||
} | ||
|
||
public void setCreativeInstanceId(String creativeInstanceId) { | ||
mCreativeInstanceId = creativeInstanceId; | ||
} | ||
|
||
public String getPlacementId() { | ||
return mPlacementId; | ||
} | ||
|
||
public void setPlacementId(String placementId) { | ||
mPlacementId = placementId; | ||
} | ||
|
||
public String getTargetUrl() { | ||
return mTargetUrl; | ||
} | ||
|
||
public void setTargetUrl(String targetUrl) { | ||
mTargetUrl = targetUrl; | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.