| OLD | NEW |
| 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_INSTALL_HELPER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "content/browser/utility_process_host.h" | 9 #include <vector> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/public/browser/utility_process_host_client.h" |
| 10 #include "content/public/common/url_fetcher_delegate.h" | 14 #include "content/public/common/url_fetcher_delegate.h" |
| 11 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 | 17 |
| 14 class UtilityProcessHost; | |
| 15 class SkBitmap; | 18 class SkBitmap; |
| 16 | 19 |
| 17 namespace base { | 20 namespace base { |
| 18 class DictionaryValue; | 21 class DictionaryValue; |
| 19 class ListValue; | 22 class ListValue; |
| 20 } | 23 } |
| 21 | 24 |
| 25 namespace content { |
| 26 class UtilityProcessHost; |
| 27 } |
| 28 |
| 22 namespace net { | 29 namespace net { |
| 23 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
| 24 } | 31 } |
| 25 | 32 |
| 26 // This is a class to help dealing with webstore-provided data. It manages | 33 // This is a class to help dealing with webstore-provided data. It manages |
| 27 // sending work to the utility process for parsing manifests and | 34 // sending work to the utility process for parsing manifests and |
| 28 // fetching/decoding icon data. Clients must implement the | 35 // fetching/decoding icon data. Clients must implement the |
| 29 // WebstoreInstallHelper::Delegate interface to receive the parsed data. | 36 // WebstoreInstallHelper::Delegate interface to receive the parsed data. |
| 30 class WebstoreInstallHelper : public UtilityProcessHost::Client, | 37 class WebstoreInstallHelper : public content::UtilityProcessHostClient, |
| 31 public content::URLFetcherDelegate { | 38 public content::URLFetcherDelegate { |
| 32 public: | 39 public: |
| 33 class Delegate { | 40 class Delegate { |
| 34 public: | 41 public: |
| 35 enum InstallHelperResultCode { | 42 enum InstallHelperResultCode { |
| 36 UNKNOWN_ERROR, | 43 UNKNOWN_ERROR, |
| 37 ICON_ERROR, | 44 ICON_ERROR, |
| 38 MANIFEST_ERROR | 45 MANIFEST_ERROR |
| 39 }; | 46 }; |
| 40 | 47 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 67 virtual ~WebstoreInstallHelper(); | 74 virtual ~WebstoreInstallHelper(); |
| 68 | 75 |
| 69 void StartWorkOnIOThread(); | 76 void StartWorkOnIOThread(); |
| 70 void StartFetchedImageDecode(); | 77 void StartFetchedImageDecode(); |
| 71 void ReportResultsIfComplete(); | 78 void ReportResultsIfComplete(); |
| 72 void ReportResultFromUIThread(); | 79 void ReportResultFromUIThread(); |
| 73 | 80 |
| 74 // Implementing the content::URLFetcherDelegate interface. | 81 // Implementing the content::URLFetcherDelegate interface. |
| 75 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 82 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 76 | 83 |
| 77 // Implementing pieces of the UtilityProcessHost::Client interface. | 84 // Implementing pieces of the UtilityProcessHostClient interface. |
| 78 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 85 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 79 | 86 |
| 80 // Message handlers. | 87 // Message handlers. |
| 81 void OnDecodeImageSucceeded(const SkBitmap& decoded_image); | 88 void OnDecodeImageSucceeded(const SkBitmap& decoded_image); |
| 82 void OnDecodeImageFailed(); | 89 void OnDecodeImageFailed(); |
| 83 void OnJSONParseSucceeded(const base::ListValue& wrapper); | 90 void OnJSONParseSucceeded(const base::ListValue& wrapper); |
| 84 void OnJSONParseFailed(const std::string& error_message); | 91 void OnJSONParseFailed(const std::string& error_message); |
| 85 | 92 |
| 86 // The client who we'll report results back to. | 93 // The client who we'll report results back to. |
| 87 Delegate* delegate_; | 94 Delegate* delegate_; |
| 88 | 95 |
| 89 // The extension id of the manifest we're parsing. | 96 // The extension id of the manifest we're parsing. |
| 90 std::string id_; | 97 std::string id_; |
| 91 | 98 |
| 92 // The manifest to parse. | 99 // The manifest to parse. |
| 93 std::string manifest_; | 100 std::string manifest_; |
| 94 | 101 |
| 95 // Only one of these should be non-empty. If |icon_base64_data_| is non-emtpy, | 102 // Only one of these should be non-empty. If |icon_base64_data_| is non-emtpy, |
| 96 // it's a base64-encoded string that needs to be parsed into an SkBitmap. If | 103 // it's a base64-encoded string that needs to be parsed into an SkBitmap. If |
| 97 // |icon_url_| is non-empty, it needs to be fetched and decoded into an | 104 // |icon_url_| is non-empty, it needs to be fetched and decoded into an |
| 98 // SkBitmap. | 105 // SkBitmap. |
| 99 std::string icon_base64_data_; | 106 std::string icon_base64_data_; |
| 100 GURL icon_url_; | 107 GURL icon_url_; |
| 101 std::vector<unsigned char> fetched_icon_data_; | 108 std::vector<unsigned char> fetched_icon_data_; |
| 102 | 109 |
| 103 // For fetching the icon, if needed. | 110 // For fetching the icon, if needed. |
| 104 scoped_ptr<content::URLFetcher> url_fetcher_; | 111 scoped_ptr<content::URLFetcher> url_fetcher_; |
| 105 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. | 112 net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. |
| 106 | 113 |
| 107 base::WeakPtr<UtilityProcessHost> utility_host_; | 114 base::WeakPtr<content::UtilityProcessHost> utility_host_; |
| 108 | 115 |
| 109 // Flags for whether we're done doing icon decoding and manifest parsing. | 116 // Flags for whether we're done doing icon decoding and manifest parsing. |
| 110 bool icon_decode_complete_; | 117 bool icon_decode_complete_; |
| 111 bool manifest_parse_complete_; | 118 bool manifest_parse_complete_; |
| 112 | 119 |
| 113 // The results of succesful decoding/parsing. | 120 // The results of succesful decoding/parsing. |
| 114 SkBitmap icon_; | 121 SkBitmap icon_; |
| 115 scoped_ptr<base::DictionaryValue> parsed_manifest_; | 122 scoped_ptr<base::DictionaryValue> parsed_manifest_; |
| 116 | 123 |
| 117 // A details string for keeping track of any errors. | 124 // A details string for keeping track of any errors. |
| 118 std::string error_; | 125 std::string error_; |
| 119 | 126 |
| 120 // A code to distinguish between an error with the icon, and an error with the | 127 // A code to distinguish between an error with the icon, and an error with the |
| 121 // manifest. | 128 // manifest. |
| 122 Delegate::InstallHelperResultCode parse_error_; | 129 Delegate::InstallHelperResultCode parse_error_; |
| 123 }; | 130 }; |
| 124 | 131 |
| 125 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ | 132 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ |
| OLD | NEW |