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

Unified Diff: content/renderer/dom_automation_controller.cc

Issue 133403003: Don't try to send automation message after the corresponding RV is gone (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/dom_automation_controller.h ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/dom_automation_controller.cc
diff --git a/content/renderer/dom_automation_controller.cc b/content/renderer/dom_automation_controller.cc
index 805426c86bbd5a6ad8dfc5e708f703164bd9a380..f3f0914d51703da36b0232c6c5c8a0a51625d987 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) {
« no previous file with comments | « content/renderer/dom_automation_controller.h ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698