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

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

Issue 1211003006: [Extensions OOPI] Update app window bindings for OOPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
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 "extensions/renderer/app_window_custom_bindings.h" 5 #include "extensions/renderer/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 "content/public/child/v8_value_converter.h" 10 #include "content/public/child/v8_value_converter.h"
11 #include "content/public/renderer/render_frame.h" 11 #include "content/public/renderer/render_frame.h"
12 #include "content/public/renderer/render_frame_observer.h"
12 #include "content/public/renderer/render_thread.h" 13 #include "content/public/renderer/render_thread.h"
13 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
14 #include "content/public/renderer/render_view_observer.h"
15 #include "content/public/renderer/render_view_visitor.h"
16 #include "extensions/common/extension_messages.h" 15 #include "extensions/common/extension_messages.h"
17 #include "extensions/common/switches.h" 16 #include "extensions/common/switches.h"
18 #include "extensions/renderer/dispatcher.h" 17 #include "extensions/renderer/dispatcher.h"
19 #include "extensions/renderer/script_context.h" 18 #include "extensions/renderer/script_context.h"
20 #include "extensions/renderer/script_context_set.h" 19 #include "extensions/renderer/script_context_set.h"
21 #include "grit/extensions_renderer_resources.h" 20 #include "grit/extensions_renderer_resources.h"
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" 21 #include "third_party/WebKit/public/web/WebLocalFrame.h"
23 #include "third_party/WebKit/public/web/WebView.h" 22 #include "third_party/WebKit/public/web/WebView.h"
24 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
25 #include "v8/include/v8.h" 24 #include "v8/include/v8.h"
26 25
27 namespace extensions { 26 namespace extensions {
28 27
29 class DidCreateDocumentElementObserver : public content::RenderViewObserver { 28 class DidCreateDocumentElementObserver : public content::RenderFrameObserver {
30 public: 29 public:
31 DidCreateDocumentElementObserver(content::RenderView* view, 30 DidCreateDocumentElementObserver(content::RenderFrame* frame,
32 Dispatcher* dispatcher) 31 Dispatcher* dispatcher)
not at google - send to devlin 2015/07/08 20:22:20 Can you change this to just pass in the ScriptCont
Devlin 2015/07/08 21:08:46 Sure, done.
33 : content::RenderViewObserver(view), dispatcher_(dispatcher) {} 32 : content::RenderFrameObserver(frame), dispatcher_(dispatcher) {
33 DCHECK(dispatcher_);
34 }
34 35
35 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override { 36 void DidCreateDocumentElement() override {
36 DCHECK(frame); 37 blink::WebLocalFrame* web_frame = render_frame()->GetWebFrame();
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 (web_frame->parent())
40 return; 40 return;
41 ScriptContext* script_context = 41 ScriptContext* script_context =
42 dispatcher_->script_context_set().GetByV8Context( 42 dispatcher_->script_context_set().GetByV8Context(
43 frame->mainWorldScriptContext()); 43 web_frame->mainWorldScriptContext());
44 if (!script_context) 44 if (!script_context)
45 return; 45 return;
46 script_context->module_system()->CallModuleMethod( 46 script_context->module_system()->CallModuleMethod(
47 "injectAppTitlebar", "didCreateDocumentElement"); 47 "injectAppTitlebar", "didCreateDocumentElement");
48 } 48 }
49 49
50 private: 50 private:
51 Dispatcher* dispatcher_; 51 Dispatcher* dispatcher_;
52
53 DISALLOW_COPY_AND_ASSIGN(DidCreateDocumentElementObserver);
52 }; 54 };
53 55
54 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher, 56 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher,
55 ScriptContext* context) 57 ScriptContext* context)
56 : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) { 58 : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) {
57 RouteFunction("GetView", 59 RouteFunction("GetFrame", base::Bind(&AppWindowCustomBindings::GetFrame,
58 base::Bind(&AppWindowCustomBindings::GetView, 60 base::Unretained(this)));
59 base::Unretained(this)));
60 61
61 RouteFunction("GetWindowControlsHtmlTemplate", 62 RouteFunction("GetWindowControlsHtmlTemplate",
62 base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate, 63 base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate,
63 base::Unretained(this))); 64 base::Unretained(this)));
64 } 65 }
65 66
66 void AppWindowCustomBindings::GetView( 67 void AppWindowCustomBindings::GetFrame(
67 const v8::FunctionCallbackInfo<v8::Value>& args) { 68 const v8::FunctionCallbackInfo<v8::Value>& args) {
68 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn 69 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn
69 // these argument checks into CHECK(). 70 // these argument checks into CHECK().
70 if (args.Length() != 2) 71 if (args.Length() != 2)
71 return; 72 return;
72 73
73 if (!args[0]->IsInt32()) 74 if (!args[0]->IsInt32())
74 return; 75 return;
75 76
76 if (!args[1]->IsBoolean()) 77 if (!args[1]->IsBoolean())
77 return; 78 return;
78 79
79 int view_id = args[0]->Int32Value(); 80 int frame_id = args[0]->Int32Value();
80 81
81 bool inject_titlebar = args[1]->BooleanValue(); 82 bool inject_titlebar = args[1]->BooleanValue();
82 83
83 if (view_id == MSG_ROUTING_NONE) 84 if (frame_id == MSG_ROUTING_NONE)
84 return; 85 return;
85 86
86 content::RenderView* view = content::RenderView::FromRoutingID(view_id); 87 content::RenderFrame* app_frame =
87 if (!view) 88 content::RenderFrame::FromRoutingID(frame_id);
89 if (!app_frame)
88 return; 90 return;
89 91
90 if (inject_titlebar) 92 if (inject_titlebar)
91 new DidCreateDocumentElementObserver(view, dispatcher_); 93 new DidCreateDocumentElementObserver(app_frame, dispatcher_);
not at google - send to devlin 2015/07/08 20:22:20 I feel like this shouldn't happen until we know fo
Devlin 2015/07/08 21:08:46 Done.
92 94
93 // TODO(jeremya): it doesn't really make sense to set the opener here, but we 95 // TODO(jeremya): it doesn't really make sense to set the opener here, but we
94 // need to make sure the security origin is set up before returning the DOM 96 // need to make sure the security origin is set up before returning the DOM
95 // reference. A better way to do this would be to have the browser pass the 97 // reference. A better way to do this would be to have the browser pass the
96 // opener through so opener_id is set in RenderViewImpl's constructor. 98 // opener through so opener_id is set in RenderViewImpl's constructor.
97 content::RenderFrame* render_frame = context()->GetRenderFrame(); 99 content::RenderFrame* context_render_frame = context()->GetRenderFrame();
98 content::RenderView* render_view = 100 content::RenderView* context_render_view =
99 render_frame ? render_frame->GetRenderView() : nullptr; 101 context_render_frame ? context_render_frame->GetRenderView() : nullptr;
100 if (!render_view) 102 if (!context_render_view)
101 return; 103 return;
102 blink::WebFrame* opener = render_view->GetWebView()->mainFrame(); 104 blink::WebFrame* opener = context_render_view->GetWebView()->mainFrame();
not at google - send to devlin 2015/07/08 20:22:20 I think the "opener" is equally correctly just con
Devlin 2015/07/08 21:08:46 It is potentially a behavior change. But let's tr
103 blink::WebFrame* frame = view->GetWebView()->mainFrame(); 105 blink::WebLocalFrame* app_web_frame = app_frame->GetWebFrame();
104 frame->setOpener(opener); 106 app_web_frame->setOpener(opener);
105 content::RenderThread::Get()->Send( 107 content::RenderThread::Get()->Send(
106 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); 108 new ExtensionHostMsg_ResumeRequests(app_frame->GetRoutingID()));
107 109
108 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); 110 v8::Local<v8::Value> window =
111 app_web_frame->mainWorldScriptContext()->Global();
109 args.GetReturnValue().Set(window); 112 args.GetReturnValue().Set(window);
110 } 113 }
111 114
112 void AppWindowCustomBindings::GetWindowControlsHtmlTemplate( 115 void AppWindowCustomBindings::GetWindowControlsHtmlTemplate(
113 const v8::FunctionCallbackInfo<v8::Value>& args) { 116 const v8::FunctionCallbackInfo<v8::Value>& args) {
114 CHECK_EQ(args.Length(), 0); 117 CHECK_EQ(args.Length(), 0);
115 118
116 v8::Local<v8::Value> result = v8::String::Empty(args.GetIsolate()); 119 v8::Local<v8::Value> result = v8::String::Empty(args.GetIsolate());
117 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 120 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
118 switches::kEnableAppWindowControls)) { 121 switches::kEnableAppWindowControls)) {
119 base::StringValue value( 122 base::StringValue value(
120 ResourceBundle::GetSharedInstance() 123 ResourceBundle::GetSharedInstance()
121 .GetRawDataResource(IDR_WINDOW_CONTROLS_TEMPLATE_HTML) 124 .GetRawDataResource(IDR_WINDOW_CONTROLS_TEMPLATE_HTML)
122 .as_string()); 125 .as_string());
123 scoped_ptr<content::V8ValueConverter> converter( 126 scoped_ptr<content::V8ValueConverter> converter(
124 content::V8ValueConverter::create()); 127 content::V8ValueConverter::create());
125 result = converter->ToV8Value(&value, context()->v8_context()); 128 result = converter->ToV8Value(&value, context()->v8_context());
126 } 129 }
127 args.GetReturnValue().Set(result); 130 args.GetReturnValue().Set(result);
128 } 131 }
129 132
130 } // namespace extensions 133 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698