summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 06:06:06 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 06:06:06 +0000
commit1f56ac159cfaae8bd00472b9e81a442e99e5389e (patch)
tree0f915aeacac92d28f346b6a61210050e881ab2ad
parentc6584ac8d2e57fa5193c3203e09c13fcf270474c (diff)
downloadchromium_src-1f56ac159cfaae8bd00472b9e81a442e99e5389e.zip
chromium_src-1f56ac159cfaae8bd00472b9e81a442e99e5389e.tar.gz
chromium_src-1f56ac159cfaae8bd00472b9e81a442e99e5389e.tar.bz2
app_shell attempts to load an app when passed --app=<path/to/app>
Initialize the extensions system with a BrowserContext (not a profile). This doesn't work yet, but allows us to see how far we can run and helps identify the next area to work on. BUG=None TEST=None, for developers only Review URL: https://codereview.chromium.org/99073004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238596 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/app_load_service.cc5
-rw-r--r--apps/apps.gypi5
-rw-r--r--apps/shell/DEPS6
-rw-r--r--apps/shell/app_shell_browser_context.cc82
-rw-r--r--apps/shell/app_shell_browser_context.h42
-rw-r--r--apps/shell/app_shell_browser_main_parts.cc100
-rw-r--r--apps/shell/app_shell_browser_main_parts.h23
-rw-r--r--apps/shell/app_shell_content_browser_client.cc6
8 files changed, 242 insertions, 27 deletions
diff --git a/apps/app_load_service.cc b/apps/app_load_service.cc
index afe99f8..3526566 100644
--- a/apps/app_load_service.cc
+++ b/apps/app_load_service.cc
@@ -21,6 +21,7 @@
using extensions::Extension;
using extensions::ExtensionPrefs;
+using extensions::ExtensionSystem;
namespace apps {
@@ -52,8 +53,10 @@ void AppLoadService::RestartApplication(const std::string& extension_id) {
bool AppLoadService::LoadAndLaunch(const base::FilePath& extension_path,
const CommandLine& command_line,
const base::FilePath& current_dir) {
+ ExtensionService* extension_service =
+ ExtensionSystem::GetForBrowserContext(profile_)->extension_service();
std::string extension_id;
- if (!extensions::UnpackedInstaller::Create(profile_->GetExtensionService())->
+ if (!extensions::UnpackedInstaller::Create(extension_service)->
LoadFromCommandLine(base::FilePath(extension_path), &extension_id)) {
return false;
}
diff --git a/apps/apps.gypi b/apps/apps.gypi
index 0d788c9..e26ea5d 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -108,7 +108,10 @@
},
'dependencies': [
'apps',
+ 'chrome_resources.gyp:packed_resources',
+ 'test_support_common',
'../base/base.gyp:base',
+ '../base/base.gyp:base_prefs_test_support',
'../content/content.gyp:content',
'../content/content_shell_and_tests.gyp:content_shell_lib',
'../skia/skia.gyp:skia',
@@ -119,6 +122,8 @@
'..',
],
'sources': [
+ 'shell/app_shell_browser_context.cc',
+ 'shell_app_shell_browser_context.h',
'shell/app_shell_browser_main_parts.cc',
'shell/app_shell_browser_main_parts.h',
'shell/app_shell_content_browser_client.cc',
diff --git a/apps/shell/DEPS b/apps/shell/DEPS
index a539283..55c7e28 100644
--- a/apps/shell/DEPS
+++ b/apps/shell/DEPS
@@ -1,9 +1,13 @@
include_rules = [
"-chrome",
+ "+chromeos",
+ "+components/user_prefs",
"+ui/shell",
"+webkit/common/user_agent/user_agent_util.h",
- # Pieces of content_shell reused in app_shell.
# TODO(jamescook): Remove these. http://crbug.com/305404
+ # Chrome pieces for bring-up.
+ "+chrome/common/chrome_paths.h",
+ # Pieces of content_shell reused in app_shell.
"+content/shell/browser/shell_browser_context.h",
]
diff --git a/apps/shell/app_shell_browser_context.cc b/apps/shell/app_shell_browser_context.cc
new file mode 100644
index 0000000..e95fa75
--- /dev/null
+++ b/apps/shell/app_shell_browser_context.cc
@@ -0,0 +1,82 @@
+// Copyright 2013 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 "apps/shell/app_shell_browser_context.h"
+
+#include "apps/app_load_service_factory.h"
+#include "base/prefs/pref_service.h"
+#include "base/prefs/pref_service_factory.h"
+#include "base/prefs/testing_pref_store.h"
+#include "components/user_prefs/pref_registry_syncable.h"
+#include "components/user_prefs/user_prefs.h"
+
+namespace {
+
+// See ChromeBrowserMainExtraPartsProfiles for details.
+void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
+ apps::AppLoadServiceFactory::GetInstance();
+}
+
+// See chrome::RegisterProfilePrefs() in chrome/browser/prefs/browser_prefs.cc
+void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) {
+ // TODO(jamescook): ExtensionPrefs::RegisterProfilePrefs(registry)
+}
+
+} // namespace
+
+namespace apps {
+
+// TODO(jamescook): Should this be an off-the-record context?
+// TODO(jamescook): Could initialize NetLog here to get logs from the networking
+// stack.
+AppShellBrowserContext::AppShellBrowserContext()
+ : content::ShellBrowserContext(false, NULL) {
+ EnsureBrowserContextKeyedServiceFactoriesBuilt();
+
+ base::PrefServiceFactory factory;
+ factory.set_user_prefs(new TestingPrefStore);
+ factory.set_extension_prefs(new TestingPrefStore);
+ // app_shell should not require syncable preferences, but for now we need to
+ // recycle some of the RegisterProfilePrefs() code in Chrome.
+ // TODO(jamescook): Convert this to user_prefs::PrefRegistrySimple.
+ user_prefs::PrefRegistrySyncable* pref_registry =
+ new user_prefs::PrefRegistrySyncable;
+ // Prefs should be registered before the PrefService is created.
+ RegisterPrefs(pref_registry);
+ prefs_ = factory.Create(pref_registry).Pass();
+ user_prefs::UserPrefs::Set(this, prefs_.get());
+}
+
+AppShellBrowserContext::~AppShellBrowserContext() {
+}
+
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext1() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext2() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext3() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext4() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext5() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext6() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext7() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext8() {
+ NOTREACHED();
+}
+void AppShellBrowserContext::ProfileFunctionCallOnNonProfileBrowserContext9() {
+ NOTREACHED();
+}
+
+} // namespace apps
diff --git a/apps/shell/app_shell_browser_context.h b/apps/shell/app_shell_browser_context.h
new file mode 100644
index 0000000..3a12679
--- /dev/null
+++ b/apps/shell/app_shell_browser_context.h
@@ -0,0 +1,42 @@
+// Copyright 2013 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 APPS_SHELL_APP_SHELL_BROWSER_CONTEXT_H_
+#define APPS_SHELL_APP_SHELL_BROWSER_CONTEXT_H_
+
+#include "base/compiler_specific.h"
+#include "content/shell/browser/shell_browser_context.h"
+
+class PrefService;
+
+namespace apps {
+
+// The BrowserContext used by the content, apps and extensions systems in
+// app_shell.
+class AppShellBrowserContext : public content::ShellBrowserContext {
+ public:
+ AppShellBrowserContext();
+ virtual ~AppShellBrowserContext();
+
+ // HACK: Pad the virtual function table so we trip an assertion if someone
+ // tries to use |this| as a Profile.
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext1();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext2();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext3();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext4();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext5();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext6();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext7();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext8();
+ virtual void ProfileFunctionCallOnNonProfileBrowserContext9();
+
+ private:
+ scoped_ptr<PrefService> prefs_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppShellBrowserContext);
+};
+
+} // namespace apps
+
+#endif // APPS_SHELL_APP_SHELL_BROWSER_CONTEXT_H_
diff --git a/apps/shell/app_shell_browser_main_parts.cc b/apps/shell/app_shell_browser_main_parts.cc
index 67caffa..1cc9456 100644
--- a/apps/shell/app_shell_browser_main_parts.cc
+++ b/apps/shell/app_shell_browser_main_parts.cc
@@ -4,13 +4,23 @@
#include "apps/shell/app_shell_browser_main_parts.h"
+#include "apps/app_load_service.h"
+#include "apps/shell/app_shell_browser_context.h"
#include "apps/shell/web_view_window.h"
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/path_service.h"
#include "base/run_loop.h"
+#include "chrome/common/chrome_paths.h"
+#include "chromeos/chromeos_paths.h"
#include "content/public/common/result_codes.h"
-#include "content/shell/browser/shell_browser_context.h"
+#include "extensions/common/extension_paths.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/test_screen.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/screen.h"
#include "ui/wm/test/wm_test_helper.h"
namespace apps {
@@ -22,6 +32,35 @@ AppShellBrowserMainParts::AppShellBrowserMainParts(
AppShellBrowserMainParts::~AppShellBrowserMainParts() {
}
+void AppShellBrowserMainParts::CreateRootWindow() {
+ // TODO(jamescook): Replace this with a real Screen implementation.
+ gfx::Screen::SetScreenInstance(
+ gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
+ // Set up basic pieces of views::corewm.
+ wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600)));
+ // Ensure the X window gets mapped.
+ wm_test_helper_->root_window()->host()->Show();
+}
+
+void AppShellBrowserMainParts::LoadAndLaunchApp(const base::FilePath& app_dir) {
+ base::FilePath current_dir;
+ CHECK(file_util::GetCurrentDirectory(&current_dir));
+
+ // HACK: This allows us to see how far we can get without crashing.
+ Profile* profile = reinterpret_cast<Profile*>(browser_context_.get());
+ LOG(WARNING) << "-----------------------------------";
+ LOG(WARNING) << "app_shell is expected to crash now.";
+ LOG(WARNING) << "-----------------------------------";
+
+ apps::AppLoadService* app_load_service =
+ apps::AppLoadService::Get(profile);
+ DCHECK(app_load_service);
+ if (!app_load_service->LoadAndLaunch(
+ app_dir, *CommandLine::ForCurrentProcess(), current_dir)) {
+ LOG(ERROR) << "Unable to launch app at \"" << app_dir.value() << "\"";
+ }
+}
+
void AppShellBrowserMainParts::PreMainMessageLoopStart() {
// TODO(jamescook): Initialize touch here?
}
@@ -32,25 +71,52 @@ void AppShellBrowserMainParts::PostMainMessageLoopStart() {
void AppShellBrowserMainParts::PreEarlyInitialization() {
}
+int AppShellBrowserMainParts::PreCreateThreads() {
+ // TODO(jamescook): Initialize chromeos::CrosSettings here?
+
+ // Return no error.
+ return 0;
+}
+
void AppShellBrowserMainParts::PreMainMessageLoopRun() {
- // TODO(jamescook): Could initialize NetLog here to get logs from the
- // networking stack.
- // TODO(jamescook): Should this be an off-the-record context?
- browser_context_.reset(new content::ShellBrowserContext(false, NULL));
+ // NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc
+ // Set up all the paths to load files.
+ chrome::RegisterPathProvider();
+ chromeos::RegisterPathProvider();
+ extensions::RegisterPathProvider();
- // TODO(jamescook): Replace this with a real Screen implementation.
- gfx::Screen::SetScreenInstance(
- gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
- // Set up basic pieces of views::corewm.
- wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600)));
- // Ensure the X window gets mapped.
- wm_test_helper_->root_window()->host()->Show();
+ // The extensions system needs manifest data from the Chrome PAK file.
+ base::FilePath resources_pack_path;
+ PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
+ ResourceBundle::GetSharedInstance().AddDataPackFromPath(
+ resources_pack_path, ui::SCALE_FACTOR_NONE);
+
+ // TODO(jamescook): Initialize chromeos::UserManager.
+
+ // TODO(jamescook): Initialize ExtensionsClient and ExtensionsBrowserClient.
+
+ // Initialize our "profile" equivalent.
+ browser_context_.reset(new AppShellBrowserContext);
+
+ // TODO(jamescook): Initialize policy::ProfilePolicyConnector.
+ // TODO(jamescook): Initialize ExtensionSystem and InitForRegularProfile.
+ // TODO(jamescook): CreateBrowserContextServices using
+ // BrowserContextDependencyManager.
+
+ CreateRootWindow();
- // TODO(jamescook): Create an apps::ShellWindow here. For now, create a
- // window with a WebView just to ensure that the content module is properly
- // initialized.
- ShowWebViewWindow(browser_context_.get(),
- wm_test_helper_->root_window()->window());
+ const std::string kAppSwitch = "app";
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(kAppSwitch)) {
+ base::FilePath app_dir(command_line->GetSwitchValueNative(kAppSwitch));
+ LoadAndLaunchApp(app_dir);
+ } else {
+ // TODO(jamescook): Create an apps::ShellWindow here. For now, create a
+ // window with a WebView just to ensure that the content module is properly
+ // initialized.
+ ShowWebViewWindow(browser_context_.get(),
+ wm_test_helper_->root_window()->window());
+ }
}
bool AppShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
diff --git a/apps/shell/app_shell_browser_main_parts.h b/apps/shell/app_shell_browser_main_parts.h
index 896760c..f8b05c3 100644
--- a/apps/shell/app_shell_browser_main_parts.h
+++ b/apps/shell/app_shell_browser_main_parts.h
@@ -10,6 +10,10 @@
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_main_parts.h"
+namespace base {
+class FilePath;
+}
+
namespace content {
class ShellBrowserContext;
struct MainFunctionParams;
@@ -25,6 +29,8 @@ class WMTestHelper;
namespace apps {
+class AppShellBrowserContext;
+
// Handles initialization of AppShell.
class AppShellBrowserMainParts : public content::BrowserMainParts {
public:
@@ -32,20 +38,27 @@ class AppShellBrowserMainParts : public content::BrowserMainParts {
const content::MainFunctionParams& parameters);
virtual ~AppShellBrowserMainParts();
+ AppShellBrowserContext* browser_context() {
+ return browser_context_.get();
+ }
+
+ // Creates the window that hosts the apps.
+ void CreateRootWindow();
+
+ // Launches an application from a directory.
+ void LoadAndLaunchApp(const base::FilePath& app_dir);
+
// BrowserMainParts overrides.
virtual void PreEarlyInitialization() OVERRIDE;
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;
- content::ShellBrowserContext* browser_context() {
- return browser_context_.get();
- }
-
private:
- scoped_ptr<content::ShellBrowserContext> browser_context_;
+ scoped_ptr<AppShellBrowserContext> browser_context_;
// Enable a minimal set of views::corewm to be initialized.
scoped_ptr<wm::WMTestHelper> wm_test_helper_;
diff --git a/apps/shell/app_shell_content_browser_client.cc b/apps/shell/app_shell_content_browser_client.cc
index 964d0cf..a5eedbd 100644
--- a/apps/shell/app_shell_content_browser_client.cc
+++ b/apps/shell/app_shell_content_browser_client.cc
@@ -4,6 +4,7 @@
#include "apps/shell/app_shell_content_browser_client.h"
+#include "apps/shell/app_shell_browser_context.h"
#include "apps/shell/app_shell_browser_main_parts.h"
#include "content/shell/browser/shell_browser_context.h"
@@ -27,9 +28,8 @@ AppShellContentBrowserClient::CreateRequestContext(
content::BrowserContext* content_browser_context,
content::ProtocolHandlerMap* protocol_handlers) {
// TODO(jamescook): Should this be an off-the-record context?
- content::ShellBrowserContext* shell_browser_context =
- browser_main_parts_->browser_context();
- return shell_browser_context->CreateRequestContext(protocol_handlers);
+ return browser_main_parts_->browser_context()->CreateRequestContext(
+ protocol_handlers);
}
} // namespace apps