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.
5 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_
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"
16 class ExtensionEnableFlow;
23 namespace extensions {
25 class ExtensionRegistry;
28 // EphemeralAppLauncher manages the launching of ephemeral apps. It handles
29 // display of a prompt, initiates install of the app (if necessary) and finally
31 class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller,
32 public content::WebContentsObserver,
33 public ExtensionEnableFlowDelegate {
35 typedef WebstoreStandaloneInstaller::Callback Callback;
37 // Create for the app launcher.
38 static scoped_refptr<EphemeralAppLauncher> CreateForLauncher(
39 const std::string& webstore_item_id,
41 gfx::NativeWindow parent_window,
42 const Callback& callback);
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);
49 // Initiate app launch.
53 friend class base::RefCountedThreadSafe<EphemeralAppLauncher>;
55 EphemeralAppLauncher(const std::string& webstore_item_id,
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);
63 virtual ~EphemeralAppLauncher();
65 void LaunchApp(const extensions::Extension* extension) const;
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()
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;
89 // content::WebContentsObserver implementation.
90 virtual void WebContentsDestroyed() OVERRIDE;
92 // ExtensionEnableFlowDelegate implementation.
93 virtual void ExtensionEnableFlowFinished() OVERRIDE;
94 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE;
96 gfx::NativeWindow parent_window_;
97 scoped_ptr<content::WebContents> dummy_web_contents_;
99 // Created in CheckInstallValid().
100 scoped_refptr<extensions::Extension> extension_;
102 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_;
104 DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher);
107 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_