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

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
47 namespace {
48
49 const char kCastContextStateKey[] = "CastContextState";
50
51 } // namespace
52
37 namespace chromecast { 53 namespace chromecast {
38 namespace shell { 54 namespace shell {
39 55
40 namespace { 56 namespace {
41 57
42 // Default background color to set for WebViews. WebColor is in ARGB format 58 // Default background color to set for WebViews. WebColor is in ARGB format
43 // though the comment of WebColor says it is in RGBA. 59 // though the comment of WebColor says it is in RGBA.
44 const blink::WebColor kColorBlack = 0xFF000000; 60 const blink::WebColor kColorBlack = 0xFF000000;
45 61
46 } // namespace 62 } // namespace
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const base::Closure& closure) { 157 const base::Closure& closure) {
142 if (!render_frame->IsHidden() || allow_hidden_media_playback_) { 158 if (!render_frame->IsHidden() || allow_hidden_media_playback_) {
143 closure.Run(); 159 closure.Run();
144 return; 160 return;
145 } 161 }
146 162
147 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. 163 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
148 new CastMediaLoadDeferrer(render_frame, closure); 164 new CastMediaLoadDeferrer(render_frame, closure);
149 } 165 }
150 166
167 void CastContentRendererClient::ExecuteJavaScript(
168 content::RenderFrame* render_frame, int resource_id) {
derekjchow1 2016/09/15 00:48:02 DCHECK(render_frame)
jam 2016/09/15 16:30:12 note this isn't really needed, since if render_fra
169 const std::string& js_string = ui::ResourceBundle::GetSharedInstance()
170 .GetRawDataResource(resource_id)
171 .as_string();
172 render_frame->ExecuteJavaScript(base::UTF8ToUTF16(js_string));
173 }
174
175 void CastContentRendererClient::RunScriptsAtDocumentStart(
176 content::RenderFrame* render_frame) {
177 // This method enables Mojo bindings in JavaScript for Chromecast.
178
179 v8::HandleScope handle_scope(blink::mainThreadIsolate());
180 blink::WebLocalFrame* frame = render_frame->GetWebFrame();
derekjchow1 2016/09/15 00:48:02 You can probably move lines 179 & 181-183 into the
181 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
182 gin::PerContextData* context_data = gin::PerContextData::From(context);
183 gin::ContextHolder* context_holder = context_data->context_holder();
184 CastGinRunner* runner = new CastGinRunner(frame, context_holder);
185 context_data->SetUserData(kCastContextStateKey, runner);
derekjchow1 2016/09/15 00:48:02 Will runner get leaked if you do not explicitly re
jarhar 2016/09/16 03:29:41 Done.
186 gin::Runner::Scope scoper(runner);
187
188 // Initialize AMD API for Mojo.
189 render_frame->EnsureMojoBuiltinsAreAvailable(context_holder->isolate(),
190 context);
191 gin::ModuleRegistry::InstallGlobals(context_holder->isolate(),
192 context->Global());
193
194 // Inject JavaScript files in the correct dependency order.
195 static const int mojoResourceIds[] = {
alokp 2016/09/16 04:27:22 mojoResourceIds -> mojo_resource_ids
jarhar 2016/09/16 20:54:22 Done.
196 IDR_MOJO_UNICODE_JS,
197 IDR_MOJO_BUFFER_JS,
198 IDR_MOJO_CODEC_JS,
199 IDR_MOJO_CONNECTOR_JS,
200 IDR_MOJO_VALIDATOR_JS,
201 IDR_MOJO_ROUTER_JS,
202 IDR_MOJO_BINDINGS_JS,
203 IDR_MOJO_CONNECTION_JS,
204 };
205 for (size_t i = 0; i < arraysize(mojoResourceIds); i++) {
206 ExecuteJavaScript(render_frame, mojoResourceIds[i]);
207 }
208 }
209
151 } // namespace shell 210 } // namespace shell
152 } // namespace chromecast 211 } // 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