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