Skip to content

Commit

Permalink
Support WebView in ash.
Browse files Browse the repository at this point in the history
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10054038

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132063 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed Apr 12, 2012
1 parent d78e2b2 commit fa4a458
Show file tree
Hide file tree
Showing 19 changed files with 1,075 additions and 109 deletions.
19 changes: 19 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@
'../base/base.gyp:base',
'../base/base.gyp:base_i18n',
'../chrome/chrome_resources.gyp:packed_resources',
'../content/content.gyp:content_shell_lib',
'../content/content.gyp:content',
'../skia/skia.gyp:skia',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc',
Expand All @@ -438,6 +440,12 @@
'sources': [
'shell/app_list.cc',
'shell/bubble.cc',
'shell/content_client/shell_browser_main_parts.cc',
'shell/content_client/shell_browser_main_parts.h',
'shell/content_client/shell_content_browser_client.cc',
'shell/content_client/shell_content_browser_client.h',
'shell/content_client/shell_main_delegate.cc',
'shell/content_client/shell_main_delegate.h',
'shell/example_factory.h',
'shell/launcher_delegate_impl.cc',
'shell/launcher_delegate_impl.h',
Expand All @@ -460,9 +468,20 @@
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources_standard/ui_resources_standard.rc',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc',
'../content/app/startup_helper_win.cc',
'../ui/views/test/test_views_delegate.cc',
],
'conditions': [
['OS=="win"', {
'msvs_settings': {
'VCLinkerTool': {
'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS
},
},
'dependencies': [
'../sandbox/sandbox.gyp:sandbox',
],
}],
['OS=="mac"', {
'product_name': 'AuraShell',
'mac_bundle': 1,
Expand Down
12 changes: 12 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Monitor;
class RootWindow;
class Window;
}
namespace content {
class BrowserContext;
}

namespace gfx {
class Point;
class Rect;
Expand Down Expand Up @@ -251,6 +255,11 @@ class ASH_EXPORT Shell {
return shadow_controller_.get();
}

content::BrowserContext* browser_context() { return browser_context_; }
void set_browser_context(content::BrowserContext* browser_context) {
browser_context_ = browser_context;
}

private:
FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, MouseEventCursors);
FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, TransformActivate);
Expand Down Expand Up @@ -348,6 +357,9 @@ class ASH_EXPORT Shell {
// |status_widget_|).
scoped_ptr<SystemTray> tray_;

// Used by ash/shell.
content::BrowserContext* browser_context_;

DISALLOW_COPY_AND_ASSIGN(Shell);
};

Expand Down
4 changes: 4 additions & 0 deletions ash/shell/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include_rules = [
"+content",
"+sandbox",
]
3 changes: 2 additions & 1 deletion ash/shell/app_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class WindowTypeLauncherItem : public ash::AppListItemModel {
case EXAMPLES_WINDOW: {
#if !defined(OS_MACOSX)
views::examples::ShowExamplesWindow(
views::examples::DO_NOTHING_ON_CLOSE, NULL);
views::examples::DO_NOTHING_ON_CLOSE,
ash::Shell::GetInstance()->browser_context());
#endif
break;
}
Expand Down
3 changes: 3 additions & 0 deletions ash/shell/content_client/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+content",
]
120 changes: 120 additions & 0 deletions ash/shell/content_client/shell_browser_main_parts.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) 2012 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 "ash/shell/content_client/shell_browser_main_parts.h"

#include "ash/shell/shell_delegate_impl.h"
#include "ash/shell/window_watcher.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/common/content_switches.h"
#include "content/shell/shell.h"
#include "content/shell/shell_browser_context.h"
#include "content/shell/shell_devtools_delegate.h"
#include "content/shell/shell_switches.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_module.h"
#include "ui/aura/client/stacking_client.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/test/compositor_test_support.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/focus/accelerator_handler.h"

namespace ash {
namespace shell {
void InitWindowTypeLauncher();

namespace {
class ShellViewsDelegate : public views::TestViewsDelegate {
public:
ShellViewsDelegate() {}
virtual ~ShellViewsDelegate() {}

// Overridden from views::TestViewsDelegate:
virtual views::NonClientFrameView* CreateDefaultNonClientFrameView(
views::Widget* widget) OVERRIDE {
return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(widget);
}
bool UseTransparentWindows() const OVERRIDE {
// Ash uses transparent window frames.
return true;
}

private:
DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate);
};

} // namespace

ShellBrowserMainParts::ShellBrowserMainParts(
const content::MainFunctionParams& parameters)
: BrowserMainParts(),
devtools_delegate_(NULL) {
}

ShellBrowserMainParts::~ShellBrowserMainParts() {
}

#if !defined(OS_MACOSX)
void ShellBrowserMainParts::PreMainMessageLoopStart() {
}
#endif

int ShellBrowserMainParts::PreCreateThreads() {
return 0;
}

void ShellBrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(new content::ShellBrowserContext);

// A ViewsDelegate is required.
if (!views::ViewsDelegate::views_delegate)
views::ViewsDelegate::views_delegate = new ShellViewsDelegate;

ash::shell::ShellDelegateImpl* delegate = new ash::shell::ShellDelegateImpl;
ash::Shell::CreateInstance(delegate);
ash::Shell::GetInstance()->set_browser_context(browser_context_.get());

window_watcher_.reset(new ash::shell::WindowWatcher);
delegate->SetWatcher(window_watcher_.get());

ash::shell::InitWindowTypeLauncher();

ash::Shell::GetRootWindow()->ShowRootWindow();
}

void ShellBrowserMainParts::PostMainMessageLoopRun() {
if (devtools_delegate_)
devtools_delegate_->Stop();
browser_context_.reset();

window_watcher_.reset();
ash::Shell::DeleteInstance();
aura::Env::DeleteInstance();
}

bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
MessageLoopForUI::current()->Run();
return true;
}

ui::Clipboard* ShellBrowserMainParts::GetClipboard() {
if (!clipboard_.get())
clipboard_.reset(new ui::Clipboard());
return clipboard_.get();
}

} // namespace shell
} // namespace ash
77 changes: 77 additions & 0 deletions ash/shell/content_client/shell_browser_main_parts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2012 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 ASH_SHELL_CONTENT_CLIENT_EXAMPLES_BROWSER_MAIN_PARTS_H_
#define ASH_SHELL_CONTENT_CLIENT_EXAMPLES_BROWSER_MAIN_PARTS_H_
#pragma once

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_main_parts.h"

namespace base {
class Thread;
}

namespace ui {
class Clipboard;
}

namespace content {
class ShellBrowserContext;
class ShellDevToolsDelegate;
struct MainFunctionParams;
}

namespace views {
class ViewsDelegate;
}

namespace ash {
namespace shell {

class WindowWatcher;

class ShellBrowserMainParts : public content::BrowserMainParts {
public:
explicit ShellBrowserMainParts(
const content::MainFunctionParams& parameters);
virtual ~ShellBrowserMainParts();

// Overridden from content::BrowserMainParts:
virtual void PreEarlyInitialization() OVERRIDE {}
virtual void PostEarlyInitialization() OVERRIDE {}
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void PostMainMessageLoopStart() OVERRIDE {}
virtual void ToolkitInitialized() OVERRIDE {}
virtual int PreCreateThreads() OVERRIDE;
virtual void PreMainMessageLoopRun() OVERRIDE;
virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
virtual void PostMainMessageLoopRun() OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE {}

ui::Clipboard* GetClipboard();
content::ShellDevToolsDelegate* devtools_delegate() {
return devtools_delegate_;
}

content::ShellBrowserContext* browser_context() {
return browser_context_.get();
}

private:
scoped_ptr<content::ShellBrowserContext> browser_context_;

scoped_ptr<ui::Clipboard> clipboard_;
content::ShellDevToolsDelegate* devtools_delegate_;
scoped_ptr<views::ViewsDelegate> views_delegate_;
scoped_ptr<ash::shell::WindowWatcher> window_watcher_;

DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts);
};

} // namespace shell
} // namespace ash

#endif // ASH_SHELL_CONTENT_CLIENT_EXAMPLES_BROWSER_MAIN_PARTS_H_
Loading

0 comments on commit fa4a458

Please sign in to comment.