OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/object_backed_native_handler.h" | 5 #include "extensions/renderer/object_backed_native_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
9 #include "extensions/renderer/console.h" | 9 #include "extensions/renderer/console.h" |
10 #include "extensions/renderer/module_system.h" | 10 #include "extensions/renderer/module_system.h" |
11 #include "extensions/renderer/script_context.h" | 11 #include "extensions/renderer/script_context.h" |
| 12 #include "extensions/renderer/script_context_set.h" |
12 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
13 | 14 |
14 namespace extensions { | 15 namespace extensions { |
15 | 16 |
16 namespace { | 17 namespace { |
17 // Key for the base::Bound routed function. | 18 // Key for the base::Bound routed function. |
18 const char* kHandlerFunction = "handler_function"; | 19 const char* kHandlerFunction = "handler_function"; |
19 } // namespace | 20 } // namespace |
20 | 21 |
21 ObjectBackedNativeHandler::ObjectBackedNativeHandler(ScriptContext* context) | 22 ObjectBackedNativeHandler::ObjectBackedNativeHandler(ScriptContext* context) |
(...skipping 15 matching lines...) Expand all Loading... |
37 void ObjectBackedNativeHandler::Router( | 38 void ObjectBackedNativeHandler::Router( |
38 const v8::FunctionCallbackInfo<v8::Value>& args) { | 39 const v8::FunctionCallbackInfo<v8::Value>& args) { |
39 v8::HandleScope handle_scope(args.GetIsolate()); | 40 v8::HandleScope handle_scope(args.GetIsolate()); |
40 v8::Local<v8::Object> data = args.Data().As<v8::Object>(); | 41 v8::Local<v8::Object> data = args.Data().As<v8::Object>(); |
41 | 42 |
42 v8::Local<v8::Value> handler_function_value = | 43 v8::Local<v8::Value> handler_function_value = |
43 data->Get(v8::String::NewFromUtf8(args.GetIsolate(), kHandlerFunction)); | 44 data->Get(v8::String::NewFromUtf8(args.GetIsolate(), kHandlerFunction)); |
44 // See comment in header file for why we do this. | 45 // See comment in header file for why we do this. |
45 if (handler_function_value.IsEmpty() || | 46 if (handler_function_value.IsEmpty() || |
46 handler_function_value->IsUndefined()) { | 47 handler_function_value->IsUndefined()) { |
47 console::Error(args.GetIsolate()->GetCallingContext(), | 48 ScriptContext* script_context = ScriptContextSet::GetContextByV8Context( |
| 49 args.GetIsolate()->GetCallingContext()); |
| 50 console::Error(script_context ? script_context->GetRenderFrame() : nullptr, |
48 "Extension view no longer exists"); | 51 "Extension view no longer exists"); |
49 return; | 52 return; |
50 } | 53 } |
51 DCHECK(handler_function_value->IsExternal()); | 54 DCHECK(handler_function_value->IsExternal()); |
52 static_cast<HandlerFunction*>( | 55 static_cast<HandlerFunction*>( |
53 handler_function_value.As<v8::External>()->Value())->Run(args); | 56 handler_function_value.As<v8::External>()->Value())->Run(args); |
54 } | 57 } |
55 | 58 |
56 void ObjectBackedNativeHandler::RouteFunction( | 59 void ObjectBackedNativeHandler::RouteFunction( |
57 const std::string& name, | 60 const std::string& name, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 data->Delete(v8::String::NewFromUtf8(isolate, kHandlerFunction)); | 93 data->Delete(v8::String::NewFromUtf8(isolate, kHandlerFunction)); |
91 } | 94 } |
92 | 95 |
93 router_data_.Clear(); | 96 router_data_.Clear(); |
94 object_template_.Reset(); | 97 object_template_.Reset(); |
95 | 98 |
96 NativeHandler::Invalidate(); | 99 NativeHandler::Invalidate(); |
97 } | 100 } |
98 | 101 |
99 } // namespace extensions | 102 } // namespace extensions |
OLD | NEW |