1 /******************************************************************************* |
|
2 * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 *******************************************************************************/ |
|
19 package org.symbian.tools.wrttools.debug.internal.launch; |
|
20 |
|
21 import java.io.IOException; |
|
22 import java.net.MalformedURLException; |
|
23 import java.net.URI; |
|
24 import java.net.URL; |
|
25 import java.util.List; |
|
26 |
|
27 import org.chromium.debug.core.model.TabSelector; |
|
28 import org.chromium.sdk.Browser.TabConnector; |
|
29 import org.chromium.sdk.Browser.TabFetcher; |
|
30 |
|
31 public class WidgetTabSelector implements TabSelector { |
|
32 private final URI uri; |
|
33 private TabConnector connector; |
|
34 |
|
35 public WidgetTabSelector(URI uri) { |
|
36 this.uri = uri; |
|
37 } |
|
38 |
|
39 public TabConnector selectTab(TabFetcher tabFetcher) throws IOException { |
|
40 // Give it time to start the process/tab. 5 retries, 500 ms inbetween. |
|
41 for (int i = 0; i < 5; i++) { |
|
42 List<? extends TabConnector> tabs = tabFetcher.getTabs(); |
|
43 for (TabConnector tabConnector : tabs) { |
|
44 String url = tabConnector.getUrl(); |
|
45 try { |
|
46 if (uri.toURL().equals(new URL(url))) { |
|
47 connector = tabConnector; |
|
48 return tabConnector; |
|
49 } |
|
50 } catch (MalformedURLException e) { |
|
51 // Ignore - fails because of "chrome" protocol, we should ignore these tabs anyways |
|
52 } |
|
53 } |
|
54 } |
|
55 return null; |
|
56 } |
|
57 |
|
58 public TabConnector getConnector() { |
|
59 return connector; |
|
60 } |
|
61 } |
|