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

Side by Side 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: Use correct comment instead of copy/pasting. 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 unified diff | Download patch
OLDNEW
(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/public/web/WebFrame.h"
12 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
13
14 namespace extensions {
15
16 namespace {
17 class LoadWatcher : public content::RenderViewObserver {
18 public:
19 LoadWatcher(ChromeV8Context* context,
20 content::RenderView* view,
21 v8::Handle<v8::Function> cb)
22 : content::RenderViewObserver(view),
23 context_(context),
24 callback_(cb) {
25 }
26
27 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE {
28 CallbackAndDie(true);
29 }
30
31 virtual void DidFailProvisionalLoad(
32 WebKit::WebFrame* frame,
33 const WebKit::WebURLError& error) OVERRIDE {
34 CallbackAndDie(false);
35 }
36
37 private:
38 ChromeV8Context* context_;
39 ScopedPersistent<v8::Function> callback_;
40
41 void CallbackAndDie(bool succeeded) {
42 v8::HandleScope handle_scope;
43 // Don't need Context::Scope, CallFunction does that for us.
44 v8::Handle<v8::Value> args[] = { v8::Boolean::New(succeeded) };
45 context_->CallFunction(callback_.get(), 1, args);
46 delete this;
47 }
48 };
49 } // namespace
50
51
52 RenderViewObserverNatives::RenderViewObserverNatives(Dispatcher* dispatcher,
53 ChromeV8Context* context)
54 : ChromeV8Extension(dispatcher, context) {
55 RouteFunction("OnDocumentCreated",
56 base::Bind(&RenderViewObserverNatives::OnDocumentCreated,
57 base::Unretained(this)));
58 }
59
60 void RenderViewObserverNatives::OnDocumentCreated(
61 const v8::FunctionCallbackInfo<v8::Value>& args) {
62 CHECK(args.Length() == 2);
63 CHECK(args[0]->IsInt32());
64 CHECK(args[1]->IsFunction());
65
66 int view_id = args[0]->Int32Value();
67
68 content::RenderView* view = content::RenderView::FromRoutingID(view_id);
69 if (!view)
70 return;
71
72 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[1]);
73 new LoadWatcher(context(), view, func);
74
75 args.GetReturnValue().Set(true);
76 }
77
78 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698