summaryrefslogtreecommitdiffstats
path: root/chromecast/shell/app
diff options
context:
space:
mode:
Diffstat (limited to 'chromecast/shell/app')
-rw-r--r--chromecast/shell/app/DEPS1
-rw-r--r--chromecast/shell/app/android/cast_jni_loader.cc36
-rw-r--r--chromecast/shell/app/cast_main_delegate.cc56
-rw-r--r--chromecast/shell/app/cast_main_delegate.h13
4 files changed, 104 insertions, 2 deletions
diff --git a/chromecast/shell/app/DEPS b/chromecast/shell/app/DEPS
index 7c1793e..efc610d 100644
--- a/chromecast/shell/app/DEPS
+++ b/chromecast/shell/app/DEPS
@@ -1,3 +1,4 @@
include_rules = [
"+content/public/app",
+ "+content/public/browser",
]
diff --git a/chromecast/shell/app/android/cast_jni_loader.cc b/chromecast/shell/app/android/cast_jni_loader.cc
new file mode 100644
index 0000000..4cbf8f8
--- /dev/null
+++ b/chromecast/shell/app/android/cast_jni_loader.cc
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "base/android/library_loader/library_loader_hooks.h"
+#include "base/basictypes.h"
+#include "base/debug/debugger.h"
+#include "base/logging.h"
+#include "chromecast/android/cast_jni_registrar.h"
+#include "chromecast/android/platform_jni_loader.h"
+#include "chromecast/shell/app/cast_main_delegate.h"
+#include "content/public/app/android_library_loader_hooks.h"
+#include "content/public/app/content_main.h"
+#include "content/public/browser/android/compositor.h"
+
+// This is called by the VM when the shared library is first loaded.
+JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ base::android::SetLibraryLoadedHook(&content::LibraryLoaded);
+ base::android::InitVM(vm);
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1;
+
+ // To be called only from the UI thread. If loading the library is done on
+ // a separate thread, this should be moved elsewhere.
+ if (!chromecast::android::RegisterJni(env)) return -1;
+ // Allow platform-specific implementations to perform more JNI registration.
+ if (!chromecast::android::PlatformRegisterJni(env)) return -1;
+
+ content::Compositor::Initialize();
+ content::SetContentMainDelegate(new chromecast::shell::CastMainDelegate);
+
+ return JNI_VERSION_1_4;
+}
diff --git a/chromecast/shell/app/cast_main_delegate.cc b/chromecast/shell/app/cast_main_delegate.cc
index 1fb2ad7..f713f5b 100644
--- a/chromecast/shell/app/cast_main_delegate.cc
+++ b/chromecast/shell/app/cast_main_delegate.cc
@@ -4,12 +4,16 @@
#include "chromecast/shell/app/cast_main_delegate.h"
+#include "base/cpu.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "base/posix/global_descriptors.h"
#include "chromecast/common/cast_paths.h"
#include "chromecast/common/cast_resource_delegate.h"
+#include "chromecast/common/global_descriptors.h"
#include "chromecast/shell/browser/cast_content_browser_client.h"
#include "chromecast/shell/renderer/cast_content_renderer_client.h"
+#include "content/public/browser/browser_main_runner.h"
#include "content/public/common/content_switches.h"
#include "ui/base/resource/resource_bundle.h"
@@ -23,26 +27,74 @@ CastMainDelegate::~CastMainDelegate() {
}
bool CastMainDelegate::BasicStartupComplete(int* exit_code) {
+ RegisterPathProvider();
+
logging::LoggingSettings settings;
+#if defined(OS_ANDROID)
+ base::FilePath log_file;
+ PathService::Get(FILE_CAST_ANDROID_LOG, &log_file);
+ settings.logging_dest = logging::LOG_TO_ALL;
+ settings.log_file = log_file.value().c_str();
+ settings.delete_old = logging::DELETE_OLD_LOG_FILE;
+#else
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+#endif // defined(OS_ANDROID)
logging::InitLogging(settings);
// Time, process, and thread ID are available through logcat.
logging::SetLogItems(true, true, false, false);
- RegisterPathProvider();
-
content::SetContentClient(&content_client_);
return false;
}
void CastMainDelegate::PreSandboxStartup() {
+#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
+ // Create an instance of the CPU class to parse /proc/cpuinfo and cache the
+ // results. This data needs to be cached when file-reading is still allowed,
+ // since base::CPU expects to be callable later, when file-reading is no
+ // longer allowed.
+ base::CPU cpu_info;
+#endif
+
InitializeResourceBundle();
}
+int CastMainDelegate::RunProcess(
+ const std::string& process_type,
+ const content::MainFunctionParams& main_function_params) {
+#if defined(OS_ANDROID)
+ if (!process_type.empty())
+ return -1;
+
+ // Note: Android must handle running its own browser process.
+ // See ChromeMainDelegateAndroid::RunProcess.
+ browser_runner_.reset(content::BrowserMainRunner::Create());
+ return browser_runner_->Initialize(main_function_params);
+#else
+ return -1;
+#endif // defined(OS_ANDROID)
+}
+
+#if !defined(OS_ANDROID)
void CastMainDelegate::ZygoteForked() {
}
+#endif // !defined(OS_ANDROID)
void CastMainDelegate::InitializeResourceBundle() {
+#if defined(OS_ANDROID)
+ // On Android, the renderer runs with a different UID and can never access
+ // the file system. Use the file descriptor passed in at launch time.
+ int pak_fd =
+ base::GlobalDescriptors::GetInstance()->MaybeGet(kAndroidPakDescriptor);
+ if (pak_fd >= 0) {
+ ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
+ base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile);
+ ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
+ base::File(pak_fd), ui::SCALE_FACTOR_100P);
+ return;
+ }
+#endif
+
resource_delegate_.reset(new CastResourceDelegate());
// TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer
// hardcodes resource file names.
diff --git a/chromecast/shell/app/cast_main_delegate.h b/chromecast/shell/app/cast_main_delegate.h
index 8c9ed62..4240953 100644
--- a/chromecast/shell/app/cast_main_delegate.h
+++ b/chromecast/shell/app/cast_main_delegate.h
@@ -10,6 +10,10 @@
#include "chromecast/shell/common/cast_content_client.h"
#include "content/public/app/content_main_delegate.h"
+namespace content {
+class BrowserMainRunner;
+} // namespace content
+
namespace chromecast {
class CastResourceDelegate;
@@ -27,7 +31,12 @@ class CastMainDelegate : public content::ContentMainDelegate {
// content::ContentMainDelegate implementation:
virtual bool BasicStartupComplete(int* exit_code) OVERRIDE;
virtual void PreSandboxStartup() OVERRIDE;
+ virtual int RunProcess(
+ const std::string& process_type,
+ const content::MainFunctionParams& main_function_params) OVERRIDE;
+#if !defined(OS_ANDROID)
virtual void ZygoteForked() OVERRIDE;
+#endif // !defined(OS_ANDROID)
virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE;
virtual content::ContentRendererClient*
CreateContentRendererClient() OVERRIDE;
@@ -40,6 +49,10 @@ class CastMainDelegate : public content::ContentMainDelegate {
scoped_ptr<CastResourceDelegate> resource_delegate_;
CastContentClient content_client_;
+#if defined(OS_ANDROID)
+ scoped_ptr<content::BrowserMainRunner> browser_runner_;
+#endif // defined(OS_ANDROID)
+
DISALLOW_COPY_AND_ASSIGN(CastMainDelegate);
};