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 "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
13 #include "content/public/browser/utility_process_host_client.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
18 class DictionaryValue
;
27 class UtilityProcessHost
;
31 class URLRequestContextGetter
;
34 namespace extensions
{
36 // This is a class to help dealing with webstore-provided data. It manages
37 // sending work to the utility process for parsing manifests and
38 // fetching/decoding icon data. Clients must implement the
39 // WebstoreInstallHelper::Delegate interface to receive the parsed data.
40 class WebstoreInstallHelper
: public content::UtilityProcessHostClient
,
41 public chrome::BitmapFetcherDelegate
{
45 enum InstallHelperResultCode
{
51 // Called when we've successfully parsed the manifest and decoded the icon
52 // in the utility process. Ownership of parsed_manifest is transferred.
53 virtual void OnWebstoreParseSuccess(
54 const std::string
& id
,
56 base::DictionaryValue
* parsed_manifest
) = 0;
58 // Called to indicate a parse failure. The |result_code| parameter should
59 // indicate whether the problem was with the manifest or icon.
60 virtual void OnWebstoreParseFailure(
61 const std::string
& id
,
62 InstallHelperResultCode result_code
,
63 const std::string
& error_message
) = 0;
66 virtual ~Delegate() {}
69 // It is legal for |icon_url| to be empty.
70 WebstoreInstallHelper(Delegate
* delegate
,
71 const std::string
& id
,
72 const std::string
& manifest
,
74 net::URLRequestContextGetter
* context_getter
);
78 ~WebstoreInstallHelper() override
;
80 void StartWorkOnIOThread();
81 void ReportResultsIfComplete();
82 void ReportResultFromUIThread();
84 // Implementing pieces of the UtilityProcessHostClient interface.
85 bool OnMessageReceived(const IPC::Message
& message
) override
;
88 void OnJSONParseSucceeded(const base::ListValue
& wrapper
);
89 void OnJSONParseFailed(const std::string
& error_message
);
91 // Implementing the chrome::BitmapFetcherDelegate interface.
92 void OnFetchComplete(const GURL
& url
, const SkBitmap
* image
) override
;
94 // The client who we'll report results back to.
97 // The extension id of the manifest we're parsing.
100 // The manifest to parse.
101 std::string manifest_
;
103 // If |icon_url_| is non-empty, it needs to be fetched and decoded into an
106 net::URLRequestContextGetter
* context_getter_
; // Only usable on UI thread.
107 scoped_ptr
<chrome::BitmapFetcher
> icon_fetcher_
;
109 base::WeakPtr
<content::UtilityProcessHost
> utility_host_
;
111 // Flags for whether we're done doing icon decoding and manifest parsing.
112 bool icon_decode_complete_
;
113 bool manifest_parse_complete_
;
115 // The results of successful decoding/parsing.
117 scoped_ptr
<base::DictionaryValue
> parsed_manifest_
;
119 // A details string for keeping track of any errors.
122 // A code to distinguish between an error with the icon, and an error with the
124 Delegate::InstallHelperResultCode parse_error_
;
127 } // namespace extensions
129 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_