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

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

Issue 1265843005: Refactor feedback to use native JS object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@js-mojo-combine
Patch Set: Param order Created 5 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 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"
(...skipping 27 matching lines...) Expand all
38 38
39 v8::Local<v8::Object> distiller_obj = 39 v8::Local<v8::Object> distiller_obj =
40 GetOrCreateDistillerObject(isolate, context->Global()); 40 GetOrCreateDistillerObject(isolate, context->Global());
41 41
42 distiller_obj->Set( 42 distiller_obj->Set(
43 gin::StringToSymbol(isolate, "echo"), 43 gin::StringToSymbol(isolate, "echo"),
44 gin::CreateFunctionTemplate( 44 gin::CreateFunctionTemplate(
45 isolate, base::Bind(&DistillerNativeJavaScript::DistillerEcho, 45 isolate, base::Bind(&DistillerNativeJavaScript::DistillerEcho,
46 base::Unretained(this))) 46 base::Unretained(this)))
47 ->GetFunction()); 47 ->GetFunction());
48
49 distiller_obj->Set(
50 gin::StringToSymbol(isolate, "sendFeedback"),
51 gin::CreateFunctionTemplate(
52 isolate, base::Bind(&DistillerNativeJavaScript::DistillerSendFeedback,
53 base::Unretained(this)))
54 ->GetFunction());
48 } 55 }
49 56
50 std::string DistillerNativeJavaScript::DistillerEcho( 57 void DistillerNativeJavaScript::ensureServiceConnected() {
51 const std::string& message) {
52 if (!distiller_js_service_) { 58 if (!distiller_js_service_) {
53 render_frame_->GetServiceRegistry()->ConnectToRemoteService( 59 render_frame_->GetServiceRegistry()->ConnectToRemoteService(
nyquist 2015/09/10 19:04:13 Is this a blocking call?
mdjones 2015/09/11 16:50:13 No, from my understanding you immediately get back
nyquist 2015/09/11 17:14:23 So if it's not blocking, what will happen when you
mdjones 2015/09/11 18:25:54 It fails quietly. It is possible to check for an e
54 mojo::GetProxy(&distiller_js_service_)); 60 mojo::GetProxy(&distiller_js_service_));
55 } 61 }
62 }
63
64 void DistillerNativeJavaScript::DistillerSendFeedback(bool good) {
65 ensureServiceConnected();
66 distiller_js_service_->HandleDistillerFeedbackCall(good);
67 }
68
69 std::string DistillerNativeJavaScript::DistillerEcho(
70 const std::string& message) {
71 ensureServiceConnected();
56 // TODO(mdjones): It is possible and beneficial to have information 72 // TODO(mdjones): It is possible and beneficial to have information
57 // returned from the browser process with these calls. The problem 73 // returned from the browser process with these calls. The problem
58 // is waiting blocks this process. 74 // is waiting blocks this process.
59 distiller_js_service_->HandleDistillerEchoCall(message); 75 distiller_js_service_->HandleDistillerEchoCall(message);
60 76
61 return message; 77 return message;
62 } 78 }
63 79
64 v8::Local<v8::Object> GetOrCreateDistillerObject(v8::Isolate* isolate, 80 v8::Local<v8::Object> GetOrCreateDistillerObject(v8::Isolate* isolate,
65 v8::Local<v8::Object> global) { 81 v8::Local<v8::Object> global) {
66 v8::Local<v8::Object> distiller_obj; 82 v8::Local<v8::Object> distiller_obj;
67 v8::Local<v8::Value> distiller_value = 83 v8::Local<v8::Value> distiller_value =
68 global->Get(gin::StringToV8(isolate, "distiller")); 84 global->Get(gin::StringToV8(isolate, "distiller"));
69 if (distiller_value.IsEmpty() || !distiller_value->IsObject()) { 85 if (distiller_value.IsEmpty() || !distiller_value->IsObject()) {
70 distiller_obj = v8::Object::New(isolate); 86 distiller_obj = v8::Object::New(isolate);
71 global->Set(gin::StringToSymbol(isolate, "distiller"), distiller_obj); 87 global->Set(gin::StringToSymbol(isolate, "distiller"), distiller_obj);
72 } else { 88 } else {
73 distiller_obj = v8::Local<v8::Object>::Cast(distiller_value); 89 distiller_obj = v8::Local<v8::Object>::Cast(distiller_value);
74 } 90 }
75 return distiller_obj; 91 return distiller_obj;
76 } 92 }
77 93
78 } // namespace dom_distiller 94 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698