| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.BroadcastReceiver; | 8 import android.content.BroadcastReceiver; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| 11 import android.content.IntentFilter; | 11 import android.content.IntentFilter; |
| 12 import android.os.Bundle; | 12 import android.os.Bundle; |
| 13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
| 14 import android.util.Log; | 14 import android.util.Log; |
| 15 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
| 16 | 16 |
| 17 import org.chromium.base.ChromiumActivity; | 17 import org.chromium.base.ChromiumActivity; |
| 18 import org.chromium.content.app.LibraryLoader; | 18 import org.chromium.content.app.LibraryLoader; |
| 19 import org.chromium.content.browser.ActivityContentVideoViewDelegate; | 19 import org.chromium.content.browser.ActivityContentVideoViewDelegate; |
| 20 import org.chromium.content.browser.ContentVideoView; | 20 import org.chromium.content.browser.ContentVideoView; |
| 21 import org.chromium.content.browser.ContentView; | 21 import org.chromium.content.browser.ContentView; |
| 22 import org.chromium.content.browser.DeviceUtils; | 22 import org.chromium.content.browser.DeviceUtils; |
| 23 import org.chromium.content.browser.TracingIntentHandler; | 23 import org.chromium.content.browser.TracingIntentHandler; |
| 24 import org.chromium.content.common.CommandLine; | 24 import org.chromium.content.common.CommandLine; |
| 25 import org.chromium.content.common.ProcessInitException; |
| 25 import org.chromium.ui.gfx.ActivityNativeWindow; | 26 import org.chromium.ui.gfx.ActivityNativeWindow; |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Activity for managing the Content Shell. | 29 * Activity for managing the Content Shell. |
| 29 */ | 30 */ |
| 30 public class ContentShellActivity extends ChromiumActivity { | 31 public class ContentShellActivity extends ChromiumActivity { |
| 31 | 32 |
| 32 public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shel
l-command-line"; | 33 public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shel
l-command-line"; |
| 33 private static final String TAG = ContentShellActivity.class.getName(); | 34 private static final String TAG = ContentShellActivity.class.getName(); |
| 34 | 35 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 if (!CommandLine.isInitialized()) { | 53 if (!CommandLine.isInitialized()) { |
| 53 CommandLine.initFromFile(COMMAND_LINE_FILE); | 54 CommandLine.initFromFile(COMMAND_LINE_FILE); |
| 54 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); | 55 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); |
| 55 if (commandLineParams != null) { | 56 if (commandLineParams != null) { |
| 56 CommandLine.getInstance().appendSwitchesAndArguments(commandLine
Params); | 57 CommandLine.getInstance().appendSwitchesAndArguments(commandLine
Params); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 waitForDebuggerIfNeeded(); | 60 waitForDebuggerIfNeeded(); |
| 60 | 61 |
| 61 DeviceUtils.addDeviceSpecificUserAgentSwitch(this); | 62 DeviceUtils.addDeviceSpecificUserAgentSwitch(this); |
| 63 try { |
| 64 LibraryLoader.ensureInitialized(); |
| 62 | 65 |
| 63 LibraryLoader.ensureInitialized(); | 66 setContentView(R.layout.content_shell_activity); |
| 67 mShellManager = (ShellManager) findViewById(R.id.shell_container); |
| 68 mActivityNativeWindow = new ActivityNativeWindow(this); |
| 69 mActivityNativeWindow.restoreInstanceState(savedInstanceState); |
| 70 mShellManager.setWindow(mActivityNativeWindow); |
| 71 ContentVideoView.registerContentVideoViewContextDelegate( |
| 72 new ActivityContentVideoViewDelegate(this)); |
| 64 | 73 |
| 65 setContentView(R.layout.content_shell_activity); | 74 String startupUrl = getUrlFromIntent(getIntent()); |
| 66 mShellManager = (ShellManager) findViewById(R.id.shell_container); | 75 if (!TextUtils.isEmpty(startupUrl)) { |
| 67 mActivityNativeWindow = new ActivityNativeWindow(this); | 76 mShellManager.setStartupUrl(Shell.sanitizeUrl(startupUrl)); |
| 68 mActivityNativeWindow.restoreInstanceState(savedInstanceState); | 77 } |
| 69 mShellManager.setWindow(mActivityNativeWindow); | 78 if (!ContentView.enableMultiProcess(this, ContentView.MAX_RENDERERS_
AUTOMATIC)) { |
| 70 ContentVideoView.registerContentVideoViewContextDelegate( | 79 String shellUrl = DEFAULT_SHELL_URL; |
| 71 new ActivityContentVideoViewDelegate(this)); | 80 if (savedInstanceState != null |
| 72 | |
| 73 String startupUrl = getUrlFromIntent(getIntent()); | |
| 74 if (!TextUtils.isEmpty(startupUrl)) { | |
| 75 mShellManager.setStartupUrl(Shell.sanitizeUrl(startupUrl)); | |
| 76 } | |
| 77 | |
| 78 if (!ContentView.enableMultiProcess(this, ContentView.MAX_RENDERERS_AUTO
MATIC)) { | |
| 79 String shellUrl = DEFAULT_SHELL_URL; | |
| 80 if (savedInstanceState != null | |
| 81 && savedInstanceState.containsKey(ACTIVE_SHELL_URL_KEY)) { | 81 && savedInstanceState.containsKey(ACTIVE_SHELL_URL_KEY)) { |
| 82 shellUrl = savedInstanceState.getString(ACTIVE_SHELL_URL_KEY); | 82 shellUrl = savedInstanceState.getString(ACTIVE_SHELL_URL_KEY
); |
| 83 } |
| 84 mShellManager.launchShell(shellUrl); |
| 83 } | 85 } |
| 84 mShellManager.launchShell(shellUrl); | 86 } catch (ProcessInitException e) { |
| 87 Log.e(TAG, "ContentView initialization failed.", e); |
| 88 finish(); |
| 85 } | 89 } |
| 86 } | 90 } |
| 87 | 91 |
| 88 @Override | 92 @Override |
| 89 protected void onSaveInstanceState(Bundle outState) { | 93 protected void onSaveInstanceState(Bundle outState) { |
| 90 super.onSaveInstanceState(outState); | 94 super.onSaveInstanceState(outState); |
| 91 Shell activeShell = getActiveShell(); | 95 Shell activeShell = getActiveShell(); |
| 92 if (activeShell != null) { | 96 if (activeShell != null) { |
| 93 outState.putString(ACTIVE_SHELL_URL_KEY, activeShell.getContentView(
).getUrl()); | 97 outState.putString(ACTIVE_SHELL_URL_KEY, activeShell.getContentView(
).getUrl()); |
| 94 } | 98 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 205 |
| 202 /** | 206 /** |
| 203 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one | 207 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one |
| 204 * is not showing. | 208 * is not showing. |
| 205 */ | 209 */ |
| 206 public ContentView getActiveContentView() { | 210 public ContentView getActiveContentView() { |
| 207 Shell shell = getActiveShell(); | 211 Shell shell = getActiveShell(); |
| 208 return shell != null ? shell.getContentView() : null; | 212 return shell != null ? shell.getContentView() : null; |
| 209 } | 213 } |
| 210 } | 214 } |
| OLD | NEW |