Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/extensions/render_view_observer_natives.h" | |
| 6 | |
| 7 #include "chrome/common/extensions/api/extension_api.h" | |
| 8 #include "chrome/renderer/extensions/dispatcher.h" | |
| 9 #include "content/public/renderer/render_view.h" | |
| 10 #include "content/public/renderer/render_view_observer.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup pression.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 16 namespace { | |
| 17 class LoadWatcher : public content::RenderViewObserver { | |
| 18 public: | |
| 19 LoadWatcher(content::RenderView* view, | |
| 20 v8::Handle<v8::Function> cb) | |
| 21 : content::RenderViewObserver(view), | |
| 22 callback_(cb) { | |
| 23 } | |
| 24 | |
| 25 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE { | |
| 26 CallbackAndDie(frame, true); | |
| 27 } | |
| 28 | |
| 29 virtual void DidFailProvisionalLoad( | |
| 30 WebKit::WebFrame* frame, | |
| 31 const WebKit::WebURLError& error) OVERRIDE { | |
| 32 CallbackAndDie(frame, false); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 ScopedPersistent<v8::Function> callback_; | |
| 37 | |
| 38 void CallbackAndDie(WebKit::WebFrame* frame, bool succeeded) { | |
| 39 v8::HandleScope handle_scope; | |
| 40 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | |
|
not at google - send to devlin
2013/06/14 00:58:32
I suspect it has something to do with this context
| |
| 41 v8::Context::Scope scope(context); | |
| 42 v8::Local<v8::Object> global = context->Global(); | |
| 43 { | |
| 44 WebKit::WebScopedMicrotaskSuppression suppression; | |
| 45 v8::Handle<v8::Value> args[] = { | |
| 46 succeeded ? v8::True() : v8::False() | |
| 47 }; | |
| 48 callback_->Call(global, 1, args); | |
|
not at google - send to devlin
2013/06/14 05:26:27
To answer your comment:
The problem I think is he
lazyboy
2013/06/14 16:23:32
Why are there two frames? My assumption was the ch
not at google - send to devlin
2013/06/14 16:45:27
The first frame is the one that created the app wi
| |
| 49 } | |
| 50 delete this; | |
| 51 } | |
| 52 }; | |
| 53 } // namespace | |
| 54 | |
| 55 | |
| 56 RenderViewObserverNatives::RenderViewObserverNatives(Dispatcher* dispatcher, | |
| 57 ChromeV8Context* context) | |
| 58 : ChromeV8Extension(dispatcher, context) { | |
| 59 RouteFunction("OnDocumentCreated", | |
| 60 base::Bind(&RenderViewObserverNatives::OnDocumentCreated, | |
| 61 base::Unretained(this))); | |
| 62 RouteFunction( | |
| 63 "OnDocumentCreatedForCurrentContext", | |
| 64 base::Bind(&RenderViewObserverNatives::OnDocumentCreatedForCurrentContext, | |
| 65 base::Unretained(this))); | |
| 66 } | |
| 67 | |
| 68 v8::Handle<v8::Value> RenderViewObserverNatives::OnDocumentCreated( | |
| 69 const v8::Arguments& args) { | |
| 70 CHECK(args.Length() == 2); | |
| 71 CHECK(args[0]->IsInt32()); | |
| 72 CHECK(args[1]->IsFunction()); | |
| 73 | |
| 74 int view_id = args[0]->Int32Value(); | |
| 75 | |
| 76 content::RenderView* view = content::RenderView::FromRoutingID(view_id); | |
| 77 if (!view) | |
| 78 return v8::Undefined(); | |
| 79 | |
| 80 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[1]); | |
| 81 new LoadWatcher(view, func); | |
| 82 | |
| 83 return v8::True(); | |
| 84 } | |
| 85 | |
| 86 v8::Handle<v8::Value> | |
| 87 RenderViewObserverNatives::OnDocumentCreatedForCurrentContext( | |
| 88 const v8::Arguments& args) { | |
| 89 CHECK(args.Length() == 1); | |
| 90 CHECK(args[0]->IsFunction()); | |
| 91 | |
| 92 content::RenderView* view = context()->GetRenderView(); | |
| 93 if (!view) | |
| 94 return v8::Undefined(); | |
| 95 | |
| 96 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[0]); | |
| 97 new LoadWatcher(view, func); | |
| 98 | |
| 99 return v8::True(); | |
| 100 } | |
| 101 | |
| 102 } // namespace extensions | |
| OLD | NEW |