OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.content_shell; | 5 package org.chromium.content_shell; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.drawable.ClipDrawable; | 8 import android.graphics.drawable.ClipDrawable; |
9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
10 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
11 import android.view.KeyEvent; | 11 import android.view.KeyEvent; |
12 import android.view.View; | 12 import android.view.View; |
13 import android.view.ViewGroup; | 13 import android.view.ViewGroup; |
14 import android.view.inputmethod.EditorInfo; | 14 import android.view.inputmethod.EditorInfo; |
15 import android.view.inputmethod.InputMethodManager; | 15 import android.view.inputmethod.InputMethodManager; |
16 import android.widget.EditText; | 16 import android.widget.EditText; |
17 import android.widget.FrameLayout; | 17 import android.widget.FrameLayout; |
18 import android.widget.ImageButton; | 18 import android.widget.ImageButton; |
19 import android.widget.LinearLayout; | 19 import android.widget.LinearLayout; |
20 import android.widget.TextView; | 20 import android.widget.TextView; |
21 import android.widget.TextView.OnEditorActionListener; | 21 import android.widget.TextView.OnEditorActionListener; |
22 | 22 |
23 import org.chromium.base.CalledByNative; | 23 import org.chromium.base.CalledByNative; |
24 import org.chromium.base.JNINamespace; | 24 import org.chromium.base.JNINamespace; |
25 import org.chromium.content.browser.ContentView; | 25 import org.chromium.content.browser.ContentView; |
26 import org.chromium.content.browser.ContentViewClient; | 26 import org.chromium.content.browser.ContentViewClient; |
27 import org.chromium.content.browser.ContentViewCore; | 27 import org.chromium.content.browser.ContentViewCore; |
28 import org.chromium.content.browser.ContentViewRenderView; | 28 import org.chromium.content.browser.ContentViewRenderView; |
29 import org.chromium.content_public.browser.LoadUrlParams; | 29 import org.chromium.content_public.browser.LoadUrlParams; |
| 30 import org.chromium.content_public.browser.NavigationController; |
| 31 import org.chromium.content_public.browser.WebContents; |
30 import org.chromium.ui.base.WindowAndroid; | 32 import org.chromium.ui.base.WindowAndroid; |
31 | 33 |
32 /** | 34 /** |
33 * Container for the various UI components that make up a shell window. | 35 * Container for the various UI components that make up a shell window. |
34 */ | 36 */ |
35 @JNINamespace("content") | 37 @JNINamespace("content") |
36 public class Shell extends LinearLayout { | 38 public class Shell extends LinearLayout { |
37 | 39 |
38 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; | 40 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; |
39 | 41 |
40 private final Runnable mClearProgressRunnable = new Runnable() { | 42 private final Runnable mClearProgressRunnable = new Runnable() { |
41 @Override | 43 @Override |
42 public void run() { | 44 public void run() { |
43 mProgressDrawable.setLevel(0); | 45 mProgressDrawable.setLevel(0); |
44 } | 46 } |
45 }; | 47 }; |
46 | 48 |
47 private ContentViewCore mContentViewCore; | 49 private ContentViewCore mContentViewCore; |
| 50 private WebContents mWebContents; |
| 51 private NavigationController mNavigationController; |
48 private ContentViewClient mContentViewClient; | 52 private ContentViewClient mContentViewClient; |
49 private EditText mUrlTextView; | 53 private EditText mUrlTextView; |
50 private ImageButton mPrevButton; | 54 private ImageButton mPrevButton; |
51 private ImageButton mNextButton; | 55 private ImageButton mNextButton; |
52 private ImageButton mStopButton; | 56 private ImageButton mStopButton; |
53 private ImageButton mReloadButton; | 57 private ImageButton mReloadButton; |
54 | 58 |
55 private ClipDrawable mProgressDrawable; | 59 private ClipDrawable mProgressDrawable; |
56 | 60 |
57 private long mNativeShell; | 61 private long mNativeShell; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 return true; | 159 return true; |
156 } | 160 } |
157 }); | 161 }); |
158 mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { | 162 mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { |
159 @Override | 163 @Override |
160 public void onFocusChange(View v, boolean hasFocus) { | 164 public void onFocusChange(View v, boolean hasFocus) { |
161 setKeyboardVisibilityForUrl(hasFocus); | 165 setKeyboardVisibilityForUrl(hasFocus); |
162 mNextButton.setVisibility(hasFocus ? GONE : VISIBLE); | 166 mNextButton.setVisibility(hasFocus ? GONE : VISIBLE); |
163 mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE); | 167 mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE); |
164 if (!hasFocus) { | 168 if (!hasFocus) { |
165 mUrlTextView.setText(mContentViewCore.getUrl()); | 169 mUrlTextView.setText(mWebContents.getUrl()); |
166 } | 170 } |
167 } | 171 } |
168 }); | 172 }); |
169 mUrlTextView.setOnKeyListener(new OnKeyListener() { | 173 mUrlTextView.setOnKeyListener(new OnKeyListener() { |
170 @Override | 174 @Override |
171 public boolean onKey(View v, int keyCode, KeyEvent event) { | 175 public boolean onKey(View v, int keyCode, KeyEvent event) { |
172 if (keyCode == KeyEvent.KEYCODE_BACK) { | 176 if (keyCode == KeyEvent.KEYCODE_BACK) { |
173 mContentViewCore.getContainerView().requestFocus(); | 177 mContentViewCore.getContainerView().requestFocus(); |
174 return true; | 178 return true; |
175 } | 179 } |
176 return false; | 180 return false; |
177 } | 181 } |
178 }); | 182 }); |
179 } | 183 } |
180 | 184 |
181 /** | 185 /** |
182 * Loads an URL. This will perform minimal amounts of sanitizing of the URL
to attempt to | 186 * Loads an URL. This will perform minimal amounts of sanitizing of the URL
to attempt to |
183 * make it valid. | 187 * make it valid. |
184 * | 188 * |
185 * @param url The URL to be loaded by the shell. | 189 * @param url The URL to be loaded by the shell. |
186 */ | 190 */ |
187 public void loadUrl(String url) { | 191 public void loadUrl(String url) { |
188 if (url == null) return; | 192 if (url == null) return; |
189 | 193 |
190 if (TextUtils.equals(url, mContentViewCore.getUrl())) { | 194 if (TextUtils.equals(url, mWebContents.getUrl())) { |
191 mContentViewCore.reload(true); | 195 mNavigationController.reload(true); |
192 } else { | 196 } else { |
193 mContentViewCore.loadUrl(new LoadUrlParams(sanitizeUrl(url))); | 197 mNavigationController.loadUrl(new LoadUrlParams(sanitizeUrl(url))); |
194 } | 198 } |
195 mUrlTextView.clearFocus(); | 199 mUrlTextView.clearFocus(); |
196 // TODO(aurimas): Remove this when crbug.com/174541 is fixed. | 200 // TODO(aurimas): Remove this when crbug.com/174541 is fixed. |
197 mContentViewCore.getContainerView().clearFocus(); | 201 mContentViewCore.getContainerView().clearFocus(); |
198 mContentViewCore.getContainerView().requestFocus(); | 202 mContentViewCore.getContainerView().requestFocus(); |
199 } | 203 } |
200 | 204 |
201 /** | 205 /** |
202 * Given an URL, this performs minimal sanitizing to ensure it will be valid
. | 206 * Given an URL, this performs minimal sanitizing to ensure it will be valid
. |
203 * @param url The url to be sanitized. | 207 * @param url The url to be sanitized. |
204 * @return The sanitized URL. | 208 * @return The sanitized URL. |
205 */ | 209 */ |
206 public static String sanitizeUrl(String url) { | 210 public static String sanitizeUrl(String url) { |
207 if (url == null) return null; | 211 if (url == null) return null; |
208 if (url.startsWith("www.") || url.indexOf(":") == -1) url = "http://" +
url; | 212 if (url.startsWith("www.") || url.indexOf(":") == -1) url = "http://" +
url; |
209 return url; | 213 return url; |
210 } | 214 } |
211 | 215 |
212 private void initializeNavigationButtons() { | 216 private void initializeNavigationButtons() { |
213 mPrevButton = (ImageButton) findViewById(R.id.prev); | 217 mPrevButton = (ImageButton) findViewById(R.id.prev); |
214 mPrevButton.setOnClickListener(new OnClickListener() { | 218 mPrevButton.setOnClickListener(new OnClickListener() { |
215 @Override | 219 @Override |
216 public void onClick(View v) { | 220 public void onClick(View v) { |
217 if (mContentViewCore.canGoBack()) mContentViewCore.goBack(); | 221 if (mNavigationController.canGoBack()) mNavigationController.goB
ack(); |
218 } | 222 } |
219 }); | 223 }); |
220 | 224 |
221 mNextButton = (ImageButton) findViewById(R.id.next); | 225 mNextButton = (ImageButton) findViewById(R.id.next); |
222 mNextButton.setOnClickListener(new OnClickListener() { | 226 mNextButton.setOnClickListener(new OnClickListener() { |
223 @Override | 227 @Override |
224 public void onClick(View v) { | 228 public void onClick(View v) { |
225 if (mContentViewCore.canGoForward()) mContentViewCore.goForward(
); | 229 if (mNavigationController.canGoForward()) mNavigationController.
goForward(); |
226 } | 230 } |
227 }); | 231 }); |
228 mStopButton = (ImageButton)findViewById(R.id.stop); | 232 mStopButton = (ImageButton)findViewById(R.id.stop); |
229 mStopButton.setOnClickListener(new OnClickListener() { | 233 mStopButton.setOnClickListener(new OnClickListener() { |
230 @Override | 234 @Override |
231 public void onClick(View v) { | 235 public void onClick(View v) { |
232 if (mLoading) mContentViewCore.stopLoading(); | 236 if (mLoading) mWebContents.stop(); |
233 } | 237 } |
234 }); | 238 }); |
235 mReloadButton = (ImageButton)findViewById(R.id.reload); | 239 mReloadButton = (ImageButton)findViewById(R.id.reload); |
236 mReloadButton.setOnClickListener(new OnClickListener() { | 240 mReloadButton.setOnClickListener(new OnClickListener() { |
237 @Override | 241 @Override |
238 public void onClick(View v) { | 242 public void onClick(View v) { |
239 mContentViewCore.reload(true); | 243 mNavigationController.reload(true); |
240 } | 244 } |
241 }); | 245 }); |
242 } | 246 } |
243 | 247 |
244 @SuppressWarnings("unused") | 248 @SuppressWarnings("unused") |
245 @CalledByNative | 249 @CalledByNative |
246 private void onUpdateUrl(String url) { | 250 private void onUpdateUrl(String url) { |
247 mUrlTextView.setText(url); | 251 mUrlTextView.setText(url); |
248 } | 252 } |
249 | 253 |
(...skipping 25 matching lines...) Expand all Loading... |
275 * @param nativeWebContents The pointer to the native tab contents object. | 279 * @param nativeWebContents The pointer to the native tab contents object. |
276 */ | 280 */ |
277 @SuppressWarnings("unused") | 281 @SuppressWarnings("unused") |
278 @CalledByNative | 282 @CalledByNative |
279 private void initFromNativeTabContents(long nativeWebContents) { | 283 private void initFromNativeTabContents(long nativeWebContents) { |
280 Context context = getContext(); | 284 Context context = getContext(); |
281 mContentViewCore = new ContentViewCore(context); | 285 mContentViewCore = new ContentViewCore(context); |
282 ContentView cv = ContentView.newInstance(context, mContentViewCore); | 286 ContentView cv = ContentView.newInstance(context, mContentViewCore); |
283 mContentViewCore.initialize(cv, cv, nativeWebContents, mWindow); | 287 mContentViewCore.initialize(cv, cv, nativeWebContents, mWindow); |
284 mContentViewCore.setContentViewClient(mContentViewClient); | 288 mContentViewCore.setContentViewClient(mContentViewClient); |
285 | 289 mWebContents = mContentViewCore.getWebContents(); |
| 290 mNavigationController = mWebContents.getNavigationController(); |
286 if (getParent() != null) mContentViewCore.onShow(); | 291 if (getParent() != null) mContentViewCore.onShow(); |
287 if (mContentViewCore.getUrl() != null) mUrlTextView.setText(mContentView
Core.getUrl()); | 292 if (mWebContents.getUrl() != null) { |
| 293 mUrlTextView.setText(mWebContents.getUrl()); |
| 294 } |
288 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(cv, | 295 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(cv, |
289 new FrameLayout.LayoutParams( | 296 new FrameLayout.LayoutParams( |
290 FrameLayout.LayoutParams.MATCH_PARENT, | 297 FrameLayout.LayoutParams.MATCH_PARENT, |
291 FrameLayout.LayoutParams.MATCH_PARENT)); | 298 FrameLayout.LayoutParams.MATCH_PARENT)); |
292 cv.requestFocus(); | 299 cv.requestFocus(); |
293 mContentViewRenderView.setCurrentContentViewCore(mContentViewCore); | 300 mContentViewRenderView.setCurrentContentViewCore(mContentViewCore); |
294 } | 301 } |
295 | 302 |
296 /** | 303 /** |
297 * Enable/Disable navigation(Prev/Next) button if navigation is allowed/disa
llowed | 304 * Enable/Disable navigation(Prev/Next) button if navigation is allowed/disa
llowed |
(...skipping 30 matching lines...) Expand all Loading... |
328 Context.INPUT_METHOD_SERVICE); | 335 Context.INPUT_METHOD_SERVICE); |
329 if (visible) { | 336 if (visible) { |
330 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); | 337 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); |
331 } else { | 338 } else { |
332 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); | 339 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); |
333 } | 340 } |
334 } | 341 } |
335 | 342 |
336 private static native void nativeCloseShell(long shellPtr); | 343 private static native void nativeCloseShell(long shellPtr); |
337 } | 344 } |
OLD | NEW |