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