Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Side by Side Diff: chrome/browser/extensions/webstore_inline_installer.h

Issue 10907104: Support an --install-from-webstore command line switch (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebased Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h" 14 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/webstore_install_helper.h" 15 #include "chrome/browser/extensions/webstore_install_helper.h"
15 #include "chrome/browser/extensions/webstore_installer.h" 16 #include "chrome/browser/extensions/webstore_installer.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 #include "net/url_request/url_fetcher_delegate.h" 19 #include "net/url_request/url_fetcher_delegate.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
20 21
21 22
22 namespace net { 23 namespace net {
23 class URLFetcher; 24 class URLFetcher;
24 } 25 }
25 26
26 namespace extensions { 27 namespace extensions {
27 class Extension; 28 class Extension;
28 class SafeWebstoreResponseParser; 29 class SafeWebstoreResponseParser;
29 30
31 // TODO(asargent) - rename this class to something like
32 // WebstoreStandaloneInstaller.
33 //
30 // Manages inline installs requested by a page (downloads and parses metadata 34 // Manages inline installs requested by a page (downloads and parses metadata
31 // from the webstore, shows the install UI, starts the download once the user 35 // from the webstore, shows the install UI, starts the download once the user
32 // confirms). Clients must implement the WebstoreInlineInstaller::Delegate 36 // confirms). Clients must implement the WebstoreInlineInstaller::Delegate
33 // interface to be notified when the inline install completes (successfully or 37 // interface to be notified when the inline install completes (successfully or
34 // not). The client will not be notified if the WebContents that this install 38 // not). The client will not be notified if the WebContents that this install
35 // request is attached to goes away. 39 // request is attached to goes away.
36 class WebstoreInlineInstaller 40 class WebstoreInlineInstaller
37 : public base::RefCountedThreadSafe<WebstoreInlineInstaller>, 41 : public base::RefCountedThreadSafe<WebstoreInlineInstaller>,
38 public ExtensionInstallPrompt::Delegate, 42 public ExtensionInstallPrompt::Delegate,
39 public content::WebContentsObserver, 43 public content::WebContentsObserver,
40 public net::URLFetcherDelegate, 44 public net::URLFetcherDelegate,
41 public WebstoreInstaller::Delegate, 45 public WebstoreInstaller::Delegate,
42 public WebstoreInstallHelper::Delegate { 46 public WebstoreInstallHelper::Delegate {
43 public: 47 public:
44 class Delegate { 48 enum VerifiedSiteRequired {
45 public: 49 REQUIRE_VERIFIED_SITE,
46 virtual void OnInlineInstallSuccess(int install_id, 50 DO_NOT_REQUIRE_VERIFIED_SITE
47 int return_route_id) = 0;
48 virtual void OnInlineInstallFailure(int install_id,
49 int return_route_id,
50 const std::string& error) = 0;
51 }; 51 };
52 52
53 // A callback for when the install process completes successfully or not. If
54 // there was a failure, |success| will be false and |error| may contain a
55 // developer-readable error message about why it failed.
56 typedef base::Callback<void(bool success, const std::string& error)> Callback;
57
53 WebstoreInlineInstaller(content::WebContents* web_contents, 58 WebstoreInlineInstaller(content::WebContents* web_contents,
54 int install_id,
55 int return_route_id,
56 std::string webstore_item_id, 59 std::string webstore_item_id,
60 VerifiedSiteRequired require_verified_site,
57 GURL requestor_url, 61 GURL requestor_url,
58 Delegate* d); 62 Callback callback);
63
64 void set_skip_post_install_ui(bool skip) { skip_post_install_ui_ = skip; }
65
59 void BeginInstall(); 66 void BeginInstall();
60 67
61 private: 68 private:
62 friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>; 69 friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>;
63 friend class SafeWebstoreResponseParser; 70 friend class SafeWebstoreResponseParser;
64 FRIEND_TEST_ALL_PREFIXES(WebstoreInlineInstallerTest, DomainVerification); 71 FRIEND_TEST_ALL_PREFIXES(WebstoreInlineInstallerTest, DomainVerification);
65 72
66 virtual ~WebstoreInlineInstaller(); 73 virtual ~WebstoreInlineInstaller();
67 74
68 // Several delegate/client inteface implementations follow. The normal flow 75 // Several delegate/client inteface implementations follow. The normal flow
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 virtual void OnExtensionInstallFailure(const std::string& id, 115 virtual void OnExtensionInstallFailure(const std::string& id,
109 const std::string& error) OVERRIDE; 116 const std::string& error) OVERRIDE;
110 117
111 void CompleteInstall(const std::string& error); 118 void CompleteInstall(const std::string& error);
112 119
113 // Checks whether the install is initiated by a page in the verified site 120 // Checks whether the install is initiated by a page in the verified site
114 // (which is at least a domain, but can also have a port or a path). 121 // (which is at least a domain, but can also have a port or a path).
115 static bool IsRequestorURLInVerifiedSite(const GURL& requestor_url, 122 static bool IsRequestorURLInVerifiedSite(const GURL& requestor_url,
116 const std::string& verified_site); 123 const std::string& verified_site);
117 124
118 int install_id_;
119 int return_route_id_;
120 std::string id_; 125 std::string id_;
126 bool require_verified_site_;
121 GURL requestor_url_; 127 GURL requestor_url_;
122 Delegate* delegate_; 128 Callback callback_;
123 scoped_ptr<ExtensionInstallPrompt> install_ui_; 129 scoped_ptr<ExtensionInstallPrompt> install_ui_;
130 bool skip_post_install_ui_;
124 131
125 // For fetching webstore JSON data. 132 // For fetching webstore JSON data.
126 scoped_ptr<net::URLFetcher> webstore_data_url_fetcher_; 133 scoped_ptr<net::URLFetcher> webstore_data_url_fetcher_;
127 134
128 // Extracted from the webstore JSON data response. 135 // Extracted from the webstore JSON data response.
129 std::string localized_name_; 136 std::string localized_name_;
130 std::string localized_description_; 137 std::string localized_description_;
131 std::string localized_user_count_; 138 std::string localized_user_count_;
132 double average_rating_; 139 double average_rating_;
133 int rating_count_; 140 int rating_count_;
134 scoped_ptr<DictionaryValue> webstore_data_; 141 scoped_ptr<DictionaryValue> webstore_data_;
135 scoped_ptr<DictionaryValue> manifest_; 142 scoped_ptr<DictionaryValue> manifest_;
136 scoped_refptr<Extension> dummy_extension_; 143 scoped_refptr<Extension> dummy_extension_;
137 SkBitmap icon_; 144 SkBitmap icon_;
138 145
139 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller); 146 DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller);
140 }; 147 };
141 148
142 } // namespace extensions 149 } // namespace extensions
143 150
144 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_ 151 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698