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 #include "chrome/browser/extensions/webstore_inline_installer.h" | 5 #include "chrome/browser/extensions/webstore_inline_installer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/crx_installer.h" | 13 #include "chrome/browser/extensions/crx_installer.h" |
14 #include "chrome/browser/extensions/extension_install_dialog.h" | 14 #include "chrome/browser/extensions/extension_install_dialog.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_utility_messages.h" | 17 #include "chrome/common/chrome_utility_messages.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/extensions/url_pattern.h" | 20 #include "chrome/common/extensions/url_pattern.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "content/browser/utility_process_host.h" | |
23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/utility_process_host.h" |
| 24 #include "content/public/browser/utility_process_host_client.h" |
24 #include "content/public/common/url_fetcher.h" | 25 #include "content/public/common/url_fetcher.h" |
25 #include "net/base/escape.h" | 26 #include "net/base/escape.h" |
26 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
28 | 29 |
29 using content::BrowserThread; | 30 using content::BrowserThread; |
30 using content::OpenURLParams; | 31 using content::OpenURLParams; |
| 32 using content::UtilityProcessHost; |
| 33 using content::UtilityProcessHostClient; |
31 using content::WebContents; | 34 using content::WebContents; |
32 | 35 |
33 const char kManifestKey[] = "manifest"; | 36 const char kManifestKey[] = "manifest"; |
34 const char kIconUrlKey[] = "icon_url"; | 37 const char kIconUrlKey[] = "icon_url"; |
35 const char kLocalizedNameKey[] = "localized_name"; | 38 const char kLocalizedNameKey[] = "localized_name"; |
36 const char kLocalizedDescriptionKey[] = "localized_description"; | 39 const char kLocalizedDescriptionKey[] = "localized_description"; |
37 const char kUsersKey[] = "users"; | 40 const char kUsersKey[] = "users"; |
38 const char kAverageRatingKey[] = "average_rating"; | 41 const char kAverageRatingKey[] = "average_rating"; |
39 const char kRatingCountKey[] = "rating_count"; | 42 const char kRatingCountKey[] = "rating_count"; |
40 const char kVerifiedSiteKey[] = "verified_site"; | 43 const char kVerifiedSiteKey[] = "verified_site"; |
41 const char kInlineInstallNotSupportedKey[] = "inline_install_not_supported"; | 44 const char kInlineInstallNotSupportedKey[] = "inline_install_not_supported"; |
42 const char kRedirectUrlKey[] = "redirect_url"; | 45 const char kRedirectUrlKey[] = "redirect_url"; |
43 | 46 |
44 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; | 47 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; |
45 const char kWebstoreRequestError[] = | 48 const char kWebstoreRequestError[] = |
46 "Could not fetch data from the Chrome Web Store"; | 49 "Could not fetch data from the Chrome Web Store"; |
47 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; | 50 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; |
48 const char kInvalidManifestError[] = "Invalid manifest"; | 51 const char kInvalidManifestError[] = "Invalid manifest"; |
49 const char kUserCancelledError[] = "User cancelled install"; | 52 const char kUserCancelledError[] = "User cancelled install"; |
50 const char kNoVerifiedSiteError[] = | 53 const char kNoVerifiedSiteError[] = |
51 "Inline installs can only be initiated for Chrome Web Store items that " | 54 "Inline installs can only be initiated for Chrome Web Store items that " |
52 "have a verified site"; | 55 "have a verified site"; |
53 const char kNotFromVerifiedSiteError[] = | 56 const char kNotFromVerifiedSiteError[] = |
54 "Installs can only be initiated by the Chrome Web Store item's verified " | 57 "Installs can only be initiated by the Chrome Web Store item's verified " |
55 "site"; | 58 "site"; |
56 const char kInlineInstallSupportedError[] = | 59 const char kInlineInstallSupportedError[] = |
57 "Inline installation is not supported for this item. The user will be " | 60 "Inline installation is not supported for this item. The user will be " |
58 "redirected to the Chrome Web Store."; | 61 "redirected to the Chrome Web Store."; |
59 | 62 |
60 class SafeWebstoreResponseParser : public UtilityProcessHost::Client { | 63 class SafeWebstoreResponseParser : public UtilityProcessHostClient { |
61 public: | 64 public: |
62 SafeWebstoreResponseParser(WebstoreInlineInstaller *client, | 65 SafeWebstoreResponseParser(WebstoreInlineInstaller *client, |
63 const std::string& webstore_data) | 66 const std::string& webstore_data) |
64 : client_(client), | 67 : client_(client), |
65 webstore_data_(webstore_data), | 68 webstore_data_(webstore_data) {} |
66 utility_host_(NULL) {} | |
67 | 69 |
68 void Start() { | 70 void Start() { |
69 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
70 BrowserThread::PostTask( | 72 BrowserThread::PostTask( |
71 BrowserThread::IO, | 73 BrowserThread::IO, |
72 FROM_HERE, | 74 FROM_HERE, |
73 base::Bind(&SafeWebstoreResponseParser::StartWorkOnIOThread, this)); | 75 base::Bind(&SafeWebstoreResponseParser::StartWorkOnIOThread, this)); |
74 } | 76 } |
75 | 77 |
76 void StartWorkOnIOThread() { | 78 void StartWorkOnIOThread() { |
77 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 79 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
78 utility_host_ = new UtilityProcessHost(this, BrowserThread::IO); | 80 UtilityProcessHost* host = |
79 utility_host_->set_use_linux_zygote(true); | 81 UtilityProcessHost::Create(this, BrowserThread::IO); |
80 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(webstore_data_)); | 82 host->EnableZygote(); |
| 83 host->Send(new ChromeUtilityMsg_ParseJSON(webstore_data_)); |
81 } | 84 } |
82 | 85 |
83 // Implementing pieces of the UtilityProcessHost::Client interface. | 86 // Implementing pieces of the UtilityProcessHostClient interface. |
84 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 87 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
85 bool handled = true; | 88 bool handled = true; |
86 IPC_BEGIN_MESSAGE_MAP(SafeWebstoreResponseParser, message) | 89 IPC_BEGIN_MESSAGE_MAP(SafeWebstoreResponseParser, message) |
87 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, | 90 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, |
88 OnJSONParseSucceeded) | 91 OnJSONParseSucceeded) |
89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, | 92 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, |
90 OnJSONParseFailed) | 93 OnJSONParseFailed) |
91 IPC_MESSAGE_UNHANDLED(handled = false) | 94 IPC_MESSAGE_UNHANDLED(handled = false) |
92 IPC_END_MESSAGE_MAP() | 95 IPC_END_MESSAGE_MAP() |
93 return handled; | 96 return handled; |
(...skipping 15 matching lines...) Expand all Loading... |
109 | 112 |
110 virtual void OnJSONParseFailed(const std::string& error_message) { | 113 virtual void OnJSONParseFailed(const std::string& error_message) { |
111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 114 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
112 error_ = error_message; | 115 error_ = error_message; |
113 ReportResults(); | 116 ReportResults(); |
114 } | 117 } |
115 | 118 |
116 void ReportResults() { | 119 void ReportResults() { |
117 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 120 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
118 | 121 |
119 // The utility_host_ will take care of deleting itself after this call. | |
120 utility_host_ = NULL; | |
121 | |
122 BrowserThread::PostTask( | 122 BrowserThread::PostTask( |
123 BrowserThread::UI, | 123 BrowserThread::UI, |
124 FROM_HERE, | 124 FROM_HERE, |
125 base::Bind(&SafeWebstoreResponseParser::ReportResultOnUIThread, this)); | 125 base::Bind(&SafeWebstoreResponseParser::ReportResultOnUIThread, this)); |
126 } | 126 } |
127 | 127 |
128 void ReportResultOnUIThread() { | 128 void ReportResultOnUIThread() { |
129 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
130 if (error_.empty() && parsed_webstore_data_.get()) { | 130 if (error_.empty() && parsed_webstore_data_.get()) { |
131 client_->OnWebstoreResponseParseSuccess(parsed_webstore_data_.release()); | 131 client_->OnWebstoreResponseParseSuccess(parsed_webstore_data_.release()); |
132 } else { | 132 } else { |
133 client_->OnWebstoreResponseParseFailure(error_); | 133 client_->OnWebstoreResponseParseFailure(error_); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 private: | 137 private: |
138 virtual ~SafeWebstoreResponseParser() {} | 138 virtual ~SafeWebstoreResponseParser() {} |
139 | 139 |
140 WebstoreInlineInstaller* client_; | 140 WebstoreInlineInstaller* client_; |
141 | 141 |
142 std::string webstore_data_; | 142 std::string webstore_data_; |
143 | |
144 UtilityProcessHost* utility_host_; | |
145 | |
146 std::string error_; | 143 std::string error_; |
147 scoped_ptr<DictionaryValue> parsed_webstore_data_; | 144 scoped_ptr<DictionaryValue> parsed_webstore_data_; |
148 }; | 145 }; |
149 | 146 |
150 WebstoreInlineInstaller::WebstoreInlineInstaller(WebContents* web_contents, | 147 WebstoreInlineInstaller::WebstoreInlineInstaller(WebContents* web_contents, |
151 int install_id, | 148 int install_id, |
152 std::string webstore_item_id, | 149 std::string webstore_item_id, |
153 GURL requestor_url, | 150 GURL requestor_url, |
154 Delegate* delegate) | 151 Delegate* delegate) |
155 : content::WebContentsObserver(web_contents), | 152 : content::WebContentsObserver(web_contents), |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 if (web_contents()) { | 447 if (web_contents()) { |
451 if (error.empty()) { | 448 if (error.empty()) { |
452 delegate_->OnInlineInstallSuccess(install_id_); | 449 delegate_->OnInlineInstallSuccess(install_id_); |
453 } else { | 450 } else { |
454 delegate_->OnInlineInstallFailure(install_id_, error); | 451 delegate_->OnInlineInstallFailure(install_id_, error); |
455 } | 452 } |
456 } | 453 } |
457 | 454 |
458 Release(); // Matches the AddRef in BeginInstall. | 455 Release(); // Matches the AddRef in BeginInstall. |
459 } | 456 } |
OLD | NEW |