summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2014-09-24 14:28:50 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-24 21:29:09 +0000
commitc856b9bf12c634b7b5f2879761fb8a63cc5f0822 (patch)
treed2decdd2d4c8c546d9d4079c81f7897353536ff7
parent8d01729a29f61388655fe8abbbff506697777fa5 (diff)
downloadchromium_src-c856b9bf12c634b7b5f2879761fb8a63cc5f0822.zip
chromium_src-c856b9bf12c634b7b5f2879761fb8a63cc5f0822.tar.gz
chromium_src-c856b9bf12c634b7b5f2879761fb8a63cc5f0822.tar.bz2
Do not show the activity widget in ActivityManager::AddActivity
* Instead, show it explicitly on caller side. This is necessary as the extensions system controls the app window's visibility. Remove ActivityViewManager Instead of keeping activity -> widget map, use views::Widget::GetWidgetForNativeWindow BUG=417017 TEST=ActivityManagerTest.Basic Review URL: https://codereview.chromium.org/596623005 Cr-Commit-Position: refs/heads/master@{#296524}
-rw-r--r--athena/activity/activity.cc9
-rw-r--r--athena/activity/activity_manager_impl.cc66
-rw-r--r--athena/activity/activity_manager_impl.h7
-rw-r--r--athena/activity/activity_manager_unittest.cc5
-rw-r--r--athena/activity/activity_view_manager_impl.cc120
-rw-r--r--athena/activity/public/activity.h7
-rw-r--r--athena/activity/public/activity_view_manager.h33
-rw-r--r--athena/athena.gyp2
-rw-r--r--athena/content/web_activity.cc6
-rw-r--r--athena/extensions/athena_app_delegate_base.cc3
-rw-r--r--athena/main/placeholder.cc5
-rw-r--r--athena/main/url_search_provider.cc4
-rw-r--r--athena/resource_manager/resource_manager_impl.cc3
13 files changed, 94 insertions, 176 deletions
diff --git a/athena/activity/activity.cc b/athena/activity/activity.cc
index 1f23837..f09428d 100644
--- a/athena/activity/activity.cc
+++ b/athena/activity/activity.cc
@@ -5,10 +5,19 @@
#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_manager.h"
+#include "ui/views/widget/widget.h"
namespace athena {
// static
+void Activity::Show(Activity* activity) {
+ views::Widget* widget =
+ views::Widget::GetWidgetForNativeWindow(activity->GetWindow());
+ DCHECK(widget);
+ widget->Show();
+}
+
+// static
void Activity::Delete(Activity* activity) {
ActivityManager::Get()->RemoveActivity(activity);
delete activity;
diff --git a/athena/activity/activity_manager_impl.cc b/athena/activity/activity_manager_impl.cc
index b0074cb..7313b24 100644
--- a/athena/activity/activity_manager_impl.cc
+++ b/athena/activity/activity_manager_impl.cc
@@ -6,11 +6,13 @@
#include <algorithm>
+#include "athena/activity/activity_widget_delegate.h"
#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_manager_observer.h"
-#include "athena/activity/public/activity_view_manager.h"
+#include "athena/activity/public/activity_view_model.h"
#include "base/logging.h"
#include "base/observer_list.h"
+#include "ui/views/widget/widget.h"
namespace athena {
@@ -18,6 +20,25 @@ namespace {
ActivityManager* instance = NULL;
+views::Widget* CreateWidget(Activity* activity) {
+ ActivityViewModel* view_model = activity->GetActivityViewModel();
+ 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);
+ widget->Init(params);
+ activity->GetActivityViewModel()->Init();
+ return widget;
+}
+
+views::Widget* GetWidget(Activity* activity) {
+ CHECK(activity);
+ CHECK(activity->GetWindow());
+ return views::Widget::GetWidgetForNativeWindow(activity->GetWindow());
+}
+
} // namespace
ActivityManagerImpl::ActivityManagerImpl() {
@@ -37,8 +58,8 @@ void ActivityManagerImpl::AddActivity(Activity* activity) {
CHECK(activities_.end() ==
std::find(activities_.begin(), activities_.end(), activity));
activities_.push_back(activity);
- ActivityViewManager* manager = ActivityViewManager::Get();
- manager->AddActivity(activity);
+ views::Widget* widget = CreateWidget(activity);
+ widget->AddObserver(this);
FOR_EACH_OBSERVER(ActivityManagerObserver,
observers_,
OnActivityStarted(activity));
@@ -47,19 +68,21 @@ void ActivityManagerImpl::AddActivity(Activity* activity) {
void ActivityManagerImpl::RemoveActivity(Activity* activity) {
std::vector<Activity*>::iterator find =
std::find(activities_.begin(), activities_.end(), activity);
- FOR_EACH_OBSERVER(ActivityManagerObserver,
- observers_,
- OnActivityEnding(activity));
+ DCHECK(find != activities_.end());
if (find != activities_.end()) {
+ FOR_EACH_OBSERVER(
+ ActivityManagerObserver, observers_, OnActivityEnding(activity));
activities_.erase(find);
- ActivityViewManager* manager = ActivityViewManager::Get();
- manager->RemoveActivity(activity);
+ views::Widget* widget = GetWidget(activity);
+ widget->RemoveObserver(this);
+ widget->Close();
}
}
void ActivityManagerImpl::UpdateActivity(Activity* activity) {
- ActivityViewManager* manager = ActivityViewManager::Get();
- manager->UpdateActivity(activity);
+ views::Widget* widget = GetWidget(activity);
+ widget->UpdateWindowIcon();
+ widget->UpdateWindowTitle();
}
void ActivityManagerImpl::AddObserver(ActivityManagerObserver* observer) {
@@ -70,10 +93,28 @@ void ActivityManagerImpl::RemoveObserver(ActivityManagerObserver* observer) {
observers_.RemoveObserver(observer);
}
+void ActivityManagerImpl::OnWidgetDestroying(views::Widget* widget) {
+ struct Matcher {
+ Matcher(aura::Window* w) : window(w) {}
+
+ bool operator()(Activity* activity) {
+ return activity->GetWindow() == window;
+ }
+ aura::Window* window;
+ };
+ std::vector<Activity*>::iterator iter =
+ std::find_if(activities_.begin(),
+ activities_.end(),
+ Matcher(widget->GetNativeWindow()));
+ DCHECK(iter != activities_.end());
+ if (iter != activities_.end()) {
+ widget->RemoveObserver(this);
+ Activity::Delete(*iter);
+ }
+}
+
// static
ActivityManager* ActivityManager::Create() {
- ActivityViewManager::Create();
-
new ActivityManagerImpl();
CHECK(instance);
return instance;
@@ -86,7 +127,6 @@ ActivityManager* ActivityManager::Get() {
void ActivityManager::Shutdown() {
CHECK(instance);
delete instance;
- ActivityViewManager::Shutdown();
}
diff --git a/athena/activity/activity_manager_impl.h b/athena/activity/activity_manager_impl.h
index 35e627c..2e99be1 100644
--- a/athena/activity/activity_manager_impl.h
+++ b/athena/activity/activity_manager_impl.h
@@ -8,12 +8,14 @@
#include "base/macros.h"
#include "base/observer_list.h"
+#include "ui/views/widget/widget_observer.h"
namespace athena {
class ActivityManagerObserver;
-class ActivityManagerImpl : public ActivityManager {
+class ActivityManagerImpl : public ActivityManager,
+ public views::WidgetObserver {
public:
ActivityManagerImpl();
virtual ~ActivityManagerImpl();
@@ -27,6 +29,9 @@ class ActivityManagerImpl : public ActivityManager {
virtual void AddObserver(ActivityManagerObserver* observer) OVERRIDE;
virtual void RemoveObserver(ActivityManagerObserver* observer) OVERRIDE;
+ // views::WidgetObserver
+ virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
+
private:
std::vector<Activity*> activities_;
diff --git a/athena/activity/activity_manager_unittest.cc b/athena/activity/activity_manager_unittest.cc
index a2b4cb4..f24d1b5 100644
--- a/athena/activity/activity_manager_unittest.cc
+++ b/athena/activity/activity_manager_unittest.cc
@@ -20,6 +20,11 @@ TEST_F(ActivityManagerTest, Basic) {
NULL, base::string16(), GURL());
EXPECT_EQ(1, activity_manager->num_activities());
+ // Activity is not visible when created.
+ EXPECT_FALSE(activity1->GetWindow()->TargetVisibility());
+ Activity::Show(activity1);
+ EXPECT_TRUE(activity1->GetWindow()->TargetVisibility());
+
Activity* activity2 = athena::ActivityFactory::Get()->CreateWebActivity(
NULL, base::string16(), GURL());
EXPECT_EQ(2, activity_manager->num_activities());
diff --git a/athena/activity/activity_view_manager_impl.cc b/athena/activity/activity_view_manager_impl.cc
deleted file mode 100644
index 129822e..0000000
--- a/athena/activity/activity_view_manager_impl.cc
+++ /dev/null
@@ -1,120 +0,0 @@
-// 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 "athena/activity/public/activity_view_manager.h"
-
-#include <algorithm>
-#include <map>
-
-#include "athena/activity/activity_widget_delegate.h"
-#include "athena/activity/public/activity.h"
-#include "athena/activity/public/activity_manager.h"
-#include "athena/activity/public/activity_view_model.h"
-#include "athena/screen/public/screen_manager.h"
-#include "ui/aura/window.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_observer.h"
-
-namespace athena {
-namespace {
-
-typedef std::map<Activity*, views::Widget*> ActivityWidgetMap;
-
-views::Widget* CreateWidget(Activity* activity) {
- ActivityViewModel* view_model = activity->GetActivityViewModel();
- 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);
- widget->Init(params);
- return widget;
-}
-
-ActivityViewManager* instance = NULL;
-
-class ActivityViewManagerImpl : public ActivityViewManager,
- public views::WidgetObserver {
- public:
- ActivityViewManagerImpl() {
- CHECK(!instance);
- instance = this;
- }
-
- virtual ~ActivityViewManagerImpl() {
- CHECK_EQ(this, instance);
- instance = NULL;
- }
-
- // ActivityViewManager:
- virtual void AddActivity(Activity* activity) OVERRIDE {
- CHECK(activity_widgets_.end() == activity_widgets_.find(activity));
- views::Widget* container = CreateWidget(activity);
- container->AddObserver(this);
- activity_widgets_[activity] = container;
- container->Show();
- container->Activate();
- // Call the Activity model's initializer. It might re-order the activity
- // against others, which has to be done before before registering it to the
- // system.
- activity->GetActivityViewModel()->Init();
- }
-
- virtual void RemoveActivity(Activity* activity) OVERRIDE {
- ActivityWidgetMap::iterator find = activity_widgets_.find(activity);
- if (find != activity_widgets_.end()) {
- views::Widget* widget = find->second;
- widget->RemoveObserver(this);
- widget->Close();
- activity_widgets_.erase(activity);
- }
- }
-
- virtual void UpdateActivity(Activity* activity) OVERRIDE {
- ActivityWidgetMap::iterator find = activity_widgets_.find(activity);
- if (find != activity_widgets_.end()) {
- find->second->UpdateWindowIcon();
- find->second->UpdateWindowTitle();
- }
- }
-
- // views::WidgetObserver:
- virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE {
- for (ActivityWidgetMap::iterator iter = activity_widgets_.begin();
- iter != activity_widgets_.end();
- ++iter) {
- if (iter->second == widget) {
- Activity::Delete(iter->first);
- break;
- }
- }
- }
-
- private:
- ActivityWidgetMap activity_widgets_;
-
- DISALLOW_COPY_AND_ASSIGN(ActivityViewManagerImpl);
-};
-
-} // namespace
-
-// static
-ActivityViewManager* ActivityViewManager::Create() {
- new ActivityViewManagerImpl();
- CHECK(instance);
- return instance;
-}
-
-ActivityViewManager* ActivityViewManager::Get() {
- return instance;
-}
-
-void ActivityViewManager::Shutdown() {
- CHECK(instance);
- delete instance;
-}
-
-} // namespace athena
diff --git a/athena/activity/public/activity.h b/athena/activity/public/activity.h
index b26617a..bd7df61 100644
--- a/athena/activity/public/activity.h
+++ b/athena/activity/public/activity.h
@@ -62,7 +62,10 @@ class ATHENA_EXPORT Activity {
ACTIVITY_MEDIA_STATE_AUDIO_PLAYING // Audible audio is playing in activity.
};
- // Delete an activity.
+ // Shows and activates an activity.
+ static void Show(Activity* activity);
+
+ // Deletes an activity.
static void Delete(Activity* activity);
// The Activity retains ownership of the returned view-model.
@@ -82,6 +85,8 @@ class ATHENA_EXPORT Activity {
// Returns the window for the activity. This can be used to determine the
// stacking order of this activity against others.
+ // TODO(oshima): Consider returning base::Window window instead,
+ // which has Show/ShowInactive and other control methods.
virtual aura::Window* GetWindow() = 0;
protected:
diff --git a/athena/activity/public/activity_view_manager.h b/athena/activity/public/activity_view_manager.h
deleted file mode 100644
index 6ca8b31..0000000
--- a/athena/activity/public/activity_view_manager.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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 ATHENA_ACTIVITY_PUBLIC_ACTIVITY_VIEW_MANAGER_H_
-#define ATHENA_ACTIVITY_PUBLIC_ACTIVITY_VIEW_MANAGER_H_
-
-#include "athena/athena_export.h"
-
-namespace athena {
-
-class Activity;
-
-// Manages the views for the activities.
-class ATHENA_EXPORT ActivityViewManager {
- public:
- static ActivityViewManager* Create();
- static ActivityViewManager* Get();
- static void Shutdown();
-
- virtual ~ActivityViewManager() {}
-
- // Adds/Removes a task.
- virtual void AddActivity(Activity* task) = 0;
- virtual void RemoveActivity(Activity* task) = 0;
-
- // Updates the UI when the task color/title changes.
- virtual void UpdateActivity(Activity* task) = 0;
-};
-
-} // namespace athena
-
-#endif // ATHENA_ACTIVITY_PUBLIC_ACTIVITY_VIEW_MANAGER_H_
diff --git a/athena/athena.gyp b/athena/athena.gyp
index 2044bc4b..1ef460c 100644
--- a/athena/athena.gyp
+++ b/athena/athena.gyp
@@ -39,7 +39,6 @@
'activity/activity_factory.cc',
'activity/activity_manager_impl.cc',
'activity/activity_manager_impl.h',
- 'activity/activity_view_manager_impl.cc',
'activity/activity_frame_view.cc',
'activity/activity_frame_view.h',
'activity/activity_widget_delegate.cc',
@@ -48,7 +47,6 @@
'activity/public/activity_factory.h',
'activity/public/activity_manager.h',
'activity/public/activity_manager_observer.h',
- 'activity/public/activity_view_manager.h',
'activity/public/activity_view_model.h',
'athena_export.h',
'env/athena_env_impl.cc',
diff --git a/athena/content/web_activity.cc b/athena/content/web_activity.cc
index e206365..bdf2e41 100644
--- a/athena/content/web_activity.cc
+++ b/athena/content/web_activity.cc
@@ -235,9 +235,9 @@ class AthenaWebView : public views::WebView {
case NEW_BACKGROUND_TAB:
case NEW_POPUP:
case NEW_WINDOW: {
- ActivityManager::Get()->AddActivity(
- ActivityFactory::Get()->CreateWebActivity(
- browser_context(), base::string16(), params.url));
+ Activity* activity = ActivityFactory::Get()->CreateWebActivity(
+ browser_context(), base::string16(), params.url);
+ Activity::Show(activity);
break;
}
default:
diff --git a/athena/extensions/athena_app_delegate_base.cc b/athena/extensions/athena_app_delegate_base.cc
index 53c1b96..451fc981 100644
--- a/athena/extensions/athena_app_delegate_base.cc
+++ b/athena/extensions/athena_app_delegate_base.cc
@@ -4,6 +4,7 @@
#include "athena/extensions/athena_app_delegate_base.h"
+#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_factory.h"
#include "athena/env/public/athena_env.h"
#include "content/public/browser/web_contents.h"
@@ -22,7 +23,7 @@ content::WebContents* OpenURLInActivity(content::BrowserContext* context,
// Force all links to open in a new activity.
Activity* activity = ActivityFactory::Get()->CreateWebActivity(
context, base::string16(), params.url);
- DCHECK(activity);
+ Activity::Show(activity);
// TODO(oshima): Get the web cotnents from activity.
return NULL;
}
diff --git a/athena/main/placeholder.cc b/athena/main/placeholder.cc
index 0baa542..c0d89f0 100644
--- a/athena/main/placeholder.cc
+++ b/athena/main/placeholder.cc
@@ -4,6 +4,7 @@
#include "athena/main/placeholder.h"
+#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_factory.h"
#include "athena/resources/grit/athena_resources.h"
#include "athena/system/public/system_ui.h"
@@ -15,9 +16,11 @@ void CreateTestPages(content::BrowserContext* browser_context) {
"http://cyan.bikeshed.com", "https://news.google.com",
"http://blue.bikeshed.com", "https://www.google.com",
};
+ athena::ActivityFactory* factory = athena::ActivityFactory::Get();
for (size_t i = 0; i < arraysize(kTestURLs); ++i) {
- athena::ActivityFactory::Get()->CreateWebActivity(
+ athena::Activity* activity = factory->CreateWebActivity(
browser_context, base::string16(), GURL(kTestURLs[i]));
+ athena::Activity::Show(activity);
}
}
diff --git a/athena/main/url_search_provider.cc b/athena/main/url_search_provider.cc
index 5ca3b7f..23b34f8 100644
--- a/athena/main/url_search_provider.cc
+++ b/athena/main/url_search_provider.cc
@@ -4,6 +4,7 @@
#include "athena/main/url_search_provider.h"
+#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_factory.h"
#include "athena/content/public/scheme_classifier_factory.h"
#include "base/strings/utf_string_conversions.h"
@@ -171,8 +172,9 @@ class UrlSearchResult : public app_list::SearchResult {
private:
// Overriddenn from app_list::SearchResult:
virtual void Open(int event_flags) OVERRIDE {
- ActivityFactory::Get()->CreateWebActivity(
+ Activity* activity = ActivityFactory::Get()->CreateWebActivity(
browser_context_, base::string16(), match_.destination_url);
+ Activity::Show(activity);
}
void UpdateIcon() {
diff --git a/athena/resource_manager/resource_manager_impl.cc b/athena/resource_manager/resource_manager_impl.cc
index 9c18a75..3cb303a 100644
--- a/athena/resource_manager/resource_manager_impl.cc
+++ b/athena/resource_manager/resource_manager_impl.cc
@@ -22,6 +22,7 @@
#include "ui/aura/window.h"
namespace athena {
+namespace {
class ResourceManagerImpl : public ResourceManager,
public WindowManagerObserver,
@@ -459,6 +460,8 @@ bool ResourceManagerImpl::AllowedToUnloadActivity() {
base::Time::Now() >= next_resource_management_time_;
}
+} // namespace
+
// static
void ResourceManager::Create() {
DCHECK(!instance);