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; |
12 import org.chromium.blimp.core.common.BlimpClientContextInternal; | |
11 import org.chromium.blimp.core.settings.AboutBlimpPreferences; | 13 import org.chromium.blimp.core.settings.AboutBlimpPreferences; |
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, BlimpClientCo ntextInternal { |
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(long nativeBlimpSettingsAndroid) { |
41 mDelegate = delegate; | 42 nativeInitSettingsPage(mNativeBlimpClientContextImplAndroid, nativeBlimp SettingsAndroid); |
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 void attachBlimpPreferences(PreferenceFragment fragment, | 71 public boolean isBlimpEnabled() { |
71 BlimpSettingsCallbacks callbacks) { | 72 return PreferencesUtil.isBlimpEnabled() |
72 AboutBlimpPreferences.addBlimpPreferences(fragment); | 73 || CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGIN E_IP); |
73 AboutBlimpPreferences.registerCallback(callbacks); | |
74 } | 74 } |
75 | 75 |
76 @Override | 76 @Override |
77 public void attachBlimpPreferences(PreferenceFragment fragment) { | |
78 AboutBlimpPreferences.addBlimpPreferences(fragment); | |
79 AboutBlimpPreferences.setContext(this); | |
David Trainor- moved to gerrit
2016/08/29 05:12:24
What do you think about merging these methods?
xingliu
2016/08/30 04:47:42
Done, there is one function to do these two things
| |
80 } | |
81 | |
82 @Override | |
83 public void setDelegate(BlimpClientContextDelegate delegate) { | |
84 mDelegate = delegate; | |
85 } | |
86 | |
87 @Override | |
77 public void connect() { | 88 public void connect() { |
78 assert mNativeBlimpClientContextImplAndroid != 0; | 89 assert mNativeBlimpClientContextImplAndroid != 0; |
79 nativeConnectFromJava(mNativeBlimpClientContextImplAndroid); | 90 nativeConnectFromJava(mNativeBlimpClientContextImplAndroid); |
80 } | 91 } |
81 | 92 |
82 @CalledByNative | 93 @CalledByNative |
83 private void clearNativePtr() { | 94 private void clearNativePtr() { |
84 mNativeBlimpClientContextImplAndroid = 0; | 95 mNativeBlimpClientContextImplAndroid = 0; |
85 } | 96 } |
86 | 97 |
87 @CalledByNative | 98 @CalledByNative |
88 private long getNativePtr() { | 99 private long getNativePtr() { |
89 assert mNativeBlimpClientContextImplAndroid != 0; | 100 assert mNativeBlimpClientContextImplAndroid != 0; |
90 return mNativeBlimpClientContextImplAndroid; | 101 return mNativeBlimpClientContextImplAndroid; |
91 } | 102 } |
92 | 103 |
93 @CalledByNative | 104 @CalledByNative |
94 private String getAssignerUrl() { | 105 private String getAssignerUrl() { |
95 return PreferencesUtil.getLastUsedAssigner(); | 106 return PreferencesUtil.getLastUsedAssigner(); |
96 } | 107 } |
97 | 108 |
98 private native BlimpContents nativeCreateBlimpContentsJava( | 109 private native BlimpContents nativeCreateBlimpContentsJava( |
99 long nativeBlimpClientContextImplAndroid); | 110 long nativeBlimpClientContextImplAndroid); |
100 | 111 |
101 private native void nativeConnectFromJava(long nativeBlimpClientContextImplA ndroid); | 112 private native void nativeConnectFromJava(long nativeBlimpClientContextImplA ndroid); |
113 private native void nativeInitSettingsPage( | |
114 long nativeBlimpClientContextImplAndroid, long nativeBlimpSettingsAn droid); | |
102 } | 115 } |
OLD | NEW |