| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser.installedapp; | |
| 6 | |
| 7 import org.chromium.base.ContextUtils; | |
| 8 import org.chromium.content_public.browser.RenderFrameHost; | |
| 9 import org.chromium.installedapp.mojom.InstalledAppProvider; | |
| 10 import org.chromium.services.service_manager.InterfaceFactory; | |
| 11 | |
| 12 import java.net.URI; | |
| 13 import java.net.URISyntaxException; | |
| 14 | |
| 15 /** Factory to create instances of the InstalledAppProvider Mojo service. */ | |
| 16 public class InstalledAppProviderFactory implements InterfaceFactory<InstalledAp
pProvider> { | |
| 17 private final FrameUrlDelegateImpl mFrameUrlDelegate; | |
| 18 | |
| 19 private static final class FrameUrlDelegateImpl | |
| 20 implements InstalledAppProviderImpl.FrameUrlDelegate { | |
| 21 private final RenderFrameHost mRenderFrameHost; | |
| 22 | |
| 23 public FrameUrlDelegateImpl(RenderFrameHost renderFrameHost) { | |
| 24 mRenderFrameHost = renderFrameHost; | |
| 25 } | |
| 26 | |
| 27 @Override | |
| 28 public URI getUrl() { | |
| 29 String url = mRenderFrameHost.getLastCommittedURL(); | |
| 30 if (url == null) return null; | |
| 31 | |
| 32 try { | |
| 33 return new URI(url); | |
| 34 } catch (URISyntaxException e) { | |
| 35 throw new AssertionError(e); | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 public InstalledAppProviderFactory(RenderFrameHost renderFrameHost) { | |
| 41 mFrameUrlDelegate = new FrameUrlDelegateImpl(renderFrameHost); | |
| 42 } | |
| 43 | |
| 44 @Override | |
| 45 public InstalledAppProvider createImpl() { | |
| 46 return new InstalledAppProviderImpl( | |
| 47 mFrameUrlDelegate, ContextUtils.getApplicationContext()); | |
| 48 } | |
| 49 } | |
| OLD | NEW |