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.content.app.AppResource; | 14 import org.chromium.content.app.AppResource; |
15 import org.chromium.content.app.LibraryLoader; | 15 import org.chromium.content.app.LibraryLoader; |
16 import org.chromium.content.browser.ContentView; | 16 import org.chromium.content.browser.ContentView; |
17 import org.chromium.content.common.CommandLine; | 17 import org.chromium.content.common.CommandLine; |
18 import org.chromium.ui.gfx.ActivityNativeWindow; | 18 import org.chromium.ui.gfx.ActivityNativeWindow; |
19 | 19 |
20 /** | 20 /** |
21 * Activity for managing the Content Shell. | 21 * Activity for managing the Content Shell. |
22 */ | 22 */ |
23 public class ContentShellActivity extends Activity { | 23 public class ContentShellActivity extends Activity { |
24 | 24 |
25 private static final String COMMAND_LINE_FILE = "/data/local/tmp/content-she
ll-command-line"; | 25 private static final String COMMAND_LINE_FILE = "/data/local/tmp/content-she
ll-command-line"; |
26 private static final String TAG = ContentShellActivity.class.getName(); | 26 private static final String TAG = ContentShellActivity.class.getName(); |
27 | 27 |
28 private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; | 28 private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; |
29 public static final String DEFAULT_SHELL_URL = "http://www.google.com"; | 29 public static final String DEFAULT_SHELL_URL = "http://www.google.com"; |
| 30 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; |
30 | 31 |
31 private ShellManager mShellManager; | 32 private ShellManager mShellManager; |
32 private ActivityNativeWindow mActivityNativeWindow; | 33 private ActivityNativeWindow mActivityNativeWindow; |
33 | 34 |
34 @Override | 35 @Override |
35 protected void onCreate(Bundle savedInstanceState) { | 36 protected void onCreate(Bundle savedInstanceState) { |
36 super.onCreate(savedInstanceState); | 37 super.onCreate(savedInstanceState); |
37 | 38 |
38 // Initializing the command line must occur before loading the library. | 39 // Initializing the command line must occur before loading the library. |
39 if (!CommandLine.isInitialized()) CommandLine.initFromFile(COMMAND_LINE_
FILE); | 40 if (!CommandLine.isInitialized()) { |
| 41 CommandLine.initFromFile(COMMAND_LINE_FILE); |
| 42 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); |
| 43 if (commandLineParams != null) { |
| 44 CommandLine.getInstance().appendSwitchesAndArguments(commandLine
Params); |
| 45 } |
| 46 } |
40 waitForDebuggerIfNeeded(); | 47 waitForDebuggerIfNeeded(); |
41 | 48 |
42 LibraryLoader.loadAndInitSync(); | 49 LibraryLoader.loadAndInitSync(); |
43 initializeContentViewResources(); | 50 initializeContentViewResources(); |
44 | 51 |
45 setContentView(R.layout.content_shell_activity); | 52 setContentView(R.layout.content_shell_activity); |
46 mShellManager = (ShellManager) findViewById(R.id.shell_container); | 53 mShellManager = (ShellManager) findViewById(R.id.shell_container); |
47 mActivityNativeWindow = new ActivityNativeWindow(this); | 54 mActivityNativeWindow = new ActivityNativeWindow(this); |
48 mActivityNativeWindow.restoreInstanceState(savedInstanceState); | 55 mActivityNativeWindow.restoreInstanceState(savedInstanceState); |
49 mShellManager.setWindow(mActivityNativeWindow); | 56 mShellManager.setWindow(mActivityNativeWindow); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (activeView != null && activeView.getContentView().canGoBack()) { | 97 if (activeView != null && activeView.getContentView().canGoBack()) { |
91 activeView.getContentView().goBack(); | 98 activeView.getContentView().goBack(); |
92 return true; | 99 return true; |
93 } | 100 } |
94 | 101 |
95 return super.onKeyUp(keyCode, event); | 102 return super.onKeyUp(keyCode, event); |
96 } | 103 } |
97 | 104 |
98 @Override | 105 @Override |
99 protected void onNewIntent(Intent intent) { | 106 protected void onNewIntent(Intent intent) { |
| 107 if (getCommandLineParamsFromIntent(intent) != null) { |
| 108 Log.i(TAG, "Ignoring command line params: can only be set when creat
ing the activity."); |
| 109 } |
| 110 |
100 String url = getUrlFromIntent(intent); | 111 String url = getUrlFromIntent(intent); |
101 if (!TextUtils.isEmpty(url)) { | 112 if (!TextUtils.isEmpty(url)) { |
102 Shell activeView = getActiveShell(); | 113 Shell activeView = getActiveShell(); |
103 if (activeView != null) { | 114 if (activeView != null) { |
104 activeView.loadUrl(url); | 115 activeView.loadUrl(url); |
105 } | 116 } |
106 } | 117 } |
107 } | 118 } |
108 | 119 |
109 @Override | 120 @Override |
(...skipping 15 matching lines...) Expand all Loading... |
125 @Override | 136 @Override |
126 public void onActivityResult(int requestCode, int resultCode, Intent data) { | 137 public void onActivityResult(int requestCode, int resultCode, Intent data) { |
127 super.onActivityResult(requestCode, resultCode, data); | 138 super.onActivityResult(requestCode, resultCode, data); |
128 mActivityNativeWindow.onActivityResult(requestCode, resultCode, data); | 139 mActivityNativeWindow.onActivityResult(requestCode, resultCode, data); |
129 } | 140 } |
130 | 141 |
131 private static String getUrlFromIntent(Intent intent) { | 142 private static String getUrlFromIntent(Intent intent) { |
132 return intent != null ? intent.getDataString() : null; | 143 return intent != null ? intent.getDataString() : null; |
133 } | 144 } |
134 | 145 |
| 146 private static String[] getCommandLineParamsFromIntent(Intent intent) { |
| 147 return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY
) : null; |
| 148 } |
| 149 |
135 /** | 150 /** |
136 * @return The {@link ShellManager} configured for the activity or null if i
t has not been | 151 * @return The {@link ShellManager} configured for the activity or null if i
t has not been |
137 * created yet. | 152 * created yet. |
138 */ | 153 */ |
139 public ShellManager getShellManager() { | 154 public ShellManager getShellManager() { |
140 return mShellManager; | 155 return mShellManager; |
141 } | 156 } |
142 | 157 |
143 /** | 158 /** |
144 * @return The currently visible {@link Shell} or null if one is not showing
. | 159 * @return The currently visible {@link Shell} or null if one is not showing
. |
145 */ | 160 */ |
146 public Shell getActiveShell() { | 161 public Shell getActiveShell() { |
147 return mShellManager != null ? mShellManager.getActiveShell() : null; | 162 return mShellManager != null ? mShellManager.getActiveShell() : null; |
148 } | 163 } |
149 | 164 |
150 /** | 165 /** |
151 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one | 166 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one |
152 * is not showing. | 167 * is not showing. |
153 */ | 168 */ |
154 public ContentView getActiveContentView() { | 169 public ContentView getActiveContentView() { |
155 Shell shell = getActiveShell(); | 170 Shell shell = getActiveShell(); |
156 return shell != null ? shell.getContentView() : null; | 171 return shell != null ? shell.getContentView() : null; |
157 } | 172 } |
158 | 173 |
159 private void initializeContentViewResources() { | 174 private void initializeContentViewResources() { |
160 AppResource.DIMENSION_LINK_PREVIEW_OVERLAY_RADIUS = R.dimen.link_preview
_overlay_radius; | 175 AppResource.DIMENSION_LINK_PREVIEW_OVERLAY_RADIUS = R.dimen.link_preview
_overlay_radius; |
| 176 AppResource.DRAWABLE_ICON_ACTION_BAR_SHARE = R.drawable.ic_menu_share_ho
lo_light; |
| 177 AppResource.DRAWABLE_ICON_ACTION_BAR_WEB_SEARCH = R.drawable.ic_menu_sea
rch_holo_light; |
161 AppResource.DRAWABLE_LINK_PREVIEW_POPUP_OVERLAY = R.drawable.popup_zoome
r_overlay; | 178 AppResource.DRAWABLE_LINK_PREVIEW_POPUP_OVERLAY = R.drawable.popup_zoome
r_overlay; |
| 179 AppResource.STRING_ACTION_BAR_SHARE = R.string.action_bar_share; |
| 180 AppResource.STRING_ACTION_BAR_WEB_SEARCH = R.string.action_bar_search; |
162 AppResource.STRING_CONTENT_VIEW_CONTENT_DESCRIPTION = R.string.accessibi
lity_content_view; | 181 AppResource.STRING_CONTENT_VIEW_CONTENT_DESCRIPTION = R.string.accessibi
lity_content_view; |
163 AppResource.STRING_MEDIA_PLAYER_MESSAGE_PLAYBACK_ERROR = | 182 AppResource.STRING_MEDIA_PLAYER_MESSAGE_PLAYBACK_ERROR = |
164 R.string.media_player_error_text_invalid_progressive_playback; | 183 R.string.media_player_error_text_invalid_progressive_playback; |
165 AppResource.STRING_MEDIA_PLAYER_MESSAGE_UNKNOWN_ERROR = | 184 AppResource.STRING_MEDIA_PLAYER_MESSAGE_UNKNOWN_ERROR = |
166 R.string.media_player_error_text_unknown; | 185 R.string.media_player_error_text_unknown; |
167 AppResource.STRING_MEDIA_PLAYER_ERROR_BUTTON = R.string.media_player_err
or_button; | 186 AppResource.STRING_MEDIA_PLAYER_ERROR_BUTTON = R.string.media_player_err
or_button; |
168 AppResource.STRING_MEDIA_PLAYER_ERROR_TITLE = R.string.media_player_erro
r_title; | 187 AppResource.STRING_MEDIA_PLAYER_ERROR_TITLE = R.string.media_player_erro
r_title; |
169 } | 188 } |
170 } | 189 } |
OLD | NEW |