| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/render_view_observer_natives.h" | 5 #include "extensions/renderer/render_view_observer_natives.h" |
| 6 | 6 |
| 7 #include "content/public/renderer/render_view.h" | 7 #include "content/public/renderer/render_view.h" |
| 8 #include "content/public/renderer/render_view_observer.h" | 8 #include "content/public/renderer/render_view_observer.h" |
| 9 #include "extensions/common/extension_api.h" | 9 #include "extensions/common/extension_api.h" |
| 10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
| 11 #include "third_party/WebKit/public/web/WebFrame.h" | 11 #include "third_party/WebKit/public/web/WebFrame.h" |
| 12 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 12 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Deletes itself when done. | 18 // Deletes itself when done. |
| 19 class LoadWatcher : public content::RenderViewObserver { | 19 class LoadWatcher : public content::RenderViewObserver { |
| 20 public: | 20 public: |
| 21 LoadWatcher(ScriptContext* context, | 21 LoadWatcher(ScriptContext* context, |
| 22 content::RenderView* view, | 22 content::RenderView* view, |
| 23 v8::Handle<v8::Function> cb) | 23 v8::Handle<v8::Function> cb) |
| 24 : content::RenderViewObserver(view), context_(context), callback_(cb) {} | 24 : content::RenderViewObserver(view), context_(context), callback_(cb) {} |
| 25 | 25 |
| 26 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE { | 26 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) override { |
| 27 CallbackAndDie(true); | 27 CallbackAndDie(true); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void DidFailProvisionalLoad(blink::WebLocalFrame* frame, | 30 virtual void DidFailProvisionalLoad(blink::WebLocalFrame* frame, |
| 31 const blink::WebURLError& error) | 31 const blink::WebURLError& error) |
| 32 OVERRIDE { | 32 override { |
| 33 CallbackAndDie(false); | 33 CallbackAndDie(false); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 void CallbackAndDie(bool succeeded) { | 37 void CallbackAndDie(bool succeeded) { |
| 38 v8::Isolate* isolate = context_->isolate(); | 38 v8::Isolate* isolate = context_->isolate(); |
| 39 v8::HandleScope handle_scope(isolate); | 39 v8::HandleScope handle_scope(isolate); |
| 40 v8::Handle<v8::Value> args[] = {v8::Boolean::New(isolate, succeeded)}; | 40 v8::Handle<v8::Value> args[] = {v8::Boolean::New(isolate, succeeded)}; |
| 41 context_->CallFunction(callback_.NewHandle(isolate), 1, args); | 41 context_->CallFunction(callback_.NewHandle(isolate), 1, args); |
| 42 delete this; | 42 delete this; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 LOG(WARNING) << "No render view found to register LoadWatcher."; | 68 LOG(WARNING) << "No render view found to register LoadWatcher."; |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 | 71 |
| 72 new LoadWatcher(context(), view, args[1].As<v8::Function>()); | 72 new LoadWatcher(context(), view, args[1].As<v8::Function>()); |
| 73 | 73 |
| 74 args.GetReturnValue().Set(true); | 74 args.GetReturnValue().Set(true); |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace extensions | 77 } // namespace extensions |
| OLD | NEW |