Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: content/browser/mojo/mojo_shell_context.cc

Issue 2259903002: Enforce capability spec renderer <--> browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/mojo/mojo_shell_context.h" 5 #include "content/browser/mojo/mojo_shell_context.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/json/json_reader.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "content/browser/gpu/gpu_process_host.h" 17 #include "content/browser/gpu/gpu_process_host.h"
17 #include "content/common/mojo/constants.h" 18 #include "content/browser/mojo/merge_dictionary.h"
18 #include "content/common/mojo/mojo_shell_connection_impl.h" 19 #include "content/common/mojo/mojo_shell_connection_impl.h"
19 #include "content/grit/content_resources.h" 20 #include "content/grit/content_resources.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/content_browser_client.h" 22 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/utility_process_host.h" 23 #include "content/public/browser/utility_process_host.h"
23 #include "content/public/browser/utility_process_host_client.h" 24 #include "content/public/browser/utility_process_host_client.h"
24 #include "content/public/common/content_client.h" 25 #include "content/public/common/content_client.h"
25 #include "content/public/common/mojo_shell_connection.h" 26 #include "content/public/common/mojo_shell_connection.h"
27 #include "content/public/common/service_names.h"
26 #include "mojo/edk/embedder/embedder.h" 28 #include "mojo/edk/embedder/embedder.h"
27 #include "services/catalog/catalog.h" 29 #include "services/catalog/catalog.h"
28 #include "services/catalog/manifest_provider.h" 30 #include "services/catalog/manifest_provider.h"
29 #include "services/catalog/store.h" 31 #include "services/catalog/store.h"
30 #include "services/file/public/cpp/constants.h" 32 #include "services/file/public/cpp/constants.h"
31 #include "services/shell/connect_params.h" 33 #include "services/shell/connect_params.h"
32 #include "services/shell/native_runner.h" 34 #include "services/shell/native_runner.h"
33 #include "services/shell/public/cpp/connector.h" 35 #include "services/shell/public/cpp/connector.h"
34 #include "services/shell/public/cpp/service.h" 36 #include "services/shell/public/cpp/service.h"
35 #include "services/shell/public/interfaces/service.mojom.h" 37 #include "services/shell/public/interfaces/service.mojom.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 103
102 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS 104 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS
103 105
104 // A ManifestProvider which resolves application names to builtin manifest 106 // A ManifestProvider which resolves application names to builtin manifest
105 // resources for the catalog service to consume. 107 // resources for the catalog service to consume.
106 class BuiltinManifestProvider : public catalog::ManifestProvider { 108 class BuiltinManifestProvider : public catalog::ManifestProvider {
107 public: 109 public:
108 BuiltinManifestProvider() {} 110 BuiltinManifestProvider() {}
109 ~BuiltinManifestProvider() override {} 111 ~BuiltinManifestProvider() override {}
110 112
111 void AddManifests(std::unique_ptr< 113 void AddManifestValue(const std::string& name,
112 ContentBrowserClient::MojoApplicationManifestMap> manifests) { 114 std::unique_ptr<base::Value> manifest_contents) {
113 DCHECK(!manifests_); 115 auto result = manifests_.insert(
114 manifests_ = std::move(manifests); 116 std::make_pair(name, std::move(manifest_contents)));
115 }
116
117 void AddManifestResource(const std::string& name, int resource_id) {
118 std::string contents = GetContentClient()->GetDataResource(
119 resource_id, ui::ScaleFactor::SCALE_FACTOR_NONE).as_string();
120 DCHECK(!contents.empty());
121
122 DCHECK(manifests_);
123 auto result = manifests_->insert(std::make_pair(name, contents));
124 DCHECK(result.second) << "Duplicate manifest entry: " << name; 117 DCHECK(result.second) << "Duplicate manifest entry: " << name;
125 } 118 }
126 119
127 private: 120 private:
128 // catalog::ManifestProvider: 121 // catalog::ManifestProvider:
129 bool GetApplicationManifest(const base::StringPiece& name, 122 std::unique_ptr<base::Value> GetManifest(const std::string& name) override {
130 std::string* manifest_contents) override { 123 auto it = manifests_.find(name);
131 auto manifest_it = manifests_->find(name.as_string()); 124 return it != manifests_.end() ? it->second->CreateDeepCopy() : nullptr;
132 if (manifest_it != manifests_->end()) {
133 *manifest_contents = manifest_it->second;
134 DCHECK(!manifest_contents->empty());
135 return true;
136 }
137 return false;
138 } 125 }
139 126
140 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_; 127 std::map<std::string, std::unique_ptr<base::Value>> manifests_;
141 128
142 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); 129 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider);
143 }; 130 };
144 131
145 } // namespace 132 } // namespace
146 133
147 // State which lives on the IO thread and drives the ServiceManager. 134 // State which lives on the IO thread and drives the ServiceManager.
148 class MojoShellContext::InProcessServiceManagerContext 135 class MojoShellContext::InProcessServiceManagerContext
149 : public base::RefCountedThreadSafe<InProcessServiceManagerContext> { 136 : public base::RefCountedThreadSafe<InProcessServiceManagerContext> {
150 public: 137 public:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 194
208 DISALLOW_COPY_AND_ASSIGN(InProcessServiceManagerContext); 195 DISALLOW_COPY_AND_ASSIGN(InProcessServiceManagerContext);
209 }; 196 };
210 197
211 MojoShellContext::MojoShellContext() { 198 MojoShellContext::MojoShellContext() {
212 shell::mojom::ServiceRequest request; 199 shell::mojom::ServiceRequest request;
213 if (shell::ShellIsRemote()) { 200 if (shell::ShellIsRemote()) {
214 mojo::edk::SetParentPipeHandleFromCommandLine(); 201 mojo::edk::SetParentPipeHandleFromCommandLine();
215 request = shell::GetServiceRequestFromCommandLine(); 202 request = shell::GetServiceRequestFromCommandLine();
216 } else { 203 } else {
217 // Allow the embedder to register additional Mojo application manifests
218 // beyond the default ones below.
219 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests(
220 new ContentBrowserClient::MojoApplicationManifestMap);
221 GetContentClient()->browser()->RegisterMojoApplicationManifests(
222 manifests.get());
223 std::unique_ptr<BuiltinManifestProvider> manifest_provider = 204 std::unique_ptr<BuiltinManifestProvider> manifest_provider =
224 base::MakeUnique<BuiltinManifestProvider>(); 205 base::MakeUnique<BuiltinManifestProvider>();
225 manifest_provider->AddManifests(std::move(manifests));
226 manifest_provider->AddManifestResource(kBrowserMojoApplicationName,
227 IDR_MOJO_CONTENT_BROWSER_MANIFEST);
228 manifest_provider->AddManifestResource(kGpuMojoApplicationName,
229 IDR_MOJO_CONTENT_GPU_MANIFEST);
230 manifest_provider->AddManifestResource(kPluginMojoApplicationName,
231 IDR_MOJO_CONTENT_PLUGIN_MANIFEST);
232 manifest_provider->AddManifestResource(kRendererMojoApplicationName,
233 IDR_MOJO_CONTENT_RENDERER_MANIFEST);
234 manifest_provider->AddManifestResource(kUtilityMojoApplicationName,
235 IDR_MOJO_CONTENT_UTILITY_MANIFEST);
236 manifest_provider->AddManifestResource("mojo:catalog",
237 IDR_MOJO_CATALOG_MANIFEST);
238 manifest_provider->AddManifestResource(file::kFileServiceName,
239 IDR_MOJO_FILE_MANIFEST);
240 206
207 static const struct ManifestInfo {
208 const char* name;
209 int resource_id;
210 } kManifests[] = {
211 { kBrowserMojoApplicationName, IDR_MOJO_CONTENT_BROWSER_MANIFEST },
212 { kGpuMojoApplicationName, IDR_MOJO_CONTENT_GPU_MANIFEST },
213 { kPluginMojoApplicationName, IDR_MOJO_CONTENT_PLUGIN_MANIFEST },
214 { kRendererMojoApplicationName, IDR_MOJO_CONTENT_RENDERER_MANIFEST },
215 { kUtilityMojoApplicationName, IDR_MOJO_CONTENT_UTILITY_MANIFEST },
216 { "mojo:catalog", IDR_MOJO_CATALOG_MANIFEST },
217 { file::kFileServiceName, IDR_MOJO_FILE_MANIFEST }
218 };
219
220 for (size_t i = 0; i < arraysize(kManifests); ++i) {
221 std::string contents = GetContentClient()->GetDataResource(
222 kManifests[i].resource_id,
223 ui::ScaleFactor::SCALE_FACTOR_NONE).as_string();
224 DCHECK(!contents.empty());
225 std::unique_ptr<base::Value> manifest_value =
226 base::JSONReader::Read(contents);
227 std::unique_ptr<base::Value> overlay_value =
228 GetContentClient()->browser()->GetServiceManifestOverlay(
229 kManifests[i].name);
230 if (overlay_value) {
231 base::DictionaryValue* manifest_dictionary = nullptr;
232 CHECK(manifest_value->GetAsDictionary(&manifest_dictionary));
233 base::DictionaryValue* overlay_dictionary = nullptr;
234 CHECK(overlay_value->GetAsDictionary(&overlay_dictionary));
235 MergeDictionary(manifest_dictionary, overlay_dictionary);
236 }
237 manifest_provider->AddManifestValue(kManifests[i].name,
238 std::move(manifest_value));
239 }
241 in_process_context_ = new InProcessServiceManagerContext; 240 in_process_context_ = new InProcessServiceManagerContext;
242 request = in_process_context_->Start(std::move(manifest_provider)); 241 request = in_process_context_->Start(std::move(manifest_provider));
243 } 242 }
244 MojoShellConnection::SetForProcess(MojoShellConnection::Create( 243 MojoShellConnection::SetForProcess(MojoShellConnection::Create(
245 std::move(request), 244 std::move(request),
246 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); 245 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
247 246
248 ContentBrowserClient::StaticMojoApplicationMap apps; 247 ContentBrowserClient::StaticMojoApplicationMap apps;
249 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 248 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
250 for (const auto& entry : apps) { 249 for (const auto& entry : apps) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 in_process_context_->ShutDown(); 295 in_process_context_->ShutDown();
297 } 296 }
298 297
299 // static 298 // static
300 shell::Connector* MojoShellContext::GetConnectorForIOThread() { 299 shell::Connector* MojoShellContext::GetConnectorForIOThread() {
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
302 return g_io_thread_connector.Get().get(); 301 return g_io_thread_connector.Get().get();
303 } 302 }
304 303
305 } // namespace content 304 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/merge_dictionary_unittest.cc ('k') | content/browser/ppapi_plugin_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698