#include "athena/content/app_activity.h"
#include "athena/activity/public/activity_manager.h"
+#include "athena/activity/public/activity_view.h"
#include "athena/content/app_activity_registry.h"
#include "athena/content/content_proxy.h"
+#include "athena/content/media_utils.h"
#include "athena/content/public/app_registry.h"
#include "athena/wm/public/window_list_provider.h"
#include "athena/wm/public/window_manager.h"
#include "content/public/browser/web_contents.h"
-#include "extensions/browser/app_window/app_window.h"
#include "ui/aura/window.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h"
+#include "ui/wm/core/window_util.h"
namespace athena {
// TODO(mukai): specifies the same accelerators of WebActivity.
-AppActivity::AppActivity(extensions::AppWindow* app_window,
- views::WebView* web_view)
- : app_id_(app_window->extension_id()),
+AppActivity::AppActivity(const std::string& app_id, views::WebView* web_view)
+ : app_id_(app_id),
web_view_(web_view),
current_state_(ACTIVITY_UNLOADED),
- app_activity_registry_(NULL) {
- DCHECK_EQ(app_window->web_contents(), web_view->GetWebContents());
- Observe(app_window->web_contents());
+ app_activity_registry_(nullptr),
+ activity_view_(nullptr) {
+ Observe(web_view->GetWebContents());
}
scoped_ptr<ContentProxy> AppActivity::GetContentProxy() {
}
Activity::ActivityMediaState AppActivity::GetMediaState() {
- // TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
- // and the AudioStreamMonitor needs to be moved from Chrome into contents to
- // make it more modular and so that we can use it from here.
- return Activity::ACTIVITY_MEDIA_STATE_NONE;
+ return current_state_ == ACTIVITY_UNLOADED ?
+ Activity::ACTIVITY_MEDIA_STATE_NONE :
+ GetActivityMediaState(GetWebContents());
}
aura::Window* AppActivity::GetWindow() {
- return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
+ return web_view_ && web_view_->GetWidget()
+ ? web_view_->GetWidget()->GetNativeWindow()
+ : nullptr;
}
content::WebContents* AppActivity::GetWebContents() {
- return !web_view_ ? NULL : web_view_->GetWebContents();
+ return !web_view_ ? nullptr : web_view_->GetWebContents();
}
void AppActivity::Init() {
+ // Before we remove the proxy, we have to register the activity and
+ // initialize its to move it to the proper activity list location.
+ RegisterActivity();
+
DCHECK(app_activity_registry_);
Activity* app_proxy = app_activity_registry_->unloaded_activity_proxy();
if (app_proxy) {
// |ResourceManager| - so we can move it around if needed.
WindowListProvider* window_list_provider =
WindowManager::Get()->GetWindowListProvider();
- window_list_provider->StackWindowFrontOf(app_proxy->GetWindow(),
- GetWindow());
- Activity::Delete(app_proxy);
- // With the removal the object, the proxy should be deleted.
+ // TODO(skuhne): After the decision is made how we want to handle visibility
+ // transitions (issue 421680) this code might change.
+ // If the proxy was the active window, its deletion will cause a window
+ // reordering since the next activatable window in line will move up to the
+ // front. Since the application window is still hidden at this time, it is
+ // not yet activatable and the window behind it will move to the front.
+ if (wm::IsActiveWindow(app_proxy->GetWindow())) {
+ // Delete the proxy window first and then move the new window to the top
+ // of the stack, replacing the proxy window. Note that by deleting the
+ // proxy the activation will change to the next (activatable) object and
+ // thus we have to move the window in front at the end.
+ Activity::Delete(app_proxy);
+ if (GetWindow() != window_list_provider->GetWindowList().back()) {
+ window_list_provider->StackWindowFrontOf(
+ GetWindow(),
+ window_list_provider->GetWindowList().back());
+ }
+ } else {
+ // The app window goes in front of the proxy window (we need to first
+ // place the window before we can delete it).
+ window_list_provider->StackWindowFrontOf(GetWindow(),
+ app_proxy->GetWindow());
+ Activity::Delete(app_proxy);
+ }
+ // The proxy should now be deleted.
DCHECK(!app_activity_registry_->unloaded_activity_proxy());
}
+
+ // Make sure the content gets properly shown.
+ if (current_state_ == ACTIVITY_VISIBLE) {
+ HideContentProxy();
+ } else if (current_state_ == ACTIVITY_INVISIBLE) {
+ ShowContentProxy();
+ } else {
+ // If not previously specified, we change the state now to invisible..
+ SetCurrentState(ACTIVITY_INVISIBLE);
+ }
}
SkColor AppActivity::GetRepresentativeColor() const {
return gfx::ImageSkia();
}
-bool AppActivity::UsesFrame() const {
- return false;
+void AppActivity::SetActivityView(ActivityView* view) {
+ DCHECK(!activity_view_);
+ activity_view_ = view;
}
-views::Widget* AppActivity::CreateWidget() {
- // Make sure the content gets properly shown.
- if (current_state_ == ACTIVITY_VISIBLE) {
- HideContentProxy();
- } else if (current_state_ == ACTIVITY_INVISIBLE) {
- ShowContentProxy();
- } else {
- // If not previously specified, we change the state now to invisible..
- SetCurrentState(ACTIVITY_INVISIBLE);
- }
- RegisterActivity();
- return web_view_->GetWidget();
+bool AppActivity::UsesFrame() const {
+ return false;
}
views::View* AppActivity::GetContentsView() {
AppActivity::AppActivity(const std::string& app_id)
: app_id_(app_id),
- web_view_(NULL),
+ web_view_(nullptr),
current_state_(ACTIVITY_UNLOADED),
- app_activity_registry_(NULL) {
+ app_activity_registry_(nullptr),
+ activity_view_(nullptr) {
}
AppActivity::~AppActivity() {
void AppActivity::TitleWasSet(content::NavigationEntry* entry,
bool explicit_set) {
- ActivityManager::Get()->UpdateActivity(this);
+ if (activity_view_)
+ activity_view_->UpdateTitle();
}
void AppActivity::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) {
- ActivityManager::Get()->UpdateActivity(this);
+ if (activity_view_)
+ activity_view_->UpdateIcon();
}
// Register an |activity| with an application.
void AppActivity::ShowContentProxy() {
if (!content_proxy_.get() && web_view_)
- content_proxy_.reset(new ContentProxy(web_view_, this));
+ content_proxy_.reset(new ContentProxy(web_view_));
}
} // namespace athena