summaryrefslogtreecommitdiffstats
path: root/chromecast
diff options
context:
space:
mode:
authorlcwu@chromium.org <lcwu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-11 02:44:29 +0000
committerlcwu@chromium.org <lcwu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-11 02:44:29 +0000
commit844ac63d83154b0bbba454b071f62c6b00a4e4c6 (patch)
tree03d7998428dee3e6c7103250e2a8221339c27475 /chromecast
parent193f047ccc0dec59f7b795ef7dc31626d9276199 (diff)
downloadchromium_src-844ac63d83154b0bbba454b071f62c6b00a4e4c6.zip
chromium_src-844ac63d83154b0bbba454b071f62c6b00a4e4c6.tar.gz
chromium_src-844ac63d83154b0bbba454b071f62c6b00a4e4c6.tar.bz2
Initial checkin of chromecast content embedder (cast_shell) and related build scripts.
BUG=336640 Review URL: https://codereview.chromium.org/223143003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282508 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromecast')
-rw-r--r--chromecast/DEPS8
-rw-r--r--chromecast/chromecast.gyp156
-rw-r--r--chromecast/common/cast_paths.cc37
-rw-r--r--chromecast/common/cast_paths.h27
-rw-r--r--chromecast/net/network_change_notifier_cast.cc20
-rw-r--r--chromecast/net/network_change_notifier_cast.h34
-rw-r--r--chromecast/net/network_change_notifier_factory_cast.cc31
-rw-r--r--chromecast/net/network_change_notifier_factory_cast.h33
-rw-r--r--chromecast/service/DEPS3
-rw-r--r--chromecast/service/cast_platform_init_stub.cc13
-rw-r--r--chromecast/service/cast_service.cc140
-rw-r--r--chromecast/service/cast_service.h53
-rw-r--r--chromecast/shell/app/DEPS3
-rw-r--r--chromecast/shell/app/cast_main.cc14
-rw-r--r--chromecast/shell/app/cast_main_delegate.cc68
-rw-r--r--chromecast/shell/app/cast_main_delegate.h45
-rw-r--r--chromecast/shell/browser/DEPS3
-rw-r--r--chromecast/shell/browser/cast_browser_context.cc131
-rw-r--r--chromecast/shell/browser/cast_browser_context.h64
-rw-r--r--chromecast/shell/browser/cast_browser_main_parts.cc101
-rw-r--r--chromecast/shell/browser/cast_browser_main_parts.h60
-rw-r--r--chromecast/shell/browser/cast_content_browser_client.cc146
-rw-r--r--chromecast/shell/browser/cast_content_browser_client.h82
-rw-r--r--chromecast/shell/browser/cast_http_user_agent_settings.cc33
-rw-r--r--chromecast/shell/browser/cast_http_user_agent_settings.h33
-rw-r--r--chromecast/shell/browser/geolocation/cast_access_token_store.cc51
-rw-r--r--chromecast/shell/browser/geolocation/cast_access_token_store.h47
-rw-r--r--chromecast/shell/browser/url_request_context_factory.cc388
-rw-r--r--chromecast/shell/browser/url_request_context_factory.h103
-rw-r--r--chromecast/shell/common/cast_content_client.cc53
-rw-r--r--chromecast/shell/common/cast_content_client.h33
-rw-r--r--chromecast/shell/renderer/DEPS3
-rw-r--r--chromecast/shell/renderer/cast_content_renderer_client.cc34
-rw-r--r--chromecast/shell/renderer/cast_content_renderer_client.h27
34 files changed, 2077 insertions, 0 deletions
diff --git a/chromecast/DEPS b/chromecast/DEPS
new file mode 100644
index 0000000..1a7a778
--- /dev/null
+++ b/chromecast/DEPS
@@ -0,0 +1,8 @@
+# Do not add any includes under chrome/ anywhere in chromecast.
+
+include_rules = [
+ "+content/public/common",
+ "+crypto",
+ "+net",
+ "+ui",
+]
diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp
new file mode 100644
index 0000000..6328a51
--- /dev/null
+++ b/chromecast/chromecast.gyp
@@ -0,0 +1,156 @@
+# 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.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ 'chromecast_branding%': 'Chromium',
+ },
+ 'target_defaults': {
+ 'include_dirs': [
+ '..', # Root of Chromium checkout
+ ],
+ },
+ 'targets': [
+ {
+ 'target_name': 'cast_common',
+ 'type': '<(component)',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ ],
+ 'sources': [
+ 'common/cast_paths.cc',
+ 'common/cast_paths.h',
+ ],
+ 'conditions': [
+ ['chromecast_branding=="Chrome"', {
+ 'dependencies': [
+ 'internal/chromecast_internal.gyp:cast_common_internal',
+ ],
+ }],
+ ],
+ },
+ {
+ 'target_name': 'cast_service',
+ 'type': '<(component)',
+ 'dependencies': [
+ '../skia/skia.gyp:skia',
+ ],
+ 'sources': [
+ 'service/cast_service.cc',
+ 'service/cast_service.h',
+ ],
+ 'conditions': [
+ ['chromecast_branding=="Chrome"', {
+ 'dependencies': [
+ 'internal/chromecast_internal.gyp:cast_service_internal',
+ ],
+ }, {
+ 'sources': [
+ 'service/cast_platform_init_stub.cc',
+ ],
+ }],
+ ],
+ },
+ {
+ 'target_name': 'cast_shell_resources',
+ 'type': 'none',
+ # Place holder for cast_shell specific resources.
+ },
+ {
+ 'target_name': 'cast_shell_pak',
+ 'type': 'none',
+ 'dependencies': [
+ 'cast_shell_resources',
+ '../content/browser/devtools/devtools_resources.gyp:devtools_resources',
+ '../content/content_resources.gyp:content_resources',
+ '../net/net.gyp:net_resources',
+ '../ui/resources/ui_resources.gyp:ui_resources',
+ '../ui/strings/ui_strings.gyp:ui_strings',
+ '../webkit/webkit_resources.gyp:webkit_resources',
+ '../webkit/webkit_resources.gyp:webkit_strings',
+ ],
+ 'variables': {
+ 'repack_path': '../tools/grit/grit/format/repack.py',
+ },
+ 'actions': [
+ {
+ 'action_name': 'repack_cast_shell_pack',
+ 'variables': {
+ 'pak_inputs': [
+ '<(SHARED_INTERMEDIATE_DIR)/content/content_resources.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/ui/app_locale_settings/app_locale_settings_en-US.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources_100_percent.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/webui_resources.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/ui/ui_strings/ui_strings_en-US.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/webkit/devtools_resources.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/webkit/blink_resources.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources_100_percent.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_strings_en-US.pak',
+ ],
+ },
+ 'inputs': [
+ '<(repack_path)',
+ '<@(pak_inputs)',
+ ],
+ 'action': ['python', '<(repack_path)', '<@(_outputs)',
+ '<@(pak_inputs)'],
+ 'outputs': [
+ '<(PRODUCT_DIR)/cast_shell.pak',
+ ],
+ },
+ ],
+ },
+ {
+ 'target_name': 'cast_shell',
+ 'type': 'executable',
+ 'dependencies': [
+ 'cast_common',
+ 'cast_service',
+ 'cast_shell_pak',
+ '../ui/aura/aura.gyp:aura_test_support',
+ '../content/content.gyp:content',
+ '../content/content.gyp:content_app_browser',
+ '../skia/skia.gyp:skia',
+ ],
+ 'sources': [
+ 'net/network_change_notifier_cast.cc',
+ 'net/network_change_notifier_cast.h',
+ 'net/network_change_notifier_factory_cast.cc',
+ 'net/network_change_notifier_factory_cast.h',
+ 'shell/app/cast_main.cc',
+ 'shell/app/cast_main_delegate.cc',
+ 'shell/app/cast_main_delegate.h',
+ 'shell/browser/cast_browser_context.cc',
+ 'shell/browser/cast_browser_context.h',
+ 'shell/browser/cast_browser_main_parts.cc',
+ 'shell/browser/cast_browser_main_parts.h',
+ 'shell/browser/cast_content_browser_client.cc',
+ 'shell/browser/cast_content_browser_client.h',
+ 'shell/browser/cast_http_user_agent_settings.cc',
+ 'shell/browser/cast_http_user_agent_settings.h',
+ 'shell/browser/geolocation/cast_access_token_store.cc',
+ 'shell/browser/geolocation/cast_access_token_store.h',
+ 'shell/browser/url_request_context_factory.cc',
+ 'shell/browser/url_request_context_factory.h',
+ 'shell/common/cast_content_client.cc',
+ 'shell/common/cast_content_client.h',
+ 'shell/renderer/cast_content_renderer_client.cc',
+ 'shell/renderer/cast_content_renderer_client.h',
+ ],
+ 'conditions': [
+ ['chromecast_branding=="Chrome"', {
+ 'dependencies': [
+ 'internal/chromecast_internal.gyp:cast_gfx_internal',
+ ],
+ }, {
+ 'dependencies': [
+ '../ui/ozone/ozone.gyp:eglplatform_shim_x11',
+ ],
+ }],
+ ],
+ },
+ ], # end of targets
+}
diff --git a/chromecast/common/cast_paths.cc b/chromecast/common/cast_paths.cc
new file mode 100644
index 0000000..b3a7716
--- /dev/null
+++ b/chromecast/common/cast_paths.cc
@@ -0,0 +1,37 @@
+// 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 "chromecast/common/cast_paths.h"
+
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/path_service.h"
+#include "build/build_config.h"
+
+namespace chromecast {
+
+bool PathProvider(int key, base::FilePath* result) {
+ switch (key) {
+ case DIR_CAST_HOME: {
+ base::FilePath home = base::GetHomeDir();
+#if defined(ARCH_CPU_ARMEL)
+ // When running on the actual device, $HOME is set to the user's
+ // directory under the data partition.
+ *result = home;
+#else
+ // When running a development instance as a regular user, use
+ // a data directory under $HOME (similar to Chrome).
+ *result = home.Append(".config/cast_shell");
+#endif
+ return true;
+ }
+ }
+ return false;
+}
+
+void RegisterPathProvider() {
+ PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
+}
+
+} // namespace chromecast
diff --git a/chromecast/common/cast_paths.h b/chromecast/common/cast_paths.h
new file mode 100644
index 0000000..d7b43a4
--- /dev/null
+++ b/chromecast/common/cast_paths.h
@@ -0,0 +1,27 @@
+// 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.
+
+#ifndef CHROMECAST_COMMON_CAST_PATHS_H_
+#define CHROMECAST_COMMON_CAST_PATHS_H_
+
+// This file declares path keys for the chromecast module. These can be used
+// with the PathService to access various special directories and files.
+
+namespace chromecast {
+
+enum {
+ PATH_START = 8000,
+
+ DIR_CAST_HOME, // Return a modified $HOME which works for both
+ // development use and the actual device.
+
+ PATH_END
+};
+
+// Call once to register the provider for the path keys defined above.
+void RegisterPathProvider();
+
+} // namespace chromecast
+
+#endif // CHROMECAST_COMMON_CAST_PATHS_H_
diff --git a/chromecast/net/network_change_notifier_cast.cc b/chromecast/net/network_change_notifier_cast.cc
new file mode 100644
index 0000000..ab6a218
--- /dev/null
+++ b/chromecast/net/network_change_notifier_cast.cc
@@ -0,0 +1,20 @@
+// 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 "chromecast/net/network_change_notifier_cast.h"
+
+namespace chromecast {
+
+NetworkChangeNotifierCast::NetworkChangeNotifierCast() {
+}
+
+NetworkChangeNotifierCast::~NetworkChangeNotifierCast() {
+}
+
+net::NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierCast::GetCurrentConnectionType() const {
+ return net::NetworkChangeNotifier::CONNECTION_NONE;
+}
+
+} // namespace chromecast
diff --git a/chromecast/net/network_change_notifier_cast.h b/chromecast/net/network_change_notifier_cast.h
new file mode 100644
index 0000000..7a9aed1
--- /dev/null
+++ b/chromecast/net/network_change_notifier_cast.h
@@ -0,0 +1,34 @@
+// 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.
+
+#ifndef CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_CAST_H_
+#define CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_CAST_H_
+
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "net/base/network_change_notifier.h"
+
+namespace chromecast {
+
+// TODO(lcwu): http://crbug.com/391064. This is a place holder for
+// cast-specific NetworkChangeNotifier implementation. The actual
+// implementation of this class will come in later CLs.
+class NetworkChangeNotifierCast : public net::NetworkChangeNotifier {
+ public:
+ NetworkChangeNotifierCast();
+ virtual ~NetworkChangeNotifierCast();
+
+ // net::NetworkChangeNotifier implementation:
+ virtual net::NetworkChangeNotifier::ConnectionType
+ GetCurrentConnectionType() const OVERRIDE;
+
+ private:
+ friend class NetworkChangeNotifierCastTest;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierCast);
+};
+
+} // namespace chromecast
+
+#endif // CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_CAST_H_
diff --git a/chromecast/net/network_change_notifier_factory_cast.cc b/chromecast/net/network_change_notifier_factory_cast.cc
new file mode 100644
index 0000000..1c41171
--- /dev/null
+++ b/chromecast/net/network_change_notifier_factory_cast.cc
@@ -0,0 +1,31 @@
+// 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 "chromecast/net/network_change_notifier_factory_cast.h"
+
+#include "base/lazy_instance.h"
+#include "chromecast/net/network_change_notifier_cast.h"
+
+namespace chromecast {
+
+namespace {
+
+base::LazyInstance<NetworkChangeNotifierCast> g_network_change_notifier_cast =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+net::NetworkChangeNotifier* NetworkChangeNotifierFactoryCast::CreateInstance() {
+ return g_network_change_notifier_cast.Pointer();
+}
+
+NetworkChangeNotifierFactoryCast::~NetworkChangeNotifierFactoryCast() {
+}
+
+// static
+NetworkChangeNotifierCast* NetworkChangeNotifierFactoryCast::GetInstance() {
+ return g_network_change_notifier_cast.Pointer();
+}
+
+} // namespace chromecast
diff --git a/chromecast/net/network_change_notifier_factory_cast.h b/chromecast/net/network_change_notifier_factory_cast.h
new file mode 100644
index 0000000..6ffa709
--- /dev/null
+++ b/chromecast/net/network_change_notifier_factory_cast.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_CAST_H_
+#define CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_CAST_H_
+
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "net/base/network_change_notifier_factory.h"
+
+namespace chromecast {
+
+class NetworkChangeNotifierCast;
+
+class NetworkChangeNotifierFactoryCast
+ : public net::NetworkChangeNotifierFactory {
+ public:
+ NetworkChangeNotifierFactoryCast() {}
+ virtual ~NetworkChangeNotifierFactoryCast();
+
+ // net::NetworkChangeNotifierFactory implementation:
+ virtual net::NetworkChangeNotifier* CreateInstance() OVERRIDE;
+
+ static NetworkChangeNotifierCast* GetInstance();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierFactoryCast);
+};
+
+} // namespace chromecast
+
+#endif // CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_CAST_H_
diff --git a/chromecast/service/DEPS b/chromecast/service/DEPS
new file mode 100644
index 0000000..1c35d9c
--- /dev/null
+++ b/chromecast/service/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+content/public/browser",
+]
diff --git a/chromecast/service/cast_platform_init_stub.cc b/chromecast/service/cast_platform_init_stub.cc
new file mode 100644
index 0000000..4d1928d
--- /dev/null
+++ b/chromecast/service/cast_platform_init_stub.cc
@@ -0,0 +1,13 @@
+// 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 "chromecast/service/cast_service.h"
+
+namespace chromecast {
+
+// static
+void CastService::PlatformInitialize() {
+}
+
+}
diff --git a/chromecast/service/cast_service.cc b/chromecast/service/cast_service.cc
new file mode 100644
index 0000000..f072523
--- /dev/null
+++ b/chromecast/service/cast_service.cc
@@ -0,0 +1,140 @@
+// 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 "chromecast/service/cast_service.h"
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/threading/thread_checker.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "net/base/filename_util.h"
+#include "ui/aura/env.h"
+#include "ui/aura/layout_manager.h"
+#include "ui/aura/test/test_screen.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/gfx/size.h"
+#include "url/gurl.h"
+
+namespace chromecast {
+
+namespace {
+
+GURL GetStartupURL() {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ const base::CommandLine::StringVector& args = command_line->GetArgs();
+
+ if (args.empty())
+ return GURL("http://www.google.com/");
+
+ GURL url(args[0]);
+ if (url.is_valid() && url.has_scheme())
+ return url;
+
+ return net::FilePathToFileURL(base::FilePath(args[0]));
+}
+
+class FillLayout : public aura::LayoutManager {
+ public:
+ explicit FillLayout(aura::Window* root) : root_(root) {}
+ virtual ~FillLayout() {}
+
+ private:
+ // aura::LayoutManager:
+ virtual void OnWindowResized() OVERRIDE {}
+
+ virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
+ child->SetBounds(root_->bounds());
+ }
+
+ virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
+
+ virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
+
+ virtual void OnChildWindowVisibilityChanged(aura::Window* child,
+ bool visible) OVERRIDE {}
+
+ virtual void SetChildBounds(aura::Window* child,
+ const gfx::Rect& requested_bounds) OVERRIDE {
+ SetChildBoundsDirect(child, requested_bounds);
+ }
+
+ aura::Window* root_;
+
+ DISALLOW_COPY_AND_ASSIGN(FillLayout);
+};
+
+} // namespace
+
+CastService::CastService(content::BrowserContext* browser_context)
+ : browser_context_(browser_context),
+ stopped_(true),
+ thread_checker_(new base::ThreadChecker()) {
+}
+
+CastService::~CastService() {
+ DCHECK(thread_checker_->CalledOnValidThread());
+ DCHECK(stopped_);
+}
+
+void CastService::Initialize() {
+ PlatformInitialize();
+}
+
+void CastService::Start() {
+ DCHECK(thread_checker_->CalledOnValidThread());
+
+ Initialize();
+
+ // Aura initialization
+ gfx::Size initial_size = gfx::Size(1280, 720);
+ // TODO(lcwu): http://crbug.com/391074. Chromecast only needs a minimal
+ // implementation of gfx::screen and aura's TestScreen will do for now.
+ // Change the code to use ozone's screen implementation when it is ready.
+ aura::TestScreen* screen = aura::TestScreen::Create(initial_size);
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen);
+ CHECK(aura::Env::GetInstance());
+ window_tree_host_.reset(
+ aura::WindowTreeHost::Create(gfx::Rect(initial_size)));
+ window_tree_host_->InitHost();
+ window_tree_host_->window()->SetLayoutManager(
+ new FillLayout(window_tree_host_->window()));
+ window_tree_host_->Show();
+
+ // Create a WebContents
+ content::WebContents::CreateParams create_params(browser_context_, NULL);
+ create_params.routing_id = MSG_ROUTING_NONE;
+ create_params.initial_size = initial_size;
+ web_contents_.reset(content::WebContents::Create(create_params));
+
+ // Add and show content's view/window
+ aura::Window* content_window = web_contents_->GetNativeView();
+ aura::Window* parent = window_tree_host_->window();
+ if (!parent->Contains(content_window)) {
+ parent->AddChild(content_window);
+ }
+ content_window->Show();
+
+ web_contents_->GetController().LoadURL(GetStartupURL(),
+ content::Referrer(),
+ content::PAGE_TRANSITION_TYPED,
+ std::string());
+
+ stopped_ = false;
+}
+
+void CastService::Stop() {
+ DCHECK(thread_checker_->CalledOnValidThread());
+
+ web_contents_->GetRenderViewHost()->ClosePage();
+ window_tree_host_.reset();
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
+ aura::Env::DeleteInstance();
+ web_contents_.reset();
+ stopped_ = true;
+}
+
+} // namespace chromecast
diff --git a/chromecast/service/cast_service.h b/chromecast/service/cast_service.h
new file mode 100644
index 0000000..de408b4
--- /dev/null
+++ b/chromecast/service/cast_service.h
@@ -0,0 +1,53 @@
+// 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.
+
+#ifndef CHROMECAST_SERVICE_CAST_SERVICE_H_
+#define CHROMECAST_SERVICE_CAST_SERVICE_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace aura {
+class WindowTreeHost;
+}
+
+namespace base {
+class ThreadChecker;
+}
+
+namespace content{
+class BrowserContext;
+class WebContents;
+}
+
+namespace chromecast {
+
+class CastService {
+ public:
+ explicit CastService(content::BrowserContext* browser_context);
+ virtual ~CastService();
+
+ // Start/stop the cast service.
+ void Start();
+ void Stop();
+
+ private:
+ // Platform specific initialization if any.
+ static void PlatformInitialize();
+
+ void Initialize();
+
+ content::BrowserContext* const browser_context_;
+ scoped_ptr<aura::WindowTreeHost> window_tree_host_;
+ scoped_ptr<content::WebContents> web_contents_;
+ bool stopped_;
+
+ const scoped_ptr<base::ThreadChecker> thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastService);
+};
+
+} // namespace chromecast
+
+#endif // CHROMECAST_SERVICE_CAST_SERVICE_H_
diff --git a/chromecast/shell/app/DEPS b/chromecast/shell/app/DEPS
new file mode 100644
index 0000000..7c1793e
--- /dev/null
+++ b/chromecast/shell/app/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+content/public/app",
+]
diff --git a/chromecast/shell/app/cast_main.cc b/chromecast/shell/app/cast_main.cc
new file mode 100644
index 0000000..6b731b9
--- /dev/null
+++ b/chromecast/shell/app/cast_main.cc
@@ -0,0 +1,14 @@
+// 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 "chromecast/shell/app/cast_main_delegate.h"
+#include "content/public/app/content_main.h"
+
+int main(int argc, const char** argv) {
+ chromecast::shell::CastMainDelegate delegate;
+ content::ContentMainParams params(&delegate);
+ params.argc = argc;
+ params.argv = argv;
+ return content::ContentMain(params);
+}
diff --git a/chromecast/shell/app/cast_main_delegate.cc b/chromecast/shell/app/cast_main_delegate.cc
new file mode 100644
index 0000000..87c5fbf
--- /dev/null
+++ b/chromecast/shell/app/cast_main_delegate.cc
@@ -0,0 +1,68 @@
+// 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 "chromecast/shell/app/cast_main_delegate.h"
+
+#include "base/base_paths.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "chromecast/common/cast_paths.h"
+#include "chromecast/shell/browser/cast_content_browser_client.h"
+#include "chromecast/shell/renderer/cast_content_renderer_client.h"
+#include "content/public/common/content_switches.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace chromecast {
+namespace shell {
+
+CastMainDelegate::CastMainDelegate() {
+}
+
+CastMainDelegate::~CastMainDelegate() {
+}
+
+bool CastMainDelegate::BasicStartupComplete(int* exit_code) {
+ logging::LoggingSettings settings;
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+ 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() {
+ InitializeResourceBundle();
+}
+
+void CastMainDelegate::ZygoteForked() {
+}
+
+// static
+void CastMainDelegate::InitializeResourceBundle() {
+ base::FilePath pak_file;
+ base::FilePath pak_dir;
+
+ PathService::Get(base::DIR_MODULE, &pak_dir);
+
+ pak_file = pak_dir.Append(FILE_PATH_LITERAL("cast_shell.pak"));
+ ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
+}
+
+content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() {
+ browser_client_.reset(new CastContentBrowserClient);
+ return browser_client_.get();
+}
+
+content::ContentRendererClient*
+CastMainDelegate::CreateContentRendererClient() {
+ renderer_client_.reset(new CastContentRendererClient);
+ return renderer_client_.get();
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/app/cast_main_delegate.h b/chromecast/shell/app/cast_main_delegate.h
new file mode 100644
index 0000000..a9abc90
--- /dev/null
+++ b/chromecast/shell/app/cast_main_delegate.h
@@ -0,0 +1,45 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_APP_CAST_MAIN_DELEGATE_H_
+#define CHROMECAST_SHELL_APP_CAST_MAIN_DELEGATE_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "chromecast/shell/common/cast_content_client.h"
+#include "content/public/app/content_main_delegate.h"
+
+namespace chromecast {
+namespace shell {
+
+class CastContentBrowserClient;
+class CastContentRendererClient;
+
+class CastMainDelegate : public content::ContentMainDelegate {
+ public:
+ CastMainDelegate();
+ virtual ~CastMainDelegate();
+
+ // content::ContentMainDelegate implementation:
+ virtual bool BasicStartupComplete(int* exit_code) OVERRIDE;
+ virtual void PreSandboxStartup() OVERRIDE;
+ virtual void ZygoteForked() OVERRIDE;
+ virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE;
+ virtual content::ContentRendererClient*
+ CreateContentRendererClient() OVERRIDE;
+
+ private:
+ static void InitializeResourceBundle();
+
+ scoped_ptr<CastContentBrowserClient> browser_client_;
+ scoped_ptr<CastContentRendererClient> renderer_client_;
+ CastContentClient content_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastMainDelegate);
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_APP_CAST_MAIN_DELEGATE_H_
diff --git a/chromecast/shell/browser/DEPS b/chromecast/shell/browser/DEPS
new file mode 100644
index 0000000..1c35d9c
--- /dev/null
+++ b/chromecast/shell/browser/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+content/public/browser",
+]
diff --git a/chromecast/shell/browser/cast_browser_context.cc b/chromecast/shell/browser/cast_browser_context.cc
new file mode 100644
index 0000000..34658ccb
--- /dev/null
+++ b/chromecast/shell/browser/cast_browser_context.cc
@@ -0,0 +1,131 @@
+// 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 "chromecast/shell/browser/cast_browser_context.h"
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/path_service.h"
+#include "chromecast/common/cast_paths.h"
+#include "chromecast/shell/browser/url_request_context_factory.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_context.h"
+#include "content/public/browser/storage_partition.h"
+#include "content/public/common/content_switches.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace chromecast {
+namespace shell {
+
+class CastBrowserContext::CastResourceContext :
+ public content::ResourceContext {
+ public:
+ CastResourceContext(URLRequestContextFactory* url_request_context_factory) :
+ url_request_context_factory_(url_request_context_factory) {}
+ virtual ~CastResourceContext() {}
+
+ // ResourceContext implementation:
+ virtual net::HostResolver* GetHostResolver() OVERRIDE {
+ return url_request_context_factory_->GetMainGetter()->
+ GetURLRequestContext()->host_resolver();
+ }
+
+ virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
+ return url_request_context_factory_->GetMainGetter()->
+ GetURLRequestContext();
+ }
+
+ virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
+ return false;
+ }
+
+ virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
+ return false;
+ }
+
+ private:
+ URLRequestContextFactory* url_request_context_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastResourceContext);
+};
+
+CastBrowserContext::CastBrowserContext(
+ URLRequestContextFactory* url_request_context_factory)
+ : url_request_context_factory_(url_request_context_factory),
+ resource_context_(new CastResourceContext(url_request_context_factory)) {
+ InitWhileIOAllowed();
+}
+
+CastBrowserContext::~CastBrowserContext() {
+}
+
+void CastBrowserContext::InitWhileIOAllowed() {
+ // Chromecast doesn't support user profiles nor does it have
+ // incognito mode. This means that all of the persistent
+ // data (currently only cookies and local storage) will be
+ // shared in a single location as defined here.
+ CHECK(PathService::Get(DIR_CAST_HOME, &path_));
+}
+
+base::FilePath CastBrowserContext::GetPath() const {
+ return path_;
+}
+
+bool CastBrowserContext::IsOffTheRecord() const {
+ return false;
+}
+
+net::URLRequestContextGetter* CastBrowserContext::GetRequestContext() {
+ return GetDefaultStoragePartition(this)->GetURLRequestContext();
+}
+
+net::URLRequestContextGetter*
+CastBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) {
+ return GetRequestContext();
+}
+
+net::URLRequestContextGetter* CastBrowserContext::GetMediaRequestContext() {
+ return url_request_context_factory_->GetMediaGetter();
+}
+
+net::URLRequestContextGetter*
+CastBrowserContext::GetMediaRequestContextForRenderProcess(
+ int renderer_child_id) {
+ return GetMediaRequestContext();
+}
+
+net::URLRequestContextGetter*
+CastBrowserContext::GetMediaRequestContextForStoragePartition(
+ const base::FilePath& partition_path, bool in_memory) {
+ return GetMediaRequestContext();
+}
+
+content::ResourceContext* CastBrowserContext::GetResourceContext() {
+ return resource_context_.get();
+}
+
+content::DownloadManagerDelegate*
+CastBrowserContext::GetDownloadManagerDelegate() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+content::BrowserPluginGuestManager* CastBrowserContext::GetGuestManager() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+quota::SpecialStoragePolicy* CastBrowserContext::GetSpecialStoragePolicy() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+content::PushMessagingService* CastBrowserContext::GetPushMessagingService() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/cast_browser_context.h b/chromecast/shell/browser/cast_browser_context.h
new file mode 100644
index 0000000..93584e9
--- /dev/null
+++ b/chromecast/shell/browser/cast_browser_context.h
@@ -0,0 +1,64 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_BROWSER_CAST_BROWSER_CONTEXT_H_
+#define CHROMECAST_SHELL_BROWSER_CAST_BROWSER_CONTEXT_H_
+
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/content_browser_client.h"
+
+namespace chromecast {
+namespace shell {
+
+class URLRequestContextFactory;
+
+// Chromecast does not currently support multiple profiles. So there is a
+// single BrowserContext for all chromecast renderers.
+// There is no support for PartitionStorage.
+class CastBrowserContext : public content::BrowserContext {
+ public:
+ explicit CastBrowserContext(
+ URLRequestContextFactory* url_request_context_factory);
+ virtual ~CastBrowserContext();
+
+ // BrowserContext implementation:
+ virtual base::FilePath GetPath() const OVERRIDE;
+ virtual bool IsOffTheRecord() const OVERRIDE;
+ virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
+ virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
+ int renderer_child_id) OVERRIDE;
+ virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
+ virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
+ int renderer_child_id) OVERRIDE;
+ virtual net::URLRequestContextGetter*
+ GetMediaRequestContextForStoragePartition(
+ const base::FilePath& partition_path,
+ bool in_memory) OVERRIDE;
+ virtual content::ResourceContext* GetResourceContext() OVERRIDE;
+ virtual content::DownloadManagerDelegate*
+ GetDownloadManagerDelegate() OVERRIDE;
+ virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE;
+ virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
+ virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
+
+ private:
+ class CastResourceContext;
+
+ // Performs initialization of the CastBrowserContext while IO is still
+ // allowed on the current thread.
+ void InitWhileIOAllowed();
+
+ URLRequestContextFactory* const url_request_context_factory_;
+ base::FilePath path_;
+ scoped_ptr<CastResourceContext> resource_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastBrowserContext);
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_BROWSER_CAST_BROWSER_CONTEXT_H_
diff --git a/chromecast/shell/browser/cast_browser_main_parts.cc b/chromecast/shell/browser/cast_browser_main_parts.cc
new file mode 100644
index 0000000..742dc0b
--- /dev/null
+++ b/chromecast/shell/browser/cast_browser_main_parts.cc
@@ -0,0 +1,101 @@
+// 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 "chromecast/shell/browser/cast_browser_main_parts.h"
+
+#include "base/command_line.h"
+#include "chromecast/net/network_change_notifier_cast.h"
+#include "chromecast/net/network_change_notifier_factory_cast.h"
+#include "chromecast/service/cast_service.h"
+#include "chromecast/shell/browser/cast_browser_context.h"
+#include "chromecast/shell/browser/url_request_context_factory.h"
+
+namespace chromecast {
+namespace shell {
+
+// static
+CastBrowserMainParts* CastBrowserMainParts::instance_ = NULL;
+
+namespace {
+
+struct DefaultCommandLineSwitch {
+ const char* const switch_name;
+ const char* const switch_value;
+};
+
+DefaultCommandLineSwitch g_default_switches[] = {
+ { "enable-webrtc-hw-decoding", "" },
+ { "disable-plugins", "" },
+ { "enable-threaded-compositing", "" },
+ { NULL, NULL }, // Termination
+};
+
+void AddDefaultCommandLineSwitches(CommandLine* command_line) {
+ int i = 0;
+ while (g_default_switches[i].switch_name != NULL) {
+ command_line->AppendSwitchASCII(
+ std::string(g_default_switches[i].switch_name),
+ std::string(g_default_switches[i].switch_value));
+ ++i;
+ }
+}
+
+} // namespace
+
+CastBrowserMainParts::CastBrowserMainParts(
+ const content::MainFunctionParams& parameters,
+ URLRequestContextFactory* url_request_context_factory)
+ : BrowserMainParts(),
+ url_request_context_factory_(url_request_context_factory) {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ AddDefaultCommandLineSwitches(command_line);
+ DCHECK(instance_ == NULL);
+ instance_ = this;
+}
+
+CastBrowserMainParts::~CastBrowserMainParts() {
+ DCHECK(instance_ == this);
+ instance_ = NULL;
+}
+
+void CastBrowserMainParts::PreMainMessageLoopStart() {
+ net::NetworkChangeNotifier::SetFactory(
+ new NetworkChangeNotifierFactoryCast());
+}
+
+void CastBrowserMainParts::PostMainMessageLoopStart() {
+ NOTIMPLEMENTED();
+}
+
+int CastBrowserMainParts::PreCreateThreads() {
+ return 0;
+}
+
+void CastBrowserMainParts::PreMainMessageLoopRun() {
+ url_request_context_factory_->InitializeOnUIThread();
+
+ browser_context_.reset(new CastBrowserContext(url_request_context_factory_));
+
+ cast_service_.reset(new CastService(browser_context_.get()));
+ cast_service_->Start();
+}
+
+bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) {
+ base::MessageLoopForUI::current()->Run();
+ return true;
+}
+
+void CastBrowserMainParts::PostMainMessageLoopRun() {
+ cast_service_->Stop();
+ browser_context_.reset();
+}
+
+// static
+CastBrowserMainParts* CastBrowserMainParts::GetInstance() {
+ DCHECK(instance_ != NULL);
+ return instance_;
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/cast_browser_main_parts.h b/chromecast/shell/browser/cast_browser_main_parts.h
new file mode 100644
index 0000000..eccd512
--- /dev/null
+++ b/chromecast/shell/browser/cast_browser_main_parts.h
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_BROWSER_CAST_BROWSER_MAIN_PARTS_H_
+#define CHROMECAST_SHELL_BROWSER_CAST_BROWSER_MAIN_PARTS_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/browser_main_parts.h"
+
+namespace content {
+struct MainFunctionParams;
+}
+
+namespace chromecast {
+
+class CastService;
+
+namespace shell {
+
+class CastBrowserContext;
+class URLRequestContextFactory;
+
+class CastBrowserMainParts : public content::BrowserMainParts {
+ public:
+ CastBrowserMainParts(
+ const content::MainFunctionParams& parameters,
+ URLRequestContextFactory* url_request_context_factory);
+ virtual ~CastBrowserMainParts();
+
+ // content::BrowserMainParts implementation:
+ virtual void PreMainMessageLoopStart() OVERRIDE;
+ virtual void PostMainMessageLoopStart() OVERRIDE;
+ virtual int PreCreateThreads() OVERRIDE;
+ virtual void PreMainMessageLoopRun() OVERRIDE;
+ virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
+ virtual void PostMainMessageLoopRun() OVERRIDE;
+
+ CastBrowserContext* browser_context() {
+ return browser_context_.get();
+ }
+
+ private:
+ static CastBrowserMainParts* GetInstance();
+
+ static CastBrowserMainParts* instance_;
+ scoped_ptr<CastBrowserContext> browser_context_;
+ scoped_ptr<CastService> cast_service_;
+ URLRequestContextFactory* const url_request_context_factory_;
+
+
+ DISALLOW_COPY_AND_ASSIGN(CastBrowserMainParts);
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_BROWSER_CAST_BROWSER_MAIN_PARTS_H_
diff --git a/chromecast/shell/browser/cast_content_browser_client.cc b/chromecast/shell/browser/cast_content_browser_client.cc
new file mode 100644
index 0000000..68d8391
--- /dev/null
+++ b/chromecast/shell/browser/cast_content_browser_client.cc
@@ -0,0 +1,146 @@
+// 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 "chromecast/shell/browser/cast_content_browser_client.h"
+
+#include "base/command_line.h"
+#include "chromecast/shell/browser/cast_browser_context.h"
+#include "chromecast/shell/browser/cast_browser_main_parts.h"
+#include "chromecast/shell/browser/geolocation/cast_access_token_store.h"
+#include "chromecast/shell/browser/url_request_context_factory.h"
+#include "content/public/browser/certificate_request_result_type.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/common/content_descriptors.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/common/url_constants.h"
+#include "content/public/common/web_preferences.h"
+
+namespace chromecast {
+namespace shell {
+
+CastContentBrowserClient::CastContentBrowserClient()
+ : url_request_context_factory_(new URLRequestContextFactory()) {
+}
+
+CastContentBrowserClient::~CastContentBrowserClient() {
+}
+
+content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) {
+ shell_browser_main_parts_.reset(
+ new CastBrowserMainParts(parameters, url_request_context_factory_.get()));
+ return shell_browser_main_parts_.get();
+}
+
+void CastContentBrowserClient::RenderProcessWillLaunch(
+ content::RenderProcessHost* host) {
+}
+
+net::URLRequestContextGetter* CastContentBrowserClient::CreateRequestContext(
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors) {
+ return url_request_context_factory_->CreateMainGetter(
+ browser_context,
+ protocol_handlers,
+ request_interceptors.Pass());
+}
+
+bool CastContentBrowserClient::IsHandledURL(const GURL& url) {
+ if (!url.is_valid())
+ return false;
+
+ static const char* const kProtocolList[] = {
+ url::kBlobScheme,
+ url::kFileSystemScheme,
+ content::kChromeUIScheme,
+ content::kChromeDevToolsScheme,
+ url::kDataScheme,
+ };
+
+ const std::string& scheme = url.scheme();
+ for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
+ if (scheme == kProtocolList[i])
+ return true;
+ }
+ return false;
+}
+
+void CastContentBrowserClient::AppendExtraCommandLineSwitches(
+ base::CommandLine* command_line,
+ int child_process_id) {
+
+ std::string process_type =
+ command_line->GetSwitchValueNative(switches::kProcessType);
+ // Renderer process comamndline
+ if (process_type == switches::kRendererProcess) {
+ // Any browser command-line switches that should be propagated to
+ // the renderer go here.
+ }
+}
+
+content::AccessTokenStore* CastContentBrowserClient::CreateAccessTokenStore() {
+ return new CastAccessTokenStore(shell_browser_main_parts_->browser_context());
+}
+
+void CastContentBrowserClient::OverrideWebkitPrefs(
+ content::RenderViewHost* render_view_host,
+ const GURL& url,
+ content::WebPreferences* prefs) {
+ prefs->allow_scripts_to_close_windows = true;
+ // TODO(lcwu): http://crbug.com/391089. This pref is set to true by default
+ // because some content providers such as YouTube use plain http requests
+ // to retrieve media data chunks while running in a https page. This pref
+ // should be disabled once all the content providers are no longer doing that.
+ prefs->allow_running_insecure_content = true;
+}
+
+std::string CastContentBrowserClient::GetApplicationLocale() {
+ return "en-US";
+}
+
+void CastContentBrowserClient::AllowCertificateError(
+ int render_process_id,
+ int render_view_id,
+ int cert_error,
+ const net::SSLInfo& ssl_info,
+ const GURL& request_url,
+ content::ResourceType::Type resource_type,
+ bool overridable,
+ bool strict_enforcement,
+ const base::Callback<void(bool)>& callback,
+ content::CertificateRequestResultType* result) {
+ // Allow developers to override certificate errors.
+ // Otherwise, any fatal certificate errors will cause an abort.
+ *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
+ return;
+}
+
+bool CastContentBrowserClient::CanCreateWindow(
+ const GURL& opener_url,
+ const GURL& opener_top_level_frame_url,
+ const GURL& source_origin,
+ WindowContainerType container_type,
+ const GURL& target_url,
+ const content::Referrer& referrer,
+ WindowOpenDisposition disposition,
+ const blink::WebWindowFeatures& features,
+ bool user_gesture,
+ bool opener_suppressed,
+ content::ResourceContext* context,
+ int render_process_id,
+ int opener_id,
+ bool* no_javascript_access) {
+ *no_javascript_access = true;
+ return false;
+}
+
+void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
+ const base::CommandLine& command_line,
+ int child_process_id,
+ std::vector<content::FileDescriptorInfo>* mappings) {
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/cast_content_browser_client.h b/chromecast/shell/browser/cast_content_browser_client.h
new file mode 100644
index 0000000..0bfe197
--- /dev/null
+++ b/chromecast/shell/browser/cast_content_browser_client.h
@@ -0,0 +1,82 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_BROWSER_CAST_CONTENT_BROWSER_CLIENT_H_
+#define CHROMECAST_SHELL_BROWSER_CAST_CONTENT_BROWSER_CLIENT_H_
+
+#include "base/macros.h"
+#include "content/public/browser/content_browser_client.h"
+
+namespace chromecast {
+namespace shell {
+
+class CastBrowserMainParts;
+class URLRequestContextFactory;
+
+class CastContentBrowserClient: public content::ContentBrowserClient {
+ public:
+ CastContentBrowserClient();
+ virtual ~CastContentBrowserClient();
+
+ // content::ContentBrowserClient implementation:
+ virtual content::BrowserMainParts* CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) OVERRIDE;
+ virtual void RenderProcessWillLaunch(
+ content::RenderProcessHost* host) OVERRIDE;
+ virtual net::URLRequestContextGetter* CreateRequestContext(
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors)
+ OVERRIDE;
+ virtual bool IsHandledURL(const GURL& url) OVERRIDE;
+ virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
+ int child_process_id) OVERRIDE;
+ virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
+ virtual void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
+ const GURL& url,
+ content::WebPreferences* prefs) OVERRIDE;
+ virtual std::string GetApplicationLocale() OVERRIDE;
+ virtual void AllowCertificateError(
+ int render_process_id,
+ int render_view_id,
+ int cert_error,
+ const net::SSLInfo& ssl_info,
+ const GURL& request_url,
+ content::ResourceType::Type resource_type,
+ bool overridable,
+ bool strict_enforcement,
+ const base::Callback<void(bool)>& callback,
+ content::CertificateRequestResultType* result) OVERRIDE;
+ virtual bool CanCreateWindow(
+ const GURL& opener_url,
+ const GURL& opener_top_level_frame_url,
+ const GURL& source_origin,
+ WindowContainerType container_type,
+ const GURL& target_url,
+ const content::Referrer& referrer,
+ WindowOpenDisposition disposition,
+ const blink::WebWindowFeatures& features,
+ bool user_gesture,
+ bool opener_suppressed,
+ content::ResourceContext* context,
+ int render_process_id,
+ int opener_id,
+ bool* no_javascript_access) OVERRIDE;
+ virtual void GetAdditionalMappedFilesForChildProcess(
+ const base::CommandLine& command_line,
+ int child_process_id,
+ std::vector<content::FileDescriptorInfo>* mappings) OVERRIDE;
+
+ private:
+ scoped_ptr<CastBrowserMainParts> shell_browser_main_parts_;
+
+ scoped_ptr<URLRequestContextFactory> url_request_context_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastContentBrowserClient);
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_BROWSER_CAST_CONTENT_BROWSER_CLIENT_H_
diff --git a/chromecast/shell/browser/cast_http_user_agent_settings.cc b/chromecast/shell/browser/cast_http_user_agent_settings.cc
new file mode 100644
index 0000000..32957a6
--- /dev/null
+++ b/chromecast/shell/browser/cast_http_user_agent_settings.cc
@@ -0,0 +1,33 @@
+// 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 "chromecast/shell/browser/cast_http_user_agent_settings.h"
+
+#include "base/logging.h"
+#include "chromecast/shell/common/cast_content_client.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/http/http_util.h"
+
+namespace chromecast {
+namespace shell {
+
+CastHttpUserAgentSettings::CastHttpUserAgentSettings() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+}
+
+CastHttpUserAgentSettings::~CastHttpUserAgentSettings() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+}
+
+std::string CastHttpUserAgentSettings::GetAcceptLanguage() const {
+ accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader("en-US");
+ return accept_language_;
+}
+
+std::string CastHttpUserAgentSettings::GetUserAgent() const {
+ return chromecast::shell::GetUserAgent();
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/cast_http_user_agent_settings.h b/chromecast/shell/browser/cast_http_user_agent_settings.h
new file mode 100644
index 0000000..00f86d5
--- /dev/null
+++ b/chromecast/shell/browser/cast_http_user_agent_settings.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_BROWSER_CAST_HTTP_USER_AGENT_SETTINGS_H_
+#define CHROMECAST_SHELL_BROWSER_CAST_HTTP_USER_AGENT_SETTINGS_H_
+
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "base/prefs/pref_member.h"
+#include "net/url_request/http_user_agent_settings.h"
+
+namespace chromecast {
+namespace shell {
+
+class CastHttpUserAgentSettings : public net::HttpUserAgentSettings {
+ public:
+ CastHttpUserAgentSettings();
+ virtual ~CastHttpUserAgentSettings();
+
+ // net::HttpUserAgentSettings implementation:
+ virtual std::string GetAcceptLanguage() const OVERRIDE;
+ virtual std::string GetUserAgent() const OVERRIDE;
+
+ private:
+ mutable std::string accept_language_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastHttpUserAgentSettings);
+};
+
+} // namespace shell
+} // namespace chromecast
+#endif // CHROMECAST_SHELL_BROWSER_CAST_HTTP_USER_AGENT_SETTINGS_H_
diff --git a/chromecast/shell/browser/geolocation/cast_access_token_store.cc b/chromecast/shell/browser/geolocation/cast_access_token_store.cc
new file mode 100644
index 0000000..cae51df
--- /dev/null
+++ b/chromecast/shell/browser/geolocation/cast_access_token_store.cc
@@ -0,0 +1,51 @@
+// 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 "chromecast/shell/browser/geolocation/cast_access_token_store.h"
+
+#include "base/callback_helpers.h"
+#include "chromecast/shell/browser/cast_browser_context.h"
+#include "chromecast/shell/browser/cast_content_browser_client.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/content_client.h"
+
+namespace chromecast {
+namespace shell {
+
+CastAccessTokenStore::CastAccessTokenStore(
+ content::BrowserContext* browser_context)
+ : browser_context_(browser_context) {
+}
+
+CastAccessTokenStore::~CastAccessTokenStore() {
+}
+
+void CastAccessTokenStore::GetRequestContextGetterOnUIThread() {
+ request_context_ = browser_context_->GetRequestContext();
+}
+
+void CastAccessTokenStore::RespondOnOriginatingThread() {
+ base::ResetAndReturn(&callback_).Run(access_token_set_, request_context_);
+}
+
+void CastAccessTokenStore::LoadAccessTokens(
+ const LoadAccessTokensCallbackType& callback) {
+ callback_ = callback;
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&CastAccessTokenStore::GetRequestContextGetterOnUIThread,
+ this),
+ base::Bind(&CastAccessTokenStore::RespondOnOriginatingThread, this));
+}
+
+void CastAccessTokenStore::SaveAccessToken(
+ const GURL& server_url, const base::string16& access_token) {
+ if (access_token_set_[server_url] != access_token) {
+ access_token_set_[server_url] = access_token;
+ }
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/geolocation/cast_access_token_store.h b/chromecast/shell/browser/geolocation/cast_access_token_store.h
new file mode 100644
index 0000000..4ec069b
--- /dev/null
+++ b/chromecast/shell/browser/geolocation/cast_access_token_store.h
@@ -0,0 +1,47 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_BROWSER_GEOLOCATION_CAST_ACCESS_TOKEN_STORE_H_
+#define CHROMECAST_SHELL_BROWSER_GEOLOCATION_CAST_ACCESS_TOKEN_STORE_H_
+
+#include "base/macros.h"
+#include "content/public/browser/access_token_store.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace chromecast {
+namespace shell {
+
+// Access token store for chromecast devices used to initialize the network
+// location provider.
+class CastAccessTokenStore : public content::AccessTokenStore {
+ public:
+ explicit CastAccessTokenStore(content::BrowserContext* browser_context);
+
+ private:
+ virtual ~CastAccessTokenStore();
+
+ // AccessTokenStore implementation:
+ virtual void LoadAccessTokens(
+ const LoadAccessTokensCallbackType& callback) OVERRIDE;
+ virtual void SaveAccessToken(
+ const GURL& server_url, const base::string16& access_token) OVERRIDE;
+
+ void GetRequestContextGetterOnUIThread();
+ void RespondOnOriginatingThread();
+
+ content::BrowserContext* const browser_context_;
+ net::URLRequestContextGetter* request_context_;
+ AccessTokenSet access_token_set_;
+ LoadAccessTokensCallbackType callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastAccessTokenStore);
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_BROWSER_GEOLOCATION_CAST_ACCESS_TOKEN_STORE_H_
diff --git a/chromecast/shell/browser/url_request_context_factory.cc b/chromecast/shell/browser/url_request_context_factory.cc
new file mode 100644
index 0000000..a1db712
--- /dev/null
+++ b/chromecast/shell/browser/url_request_context_factory.cc
@@ -0,0 +1,388 @@
+// 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 "chromecast/shell/browser/url_request_context_factory.h"
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/path_service.h"
+#include "base/threading/worker_pool.h"
+#include "chromecast/shell/browser/cast_http_user_agent_settings.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/cookie_store_factory.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/common/url_constants.h"
+#include "net/cert/cert_verifier.h"
+#include "net/cookies/cookie_store.h"
+#include "net/dns/host_resolver.h"
+#include "net/http/http_auth_handler_factory.h"
+#include "net/http/http_cache.h"
+#include "net/http/http_network_layer.h"
+#include "net/http/http_server_properties_impl.h"
+#include "net/http/http_stream_factory.h"
+#include "net/ocsp/nss_ocsp.h"
+#include "net/proxy/proxy_service.h"
+#include "net/socket/next_proto.h"
+#include "net/ssl/default_server_bound_cert_store.h"
+#include "net/ssl/server_bound_cert_service.h"
+#include "net/ssl/ssl_config_service_defaults.h"
+#include "net/url_request/data_protocol_handler.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_intercepting_job_factory.h"
+#include "net/url_request/url_request_job_factory_impl.h"
+
+namespace chromecast {
+namespace shell {
+
+namespace {
+
+const char kCookieStoreFile[] = "Cookies";
+
+} // namespace
+
+// Private classes to expose URLRequestContextGetter that call back to the
+// URLRequestContextFactory to create the URLRequestContext on demand.
+//
+// The URLRequestContextFactory::URLRequestContextGetter class is used for both
+// the system and media URLRequestCotnexts.
+class URLRequestContextFactory::URLRequestContextGetter
+ : public net::URLRequestContextGetter {
+ public:
+ URLRequestContextGetter(URLRequestContextFactory* factory, bool is_media)
+ : is_media_(is_media),
+ factory_(factory) {
+ }
+
+ virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
+ if (!request_context_) {
+ if (is_media_) {
+ request_context_.reset(factory_->CreateMediaRequestContext());
+ } else {
+ request_context_.reset(factory_->CreateSystemRequestContext());
+ // Set request context used by NSS for Crl requests.
+ net::SetURLRequestContextForNSSHttpIO(request_context_.get());
+ }
+ }
+ return request_context_.get();
+ }
+
+ virtual scoped_refptr<base::SingleThreadTaskRunner>
+ GetNetworkTaskRunner() const OVERRIDE {
+ return content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO);
+ }
+
+ private:
+ virtual ~URLRequestContextGetter() {}
+
+ const bool is_media_;
+ URLRequestContextFactory* const factory_;
+ scoped_ptr<net::URLRequestContext> request_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter);
+};
+
+// The URLRequestContextFactory::MainURLRequestContextGetter class is used for
+// the main URLRequestContext.
+class URLRequestContextFactory::MainURLRequestContextGetter
+ : public net::URLRequestContextGetter {
+ public:
+ MainURLRequestContextGetter(
+ URLRequestContextFactory* factory,
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors)
+ : browser_context_(browser_context),
+ factory_(factory),
+ request_interceptors_(request_interceptors.Pass()) {
+ std::swap(protocol_handlers_, *protocol_handlers);
+ }
+
+ virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
+ if (!request_context_) {
+ request_context_.reset(factory_->CreateMainRequestContext(
+ browser_context_, &protocol_handlers_, request_interceptors_.Pass()));
+ protocol_handlers_.clear();
+ }
+ return request_context_.get();
+ }
+
+ virtual scoped_refptr<base::SingleThreadTaskRunner>
+ GetNetworkTaskRunner() const OVERRIDE {
+ return content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO);
+ }
+
+ private:
+ virtual ~MainURLRequestContextGetter() {}
+
+ content::BrowserContext* const browser_context_;
+ URLRequestContextFactory* const factory_;
+ content::ProtocolHandlerMap protocol_handlers_;
+ content::URLRequestInterceptorScopedVector request_interceptors_;
+ scoped_ptr<net::URLRequestContext> request_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(MainURLRequestContextGetter);
+};
+
+URLRequestContextFactory::URLRequestContextFactory()
+ : system_dependencies_initialized_(false),
+ main_dependencies_initialized_(false),
+ media_dependencies_initialized_(false) {
+}
+
+URLRequestContextFactory::~URLRequestContextFactory() {
+}
+
+void URLRequestContextFactory::InitializeOnUIThread() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ // Cast http user agent settings must be initialized in UI thread
+ // because it registers itself to pref notification observer which is not
+ // thread safe.
+ http_user_agent_settings_.reset(new CastHttpUserAgentSettings());
+}
+
+net::URLRequestContextGetter* URLRequestContextFactory::CreateMainGetter(
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors) {
+ DCHECK(!main_getter_) << "Main URLRequestContextGetter already initialized";
+ main_getter_ = new MainURLRequestContextGetter(this,
+ browser_context,
+ protocol_handlers,
+ request_interceptors.Pass());
+ return main_getter_.get();
+}
+
+net::URLRequestContextGetter* URLRequestContextFactory::GetMainGetter() {
+ CHECK(main_getter_);
+ return main_getter_.get();
+}
+
+net::URLRequestContextGetter* URLRequestContextFactory::GetSystemGetter() {
+ if (!system_getter_) {
+ system_getter_ = new URLRequestContextGetter(this, false);
+ }
+ return system_getter_.get();
+}
+
+net::URLRequestContextGetter* URLRequestContextFactory::GetMediaGetter() {
+ if (!media_getter_) {
+ media_getter_ = new URLRequestContextGetter(this, true);
+ }
+ return media_getter_.get();
+}
+
+void URLRequestContextFactory::InitializeSystemContextDependencies() {
+ if (system_dependencies_initialized_)
+ return;
+
+ host_resolver_ = net::HostResolver::CreateDefaultResolver(NULL);
+
+ // TODO(lcwu): http://crbug.com/392352. For performance and security reasons,
+ // a persistent (on-disk) HttpServerProperties and ServerBoundCertService
+ // might be desirable in the future.
+ server_bound_cert_service_.reset(new net::ServerBoundCertService(
+ new net::DefaultServerBoundCertStore(NULL),
+ base::WorkerPool::GetTaskRunner(true)));
+
+ cert_verifier_.reset(net::CertVerifier::CreateDefault());
+
+ ssl_config_service_ = new net::SSLConfigServiceDefaults;
+
+ transport_security_state_.reset(new net::TransportSecurityState());
+ http_auth_handler_factory_.reset(
+ net::HttpAuthHandlerFactory::CreateDefault(host_resolver_.get()));
+
+ http_server_properties_.reset(new net::HttpServerPropertiesImpl);
+
+ proxy_service_.reset(net::ProxyService::CreateUsingSystemProxyResolver(
+ net::ProxyService::CreateSystemProxyConfigService(
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO).get(),
+ content::BrowserThread::UnsafeGetMessageLoopForThread(
+ content::BrowserThread::FILE)),
+ 0,
+ NULL));
+ system_dependencies_initialized_ = true;
+}
+
+void URLRequestContextFactory::InitializeMainContextDependencies(
+ net::HttpTransactionFactory* transaction_factory,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors) {
+ if (main_dependencies_initialized_)
+ return;
+
+ main_transaction_factory_.reset(transaction_factory);
+ scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
+ new net::URLRequestJobFactoryImpl());
+ // Keep ProtocolHandlers added in sync with
+ // CastContentBrowserClient::IsHandledURL().
+ bool set_protocol = false;
+ for (content::ProtocolHandlerMap::iterator it = protocol_handlers->begin();
+ it != protocol_handlers->end();
+ ++it) {
+ set_protocol = job_factory->SetProtocolHandler(
+ it->first, it->second.release());
+ DCHECK(set_protocol);
+ }
+ set_protocol = job_factory->SetProtocolHandler(
+ url::kDataScheme,
+ new net::DataProtocolHandler);
+ DCHECK(set_protocol);
+
+ // Set up interceptors in the reverse order.
+ scoped_ptr<net::URLRequestJobFactory> top_job_factory =
+ job_factory.PassAs<net::URLRequestJobFactory>();
+ for (content::URLRequestInterceptorScopedVector::reverse_iterator i =
+ request_interceptors.rbegin();
+ i != request_interceptors.rend();
+ ++i) {
+ top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
+ top_job_factory.Pass(), make_scoped_ptr(*i)));
+ }
+ request_interceptors.weak_clear();
+
+ main_job_factory_.reset(top_job_factory.release());
+
+ main_dependencies_initialized_ = true;
+}
+
+void URLRequestContextFactory::InitializeMediaContextDependencies(
+ net::HttpTransactionFactory* transaction_factory) {
+ if (media_dependencies_initialized_)
+ return;
+
+ media_transaction_factory_.reset(transaction_factory);
+ media_dependencies_initialized_ = true;
+}
+
+void URLRequestContextFactory::PopulateNetworkSessionParams(
+ bool ignore_certificate_errors,
+ net::HttpNetworkSession::Params* params) {
+ params->host_resolver = host_resolver_.get();
+ params->cert_verifier = cert_verifier_.get();
+ params->server_bound_cert_service = server_bound_cert_service_.get();
+ params->ssl_config_service = ssl_config_service_.get();
+ params->transport_security_state = transport_security_state_.get();
+ params->http_auth_handler_factory = http_auth_handler_factory_.get();
+ params->http_server_properties = http_server_properties_->GetWeakPtr();
+ params->ignore_certificate_errors = ignore_certificate_errors;
+ params->proxy_service = proxy_service_.get();
+
+ // TODO(lcwu): http://crbug.com/329681. Remove this once spdy is enabled
+ // by default at the content level.
+ params->next_protos = net::NextProtosSpdy31();
+ params->use_alternate_protocols = true;
+}
+
+net::URLRequestContext* URLRequestContextFactory::CreateSystemRequestContext() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ InitializeSystemContextDependencies();
+ net::HttpNetworkSession::Params system_params;
+ PopulateNetworkSessionParams(false, &system_params);
+ system_transaction_factory_.reset(new net::HttpNetworkLayer(
+ new net::HttpNetworkSession(system_params)));
+
+ net::URLRequestContext* system_context = new net::URLRequestContext();
+ system_context->set_host_resolver(host_resolver_.get());
+ system_context->set_server_bound_cert_service(
+ server_bound_cert_service_.get());
+ system_context->set_cert_verifier(cert_verifier_.get());
+ system_context->set_proxy_service(proxy_service_.get());
+ system_context->set_ssl_config_service(ssl_config_service_.get());
+ system_context->set_transport_security_state(
+ transport_security_state_.get());
+ system_context->set_http_auth_handler_factory(
+ http_auth_handler_factory_.get());
+ system_context->set_http_server_properties(
+ http_server_properties_->GetWeakPtr());
+ system_context->set_http_transaction_factory(
+ system_transaction_factory_.get());
+ system_context->set_http_user_agent_settings(
+ http_user_agent_settings_.get());
+ system_context->set_cookie_store(
+ content::CreateCookieStore(content::CookieStoreConfig()));
+ return system_context;
+}
+
+net::URLRequestContext* URLRequestContextFactory::CreateMediaRequestContext() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ DCHECK(main_getter_)
+ << "Getting MediaRequestContext before MainRequestContext";
+ net::URLRequestContext* main_context = main_getter_->GetURLRequestContext();
+
+ // Set non caching backend.
+ net::HttpNetworkSession* main_session =
+ main_transaction_factory_->GetSession();
+ InitializeMediaContextDependencies(
+ new net::HttpNetworkLayer(main_session));
+
+ net::URLRequestContext* media_context = new net::URLRequestContext();
+ media_context->CopyFrom(main_context);
+ media_context->set_http_transaction_factory(
+ media_transaction_factory_.get());
+ return media_context;
+}
+
+net::URLRequestContext* URLRequestContextFactory::CreateMainRequestContext(
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ InitializeSystemContextDependencies();
+
+ net::HttpCache::BackendFactory* main_backend =
+ net::HttpCache::DefaultBackend::InMemory(16 * 1024 * 1024);
+
+ bool ignore_certificate_errors = false;
+ CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+ if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors)) {
+ ignore_certificate_errors = true;
+ }
+ net::HttpNetworkSession::Params network_session_params;
+ PopulateNetworkSessionParams(ignore_certificate_errors,
+ &network_session_params);
+ InitializeMainContextDependencies(
+ new net::HttpCache(network_session_params, main_backend),
+ protocol_handlers,
+ request_interceptors.Pass());
+
+ content::CookieStoreConfig cookie_config(
+ browser_context->GetPath().Append(kCookieStoreFile),
+ content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES,
+ NULL, NULL);
+ cookie_config.background_task_runner =
+ scoped_refptr<base::SequencedTaskRunner>();
+ scoped_refptr<net::CookieStore> cookie_store =
+ content::CreateCookieStore(cookie_config);
+
+ net::URLRequestContext* main_context = new net::URLRequestContext();
+ main_context->set_host_resolver(host_resolver_.get());
+ main_context->set_server_bound_cert_service(
+ server_bound_cert_service_.get());
+ main_context->set_cert_verifier(cert_verifier_.get());
+ main_context->set_proxy_service(proxy_service_.get());
+ main_context->set_ssl_config_service(ssl_config_service_.get());
+ main_context->set_transport_security_state(transport_security_state_.get());
+ main_context->set_http_auth_handler_factory(
+ http_auth_handler_factory_.get());
+ main_context->set_http_server_properties(
+ http_server_properties_->GetWeakPtr());
+ main_context->set_cookie_store(cookie_store.get());
+ main_context->set_http_user_agent_settings(
+ http_user_agent_settings_.get());
+
+ main_context->set_http_transaction_factory(
+ main_transaction_factory_.get());
+ main_context->set_job_factory(main_job_factory_.get());
+ return main_context;
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/url_request_context_factory.h b/chromecast/shell/browser/url_request_context_factory.h
new file mode 100644
index 0000000..e094c0d
--- /dev/null
+++ b/chromecast/shell/browser/url_request_context_factory.h
@@ -0,0 +1,103 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_
+#define CHROMECAST_SHELL_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_
+
+#include "content/public/browser/content_browser_client.h"
+#include "net/http/http_network_session.h"
+
+namespace net {
+class HttpTransactionFactory;
+class HttpUserAgentSettings;
+class URLRequestJobFactory;
+} // namespace net
+
+namespace chromecast {
+namespace shell {
+
+class URLRequestContextFactory {
+ public:
+ URLRequestContextFactory();
+ ~URLRequestContextFactory();
+
+ // Some members must be initialized on UI thread.
+ void InitializeOnUIThread();
+
+ // Since main context requires a bunch of input params, if these get called
+ // multiple times, either multiple main contexts should be supported/managed
+ // or the input params need to be the same as before. So to be safe,
+ // the CreateMainGetter function currently DCHECK to make sure it is not
+ // called more than once.
+ // The media and system getters however, do not need input, so it is actually
+ // safe to call these multiple times. The impl create only 1 getter of each
+ // type and return the same instance each time the methods are called, thus
+ // the name difference.
+ net::URLRequestContextGetter* GetSystemGetter();
+ net::URLRequestContextGetter* CreateMainGetter(
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors);
+ net::URLRequestContextGetter* GetMainGetter();
+ net::URLRequestContextGetter* GetMediaGetter();
+
+ private:
+ class URLRequestContextGetter;
+ class MainURLRequestContextGetter;
+ friend class URLRequestContextGetter;
+ friend class MainURLRequestContextGetter;
+
+ void InitializeSystemContextDependencies();
+ void InitializeMainContextDependencies(
+ net::HttpTransactionFactory* factory,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors);
+ void InitializeMediaContextDependencies(net::HttpTransactionFactory* factory);
+
+ void PopulateNetworkSessionParams(bool ignore_certificate_errors,
+ net::HttpNetworkSession::Params* params);
+
+ // These are called by the RequestContextGetters to create each
+ // RequestContext.
+ // They must be called on the IO thread.
+ net::URLRequestContext* CreateSystemRequestContext();
+ net::URLRequestContext* CreateMediaRequestContext();
+ net::URLRequestContext* CreateMainRequestContext(
+ content::BrowserContext* browser_context,
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors);
+
+ scoped_refptr<net::URLRequestContextGetter> system_getter_;
+ scoped_refptr<net::URLRequestContextGetter> media_getter_;
+ scoped_refptr<net::URLRequestContextGetter> main_getter_;
+
+ // Shared objects for all contexts.
+ // The URLRequestContextStorage class is not used as owner to these objects
+ // since they are shared between the different URLRequestContexts.
+ // The URLRequestContextStorage class manages dependent resources for a single
+ // instance of URLRequestContext only.
+ bool system_dependencies_initialized_;
+ scoped_ptr<net::HostResolver> host_resolver_;
+ scoped_ptr<net::ServerBoundCertService> server_bound_cert_service_;
+ scoped_ptr<net::CertVerifier> cert_verifier_;
+ scoped_refptr<net::SSLConfigService> ssl_config_service_;
+ scoped_ptr<net::TransportSecurityState> transport_security_state_;
+ scoped_ptr<net::ProxyService> proxy_service_;
+ scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_;
+ scoped_ptr<net::HttpServerProperties> http_server_properties_;
+ scoped_ptr<net::HttpUserAgentSettings> http_user_agent_settings_;
+ scoped_ptr<net::HttpTransactionFactory> system_transaction_factory_;
+
+ bool main_dependencies_initialized_;
+ scoped_ptr<net::HttpTransactionFactory> main_transaction_factory_;
+ scoped_ptr<net::URLRequestJobFactory> main_job_factory_;
+
+ bool media_dependencies_initialized_;
+ scoped_ptr<net::HttpTransactionFactory> media_transaction_factory_;
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_
diff --git a/chromecast/shell/common/cast_content_client.cc b/chromecast/shell/common/cast_content_client.cc
new file mode 100644
index 0000000..a09ec45
--- /dev/null
+++ b/chromecast/shell/common/cast_content_client.cc
@@ -0,0 +1,53 @@
+// 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 "chromecast/shell/common/cast_content_client.h"
+
+#include "content/public/common/user_agent.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace chromecast {
+namespace shell {
+
+// TODO(lcwu): http://crbug.com/391080. Create the actual Chromecast
+// product version string and hook it up here.
+#define PRODUCT_VERSION "0.0.0.0"
+
+std::string GetUserAgent() {
+ std::string product = "Chrome/" PRODUCT_VERSION;
+ return content::BuildUserAgentFromProduct(product);
+}
+
+CastContentClient::~CastContentClient() {
+}
+
+std::string CastContentClient::GetUserAgent() const {
+ return chromecast::shell::GetUserAgent();
+}
+
+base::string16 CastContentClient::GetLocalizedString(int message_id) const {
+ return l10n_util::GetStringUTF16(message_id);
+}
+
+base::StringPiece CastContentClient::GetDataResource(
+ int resource_id,
+ ui::ScaleFactor scale_factor) const {
+ return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
+ resource_id, scale_factor);
+}
+
+base::RefCountedStaticMemory* CastContentClient::GetDataResourceBytes(
+ int resource_id) const {
+ return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
+ resource_id);
+}
+
+gfx::Image& CastContentClient::GetNativeImageNamed(int resource_id) const {
+ return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
+ resource_id);
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/common/cast_content_client.h b/chromecast/shell/common/cast_content_client.h
new file mode 100644
index 0000000..2631864
--- /dev/null
+++ b/chromecast/shell/common/cast_content_client.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_COMMON_CAST_CONTENT_CLIENT_H_
+#define CHROMECAST_SHELL_COMMON_CAST_CONTENT_CLIENT_H_
+
+#include "content/public/common/content_client.h"
+
+namespace chromecast {
+namespace shell {
+
+std::string GetUserAgent();
+
+class CastContentClient : public content::ContentClient {
+ public:
+ virtual ~CastContentClient();
+
+ // content::ContentClient implementation:
+ virtual std::string GetUserAgent() const OVERRIDE;
+ virtual base::string16 GetLocalizedString(int message_id) const OVERRIDE;
+ virtual base::StringPiece GetDataResource(
+ int resource_id,
+ ui::ScaleFactor scale_factor) const OVERRIDE;
+ virtual base::RefCountedStaticMemory* GetDataResourceBytes(
+ int resource_id) const OVERRIDE;
+ virtual gfx::Image& GetNativeImageNamed(int resource_id) const OVERRIDE;
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_COMMON_CAST_CONTENT_CLIENT_H_
diff --git a/chromecast/shell/renderer/DEPS b/chromecast/shell/renderer/DEPS
new file mode 100644
index 0000000..725e151
--- /dev/null
+++ b/chromecast/shell/renderer/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+content/public/renderer",
+]
diff --git a/chromecast/shell/renderer/cast_content_renderer_client.cc b/chromecast/shell/renderer/cast_content_renderer_client.cc
new file mode 100644
index 0000000..c3855a7
--- /dev/null
+++ b/chromecast/shell/renderer/cast_content_renderer_client.cc
@@ -0,0 +1,34 @@
+// 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 "chromecast/shell/renderer/cast_content_renderer_client.h"
+
+#include <sys/sysinfo.h>
+
+#include "base/command_line.h"
+#include "base/memory/memory_pressure_listener.h"
+#include "content/public/common/content_switches.h"
+#include "crypto/nss_util.h"
+
+namespace chromecast {
+namespace shell {
+
+void CastContentRendererClient::RenderThreadStarted() {
+#if defined(USE_NSS)
+ // Note: Copied from chrome_render_process_observer.cc to fix b/8676652.
+ //
+ // On platforms where the system NSS shared libraries are used,
+ // initialize NSS now because it won't be able to load the .so's
+ // after entering the sandbox.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
+ crypto::InitNSSSafely();
+#endif
+}
+
+void CastContentRendererClient::AddKeySystems(
+ std::vector<content::KeySystemInfo>* key_systems) {
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/renderer/cast_content_renderer_client.h b/chromecast/shell/renderer/cast_content_renderer_client.h
new file mode 100644
index 0000000..b12814f
--- /dev/null
+++ b/chromecast/shell/renderer/cast_content_renderer_client.h
@@ -0,0 +1,27 @@
+// 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.
+
+#ifndef CHROMECAST_SHELL_RENDERER_CAST_CONTENT_RENDERER_CLIENT_H_
+#define CHROMECAST_SHELL_RENDERER_CAST_CONTENT_RENDERER_CLIENT_H_
+
+#include "content/public/renderer/content_renderer_client.h"
+
+namespace chromecast {
+namespace shell {
+
+class CastContentRendererClient : public content::ContentRendererClient {
+ public:
+ CastContentRendererClient() {}
+ virtual ~CastContentRendererClient() {}
+
+ // ContentRendererClient implementation:
+ virtual void RenderThreadStarted() OVERRIDE;
+ virtual void AddKeySystems(
+ std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_RENDERER_CAST_CONTENT_RENDERER_CLIENT_H_