diff options
author | oshima <oshima@chromium.org> | 2014-09-10 19:15:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-11 03:07:10 +0000 |
commit | be9f162893a0ed54ee4c8f5fac3b8e2a113bea02 (patch) | |
tree | 4022c88c9144880bee1abd985e0040d5adf895c7 /athena | |
parent | f1d241a504fb4cdc18501ffb7b0369aa0135cc9d (diff) | |
download | chromium_src-be9f162893a0ed54ee4c8f5fac3b8e2a113bea02.zip chromium_src-be9f162893a0ed54ee4c8f5fac3b8e2a113bea02.tar.gz chromium_src-be9f162893a0ed54ee4c8f5fac3b8e2a113bea02.tar.bz2 |
V2 app support step2 : Use NativeAppWindow for Activity's window.
This CL removes redundant widget created by Activity, and use NativeAppWindow instead.
Activity APIs needs to some cleanup and I'll look into it once hashimoto-san finished app_window transition.
step3 will replace ChromeAppNativeWindowViews with athena's impl.
BUG=410448
Review URL: https://codereview.chromium.org/558243002
Cr-Commit-Position: refs/heads/master@{#294297}
Diffstat (limited to 'athena')
22 files changed, 112 insertions, 38 deletions
diff --git a/athena/activity/activity_view_manager_impl.cc b/athena/activity/activity_view_manager_impl.cc index 76d40d4..240e5bd 100644 --- a/athena/activity/activity_view_manager_impl.cc +++ b/athena/activity/activity_view_manager_impl.cc @@ -24,10 +24,12 @@ typedef std::map<Activity*, views::Widget*> ActivityWidgetMap; views::Widget* CreateWidget(Activity* activity) { ActivityViewModel* view_model = activity->GetActivityViewModel(); - views::Widget* widget = new views::Widget; + views::Widget* widget = view_model->CreateWidget(); + if (widget) + return widget; + widget = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); params.delegate = new ActivityWidgetDelegate(view_model); - params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; widget->Init(params); return widget; } diff --git a/athena/activity/public/activity_factory.h b/athena/activity/public/activity_factory.h index a8ca4af..e69ee7a 100644 --- a/athena/activity/public/activity_factory.h +++ b/athena/activity/public/activity_factory.h @@ -17,6 +17,10 @@ class AppWindow; class ShellAppWindow; } +namespace views { +class WebView; +} + namespace athena { class Activity; @@ -46,8 +50,10 @@ class ATHENA_EXPORT ActivityFactory { virtual Activity* CreateAppActivity(extensions::ShellAppWindow* app_window, const std::string& id) = 0; - // Create an activity of an app with |app_window| for chrome environment. - virtual Activity* CreateAppActivity(extensions::AppWindow* app_window) = 0; + // Create an activity of an app with |app_window| for chrome environment and + // |web_view| that will host the content. + virtual Activity* CreateAppActivity(extensions::AppWindow* app_window, + views::WebView* web_view) = 0; }; } // namespace athena diff --git a/athena/activity/public/activity_view_model.h b/athena/activity/public/activity_view_model.h index 12b8ced..3406244 100644 --- a/athena/activity/public/activity_view_model.h +++ b/athena/activity/public/activity_view_model.h @@ -16,6 +16,7 @@ class ImageSkia; namespace views { class View; +class Widget; } namespace athena { @@ -46,6 +47,10 @@ class ATHENA_EXPORT ActivityViewModel { // be deleted by the resource manager. virtual views::View* GetContentsView() = 0; + // Creates a custom widget for the activity. Returns NULL to use default + // implementation. + virtual views::Widget* CreateWidget() = 0; + // This gets called before the Activity gets (partially) thrown out of memory // to create a preview image of the activity. Note that even if this function // gets called, |GetOverviewModeImage()| could still return an empty image. diff --git a/athena/athena.gyp b/athena/athena.gyp index 16ccb70..22f1adb 100644 --- a/athena/athena.gyp +++ b/athena/athena.gyp @@ -187,6 +187,7 @@ 'type': 'static_library', 'dependencies': [ '../extensions/shell/app_shell.gyp:app_shell_lib', + '../skia/skia.gyp:skia', ], 'sources': [ 'content/shell/content_activity_factory.cc', diff --git a/athena/content/app_activity.cc b/athena/content/app_activity.cc index 2c7dc8b..c87ed61 100644 --- a/athena/content/app_activity.cc +++ b/athena/content/app_activity.cc @@ -116,10 +116,7 @@ bool AppActivity::UsesFrame() const { views::View* AppActivity::GetContentsView() { if (!web_view_) { - // TODO(oshima): use apps::NativeAppWindowViews - content::WebContents* web_contents = GetWebContents(); - web_view_ = new views::WebView(web_contents->GetBrowserContext()); - web_view_->SetWebContents(web_contents); + web_view_ = GetWebView(); // Make sure the content gets properly shown. if (current_state_ == ACTIVITY_VISIBLE) { MakeVisible(); @@ -129,7 +126,6 @@ views::View* AppActivity::GetContentsView() { // If not previously specified, we change the state now to invisible.. SetCurrentState(ACTIVITY_INVISIBLE); } - Observe(web_contents); RegisterActivity(); } return web_view_; @@ -174,7 +170,7 @@ void AppActivity::DidUpdateFaviconURL( // Note: This should only get called once for an |app_window| of the // |activity|. void AppActivity::RegisterActivity() { - content::WebContents* web_contents = GetWebContents(); + content::WebContents* web_contents = web_view_->GetWebContents(); AppRegistry* app_registry = AppRegistry::Get(); // Get the application's registry. app_activity_registry_ = app_registry->GetAppActivityRegistry( diff --git a/athena/content/app_activity.h b/athena/content/app_activity.h index 3c69596..c721446 100644 --- a/athena/content/app_activity.h +++ b/athena/content/app_activity.h @@ -10,10 +10,6 @@ #include "content/public/browser/web_contents_observer.h" #include "ui/gfx/image/image_skia.h" -namespace contents { -class WebContents; -} - namespace views { class WebView; } @@ -57,7 +53,7 @@ class AppActivity : public Activity, virtual void DidUpdateFaviconURL( const std::vector<content::FaviconURL>& candidates) OVERRIDE; - virtual content::WebContents* GetWebContents() = 0; + virtual views::WebView* GetWebView() = 0; private: // Register this activity with its application. diff --git a/athena/content/app_activity_proxy.cc b/athena/content/app_activity_proxy.cc index bf08a59..491aaef 100644 --- a/athena/content/app_activity_proxy.cc +++ b/athena/content/app_activity_proxy.cc @@ -84,6 +84,10 @@ views::View* AppActivityProxy::GetContentsView() { return view_; } +views::Widget* AppActivityProxy::CreateWidget() { + return NULL; +} + void AppActivityProxy::CreateOverviewModeImage() { // Nothing we can do here. } diff --git a/athena/content/app_activity_proxy.h b/athena/content/app_activity_proxy.h index 6ea263f..0d18d7b 100644 --- a/athena/content/app_activity_proxy.h +++ b/athena/content/app_activity_proxy.h @@ -43,6 +43,7 @@ class AppActivityProxy : public Activity, virtual base::string16 GetTitle() const OVERRIDE; virtual bool UsesFrame() const OVERRIDE; virtual views::View* GetContentsView() OVERRIDE; + virtual views::Widget* CreateWidget() OVERRIDE; virtual void CreateOverviewModeImage() OVERRIDE; virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE; virtual void PrepareContentsForOverview() OVERRIDE; diff --git a/athena/content/app_activity_unittest.cc b/athena/content/app_activity_unittest.cc index 6c28795..8afc2fc 100644 --- a/athena/content/app_activity_unittest.cc +++ b/athena/content/app_activity_unittest.cc @@ -68,7 +68,7 @@ class TestAppActivity : public AppActivity { } // AppActivity: - virtual content::WebContents* GetWebContents() OVERRIDE { return NULL; } + virtual views::WebView* GetWebView() OVERRIDE { return NULL; } // ActivityViewModel: virtual void Init() OVERRIDE {} @@ -76,6 +76,7 @@ class TestAppActivity : public AppActivity { virtual base::string16 GetTitle() const OVERRIDE { return title_; } virtual bool UsesFrame() const OVERRIDE { return true; } virtual views::View* GetContentsView() OVERRIDE { return view_; } + virtual views::Widget* CreateWidget() OVERRIDE { return NULL; } virtual void CreateOverviewModeImage() OVERRIDE {} private: diff --git a/athena/content/chrome/content_activity_factory.cc b/athena/content/chrome/content_activity_factory.cc index 53ca853..a8ba6d5 100644 --- a/athena/content/chrome/content_activity_factory.cc +++ b/athena/content/chrome/content_activity_factory.cc @@ -6,6 +6,7 @@ #include "athena/content/app_activity.h" #include "extensions/browser/app_window/app_window.h" +#include "ui/views/controls/webview/webview.h" // TODO(oshima): Consolidate this and app shell implementation once // crbug.com/403726 is fixed. @@ -14,19 +15,32 @@ namespace { class ChromeAppActivity : public AppActivity { public: - explicit ChromeAppActivity(extensions::AppWindow* app_window) - : AppActivity(app_window->extension_id()), app_window_(app_window) {} + ChromeAppActivity(extensions::AppWindow* app_window, views::WebView* web_view) + : AppActivity(app_window->extension_id()), + app_window_(app_window), + web_view_(web_view) { + DCHECK_EQ(app_window->web_contents(), web_view->GetWebContents()); + Observe(app_window_->web_contents()); + } private: virtual ~ChromeAppActivity() {} - // AppActivity: - virtual content::WebContents* GetWebContents() OVERRIDE { - return app_window_->web_contents(); + // ActivityViewModel overrides: + virtual views::Widget* CreateWidget() OVERRIDE { + // This is necessary to register apps. + // TODO(oshima): This will become unnecessary once the + // shell_app_window is removed. + GetContentsView(); + return web_view_->GetWidget(); } + // AppActivity: + virtual views::WebView* GetWebView() OVERRIDE { return web_view_; } + // Not owned. extensions::AppWindow* app_window_; + views::WebView* web_view_; DISALLOW_COPY_AND_ASSIGN(ChromeAppActivity); }; @@ -34,8 +48,9 @@ class ChromeAppActivity : public AppActivity { } // namespace Activity* ContentActivityFactory::CreateAppActivity( - extensions::AppWindow* app_window) { - return new ChromeAppActivity(app_window); + extensions::AppWindow* app_window, + views::WebView* web_view) { + return new ChromeAppActivity(app_window, web_view); } Activity* ContentActivityFactory::CreateAppActivity( diff --git a/athena/content/content_activity_factory.h b/athena/content/content_activity_factory.h index a00d6db..d3a23ba 100644 --- a/athena/content/content_activity_factory.h +++ b/athena/content/content_activity_factory.h @@ -21,8 +21,8 @@ class ContentActivityFactory : public ActivityFactory { const GURL& url) OVERRIDE; virtual Activity* CreateAppActivity(extensions::ShellAppWindow* app_window, const std::string& app_id) OVERRIDE; - virtual Activity* CreateAppActivity( - extensions::AppWindow* app_window) OVERRIDE; + virtual Activity* CreateAppActivity(extensions::AppWindow* app_window, + views::WebView* web_view) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(ContentActivityFactory); diff --git a/athena/content/shell/content_activity_factory.cc b/athena/content/shell/content_activity_factory.cc index 03e637d..d87c81e 100644 --- a/athena/content/shell/content_activity_factory.cc +++ b/athena/content/shell/content_activity_factory.cc @@ -15,7 +15,8 @@ Activity* ContentActivityFactory::CreateAppActivity( } Activity* ContentActivityFactory::CreateAppActivity( - extensions::AppWindow* app_window) { + extensions::AppWindow* app_window, + views::WebView* web_view) { return NULL; } diff --git a/athena/content/shell/shell_app_activity.cc b/athena/content/shell/shell_app_activity.cc index 7e414e7..d8a5077 100644 --- a/athena/content/shell/shell_app_activity.cc +++ b/athena/content/shell/shell_app_activity.cc @@ -4,7 +4,9 @@ #include "athena/content/shell/shell_app_activity.h" +#include "content/public/browser/web_contents.h" #include "extensions/shell/browser/shell_app_window.h" +#include "ui/views/controls/webview/webview.h" namespace athena { @@ -16,8 +18,18 @@ ShellAppActivity::ShellAppActivity(extensions::ShellAppWindow* app_window, ShellAppActivity::~ShellAppActivity() { } -content::WebContents* ShellAppActivity::GetWebContents() { - return shell_app_window_->GetAssociatedWebContents(); +views::Widget* ShellAppActivity::CreateWidget() { + return NULL; // Use default widget. +} + +views::WebView* ShellAppActivity::GetWebView() { + content::WebContents* web_contents = + shell_app_window_->GetAssociatedWebContents(); + views::WebView* web_view = + new views::WebView(web_contents->GetBrowserContext()); + web_view->SetWebContents(web_contents); + Observe(web_contents); + return web_view; } } // namespace athena diff --git a/athena/content/shell/shell_app_activity.h b/athena/content/shell/shell_app_activity.h index f91c555..336293e 100644 --- a/athena/content/shell/shell_app_activity.h +++ b/athena/content/shell/shell_app_activity.h @@ -22,8 +22,11 @@ class ShellAppActivity : public AppActivity { virtual ~ShellAppActivity(); private: + // ActivityViewModel: + virtual views::Widget* CreateWidget() OVERRIDE; + // AppActivity: - virtual content::WebContents* GetWebContents() OVERRIDE; + virtual views::WebView* GetWebView() OVERRIDE; scoped_ptr<extensions::ShellAppWindow> shell_app_window_; diff --git a/athena/content/web_activity.cc b/athena/content/web_activity.cc index 50d71c9..6d8b217 100644 --- a/athena/content/web_activity.cc +++ b/athena/content/web_activity.cc @@ -472,6 +472,10 @@ views::View* WebActivity::GetContentsView() { return web_view_; } +views::Widget* WebActivity::CreateWidget() { + return NULL; // Use default widget. +} + void WebActivity::CreateOverviewModeImage() { // TODO(skuhne): Create an overview. } diff --git a/athena/content/web_activity.h b/athena/content/web_activity.h index 6f8f9a9..4200e84 100644 --- a/athena/content/web_activity.h +++ b/athena/content/web_activity.h @@ -51,6 +51,7 @@ class WebActivity : public Activity, virtual base::string16 GetTitle() const OVERRIDE; virtual bool UsesFrame() const OVERRIDE; virtual views::View* GetContentsView() OVERRIDE; + virtual views::Widget* CreateWidget() OVERRIDE; virtual void CreateOverviewModeImage() OVERRIDE; virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE; virtual void PrepareContentsForOverview() OVERRIDE; diff --git a/athena/extensions/chrome/athena_apps_client.cc b/athena/extensions/chrome/athena_apps_client.cc index 37a0531..cc0f67a 100644 --- a/athena/extensions/chrome/athena_apps_client.cc +++ b/athena/extensions/chrome/athena_apps_client.cc @@ -17,6 +17,24 @@ #include "extensions/common/extension.h" namespace athena { +namespace { + +// A short term hack to get WebView from ChromeNativeAppWindowViews. +// TODO(oshima): Implement athena's NativeAppWindow. +class AthenaNativeAppWindowViews : public ChromeNativeAppWindowViews { + public: + AthenaNativeAppWindowViews() {} + virtual ~AthenaNativeAppWindowViews() {} + + views::WebView* GetWebView() { + return web_view(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(AthenaNativeAppWindowViews); +}; + +} // namespace AthenaAppsClient::AthenaAppsClient() { } @@ -41,12 +59,12 @@ extensions::AppWindow* AthenaAppsClient::CreateAppWindow( extensions::NativeAppWindow* AthenaAppsClient::CreateNativeAppWindow( extensions::AppWindow* app_window, const extensions::AppWindow::CreateParams& params) { - // TODO(oshima): Implement athena's native appwindow. - ChromeNativeAppWindowViews* window = new ChromeNativeAppWindowViews; - window->Init(app_window, params); - athena::ActivityManager::Get()->AddActivity( - athena::ActivityFactory::Get()->CreateAppActivity(app_window)); - return window; + AthenaNativeAppWindowViews* native_window = new AthenaNativeAppWindowViews; + native_window->Init(app_window, params); + Activity* app_activity = ActivityFactory::Get()->CreateAppActivity( + app_window, native_window->GetWebView()); + ActivityManager::Get()->AddActivity(app_activity); + return native_window; } void AthenaAppsClient::IncrementKeepAliveCount() { diff --git a/athena/resource_manager/resource_manager_unittest.cc b/athena/resource_manager/resource_manager_unittest.cc index 4d49f0c..ccc89f8 100644 --- a/athena/resource_manager/resource_manager_unittest.cc +++ b/athena/resource_manager/resource_manager_unittest.cc @@ -53,6 +53,7 @@ class TestActivity : public Activity, virtual base::string16 GetTitle() const OVERRIDE { return title_; } virtual bool UsesFrame() const OVERRIDE { return true; } virtual views::View* GetContentsView() OVERRIDE { return view_; } + virtual views::Widget* CreateWidget() OVERRIDE { return NULL; } virtual void CreateOverviewModeImage() OVERRIDE {} virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE { return image_; } virtual void PrepareContentsForOverview() OVERRIDE {} diff --git a/athena/test/sample_activity.cc b/athena/test/sample_activity.cc index 7c052a5..10bf263 100644 --- a/athena/test/sample_activity.cc +++ b/athena/test/sample_activity.cc @@ -73,6 +73,10 @@ views::View* SampleActivity::GetContentsView() { return contents_view_; } +views::Widget* SampleActivity::CreateWidget() { + return NULL; +} + void SampleActivity::CreateOverviewModeImage() { } diff --git a/athena/test/sample_activity.h b/athena/test/sample_activity.h index 8658e0b..01706ca 100644 --- a/athena/test/sample_activity.h +++ b/athena/test/sample_activity.h @@ -36,6 +36,7 @@ class SampleActivity : public Activity, virtual base::string16 GetTitle() const OVERRIDE; virtual bool UsesFrame() const OVERRIDE; virtual views::View* GetContentsView() OVERRIDE; + virtual views::Widget* CreateWidget() OVERRIDE; virtual void CreateOverviewModeImage() OVERRIDE; virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE; virtual void PrepareContentsForOverview() OVERRIDE; diff --git a/athena/test/sample_activity_factory.cc b/athena/test/sample_activity_factory.cc index 92fa71a5..8fb0bd2 100644 --- a/athena/test/sample_activity_factory.cc +++ b/athena/test/sample_activity_factory.cc @@ -45,7 +45,9 @@ Activity* SampleActivityFactory::CreateAppActivity( } Activity* SampleActivityFactory::CreateAppActivity( - extensions::AppWindow* app_window) { + extensions::AppWindow* app_window, + views::WebView* web_view) { + DCHECK(!web_view); return new SampleActivity( kDefaultAppColor, kDefaultAppContentColor, base::UTF8ToUTF16("App")); } diff --git a/athena/test/sample_activity_factory.h b/athena/test/sample_activity_factory.h index 7c1764b6..af4a5be 100644 --- a/athena/test/sample_activity_factory.h +++ b/athena/test/sample_activity_factory.h @@ -22,8 +22,8 @@ class SampleActivityFactory : public ActivityFactory { const GURL& url) OVERRIDE; virtual Activity* CreateAppActivity(extensions::ShellAppWindow* app_window, const std::string& app_id) OVERRIDE; - virtual Activity* CreateAppActivity( - extensions::AppWindow* app_window) OVERRIDE; + virtual Activity* CreateAppActivity(extensions::AppWindow* app_window, + views::WebView* web_view) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(SampleActivityFactory); |