Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
| 6 | 6 |
| 7 import android.net.Uri; | 7 import android.net.Uri; |
| 8 import android.support.customtabs.CustomTabsService; | 8 import android.support.customtabs.CustomTabsService; |
| 9 import android.support.customtabs.CustomTabsSessionToken; | 9 import android.support.customtabs.CustomTabsSessionToken; |
| 10 | 10 |
| 11 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
| 12 import org.chromium.chrome.browser.tab.Tab; | 12 import org.chromium.chrome.browser.tab.Tab; |
| 13 import org.chromium.content.browser.AppWebMessagePort; | 13 import org.chromium.content.browser.AppWebMessagePort; |
| 14 import org.chromium.content.browser.AppWebMessagePortService; | 14 import org.chromium.content.browser.AppWebMessagePortService; |
| 15 import org.chromium.content.browser.AppWebMessagePortService.MessageChannelObser ver; | 15 import org.chromium.content.browser.AppWebMessagePortService.MessageChannelObser ver; |
| 16 import org.chromium.content.browser.PostMessageSender; | 16 import org.chromium.content.browser.PostMessageSender; |
| 17 import org.chromium.content.browser.PostMessageSender.PostMessageSenderDelegate; | 17 import org.chromium.content.browser.PostMessageSender.PostMessageSenderDelegate; |
| 18 import org.chromium.content_public.browser.MessagePort; | 18 import org.chromium.content_public.browser.MessagePort; |
| 19 import org.chromium.content_public.browser.MessagePort.MessageCallback; | 19 import org.chromium.content_public.browser.MessagePort.MessageCallback; |
| 20 import org.chromium.content_public.browser.NavigationHandle; | |
| 20 import org.chromium.content_public.browser.WebContents; | 21 import org.chromium.content_public.browser.WebContents; |
| 21 import org.chromium.content_public.browser.WebContentsObserver; | 22 import org.chromium.content_public.browser.WebContentsObserver; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * A class that handles postMessage communications with a designated {@link Cust omTabsSessionToken}. | 25 * A class that handles postMessage communications with a designated {@link Cust omTabsSessionToken}. |
| 25 */ | 26 */ |
| 26 public class PostMessageHandler { | 27 public class PostMessageHandler { |
| 27 private static AppWebMessagePortService sService; | 28 private static AppWebMessagePortService sService; |
| 28 | 29 |
| 29 private final CustomTabsSessionToken mSession; | 30 private final CustomTabsSessionToken mSession; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 * {@link CustomTabsSessionToken} with a new {@link WebContents} and the {@l ink Tab} that | 62 * {@link CustomTabsSessionToken} with a new {@link WebContents} and the {@l ink Tab} that |
| 62 * contains it. | 63 * contains it. |
| 63 * @param webContents The new {@link WebContents} that the session got assoc iated with. | 64 * @param webContents The new {@link WebContents} that the session got assoc iated with. |
| 64 */ | 65 */ |
| 65 public void reset(final WebContents webContents) { | 66 public void reset(final WebContents webContents) { |
| 66 if (mOrigin == null) return; | 67 if (mOrigin == null) return; |
| 67 new WebContentsObserver(webContents) { | 68 new WebContentsObserver(webContents) { |
| 68 private boolean mNavigatedOnce; | 69 private boolean mNavigatedOnce; |
| 69 | 70 |
| 70 @Override | 71 @Override |
| 71 public void didNavigateMainFrame(String url, String baseUrl, | 72 public void didFinishNavigation(NavigationHandle navigation) { |
|
Maria
2016/12/27 19:31:10
I think this should now include a check that we ar
| |
| 72 boolean isNavigationToDifferentPage, boolean isFragmentNavig ation, | 73 if (mNavigatedOnce && !navigation.isSamePage() && mChannel != nu ll) { |
| 73 int statusCode) { | |
| 74 if (mNavigatedOnce && isNavigationToDifferentPage && mChannel != null) { | |
| 75 mChannel[0].close(); | 74 mChannel[0].close(); |
| 76 mChannel = null; | 75 mChannel = null; |
| 77 mSenderDelegate = null; | 76 mSenderDelegate = null; |
| 78 mPostMessageSender = null; | 77 mPostMessageSender = null; |
| 79 webContents.removeObserver(this); | 78 webContents.removeObserver(this); |
| 80 return; | 79 return; |
| 81 } | 80 } |
| 82 mNavigatedOnce = true; | 81 mNavigatedOnce = true; |
| 83 } | 82 } |
| 84 | 83 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 public void run() { | 144 public void run() { |
| 146 // It is still possible that the page has navigated while this t ask is in the queue. | 145 // It is still possible that the page has navigated while this t ask is in the queue. |
| 147 // If that happens fail gracefully. | 146 // If that happens fail gracefully. |
| 148 if (mChannel == null || mChannel[0].isClosed()) return; | 147 if (mChannel == null || mChannel[0].isClosed()) return; |
| 149 mChannel[0].postMessage(message, null); | 148 mChannel[0].postMessage(message, null); |
| 150 } | 149 } |
| 151 }); | 150 }); |
| 152 return CustomTabsService.RESULT_SUCCESS; | 151 return CustomTabsService.RESULT_SUCCESS; |
| 153 } | 152 } |
| 154 } | 153 } |
| OLD | NEW |