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

Unified Diff: android_webview/renderer/aw_execution_termination_filter.h

Issue 366913006: [Android WebView] Terminate execution of stuck JS code on navigation requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 5 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
Index: android_webview/renderer/aw_execution_termination_filter.h
diff --git a/android_webview/renderer/aw_execution_termination_filter.h b/android_webview/renderer/aw_execution_termination_filter.h
new file mode 100644
index 0000000000000000000000000000000000000000..14b88b1c50495a8661c0051abee3230462c6d686
--- /dev/null
+++ b/android_webview/renderer/aw_execution_termination_filter.h
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ANDROID_WEBVIEW_RENDERER_AW_EXECUTION_TERMINATION_FILTER_H_
+#define ANDROID_WEBVIEW_RENDERER_AW_EXECUTION_TERMINATION_FILTER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/timer/timer.h"
+#include "ipc/message_filter.h"
+
+namespace base {
+class MessageLoopProxy;
+}
+
+namespace v8 {
+class Isolate;
+}
+
+namespace android_webview {
+
+// The purpose of AwExecutionTerminationFilter is to attempt to terminate
+// any JavaScript code that is stuck in a loop before doing a navigation
+// originating from a Andoird WebView URL loading functions.
+//
+// This is how it works. AwExecutionTerminationFilter is created on render
+// thread. It listens on IO thread for navigation requests coming from
+// AwContents.loadUrl calls. On each such a request, it posts a delayed
+// cancellable task on the IO thread's message loop and, at the same time, posts
+// a cancellation task on the render thread's message loop. If render thread
+// is not stuck, the cancellation task runs and cancels the delayed task.
+// Otherwise, the delayed task runs and terminates execution of JS code
+// from the IO thread.
+class AwExecutionTerminationFilter : public IPC::MessageFilter {
+ public:
+ AwExecutionTerminationFilter(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
+ const scoped_refptr<base::MessageLoopProxy>& main_message_loop);
+
+ void SetRenderThreadIsolate(v8::Isolate* isolate);
+
+ private:
+ virtual ~AwExecutionTerminationFilter();
+
+ // IPC::MessageFilter methods.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ void OnCheckRenderThreadResponsiveness();
+ void StopTimerOnMainThread();
+ void StopTimer();
+ void TerminateExecution();
+
+ const scoped_refptr<base::MessageLoopProxy> io_message_loop_;
+ const scoped_refptr<base::MessageLoopProxy> main_message_loop_;
+
+ v8::Isolate* render_thread_isolate_;
+ base::OneShotTimer<AwExecutionTerminationFilter> termination_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(AwExecutionTerminationFilter);
+};
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_RENDERER_AW_EXECUTION_TERMINATION_FILTER_H_
« no previous file with comments | « android_webview/renderer/aw_content_renderer_client.cc ('k') | android_webview/renderer/aw_execution_termination_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698