|
8 | 8 | #include <vector>
|
9 | 9 |
|
10 | 10 | #include "atom/common/api/api_messages.h"
|
| 11 | +#include "atom/common/native_mate_converters/string16_converter.h" |
| 12 | +#include "atom/common/native_mate_converters/value_converter.h" |
11 | 13 | #include "atom/common/options_switches.h"
|
12 |
| -#include "atom/renderer/api/atom_renderer_bindings.h" |
13 | 14 | #include "atom/renderer/atom_renderer_client.h"
|
14 | 15 | #include "base/command_line.h"
|
15 | 16 | #include "base/strings/string_number_conversions.h"
|
|
19 | 20 | #include "third_party/WebKit/public/web/WebDocument.h"
|
20 | 21 | #include "third_party/WebKit/public/web/WebFrame.h"
|
21 | 22 | #include "third_party/WebKit/public/web/WebLocalFrame.h"
|
| 23 | +#include "third_party/WebKit/public/web/WebKit.h" |
22 | 24 | #include "third_party/WebKit/public/web/WebView.h"
|
23 | 25 |
|
24 | 26 | #include "atom/common/node_includes.h"
|
25 | 27 |
|
26 |
| -using blink::WebFrame; |
27 |
| - |
28 | 28 | namespace atom {
|
29 | 29 |
|
| 30 | +namespace { |
| 31 | + |
| 32 | +v8::Handle<v8::Object> GetProcessObject(v8::Isolate* isolate, |
| 33 | + v8::Handle<v8::Context> context) { |
| 34 | + v8::Handle<v8::String> key = mate::StringToV8(isolate, "process"); |
| 35 | + return context->Global()->Get(key)->ToObject(); |
| 36 | +} |
| 37 | + |
| 38 | +std::vector<v8::Handle<v8::Value>> ListValueToVector( |
| 39 | + v8::Isolate* isolate, |
| 40 | + const base::ListValue& list) { |
| 41 | + v8::Handle<v8::Value> array = mate::ConvertToV8(isolate, list); |
| 42 | + std::vector<v8::Handle<v8::Value>> result; |
| 43 | + mate::ConvertFromV8(isolate, array, &result); |
| 44 | + return result; |
| 45 | +} |
| 46 | + |
| 47 | +} // namespace |
| 48 | + |
30 | 49 | AtomRenderViewObserver::AtomRenderViewObserver(
|
31 | 50 | content::RenderView* render_view,
|
32 | 51 | AtomRendererClient* renderer_client)
|
@@ -82,8 +101,25 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
|
82 | 101 | if (!document_created_)
|
83 | 102 | return;
|
84 | 103 |
|
85 |
| - renderer_client_->atom_bindings()->OnBrowserMessage( |
86 |
| - render_view(), channel, args); |
| 104 | + if (!render_view()->GetWebView()) |
| 105 | + return; |
| 106 | + |
| 107 | + blink::WebFrame* frame = render_view()->GetWebView()->mainFrame(); |
| 108 | + if (!frame || frame->isWebRemoteFrame()) |
| 109 | + return; |
| 110 | + |
| 111 | + v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 112 | + v8::HandleScope handle_scope(isolate); |
| 113 | + |
| 114 | + v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 115 | + v8::Context::Scope context_scope(context); |
| 116 | + |
| 117 | + std::vector<v8::Handle<v8::Value>> arguments = ListValueToVector( |
| 118 | + isolate, args); |
| 119 | + arguments.insert(arguments.begin(), mate::ConvertToV8(isolate, channel)); |
| 120 | + |
| 121 | + v8::Handle<v8::Object> process = GetProcessObject(isolate, context); |
| 122 | + node::MakeCallback(isolate, process, "emit", arguments.size(), &arguments[0]); |
87 | 123 | }
|
88 | 124 |
|
89 | 125 | } // namespace atom
|
0 commit comments