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

Side by Side Diff: chrome/renderer/extensions/dispatcher.cc

Issue 12313142: Revert 184837 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/event_bindings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dispatcher.h" 5 #include "chrome/renderer/extensions/dispatcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
11 #include "base/string_split.h"
12 #include "chrome/common/child_process_logging.h" 11 #include "chrome/common/child_process_logging.h"
13 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/chrome_version_info.h" 13 #include "chrome/common/chrome_version_info.h"
15 #include "chrome/common/extensions/api/extension_api.h" 14 #include "chrome/common/extensions/api/extension_api.h"
16 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_messages.h" 16 #include "chrome/common/extensions/extension_messages.h"
18 #include "chrome/common/extensions/features/feature.h"
19 #include "chrome/common/extensions/manifest.h" 17 #include "chrome/common/extensions/manifest.h"
20 #include "chrome/common/extensions/permissions/permission_set.h" 18 #include "chrome/common/extensions/permissions/permission_set.h"
21 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
22 #include "chrome/common/view_type.h" 20 #include "chrome/common/view_type.h"
23 #include "chrome/renderer/chrome_render_process_observer.h" 21 #include "chrome/renderer/chrome_render_process_observer.h"
24 #include "chrome/renderer/extensions/api_definitions_natives.h" 22 #include "chrome/renderer/extensions/api_definitions_natives.h"
25 #include "chrome/renderer/extensions/app_bindings.h" 23 #include "chrome/renderer/extensions/app_bindings.h"
26 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" 24 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h"
27 #include "chrome/renderer/extensions/app_window_custom_bindings.h" 25 #include "chrome/renderer/extensions/app_window_custom_bindings.h"
28 #include "chrome/renderer/extensions/binding_generating_native_handler.h"
29 #include "chrome/renderer/extensions/chrome_v8_context.h" 26 #include "chrome/renderer/extensions/chrome_v8_context.h"
30 #include "chrome/renderer/extensions/chrome_v8_extension.h" 27 #include "chrome/renderer/extensions/chrome_v8_extension.h"
31 #include "chrome/renderer/extensions/content_watcher.h" 28 #include "chrome/renderer/extensions/content_watcher.h"
32 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" 29 #include "chrome/renderer/extensions/context_menus_custom_bindings.h"
33 #include "chrome/renderer/extensions/event_bindings.h" 30 #include "chrome/renderer/extensions/event_bindings.h"
34 #include "chrome/renderer/extensions/extension_custom_bindings.h" 31 #include "chrome/renderer/extensions/extension_custom_bindings.h"
35 #include "chrome/renderer/extensions/extension_groups.h" 32 #include "chrome/renderer/extensions/extension_groups.h"
36 #include "chrome/renderer/extensions/extension_helper.h" 33 #include "chrome/renderer/extensions/extension_helper.h"
37 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" 34 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
38 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" 35 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
39 #include "chrome/renderer/extensions/file_system_natives.h" 36 #include "chrome/renderer/extensions/file_system_natives.h"
40 #include "chrome/renderer/extensions/i18n_custom_bindings.h" 37 #include "chrome/renderer/extensions/i18n_custom_bindings.h"
41 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" 38 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h"
42 #include "chrome/renderer/extensions/miscellaneous_bindings.h" 39 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
43 #include "chrome/renderer/extensions/module_system.h" 40 #include "chrome/renderer/extensions/module_system.h"
44 #include "chrome/renderer/extensions/object_backed_native_handler.h" 41 #include "chrome/renderer/extensions/native_handler.h"
45 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" 42 #include "chrome/renderer/extensions/page_actions_custom_bindings.h"
46 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" 43 #include "chrome/renderer/extensions/page_capture_custom_bindings.h"
47 #include "chrome/renderer/extensions/request_sender.h" 44 #include "chrome/renderer/extensions/request_sender.h"
48 #include "chrome/renderer/extensions/runtime_custom_bindings.h" 45 #include "chrome/renderer/extensions/runtime_custom_bindings.h"
49 #include "chrome/renderer/extensions/send_request_natives.h" 46 #include "chrome/renderer/extensions/send_request_natives.h"
50 #include "chrome/renderer/extensions/set_icon_natives.h" 47 #include "chrome/renderer/extensions/set_icon_natives.h"
51 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" 48 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h"
52 #include "chrome/renderer/extensions/tab_finder.h" 49 #include "chrome/renderer/extensions/tab_finder.h"
53 #include "chrome/renderer/extensions/tabs_custom_bindings.h" 50 #include "chrome/renderer/extensions/tabs_custom_bindings.h"
54 #include "chrome/renderer/extensions/tts_custom_bindings.h" 51 #include "chrome/renderer/extensions/tts_custom_bindings.h"
(...skipping 30 matching lines...) Expand all
85 namespace extensions { 82 namespace extensions {
86 83
87 namespace { 84 namespace {
88 85
89 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; 86 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000;
90 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; 87 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000;
91 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; 88 static const char kEventDispatchFunction[] = "Event.dispatchEvent";
92 static const char kOnSuspendEvent[] = "runtime.onSuspend"; 89 static const char kOnSuspendEvent[] = "runtime.onSuspend";
93 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; 90 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled";
94 91
95 static v8::Handle<v8::Object> GetOrCreateChrome( 92 class ChromeHiddenNativeHandler : public NativeHandler {
96 v8::Handle<v8::Context> context) {
97 v8::Handle<v8::String> chrome_string(v8::String::New("chrome"));
98 v8::Handle<v8::Object> global(context->Global());
99 v8::Handle<v8::Value> chrome(global->Get(chrome_string));
100 if (chrome.IsEmpty() || chrome->IsUndefined()) {
101 v8::Handle<v8::Object> chrome_object(v8::Object::New());
102 global->Set(chrome_string, chrome_object);
103 return chrome_object;
104 }
105 CHECK(chrome->IsObject());
106 return chrome->ToObject();
107 }
108
109 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler {
110 public: 93 public:
111 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, 94 explicit ChromeHiddenNativeHandler(v8::Isolate* isolate)
112 v8::Handle<v8::Context> context) 95 : NativeHandler(isolate) {
113 : ObjectBackedNativeHandler(context),
114 registry_(registry) {
115 RouteFunction("GetSchema",
116 base::Bind(&SchemaRegistryNativeHandler::GetSchema,
117 base::Unretained(this)));
118 }
119
120 private:
121 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) {
122 return registry_->GetSchema(*v8::String::AsciiValue(args[0]));
123 }
124
125 V8SchemaRegistry* registry_;
126 };
127
128 class V8ContextNativeHandler : public ObjectBackedNativeHandler {
129 public:
130 explicit V8ContextNativeHandler(ChromeV8Context* context)
131 : ObjectBackedNativeHandler(context->v8_context()),
132 context_(context) {
133 RouteFunction("GetAvailability",
134 base::Bind(&V8ContextNativeHandler::GetAvailability,
135 base::Unretained(this)));
136 }
137
138 private:
139 v8::Handle<v8::Value> GetAvailability(const v8::Arguments& args) {
140 CHECK_EQ(args.Length(), 1);
141 std::string api_name = *v8::String::AsciiValue(args[0]->ToString());
142 Feature::Availability availability = context_->GetAvailability(api_name);
143
144 v8::Handle<v8::Object> ret = v8::Object::New();
145 ret->Set(v8::String::New("is_available"),
146 v8::Boolean::New(availability.is_available()));
147 ret->Set(v8::String::New("message"),
148 v8::String::New(availability.message().c_str()));
149 return ret;
150 }
151
152 ChromeV8Context* context_;
153 };
154
155 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler {
156 public:
157 explicit ChromeHiddenNativeHandler(v8::Handle<v8::Context> context)
158 : ObjectBackedNativeHandler(context) {
159 RouteFunction("GetChromeHidden", 96 RouteFunction("GetChromeHidden",
160 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, 97 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden,
161 base::Unretained(this))); 98 base::Unretained(this)));
162 } 99 }
163 100
164 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { 101 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) {
165 return ChromeV8Context::GetOrCreateChromeHidden(v8_context()); 102 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent());
166 } 103 }
167 }; 104 };
168 105
169 class ChromeNativeHandler : public ObjectBackedNativeHandler { 106 class PrintNativeHandler : public NativeHandler {
170 public: 107 public:
171 explicit ChromeNativeHandler(v8::Handle<v8::Context> context) 108 explicit PrintNativeHandler(v8::Isolate* isolate)
172 : ObjectBackedNativeHandler(context) { 109 : NativeHandler(isolate) {
173 RouteFunction("GetChrome",
174 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this)));
175 }
176
177 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) {
178 return GetOrCreateChrome(v8_context());
179 }
180 };
181
182 class PrintNativeHandler : public ObjectBackedNativeHandler {
183 public:
184 explicit PrintNativeHandler(v8::Handle<v8::Context> context)
185 : ObjectBackedNativeHandler(context) {
186 RouteFunction("Print", 110 RouteFunction("Print",
187 base::Bind(&PrintNativeHandler::Print, 111 base::Bind(&PrintNativeHandler::Print,
188 base::Unretained(this))); 112 base::Unretained(this)));
189 } 113 }
190 114
191 v8::Handle<v8::Value> Print(const v8::Arguments& args) { 115 v8::Handle<v8::Value> Print(const v8::Arguments& args) {
192 if (args.Length() < 1) 116 if (args.Length() < 1)
193 return v8::Undefined(); 117 return v8::Undefined();
194 118
195 std::vector<std::string> components; 119 std::vector<std::string> components;
(...skipping 11 matching lines...) Expand all
207 : ChromeV8Extension(dispatcher) { 131 : ChromeV8Extension(dispatcher) {
208 RouteFunction("IncrementKeepaliveCount", 132 RouteFunction("IncrementKeepaliveCount",
209 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, 133 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount,
210 base::Unretained(this))); 134 base::Unretained(this)));
211 RouteFunction("DecrementKeepaliveCount", 135 RouteFunction("DecrementKeepaliveCount",
212 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, 136 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount,
213 base::Unretained(this))); 137 base::Unretained(this)));
214 } 138 }
215 139
216 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { 140 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) {
217 ChromeV8Context* context = 141 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent();
218 dispatcher()->v8_context_set().GetByV8Context(v8_context());
219 if (!context) 142 if (!context)
220 return v8::Undefined(); 143 return v8::Undefined();
221 RenderView* render_view = context->GetRenderView(); 144 RenderView* render_view = context->GetRenderView();
222 if (IsContextLazyBackgroundPage(render_view, context->extension())) { 145 if (IsContextLazyBackgroundPage(render_view, context->extension())) {
223 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( 146 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount(
224 render_view->GetRoutingID())); 147 render_view->GetRoutingID()));
225 } 148 }
226 return v8::Undefined(); 149 return v8::Undefined();
227 } 150 }
228 151
229 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { 152 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) {
230 ChromeV8Context* context = 153 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent();
231 dispatcher()->v8_context_set().GetByV8Context(v8_context());
232 if (!context) 154 if (!context)
233 return v8::Undefined(); 155 return v8::Undefined();
234 RenderView* render_view = context->GetRenderView(); 156 RenderView* render_view = context->GetRenderView();
235 if (IsContextLazyBackgroundPage(render_view, context->extension())) { 157 if (IsContextLazyBackgroundPage(render_view, context->extension())) {
236 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( 158 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount(
237 render_view->GetRoutingID())); 159 render_view->GetRoutingID()));
238 } 160 }
239 return v8::Undefined(); 161 return v8::Undefined();
240 } 162 }
241 163
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 231 }
310 232
311 private: 233 private:
312 std::string extension_id_; 234 std::string extension_id_;
313 std::string context_type_; 235 std::string context_type_;
314 bool is_incognito_context_; 236 bool is_incognito_context_;
315 int manifest_version_; 237 int manifest_version_;
316 bool send_request_disabled_; 238 bool send_request_disabled_;
317 }; 239 };
318 240
319 class LoggingNativeHandler : public ObjectBackedNativeHandler { 241 class LoggingNativeHandler : public NativeHandler {
320 public: 242 public:
321 explicit LoggingNativeHandler(v8::Handle<v8::Context> context) 243 explicit LoggingNativeHandler(v8::Isolate* isolate)
322 : ObjectBackedNativeHandler(context) { 244 : NativeHandler(isolate) {
323 RouteFunction("DCHECK", 245 RouteFunction("DCHECK",
324 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); 246 base::Bind(&LoggingNativeHandler::Dcheck,
247 base::Unretained(this)));
325 } 248 }
326 249
327 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { 250 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) {
328 CHECK_LE(args.Length(), 2); 251 CHECK_LE(args.Length(), 2);
329 bool check_value = args[0]->BooleanValue(); 252 bool check_value = args[0]->BooleanValue();
330 std::string error_message; 253 std::string error_message;
331 if (args.Length() == 2) 254 if (args.Length() == 2)
332 error_message = "Error: " + std::string(*v8::String::AsciiValue(args[1])); 255 error_message = "Error: " + std::string(*v8::String::AsciiValue(args[1]));
333 256
334 v8::Handle<v8::StackTrace> stack_trace = 257 v8::Handle<v8::StackTrace> stack_trace =
335 v8::StackTrace::CurrentStackTrace(10); 258 v8::StackTrace::CurrentStackTrace(10);
336 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { 259 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) {
337 error_message += "\n <no stack trace>"; 260 error_message += "\n <no stack trace>";
338 } else { 261 } else {
339 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) { 262 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) {
340 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); 263 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i);
341 CHECK(!frame.IsEmpty()); 264 CHECK(!frame.IsEmpty());
342 error_message += base::StringPrintf("\n at %s (%s:%d:%d)", 265 error_message += base::StringPrintf("\n at %s (%s:%d:%d)",
343 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), 266 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(),
344 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), 267 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(),
345 frame->GetLineNumber(), 268 frame->GetLineNumber(),
346 frame->GetColumn()); 269 frame->GetColumn());
347 } 270 }
348 } 271 }
349 DCHECK(check_value) << error_message; 272 DCHECK(check_value) << error_message;
273 LOG(WARNING) << error_message;
350 return v8::Undefined(); 274 return v8::Undefined();
351 } 275 }
352 276
353 private: 277 private:
354 std::string ToStringOrDefault(const v8::Handle<v8::String>& v8_string, 278 std::string ToStringOrDefault(const v8::Handle<v8::String>& v8_string,
355 const std::string& dflt) { 279 const std::string& dflt) {
356 if (v8_string.IsEmpty()) 280 if (v8_string.IsEmpty())
357 return dflt; 281 return dflt;
358 std::string ascii_value = *v8::String::AsciiValue(v8_string); 282 std::string ascii_value = *v8::String::AsciiValue(v8_string);
359 return ascii_value.empty() ? dflt : ascii_value; 283 return ascii_value.empty() ? dflt : ascii_value;
(...skipping 11 matching lines...) Expand all
371 } 295 }
372 296
373 void InstallWebstoreBindings(ModuleSystem* module_system, 297 void InstallWebstoreBindings(ModuleSystem* module_system,
374 v8::Handle<v8::Object> chrome, 298 v8::Handle<v8::Object> chrome,
375 v8::Handle<v8::Object> chrome_hidden) { 299 v8::Handle<v8::Object> chrome_hidden) {
376 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); 300 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore");
377 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", 301 module_system->SetLazyField(chrome_hidden, "webstore", "webstore",
378 "chromeHiddenWebstore"); 302 "chromeHiddenWebstore");
379 } 303 }
380 304
305 static v8::Handle<v8::Object> GetOrCreateChrome(
306 v8::Handle<v8::Context> context) {
307 v8::Handle<v8::String> chrome_string(v8::String::New("chrome"));
308 v8::Handle<v8::Object> global(context->Global());
309 v8::Handle<v8::Value> chrome(global->Get(chrome_string));
310 if (chrome.IsEmpty() || chrome->IsUndefined()) {
311 v8::Handle<v8::Object> chrome_object(v8::Object::New());
312 global->Set(chrome_string, chrome_object);
313 return chrome_object;
314 }
315 CHECK(chrome->IsObject());
316 return chrome->ToObject();
317 }
318
381 } // namespace 319 } // namespace
382 320
383 Dispatcher::Dispatcher() 321 Dispatcher::Dispatcher()
384 : content_watcher_(new ContentWatcher(this)), 322 : content_watcher_(new ContentWatcher(this)),
385 is_webkit_initialized_(false), 323 is_webkit_initialized_(false),
386 webrequest_adblock_(false), 324 webrequest_adblock_(false),
387 webrequest_adblock_plus_(false), 325 webrequest_adblock_plus_(false),
388 webrequest_other_(false), 326 webrequest_other_(false),
389 source_map_(&ResourceBundle::GetSharedInstance()) { 327 source_map_(&ResourceBundle::GetSharedInstance()) {
390 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 328 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
391 is_extension_process_ = 329 is_extension_process_ =
392 command_line.HasSwitch(switches::kExtensionProcess) || 330 command_line.HasSwitch(switches::kExtensionProcess) ||
393 command_line.HasSwitch(switches::kSingleProcess); 331 command_line.HasSwitch(switches::kSingleProcess);
394 332
395 if (is_extension_process_) { 333 if (is_extension_process_) {
396 RenderThread::Get()->SetIdleNotificationDelayInMs( 334 RenderThread::Get()->SetIdleNotificationDelayInMs(
397 kInitialExtensionIdleHandlerDelayMs); 335 kInitialExtensionIdleHandlerDelayMs);
398 } 336 }
399 337
400 user_script_slave_.reset(new UserScriptSlave(&extensions_)); 338 user_script_slave_.reset(new UserScriptSlave(&extensions_));
401 request_sender_.reset(new RequestSender(this)); 339 request_sender_.reset(new RequestSender(this, &v8_context_set_));
402 PopulateSourceMap(); 340 PopulateSourceMap();
403 PopulateLazyBindingsMap(); 341 PopulateLazyBindingsMap();
404 } 342 }
405 343
406 Dispatcher::~Dispatcher() { 344 Dispatcher::~Dispatcher() {
407 } 345 }
408 346
409 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { 347 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) {
410 bool handled = true; 348 bool handled = true;
411 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) 349 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message)
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } // namespace 553 } // namespace
616 554
617 bool Dispatcher::AllowScriptExtension(WebFrame* frame, 555 bool Dispatcher::AllowScriptExtension(WebFrame* frame,
618 const std::string& v8_extension_name, 556 const std::string& v8_extension_name,
619 int extension_group, 557 int extension_group,
620 int world_id) { 558 int world_id) {
621 g_hack_extension_group = extension_group; 559 g_hack_extension_group = extension_group;
622 return true; 560 return true;
623 } 561 }
624 562
625 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
626 v8::Handle<v8::Object> object,
627 const std::string& field) {
628 v8::Handle<v8::String> key = v8::String::New(field.c_str());
629 // This little dance is for APIs that may be unavailable but have available
630 // children. For example, chrome.app can be unavailable, while
631 // chrome.app.runtime is available. The lazy getter for chrome.app must be
632 // deleted, so that there isn't an error when accessing chrome.app.runtime.
633 if (object->Has(key)) {
634 v8::Handle<v8::Object> existing =
635 v8::Handle<v8::Object>::Cast(object->Get(key));
636 if (!existing.IsEmpty() && !existing->IsUndefined())
637 return existing;
638 else
639 object->Delete(key);
640 }
641
642 v8::Handle<v8::Object> new_object = v8::Object::New();
643 object->Set(key, new_object);
644 return new_object;
645 }
646
647 void Dispatcher::RegisterSchemaGeneratedBindings(
648 ModuleSystem* module_system,
649 ChromeV8Context* context,
650 v8::Handle<v8::Context> v8_context) {
651 std::set<std::string> apis =
652 ExtensionAPI::GetSharedInstance()->GetAllAPINames();
653 for (std::set<std::string>::iterator it = apis.begin();
654 it != apis.end(); ++it) {
655 const std::string& api_name = *it;
656
657 std::vector<std::string> split;
658 base::SplitString(api_name, '.', &split);
659
660 v8::Handle<v8::Object> bind_object = GetOrCreateChrome(v8_context);
661 for (size_t i = 0; i < split.size() - 1; ++i)
662 bind_object = GetOrCreateObject(bind_object, split[i]);
663
664 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) {
665 InstallBindings(module_system, v8_context, api_name);
666 } else if (!source_map_.Contains(api_name)) {
667 module_system->RegisterNativeHandler(
668 api_name,
669 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler(
670 module_system,
671 api_name,
672 "binding")));
673 module_system->SetNativeLazyField(bind_object,
674 split.back(),
675 api_name,
676 "binding");
677 } else {
678 module_system->SetLazyField(bind_object,
679 split.back(),
680 api_name,
681 "binding");
682 }
683 }
684 }
685
686 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, 563 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
687 ChromeV8Context* context) { 564 ChromeV8Context* context) {
688 module_system->RegisterNativeHandler("event_bindings", 565 module_system->RegisterNativeHandler("event_bindings",
689 scoped_ptr<NativeHandler>( 566 scoped_ptr<NativeHandler>(EventBindings::Get(this)));
690 EventBindings::Create(this, context->v8_context())));
691 module_system->RegisterNativeHandler("miscellaneous_bindings", 567 module_system->RegisterNativeHandler("miscellaneous_bindings",
692 scoped_ptr<NativeHandler>( 568 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this)));
693 MiscellaneousBindings::Get(this, context->v8_context())));
694 module_system->RegisterNativeHandler("apiDefinitions", 569 module_system->RegisterNativeHandler("apiDefinitions",
695 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); 570 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this)));
696 module_system->RegisterNativeHandler("sendRequest", 571 module_system->RegisterNativeHandler("sendRequest",
697 scoped_ptr<NativeHandler>( 572 scoped_ptr<NativeHandler>(
698 new SendRequestNatives(this, request_sender_.get(), context))); 573 new SendRequestNatives(this, request_sender_.get())));
699 module_system->RegisterNativeHandler("setIcon", 574 module_system->RegisterNativeHandler("setIcon",
700 scoped_ptr<NativeHandler>( 575 scoped_ptr<NativeHandler>(
701 new SetIconNatives(this, request_sender_.get(), context))); 576 new SetIconNatives(this, request_sender_.get())));
702 module_system->RegisterNativeHandler("contentWatcherNative", 577 module_system->RegisterNativeHandler("contentWatcherNative",
703 content_watcher_->MakeNatives()); 578 content_watcher_->MakeNatives());
704 579
705 // Natives used by multiple APIs. 580 // Natives used by multiple APIs.
706 module_system->RegisterNativeHandler("file_system_natives", 581 module_system->RegisterNativeHandler("file_system_natives",
707 scoped_ptr<NativeHandler>(new FileSystemNatives(context->v8_context()))); 582 scoped_ptr<NativeHandler>(new FileSystemNatives()));
708 583
709 // Custom bindings. 584 // Custom bindings.
710 module_system->RegisterNativeHandler("app", 585 module_system->RegisterNativeHandler("app",
711 scoped_ptr<NativeHandler>(new AppBindings(this, context))); 586 scoped_ptr<NativeHandler>(new AppBindings(this, context)));
712 module_system->RegisterNativeHandler("app_runtime", 587 module_system->RegisterNativeHandler("app_runtime",
713 scoped_ptr<NativeHandler>( 588 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings()));
714 new AppRuntimeCustomBindings(this, context->v8_context())));
715 module_system->RegisterNativeHandler("app_window", 589 module_system->RegisterNativeHandler("app_window",
716 scoped_ptr<NativeHandler>( 590 scoped_ptr<NativeHandler>(new AppWindowCustomBindings(this)));
717 new AppWindowCustomBindings(this, context->v8_context())));
718 module_system->RegisterNativeHandler("context_menus", 591 module_system->RegisterNativeHandler("context_menus",
719 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); 592 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings()));
720 module_system->RegisterNativeHandler("extension", 593 module_system->RegisterNativeHandler("extension",
721 scoped_ptr<NativeHandler>( 594 scoped_ptr<NativeHandler>(
722 new ExtensionCustomBindings(this, context->v8_context()))); 595 new ExtensionCustomBindings(this)));
723 module_system->RegisterNativeHandler("sync_file_system", 596 module_system->RegisterNativeHandler("sync_file_system",
724 scoped_ptr<NativeHandler>(new SyncFileSystemCustomBindings())); 597 scoped_ptr<NativeHandler>(new SyncFileSystemCustomBindings()));
725 module_system->RegisterNativeHandler("file_browser_handler", 598 module_system->RegisterNativeHandler("file_browser_handler",
726 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( 599 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings()));
727 context->v8_context())));
728 module_system->RegisterNativeHandler("file_browser_private", 600 module_system->RegisterNativeHandler("file_browser_private",
729 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( 601 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings()));
730 context->v8_context())));
731 module_system->RegisterNativeHandler("i18n", 602 module_system->RegisterNativeHandler("i18n",
732 scoped_ptr<NativeHandler>( 603 scoped_ptr<NativeHandler>(new I18NCustomBindings()));
733 new I18NCustomBindings(this, context->v8_context())));
734 module_system->RegisterNativeHandler("mediaGalleries", 604 module_system->RegisterNativeHandler("mediaGalleries",
735 scoped_ptr<NativeHandler>(new MediaGalleriesCustomBindings())); 605 scoped_ptr<NativeHandler>(new MediaGalleriesCustomBindings()));
736 module_system->RegisterNativeHandler("page_actions", 606 module_system->RegisterNativeHandler("page_actions",
737 scoped_ptr<NativeHandler>( 607 scoped_ptr<NativeHandler>(
738 new PageActionsCustomBindings(this))); 608 new PageActionsCustomBindings(this)));
739 module_system->RegisterNativeHandler("page_capture", 609 module_system->RegisterNativeHandler("page_capture",
740 scoped_ptr<NativeHandler>( 610 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings()));
741 new PageCaptureCustomBindings(this, context->v8_context())));
742 module_system->RegisterNativeHandler("runtime", 611 module_system->RegisterNativeHandler("runtime",
743 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); 612 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context)));
744 module_system->RegisterNativeHandler("tabs", 613 module_system->RegisterNativeHandler("tabs",
745 scoped_ptr<NativeHandler>( 614 scoped_ptr<NativeHandler>(new TabsCustomBindings()));
746 new TabsCustomBindings(this, context->v8_context())));
747 module_system->RegisterNativeHandler("tts", 615 module_system->RegisterNativeHandler("tts",
748 scoped_ptr<NativeHandler>(new TTSCustomBindings())); 616 scoped_ptr<NativeHandler>(new TTSCustomBindings()));
749 module_system->RegisterNativeHandler("web_request", 617 module_system->RegisterNativeHandler("web_request",
750 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); 618 scoped_ptr<NativeHandler>(new WebRequestCustomBindings()));
751 module_system->RegisterNativeHandler("webstore", 619 module_system->RegisterNativeHandler("webstore",
752 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); 620 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context)));
753 } 621 }
754 622
755 void Dispatcher::PopulateSourceMap() { 623 void Dispatcher::PopulateSourceMap() {
756 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); 624 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS);
757 source_map_.RegisterSource("miscellaneous_bindings", 625 source_map_.RegisterSource("miscellaneous_bindings",
758 IDR_MISCELLANEOUS_BINDINGS_JS); 626 IDR_MISCELLANEOUS_BINDINGS_JS);
627 source_map_.RegisterSource("schema_generated_bindings",
628 IDR_SCHEMA_GENERATED_BINDINGS_JS);
759 source_map_.RegisterSource("json", IDR_JSON_JS); 629 source_map_.RegisterSource("json", IDR_JSON_JS);
760 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); 630 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS);
761 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); 631 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS);
762 632
763 // Libraries. 633 // Libraries.
764 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); 634 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS);
765 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); 635 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS);
766 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); 636 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS);
767 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); 637 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS);
768 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); 638 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS);
769 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); 639 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS);
770 source_map_.RegisterSource("utils", IDR_UTILS_JS); 640 source_map_.RegisterSource("utils", IDR_UTILS_JS);
771 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); 641 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); 688 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS);
819 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); 689 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS);
820 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); 690 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS);
821 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); 691 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS);
822 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); 692 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS);
823 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); 693 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS);
824 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); 694 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS);
825 source_map_.RegisterSource("webRequestInternal", 695 source_map_.RegisterSource("webRequestInternal",
826 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); 696 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS);
827 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); 697 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS);
828 source_map_.RegisterSource("binding", IDR_BINDING_JS);
829 698
830 // Platform app sources that are not API-specific.. 699 // Platform app sources that are not API-specific..
831 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); 700 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS);
832 source_map_.RegisterSource("web_view", IDR_WEB_VIEW_JS); 701 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS);
833 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); 702 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS);
834 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); 703 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS);
835 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); 704 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS);
836 } 705 }
837 706
838 void Dispatcher::PopulateLazyBindingsMap() { 707 void Dispatcher::PopulateLazyBindingsMap() {
839 lazy_bindings_map_["app"] = InstallAppBindings; 708 lazy_bindings_map_["app"] = InstallAppBindings;
840 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; 709 lazy_bindings_map_["webstore"] = InstallWebstoreBindings;
841 } 710 }
842 711
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 new ChromeV8Context(v8_context, frame, extension, context_type); 764 new ChromeV8Context(v8_context, frame, extension, context_type);
896 v8_context_set_.Add(context); 765 v8_context_set_.Add(context);
897 766
898 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, 767 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context,
899 &source_map_)); 768 &source_map_));
900 // Enable natives in startup. 769 // Enable natives in startup.
901 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); 770 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get());
902 771
903 RegisterNativeHandlers(module_system.get(), context); 772 RegisterNativeHandlers(module_system.get(), context);
904 773
905 module_system->RegisterNativeHandler("chrome", 774 v8::Isolate* isolate = v8_context->GetIsolate();
906 scoped_ptr<NativeHandler>(new ChromeNativeHandler(v8_context)));
907 module_system->RegisterNativeHandler("chrome_hidden", 775 module_system->RegisterNativeHandler("chrome_hidden",
908 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(v8_context))); 776 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate)));
909 module_system->RegisterNativeHandler("print", 777 module_system->RegisterNativeHandler("print",
910 scoped_ptr<NativeHandler>(new PrintNativeHandler(v8_context))); 778 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate)));
911 module_system->RegisterNativeHandler("lazy_background_page", 779 module_system->RegisterNativeHandler("lazy_background_page",
912 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); 780 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this)));
913 module_system->RegisterNativeHandler("logging", 781 module_system->RegisterNativeHandler("logging",
914 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); 782 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate)));
915 module_system->RegisterNativeHandler("schema_registry",
916 scoped_ptr<NativeHandler>(
917 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context)));
918 module_system->RegisterNativeHandler("v8_context",
919 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context)));
920 783
921 int manifest_version = extension ? extension->manifest_version() : 1; 784 int manifest_version = extension ? extension->manifest_version() : 1;
922 bool send_request_disabled = 785 bool send_request_disabled =
923 (extension && extension->location() == Manifest::LOAD && 786 (extension && extension->location() == Manifest::LOAD &&
924 extension->has_lazy_background_page()); 787 extension->has_lazy_background_page());
925 module_system->RegisterNativeHandler("process", 788 module_system->RegisterNativeHandler("process",
926 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( 789 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler(
927 this, context->GetExtensionID(), 790 this, context->GetExtensionID(),
928 context->GetContextTypeDescription(), 791 context->GetContextTypeDescription(),
929 ChromeRenderProcessObserver::is_incognito_process(), 792 ChromeRenderProcessObserver::is_incognito_process(),
930 manifest_version, send_request_disabled))); 793 manifest_version, send_request_disabled)));
931 794
932 GetOrCreateChrome(v8_context); 795 GetOrCreateChrome(v8_context);
933 796
934 // Loading JavaScript is expensive, so only run the full API bindings 797 // Loading JavaScript is expensive, so only run the full API bindings
935 // generation mechanisms in extension pages (NOT all web pages). 798 // generation mechanisms in extension pages (NOT all web pages).
936 switch (context_type) { 799 switch (context_type) {
937 case Feature::UNSPECIFIED_CONTEXT: 800 case Feature::UNSPECIFIED_CONTEXT:
938 case Feature::WEB_PAGE_CONTEXT: 801 case Feature::WEB_PAGE_CONTEXT:
939 // TODO(kalman): see comment below about ExtensionAPI. 802 // TODO(kalman): see comment below about ExtensionAPI.
940 InstallBindings(module_system.get(), v8_context, "app"); 803 InstallBindings(module_system.get(), v8_context, "app");
941 InstallBindings(module_system.get(), v8_context, "webstore"); 804 InstallBindings(module_system.get(), v8_context, "webstore");
942 break; 805 break;
806
943 case Feature::BLESSED_EXTENSION_CONTEXT: 807 case Feature::BLESSED_EXTENSION_CONTEXT:
944 case Feature::UNBLESSED_EXTENSION_CONTEXT: 808 case Feature::UNBLESSED_EXTENSION_CONTEXT:
945 case Feature::CONTENT_SCRIPT_CONTEXT: { 809 case Feature::CONTENT_SCRIPT_CONTEXT: {
946 if (extension && !extension->is_platform_app())
947 module_system->Require("miscellaneous_bindings");
948 module_system->Require("json"); // see paranoid comment in json.js 810 module_system->Require("json"); // see paranoid comment in json.js
811 module_system->Require("miscellaneous_bindings");
812 module_system->Require("schema_generated_bindings");
813 module_system->Require("apitest");
949 814
950 // TODO(kalman): move this code back out of the switch and execute it 815 // TODO(kalman): move this code back out of the switch and execute it
951 // regardless of |context_type|. ExtensionAPI knows how to return the 816 // regardless of |context_type|. ExtensionAPI knows how to return the
952 // correct APIs, however, until it doesn't have a 2MB overhead we can't 817 // correct APIs, however, until it doesn't have a 2MB overhead we can't
953 // load it in every process. 818 // load it in every process.
954 RegisterSchemaGeneratedBindings(module_system.get(), 819 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs();
955 context, 820 for (std::set<std::string>::const_iterator i = apis.begin();
956 v8_context); 821 i != apis.end(); ++i) {
822 InstallBindings(module_system.get(), v8_context, *i);
823 }
824
957 break; 825 break;
958 } 826 }
959 } 827 }
960 828
961 // Inject custom JS into the platform app context. 829 // Inject custom JS into the platform app context.
962 if (IsWithinPlatformApp(frame)) 830 if (IsWithinPlatformApp(frame))
963 module_system->Require("platformApp"); 831 module_system->Require("platformApp");
964 832
965 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 833 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
966 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); 834 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView);
967 module_system->Require(has_permission ? "web_view" : "denyWebview"); 835 module_system->Require(has_permission ? "webview" : "denyWebview");
968 } 836 }
969 837
970 context->set_module_system(module_system.Pass()); 838 context->set_module_system(module_system.Pass());
971 839
972 context->DispatchOnLoadEvent( 840 context->DispatchOnLoadEvent(
973 ChromeRenderProcessObserver::is_incognito_process(), 841 ChromeRenderProcessObserver::is_incognito_process(),
974 manifest_version); 842 manifest_version);
975 843
976 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 844 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
977 } 845 }
(...skipping 20 matching lines...) Expand all
998 return extension && extension->is_platform_app(); 866 return extension && extension->is_platform_app();
999 } 867 }
1000 868
1001 void Dispatcher::WillReleaseScriptContext( 869 void Dispatcher::WillReleaseScriptContext(
1002 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { 870 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) {
1003 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); 871 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context);
1004 if (!context) 872 if (!context)
1005 return; 873 return;
1006 874
1007 context->DispatchOnUnloadEvent(); 875 context->DispatchOnUnloadEvent();
1008 // TODO(kalman): add an invalidation observer interface to ChromeV8Context.
1009 request_sender_->InvalidateContext(context);
1010 876
1011 v8_context_set_.Remove(context); 877 v8_context_set_.Remove(context);
1012 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 878 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
1013 } 879 }
1014 880
1015 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { 881 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) {
1016 if (IsWithinPlatformApp(frame)) { 882 if (IsWithinPlatformApp(frame)) {
1017 // WebKit doesn't let us define an additional user agent stylesheet, so we 883 // WebKit doesn't let us define an additional user agent stylesheet, so we
1018 // insert the default platform app stylesheet into all documents that are 884 // insert the default platform app stylesheet into all documents that are
1019 // loaded in each app. 885 // loaded in each app.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 return Feature::UNSPECIFIED_CONTEXT; 1102 return Feature::UNSPECIFIED_CONTEXT;
1237 } 1103 }
1238 1104
1239 void Dispatcher::OnExtensionResponse(int request_id, 1105 void Dispatcher::OnExtensionResponse(int request_id,
1240 bool success, 1106 bool success,
1241 const base::ListValue& response, 1107 const base::ListValue& response,
1242 const std::string& error) { 1108 const std::string& error) {
1243 request_sender_->HandleResponse(request_id, success, response, error); 1109 request_sender_->HandleResponse(request_id, success, response, error);
1244 } 1110 }
1245 1111
1246 bool Dispatcher::CheckContextAccessToExtensionAPI( 1112 bool Dispatcher::CheckCurrentContextAccessToExtensionAPI(
1247 const std::string& function_name, ChromeV8Context* context) const { 1113 const std::string& function_name) const {
1114 ChromeV8Context* context = v8_context_set().GetCurrent();
1248 if (!context) { 1115 if (!context) {
1249 DLOG(ERROR) << "Not in a v8::Context"; 1116 DLOG(ERROR) << "Not in a v8::Context";
1250 return false; 1117 return false;
1251 } 1118 }
1252 1119
1253 if (!context->extension()) { 1120 if (!context->extension()) {
1254 v8::ThrowException( 1121 v8::ThrowException(
1255 v8::Exception::Error(v8::String::New("Not in an extension."))); 1122 v8::Exception::Error(v8::String::New("Not in an extension.")));
1256 return false; 1123 return false;
1257 } 1124 }
(...skipping 29 matching lines...) Expand all
1287 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1154 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1288 v8::ThrowException( 1155 v8::ThrowException(
1289 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1156 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1290 return false; 1157 return false;
1291 } 1158 }
1292 1159
1293 return true; 1160 return true;
1294 } 1161 }
1295 1162
1296 } // namespace extensions 1163 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/event_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698