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.blimp.core; | 5 package org.chromium.blimp.core; |
6 | 6 |
7 import android.preference.PreferenceFragment; | 7 import android.preference.PreferenceFragment; |
8 | 8 |
| 9 import org.chromium.base.CommandLine; |
9 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
10 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
11 import org.chromium.blimp.core.settings.AboutBlimpPreferences; | 12 import org.chromium.blimp.core.settings.AboutBlimpPreferences; |
| 13 import org.chromium.blimp.core.settings.BlimpPreferencesDelegate; |
12 import org.chromium.blimp.core.settings.PreferencesUtil; | 14 import org.chromium.blimp.core.settings.PreferencesUtil; |
13 import org.chromium.blimp_public.BlimpClientContext; | 15 import org.chromium.blimp_public.BlimpClientContext; |
14 import org.chromium.blimp_public.BlimpClientContextDelegate; | 16 import org.chromium.blimp_public.BlimpClientContextDelegate; |
15 import org.chromium.blimp_public.BlimpSettingsCallbacks; | |
16 import org.chromium.blimp_public.contents.BlimpContents; | 17 import org.chromium.blimp_public.contents.BlimpContents; |
17 | 18 |
18 /** | 19 /** |
19 * BlimpClientContextImpl is a Java wrapper to allow communicating with the nati
ve | 20 * BlimpClientContextImpl is a Java wrapper to allow communicating with the nati
ve |
20 * BlimpClientContextImpl object. | 21 * BlimpClientContextImpl object. |
21 */ | 22 */ |
22 @JNINamespace("blimp::client") | 23 @JNINamespace("blimp::client") |
23 public class BlimpClientContextImpl implements BlimpClientContext { | 24 public class BlimpClientContextImpl implements BlimpClientContext, BlimpPreferen
cesDelegate { |
24 | |
25 // Delegate that contains functions Blimp needed in the embedder. | 25 // Delegate that contains functions Blimp needed in the embedder. |
26 private BlimpClientContextDelegate mDelegate; | 26 private BlimpClientContextDelegate mDelegate; |
27 | 27 |
28 /** | 28 /** |
29 * Get embedder delegate which provides necessary functionality and callback
s. | 29 * Get embedder delegate which provides necessary functionality and callback
s. |
30 * | 30 * |
31 * The delegate is created through JNI in early startup. | 31 * The delegate is created through JNI in early startup. |
32 * | 32 * |
33 * @return BlimpClientContextDelegate, which contains functions we need in e
mbedder. | 33 * @return BlimpClientContextDelegate, which contains functions we need in e
mbedder. |
34 */ | 34 */ |
| 35 @Override |
35 public BlimpClientContextDelegate getDelegate() { | 36 public BlimpClientContextDelegate getDelegate() { |
36 return mDelegate; | 37 return mDelegate; |
37 } | 38 } |
38 | 39 |
39 @Override | 40 @Override |
40 public void setDelegate(BlimpClientContextDelegate delegate) { | 41 public void initSettingsPage(AboutBlimpPreferences preferences) { |
41 mDelegate = delegate; | 42 nativeInitSettingsPage(mNativeBlimpClientContextImplAndroid, preferences
); |
42 } | 43 } |
43 | 44 |
44 @CalledByNative | 45 @CalledByNative |
45 private static BlimpClientContextImpl create(long nativeBlimpClientContextIm
plAndroid) { | 46 private static BlimpClientContextImpl create(long nativeBlimpClientContextIm
plAndroid) { |
46 return new BlimpClientContextImpl(nativeBlimpClientContextImplAndroid); | 47 return new BlimpClientContextImpl(nativeBlimpClientContextImplAndroid); |
47 } | 48 } |
48 | 49 |
49 /** | 50 /** |
50 * The pointer to the BlimpClientContextImplAndroid JNI bridge. | 51 * The pointer to the BlimpClientContextImplAndroid JNI bridge. |
51 */ | 52 */ |
52 private long mNativeBlimpClientContextImplAndroid; | 53 private long mNativeBlimpClientContextImplAndroid; |
53 | 54 |
54 private BlimpClientContextImpl(long nativeBlimpClientContextImplAndroid) { | 55 private BlimpClientContextImpl(long nativeBlimpClientContextImplAndroid) { |
55 mNativeBlimpClientContextImplAndroid = nativeBlimpClientContextImplAndro
id; | 56 mNativeBlimpClientContextImplAndroid = nativeBlimpClientContextImplAndro
id; |
56 } | 57 } |
57 | 58 |
58 @Override | 59 @Override |
59 public BlimpContents createBlimpContents() { | 60 public BlimpContents createBlimpContents() { |
60 assert mNativeBlimpClientContextImplAndroid != 0; | 61 assert mNativeBlimpClientContextImplAndroid != 0; |
61 return nativeCreateBlimpContentsJava(mNativeBlimpClientContextImplAndroi
d); | 62 return nativeCreateBlimpContentsJava(mNativeBlimpClientContextImplAndroi
d); |
62 } | 63 } |
63 | 64 |
64 @Override | 65 @Override |
65 public boolean isBlimpSupported() { | 66 public boolean isBlimpSupported() { |
66 return true; | 67 return true; |
67 } | 68 } |
68 | 69 |
69 @Override | 70 @Override |
70 public boolean isBlimpEnabled() { | 71 public boolean isBlimpEnabled() { |
71 return false; | 72 return PreferencesUtil.isBlimpEnabled() |
| 73 || CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGIN
E_IP); |
72 } | 74 } |
73 | 75 |
74 @Override | 76 @Override |
75 public void attachBlimpPreferences( | 77 public void attachBlimpPreferences(PreferenceFragment fragment) { |
76 PreferenceFragment fragment, BlimpSettingsCallbacks callbacks) { | 78 AboutBlimpPreferences.addBlimpPreferences(fragment, this); |
77 AboutBlimpPreferences.addBlimpPreferences(fragment); | |
78 AboutBlimpPreferences.registerCallback(callbacks); | |
79 } | 79 } |
80 | 80 |
81 @Override | 81 @Override |
| 82 public void setDelegate(BlimpClientContextDelegate delegate) { |
| 83 mDelegate = delegate; |
| 84 } |
| 85 |
| 86 @Override |
82 public void connect() { | 87 public void connect() { |
83 assert mNativeBlimpClientContextImplAndroid != 0; | 88 assert mNativeBlimpClientContextImplAndroid != 0; |
84 nativeConnectFromJava(mNativeBlimpClientContextImplAndroid); | 89 nativeConnectFromJava(mNativeBlimpClientContextImplAndroid); |
85 } | 90 } |
86 | 91 |
87 @CalledByNative | 92 @CalledByNative |
88 private void clearNativePtr() { | 93 private void clearNativePtr() { |
89 mNativeBlimpClientContextImplAndroid = 0; | 94 mNativeBlimpClientContextImplAndroid = 0; |
90 } | 95 } |
91 | 96 |
92 @CalledByNative | 97 @CalledByNative |
93 private long getNativePtr() { | 98 private long getNativePtr() { |
94 assert mNativeBlimpClientContextImplAndroid != 0; | 99 assert mNativeBlimpClientContextImplAndroid != 0; |
95 return mNativeBlimpClientContextImplAndroid; | 100 return mNativeBlimpClientContextImplAndroid; |
96 } | 101 } |
97 | 102 |
98 @CalledByNative | 103 @CalledByNative |
99 private String getAssignerUrl() { | 104 private String getAssignerUrl() { |
100 return PreferencesUtil.getLastUsedAssigner(); | 105 return PreferencesUtil.getLastUsedAssigner(); |
101 } | 106 } |
102 | 107 |
103 private native BlimpContents nativeCreateBlimpContentsJava( | 108 private native BlimpContents nativeCreateBlimpContentsJava( |
104 long nativeBlimpClientContextImplAndroid); | 109 long nativeBlimpClientContextImplAndroid); |
105 | 110 |
106 private native void nativeConnectFromJava(long nativeBlimpClientContextImplA
ndroid); | 111 private native void nativeConnectFromJava(long nativeBlimpClientContextImplA
ndroid); |
| 112 private native void nativeInitSettingsPage( |
| 113 long nativeBlimpClientContextImplAndroid, AboutBlimpPreferences pref
erences); |
107 } | 114 } |
OLD | NEW |