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

Side by Side Diff: chrome/renderer/extensions/app_window_custom_bindings.cc

Issue 240603003: Remove ChromeV8Extension & most of ChromeV8Context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/renderer/extensions/chrome_v8_context.h"
12 #include "chrome/renderer/extensions/dispatcher.h" 11 #include "chrome/renderer/extensions/dispatcher.h"
13 #include "content/public/renderer/render_thread.h" 12 #include "content/public/renderer/render_thread.h"
14 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
15 #include "content/public/renderer/render_view_observer.h" 14 #include "content/public/renderer/render_view_observer.h"
16 #include "content/public/renderer/render_view_visitor.h" 15 #include "content/public/renderer/render_view_visitor.h"
17 #include "content/public/renderer/v8_value_converter.h" 16 #include "content/public/renderer/v8_value_converter.h"
18 #include "extensions/common/extension_messages.h" 17 #include "extensions/common/extension_messages.h"
19 #include "extensions/renderer/scoped_persistent.h" 18 #include "extensions/renderer/scoped_persistent.h"
19 #include "extensions/renderer/script_context.h"
20 #include "extensions/renderer/script_context_set.h"
20 #include "grit/renderer_resources.h" 21 #include "grit/renderer_resources.h"
21 #include "third_party/WebKit/public/web/WebFrame.h" 22 #include "third_party/WebKit/public/web/WebFrame.h"
22 #include "third_party/WebKit/public/web/WebView.h" 23 #include "third_party/WebKit/public/web/WebView.h"
23 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
24 #include "v8/include/v8.h" 25 #include "v8/include/v8.h"
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 class DidCreateDocumentElementObserver : public content::RenderViewObserver { 29 class DidCreateDocumentElementObserver : public content::RenderViewObserver {
29 public: 30 public:
30 DidCreateDocumentElementObserver( 31 DidCreateDocumentElementObserver(content::RenderView* view,
31 content::RenderView* view, Dispatcher* dispatcher) 32 Dispatcher* dispatcher)
32 : content::RenderViewObserver(view), dispatcher_(dispatcher) { 33 : content::RenderViewObserver(view), dispatcher_(dispatcher) {}
33 }
34 34
35 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE { 35 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE {
36 DCHECK(frame); 36 DCHECK(frame);
37 DCHECK(dispatcher_); 37 DCHECK(dispatcher_);
38 // Don't attempt to inject the titlebar into iframes. 38 // Don't attempt to inject the titlebar into iframes.
39 if (frame->parent()) 39 if (frame->parent())
40 return; 40 return;
41 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 41 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
42 ChromeV8Context* v8_context = 42 ScriptContext* script_context =
43 dispatcher_->v8_context_set().GetByV8Context( 43 dispatcher_->script_context_set().GetByV8Context(
44 frame->mainWorldScriptContext()); 44 frame->mainWorldScriptContext());
45 45
46 if (!v8_context) 46 if (!script_context)
47 return; 47 return;
48 v8::Context::Scope context_scope(v8_context->v8_context()); 48 v8::Context::Scope context_scope(script_context->v8_context());
49 v8_context->module_system()->CallModuleMethod( 49 script_context->module_system()->CallModuleMethod(
50 "injectAppTitlebar", "didCreateDocumentElement"); 50 "injectAppTitlebar", "didCreateDocumentElement");
51 } 51 }
52 52
53 private: 53 private:
54 Dispatcher* dispatcher_; 54 Dispatcher* dispatcher_;
55 }; 55 };
56 56
57 AppWindowCustomBindings::AppWindowCustomBindings( 57 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher,
58 Dispatcher* dispatcher, 58 ScriptContext* context)
59 ChromeV8Context* context) : ChromeV8Extension(dispatcher, context) { 59 : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) {
60 RouteFunction("GetView", 60 RouteFunction("GetView",
61 base::Bind(&AppWindowCustomBindings::GetView, 61 base::Bind(&AppWindowCustomBindings::GetView,
62 base::Unretained(this))); 62 base::Unretained(this)));
63 63
64 RouteFunction("GetWindowControlsHtmlTemplate", 64 RouteFunction("GetWindowControlsHtmlTemplate",
65 base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate, 65 base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate,
66 base::Unretained(this))); 66 base::Unretained(this)));
67 } 67 }
68 68
69 void AppWindowCustomBindings::GetView( 69 void AppWindowCustomBindings::GetView(
(...skipping 14 matching lines...) Expand all
84 bool inject_titlebar = args[1]->BooleanValue(); 84 bool inject_titlebar = args[1]->BooleanValue();
85 85
86 if (view_id == MSG_ROUTING_NONE) 86 if (view_id == MSG_ROUTING_NONE)
87 return; 87 return;
88 88
89 content::RenderView* view = content::RenderView::FromRoutingID(view_id); 89 content::RenderView* view = content::RenderView::FromRoutingID(view_id);
90 if (!view) 90 if (!view)
91 return; 91 return;
92 92
93 if (inject_titlebar) 93 if (inject_titlebar)
94 new DidCreateDocumentElementObserver(view, dispatcher()); 94 new DidCreateDocumentElementObserver(view, dispatcher_);
95 95
96 // TODO(jeremya): it doesn't really make sense to set the opener here, but we 96 // TODO(jeremya): it doesn't really make sense to set the opener here, but we
97 // need to make sure the security origin is set up before returning the DOM 97 // need to make sure the security origin is set up before returning the DOM
98 // reference. A better way to do this would be to have the browser pass the 98 // reference. A better way to do this would be to have the browser pass the
99 // opener through so opener_id is set in RenderViewImpl's constructor. 99 // opener through so opener_id is set in RenderViewImpl's constructor.
100 content::RenderView* render_view = GetRenderView(); 100 content::RenderView* render_view = context()->GetRenderView();
101 if (!render_view) 101 if (!render_view)
102 return; 102 return;
103 blink::WebFrame* opener = render_view->GetWebView()->mainFrame(); 103 blink::WebFrame* opener = render_view->GetWebView()->mainFrame();
104 blink::WebFrame* frame = view->GetWebView()->mainFrame(); 104 blink::WebFrame* frame = view->GetWebView()->mainFrame();
105 frame->setOpener(opener); 105 frame->setOpener(opener);
106 content::RenderThread::Get()->Send( 106 content::RenderThread::Get()->Send(
107 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); 107 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID()));
108 108
109 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); 109 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global();
110 args.GetReturnValue().Set(window); 110 args.GetReturnValue().Set(window);
(...skipping 10 matching lines...) Expand all
121 ResourceBundle::GetSharedInstance().GetRawDataResource( 121 ResourceBundle::GetSharedInstance().GetRawDataResource(
122 IDR_WINDOW_CONTROLS_TEMPLATE_HTML).as_string()); 122 IDR_WINDOW_CONTROLS_TEMPLATE_HTML).as_string());
123 scoped_ptr<content::V8ValueConverter> converter( 123 scoped_ptr<content::V8ValueConverter> converter(
124 content::V8ValueConverter::create()); 124 content::V8ValueConverter::create());
125 result = converter->ToV8Value(value, context()->v8_context()); 125 result = converter->ToV8Value(value, context()->v8_context());
126 } 126 }
127 args.GetReturnValue().Set(result); 127 args.GetReturnValue().Set(result);
128 } 128 }
129 129
130 } // namespace extensions 130 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698