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

Side by Side Diff: chromecast/renderer/cast_content_renderer_client.cc

Issue 2342563003: [chromecast] Enable Mojo javascript bindings for cast_shell (Closed)
Patch Set: Add Mojo JavaScript support for Chromecast 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 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 "chromecast/renderer/cast_content_renderer_client.h" 5 #include "chromecast/renderer/cast_content_renderer_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 #include "chromecast/base/chromecast_switches.h" 15 #include "chromecast/base/chromecast_switches.h"
14 #include "chromecast/common/media/cast_media_client.h" 16 #include "chromecast/common/media/cast_media_client.h"
15 #include "chromecast/crash/cast_crash_keys.h" 17 #include "chromecast/crash/cast_crash_keys.h"
18 #include "chromecast/renderer/cast_gin_runner.h"
16 #include "chromecast/renderer/cast_media_load_deferrer.h" 19 #include "chromecast/renderer/cast_media_load_deferrer.h"
17 #include "chromecast/renderer/cast_render_thread_observer.h" 20 #include "chromecast/renderer/cast_render_thread_observer.h"
18 #include "chromecast/renderer/key_systems_cast.h" 21 #include "chromecast/renderer/key_systems_cast.h"
19 #include "chromecast/renderer/media/chromecast_media_renderer_factory.h" 22 #include "chromecast/renderer/media/chromecast_media_renderer_factory.h"
20 #include "chromecast/renderer/media/media_caps_observer_impl.h" 23 #include "chromecast/renderer/media/media_caps_observer_impl.h"
21 #include "components/network_hints/renderer/prescient_networking_dispatcher.h" 24 #include "components/network_hints/renderer/prescient_networking_dispatcher.h"
25 #include "content/grit/content_resources.h"
22 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
23 #include "content/public/renderer/render_frame.h" 27 #include "content/public/renderer/render_frame.h"
24 #include "content/public/renderer/render_thread.h" 28 #include "content/public/renderer/render_thread.h"
25 #include "content/public/renderer/render_view.h" 29 #include "content/public/renderer/render_view.h"
30 #include "gin/modules/module_registry.h"
31 #include "gin/per_context_data.h"
32 #include "gin/public/context_holder.h"
26 #include "media/base/media.h" 33 #include "media/base/media.h"
27 #include "services/shell/public/cpp/interface_provider.h" 34 #include "services/shell/public/cpp/interface_provider.h"
28 #include "third_party/WebKit/public/platform/WebColor.h" 35 #include "third_party/WebKit/public/platform/WebColor.h"
29 #include "third_party/WebKit/public/web/WebFrameWidget.h" 36 #include "third_party/WebKit/public/web/WebFrameWidget.h"
37 #include "third_party/WebKit/public/web/WebKit.h"
38 #include "third_party/WebKit/public/web/WebLocalFrame.h"
30 #include "third_party/WebKit/public/web/WebSettings.h" 39 #include "third_party/WebKit/public/web/WebSettings.h"
31 #include "third_party/WebKit/public/web/WebView.h" 40 #include "third_party/WebKit/public/web/WebView.h"
41 #include "ui/base/resource/resource_bundle.h"
32 42
33 #if defined(OS_ANDROID) 43 #if defined(OS_ANDROID)
34 #include "media/base/android/media_codec_util.h" 44 #include "media/base/android/media_codec_util.h"
35 #endif // OS_ANDROID 45 #endif // OS_ANDROID
36 46
37 namespace chromecast { 47 namespace chromecast {
38 namespace shell { 48 namespace shell {
39 49
40 namespace { 50 namespace {
41 51
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const base::Closure& closure) { 151 const base::Closure& closure) {
142 if (!render_frame->IsHidden() || allow_hidden_media_playback_) { 152 if (!render_frame->IsHidden() || allow_hidden_media_playback_) {
143 closure.Run(); 153 closure.Run();
144 return; 154 return;
145 } 155 }
146 156
147 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. 157 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
148 new CastMediaLoadDeferrer(render_frame, closure); 158 new CastMediaLoadDeferrer(render_frame, closure);
149 } 159 }
150 160
161 void CastContentRendererClient::ExecuteJavaScript(
162 content::RenderFrame* render_frame,
163 int resource_id) {
164 const std::string& js_string = ui::ResourceBundle::GetSharedInstance()
165 .GetRawDataResource(resource_id)
166 .as_string();
167 render_frame->ExecuteJavaScript(base::UTF8ToUTF16(js_string));
168 }
169
170 void CastContentRendererClient::RunScriptsAtDocumentStart(
171 content::RenderFrame* render_frame) {
172 // This method enables Mojo bindings in JavaScript for Chromecast.
173
174 v8::HandleScope handle_scope(blink::mainThreadIsolate());
175 blink::WebLocalFrame* frame = render_frame->GetWebFrame();
176 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
177 gin::PerContextData* context_data = gin::PerContextData::From(context);
178 gin::ContextHolder* context_holder = context_data->context_holder();
179
180 CastGinRunner* runner =
derekjchow1 2016/09/16 17:02:00 Add comment on how CastGinRunner manages it's own
jarhar 2016/09/16 20:54:22 Done.
181 new CastGinRunner(render_frame, frame, context_holder);
182 context_data->SetUserData(kCastContextData, runner);
derekjchow1 2016/09/16 17:02:00 Can this be done in the constructor of CastGinRunn
jarhar 2016/09/16 20:54:22 Done.
183 gin::Runner::Scope scoper(runner);
184
185 // Initialize AMD API for Mojo.
186 render_frame->EnsureMojoBuiltinsAreAvailable(context_holder->isolate(),
187 context);
188 gin::ModuleRegistry::InstallGlobals(context_holder->isolate(),
189 context->Global());
190
191 // Inject JavaScript files in the correct dependency order.
192 static const int mojo_resource_ids[] = {
193 IDR_MOJO_UNICODE_JS,
194 IDR_MOJO_BUFFER_JS,
195 IDR_MOJO_CODEC_JS,
196 IDR_MOJO_CONNECTOR_JS,
197 IDR_MOJO_VALIDATOR_JS,
198 IDR_MOJO_ROUTER_JS,
199 IDR_MOJO_BINDINGS_JS,
200 IDR_MOJO_CONNECTION_JS,
201 };
202 for (size_t i = 0; i < arraysize(mojo_resource_ids); i++) {
203 ExecuteJavaScript(render_frame, mojo_resource_ids[i]);
204 }
205 }
206
151 } // namespace shell 207 } // namespace shell
152 } // namespace chromecast 208 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698