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