Chromium Code Reviews| Index: chrome/renderer/extensions/automation_internal_custom_bindings.cc |
| diff --git a/chrome/renderer/extensions/automation_internal_custom_bindings.cc b/chrome/renderer/extensions/automation_internal_custom_bindings.cc |
| index 60f6647c82bad6c9044abb29f4ea6fe26b7a0ca1..49590a7ef47cbf38c66b247bd39a03c101f1a2c7 100644 |
| --- a/chrome/renderer/extensions/automation_internal_custom_bindings.cc |
| +++ b/chrome/renderer/extensions/automation_internal_custom_bindings.cc |
| @@ -7,12 +7,17 @@ |
| #include "base/bind.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/values.h" |
| +#include "chrome/common/extensions/chrome_extension_messages.h" |
| #include "chrome/common/extensions/manifest_handlers/automation.h" |
| #include "content/public/child/v8_value_converter.h" |
| +#include "content/public/renderer/render_thread.h" |
| +#include "content/public/renderer/render_view.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/manifest.h" |
| #include "extensions/renderer/script_context.h" |
| +#include "ipc/message_filter.h" |
| #include "ui/accessibility/ax_enums.h" |
| +#include "ui/accessibility/ax_node.h" |
| namespace { |
| @@ -34,6 +39,37 @@ v8::Local<v8::Object> ToEnumObject(v8::Isolate* isolate, |
| namespace extensions { |
| +class AutomationMessageFilter : public IPC::MessageFilter { |
| + public: |
| + explicit AutomationMessageFilter(AutomationInternalCustomBindings* owner) |
| + : owner_(owner) { |
|
dcheng
2015/06/06 00:00:52
Is it valid to call this constructor with no owner
dmazzoni
2015/06/08 18:02:58
Done.
|
| + content::RenderThread::Get()->AddFilter(this); |
| + } |
| + |
| + void Detach() { |
|
dcheng
2015/06/06 00:00:52
Who calls Detach()?
dmazzoni
2015/06/08 18:02:58
Oops, meant to call this in ~AutomationInternalCus
|
| + owner_ = nullptr; |
| + } |
| + |
| + // IPC::MessageFilter |
| + bool OnMessageReceived(const IPC::Message& message) override { |
| + if (owner_) |
| + return owner_->OnMessageReceived(message); |
| + else |
| + return false; |
| + } |
| + |
| +private: |
| + ~AutomationMessageFilter() override { |
| + content::RenderThread* render_thread = content::RenderThread::Get(); |
|
dcheng
2015/06/06 00:00:52
Why would this be null? To me, this conditional ma
dmazzoni
2015/06/08 18:02:57
Looks like it shouldn't be null, removed the check
|
| + if (render_thread) |
| + render_thread->RemoveFilter(this); |
| + } |
| + |
| + AutomationInternalCustomBindings* owner_; |
|
dcheng
2015/06/06 00:00:52
Since we don't use Detach() anymore, make this an
dmazzoni
2015/06/08 18:02:58
I think we need Detach() because the message filte
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter); |
| +}; |
| + |
| AutomationInternalCustomBindings::AutomationInternalCustomBindings( |
| ScriptContext* context) : ObjectBackedNativeHandler(context) { |
| RouteFunction( |
| @@ -44,11 +80,28 @@ AutomationInternalCustomBindings::AutomationInternalCustomBindings( |
| "GetSchemaAdditions", |
| base::Bind(&AutomationInternalCustomBindings::GetSchemaAdditions, |
| base::Unretained(this))); |
| + RouteFunction( |
| + "GetRoutingID", |
| + base::Bind(&AutomationInternalCustomBindings::GetRoutingID, |
| + base::Unretained(this))); |
|
dcheng
2015/06/06 00:00:52
In general, it's nice to document why base::Unreta
dmazzoni
2015/06/08 18:02:58
Done.
|
| + |
| + message_filter_ = new AutomationMessageFilter(this); |
| } |
| AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { |
| } |
| +bool AutomationInternalCustomBindings::OnMessageReceived( |
| + const IPC::Message& message) { |
| + IPC_BEGIN_MESSAGE_MAP(AutomationInternalCustomBindings, message) |
| + IPC_MESSAGE_HANDLER(ExtensionMsg_AccessibilityEvent, OnAccessibilityEvent) |
| + IPC_END_MESSAGE_MAP() |
| + |
| + // Always return false in case there are multiple |
| + // AutomationInternalCustomBindings instances attached to the same thread. |
| + return false; |
| +} |
| + |
| void AutomationInternalCustomBindings::IsInteractPermitted( |
| const v8::FunctionCallbackInfo<v8::Value>& args) { |
| const Extension* extension = context()->extension(); |
| @@ -59,6 +112,12 @@ void AutomationInternalCustomBindings::IsInteractPermitted( |
| v8::Boolean::New(GetIsolate(), automation_info->interact)); |
| } |
| +void AutomationInternalCustomBindings::GetRoutingID( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + int routing_id = context()->GetRenderView()->GetRoutingID(); |
| + args.GetReturnValue().Set(v8::Integer::New(GetIsolate(), routing_id)); |
| +} |
| + |
| void AutomationInternalCustomBindings::GetSchemaAdditions( |
| const v8::FunctionCallbackInfo<v8::Value>& args) { |
| v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); |
| @@ -82,4 +141,9 @@ void AutomationInternalCustomBindings::GetSchemaAdditions( |
| args.GetReturnValue().Set(additions); |
| } |
| +void AutomationInternalCustomBindings::OnAccessibilityEvent( |
| + const ExtensionMsg_AccessibilityEventParams& params) { |
| + // TODO(dmazzoni): finish implementing this. |
|
dcheng
2015/06/06 00:00:52
Please add me as a reviewer on the change where yo
dmazzoni
2015/06/08 18:02:57
Done: https://codereview.chromium.org/1155183006/
|
| +} |
| + |
| } // namespace extensions |