| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "athena/content/app_activity.h" | 5 #include "athena/content/app_activity.h" |
| 6 | 6 |
| 7 #include "athena/activity/public/activity_manager.h" | 7 #include "athena/activity/public/activity_manager.h" |
| 8 #include "athena/activity/public/activity_view.h" | 8 #include "athena/activity/public/activity_view.h" |
| 9 #include "athena/content/app_activity_registry.h" | 9 #include "athena/content/app_activity_registry.h" |
| 10 #include "athena/content/content_proxy.h" | 10 #include "athena/content/content_proxy.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // This will cause the application to shut down, close its windows and | 71 // This will cause the application to shut down, close its windows and |
| 72 // delete this object. Instead a |AppActivityProxy| will be created as | 72 // delete this object. Instead a |AppActivityProxy| will be created as |
| 73 // place holder. | 73 // place holder. |
| 74 if (app_activity_registry_) | 74 if (app_activity_registry_) |
| 75 app_activity_registry_->Unload(); | 75 app_activity_registry_->Unload(); |
| 76 break; | 76 break; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 Activity::ActivityState AppActivity::GetCurrentState() { | 80 Activity::ActivityState AppActivity::GetCurrentState() { |
| 81 DCHECK(web_view_ || ACTIVITY_UNLOADED == current_state_); | 81 DCHECK(GetContentsView() || ACTIVITY_UNLOADED == current_state_); |
| 82 return current_state_; | 82 return current_state_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool AppActivity::IsVisible() { | 85 bool AppActivity::IsVisible() { |
| 86 return web_view_ && | 86 return web_view_ && |
| 87 web_view_->visible() && | 87 web_view_->visible() && |
| 88 current_state_ != ACTIVITY_UNLOADED; | 88 current_state_ != ACTIVITY_UNLOADED; |
| 89 } | 89 } |
| 90 | 90 |
| 91 Activity::ActivityMediaState AppActivity::GetMediaState() { | 91 Activity::ActivityMediaState AppActivity::GetMediaState() { |
| 92 return current_state_ == ACTIVITY_UNLOADED ? | 92 return current_state_ == ACTIVITY_UNLOADED ? |
| 93 Activity::ACTIVITY_MEDIA_STATE_NONE : | 93 Activity::ACTIVITY_MEDIA_STATE_NONE : |
| 94 GetActivityMediaState(GetWebContents()); | 94 GetActivityMediaState(GetWebContents()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 aura::Window* AppActivity::GetWindow() { | 97 aura::Window* AppActivity::GetWindow() { |
| 98 return web_view_ && web_view_->GetWidget() | 98 views::View* view = GetContentsView(); |
| 99 ? web_view_->GetWidget()->GetNativeWindow() | 99 return (view && view->GetWidget()) ? view->GetWidget()->GetNativeWindow() |
| 100 : nullptr; | 100 : nullptr; |
| 101 } | 101 } |
| 102 | 102 |
| 103 content::WebContents* AppActivity::GetWebContents() { | 103 content::WebContents* AppActivity::GetWebContents() { |
| 104 return !web_view_ ? nullptr : web_view_->GetWebContents(); | 104 return !web_view_ ? nullptr : web_view_->GetWebContents(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void AppActivity::Init() { | 107 void AppActivity::Init() { |
| 108 // Before we remove the proxy, we have to register the activity and | 108 // Before we remove the proxy, we have to register the activity and |
| 109 // initialize its to move it to the proper activity list location. | 109 // initialize its to move it to the proper activity list location. |
| 110 RegisterActivity(); | 110 RegisterActivity(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 SetCurrentState(ACTIVITY_INVISIBLE); | 154 SetCurrentState(ACTIVITY_INVISIBLE); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 SkColor AppActivity::GetRepresentativeColor() const { | 158 SkColor AppActivity::GetRepresentativeColor() const { |
| 159 // TODO(sad): Compute the color from the favicon. | 159 // TODO(sad): Compute the color from the favicon. |
| 160 return SK_ColorGRAY; | 160 return SK_ColorGRAY; |
| 161 } | 161 } |
| 162 | 162 |
| 163 base::string16 AppActivity::GetTitle() const { | 163 base::string16 AppActivity::GetTitle() const { |
| 164 return web_view_->GetWebContents()->GetTitle(); | 164 return web_view_ ? web_view_->GetWebContents()->GetTitle() : base::string16(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 gfx::ImageSkia AppActivity::GetIcon() const { | 167 gfx::ImageSkia AppActivity::GetIcon() const { |
| 168 return gfx::ImageSkia(); | 168 return gfx::ImageSkia(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void AppActivity::SetActivityView(ActivityView* view) { | 171 void AppActivity::SetActivityView(ActivityView* view) { |
| 172 DCHECK(!activity_view_); | 172 DCHECK(!activity_view_); |
| 173 activity_view_ = view; | 173 activity_view_ = view; |
| 174 } | 174 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void AppActivity::DidUpdateFaviconURL( | 226 void AppActivity::DidUpdateFaviconURL( |
| 227 const std::vector<content::FaviconURL>& candidates) { | 227 const std::vector<content::FaviconURL>& candidates) { |
| 228 if (activity_view_) | 228 if (activity_view_) |
| 229 activity_view_->UpdateIcon(); | 229 activity_view_->UpdateIcon(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Register an |activity| with an application. | 232 // Register an |activity| with an application. |
| 233 // Note: This should only get called once for an |app_window| of the | 233 // Note: This should only get called once for an |app_window| of the |
| 234 // |activity|. | 234 // |activity|. |
| 235 void AppActivity::RegisterActivity() { | 235 void AppActivity::RegisterActivity() { |
| 236 content::WebContents* web_contents = web_view_->GetWebContents(); | 236 content::WebContents* web_contents = web_view_ ? web_view_->GetWebContents() |
| 237 : nullptr; |
| 237 AppRegistry* app_registry = AppRegistry::Get(); | 238 AppRegistry* app_registry = AppRegistry::Get(); |
| 238 // Get the application's registry. | 239 // Get the application's registry. |
| 239 app_activity_registry_ = app_registry->GetAppActivityRegistry( | 240 app_activity_registry_ = app_registry->GetAppActivityRegistry( |
| 240 app_id_, web_contents->GetBrowserContext()); | 241 app_id_, web_contents ? web_contents->GetBrowserContext() : nullptr); |
| 241 DCHECK(app_activity_registry_); | 242 DCHECK(app_activity_registry_); |
| 242 // Register the activity. | 243 // Register the activity. |
| 243 app_activity_registry_->RegisterAppActivity(this); | 244 app_activity_registry_->RegisterAppActivity(this); |
| 244 } | 245 } |
| 245 | 246 |
| 246 void AppActivity::HideContentProxy() { | 247 void AppActivity::HideContentProxy() { |
| 247 content_proxy_.reset(); | 248 content_proxy_.reset(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 void AppActivity::ShowContentProxy() { | 251 void AppActivity::ShowContentProxy() { |
| 251 if (!content_proxy_.get() && web_view_) | 252 if (!content_proxy_.get() && web_view_) |
| 252 content_proxy_.reset(new ContentProxy(web_view_)); | 253 content_proxy_.reset(new ContentProxy(web_view_)); |
| 253 } | 254 } |
| 254 | 255 |
| 255 } // namespace athena | 256 } // namespace athena |
| OLD | NEW |