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 "chrome/browser/extensions/webstore_standalone_installer.h"
12 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/web_contents_observer.h"
16 class ExtensionEnableFlow
;
23 namespace extensions
{
27 // EphemeralAppLauncher manages the launching of ephemeral apps. It handles
28 // display of a prompt, initiates install of the app (if necessary) and finally
30 class EphemeralAppLauncher
31 : public extensions::WebstoreStandaloneInstaller
,
32 public content::WebContentsObserver
,
33 public content::NotificationObserver
,
34 public ExtensionEnableFlowDelegate
{
36 typedef WebstoreStandaloneInstaller::Callback Callback
;
38 // Create for the app launcher.
39 static scoped_refptr
<EphemeralAppLauncher
> CreateForLauncher(
40 const std::string
& webstore_item_id
,
42 gfx::NativeWindow parent_window
,
43 const Callback
& callback
);
45 // Create for a link within a browser tab.
46 static scoped_refptr
<EphemeralAppLauncher
> CreateForLink(
47 const std::string
& webstore_item_id
,
48 content::WebContents
* web_contents
);
50 // Initiate app launch.
54 friend class base::RefCountedThreadSafe
<EphemeralAppLauncher
>;
56 EphemeralAppLauncher(const std::string
& webstore_item_id
,
58 gfx::NativeWindow parent_window
,
59 const Callback
& callback
);
60 EphemeralAppLauncher(const std::string
& webstore_item_id
,
61 content::WebContents
* web_contents
,
62 const Callback
& callback
);
64 virtual ~EphemeralAppLauncher();
66 void StartObserving();
67 void LaunchApp(const extensions::Extension
* extension
) const;
69 // WebstoreStandaloneInstaller implementation.
70 virtual bool CheckRequestorAlive() const OVERRIDE
;
71 virtual const GURL
& GetRequestorURL() const OVERRIDE
;
72 virtual bool ShouldShowPostInstallUI() const OVERRIDE
;
73 virtual bool ShouldShowAppInstalledBubble() const OVERRIDE
;
74 virtual content::WebContents
* GetWebContents() const OVERRIDE
;
75 virtual scoped_ptr
<ExtensionInstallPrompt::Prompt
>
76 CreateInstallPrompt() const OVERRIDE
;
77 virtual bool CheckInlineInstallPermitted(
78 const base::DictionaryValue
& webstore_data
,
79 std::string
* error
) const OVERRIDE
;
80 virtual bool CheckRequestorPermitted(
81 const base::DictionaryValue
& webstore_data
,
82 std::string
* error
) const OVERRIDE
;
83 virtual bool CheckInstallValid(
84 const base::DictionaryValue
& manifest
,
85 std::string
* error
) OVERRIDE
;
86 virtual scoped_ptr
<ExtensionInstallPrompt
> CreateInstallUI() OVERRIDE
;
87 virtual scoped_ptr
<extensions::WebstoreInstaller::Approval
>
88 CreateApproval() const OVERRIDE
;
89 virtual void CompleteInstall(const std::string
& error
) OVERRIDE
;
91 // content::WebContentsObserver implementation.
92 virtual void WebContentsDestroyed(
93 content::WebContents
* web_contents
) OVERRIDE
;
95 // content::NotificationObserver implementation.
96 virtual void Observe(int type
,
97 const content::NotificationSource
& source
,
98 const content::NotificationDetails
& details
) OVERRIDE
;
100 // ExtensionEnableFlowDelegate implementation.
101 virtual void ExtensionEnableFlowFinished() OVERRIDE
;
102 virtual void ExtensionEnableFlowAborted(bool user_initiated
) OVERRIDE
;
104 content::NotificationRegistrar registrar_
;
106 gfx::NativeWindow parent_window_
;
107 scoped_ptr
<content::WebContents
> dummy_web_contents_
;
109 // Created in CheckInstallValid().
110 scoped_refptr
<extensions::Extension
> extension_
;
112 scoped_ptr
<ExtensionEnableFlow
> extension_enable_flow_
;
114 DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher
);
117 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_