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