OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/miscellaneous_bindings.h" | 5 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "chrome/common/extensions/extension_messages.h" | 12 #include "chrome/common/extensions/extension_messages.h" |
13 #include "chrome/common/extensions/message_bundle.h" | 13 #include "chrome/common/extensions/message_bundle.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/renderer/extensions/chrome_v8_context.h" | 15 #include "chrome/renderer/extensions/chrome_v8_context.h" |
16 #include "chrome/renderer/extensions/chrome_v8_context_set.h" | 16 #include "chrome/renderer/extensions/chrome_v8_context_set.h" |
17 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 17 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 18 #include "chrome/renderer/extensions/dispatcher.h" |
18 #include "chrome/renderer/extensions/event_bindings.h" | 19 #include "chrome/renderer/extensions/event_bindings.h" |
19 #include "chrome/renderer/extensions/extension_dispatcher.h" | |
20 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
21 #include "content/public/renderer/render_view.h" | 21 #include "content/public/renderer/render_view.h" |
22 #include "grit/renderer_resources.h" | 22 #include "grit/renderer_resources.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup
pression.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup
pression.h" |
24 #include "v8/include/v8.h" | 24 #include "v8/include/v8.h" |
25 | 25 |
26 // Message passing API example (in a content script): | 26 // Message passing API example (in a content script): |
27 // var extension = | 27 // var extension = |
28 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); | 28 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); |
29 // var port = extension.connect(); | 29 // var port = extension.connect(); |
(...skipping 26 matching lines...) Expand all Loading... |
56 static ExtensionData::PortData& GetPortData(int port_id) { | 56 static ExtensionData::PortData& GetPortData(int port_id) { |
57 return g_extension_data.Get().ports[port_id]; | 57 return g_extension_data.Get().ports[port_id]; |
58 } | 58 } |
59 | 59 |
60 static void ClearPortData(int port_id) { | 60 static void ClearPortData(int port_id) { |
61 g_extension_data.Get().ports.erase(port_id); | 61 g_extension_data.Get().ports.erase(port_id); |
62 } | 62 } |
63 | 63 |
64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; | 64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; |
65 | 65 |
66 class ExtensionImpl : public ChromeV8Extension { | 66 class ExtensionImpl : public extensions::ChromeV8Extension { |
67 public: | 67 public: |
68 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) | 68 explicit ExtensionImpl(extensions::Dispatcher* dispatcher) |
69 : ChromeV8Extension(dispatcher) { | 69 : extensions::ChromeV8Extension(dispatcher) { |
70 RouteStaticFunction("CloseChannel", &CloseChannel); | 70 RouteStaticFunction("CloseChannel", &CloseChannel); |
71 RouteStaticFunction("PortAddRef", &PortAddRef); | 71 RouteStaticFunction("PortAddRef", &PortAddRef); |
72 RouteStaticFunction("PortRelease", &PortRelease); | 72 RouteStaticFunction("PortRelease", &PortRelease); |
73 RouteStaticFunction("PostMessage", &PostMessage); | 73 RouteStaticFunction("PostMessage", &PostMessage); |
74 RouteStaticFunction("BindToGC", &BindToGC); | 74 RouteStaticFunction("BindToGC", &BindToGC); |
75 } | 75 } |
76 | 76 |
77 ~ExtensionImpl() {} | 77 ~ExtensionImpl() {} |
78 | 78 |
79 // Sends a message along the given channel. | 79 // Sends a message along the given channel. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 NOTREACHED(); | 166 NOTREACHED(); |
167 } | 167 } |
168 return v8::Undefined(); | 168 return v8::Undefined(); |
169 } | 169 } |
170 }; | 170 }; |
171 | 171 |
172 } // namespace | 172 } // namespace |
173 | 173 |
174 namespace extensions { | 174 namespace extensions { |
175 | 175 |
176 ChromeV8Extension* MiscellaneousBindings::Get(ExtensionDispatcher* dispatcher) { | 176 ChromeV8Extension* MiscellaneousBindings::Get(Dispatcher* dispatcher) { |
177 return new ExtensionImpl(dispatcher); | 177 return new ExtensionImpl(dispatcher); |
178 } | 178 } |
179 | 179 |
180 // static | 180 // static |
181 void MiscellaneousBindings::DispatchOnConnect( | 181 void MiscellaneousBindings::DispatchOnConnect( |
182 const ChromeV8ContextSet::ContextSet& contexts, | 182 const ChromeV8ContextSet::ContextSet& contexts, |
183 int target_port_id, | 183 int target_port_id, |
184 const std::string& channel_name, | 184 const std::string& channel_name, |
185 const std::string& tab_json, | 185 const std::string& tab_json, |
186 const std::string& source_extension_id, | 186 const std::string& source_extension_id, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 294 |
295 std::vector<v8::Handle<v8::Value> > arguments; | 295 std::vector<v8::Handle<v8::Value> > arguments; |
296 arguments.push_back(v8::Integer::New(port_id)); | 296 arguments.push_back(v8::Integer::New(port_id)); |
297 arguments.push_back(v8::Boolean::New(connection_error)); | 297 arguments.push_back(v8::Boolean::New(connection_error)); |
298 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", | 298 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", |
299 arguments.size(), &arguments[0], | 299 arguments.size(), &arguments[0], |
300 NULL); | 300 NULL); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 } // namespace extension | 304 } // namespace extensions |
OLD | NEW |