• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
7 
8 #include <string>
9 
10 #include "base/basictypes.h"
11 #include "chrome/browser/extensions/webstore_standalone_installer.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/web_contents_observer.h"
14 
15 class Profile;
16 
17 namespace content {
18 class WebContents;
19 }
20 
21 namespace extensions {
22 class Extension;
23 }
24 
25 // EphemeralAppLauncher manages the launching of ephemeral apps. It handles
26 // display of a prompt, initiates install of the app (if necessary) and finally
27 // launches the app.
28 class EphemeralAppLauncher
29     : public extensions::WebstoreStandaloneInstaller,
30       public content::WebContentsObserver,
31       public content::NotificationObserver {
32  public:
33   typedef WebstoreStandaloneInstaller::Callback Callback;
34 
35   // Create for the app launcher.
36   static scoped_refptr<EphemeralAppLauncher> CreateForLauncher(
37       const std::string& webstore_item_id,
38       Profile* profile,
39       gfx::NativeWindow parent_window,
40       const Callback& callback);
41 
42   // Create for a link within a browser tab.
43   static scoped_refptr<EphemeralAppLauncher> CreateForLink(
44       const std::string& webstore_item_id,
45       content::WebContents* web_contents);
46 
47   // Initiate app launch.
48   void Start();
49 
50  private:
51   friend class base::RefCountedThreadSafe<EphemeralAppLauncher>;
52 
53   EphemeralAppLauncher(const std::string& webstore_item_id,
54                        Profile* profile,
55                        gfx::NativeWindow parent_window,
56                        const Callback& callback);
57   EphemeralAppLauncher(const std::string& webstore_item_id,
58                        content::WebContents* web_contents,
59                        const Callback& callback);
60 
61   virtual ~EphemeralAppLauncher();
62 
63   void Init();
64   void LaunchApp(const extensions::Extension* extension) const;
65 
66   // WebstoreStandaloneInstaller implementation.
67   virtual bool CheckRequestorAlive() const OVERRIDE;
68   virtual const GURL& GetRequestorURL() const OVERRIDE;
69   virtual bool ShouldShowPostInstallUI() const OVERRIDE;
70   virtual bool ShouldShowAppInstalledBubble() const OVERRIDE;
71   virtual content::WebContents* GetWebContents() const OVERRIDE;
72   virtual scoped_ptr<ExtensionInstallPrompt::Prompt>
73       CreateInstallPrompt() const OVERRIDE;
74   virtual bool CheckInlineInstallPermitted(
75       const base::DictionaryValue& webstore_data,
76       std::string* error) const OVERRIDE;
77   virtual bool CheckRequestorPermitted(
78       const base::DictionaryValue& webstore_data,
79       std::string* error) const OVERRIDE;
80   virtual bool CheckInstallValid(
81       const base::DictionaryValue& manifest,
82       std::string* error) OVERRIDE;
83   virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() OVERRIDE;
84   virtual scoped_ptr<extensions::WebstoreInstaller::Approval>
85       CreateApproval() const OVERRIDE;
86   virtual void CompleteInstall(const std::string& error) OVERRIDE;
87 
88   // content::WebContentsObserver implementation.
89   virtual void WebContentsDestroyed(
90       content::WebContents* web_contents) OVERRIDE;
91 
92   // content::NotificationObserver implementation.
93   virtual void Observe(int type,
94                        const content::NotificationSource& source,
95                        const content::NotificationDetails& details) OVERRIDE;
96 
97   content::NotificationRegistrar registrar_;
98 
99   gfx::NativeWindow parent_window_;
100   scoped_ptr<content::WebContents> dummy_web_contents_;
101 
102   DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher);
103 };
104 
105 #endif  // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
106