summaryrefslogtreecommitdiffstats
path: root/content/renderer
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-13 12:10:04 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-13 12:10:04 +0000
commit480116e7c1412b3aa58e92dc8d1d888f4fe19712 (patch)
treee06f492e7fe9f5a749213c07fd07e72248c0fb81 /content/renderer
parentcaa8dc0445093d10ca22412f2f5c35e50db463ca (diff)
downloadchromium_src-480116e7c1412b3aa58e92dc8d1d888f4fe19712.zip
chromium_src-480116e7c1412b3aa58e92dc8d1d888f4fe19712.tar.gz
chromium_src-480116e7c1412b3aa58e92dc8d1d888f4fe19712.tar.bz2
Don't try to send automation message after the corresponding RV is gone
BUG=none R=abarth@chromium.org Review URL: https://codereview.chromium.org/133403003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
-rw-r--r--content/renderer/dom_automation_controller.cc38
-rw-r--r--content/renderer/dom_automation_controller.h15
-rw-r--r--content/renderer/render_view_impl.cc2
3 files changed, 34 insertions, 21 deletions
diff --git a/content/renderer/dom_automation_controller.cc b/content/renderer/dom_automation_controller.cc
index 805426c..f3f0914 100644
--- a/content/renderer/dom_automation_controller.cc
+++ b/content/renderer/dom_automation_controller.cc
@@ -21,7 +21,8 @@ gin::WrapperInfo DomAutomationController::kWrapperInfo = {
gin::kEmbedderNativeGin};
// static
-void DomAutomationController::Install(blink::WebFrame* frame) {
+void DomAutomationController::Install(RenderViewImpl* render_view,
+ blink::WebFrame* frame) {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
@@ -31,14 +32,14 @@ void DomAutomationController::Install(blink::WebFrame* frame) {
v8::Context::Scope context_scope(context);
gin::Handle<DomAutomationController> controller =
- gin::CreateHandle(isolate, new DomAutomationController(frame));
+ gin::CreateHandle(isolate, new DomAutomationController(render_view));
v8::Handle<v8::Object> global = context->Global();
global->Set(gin::StringToV8(isolate, "domAutomationController"),
controller.ToV8());
}
-DomAutomationController::DomAutomationController(blink::WebFrame* frame)
- : frame_(frame), automation_id_(MSG_ROUTING_NONE) {}
+DomAutomationController::DomAutomationController(RenderViewImpl* render_view)
+ : RenderViewObserver(render_view), automation_id_(MSG_ROUTING_NONE) {}
DomAutomationController::~DomAutomationController() {}
@@ -46,13 +47,18 @@ gin::ObjectTemplateBuilder DomAutomationController::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<DomAutomationController>::GetObjectTemplateBuilder(
isolate)
- .SetMethod("send", &DomAutomationController::Send)
+ .SetMethod("send", &DomAutomationController::SendMsg)
.SetMethod("setAutomationId", &DomAutomationController::SetAutomationId)
.SetMethod("sendJSON", &DomAutomationController::SendJSON)
.SetMethod("sendWithId", &DomAutomationController::SendWithId);
}
-bool DomAutomationController::Send(const gin::Arguments& args) {
+void DomAutomationController::OnDestruct() {}
+
+bool DomAutomationController::SendMsg(const gin::Arguments& args) {
+ if (!render_view())
+ return false;
+
if (automation_id_ == MSG_ROUTING_NONE)
return false;
@@ -78,20 +84,21 @@ bool DomAutomationController::Send(const gin::Arguments& args) {
if (!serializer.Serialize(*value))
return false;
- RenderViewImpl* render_view = RenderViewImpl::FromWebView(frame_->view());
- bool succeeded = render_view->Send(new ViewHostMsg_DomOperationResponse(
- render_view->GetRoutingID(), json, automation_id_));
+ bool succeeded = Send(
+ new ViewHostMsg_DomOperationResponse(routing_id(), json, automation_id_));
automation_id_ = MSG_ROUTING_NONE;
return succeeded;
}
bool DomAutomationController::SendJSON(const std::string& json) {
+ if (!render_view())
+ return false;
+
if (automation_id_ == MSG_ROUTING_NONE)
return false;
- RenderViewImpl* render_view = RenderViewImpl::FromWebView(frame_->view());
- bool result = render_view->Send(new ViewHostMsg_DomOperationResponse(
- render_view->GetRoutingID(), json, automation_id_));
+ bool result = Send(
+ new ViewHostMsg_DomOperationResponse(routing_id(), json, automation_id_));
automation_id_ = MSG_ROUTING_NONE;
return result;
@@ -99,9 +106,10 @@ bool DomAutomationController::SendJSON(const std::string& json) {
bool DomAutomationController::SendWithId(int automation_id,
const std::string& str) {
- RenderViewImpl* render_view = RenderViewImpl::FromWebView(frame_->view());
- return render_view->Send(new ViewHostMsg_DomOperationResponse(
- render_view->GetRoutingID(), str, automation_id));
+ if (!render_view())
+ return false;
+ return Send(
+ new ViewHostMsg_DomOperationResponse(routing_id(), str, automation_id));
}
bool DomAutomationController::SetAutomationId(int automation_id) {
diff --git a/content/renderer/dom_automation_controller.h b/content/renderer/dom_automation_controller.h
index 8098b29..829083a 100644
--- a/content/renderer/dom_automation_controller.h
+++ b/content/renderer/dom_automation_controller.h
@@ -6,6 +6,7 @@
#define CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_
#include "base/basictypes.h"
+#include "content/public/renderer/render_view_observer.h"
#include "gin/wrappable.h"
/* DomAutomationController class:
@@ -80,17 +81,20 @@ class Arguments;
namespace content {
-class DomAutomationController : public gin::Wrappable<DomAutomationController> {
+class RenderViewImpl;
+
+class DomAutomationController : public gin::Wrappable<DomAutomationController>,
+ public RenderViewObserver {
public:
static gin::WrapperInfo kWrapperInfo;
- static void Install(blink::WebFrame* frame);
+ static void Install(RenderViewImpl* render_view, blink::WebFrame* frame);
// Makes the renderer send a javascript value to the app.
// The value to be sent can be either of type String,
// Number (double casted to int32) or Boolean. Any other type or no
// argument at all is ignored.
- bool Send(const gin::Arguments& args);
+ bool SendMsg(const gin::Arguments& args);
// Makes the renderer send a javascript value to the app.
// The value should be properly formed JSON.
@@ -102,14 +106,15 @@ class DomAutomationController : public gin::Wrappable<DomAutomationController> {
bool SetAutomationId(int automation_id);
private:
- explicit DomAutomationController(blink::WebFrame* frame);
+ explicit DomAutomationController(RenderViewImpl* render_view);
virtual ~DomAutomationController();
// gin::WrappableBase
virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) OVERRIDE;
- blink::WebFrame* frame_;
+ // RenderViewObserver
+ virtual void OnDestruct() OVERRIDE;
int automation_id_; // routing id to be used by the next channel.
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 718f9c2..0b53d80 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -3655,7 +3655,7 @@ void RenderViewImpl::didClearWindowObject(WebFrame* frame, int world_id) {
DidClearWindowObject(frame, world_id));
if ((enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) && (world_id == 0))
- DomAutomationController::Install(frame);
+ DomAutomationController::Install(this, frame);
if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION)
StatsCollectionController::Install(frame);