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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chromecast/renderer/cast_content_renderer_client.cc
diff --git a/chromecast/renderer/cast_content_renderer_client.cc b/chromecast/renderer/cast_content_renderer_client.cc
index 47d95819fd89aba862c75d2d2a90dfcee47e2560..ef03b51907920a939403336d7aed4e9a705c4057 100644
--- a/chromecast/renderer/cast_content_renderer_client.cc
+++ b/chromecast/renderer/cast_content_renderer_client.cc
@@ -5,30 +5,40 @@
#include "chromecast/renderer/cast_content_renderer_client.h"
#include <stdint.h>
+#include <string>
#include "base/command_line.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chromecast/base/chromecast_switches.h"
#include "chromecast/common/media/cast_media_client.h"
#include "chromecast/crash/cast_crash_keys.h"
+#include "chromecast/renderer/cast_gin_runner.h"
#include "chromecast/renderer/cast_media_load_deferrer.h"
#include "chromecast/renderer/cast_render_thread_observer.h"
#include "chromecast/renderer/key_systems_cast.h"
#include "chromecast/renderer/media/chromecast_media_renderer_factory.h"
#include "chromecast/renderer/media/media_caps_observer_impl.h"
#include "components/network_hints/renderer/prescient_networking_dispatcher.h"
+#include "content/grit/content_resources.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
+#include "gin/modules/module_registry.h"
+#include "gin/per_context_data.h"
+#include "gin/public/context_holder.h"
#include "media/base/media.h"
#include "services/shell/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/platform/WebColor.h"
#include "third_party/WebKit/public/web/WebFrameWidget.h"
+#include "third_party/WebKit/public/web/WebKit.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebSettings.h"
#include "third_party/WebKit/public/web/WebView.h"
+#include "ui/base/resource/resource_bundle.h"
#if defined(OS_ANDROID)
#include "media/base/android/media_codec_util.h"
@@ -148,5 +158,41 @@ void CastContentRendererClient::DeferMediaLoad(
new CastMediaLoadDeferrer(render_frame, closure);
}
+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.
+ content::RenderFrame* render_frame,
+ 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.
+ 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
+ .GetRawDataResource(resourceId)
+ .as_string();
+ render_frame->ExecuteJavaScript(base::UTF8ToUTF16(js_string));
+}
+
+void CastContentRendererClient::RunScriptsAtDocumentStart(
+ content::RenderFrame* render_frame) {
+ 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
+ blink::WebLocalFrame* frame = render_frame->GetWebFrame();
+ v8::Local<v8::Context> context = frame->mainWorldScriptContext();
+ gin::PerContextData* context_data = gin::PerContextData::From(context);
+ gin::ContextHolder* context_holder = context_data->context_holder();
+ 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
+ gin::Runner::Scope scoper(cast_runner_.get());
+
+ // Initialize AMD API for Mojo.
+ render_frame->EnsureMojoBuiltinsAreAvailable(context_holder->isolate(),
+ context);
+ gin::ModuleRegistry::InstallGlobals(context_holder->isolate(),
+ context->Global());
+
+ // Inject JavaScript files in the correct dependency order.
+ static const int mojoResourceIds[] = {
+ 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.
+ IDR_MOJO_CONNECTOR_JS, IDR_MOJO_VALIDATOR_JS, IDR_MOJO_ROUTER_JS,
+ IDR_MOJO_BINDINGS_JS, IDR_MOJO_CONNECTION_JS,
+ };
+ for (size_t i = 0; i < arraysize(mojoResourceIds); i++) {
+ InjectJavaScript(render_frame, mojoResourceIds[i]);
+ }
+}
+
} // namespace shell
} // namespace chromecast

Powered by Google App Engine
This is Rietveld 408576698