Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / webstore_install_helper.h
blob7cdb86579ac72bb6a982dfd65b29d7820932c9f5
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_INSTALL_HELPER_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "url/gurl.h"
16 namespace base {
17 class DictionaryValue;
18 class Value;
21 namespace chrome {
22 class BitmapFetcher;
25 namespace net {
26 class URLRequestContextGetter;
29 namespace safe_json_parser {
30 class SafeJsonParser;
33 namespace extensions {
35 // This is a class to help dealing with webstore-provided data. It manages
36 // sending work to the utility process for parsing manifests and
37 // fetching/decoding icon data. Clients must implement the
38 // WebstoreInstallHelper::Delegate interface to receive the parsed data.
39 class WebstoreInstallHelper : public base::RefCounted<WebstoreInstallHelper>,
40 public chrome::BitmapFetcherDelegate {
41 public:
42 class Delegate {
43 public:
44 enum InstallHelperResultCode {
45 UNKNOWN_ERROR,
46 ICON_ERROR,
47 MANIFEST_ERROR
50 // Called when we've successfully parsed the manifest and decoded the icon
51 // in the utility process. Ownership of parsed_manifest is transferred.
52 virtual void OnWebstoreParseSuccess(
53 const std::string& id,
54 const SkBitmap& icon,
55 base::DictionaryValue* parsed_manifest) = 0;
57 // Called to indicate a parse failure. The |result_code| parameter should
58 // indicate whether the problem was with the manifest or icon.
59 virtual void OnWebstoreParseFailure(
60 const std::string& id,
61 InstallHelperResultCode result_code,
62 const std::string& error_message) = 0;
64 protected:
65 virtual ~Delegate() {}
68 // It is legal for |icon_url| to be empty.
69 WebstoreInstallHelper(Delegate* delegate,
70 const std::string& id,
71 const std::string& manifest,
72 const GURL& icon_url,
73 net::URLRequestContextGetter* context_getter);
74 void Start();
76 private:
77 friend class base::RefCounted<WebstoreInstallHelper>;
79 ~WebstoreInstallHelper() override;
81 // Callbacks for the SafeJsonParser.
82 void OnJSONParseSucceeded(scoped_ptr<base::Value> result);
83 void OnJSONParseFailed(const std::string& error_message);
85 // Implementing the chrome::BitmapFetcherDelegate interface.
86 void OnFetchComplete(const GURL& url, const SkBitmap* image) override;
88 void ReportResultsIfComplete();
90 // The client who we'll report results back to.
91 Delegate* delegate_;
93 // The extension id of the manifest we're parsing.
94 std::string id_;
96 // The manifest to parse.
97 std::string manifest_;
99 scoped_refptr<safe_json_parser::SafeJsonParser> json_parser_;
101 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an
102 // SkBitmap.
103 GURL icon_url_;
104 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread.
105 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_;
107 // Flags for whether we're done doing icon decoding and manifest parsing.
108 bool icon_decode_complete_;
109 bool manifest_parse_complete_;
111 // The results of successful decoding/parsing.
112 SkBitmap icon_;
113 scoped_ptr<base::DictionaryValue> parsed_manifest_;
115 // A details string for keeping track of any errors.
116 std::string error_;
118 // A code to distinguish between an error with the icon, and an error with the
119 // manifest.
120 Delegate::InstallHelperResultCode parse_error_;
123 } // namespace extensions
125 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_