Update To 11.40.268.0
[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   ~WebstoreInlineInstaller() override;
43
44   // Implementations WebstoreStandaloneInstaller Template Method's hooks.
45   bool CheckRequestorAlive() const override;
46   const GURL& GetRequestorURL() const override;
47   bool ShouldShowPostInstallUI() const override;
48   bool ShouldShowAppInstalledBubble() const override;
49   content::WebContents* GetWebContents() const override;
50   scoped_refptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
51       const override;
52   bool CheckInlineInstallPermitted(const base::DictionaryValue& webstore_data,
53                                    std::string* error) const override;
54   bool CheckRequestorPermitted(const base::DictionaryValue& webstore_data,
55                                std::string* error) const override;
56
57  private:
58   // content::WebContentsObserver interface implementation.
59   void WebContentsDestroyed() override;
60
61   // Checks whether the install is initiated by a page in a verified site
62   // (which is at least a domain, but can also have a port or a path).
63   static bool IsRequestorURLInVerifiedSite(const GURL& requestor_url,
64                                            const std::string& verified_site);
65
66   GURL requestor_url_;
67
68   DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller);
69 };
70
71 }  // namespace extensions
72
73 #endif  // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_