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

Unified Diff: components/test_runner/spell_check_client.cc

Issue 2587823003: Allow test runner to run a callback when finishing a spellcheck request (Closed)
Patch Set: fix typo... Created 4 years 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 | « components/test_runner/spell_check_client.h ('k') | components/test_runner/test_runner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/test_runner/spell_check_client.cc
diff --git a/components/test_runner/spell_check_client.cc b/components/test_runner/spell_check_client.cc
index e9c450a479d041927c922ebb656c036797091a29..2173211e7080beba7fc113f23260a3b476cd1ef7 100644
--- a/components/test_runner/spell_check_client.cc
+++ b/components/test_runner/spell_check_client.cc
@@ -13,6 +13,8 @@
#include "components/test_runner/mock_grammar_check.h"
#include "components/test_runner/test_runner.h"
#include "components/test_runner/web_test_delegate.h"
+#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
#include "third_party/WebKit/public/web/WebTextCheckingResult.h"
@@ -36,6 +38,11 @@ void SpellCheckClient::SetEnabled(bool enabled) {
enabled_ = enabled;
}
+void SpellCheckClient::Reset() {
+ enabled_ = false;
+ resolved_callback_.Reset();
+}
+
// blink::WebSpellCheckClient
void SpellCheckClient::spellCheck(
const blink::WebString& text,
@@ -58,13 +65,17 @@ void SpellCheckClient::requestCheckingOfText(
const blink::WebVector<unsigned>& marker_offsets,
blink::WebTextCheckingCompletion* completion) {
if (!enabled_ || text.isEmpty()) {
- if (completion)
+ if (completion) {
completion->didCancelCheckingText();
+ RequestResolved();
+ }
return;
}
- if (last_requested_text_checking_completion_)
+ if (last_requested_text_checking_completion_) {
last_requested_text_checking_completion_->didCancelCheckingText();
+ RequestResolved();
+ }
last_requested_text_checking_completion_ = completion;
last_requested_text_check_string_ = text;
@@ -115,9 +126,41 @@ void SpellCheckClient::FinishLastTextCheck() {
}
last_requested_text_checking_completion_->didFinishCheckingText(results);
last_requested_text_checking_completion_ = 0;
+ RequestResolved();
if (test_runner_->shouldDumpSpellCheckCallbacks())
delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n");
}
+void SpellCheckClient::SetSpellCheckResolvedCallback(
+ v8::Local<v8::Function> callback) {
+ resolved_callback_.Reset(blink::mainThreadIsolate(), callback);
+}
+
+void SpellCheckClient::RemoveSpellCheckResolvedCallback() {
+ resolved_callback_.Reset();
+}
+
+void SpellCheckClient::RequestResolved() {
+ if (resolved_callback_.IsEmpty())
+ return;
+
+ v8::Isolate* isolate = blink::mainThreadIsolate();
+ v8::HandleScope handle_scope(isolate);
+
+ blink::WebFrame* frame = test_runner_->mainFrame();
+ if (!frame || frame->isWebRemoteFrame())
+ return;
+
+ v8::Local<v8::Context> context = frame->mainWorldScriptContext();
+ if (context.IsEmpty())
+ return;
+
+ v8::Context::Scope context_scope(context);
+
+ frame->callFunctionEvenIfScriptDisabled(
+ v8::Local<v8::Function>::New(isolate, resolved_callback_),
+ context->Global(), 0, nullptr);
+}
+
} // namespace test_runner
« no previous file with comments | « components/test_runner/spell_check_client.h ('k') | components/test_runner/test_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698