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; |
| 9 import android.content.Context; |
8 import android.content.Intent; | 10 import android.content.Intent; |
| 11 import android.content.IntentFilter; |
9 import android.os.Bundle; | 12 import android.os.Bundle; |
10 import android.text.TextUtils; | 13 import android.text.TextUtils; |
11 import android.util.Log; | 14 import android.util.Log; |
12 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
13 | 16 |
14 import org.chromium.base.ChromiumActivity; | 17 import org.chromium.base.ChromiumActivity; |
15 import org.chromium.content.app.LibraryLoader; | 18 import org.chromium.content.app.LibraryLoader; |
16 import org.chromium.content.browser.ActivityContentVideoViewDelegate; | 19 import org.chromium.content.browser.ActivityContentVideoViewDelegate; |
17 import org.chromium.content.browser.ContentVideoView; | 20 import org.chromium.content.browser.ContentVideoView; |
18 import org.chromium.content.browser.ContentView; | 21 import org.chromium.content.browser.ContentView; |
19 import org.chromium.content.browser.DeviceUtils; | 22 import org.chromium.content.browser.DeviceUtils; |
| 23 import org.chromium.content.browser.TracingIntentHandler; |
20 import org.chromium.content.common.CommandLine; | 24 import org.chromium.content.common.CommandLine; |
21 import org.chromium.ui.gfx.ActivityNativeWindow; | 25 import org.chromium.ui.gfx.ActivityNativeWindow; |
22 | 26 |
23 /** | 27 /** |
24 * Activity for managing the Content Shell. | 28 * Activity for managing the Content Shell. |
25 */ | 29 */ |
26 public class ContentShellActivity extends ChromiumActivity { | 30 public class ContentShellActivity extends ChromiumActivity { |
27 | 31 |
28 public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shel
l-command-line"; | 32 public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shel
l-command-line"; |
29 private static final String TAG = ContentShellActivity.class.getName(); | 33 private static final String TAG = ContentShellActivity.class.getName(); |
30 | 34 |
31 private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; | 35 private static final String ACTIVE_SHELL_URL_KEY = "activeUrl"; |
| 36 private static final String ACTION_START_TRACE = |
| 37 "org.chromium.content_shell.action.PROFILE_START"; |
| 38 private static final String ACTION_STOP_TRACE = |
| 39 "org.chromium.content_shell.action.PROFILE_STOP"; |
32 public static final String DEFAULT_SHELL_URL = "http://www.google.com"; | 40 public static final String DEFAULT_SHELL_URL = "http://www.google.com"; |
33 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; | 41 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; |
34 | 42 |
35 private ShellManager mShellManager; | 43 private ShellManager mShellManager; |
36 private ActivityNativeWindow mActivityNativeWindow; | 44 private ActivityNativeWindow mActivityNativeWindow; |
| 45 private BroadcastReceiver mReceiver; |
37 | 46 |
38 @Override | 47 @Override |
39 protected void onCreate(Bundle savedInstanceState) { | 48 protected void onCreate(Bundle savedInstanceState) { |
40 super.onCreate(savedInstanceState); | 49 super.onCreate(savedInstanceState); |
41 | 50 |
42 // Initializing the command line must occur before loading the library. | 51 // Initializing the command line must occur before loading the library. |
43 if (!CommandLine.isInitialized()) { | 52 if (!CommandLine.isInitialized()) { |
44 CommandLine.initFromFile(COMMAND_LINE_FILE); | 53 CommandLine.initFromFile(COMMAND_LINE_FILE); |
45 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); | 54 String[] commandLineParams = getCommandLineParamsFromIntent(getInten
t()); |
46 if (commandLineParams != null) { | 55 if (commandLineParams != null) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 131 } |
123 } | 132 } |
124 } | 133 } |
125 | 134 |
126 @Override | 135 @Override |
127 protected void onPause() { | 136 protected void onPause() { |
128 ContentView view = getActiveContentView(); | 137 ContentView view = getActiveContentView(); |
129 if (view != null) view.onActivityPause(); | 138 if (view != null) view.onActivityPause(); |
130 | 139 |
131 super.onPause(); | 140 super.onPause(); |
| 141 unregisterReceiver(mReceiver); |
132 } | 142 } |
133 | 143 |
134 @Override | 144 @Override |
135 protected void onResume() { | 145 protected void onResume() { |
136 super.onResume(); | 146 super.onResume(); |
137 | 147 |
138 ContentView view = getActiveContentView(); | 148 ContentView view = getActiveContentView(); |
139 if (view != null) view.onActivityResume(); | 149 if (view != null) view.onActivityResume(); |
| 150 IntentFilter intentFilter = new IntentFilter(ACTION_START_TRACE); |
| 151 intentFilter.addAction(ACTION_STOP_TRACE); |
| 152 mReceiver = new BroadcastReceiver() { |
| 153 @Override |
| 154 public void onReceive(Context context, Intent intent) { |
| 155 String action = intent.getAction(); |
| 156 String extra = intent.getStringExtra("file"); |
| 157 if (ACTION_START_TRACE.equals(action)) { |
| 158 if (extra.isEmpty()) { |
| 159 Log.e(TAG, "Can not start tracing without specifing savi
ng location"); |
| 160 } else { |
| 161 TracingIntentHandler.beginTracing(extra); |
| 162 Log.i(TAG, "start tracing"); |
| 163 } |
| 164 } else if (ACTION_STOP_TRACE.equals(action)) { |
| 165 Log.i(TAG, "stop tracing"); |
| 166 TracingIntentHandler.endTracing(); |
| 167 } |
| 168 } |
| 169 }; |
| 170 registerReceiver(mReceiver, intentFilter); |
140 } | 171 } |
141 | 172 |
142 @Override | 173 @Override |
143 public void onActivityResult(int requestCode, int resultCode, Intent data) { | 174 public void onActivityResult(int requestCode, int resultCode, Intent data) { |
144 super.onActivityResult(requestCode, resultCode, data); | 175 super.onActivityResult(requestCode, resultCode, data); |
145 mActivityNativeWindow.onActivityResult(requestCode, resultCode, data); | 176 mActivityNativeWindow.onActivityResult(requestCode, resultCode, data); |
146 } | 177 } |
147 | 178 |
148 private static String getUrlFromIntent(Intent intent) { | 179 private static String getUrlFromIntent(Intent intent) { |
149 return intent != null ? intent.getDataString() : null; | 180 return intent != null ? intent.getDataString() : null; |
(...skipping 20 matching lines...) Expand all Loading... |
170 | 201 |
171 /** | 202 /** |
172 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one | 203 * @return The {@link ContentView} owned by the currently visible {@link She
ll} or null if one |
173 * is not showing. | 204 * is not showing. |
174 */ | 205 */ |
175 public ContentView getActiveContentView() { | 206 public ContentView getActiveContentView() { |
176 Shell shell = getActiveShell(); | 207 Shell shell = getActiveShell(); |
177 return shell != null ? shell.getContentView() : null; | 208 return shell != null ? shell.getContentView() : null; |
178 } | 209 } |
179 } | 210 } |
OLD | NEW |