Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / android / shell / java / src / org / chromium / chrome / shell / ChromeShellApplication.java
1 // Copyright 2014 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
5 package org.chromium.chrome.shell;
6
7 import android.content.Intent;
8
9 import org.chromium.base.CommandLine;
10 import org.chromium.base.PathUtils;
11 import org.chromium.chrome.browser.ChromiumApplication;
12 import org.chromium.chrome.browser.PKCS11AuthenticationManager;
13 import org.chromium.chrome.browser.UmaUtils;
14 import org.chromium.chrome.browser.invalidation.UniqueIdInvalidationClientNameGenerator;
15 import org.chromium.content.browser.ResourceExtractor;
16
17 import java.util.ArrayList;
18
19 /**
20  * A basic test shell {@link android.app.Application}.  Handles setting up the native library and
21  * loading the right resources.
22  */
23 public class ChromeShellApplication extends ChromiumApplication {
24     private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chromeshell";
25     /**
26      * icudtl.dat provides ICU (i18n library) with all the necessary data
27      * for its operation. We used to link the data statically to our binary,
28      * but don't do that any more and need to install along with pak files.
29      * See src/third_party/icu/README.chromium.
30      */
31     private static final String[] CHROME_MANDATORY_PAKS = {
32         "en-US.pak",
33         "resources.pak",
34         "chrome_100_percent.pak",
35         "icudtl.dat",
36     };
37     private static final String COMMAND_LINE_FILE = "/data/local/tmp/chrome-shell-command-line";
38
39     ArrayList<ChromeShellApplicationObserver> mObservers;
40
41     @Override
42     public void onCreate() {
43         // We want to do this at the earliest possible point in startup.
44         UmaUtils.recordMainEntryPointTime();
45         super.onCreate();
46
47         ResourceExtractor.setMandatoryPaksToExtract(CHROME_MANDATORY_PAKS);
48         PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
49
50         mObservers = new ArrayList<ChromeShellApplicationObserver>();
51
52         // Initialize the invalidations ID, just like we would in the downstream code.
53         UniqueIdInvalidationClientNameGenerator.doInitializeAndInstallGenerator(this);
54     }
55
56     @Override
57     public void sendBroadcast(Intent intent) {
58         boolean shouldFire = true;
59         for (ChromeShellApplicationObserver observer : mObservers) {
60             shouldFire &= observer.onSendBroadcast(intent);
61         }
62
63         if (shouldFire) super.sendBroadcast(intent);
64     }
65
66     public void addObserver(ChromeShellApplicationObserver observer) {
67         mObservers.add(observer);
68     }
69
70     public void removeObserver(ChromeShellApplicationObserver observer) {
71         mObservers.remove(observer);
72     }
73
74     public static void initCommandLine() {
75         if (!CommandLine.isInitialized()) {
76             CommandLine.initFromFile(COMMAND_LINE_FILE);
77         }
78     }
79
80     @Override
81     protected void openProtectedContentSettings() {
82     }
83
84     @Override
85     protected void showSyncSettings() {
86     }
87
88     @Override
89     protected void showTermsOfServiceDialog() {
90     }
91
92     @Override
93     protected boolean areParentalControlsEnabled() {
94         return false;
95     }
96
97     @Override
98     protected PKCS11AuthenticationManager getPKCS11AuthenticationManager() {
99         return new ChromeShellPKCS11AuthenticationManager();
100     }
101 }