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