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

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

Issue 2342563003: [chromecast] Enable Mojo javascript bindings for cast_shell (Closed)
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 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::InjectJavaScript(
alokp 2016/09/14 21:55:36 This does not need to be a member function. Make i
jarhar 2016/09/15 00:32:41 Done.
alokp 2016/09/16 04:27:22 You forgot to make it a non-member function.
jarhar 2016/09/16 20:54:22 Done.
162 content::RenderFrame* render_frame,
163 const int resourceId) {
alokp 2016/09/14 21:55:36 resourceId -> resource_id. And no need for const.
jarhar 2016/09/15 00:32:41 Done.
164 const std::string& js_string = ui::ResourceBundle::GetSharedInstance()
alokp 2016/09/14 21:55:36 Use the content-client API to get js-string
jarhar 2016/09/15 00:32:41 GetContentClient() cannot be accessed from here be
165 .GetRawDataResource(resourceId)
166 .as_string();
167 render_frame->ExecuteJavaScript(base::UTF8ToUTF16(js_string));
168 }
169
170 void CastContentRendererClient::RunScriptsAtDocumentStart(
171 content::RenderFrame* render_frame) {
172 v8::HandleScope handle_scope(blink::mainThreadIsolate());
alokp 2016/09/14 21:55:36 Add a high-level comment on what exactly it is doi
jarhar 2016/09/15 00:32:42 MojoBindingsController appears to make the assumpt
173 blink::WebLocalFrame* frame = render_frame->GetWebFrame();
174 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
175 gin::PerContextData* context_data = gin::PerContextData::From(context);
176 gin::ContextHolder* context_holder = context_data->context_holder();
177 cast_runner_.reset(new CastGinRunner(frame, context_holder));
derekjchow1 2016/09/14 21:20:13 I don't think this variable needs to outlive this
jarhar 2016/09/15 00:32:42 As per our conversation, I have moved it to gin::P
178 gin::Runner::Scope scoper(cast_runner_.get());
179
180 // Initialize AMD API for Mojo.
181 render_frame->EnsureMojoBuiltinsAreAvailable(context_holder->isolate(),
182 context);
183 gin::ModuleRegistry::InstallGlobals(context_holder->isolate(),
184 context->Global());
185
186 // Inject JavaScript files in the correct dependency order.
187 static const int mojoResourceIds[] = {
188 IDR_MOJO_UNICODE_JS, IDR_MOJO_BUFFER_JS, IDR_MOJO_CODEC_JS,
alokp 2016/09/14 21:55:36 Run git-cl format to format this properly.
jarhar 2016/09/15 00:32:41 Done.
189 IDR_MOJO_CONNECTOR_JS, IDR_MOJO_VALIDATOR_JS, IDR_MOJO_ROUTER_JS,
190 IDR_MOJO_BINDINGS_JS, IDR_MOJO_CONNECTION_JS,
191 };
192 for (size_t i = 0; i < arraysize(mojoResourceIds); i++) {
193 InjectJavaScript(render_frame, mojoResourceIds[i]);
194 }
195 }
196
151 } // namespace shell 197 } // namespace shell
152 } // namespace chromecast 198 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698