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