| 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.Intent; | 8 import android.content.Intent; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| 11 import android.util.Log; | 11 import android.util.Log; |
| 12 import android.view.KeyEvent; | 12 import android.view.KeyEvent; |
| 13 | 13 |
| 14 import org.chromium.base.ChromiumActivity; | 14 import org.chromium.base.ChromiumActivity; |
| 15 import org.chromium.content.app.LibraryLoader; | 15 import org.chromium.content.app.LibraryLoader; |
| 16 import org.chromium.content.browser.ActivityContentVideoViewDelegate; | 16 import org.chromium.content.browser.ActivityContentVideoViewDelegate; |
| 17 import org.chromium.content.browser.ContentVideoView; | 17 import org.chromium.content.browser.ContentVideoView; |
| 18 import org.chromium.content.browser.ContentView; | 18 import org.chromium.content.browser.ContentView; |
| 19 import org.chromium.content.browser.DeviceUtils; | 19 import org.chromium.content.browser.DeviceUtils; |
| 20 import org.chromium.content.common.CommandLine; | 20 import org.chromium.content.common.CommandLine; |
| 21 import org.chromium.content.common.ProcessInitException; |
| 21 import org.chromium.ui.gfx.ActivityNativeWindow; | 22 import org.chromium.ui.gfx.ActivityNativeWindow; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Activity for managing the Content Shell. | 25 * Activity for managing the Content Shell. |
| 25 */ | 26 */ |
| 26 public class ContentShellActivity extends ChromiumActivity { | 27 public class ContentShellActivity extends ChromiumActivity { |
| 27 | 28 |
| 28 public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shel
l-command-line"; | 29 public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shel
l-command-line"; |
| 29 private static final String TAG = ContentShellActivity.class.getName(); | 30 private static final String TAG = ContentShellActivity.class.getName(); |
| 30 | 31 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 43 if (!CommandLine.isInitialized()) { | 44 if (!CommandLine.isInitialized()) { |
| 44 CommandLine.initFromFile(COMMAND_LINE_FILE); | 45 CommandLine.initFromFile(COMMAND_LINE_FILE); |
| 45 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); | 46 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); |
| 46 if (commandLineParams != null) { | 47 if (commandLineParams != null) { |
| 47 CommandLine.getInstance().appendSwitchesAndArguments(commandLine
Params); | 48 CommandLine.getInstance().appendSwitchesAndArguments(commandLine
Params); |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 waitForDebuggerIfNeeded(); | 51 waitForDebuggerIfNeeded(); |
| 51 | 52 |
| 52 DeviceUtils.addDeviceSpecificUserAgentSwitch(this); | 53 DeviceUtils.addDeviceSpecificUserAgentSwitch(this); |
| 54 try { |
| 55 LibraryLoader.ensureInitialized(); |
| 53 | 56 |
| 54 LibraryLoader.ensureInitialized(); | 57 setContentView(R.layout.content_shell_activity); |
| 58 mShellManager = (ShellManager) findViewById(R.id.shell_container); |
| 59 mActivityNativeWindow = new ActivityNativeWindow(this); |
| 60 mActivityNativeWindow.restoreInstanceState(savedInstanceState); |
| 61 mShellManager.setWindow(mActivityNativeWindow); |
| 62 ContentVideoView.registerContentVideoViewContextDelegate( |
| 63 new ActivityContentVideoViewDelegate(this)); |
| 55 | 64 |
| 56 setContentView(R.layout.content_shell_activity); | 65 String startupUrl = getUrlFromIntent(getIntent()); |
| 57 mShellManager = (ShellManager) findViewById(R.id.shell_container); | 66 if (!TextUtils.isEmpty(startupUrl)) { |
| 58 mActivityNativeWindow = new ActivityNativeWindow(this); | 67 mShellManager.setStartupUrl(Shell.sanitizeUrl(startupUrl)); |
| 59 mActivityNativeWindow.restoreInstanceState(savedInstanceState); | 68 } |
| 60 mShellManager.setWindow(mActivityNativeWindow); | 69 if (!ContentView.enableMultiProcess(this, ContentView.MAX_RENDERERS_
AUTOMATIC)) { |
| 61 ContentVideoView.registerContentVideoViewContextDelegate( | 70 String shellUrl = DEFAULT_SHELL_URL; |
| 62 new ActivityContentVideoViewDelegate(this)); | 71 if (savedInstanceState != null |
| 63 | |
| 64 String startupUrl = getUrlFromIntent(getIntent()); | |
| 65 if (!TextUtils.isEmpty(startupUrl)) { | |
| 66 mShellManager.setStartupUrl(Shell.sanitizeUrl(startupUrl)); | |
| 67 } | |
| 68 | |
| 69 if (!ContentView.enableMultiProcess(this, ContentView.MAX_RENDERERS_AUTO
MATIC)) { | |
| 70 String shellUrl = DEFAULT_SHELL_URL; | |
| 71 if (savedInstanceState != null | |
| 72 && savedInstanceState.containsKey(ACTIVE_SHELL_URL_KEY)) { | 72 && savedInstanceState.containsKey(ACTIVE_SHELL_URL_KEY)) { |
| 73 shellUrl = savedInstanceState.getString(ACTIVE_SHELL_URL_KEY); | 73 shellUrl = savedInstanceState.getString(ACTIVE_SHELL_URL_KEY
); |
| 74 } |
| 75 mShellManager.launchShell(shellUrl); |
| 74 } | 76 } |
| 75 mShellManager.launchShell(shellUrl); | 77 } catch (ProcessInitException e) { |
| 78 Log.e(TAG, "ContentView initialization failed.", e); |
| 79 finish(); |
| 76 } | 80 } |
| 77 } | 81 } |
| 78 | 82 |
| 79 @Override | 83 @Override |
| 80 protected void onSaveInstanceState(Bundle outState) { | 84 protected void onSaveInstanceState(Bundle outState) { |
| 81 super.onSaveInstanceState(outState); | 85 super.onSaveInstanceState(outState); |
| 82 Shell activeShell = getActiveShell(); | 86 Shell activeShell = getActiveShell(); |
| 83 if (activeShell != null) { | 87 if (activeShell != null) { |
| 84 outState.putString(ACTIVE_SHELL_URL_KEY, activeShell.getContentView(
).getUrl()); | 88 outState.putString(ACTIVE_SHELL_URL_KEY, activeShell.getContentView(
).getUrl()); |
| 85 } | 89 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 174 |
| 171 /** | 175 /** |
| 172 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one | 176 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one |
| 173 * is not showing. | 177 * is not showing. |
| 174 */ | 178 */ |
| 175 public ContentView getActiveContentView() { | 179 public ContentView getActiveContentView() { |
| 176 Shell shell = getActiveShell(); | 180 Shell shell = getActiveShell(); |
| 177 return shell != null ? shell.getContentView() : null; | 181 return shell != null ? shell.getContentView() : null; |
| 178 } | 182 } |
| 179 } | 183 } |
| OLD | NEW |