| 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::Local<v8::Function> cb) |
| 24 : content::RenderViewObserver(view), | 24 : content::RenderViewObserver(view), |
| 25 context_(context), | 25 context_(context), |
| 26 callback_(context->isolate(), cb) {} | 26 callback_(context->isolate(), cb) {} |
| 27 | 27 |
| 28 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override { | 28 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override { |
| 29 CallbackAndDie(true); | 29 CallbackAndDie(true); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void DidFailProvisionalLoad(blink::WebLocalFrame* frame, | 32 void DidFailProvisionalLoad(blink::WebLocalFrame* frame, |
| 33 const blink::WebURLError& error) override { | 33 const blink::WebURLError& error) override { |
| 34 CallbackAndDie(false); | 34 CallbackAndDie(false); |
| 35 } | 35 } |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 void CallbackAndDie(bool succeeded) { | 38 void CallbackAndDie(bool succeeded) { |
| 39 v8::Isolate* isolate = context_->isolate(); | 39 v8::Isolate* isolate = context_->isolate(); |
| 40 v8::HandleScope handle_scope(isolate); | 40 v8::HandleScope handle_scope(isolate); |
| 41 v8::Handle<v8::Value> args[] = {v8::Boolean::New(isolate, succeeded)}; | 41 v8::Local<v8::Value> args[] = {v8::Boolean::New(isolate, succeeded)}; |
| 42 context_->CallFunction(v8::Local<v8::Function>::New(isolate, callback_), | 42 context_->CallFunction(v8::Local<v8::Function>::New(isolate, callback_), |
| 43 arraysize(args), args); | 43 arraysize(args), args); |
| 44 delete this; | 44 delete this; |
| 45 } | 45 } |
| 46 | 46 |
| 47 ScriptContext* context_; | 47 ScriptContext* context_; |
| 48 v8::Global<v8::Function> callback_; | 48 v8::Global<v8::Function> callback_; |
| 49 DISALLOW_COPY_AND_ASSIGN(LoadWatcher); | 49 DISALLOW_COPY_AND_ASSIGN(LoadWatcher); |
| 50 }; | 50 }; |
| 51 } // namespace | 51 } // namespace |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 LOG(WARNING) << "No render view found to register LoadWatcher."; | 70 LOG(WARNING) << "No render view found to register LoadWatcher."; |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 new LoadWatcher(context(), view, args[1].As<v8::Function>()); | 74 new LoadWatcher(context(), view, args[1].As<v8::Function>()); |
| 75 | 75 |
| 76 args.GetReturnValue().Set(true); | 76 args.GetReturnValue().Set(true); |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace extensions | 79 } // namespace extensions |
| OLD | NEW |