EMMA Coverage Report (generated Tue Aug 20 10:07:21 PDT 2013)
[all classes][org.chromium.content_shell_apk]

COVERAGE SUMMARY FOR SOURCE FILE [ContentShellActivity.java]

nameclass, %method, %block, %line, %
ContentShellActivity.java100% (4/4)68%  (15/22)49%  (185/378)45%  (46.4/103)

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)69%  (11/16)53%  (161/304)50%  (43.4/86)
getShellManager (): ShellManager 0%   (0/1)0%   (0/3)0%   (0/1)
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)
onCreate (Bundle): void 100% (1/1)70%  (69/98)70%  (21/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): void 100% (1/1)100% (3/3)100% (1/1)
finishInitialization (): void 100% (1/1)100% (8/8)100% (2/2)
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)100% (2/2)60%  (12/20)67%  (4/6)
run (int): void 100% (1/1)43%  (6/14)60%  (3/5)
ContentShellActivity$1 (ContentShellActivity): void 100% (1/1)100% (6/6)100% (1/1)

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

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