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

Unified Diff: chrome/renderer/extensions/render_view_observer_natives.cc

Issue 16975007: Run shim's watchForTag on document.DOMContentLoaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from kalman. Created 7 years, 6 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: chrome/renderer/extensions/render_view_observer_natives.cc
diff --git a/chrome/renderer/extensions/render_view_observer_natives.cc b/chrome/renderer/extensions/render_view_observer_natives.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f9bccaaf5a04abbf44f7cf2b4e66ed8ca012e33c
--- /dev/null
+++ b/chrome/renderer/extensions/render_view_observer_natives.cc
@@ -0,0 +1,102 @@
+// Copyright 2013 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.
+
+#include "chrome/renderer/extensions/render_view_observer_natives.h"
+
+#include "chrome/common/extensions/api/extension_api.h"
+#include "chrome/renderer/extensions/dispatcher.h"
+#include "content/public/renderer/render_view.h"
+#include "content/public/renderer/render_view_observer.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSuppression.h"
+
+namespace extensions {
+
+namespace {
+class LoadWatcher : public content::RenderViewObserver {
+ public:
+ LoadWatcher(content::RenderView* view,
+ v8::Handle<v8::Function> cb)
+ : content::RenderViewObserver(view),
+ callback_(cb) {
+ }
+
+ virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE {
+ CallbackAndDie(frame, true);
+ }
+
+ virtual void DidFailProvisionalLoad(
+ WebKit::WebFrame* frame,
+ const WebKit::WebURLError& error) OVERRIDE {
+ CallbackAndDie(frame, false);
+ }
+
+ private:
+ ScopedPersistent<v8::Function> callback_;
+
+ void CallbackAndDie(WebKit::WebFrame* frame, bool succeeded) {
+ v8::HandleScope handle_scope;
+ 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
+ v8::Context::Scope scope(context);
+ v8::Local<v8::Object> global = context->Global();
+ {
+ WebKit::WebScopedMicrotaskSuppression suppression;
+ v8::Handle<v8::Value> args[] = {
+ succeeded ? v8::True() : v8::False()
+ };
+ 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
+ }
+ delete this;
+ }
+};
+} // namespace
+
+
+RenderViewObserverNatives::RenderViewObserverNatives(Dispatcher* dispatcher,
+ ChromeV8Context* context)
+ : ChromeV8Extension(dispatcher, context) {
+ RouteFunction("OnDocumentCreated",
+ base::Bind(&RenderViewObserverNatives::OnDocumentCreated,
+ base::Unretained(this)));
+ RouteFunction(
+ "OnDocumentCreatedForCurrentContext",
+ base::Bind(&RenderViewObserverNatives::OnDocumentCreatedForCurrentContext,
+ base::Unretained(this)));
+}
+
+v8::Handle<v8::Value> RenderViewObserverNatives::OnDocumentCreated(
+ const v8::Arguments& args) {
+ CHECK(args.Length() == 2);
+ CHECK(args[0]->IsInt32());
+ CHECK(args[1]->IsFunction());
+
+ int view_id = args[0]->Int32Value();
+
+ content::RenderView* view = content::RenderView::FromRoutingID(view_id);
+ if (!view)
+ return v8::Undefined();
+
+ v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[1]);
+ new LoadWatcher(view, func);
+
+ return v8::True();
+}
+
+v8::Handle<v8::Value>
+RenderViewObserverNatives::OnDocumentCreatedForCurrentContext(
+ const v8::Arguments& args) {
+ CHECK(args.Length() == 1);
+ CHECK(args[0]->IsFunction());
+
+ content::RenderView* view = context()->GetRenderView();
+ if (!view)
+ return v8::Undefined();
+
+ v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[0]);
+ new LoadWatcher(view, func);
+
+ return v8::True();
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698