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

Side by Side Diff: content/renderer/mojo_context_state.cc

Issue 2049363003: Adds support for headless chrome embedder mojo services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes for Sami Created 4 years, 5 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 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 "content/renderer/mojo_context_state.h" 5 #include "content/renderer/mojo_context_state.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "content/grit/content_resources.h" 17 #include "content/grit/content_resources.h"
18 #include "content/public/common/content_client.h" 18 #include "content/public/common/content_client.h"
19 #include "content/public/renderer/render_frame.h" 19 #include "content/public/renderer/render_frame.h"
20 #include "content/public/renderer/resource_fetcher.h" 20 #include "content/public/renderer/resource_fetcher.h"
21 #include "content/renderer/mojo_bindings_controller.h"
21 #include "content/renderer/mojo_main_runner.h" 22 #include "content/renderer/mojo_main_runner.h"
22 #include "gin/converter.h" 23 #include "gin/converter.h"
23 #include "gin/modules/module_registry.h" 24 #include "gin/modules/module_registry.h"
24 #include "gin/per_context_data.h" 25 #include "gin/per_context_data.h"
25 #include "gin/public/context_holder.h" 26 #include "gin/public/context_holder.h"
26 #include "gin/try_catch.h" 27 #include "gin/try_catch.h"
27 #include "mojo/public/js/constants.h" 28 #include "mojo/public/js/constants.h"
28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 29 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
29 #include "third_party/WebKit/public/platform/WebURLResponse.h" 30 #include "third_party/WebKit/public/platform/WebURLResponse.h"
30 #include "third_party/WebKit/public/web/WebFrame.h" 31 #include "third_party/WebKit/public/web/WebFrame.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 84 }
84 } 85 }
85 86
86 DCHECK(module_sources); 87 DCHECK(module_sources);
87 auto source_iter = module_sources->find(path); 88 auto source_iter = module_sources->find(path);
88 if (source_iter == module_sources->end()) 89 if (source_iter == module_sources->end())
89 return nullptr; 90 return nullptr;
90 return source_iter->second; 91 return source_iter->second;
91 } 92 }
92 93
94 std::string GetModulePrefixForBindingsType(MojoBindingsType bindings_type,
95 blink::WebFrame* frame) {
96 switch (bindings_type) {
97 case MojoBindingsType::FOR_UI_BINDINGS:
98 return frame->getSecurityOrigin().toString().utf8() + "/";
99 case MojoBindingsType::FOR_LAYOUT_TESTS:
100 return "layout-test-mojom://";
101 case MojoBindingsType::FOR_HEADLESS:
102 return "headless-mojom://";
jochen (gone - plz use gerrit) 2016/06/27 12:31:57 this is all a bit of a layering violation, but adm
alex clarke (OOO till 29th) 2016/07/29 09:06:23 Acknowledged.
103 }
104 NOTREACHED();
105 return "";
106 }
107
93 } // namespace 108 } // namespace
94 109
95 MojoContextState::MojoContextState(blink::WebFrame* frame, 110 MojoContextState::MojoContextState(blink::WebFrame* frame,
96 v8::Local<v8::Context> context, 111 v8::Local<v8::Context> context,
97 bool for_layout_tests) 112 MojoBindingsType bindings_type)
98 : frame_(frame), 113 : frame_(frame),
99 module_added_(false), 114 module_added_(false),
100 module_prefix_(for_layout_tests 115 module_prefix_(GetModulePrefixForBindingsType(bindings_type, frame)) {
101 ? "layout-test-mojom://"
102 : frame_->getSecurityOrigin().toString().utf8() +
103 "/") {
104 gin::PerContextData* context_data = gin::PerContextData::From(context); 116 gin::PerContextData* context_data = gin::PerContextData::From(context);
105 gin::ContextHolder* context_holder = context_data->context_holder(); 117 gin::ContextHolder* context_holder = context_data->context_holder();
106 runner_.reset(new MojoMainRunner(frame_, context_holder)); 118 runner_.reset(new MojoMainRunner(frame_, context_holder));
107 gin::Runner::Scope scoper(runner_.get()); 119 gin::Runner::Scope scoper(runner_.get());
108 gin::ModuleRegistry::From(context)->AddObserver(this); 120 gin::ModuleRegistry::From(context)->AddObserver(this);
109 content::RenderFrame::FromWebFrame(frame) 121 content::RenderFrame::FromWebFrame(frame)
110 ->EnsureMojoBuiltinsAreAvailable(context_holder->isolate(), context); 122 ->EnsureMojoBuiltinsAreAvailable(context_holder->isolate(), context);
111 v8::Local<v8::Object> install_target; 123 v8::Local<v8::Object> install_target;
112 if (for_layout_tests) { 124 if (bindings_type == MojoBindingsType::FOR_LAYOUT_TESTS) {
113 // In layout tests we install the module system under 'mojo.define' 125 // In layout tests we install the module system under 'mojo.define'
114 // for now to avoid globally exposing something as generic as 'define'. 126 // for now to avoid globally exposing something as generic as 'define'.
115 // 127 //
116 // TODO(rockot): Remove this if/when we can integrate gin + ES6 modules. 128 // TODO(rockot): Remove this if/when we can integrate gin + ES6 modules.
117 install_target = v8::Object::New(context->GetIsolate()); 129 install_target = v8::Object::New(context->GetIsolate());
118 gin::SetProperty(context->GetIsolate(), context->Global(), 130 gin::SetProperty(context->GetIsolate(), context->Global(),
119 gin::StringToSymbol(context->GetIsolate(), "mojo"), 131 gin::StringToSymbol(context->GetIsolate(), "mojo"),
120 install_target); 132 install_target);
121 } else { 133 } else {
122 // Otherwise we're fine installing a global 'define'. 134 // Otherwise we're fine installing a global 'define'.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 const std::vector<std::string>& dependencies) { 214 const std::vector<std::string>& dependencies) {
203 FetchModules(dependencies); 215 FetchModules(dependencies);
204 216
205 gin::ContextHolder* context_holder = runner_->GetContextHolder(); 217 gin::ContextHolder* context_holder = runner_->GetContextHolder();
206 gin::ModuleRegistry* registry = gin::ModuleRegistry::From( 218 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(
207 context_holder->context()); 219 context_holder->context());
208 registry->AttemptToLoadMoreModules(context_holder->isolate()); 220 registry->AttemptToLoadMoreModules(context_holder->isolate());
209 } 221 }
210 222
211 } // namespace content 223 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698