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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
10 #include "base/memory/ref_counted.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "webstore_standalone_installer.h"
18 namespace extensions {
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.
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 {
32 typedef WebstoreStandaloneInstaller::Callback Callback;
34 WebstoreInlineInstaller(content::WebContents* web_contents,
35 const std::string& webstore_item_id,
36 const GURL& requestor_url,
37 const Callback& callback);
40 friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>;
42 ~WebstoreInlineInstaller() override;
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()
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;
58 // content::WebContentsObserver interface implementation.
59 void WebContentsDestroyed() override;
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);
68 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller);
71 } // namespace extensions
73 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_