Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2015 The Android Open Source Project | 2 * Copyright (C) 2015 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. | 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at | 6 * You may obtain a copy of the License at |
| 7 * | 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * | 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 import android.widget.RemoteViews; | 29 import android.widget.RemoteViews; |
| 30 | 30 |
| 31 import java.util.List; | 31 import java.util.List; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * A class to be used for Custom Tabs related communication. Clients that want t o launch Custom Tabs | 34 * A class to be used for Custom Tabs related communication. Clients that want t o launch Custom Tabs |
| 35 * can use this class exclusively to handle all related communication. | 35 * can use this class exclusively to handle all related communication. |
| 36 */ | 36 */ |
| 37 public final class CustomTabsSession { | 37 public final class CustomTabsSession { |
| 38 private static final String TAG = "CustomTabsSession"; | 38 private static final String TAG = "CustomTabsSession"; |
| 39 private final Object mLock = new Object(); | |
| 39 private final ICustomTabsService mService; | 40 private final ICustomTabsService mService; |
| 40 private final ICustomTabsCallback mCallback; | 41 private final ICustomTabsCallback mCallback; |
| 41 private final ComponentName mComponentName; | 42 private final ComponentName mComponentName; |
| 42 | 43 |
| 43 /** | 44 /** |
| 44 * Provides browsers a way to generate a dummy {@link CustomTabsSession} for testing | 45 * Provides browsers a way to generate a dummy {@link CustomTabsSession} for testing |
| 45 * purposes. | 46 * purposes. |
| 46 * | 47 * |
| 47 * @param componentName The component the session should be created for. | 48 * @param componentName The component the session should be created for. |
| 48 * @return A dummy session with no functionality. | 49 * @return A dummy session with no functionality. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 145 |
| 145 Bundle metaBundle = new Bundle(); | 146 Bundle metaBundle = new Bundle(); |
| 146 metaBundle.putBundle(CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE, bundle ); | 147 metaBundle.putBundle(CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE, bundle ); |
| 147 try { | 148 try { |
| 148 return mService.updateVisuals(mCallback, metaBundle); | 149 return mService.updateVisuals(mCallback, metaBundle); |
| 149 } catch (RemoteException e) { | 150 } catch (RemoteException e) { |
| 150 return false; | 151 return false; |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 | 154 |
| 154 public boolean validatePostMessageOrigin() { | 155 /** |
| 156 * Sends a request to create a two way postMessage channel between the clien t and the browser. | |
| 157 * | |
| 158 * @param postMessageOrigin A origin that the client is requesting to b e identified as | |
| 159 * during the postMessage communication. | |
| 160 * @return Whether the implementation accepted the request. Note that return ing true | |
| 161 * here doesn't mean an origin has already been assigned as the vali dation is | |
| 162 * asynchronous. | |
| 163 */ | |
| 164 public boolean requestPostMessageChannel(Uri postMessageOrigin) { | |
| 155 try { | 165 try { |
| 156 return mService.validatePostMessageOrigin(mCallback); | 166 return mService.requestPostMessageChannel( |
| 167 mCallback, postMessageOrigin); | |
| 157 } catch (RemoteException e) { | 168 } catch (RemoteException e) { |
| 158 return false; | 169 return false; |
| 159 } | 170 } |
| 160 } | 171 } |
| 161 | 172 |
| 173 /** | |
| 174 * Sends a postMessage request using the origin communicated via | |
| 175 * {@link CustomTabsService#requestPostMessageChannel( | |
| 176 * CustomTabsSessionToken, Uri)}. Fails when called before | |
| 177 * {@link PostMessageServiceConnection#notifyMessageChannelReady(Bundle)} is received on | |
| 178 * the client side. | |
| 179 * | |
| 180 * @param message The message that is being sent. | |
| 181 * @param extras Reserved for future use. | |
| 182 * @return An integer constant about the postMessage request result. | |
|
Benoit L
2017/01/25 21:25:03
nit: Perhaps specify where are these constants? (T
Yusuf
2017/01/25 22:02:00
The most viable way to refer to the enum was to re
| |
| 183 */ | |
| 162 @Result | 184 @Result |
| 163 public synchronized int postMessage(String message, Bundle extras) { | 185 public int postMessage(String message, Bundle extras) { |
| 164 try { | 186 synchronized (mLock) { |
| 165 return mService.postMessage(mCallback, message, extras); | 187 try { |
| 166 } catch (RemoteException e) { | 188 return mService.postMessage(mCallback, message, extras); |
| 167 return CustomTabsService.RESULT_FAILURE_REMOTE_ERROR; | 189 } catch (RemoteException e) { |
| 190 return CustomTabsService.RESULT_FAILURE_REMOTE_ERROR; | |
| 191 } | |
| 168 } | 192 } |
| 169 } | 193 } |
| 170 | 194 |
| 171 /* package */ IBinder getBinder() { | 195 /* package */ IBinder getBinder() { |
| 172 return mCallback.asBinder(); | 196 return mCallback.asBinder(); |
| 173 } | 197 } |
| 174 | 198 |
| 175 /* package */ ComponentName getComponentName() { | 199 /* package */ ComponentName getComponentName() { |
| 176 return mComponentName; | 200 return mComponentName; |
| 177 } | 201 } |
| 178 } | 202 } |
| OLD | NEW |