Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "content/browser/utility_process_host.h" | |
| 10 #include "content/common/url_fetcher.h" | |
| 11 #include "googleurl/src/gurl.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | |
| 13 | |
| 14 class UtilityProcessHost; | |
| 15 class SkBitmap; | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 class ListValue; | |
| 20 } | |
| 21 | |
| 22 // This is a class to help dealing with webstore-provided data. It manages | |
| 23 // sending work to the utility process for parsing manifests and | |
| 24 // fetching/decoding icon data. Clients must implement the | |
| 25 // WebstoreInstallHelper::Delegate interface to receive the parsed data. | |
| 26 class WebstoreInstallHelper : public UtilityProcessHost::Client, | |
| 27 public URLFetcher::Delegate { | |
| 28 public: | |
| 29 class Delegate { | |
| 30 public: | |
| 31 enum InstallHelperResultCode { | |
| 32 UNKNOWN_ERROR, | |
| 33 ICON_ERROR, | |
| 34 MANIFEST_ERROR | |
| 35 }; | |
| 36 | |
| 37 // Called when we've successfully parsed the manifest and decoded the icon | |
| 38 // in the utility process. Ownership of parsed_manifest is transferred. | |
| 39 virtual void OnWebstoreParseSuccess( | |
| 40 const SkBitmap& icon, | |
| 41 base::DictionaryValue* parsed_manifest) = 0; | |
| 42 | |
| 43 // Called to indicate a parse failure. The |result_code| parameter should | |
| 44 // indicate whether the problem was with the manifest or icon. | |
| 45 virtual void OnWebstoreParseFailure( | |
| 46 InstallHelperResultCode result_code, | |
| 47 const std::string& error_message) = 0; | |
| 48 }; | |
| 49 | |
| 50 WebstoreInstallHelper(Delegate* delegate, | |
|
asargent_no_longer_on_chrome
2011/08/25 17:57:02
nit: include a comment here that only one of icon_
Mihai Parparita -not on Chrome
2011/08/25 18:12:10
Done.
| |
| 51 const std::string& manifest, | |
| 52 const std::string& icon_data, | |
| 53 const GURL& icon_url, | |
| 54 net::URLRequestContextGetter* context_getter); | |
| 55 void Start(); | |
| 56 | |
| 57 private: | |
| 58 ~WebstoreInstallHelper(); | |
| 59 | |
| 60 void StartWorkOnIOThread(); | |
| 61 void StartFetchedImageDecode(); | |
| 62 void ReportResultsIfComplete(); | |
| 63 void ReportResultFromUIThread(); | |
| 64 | |
| 65 // Implementing the URLFetcher::Delegate interface. | |
| 66 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | |
| 67 | |
| 68 // Implementing pieces of the UtilityProcessHost::Client interface. | |
| 69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 70 | |
| 71 // Message handlers. | |
| 72 void OnDecodeImageSucceeded(const SkBitmap& decoded_image); | |
| 73 void OnDecodeImageFailed(); | |
| 74 void OnJSONParseSucceeded(const base::ListValue& wrapper); | |
| 75 void OnJSONParseFailed(const std::string& error_message); | |
| 76 | |
| 77 // The client who we'll report results back to. | |
| 78 Delegate* delegate_; | |
| 79 | |
| 80 // The manifest to parse. | |
| 81 std::string manifest_; | |
| 82 | |
| 83 // Only one of these should be non-empty. If |icon_base64_data_| is non-emtpy, | |
| 84 // it's a base64-encoded string that needs to be parsed into an SkBitmap. If | |
| 85 // |icon_url_| is non-empty, it needs to be fetched and decoded into an | |
| 86 // SkBitmap. | |
| 87 std::string icon_base64_data_; | |
| 88 GURL icon_url_; | |
| 89 std::vector<unsigned char> fetched_icon_data_; | |
| 90 | |
| 91 // For fetching the icon, if needed. | |
| 92 scoped_ptr<URLFetcher> url_fetcher_; | |
| 93 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. | |
| 94 | |
| 95 UtilityProcessHost* utility_host_; | |
| 96 | |
| 97 // Flags for whether we're done doing icon decoding and manifest parsing. | |
| 98 bool icon_decode_complete_; | |
| 99 bool manifest_parse_complete_; | |
| 100 | |
| 101 // The results of succesful decoding/parsing. | |
| 102 SkBitmap icon_; | |
| 103 scoped_ptr<base::DictionaryValue> parsed_manifest_; | |
| 104 | |
| 105 // A details string for keeping track of any errors. | |
| 106 std::string error_; | |
| 107 | |
| 108 // A code to distinguish between an error with the icon, and an error with the | |
| 109 // manifest. | |
| 110 Delegate::InstallHelperResultCode parse_error_; | |
| 111 }; | |
| 112 | |
| 113 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | |
| OLD | NEW |