Home | History | Annotate | Download | only in content
      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.
      4 
      5 #ifndef ATHENA_CONTENT_APP_ACTIVITY_H_
      6 #define ATHENA_CONTENT_APP_ACTIVITY_H_
      7 
      8 #include "athena/activity/public/activity.h"
      9 #include "athena/activity/public/activity_view_model.h"
     10 #include "athena/content/app_activity_proxy.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "content/public/browser/web_contents_observer.h"
     13 
     14 namespace extensions {
     15 class AppWindow;
     16 }
     17 
     18 namespace views {
     19 class WebView;
     20 }
     21 
     22 namespace athena {
     23 
     24 class AppActivityRegistry;
     25 class ContentProxy;
     26 
     27 // The activity object for a hosted V2 application.
     28 // TODO(oshima): Move this to athena/extensions
     29 class AppActivity : public Activity,
     30                     public ActivityViewModel,
     31                     public content::WebContentsObserver {
     32  public:
     33   AppActivity(extensions::AppWindow* app_window, views::WebView* web_view);
     34 
     35   // Gets the content proxy so that the AppActivityProxy can take it over.
     36   scoped_ptr<ContentProxy> GetContentProxy();
     37 
     38   // Activity:
     39   virtual athena::ActivityViewModel* GetActivityViewModel() OVERRIDE;
     40   virtual void SetCurrentState(Activity::ActivityState state) OVERRIDE;
     41   virtual ActivityState GetCurrentState() OVERRIDE;
     42   virtual bool IsVisible() OVERRIDE;
     43   virtual ActivityMediaState GetMediaState() OVERRIDE;
     44   virtual aura::Window* GetWindow() OVERRIDE;
     45   virtual content::WebContents* GetWebContents() OVERRIDE;
     46 
     47   // ActivityViewModel:
     48   virtual void Init() OVERRIDE;
     49   virtual SkColor GetRepresentativeColor() const OVERRIDE;
     50   virtual base::string16 GetTitle() const OVERRIDE;
     51   virtual gfx::ImageSkia GetIcon() const OVERRIDE;
     52   virtual bool UsesFrame() const OVERRIDE;
     53   virtual views::Widget* CreateWidget() OVERRIDE;
     54   virtual views::View* GetContentsView() OVERRIDE;
     55   virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE;
     56   virtual void PrepareContentsForOverview() OVERRIDE;
     57   virtual void ResetContentsView() OVERRIDE;
     58 
     59  protected:
     60   // Constructor for test.
     61   explicit AppActivity(const std::string& app_id);
     62 
     63   virtual ~AppActivity();
     64 
     65  private:
     66  // content::WebContentsObserver:
     67   virtual void TitleWasSet(content::NavigationEntry* entry,
     68                            bool explicit_set) OVERRIDE;
     69   virtual void DidUpdateFaviconURL(
     70       const std::vector<content::FaviconURL>& candidates) OVERRIDE;
     71 
     72   // Register this activity with its application.
     73   void RegisterActivity();
     74 
     75   // Hiding the contet proxy and showing the real content instead.
     76   void HideContentProxy();
     77 
     78   // Showing a content proxy instead of the real content to save resources.
     79   void ShowContentProxy();
     80 
     81   const std::string app_id_;
     82 
     83   views::WebView* web_view_;
     84 
     85   // The current state for this activity.
     86   ActivityState current_state_;
     87 
     88   // If known the registry which holds all activities for the associated app.
     89   // This object is owned by |AppRegistry| and will be a valid pointer as long
     90   // as this object lives.
     91   AppActivityRegistry* app_activity_registry_;
     92 
     93   // The content proxy.
     94   scoped_ptr<ContentProxy> content_proxy_;
     95 
     96   DISALLOW_COPY_AND_ASSIGN(AppActivity);
     97 };
     98 
     99 }  // namespace athena
    100 
    101 #endif  // ATHENA_CONTENT_APP_ACTIVITY_H_
    102