Chromium Code Reviews| 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/content/app_activity_registry.h" | |
| 9 #include "athena/content/public/app_content_control_delegate.h" | |
| 10 #include "athena/content/public/app_registry.h" | |
| 8 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 9 #include "extensions/shell/browser/shell_app_window.h" | 12 #include "extensions/shell/browser/shell_app_window.h" |
| 10 #include "ui/views/controls/webview/webview.h" | 13 #include "ui/views/controls/webview/webview.h" |
| 14 #include "ui/views/widget/widget.h" | |
| 11 | 15 |
| 12 namespace athena { | 16 namespace athena { |
| 13 | 17 |
| 14 // TODO(mukai): specifies the same accelerators of WebActivity. | 18 // TODO(mukai): specifies the same accelerators of WebActivity. |
| 15 AppActivity::AppActivity(extensions::ShellAppWindow* app_window) | 19 AppActivity::AppActivity(extensions::ShellAppWindow* app_window) |
| 16 : app_window_(app_window), | 20 : app_window_(app_window), |
| 17 web_view_(NULL), | 21 web_view_(NULL), |
| 18 current_state_(ACTIVITY_UNLOADED) { | 22 current_state_(ACTIVITY_UNLOADED), |
| 19 DCHECK(app_window_); | 23 app_activity_registry_(NULL) { |
| 20 } | 24 } |
| 21 | 25 |
| 22 AppActivity::~AppActivity() { | 26 AppActivity::~AppActivity() { |
| 23 if (GetCurrentState() != ACTIVITY_UNLOADED) | 27 // If this activity is registered, we unregister it now. |
| 24 SetCurrentState(ACTIVITY_UNLOADED); | 28 if (app_activity_registry_) |
| 29 app_activity_registry_->UnregisterAppActivity(this); | |
| 25 } | 30 } |
| 26 | 31 |
| 27 ActivityViewModel* AppActivity::GetActivityViewModel() { | 32 ActivityViewModel* AppActivity::GetActivityViewModel() { |
| 28 return this; | 33 return this; |
| 29 } | 34 } |
| 30 | 35 |
| 31 void AppActivity::SetCurrentState(Activity::ActivityState state) { | 36 void AppActivity::SetCurrentState(Activity::ActivityState state) { |
| 37 ActivityState current_state = state; | |
| 38 // Remember the last requested state now so that a call to GetCurrentState() | |
| 39 // returns the new state. | |
| 40 current_state_ = state; | |
| 41 | |
| 32 switch (state) { | 42 switch (state) { |
| 33 case ACTIVITY_VISIBLE: | 43 case ACTIVITY_VISIBLE: |
| 34 // Fall through (for the moment). | 44 // Fall through (for the moment). |
| 35 case ACTIVITY_INVISIBLE: | 45 case ACTIVITY_INVISIBLE: |
| 36 // By clearing the overview mode image we allow the content to be shown. | 46 // By clearing the overview mode image we allow the content to be shown. |
| 37 overview_mode_image_ = gfx::ImageSkia(); | 47 overview_mode_image_ = gfx::ImageSkia(); |
| 38 // TODO(skuhne): Find out how to reload an app from the extension system. | 48 // Note: A reload from the unloaded state will be performed through the |
| 49 // |AppActivityProxy| object and no further action isn't necessary here. | |
| 39 break; | 50 break; |
| 40 case ACTIVITY_BACKGROUND_LOW_PRIORITY: | 51 case ACTIVITY_BACKGROUND_LOW_PRIORITY: |
| 41 DCHECK(ACTIVITY_VISIBLE == current_state_ || | 52 DCHECK(ACTIVITY_VISIBLE == current_state || |
| 42 ACTIVITY_INVISIBLE == current_state_); | 53 ACTIVITY_INVISIBLE == current_state); |
| 43 // TODO(skuhne): Do this. | 54 // TODO(skuhne): Do this. |
| 44 break; | 55 break; |
| 45 case ACTIVITY_PERSISTENT: | 56 case ACTIVITY_PERSISTENT: |
| 46 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); | 57 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state); |
| 47 // TODO(skuhne): Do this. | 58 // TODO(skuhne): Do this. |
| 48 break; | 59 break; |
| 49 case ACTIVITY_UNLOADED: | 60 case ACTIVITY_UNLOADED: |
| 50 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); | 61 DCHECK_NE(ACTIVITY_UNLOADED, current_state); |
| 51 // TODO(skuhne): Find out how to evict an app from the extension system. | 62 // This will cause the application to shut down, close its windows and |
| 52 // web_view_->EvictContent(); | 63 // delete this object. Instead a |AppActivityProxy| will be created as |
| 64 // place holder. | |
| 65 if (app_activity_registry_) | |
| 66 app_activity_registry_->Unload(); | |
| 53 break; | 67 break; |
| 54 } | 68 } |
| 55 // Remember the last requested state. | |
| 56 current_state_ = state; | |
| 57 } | 69 } |
| 58 | 70 |
| 59 Activity::ActivityState AppActivity::GetCurrentState() { | 71 Activity::ActivityState AppActivity::GetCurrentState() { |
| 60 // TODO(skuhne): Check here also eviction status. | |
| 61 if (!web_view_) { | 72 if (!web_view_) { |
| 62 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 73 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
| 63 return ACTIVITY_UNLOADED; | 74 return ACTIVITY_UNLOADED; |
| 64 } | 75 } |
| 65 // TODO(skuhne): This should be controlled by an observer and should not | 76 // TODO(skuhne): This should be controlled by an observer and should not |
| 66 // reside here. | 77 // reside here. |
| 67 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE) | 78 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE) |
| 68 SetCurrentState(ACTIVITY_VISIBLE); | 79 SetCurrentState(ACTIVITY_VISIBLE); |
| 69 // Note: If the activity is not visible it does not necessarily mean that it | 80 // Note: If the activity is not visible it does not necessarily mean that it |
| 70 // does not have GPU compositor resources (yet). | 81 // does not have GPU compositor resources (yet). |
| 71 return current_state_; | 82 return current_state_; |
| 72 } | 83 } |
| 73 | 84 |
| 74 bool AppActivity::IsVisible() { | 85 bool AppActivity::IsVisible() { |
| 75 return web_view_ && web_view_->IsDrawn(); | 86 return web_view_ && web_view_->IsDrawn(); |
| 76 } | 87 } |
| 77 | 88 |
| 78 Activity::ActivityMediaState AppActivity::GetMediaState() { | 89 Activity::ActivityMediaState AppActivity::GetMediaState() { |
| 79 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), | 90 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), |
| 80 // and the AudioStreamMonitor needs to be moved from Chrome into contents to | 91 // and the AudioStreamMonitor needs to be moved from Chrome into contents to |
| 81 // make it more modular and so that we can use it from here. | 92 // make it more modular and so that we can use it from here. |
| 82 return Activity::ACTIVITY_MEDIA_STATE_NONE; | 93 return Activity::ACTIVITY_MEDIA_STATE_NONE; |
| 83 } | 94 } |
| 84 | 95 |
| 96 aura::Window* AppActivity::GetWindow() { | |
| 97 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow(); | |
| 98 } | |
| 99 | |
| 85 void AppActivity::Init() { | 100 void AppActivity::Init() { |
| 86 } | 101 } |
| 87 | 102 |
| 88 SkColor AppActivity::GetRepresentativeColor() const { | 103 SkColor AppActivity::GetRepresentativeColor() const { |
| 89 // TODO(sad): Compute the color from the favicon. | 104 // TODO(sad): Compute the color from the favicon. |
| 90 return SK_ColorGRAY; | 105 return SK_ColorGRAY; |
| 91 } | 106 } |
| 92 | 107 |
| 93 base::string16 AppActivity::GetTitle() const { | 108 base::string16 AppActivity::GetTitle() const { |
| 94 return web_view_->GetWebContents()->GetTitle(); | 109 return web_view_->GetWebContents()->GetTitle(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 123 void AppActivity::TitleWasSet(content::NavigationEntry* entry, | 138 void AppActivity::TitleWasSet(content::NavigationEntry* entry, |
| 124 bool explicit_set) { | 139 bool explicit_set) { |
| 125 ActivityManager::Get()->UpdateActivity(this); | 140 ActivityManager::Get()->UpdateActivity(this); |
| 126 } | 141 } |
| 127 | 142 |
| 128 void AppActivity::DidUpdateFaviconURL( | 143 void AppActivity::DidUpdateFaviconURL( |
| 129 const std::vector<content::FaviconURL>& candidates) { | 144 const std::vector<content::FaviconURL>& candidates) { |
| 130 ActivityManager::Get()->UpdateActivity(this); | 145 ActivityManager::Get()->UpdateActivity(this); |
| 131 } | 146 } |
| 132 | 147 |
| 148 void AppActivity::DidStartNavigationToPendingEntry( | |
| 149 const GURL& url, | |
| 150 content::NavigationController::ReloadType reload_type) { | |
| 151 if (!app_activity_registry_) | |
| 152 RegisterActivity(); | |
| 153 } | |
| 154 | |
| 155 // Register an |activity| with an application. | |
| 156 // Note: This should only get called once for an |app_window| of the | |
| 157 // |activity|. | |
| 158 void AppActivity::RegisterActivity() { | |
| 159 if (app_activity_registry_) | |
| 160 return; | |
| 161 content::WebContents* web_contents = app_window_->GetAssociatedWebContents(); | |
| 162 AppRegistry* app_registry = AppRegistry::Get(); | |
| 163 // Get the application's registry. | |
| 164 app_activity_registry_ = app_registry->GetAppActivityRegistry( | |
| 165 app_registry->GetDelegate()->GetApplicationID(web_contents), | |
| 166 web_contents->GetBrowserContext()); | |
| 167 DCHECK(app_activity_registry_); | |
| 168 // Register the activity. | |
| 169 app_activity_registry_->RegisterAppActivity(this); | |
|
oshima
2014/08/19 21:22:24
can state be in UNLOADED state here?
Mr4D (OOO till 08-26)
2014/08/20 14:34:39
No. This is executed after AppActivity::GetContent
oshima
2014/08/20 19:51:49
I assume you meant the content is set?
Mr4D (OOO till 08-26)
2014/08/20 22:34:21
Well - yes, implicitly. (since GetContentsView ass
| |
| 170 } | |
| 171 | |
| 133 } // namespace athena | 172 } // namespace athena |
| OLD | NEW |