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

Side by Side Diff: components/dom_distiller/content/renderer/distiller_native_javascript.cc

Issue 2079943002: Change RenderFrame to use InterfaceRegistry et al. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a2
Patch Set: . Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/dom_distiller/content/renderer/distiller_native_javascript. h" 5 #include "components/dom_distiller/content/renderer/distiller_native_javascript. h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/dom_distiller/content/common/distiller_javascript_service.m ojom.h" 11 #include "components/dom_distiller/content/common/distiller_javascript_service.m ojom.h"
12 #include "content/public/common/service_registry.h"
13 #include "content/public/renderer/render_frame.h" 12 #include "content/public/renderer/render_frame.h"
14 #include "gin/arguments.h" 13 #include "gin/arguments.h"
15 #include "gin/function_template.h" 14 #include "gin/function_template.h"
15 #include "services/shell/public/cpp/interface_provider.h"
16 #include "third_party/WebKit/public/web/WebKit.h" 16 #include "third_party/WebKit/public/web/WebKit.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
19 19
20 using blink::WebLocalFrame; 20 using blink::WebLocalFrame;
21 21
22 namespace dom_distiller { 22 namespace dom_distiller {
23 23
24 DistillerNativeJavaScript::DistillerNativeJavaScript( 24 DistillerNativeJavaScript::DistillerNativeJavaScript(
25 content::RenderFrame* render_frame) 25 content::RenderFrame* render_frame)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const base::Callback<Sig> callback) { 78 const base::Callback<Sig> callback) {
79 // Get the isolate associated with this object. 79 // Get the isolate associated with this object.
80 v8::Isolate* isolate = javascript_object->GetIsolate(); 80 v8::Isolate* isolate = javascript_object->GetIsolate();
81 javascript_object->Set( 81 javascript_object->Set(
82 gin::StringToSymbol(isolate, name), 82 gin::StringToSymbol(isolate, name),
83 gin::CreateFunctionTemplate(isolate, callback)->GetFunction()); 83 gin::CreateFunctionTemplate(isolate, callback)->GetFunction());
84 } 84 }
85 85
86 void DistillerNativeJavaScript::EnsureServiceConnected() { 86 void DistillerNativeJavaScript::EnsureServiceConnected() {
87 if (!distiller_js_service_ || !distiller_js_service_.is_bound()) { 87 if (!distiller_js_service_ || !distiller_js_service_.is_bound()) {
88 render_frame_->GetServiceRegistry()->ConnectToRemoteService( 88 render_frame_->GetRemoteInterfaces()->GetInterface(
89 mojo::GetProxy(&distiller_js_service_)); 89 &distiller_js_service_);
90 } 90 }
91 } 91 }
92 92
93 std::string DistillerNativeJavaScript::DistillerEcho( 93 std::string DistillerNativeJavaScript::DistillerEcho(
94 const std::string& message) { 94 const std::string& message) {
95 EnsureServiceConnected(); 95 EnsureServiceConnected();
96 // TODO(mdjones): It is possible and beneficial to have information 96 // TODO(mdjones): It is possible and beneficial to have information
97 // returned from the browser process with these calls. The problem 97 // returned from the browser process with these calls. The problem
98 // is waiting blocks this process. 98 // is waiting blocks this process.
99 distiller_js_service_->HandleDistillerEchoCall(message); 99 distiller_js_service_->HandleDistillerEchoCall(message);
100 100
101 return message; 101 return message;
102 } 102 }
103 103
104 v8::Local<v8::Object> GetOrCreateDistillerObject(v8::Isolate* isolate, 104 v8::Local<v8::Object> GetOrCreateDistillerObject(v8::Isolate* isolate,
105 v8::Local<v8::Object> global) { 105 v8::Local<v8::Object> global) {
106 v8::Local<v8::Object> distiller_obj; 106 v8::Local<v8::Object> distiller_obj;
107 v8::Local<v8::Value> distiller_value = 107 v8::Local<v8::Value> distiller_value =
108 global->Get(gin::StringToV8(isolate, "distiller")); 108 global->Get(gin::StringToV8(isolate, "distiller"));
109 if (distiller_value.IsEmpty() || !distiller_value->IsObject()) { 109 if (distiller_value.IsEmpty() || !distiller_value->IsObject()) {
110 distiller_obj = v8::Object::New(isolate); 110 distiller_obj = v8::Object::New(isolate);
111 global->Set(gin::StringToSymbol(isolate, "distiller"), distiller_obj); 111 global->Set(gin::StringToSymbol(isolate, "distiller"), distiller_obj);
112 } else { 112 } else {
113 distiller_obj = v8::Local<v8::Object>::Cast(distiller_value); 113 distiller_obj = v8::Local<v8::Object>::Cast(distiller_value);
114 } 114 }
115 return distiller_obj; 115 return distiller_obj;
116 } 116 }
117 117
118 } // namespace dom_distiller 118 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698