Update To 11.40.268.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.base.ResourceExtractor;
13 import org.chromium.chrome.browser.ChromiumApplication;
14 import org.chromium.chrome.browser.PKCS11AuthenticationManager;
15 import org.chromium.chrome.browser.Tab;
16 import org.chromium.chrome.browser.UmaUtils;
17 import org.chromium.chrome.browser.invalidation.UniqueIdInvalidationClientNameGenerator;
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      *  V8's initial snapshot used to be statically linked to the binary, but
36      *  now it's loaded from external files. Therefore we need to install such
37      *  snapshots (natives_blob.bin and snapshot.bin) along with pak files.
38      */
39     private static final String[] CHROME_MANDATORY_PAKS = {
40         "en-US.pak",
41         "resources.pak",
42         "chrome_100_percent.pak",
43         "icudtl.dat",
44         "natives_blob.bin",
45         "snapshot_blob.bin"
46     };
47     private static final String COMMAND_LINE_FILE = "/data/local/tmp/chrome-shell-command-line";
48
49     ArrayList<ChromeShellApplicationObserver> mObservers;
50
51     @Override
52     public void onCreate() {
53         // We want to do this at the earliest possible point in startup.
54         UmaUtils.recordMainEntryPointTime();
55         super.onCreate();
56
57         ResourceExtractor.setMandatoryPaksToExtract(CHROME_MANDATORY_PAKS);
58         PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
59
60         mObservers = new ArrayList<ChromeShellApplicationObserver>();
61
62         // Initialize the invalidations ID, just like we would in the downstream code.
63         UniqueIdInvalidationClientNameGenerator.doInitializeAndInstallGenerator(this);
64     }
65
66     @Override
67     public void sendBroadcast(Intent intent) {
68         boolean shouldFire = true;
69         for (ChromeShellApplicationObserver observer : mObservers) {
70             shouldFire &= observer.onSendBroadcast(intent);
71         }
72
73         if (shouldFire) super.sendBroadcast(intent);
74     }
75
76     public void addObserver(ChromeShellApplicationObserver observer) {
77         mObservers.add(observer);
78     }
79
80     public void removeObserver(ChromeShellApplicationObserver observer) {
81         mObservers.remove(observer);
82     }
83
84     @Override
85     public void initCommandLine() {
86         if (!CommandLine.isInitialized()) {
87             CommandLine.initFromFile(COMMAND_LINE_FILE);
88         }
89     }
90
91     @Override
92     protected void openProtectedContentSettings() {
93     }
94
95     @Override
96     protected void showSyncSettings() {
97     }
98
99     @Override
100     protected void showAutofillSettings() {
101     }
102
103     @Override
104     protected void showPasswordSettings() {
105     }
106
107     @Override
108     protected void showTermsOfServiceDialog() {
109     }
110
111     @Override
112     protected void openClearBrowsingData(Tab tab) {
113         Log.e(TAG, "Clear browsing data not currently supported in Chrome Shell");
114     }
115
116     @Override
117     protected boolean areParentalControlsEnabled() {
118         return false;
119     }
120
121     @Override
122     protected PKCS11AuthenticationManager getPKCS11AuthenticationManager() {
123         return new ChromeShellPKCS11AuthenticationManager();
124     }
125 }