EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.content_shell_apk]

COVERAGE SUMMARY FOR SOURCE FILE [ContentShellActivity.java]

nameclass, %method, %block, %line, %
ContentShellActivity.java100% (4/4)60%  (15/25)49%  (196/403)43%  (47.6/111)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ContentShellActivity$3100% (1/1)50%  (1/2)14%  (6/42)8%   (1/12)
onReceive (Context, Intent): void 0%   (0/1)0%   (0/36)0%   (0/11)
ContentShellActivity$3 (ContentShellActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class ContentShellActivity$2100% (1/1)50%  (1/2)50%  (6/12)50%  (1/2)
getContentVideoViewClient (): ContentVideoViewClient 0%   (0/1)0%   (0/6)0%   (0/1)
ContentShellActivity$2 (ContentShellActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class ContentShellActivity100% (1/1)61%  (11/18)51%  (169/330)47%  (44.6/94)
access$100 (ContentShellActivity): void 0%   (0/1)0%   (0/3)0%   (0/1)
getShellManager (): ShellManager 0%   (0/1)0%   (0/3)0%   (0/1)
initializationFailed (): void 0%   (0/1)0%   (0/12)0%   (0/4)
onActivityResult (int, int, Intent): void 0%   (0/1)0%   (0/13)0%   (0/3)
onKeyUp (int, KeyEvent): boolean 0%   (0/1)0%   (0/27)0%   (0/6)
onNewIntent (Intent): void 0%   (0/1)0%   (0/38)0%   (0/14)
onSaveInstanceState (Bundle): void 0%   (0/1)0%   (0/19)0%   (0/6)
waitForDebuggerIfNeeded (): void 100% (1/1)36%  (5/14)40%  (2/5)
finishInitialization (Bundle): void 100% (1/1)67%  (16/24)75%  (4.5/6)
onCreate (Bundle): void 100% (1/1)74%  (68/92)67%  (20/30)
getUrlFromIntent (Intent): String 100% (1/1)86%  (6/7)85%  (0.8/1)
getCommandLineParamsFromIntent (Intent): String [] 100% (1/1)88%  (7/8)87%  (0.9/1)
getActiveShell (): Shell 100% (1/1)89%  (8/9)88%  (0.9/1)
onResume (): void 100% (1/1)93%  (28/30)97%  (7.8/8)
ContentShellActivity (): void 100% (1/1)100% (3/3)100% (1/1)
access$000 (ContentShellActivity, Bundle): void 100% (1/1)100% (4/4)100% (1/1)
getActiveContentView (): ContentView 100% (1/1)100% (10/10)100% (2/2)
onPause (): void 100% (1/1)100% (14/14)100% (5/5)
     
class ContentShellActivity$1100% (1/1)67%  (2/3)79%  (15/19)60%  (3/5)
onFailure (): void 0%   (0/1)0%   (0/4)0%   (0/2)
ContentShellActivity$1 (ContentShellActivity, Bundle): void 100% (1/1)100% (9/9)100% (1/1)
onSuccess (boolean): void 100% (1/1)100% (6/6)100% (2/2)

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
3// found in the LICENSE file.
4 
5package org.chromium.content_shell_apk;
6 
7import android.content.BroadcastReceiver;
8import android.content.Context;
9import android.content.Intent;
10import android.content.IntentFilter;
11import android.os.Bundle;
12import android.text.TextUtils;
13import android.util.Log;
14import android.view.KeyEvent;
15import android.widget.Toast;
16 
17import org.chromium.base.ChromiumActivity;
18import org.chromium.base.MemoryPressureListener;
19import org.chromium.content.app.LibraryLoader;
20import org.chromium.content.browser.ActivityContentVideoViewClient;
21import org.chromium.content.browser.AndroidBrowserProcess;
22import org.chromium.content.browser.BrowserStartupController;
23import org.chromium.content.browser.ContentVideoViewClient;
24import org.chromium.content.browser.ContentView;
25import org.chromium.content.browser.ContentViewClient;
26import org.chromium.content.browser.DeviceUtils;
27import org.chromium.content.browser.TracingIntentHandler;
28import org.chromium.content.common.CommandLine;
29import org.chromium.content.common.ProcessInitException;
30import org.chromium.content_shell.Shell;
31import org.chromium.content_shell.ShellManager;
32import org.chromium.ui.WindowAndroid;
33 
34/**
35 * Activity for managing the Content Shell.
36 */
37public class ContentShellActivity extends ChromiumActivity {
38 
39    public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shell-command-line";
40    private static final String TAG = "ContentShellActivity";
41 
42    private static final String ACTIVE_SHELL_URL_KEY = "activeUrl";
43    private static final String ACTION_START_TRACE =
44            "org.chromium.content_shell.action.PROFILE_START";
45    private static final String ACTION_STOP_TRACE =
46            "org.chromium.content_shell.action.PROFILE_STOP";
47    public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs";
48 
49    /**
50     * Sending an intent with this action will simulate a memory pressure signal
51     * at a critical level.
52     */
53    private static final String ACTION_LOW_MEMORY =
54            "org.chromium.content_shell.action.ACTION_LOW_MEMORY";
55 
56    /**
57     * Sending an intent with this action will simulate a memory pressure signal
58     * at a moderate level.
59     */
60    private static final String ACTION_TRIM_MEMORY_MODERATE =
61            "org.chromium.content_shell.action.ACTION_TRIM_MEMORY_MODERATE";
62 
63 
64    private ShellManager mShellManager;
65    private WindowAndroid mWindowAndroid;
66    private BroadcastReceiver mReceiver;
67 
68    @Override
69    protected void onCreate(final Bundle savedInstanceState) {
70        super.onCreate(savedInstanceState);
71 
72        // Initializing the command line must occur before loading the library.
73        if (!CommandLine.isInitialized()) {
74            CommandLine.initFromFile(COMMAND_LINE_FILE);
75            String[] commandLineParams = getCommandLineParamsFromIntent(getIntent());
76            if (commandLineParams != null) {
77                CommandLine.getInstance().appendSwitchesAndArguments(commandLineParams);
78            }
79        }
80        waitForDebuggerIfNeeded();
81 
82        DeviceUtils.addDeviceSpecificUserAgentSwitch(this);
83        try {
84            LibraryLoader.ensureInitialized();
85        } catch (ProcessInitException e) {
86            Log.e(TAG, "ContentView initialization failed.", e);
87            finish();
88            return;
89        }
90 
91        setContentView(R.layout.content_shell_activity);
92        mShellManager = (ShellManager) findViewById(R.id.shell_container);
93        mWindowAndroid = new WindowAndroid(this);
94        mWindowAndroid.restoreInstanceState(savedInstanceState);
95        mShellManager.setWindow(mWindowAndroid);
96 
97        String startupUrl = getUrlFromIntent(getIntent());
98        if (!TextUtils.isEmpty(startupUrl)) {
99            mShellManager.setStartupUrl(Shell.sanitizeUrl(startupUrl));
100        }
101 
102        if (CommandLine.getInstance().hasSwitch(CommandLine.DUMP_RENDER_TREE)) {
103            try {
104                if (!AndroidBrowserProcess.init(this, AndroidBrowserProcess.MAX_RENDERERS_LIMIT)) {
105                    finishInitialization(savedInstanceState);
106                }
107            } catch (ProcessInitException e) {
108                initializationFailed();
109            }
110        } else {
111            BrowserStartupController.get(this).startBrowserProcessesAsync(
112                    new BrowserStartupController.StartupCallback() {
113                @Override
114                public void onSuccess(boolean alreadyStarted) {
115                    finishInitialization(savedInstanceState);
116                }
117 
118                @Override
119                public void onFailure() {
120                    initializationFailed();
121                }
122            });
123        }
124    }
125 
126    private void finishInitialization(Bundle savedInstanceState) {
127        String shellUrl = ShellManager.DEFAULT_SHELL_URL;
128        if (savedInstanceState != null
129                && savedInstanceState.containsKey(ACTIVE_SHELL_URL_KEY)) {
130            shellUrl = savedInstanceState.getString(ACTIVE_SHELL_URL_KEY);
131        }
132        mShellManager.launchShell(shellUrl);
133        getActiveContentView().setContentViewClient(new ContentViewClient() {
134            @Override
135            public ContentVideoViewClient getContentVideoViewClient() {
136                return new ActivityContentVideoViewClient(ContentShellActivity.this);
137            }
138        });
139    }
140 
141    private void initializationFailed() {
142        Log.e(TAG, "ContentView initialization failed.");
143        Toast.makeText(ContentShellActivity.this,
144                R.string.browser_process_initialization_failed,
145                Toast.LENGTH_SHORT).show();
146        finish();
147    }
148 
149    @Override
150    protected void onSaveInstanceState(Bundle outState) {
151        super.onSaveInstanceState(outState);
152        Shell activeShell = getActiveShell();
153        if (activeShell != null) {
154            outState.putString(ACTIVE_SHELL_URL_KEY, activeShell.getContentView().getUrl());
155        }
156 
157        mWindowAndroid.saveInstanceState(outState);
158    }
159 
160    private void waitForDebuggerIfNeeded() {
161        if (CommandLine.getInstance().hasSwitch(CommandLine.WAIT_FOR_JAVA_DEBUGGER)) {
162            Log.e(TAG, "Waiting for Java debugger to connect...");
163            android.os.Debug.waitForDebugger();
164            Log.e(TAG, "Java debugger connected. Resuming execution.");
165        }
166    }
167 
168    @Override
169    public boolean onKeyUp(int keyCode, KeyEvent event) {
170        if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyUp(keyCode, event);
171 
172        Shell activeView = getActiveShell();
173        if (activeView != null && activeView.getContentView().canGoBack()) {
174            activeView.getContentView().goBack();
175            return true;
176        }
177 
178        return super.onKeyUp(keyCode, event);
179    }
180 
181    @Override
182    protected void onNewIntent(Intent intent) {
183        if (getCommandLineParamsFromIntent(intent) != null) {
184            Log.i(TAG, "Ignoring command line params: can only be set when creating the activity.");
185        }
186 
187        if (ACTION_LOW_MEMORY.equals(intent.getAction())) {
188            MemoryPressureListener.simulateMemoryPressureSignal(TRIM_MEMORY_COMPLETE);
189            return;
190        } else if (ACTION_TRIM_MEMORY_MODERATE.equals(intent.getAction())) {
191            MemoryPressureListener.simulateMemoryPressureSignal(TRIM_MEMORY_MODERATE);
192            return;
193        }
194 
195        String url = getUrlFromIntent(intent);
196        if (!TextUtils.isEmpty(url)) {
197            Shell activeView = getActiveShell();
198            if (activeView != null) {
199                activeView.loadUrl(url);
200            }
201        }
202    }
203 
204    @Override
205    protected void onPause() {
206        ContentView view = getActiveContentView();
207        if (view != null) view.onActivityPause();
208 
209        super.onPause();
210        unregisterReceiver(mReceiver);
211    }
212 
213    @Override
214    protected void onResume() {
215        super.onResume();
216 
217        ContentView view = getActiveContentView();
218        if (view != null) view.onActivityResume();
219        IntentFilter intentFilter = new IntentFilter(ACTION_START_TRACE);
220        intentFilter.addAction(ACTION_STOP_TRACE);
221        mReceiver = new BroadcastReceiver() {
222            @Override
223            public void onReceive(Context context, Intent intent) {
224                String action = intent.getAction();
225                String extra = intent.getStringExtra("file");
226                if (ACTION_START_TRACE.equals(action)) {
227                    if (extra.isEmpty()) {
228                        Log.e(TAG, "Can not start tracing without specifing saving location");
229                    } else {
230                        TracingIntentHandler.beginTracing(extra);
231                        Log.i(TAG, "start tracing");
232                    }
233                } else if (ACTION_STOP_TRACE.equals(action)) {
234                    Log.i(TAG, "stop tracing");
235                    TracingIntentHandler.endTracing();
236                }
237            }
238        };
239        registerReceiver(mReceiver, intentFilter);
240    }
241 
242    @Override
243    public void onActivityResult(int requestCode, int resultCode, Intent data) {
244        super.onActivityResult(requestCode, resultCode, data);
245        mWindowAndroid.onActivityResult(requestCode, resultCode, data);
246    }
247 
248    private static String getUrlFromIntent(Intent intent) {
249        return intent != null ? intent.getDataString() : null;
250    }
251 
252    private static String[] getCommandLineParamsFromIntent(Intent intent) {
253        return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY) : null;
254    }
255 
256    /**
257     * @return The {@link ShellManager} configured for the activity or null if it has not been
258     *         created yet.
259     */
260    public ShellManager getShellManager() {
261        return mShellManager;
262    }
263 
264    /**
265     * @return The currently visible {@link Shell} or null if one is not showing.
266     */
267    public Shell getActiveShell() {
268        return mShellManager != null ? mShellManager.getActiveShell() : null;
269    }
270 
271    /**
272     * @return The {@link ContentView} owned by the currently visible {@link Shell} or null if one
273     *         is not showing.
274     */
275    public ContentView getActiveContentView() {
276        Shell shell = getActiveShell();
277        return shell != null ? shell.getContentView() : null;
278    }
279}

[all classes][org.chromium.content_shell_apk]
EMMA 2.0.5312 (C) Vladimir Roubtsov