| OLD | NEW | 
|    1 // Copyright 2017 The Chromium Authors. All rights reserved. |    1 // Copyright 2017 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/declarative_event.h" |    5 #include "extensions/renderer/declarative_event.h" | 
|    6  |    6  | 
|    7 #include <algorithm> |    7 #include <algorithm> | 
|    8 #include <memory> |    8 #include <memory> | 
|    9  |    9  | 
|   10 #include "base/memory/ptr_util.h" |   10 #include "base/memory/ptr_util.h" | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  107  |  107  | 
|  108 }  // namespace |  108 }  // namespace | 
|  109  |  109  | 
|  110 gin::WrapperInfo DeclarativeEvent::kWrapperInfo = {gin::kEmbedderNativeGin}; |  110 gin::WrapperInfo DeclarativeEvent::kWrapperInfo = {gin::kEmbedderNativeGin}; | 
|  111  |  111  | 
|  112 DeclarativeEvent::DeclarativeEvent( |  112 DeclarativeEvent::DeclarativeEvent( | 
|  113     const std::string& name, |  113     const std::string& name, | 
|  114     APITypeReferenceMap* type_refs, |  114     APITypeReferenceMap* type_refs, | 
|  115     APIRequestHandler* request_handler, |  115     APIRequestHandler* request_handler, | 
|  116     const std::vector<std::string>& actions_list, |  116     const std::vector<std::string>& actions_list, | 
|  117     const std::vector<std::string>& conditions_list) |  117     const std::vector<std::string>& conditions_list, | 
 |  118     int webview_instance_id) | 
|  118     : event_name_(name), |  119     : event_name_(name), | 
|  119       type_refs_(type_refs), |  120       type_refs_(type_refs), | 
|  120       request_handler_(request_handler) { |  121       request_handler_(request_handler), | 
 |  122       webview_instance_id_(webview_instance_id) { | 
|  121   // In declarative events, the specification of the rules can change. This only |  123   // In declarative events, the specification of the rules can change. This only | 
|  122   // matters for the events.addRules function. Check whether or not a |  124   // matters for the events.addRules function. Check whether or not a | 
|  123   // specialized version for this event exists, and, if not, create it. |  125   // specialized version for this event exists, and, if not, create it. | 
|  124   std::string add_rules_name = name + ".addRules"; |  126   std::string add_rules_name = name + ".addRules"; | 
|  125   if (!type_refs->HasTypeMethodSignature(add_rules_name)) { |  127   if (!type_refs->HasTypeMethodSignature(add_rules_name)) { | 
|  126     // Create the specific rules spec and cache it under this type. This will |  128     // Create the specific rules spec and cache it under this type. This will | 
|  127     // result in e.g. declarativeContent.onPageChanged.Rule, since the Rule |  129     // result in e.g. declarativeContent.onPageChanged.Rule, since the Rule | 
|  128     // schema is only used for this event. |  130     // schema is only used for this event. | 
|  129     std::unique_ptr<ArgumentSpec> rules_spec = |  131     std::unique_ptr<ArgumentSpec> rules_spec = | 
|  130         BuildRulesSpec(actions_list, conditions_list); |  132         BuildRulesSpec(actions_list, conditions_list); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  172                                       gin::Arguments* arguments) { |  174                                       gin::Arguments* arguments) { | 
|  173   v8::Isolate* isolate = arguments->isolate(); |  175   v8::Isolate* isolate = arguments->isolate(); | 
|  174   v8::HandleScope handle_scope(isolate); |  176   v8::HandleScope handle_scope(isolate); | 
|  175   v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |  177   v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 
|  176  |  178  | 
|  177   std::vector<v8::Local<v8::Value>> argument_list = arguments->GetAll(); |  179   std::vector<v8::Local<v8::Value>> argument_list = arguments->GetAll(); | 
|  178  |  180  | 
|  179   // The events API has two undocumented parameters for each function: the name |  181   // The events API has two undocumented parameters for each function: the name | 
|  180   // of the event, and the "webViewInstanceId". Currently, stub 0 for webview |  182   // of the event, and the "webViewInstanceId". Currently, stub 0 for webview | 
|  181   // instance id. |  183   // instance id. | 
|  182   // TODO(devlin): We'll need to fix that to get it to work with webviews. |  | 
|  183   // Longer term, it would be *great* to just factor that out entirely (can we |  | 
|  184   // not get that information on the browser side? Investigate). |  | 
|  185   argument_list.insert(argument_list.begin(), |  184   argument_list.insert(argument_list.begin(), | 
|  186                        {gin::StringToSymbol(isolate, event_name_), |  185                        {gin::StringToSymbol(isolate, event_name_), | 
|  187                         v8::Integer::New(isolate, 0)}); |  186                         v8::Integer::New(isolate, webview_instance_id_)}); | 
|  188  |  187  | 
|  189   std::unique_ptr<base::ListValue> converted_arguments; |  188   std::unique_ptr<base::ListValue> converted_arguments; | 
|  190   v8::Local<v8::Function> callback; |  189   v8::Local<v8::Function> callback; | 
|  191   std::string error; |  190   std::string error; | 
|  192   const APISignature* signature = |  191   const APISignature* signature = | 
|  193       type_refs_->GetTypeMethodSignature(signature_name); |  192       type_refs_->GetTypeMethodSignature(signature_name); | 
|  194   DCHECK(signature); |  193   DCHECK(signature); | 
|  195   if (!signature->ParseArgumentsToJSON(context, argument_list, *type_refs_, |  194   if (!signature->ParseArgumentsToJSON(context, argument_list, *type_refs_, | 
|  196                                        &converted_arguments, &callback, |  195                                        &converted_arguments, &callback, | 
|  197                                        &error)) { |  196                                        &error)) { | 
|  198     arguments->ThrowTypeError("Invalid invocation"); |  197     arguments->ThrowTypeError("Invalid invocation"); | 
|  199     return; |  198     return; | 
|  200   } |  199   } | 
|  201  |  200  | 
|  202   request_handler_->StartRequest( |  201   request_handler_->StartRequest( | 
|  203       context, request_name, std::move(converted_arguments), callback, |  202       context, request_name, std::move(converted_arguments), callback, | 
|  204       v8::Local<v8::Function>(), binding::RequestThread::UI); |  203       v8::Local<v8::Function>(), binding::RequestThread::UI); | 
|  205 } |  204 } | 
|  206  |  205  | 
|  207 }  // namespace extensions |  206 }  // namespace extensions | 
| OLD | NEW |