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_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/utility_process_host_client.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
20 class DictionaryValue
;
25 class UtilityProcessHost
;
30 class URLRequestContextGetter
;
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 content::UtilityProcessHostClient
,
40 public net::URLFetcherDelegate
{
44 enum InstallHelperResultCode
{
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
,
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;
65 virtual ~Delegate() {}
68 // Only one of |icon_data| (based64-encoded icon data) or |icon_url| can be
69 // specified, but it is legal for both to be empty.
70 WebstoreInstallHelper(Delegate
* delegate
,
71 const std::string
& id
,
72 const std::string
& manifest
,
73 const std::string
& icon_data
,
75 net::URLRequestContextGetter
* context_getter
);
79 virtual ~WebstoreInstallHelper();
81 void StartWorkOnIOThread();
82 void StartFetchedImageDecode();
83 void ReportResultsIfComplete();
84 void ReportResultFromUIThread();
86 // Implementing the net::URLFetcherDelegate interface.
87 virtual void OnURLFetchComplete(const net::URLFetcher
* source
) OVERRIDE
;
89 // Implementing pieces of the UtilityProcessHostClient interface.
90 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
93 void OnDecodeImageSucceeded(const SkBitmap
& decoded_image
);
94 void OnDecodeImageFailed();
95 void OnJSONParseSucceeded(const base::ListValue
& wrapper
);
96 void OnJSONParseFailed(const std::string
& error_message
);
98 // The client who we'll report results back to.
101 // The extension id of the manifest we're parsing.
104 // The manifest to parse.
105 std::string manifest_
;
107 // Only one of these should be non-empty. If |icon_base64_data_| is non-emtpy,
108 // it's a base64-encoded string that needs to be parsed into an SkBitmap. If
109 // |icon_url_| is non-empty, it needs to be fetched and decoded into an
111 std::string icon_base64_data_
;
113 std::vector
<unsigned char> fetched_icon_data_
;
115 // For fetching the icon, if needed.
116 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
117 net::URLRequestContextGetter
* context_getter_
; // Only usable on UI thread.
119 base::WeakPtr
<content::UtilityProcessHost
> utility_host_
;
121 // Flags for whether we're done doing icon decoding and manifest parsing.
122 bool icon_decode_complete_
;
123 bool manifest_parse_complete_
;
125 // The results of succesful decoding/parsing.
127 scoped_ptr
<base::DictionaryValue
> parsed_manifest_
;
129 // A details string for keeping track of any errors.
132 // A code to distinguish between an error with the icon, and an error with the
134 Delegate::InstallHelperResultCode parse_error_
;
137 } // namespace extensions
139 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_