OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/app_window_custom_bindings.h" | 5 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/common/extensions/extension_action.h" | 10 #include "chrome/common/extensions/extension_action.h" |
11 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
13 #include "chrome/renderer/extensions/chrome_v8_context.h" | |
13 #include "chrome/renderer/extensions/dispatcher.h" | 14 #include "chrome/renderer/extensions/dispatcher.h" |
14 #include "chrome/renderer/extensions/extension_helper.h" | 15 #include "chrome/renderer/extensions/extension_helper.h" |
15 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
16 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
17 #include "grit/renderer_resources.h" | 18 #include "grit/renderer_resources.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | |
Mihai Parparita -not on Chrome
2012/08/31 23:12:56
Nit: this seems unused (as does WebNavigationPolic
jeremya
2012/09/01 01:42:30
Done.
| |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h " | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h " |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | |
23 #include "v8/include/v8.h" | 24 #include "v8/include/v8.h" |
24 #include "webkit/glue/webkit_glue.h" | 25 #include "webkit/glue/webkit_glue.h" |
25 | 26 |
26 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
27 #include "content/public/renderer/render_view_visitor.h" | 28 #include "content/public/renderer/render_view_visitor.h" |
28 | 29 |
29 namespace extensions { | 30 namespace extensions { |
30 | 31 |
32 class DidCreateDocumentElementObserver : public content::RenderViewObserver { | |
33 public: | |
34 DidCreateDocumentElementObserver( | |
35 content::RenderView* view, Dispatcher* dispatcher) | |
36 : content::RenderViewObserver(view), dispatcher_(dispatcher) { | |
37 } | |
38 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE { | |
Mihai Parparita -not on Chrome
2012/08/31 23:12:56
Nit: newline before this.
jeremya
2012/09/01 01:42:30
Done.
| |
39 v8::HandleScope handle_scope; | |
40 DCHECK(frame); | |
41 DCHECK(dispatcher_); | |
42 ChromeV8Context* v8_context = | |
43 dispatcher_->v8_context_set().GetByV8Context( | |
44 frame->mainWorldScriptContext()); | |
45 | |
46 if (!v8_context) | |
47 return; | |
48 v8::Context::Scope context_scope(v8_context->v8_context()); | |
49 v8_context->module_system()->CallModuleMethod( | |
50 "injectAppTitlebar", "didCreateDocumentElement"); | |
51 } | |
52 | |
53 private: | |
54 Dispatcher* dispatcher_; | |
55 bool inject_titlebar_; | |
Mihai Parparita -not on Chrome
2012/08/31 23:12:56
Seems to be unused. Though to be honest, I liked t
jeremya
2012/09/01 01:42:30
Done. Yeah, I wasn't really sure which was cleaner
| |
56 }; | |
57 | |
31 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher) | 58 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher) |
32 : ChromeV8Extension(dispatcher) { | 59 : ChromeV8Extension(dispatcher) { |
33 RouteStaticFunction("GetView", &GetView); | 60 RouteFunction("GetView", |
61 base::Bind(&AppWindowCustomBindings::GetView, | |
62 base::Unretained(this))); | |
34 } | 63 } |
35 | 64 |
36 namespace { | 65 namespace { |
37 class FindViewByID : public content::RenderViewVisitor { | 66 class FindViewByID : public content::RenderViewVisitor { |
38 public: | 67 public: |
39 explicit FindViewByID(int route_id) : route_id_(route_id), view_(NULL) { | 68 explicit FindViewByID(int route_id) : route_id_(route_id), view_(NULL) { |
40 } | 69 } |
41 | 70 |
42 content::RenderView* view() { return view_; } | 71 content::RenderView* view() { return view_; } |
43 | 72 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 // ChildThread::current()->ResolveRoute(), but ResolveRoute returns an | 104 // ChildThread::current()->ResolveRoute(), but ResolveRoute returns an |
76 // IPC::Listener*, which RenderView doesn't inherit from (RenderViewImpl | 105 // IPC::Listener*, which RenderView doesn't inherit from (RenderViewImpl |
77 // does, indirectly, via RenderWidget, but the link isn't exposed outside of | 106 // does, indirectly, via RenderWidget, but the link isn't exposed outside of |
78 // content/.) | 107 // content/.) |
79 FindViewByID view_finder(view_id); | 108 FindViewByID view_finder(view_id); |
80 content::RenderView::ForEach(&view_finder); | 109 content::RenderView::ForEach(&view_finder); |
81 content::RenderView* view = view_finder.view(); | 110 content::RenderView* view = view_finder.view(); |
82 if (!view) | 111 if (!view) |
83 return v8::Undefined(); | 112 return v8::Undefined(); |
84 | 113 |
114 new DidCreateDocumentElementObserver(view, dispatcher()); | |
115 | |
85 // TODO(jeremya): it doesn't really make sense to set the opener here, but we | 116 // TODO(jeremya): it doesn't really make sense to set the opener here, but we |
86 // need to make sure the security origin is set up before returning the DOM | 117 // need to make sure the security origin is set up before returning the DOM |
87 // reference. A better way to do this would be to have the browser pass the | 118 // reference. A better way to do this would be to have the browser pass the |
88 // opener through so opener_id is set in RenderViewImpl's constructor. | 119 // opener through so opener_id is set in RenderViewImpl's constructor. |
89 content::RenderView* render_view = GetCurrentRenderView(); | 120 content::RenderView* render_view = GetCurrentRenderView(); |
90 if (!render_view) | 121 if (!render_view) |
91 return v8::Undefined(); | 122 return v8::Undefined(); |
92 WebKit::WebFrame* opener = render_view->GetWebView()->mainFrame(); | 123 WebKit::WebFrame* opener = render_view->GetWebView()->mainFrame(); |
93 WebKit::WebFrame* frame = view->GetWebView()->mainFrame(); | 124 WebKit::WebFrame* frame = view->GetWebView()->mainFrame(); |
94 frame->setOpener(opener); | 125 frame->setOpener(opener); |
95 content::RenderThread::Get()->Send( | 126 content::RenderThread::Get()->Send( |
96 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); | 127 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); |
97 | 128 |
98 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); | 129 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); |
99 return window; | 130 return window; |
100 } | 131 } |
101 | 132 |
102 } // namespace extensions | 133 } // namespace extensions |
OLD | NEW |