Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / content / app_activity.cc
blob62ecb2cf859ab326e85c897d97ba4b4aab4bf78a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "athena/content/app_activity.h"
7 #include "athena/activity/public/activity_manager.h"
8 #include "athena/content/app_activity_registry.h"
9 #include "athena/content/public/app_registry.h"
10 #include "content/public/browser/web_contents.h"
11 #include "ui/aura/window.h"
12 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/widget/widget.h"
15 namespace athena {
17 // TODO(mukai): specifies the same accelerators of WebActivity.
18 AppActivity::AppActivity(const std::string& app_id)
19 : app_id_(app_id),
20 web_view_(NULL),
21 current_state_(ACTIVITY_UNLOADED),
22 app_activity_registry_(NULL) {
25 AppActivity::~AppActivity() {
26 // If this activity is registered, we unregister it now.
27 if (app_activity_registry_)
28 app_activity_registry_->UnregisterAppActivity(this);
31 ActivityViewModel* AppActivity::GetActivityViewModel() {
32 return this;
35 void AppActivity::SetCurrentState(Activity::ActivityState state) {
36 ActivityState current_state = state;
37 // Remember the last requested state now so that a call to GetCurrentState()
38 // returns the new state.
39 current_state_ = state;
41 switch (state) {
42 case ACTIVITY_VISIBLE:
43 // Fall through (for the moment).
44 case ACTIVITY_INVISIBLE:
45 // By clearing the overview mode image we allow the content to be shown.
46 overview_mode_image_ = gfx::ImageSkia();
47 // Note: A reload from the unloaded state will be performed through the
48 // |AppActivityProxy| object and no further action isn't necessary here.
49 break;
50 case ACTIVITY_BACKGROUND_LOW_PRIORITY:
51 DCHECK(ACTIVITY_VISIBLE == current_state ||
52 ACTIVITY_INVISIBLE == current_state);
53 // TODO(skuhne): Do this.
54 break;
55 case ACTIVITY_PERSISTENT:
56 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state);
57 // TODO(skuhne): Do this.
58 break;
59 case ACTIVITY_UNLOADED:
60 DCHECK_NE(ACTIVITY_UNLOADED, current_state);
61 // This will cause the application to shut down, close its windows and
62 // delete this object. Instead a |AppActivityProxy| will be created as
63 // place holder.
64 if (app_activity_registry_)
65 app_activity_registry_->Unload();
66 break;
70 Activity::ActivityState AppActivity::GetCurrentState() {
71 if (!web_view_) {
72 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
73 return ACTIVITY_UNLOADED;
75 // TODO(skuhne): This should be controlled by an observer and should not
76 // reside here.
77 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE)
78 SetCurrentState(ACTIVITY_VISIBLE);
79 // Note: If the activity is not visible it does not necessarily mean that it
80 // does not have GPU compositor resources (yet).
81 return current_state_;
84 bool AppActivity::IsVisible() {
85 return web_view_ &&
86 web_view_->IsDrawn() &&
87 current_state_ != ACTIVITY_UNLOADED &&
88 GetWindow() &&
89 GetWindow()->IsVisible();
92 Activity::ActivityMediaState AppActivity::GetMediaState() {
93 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents),
94 // and the AudioStreamMonitor needs to be moved from Chrome into contents to
95 // make it more modular and so that we can use it from here.
96 return Activity::ACTIVITY_MEDIA_STATE_NONE;
99 aura::Window* AppActivity::GetWindow() {
100 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
103 void AppActivity::Init() {
106 SkColor AppActivity::GetRepresentativeColor() const {
107 // TODO(sad): Compute the color from the favicon.
108 return SK_ColorGRAY;
111 base::string16 AppActivity::GetTitle() const {
112 return web_view_->GetWebContents()->GetTitle();
115 bool AppActivity::UsesFrame() const {
116 return false;
119 views::View* AppActivity::GetContentsView() {
120 if (!web_view_) {
121 // TODO(oshima): use apps::NativeAppWindowViews
122 content::WebContents* web_contents = GetWebContents();
123 web_view_ = new views::WebView(web_contents->GetBrowserContext());
124 web_view_->SetWebContents(web_contents);
125 SetCurrentState(ACTIVITY_INVISIBLE);
126 Observe(web_contents);
127 overview_mode_image_ = gfx::ImageSkia();
128 RegisterActivity();
130 return web_view_;
133 void AppActivity::CreateOverviewModeImage() {
134 // TODO(skuhne): Implement this!
137 gfx::ImageSkia AppActivity::GetOverviewModeImage() {
138 return overview_mode_image_;
141 void AppActivity::TitleWasSet(content::NavigationEntry* entry,
142 bool explicit_set) {
143 ActivityManager::Get()->UpdateActivity(this);
146 void AppActivity::DidUpdateFaviconURL(
147 const std::vector<content::FaviconURL>& candidates) {
148 ActivityManager::Get()->UpdateActivity(this);
151 // Register an |activity| with an application.
152 // Note: This should only get called once for an |app_window| of the
153 // |activity|.
154 void AppActivity::RegisterActivity() {
155 content::WebContents* web_contents = GetWebContents();
156 AppRegistry* app_registry = AppRegistry::Get();
157 // Get the application's registry.
158 app_activity_registry_ = app_registry->GetAppActivityRegistry(
159 app_id_, web_contents->GetBrowserContext());
160 DCHECK(app_activity_registry_);
161 // Register the activity.
162 app_activity_registry_->RegisterAppActivity(this);
165 } // namespace athena