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

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/key_systems_cast.h" 20 #include "chromecast/renderer/key_systems_cast.h"
18 #include "chromecast/renderer/media/media_caps_observer_impl.h" 21 #include "chromecast/renderer/media/media_caps_observer_impl.h"
19 #include "components/network_hints/renderer/prescient_networking_dispatcher.h" 22 #include "components/network_hints/renderer/prescient_networking_dispatcher.h"
23 #include "content/grit/content_resources.h"
20 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
21 #include "content/public/renderer/render_frame.h" 25 #include "content/public/renderer/render_frame.h"
22 #include "content/public/renderer/render_thread.h" 26 #include "content/public/renderer/render_thread.h"
23 #include "content/public/renderer/render_view.h" 27 #include "content/public/renderer/render_view.h"
28 #include "gin/modules/module_registry.h"
29 #include "gin/per_context_data.h"
30 #include "gin/public/context_holder.h"
24 #include "media/base/media.h" 31 #include "media/base/media.h"
25 #include "services/shell/public/cpp/interface_provider.h" 32 #include "services/shell/public/cpp/interface_provider.h"
26 #include "third_party/WebKit/public/platform/WebColor.h" 33 #include "third_party/WebKit/public/platform/WebColor.h"
27 #include "third_party/WebKit/public/web/WebFrameWidget.h" 34 #include "third_party/WebKit/public/web/WebFrameWidget.h"
35 #include "third_party/WebKit/public/web/WebKit.h"
36 #include "third_party/WebKit/public/web/WebLocalFrame.h"
28 #include "third_party/WebKit/public/web/WebSettings.h" 37 #include "third_party/WebKit/public/web/WebSettings.h"
29 #include "third_party/WebKit/public/web/WebView.h" 38 #include "third_party/WebKit/public/web/WebView.h"
39 #include "ui/base/resource/resource_bundle.h"
30 40
31 #if defined(OS_ANDROID) 41 #if defined(OS_ANDROID)
32 #include "media/base/android/media_codec_util.h" 42 #include "media/base/android/media_codec_util.h"
33 #endif // OS_ANDROID 43 #endif // OS_ANDROID
34 44
35 namespace chromecast { 45 namespace chromecast {
36 namespace shell { 46 namespace shell {
37 47
38 namespace { 48 namespace {
39 49
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const base::Closure& closure) { 131 const base::Closure& closure) {
122 if (!render_frame->IsHidden() || allow_hidden_media_playback_) { 132 if (!render_frame->IsHidden() || allow_hidden_media_playback_) {
123 closure.Run(); 133 closure.Run();
124 return; 134 return;
125 } 135 }
126 136
127 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. 137 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
128 new CastMediaLoadDeferrer(render_frame, closure); 138 new CastMediaLoadDeferrer(render_frame, closure);
129 } 139 }
130 140
141 void CastContentRendererClient::RunScriptsAtDocumentStart(
142 content::RenderFrame* render_frame) {
143 // This method enables Mojo bindings in JavaScript for Chromecast.
144
145 v8::HandleScope handle_scope(blink::mainThreadIsolate());
146 v8::Local<v8::Context> context =
147 render_frame->GetWebFrame()->mainWorldScriptContext();
148
149 // CastGinRunner manages its own lifetime.
150 CastGinRunner* runner = new CastGinRunner(render_frame);
151 gin::Runner::Scope scoper(runner);
152
153 // Initialize AMD API for Mojo.
154 render_frame->EnsureMojoBuiltinsAreAvailable(context->GetIsolate(), context);
155 gin::ModuleRegistry::InstallGlobals(context->GetIsolate(), context->Global());
156
157 // Inject JavaScript files in the correct dependency order.
158 static const int mojo_resource_ids[] = {
159 IDR_MOJO_UNICODE_JS,
160 IDR_MOJO_BUFFER_JS,
161 IDR_MOJO_CODEC_JS,
162 IDR_MOJO_CONNECTOR_JS,
163 IDR_MOJO_VALIDATOR_JS,
164 IDR_MOJO_ROUTER_JS,
165 IDR_MOJO_BINDINGS_JS,
166 IDR_MOJO_CONNECTION_JS,
167 };
168 for (size_t i = 0; i < arraysize(mojo_resource_ids); i++) {
169 ExecuteJavaScript(render_frame, mojo_resource_ids[i]);
170 }
171 }
172
173 void ExecuteJavaScript(content::RenderFrame* render_frame, int resource_id) {
174 const std::string& js_string = ui::ResourceBundle::GetSharedInstance()
175 .GetRawDataResource(resource_id)
176 .as_string();
177 render_frame->ExecuteJavaScript(base::UTF8ToUTF16(js_string));
178 }
179
131 } // namespace shell 180 } // namespace shell
132 } // namespace chromecast 181 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/renderer/cast_content_renderer_client.h ('k') | chromecast/renderer/cast_gin_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698