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_install_helper.h" | 5 #include "chrome/browser/extensions/webstore_install_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/utf_string_conversions.h" | |
10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
13 #include "chrome/common/chrome_utility_messages.h" | 14 #include "chrome/common/chrome_utility_messages.h" |
14 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 15 #include "components/safe_json_parser/safe_json_parser_messages.h" |
15 #include "chrome/grit/generated_resources.h" | |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/utility_process_host.h" | 17 #include "content/public/browser/utility_process_host.h" |
18 #include "grit/components_strings.h" | |
18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 using content::UtilityProcessHost; | 24 using content::UtilityProcessHost; |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const char kImageDecodeError[] = "Image decode failed"; | 28 const char kImageDecodeError[] = "Image decode failed"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 BrowserThread::PostTask( | 68 BrowserThread::PostTask( |
68 BrowserThread::IO, | 69 BrowserThread::IO, |
69 FROM_HERE, | 70 FROM_HERE, |
70 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this)); | 71 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this)); |
71 } | 72 } |
72 | 73 |
73 void WebstoreInstallHelper::StartWorkOnIOThread() { | 74 void WebstoreInstallHelper::StartWorkOnIOThread() { |
74 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 75 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
75 utility_host_ = UtilityProcessHost::Create( | 76 utility_host_ = UtilityProcessHost::Create( |
76 this, base::ThreadTaskRunnerHandle::Get().get())->AsWeakPtr(); | 77 this, base::ThreadTaskRunnerHandle::Get().get())->AsWeakPtr(); |
77 utility_host_->SetName(l10n_util::GetStringUTF16( | 78 utility_host_->SetName( |
78 IDS_UTILITY_PROCESS_JSON_PARSER_NAME)); | 79 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_JSON_PARSER_NAME)); |
79 utility_host_->StartBatchMode(); | 80 utility_host_->StartBatchMode(); |
80 | 81 |
81 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); | 82 utility_host_->Send(new SafeJsonParserMsg_ParseJSON(manifest_)); |
82 } | 83 } |
83 | 84 |
84 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) { | 85 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) { |
85 bool handled = true; | 86 bool handled = true; |
86 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message) | 87 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message) |
87 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, | 88 IPC_MESSAGE_HANDLER(SafeJsonParserHostMsg_ParseJSON_Succeeded, |
Robert Sesek
2015/06/01 20:25:48
nit: preserve this indenting
Eran Messeri
2015/06/02 10:31:42
N/A - this class was just converted to use the Saf
| |
88 OnJSONParseSucceeded) | 89 OnJSONParseSucceeded) |
89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, | 90 IPC_MESSAGE_HANDLER(SafeJsonParserHostMsg_ParseJSON_Failed, OnJSONParseFailed) |
90 OnJSONParseFailed) | |
91 IPC_MESSAGE_UNHANDLED(handled = false) | 91 IPC_MESSAGE_UNHANDLED(handled = false) |
92 IPC_END_MESSAGE_MAP() | 92 IPC_END_MESSAGE_MAP() |
93 return handled; | 93 return handled; |
94 } | 94 } |
95 | 95 |
96 void WebstoreInstallHelper::OnFetchComplete(const GURL& url, | 96 void WebstoreInstallHelper::OnFetchComplete(const GURL& url, |
97 const SkBitmap* image) { | 97 const SkBitmap* image) { |
98 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 98 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
99 // OnFetchComplete should only be called as icon_fetcher_ delegate to avoid | 99 // OnFetchComplete should only be called as icon_fetcher_ delegate to avoid |
100 // unbalanced Release(). | 100 // unbalanced Release(). |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 | 159 |
160 void WebstoreInstallHelper::ReportResultFromUIThread() { | 160 void WebstoreInstallHelper::ReportResultFromUIThread() { |
161 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 161 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
162 if (error_.empty() && parsed_manifest_) | 162 if (error_.empty() && parsed_manifest_) |
163 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); | 163 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); |
164 else | 164 else |
165 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); | 165 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); |
166 } | 166 } |
167 | 167 |
168 } // namespace extensions | 168 } // namespace extensions |
OLD | NEW |