Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: customtabs/src/android/support/customtabs/CustomTabsSession.java

Issue 2591513002: Add a service to handle postMessage callbacks to client (Closed)
Patch Set: lizeb@ nits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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. Will re turn
183 * {@link CustomTabsService#RESULT_SUCCESS} if successful.
184 */
162 @Result 185 @Result
163 public synchronized int postMessage(String message, Bundle extras) { 186 public int postMessage(String message, Bundle extras) {
164 try { 187 synchronized (mLock) {
165 return mService.postMessage(mCallback, message, extras); 188 try {
166 } catch (RemoteException e) { 189 return mService.postMessage(mCallback, message, extras);
167 return CustomTabsService.RESULT_FAILURE_REMOTE_ERROR; 190 } catch (RemoteException e) {
191 return CustomTabsService.RESULT_FAILURE_REMOTE_ERROR;
192 }
168 } 193 }
169 } 194 }
170 195
171 /* package */ IBinder getBinder() { 196 /* package */ IBinder getBinder() {
172 return mCallback.asBinder(); 197 return mCallback.asBinder();
173 } 198 }
174 199
175 /* package */ ComponentName getComponentName() { 200 /* package */ ComponentName getComponentName() {
176 return mComponentName; 201 return mComponentName;
177 } 202 }
178 } 203 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698