OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/utility/utility_handler.h" | 5 #include "extensions/utility/utility_handler.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "content/public/utility/utility_thread.h" | 9 #include "content/public/utility/utility_thread.h" |
10 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
11 #include "extensions/common/extension_l10n_util.h" | 11 #include "extensions/common/extension_l10n_util.h" |
12 #include "extensions/common/extension_unpacker.mojom.h" | 12 #include "extensions/common/extension_unpacker.mojom.h" |
13 #include "extensions/common/extension_utility_messages.h" | |
14 #include "extensions/common/extensions_client.h" | 13 #include "extensions/common/extensions_client.h" |
15 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
| 15 #include "extensions/common/manifest_parser.mojom.h" |
16 #include "extensions/common/update_manifest.h" | 16 #include "extensions/common/update_manifest.h" |
17 #include "extensions/strings/grit/extensions_strings.h" | 17 #include "extensions/strings/grit/extensions_strings.h" |
18 #include "extensions/utility/unpacker.h" | 18 #include "extensions/utility/unpacker.h" |
19 #include "ipc/ipc_message.h" | |
20 #include "ipc/ipc_message_macros.h" | |
21 #include "mojo/public/cpp/bindings/strong_binding.h" | 19 #include "mojo/public/cpp/bindings/strong_binding.h" |
22 #include "services/service_manager/public/cpp/interface_registry.h" | 20 #include "services/service_manager/public/cpp/interface_registry.h" |
23 #include "third_party/zlib/google/zip.h" | 21 #include "third_party/zlib/google/zip.h" |
24 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/ui_base_switches.h" | 23 #include "ui/base/ui_base_switches.h" |
26 | 24 |
27 namespace extensions { | 25 namespace extensions { |
28 | 26 |
29 namespace { | 27 namespace { |
30 | 28 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // Add install warnings. | 92 // Add install warnings. |
95 return zip::UnzipWithFilterCallback( | 93 return zip::UnzipWithFilterCallback( |
96 file, path, | 94 file, path, |
97 base::Bind(&Unpacker::ShouldExtractFile, internal.is_theme()), | 95 base::Bind(&Unpacker::ShouldExtractFile, internal.is_theme()), |
98 true /* log_skipped_files */); | 96 true /* log_skipped_files */); |
99 } | 97 } |
100 | 98 |
101 DISALLOW_COPY_AND_ASSIGN(ExtensionUnpackerImpl); | 99 DISALLOW_COPY_AND_ASSIGN(ExtensionUnpackerImpl); |
102 }; | 100 }; |
103 | 101 |
| 102 class ManifestParserImpl : public extensions::mojom::ManifestParser { |
| 103 public: |
| 104 ManifestParserImpl() = default; |
| 105 ~ManifestParserImpl() override = default; |
| 106 |
| 107 static void Create(extensions::mojom::ManifestParserRequest request) { |
| 108 mojo::MakeStrongBinding(base::MakeUnique<ManifestParserImpl>(), |
| 109 std::move(request)); |
| 110 } |
| 111 |
| 112 private: |
| 113 void Parse(const std::string& xml, const ParseCallback& callback) override { |
| 114 UpdateManifest manifest; |
| 115 if (manifest.Parse(xml)) { |
| 116 callback.Run(manifest.results()); |
| 117 } else { |
| 118 LOG(WARNING) << "Error parsing update manifest:\n" << manifest.errors(); |
| 119 callback.Run(base::nullopt); |
| 120 } |
| 121 } |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(ManifestParserImpl); |
| 124 }; |
| 125 |
104 } // namespace | 126 } // namespace |
105 | 127 |
106 UtilityHandler::UtilityHandler() = default; | 128 namespace utility_handler { |
107 | 129 |
108 UtilityHandler::~UtilityHandler() = default; | 130 void UtilityThreadStarted() { |
109 | |
110 // static | |
111 void UtilityHandler::UtilityThreadStarted() { | |
112 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 131 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
113 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); | 132 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); |
114 if (!lang.empty()) | 133 if (!lang.empty()) |
115 extension_l10n_util::SetProcessLocale(lang); | 134 extension_l10n_util::SetProcessLocale(lang); |
116 } | 135 } |
117 | 136 |
118 // static | 137 void ExposeInterfacesToBrowser(service_manager::InterfaceRegistry* registry, |
119 void UtilityHandler::ExposeInterfacesToBrowser( | 138 bool running_elevated) { |
120 service_manager::InterfaceRegistry* registry, | |
121 bool running_elevated) { | |
122 // If our process runs with elevated privileges, only add elevated Mojo | 139 // If our process runs with elevated privileges, only add elevated Mojo |
123 // interfaces to the interface registry. | 140 // interfaces to the interface registry. |
124 if (running_elevated) | 141 if (running_elevated) |
125 return; | 142 return; |
126 | 143 |
127 registry->AddInterface(base::Bind(&ExtensionUnpackerImpl::Create)); | 144 registry->AddInterface(base::Bind(&ExtensionUnpackerImpl::Create)); |
| 145 registry->AddInterface(base::Bind(&ManifestParserImpl::Create)); |
128 } | 146 } |
129 | 147 |
130 bool UtilityHandler::OnMessageReceived(const IPC::Message& message) { | 148 } // namespace utility_handler |
131 bool handled = true; | |
132 IPC_BEGIN_MESSAGE_MAP(UtilityHandler, message) | |
133 IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest, | |
134 OnParseUpdateManifest) | |
135 IPC_MESSAGE_UNHANDLED(handled = false) | |
136 IPC_END_MESSAGE_MAP() | |
137 return handled; | |
138 } | |
139 | |
140 void UtilityHandler::OnParseUpdateManifest(const std::string& xml) { | |
141 UpdateManifest manifest; | |
142 if (!manifest.Parse(xml)) { | |
143 content::UtilityThread::Get()->Send( | |
144 new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed( | |
145 manifest.errors())); | |
146 } else { | |
147 content::UtilityThread::Get()->Send( | |
148 new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded( | |
149 manifest.results())); | |
150 } | |
151 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
152 } | |
153 | 149 |
154 } // namespace extensions | 150 } // namespace extensions |
OLD | NEW |