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

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

Issue 2335423002: Revert of 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"
13 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
14 #include "base/macros.h" 13 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
16 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
17 #include "content/browser/gpu/gpu_process_host.h" 16 #include "content/browser/gpu/gpu_process_host.h"
18 #include "content/browser/mojo/merge_dictionary.h" 17 #include "content/common/mojo/constants.h"
19 #include "content/common/mojo/mojo_shell_connection_impl.h" 18 #include "content/common/mojo/mojo_shell_connection_impl.h"
20 #include "content/grit/content_resources.h" 19 #include "content/grit/content_resources.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/content_browser_client.h" 21 #include "content/public/browser/content_browser_client.h"
23 #include "content/public/browser/utility_process_host.h" 22 #include "content/public/browser/utility_process_host.h"
24 #include "content/public/browser/utility_process_host_client.h" 23 #include "content/public/browser/utility_process_host_client.h"
25 #include "content/public/common/content_client.h" 24 #include "content/public/common/content_client.h"
26 #include "content/public/common/mojo_shell_connection.h" 25 #include "content/public/common/mojo_shell_connection.h"
27 #include "content/public/common/service_names.h"
28 #include "mojo/edk/embedder/embedder.h" 26 #include "mojo/edk/embedder/embedder.h"
29 #include "services/catalog/catalog.h" 27 #include "services/catalog/catalog.h"
30 #include "services/catalog/manifest_provider.h" 28 #include "services/catalog/manifest_provider.h"
31 #include "services/catalog/store.h" 29 #include "services/catalog/store.h"
32 #include "services/file/public/cpp/constants.h" 30 #include "services/file/public/cpp/constants.h"
33 #include "services/shell/connect_params.h" 31 #include "services/shell/connect_params.h"
34 #include "services/shell/native_runner.h" 32 #include "services/shell/native_runner.h"
35 #include "services/shell/public/cpp/connector.h" 33 #include "services/shell/public/cpp/connector.h"
36 #include "services/shell/public/cpp/service.h" 34 #include "services/shell/public/cpp/service.h"
37 #include "services/shell/public/interfaces/service.mojom.h" 35 #include "services/shell/public/interfaces/service.mojom.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 shell::mojom::ServiceFactoryPtr service_factory; 94 shell::mojom::ServiceFactoryPtr service_factory;
97 BrowserThread::PostTask( 95 BrowserThread::PostTask(
98 BrowserThread::IO, FROM_HERE, 96 BrowserThread::IO, FROM_HERE,
99 base::Bind(&RequestGpuServiceFactory, 97 base::Bind(&RequestGpuServiceFactory,
100 base::Passed(GetProxy(&service_factory)))); 98 base::Passed(GetProxy(&service_factory))));
101 service_factory->CreateService(std::move(request), service_name); 99 service_factory->CreateService(std::move(request), service_name);
102 } 100 }
103 101
104 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS 102 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS
105 103
106 void MergeDictionary(base::DictionaryValue* target,
107 const base::DictionaryValue* source) {
108 for (base::DictionaryValue::Iterator it(*source); !it.IsAtEnd();
109 it.Advance()) {
110 const base::Value* merge_value = &it.value();
111 // Check whether we have to merge dictionaries.
112 if (merge_value->IsType(base::Value::TYPE_DICTIONARY)) {
113 base::DictionaryValue* sub_dict;
114 if (target->GetDictionaryWithoutPathExpansion(it.key(), &sub_dict)) {
115 MergeDictionary(
116 sub_dict,
117 static_cast<const base::DictionaryValue*>(merge_value));
118 continue;
119 }
120 }
121 if (merge_value->IsType(base::Value::TYPE_LIST)) {
122 const base::ListValue* merge_list = nullptr;
123 if (merge_value->GetAsList(&merge_list)) {
124 base::ListValue* target_list = nullptr;
125 DCHECK(target->GetListWithoutPathExpansion(it.key(), &target_list));
126 for (size_t i = 0; i < merge_list->GetSize(); ++i) {
127 std::string value;
128 DCHECK(merge_list->GetString(i, &value));
129 target_list->AppendString(value);
130 }
131 }
132 } else {
133 // All other cases: Make a copy and hook it up.
134 target->SetWithoutPathExpansion(it.key(), merge_value->DeepCopy());
135 }
136 }
137 }
138
139 // A ManifestProvider which resolves application names to builtin manifest 104 // A ManifestProvider which resolves application names to builtin manifest
140 // resources for the catalog service to consume. 105 // resources for the catalog service to consume.
141 class BuiltinManifestProvider : public catalog::ManifestProvider { 106 class BuiltinManifestProvider : public catalog::ManifestProvider {
142 public: 107 public:
143 BuiltinManifestProvider() {} 108 BuiltinManifestProvider() {}
144 ~BuiltinManifestProvider() override {} 109 ~BuiltinManifestProvider() override {}
145 110
146 void AddManifests(std::unique_ptr< 111 void AddManifests(std::unique_ptr<
147 ContentBrowserClient::MojoApplicationManifestMap> manifests) { 112 ContentBrowserClient::MojoApplicationManifestMap> manifests) {
148 DCHECK(!manifests_); 113 DCHECK(!manifests_);
149 manifests_ = std::move(manifests); 114 manifests_ = std::move(manifests);
150 } 115 }
151 116
152 void AddManifestResource(const std::string& name, int resource_id) { 117 void AddManifestResource(const std::string& name, int resource_id) {
153 std::string contents = GetContentClient()->GetDataResource( 118 std::string contents = GetContentClient()->GetDataResource(
154 resource_id, ui::ScaleFactor::SCALE_FACTOR_NONE).as_string(); 119 resource_id, ui::ScaleFactor::SCALE_FACTOR_NONE).as_string();
155 DCHECK(!contents.empty()); 120 DCHECK(!contents.empty());
156 121
157 DCHECK(manifests_); 122 DCHECK(manifests_);
158 auto result = manifests_->insert(std::make_pair(name, contents)); 123 auto result = manifests_->insert(std::make_pair(name, contents));
159 DCHECK(result.second) << "Duplicate manifest entry: " << name; 124 DCHECK(result.second) << "Duplicate manifest entry: " << name;
160 } 125 }
161 126
162 private: 127 private:
163 // catalog::ManifestProvider: 128 // catalog::ManifestProvider:
164 std::unique_ptr<base::Value> GetManifest(const std::string& name) override { 129 bool GetApplicationManifest(const base::StringPiece& name,
165 auto manifest_it = manifests_->find(name); 130 std::string* manifest_contents) override {
166 std::unique_ptr<base::Value> manifest_root; 131 auto manifest_it = manifests_->find(name.as_string());
167 if (manifest_it != manifests_->end()) 132 if (manifest_it != manifests_->end()) {
168 manifest_root = base::JSONReader::Read(manifest_it->second); 133 *manifest_contents = manifest_it->second;
169 134 DCHECK(!manifest_contents->empty());
170 base::DictionaryValue* manifest_dictionary = nullptr; 135 return true;
171 if (manifest_root && !manifest_root->GetAsDictionary(&manifest_dictionary))
172 return nullptr;
173
174 std::unique_ptr<base::Value> overlay_root =
175 GetContentClient()->browser()->GetServiceManifestOverlay(name);
176 if (overlay_root) {
177 if (!manifest_root) {
178 manifest_root = std::move(overlay_root);
179 } else {
180 base::DictionaryValue* overlay_dictionary = nullptr;
181 if (overlay_root->GetAsDictionary(&overlay_dictionary))
182 MergeDictionary(manifest_dictionary, overlay_dictionary);
183 }
184 } 136 }
185 return manifest_root; 137 return false;
186 } 138 }
187 139
188 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_; 140 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_;
189 141
190 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); 142 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider);
191 }; 143 };
192 144
193 } // namespace 145 } // namespace
194 146
195 // State which lives on the IO thread and drives the ServiceManager. 147 // State which lives on the IO thread and drives the ServiceManager.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 in_process_context_->ShutDown(); 296 in_process_context_->ShutDown();
345 } 297 }
346 298
347 // static 299 // static
348 shell::Connector* MojoShellContext::GetConnectorForIOThread() { 300 shell::Connector* MojoShellContext::GetConnectorForIOThread() {
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
350 return g_io_thread_connector.Get().get(); 302 return g_io_thread_connector.Get().get();
351 } 303 }
352 304
353 } // namespace content 305 } // 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