- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / webstore_inline_installer.h
1 // Copyright (c) 2012 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_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "webstore_standalone_installer.h"
13
14 namespace content {
15 class WebContents;
16 }
17
18 namespace extensions {
19
20 // Manages inline installs requested by a page: downloads and parses metadata
21 // from the webstore, shows the install UI, starts the download once the user
22 // confirms, optionally transfers the user to the store if the "View details"
23 // link is clicked in the UI, shows the "App installed" bubble and the
24 // post-install UI after successful installation.
25 //
26 // Clients will be notified of success or failure via the |callback| argument
27 // passed into the constructor.
28 class WebstoreInlineInstaller
29     : public WebstoreStandaloneInstaller,
30       public content::WebContentsObserver {
31  public:
32   typedef WebstoreStandaloneInstaller::Callback Callback;
33
34   WebstoreInlineInstaller(content::WebContents* web_contents,
35                           const std::string& webstore_item_id,
36                           const GURL& requestor_url,
37                           const Callback& callback);
38
39  protected:
40   friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>;
41
42   virtual ~WebstoreInlineInstaller();
43
44   // Implementations WebstoreStandaloneInstaller Template Method's hooks.
45   virtual bool CheckRequestorAlive() const OVERRIDE;
46   virtual const GURL& GetRequestorURL() const OVERRIDE;
47   virtual bool ShouldShowPostInstallUI() const OVERRIDE;
48   virtual bool ShouldShowAppInstalledBubble() const OVERRIDE;
49   virtual content::WebContents* GetWebContents() const OVERRIDE;
50   virtual scoped_ptr<ExtensionInstallPrompt::Prompt>
51       CreateInstallPrompt() const OVERRIDE;
52   virtual bool CheckInlineInstallPermitted(
53       const base::DictionaryValue& webstore_data,
54       std::string* error) const OVERRIDE;
55   virtual bool CheckRequestorPermitted(
56       const base::DictionaryValue& webstore_data,
57       std::string* error) const OVERRIDE;
58
59  private:
60   // content::WebContentsObserver interface implementation.
61   virtual void WebContentsDestroyed(
62       content::WebContents* web_contents) OVERRIDE;
63
64   // Checks whether the install is initiated by a page in a verified site
65   // (which is at least a domain, but can also have a port or a path).
66   static bool IsRequestorURLInVerifiedSite(const GURL& requestor_url,
67                                            const std::string& verified_site);
68
69   GURL requestor_url_;
70
71   DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller);
72 };
73
74 }  // namespace extensions
75
76 #endif  // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_