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

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: Not using current. 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/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(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(frame, true);
29 }
30
31 virtual void DidFailProvisionalLoad(
32 WebKit::WebFrame* frame,
33 const WebKit::WebURLError& error) OVERRIDE {
34 CallbackAndDie(frame, false);
35 }
36
37 private:
38 ChromeV8Context* context_;
39 ScopedPersistent<v8::Function> callback_;
40
41 void CallbackAndDie(WebKit::WebFrame* frame, bool succeeded) {
not at google - send to devlin 2013/06/14 16:45:27 frame not used
lazyboy 2013/06/14 18:17:34 Done.
42 v8::HandleScope handle_scope;
43 v8::Context::Scope scope(context_->v8_context());
not at google - send to devlin 2013/06/14 16:45:27 you don't need the scope, CallFunction does it for
lazyboy 2013/06/14 18:17:34 Done.
44 v8::Handle<v8::Value> args[] = {
45 succeeded ? v8::True() : v8::False()
not at google - send to devlin 2013/06/14 16:45:27 v8::Boolean::New(succeeded)
lazyboy 2013/06/14 18:17:34 Done.
46 };
47 context_->CallFunction(callback_.get(), 1, args);
48 delete this;
49 }
50 };
51 } // namespace
52
53
54 RenderViewObserverNatives::RenderViewObserverNatives(Dispatcher* dispatcher,
55 ChromeV8Context* context)
56 : ChromeV8Extension(dispatcher, context) {
57 RouteFunction("OnDocumentCreated",
58 base::Bind(&RenderViewObserverNatives::OnDocumentCreated,
59 base::Unretained(this)));
60 RouteFunction(
61 "OnDocumentCreatedForCurrentContext",
62 base::Bind(&RenderViewObserverNatives::OnDocumentCreatedForCurrentContext,
63 base::Unretained(this)));
64 }
65
66 v8::Handle<v8::Value> RenderViewObserverNatives::OnDocumentCreated(
67 const v8::Arguments& args) {
68 CHECK(args.Length() == 2);
69 CHECK(args[0]->IsInt32());
70 CHECK(args[1]->IsFunction());
71
72 int view_id = args[0]->Int32Value();
73
74 content::RenderView* view = content::RenderView::FromRoutingID(view_id);
75 if (!view)
76 return v8::Undefined();
77
78 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[1]);
79 new LoadWatcher(context(), view, func);
80
81 return v8::True();
82 }
83
84 v8::Handle<v8::Value>
85 RenderViewObserverNatives::OnDocumentCreatedForCurrentContext(
86 const v8::Arguments& args) {
87 CHECK(args.Length() == 1);
88 CHECK(args[0]->IsFunction());
89
90 content::RenderView* view = context()->GetRenderView();
91 if (!view)
not at google - send to devlin 2013/06/14 16:45:27 I think you can assume there's a render view here.
lazyboy 2013/06/14 18:17:34 Done.
92 return v8::Undefined();
93
94 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[0]);
95 new LoadWatcher(context(), view, func);
96
97 return v8::True();
98 }
99
100 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698