diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2015-07-09 10:36:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-09 17:37:20 +0000 |
commit | c3d6ba1b13ec1f050178e4f97c121b528c07520d (patch) | |
tree | f635cdcaf99a8e2abf7507c227e1e2038d733f1d /extensions/renderer/app_window_custom_bindings.cc | |
parent | 58b04162d300a4c9b067cf281c83823094c0aeb5 (diff) | |
download | chromium_src-c3d6ba1b13ec1f050178e4f97c121b528c07520d.zip chromium_src-c3d6ba1b13ec1f050178e4f97c121b528c07520d.tar.gz chromium_src-c3d6ba1b13ec1f050178e4f97c121b528c07520d.tar.bz2 |
[Extensions OOPI] Update app window bindings for OOPI
Update the app window custom bindings to use render frame logic
instead of render view logic. This involves changes to the custom
bindings themselves, as well as app window creation logic. And, for fun,
a few small cleanups while I was in the area.
BUG=455776
TBR=dbeam@chromium.org (webui)
Review URL: https://codereview.chromium.org/1211003006
Cr-Commit-Position: refs/heads/master@{#338076}
Diffstat (limited to 'extensions/renderer/app_window_custom_bindings.cc')
-rw-r--r-- | extensions/renderer/app_window_custom_bindings.cc | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/extensions/renderer/app_window_custom_bindings.cc b/extensions/renderer/app_window_custom_bindings.cc index fa5b3dc..d3383ca 100644 --- a/extensions/renderer/app_window_custom_bindings.cc +++ b/extensions/renderer/app_window_custom_bindings.cc @@ -9,13 +9,11 @@ #include "base/command_line.h" #include "content/public/child/v8_value_converter.h" #include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_view.h" -#include "content/public/renderer/render_view_observer.h" -#include "content/public/renderer/render_view_visitor.h" #include "extensions/common/extension_messages.h" #include "extensions/common/switches.h" -#include "extensions/renderer/dispatcher.h" #include "extensions/renderer/script_context.h" #include "extensions/renderer/script_context_set.h" #include "grit/extensions_renderer_resources.h" @@ -26,21 +24,22 @@ namespace extensions { -class DidCreateDocumentElementObserver : public content::RenderViewObserver { +class DidCreateDocumentElementObserver : public content::RenderFrameObserver { public: - DidCreateDocumentElementObserver(content::RenderView* view, - Dispatcher* dispatcher) - : content::RenderViewObserver(view), dispatcher_(dispatcher) {} + DidCreateDocumentElementObserver(content::RenderFrame* frame, + const ScriptContextSet* script_context_set) + : content::RenderFrameObserver(frame), + script_context_set_(script_context_set) { + DCHECK(script_context_set_); + } - void DidCreateDocumentElement(blink::WebLocalFrame* frame) override { - DCHECK(frame); - DCHECK(dispatcher_); + void DidCreateDocumentElement() override { + blink::WebLocalFrame* web_frame = render_frame()->GetWebFrame(); // Don't attempt to inject the titlebar into iframes. - if (frame->parent()) + if (web_frame->parent()) return; - ScriptContext* script_context = - dispatcher_->script_context_set().GetByV8Context( - frame->mainWorldScriptContext()); + ScriptContext* script_context = script_context_set_->GetByV8Context( + web_frame->mainWorldScriptContext()); if (!script_context) return; script_context->module_system()->CallModuleMethod( @@ -48,22 +47,25 @@ class DidCreateDocumentElementObserver : public content::RenderViewObserver { } private: - Dispatcher* dispatcher_; + const ScriptContextSet* script_context_set_; + + DISALLOW_COPY_AND_ASSIGN(DidCreateDocumentElementObserver); }; -AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher, - ScriptContext* context) - : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) { - RouteFunction("GetView", - base::Bind(&AppWindowCustomBindings::GetView, - base::Unretained(this))); +AppWindowCustomBindings::AppWindowCustomBindings( + const ScriptContextSet* script_context_set, + ScriptContext* context) + : ObjectBackedNativeHandler(context), + script_context_set_(script_context_set) { + RouteFunction("GetFrame", base::Bind(&AppWindowCustomBindings::GetFrame, + base::Unretained(this))); RouteFunction("GetWindowControlsHtmlTemplate", base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate, base::Unretained(this))); } -void AppWindowCustomBindings::GetView( +void AppWindowCustomBindings::GetFrame( const v8::FunctionCallbackInfo<v8::Value>& args) { // TODO(jeremya): convert this to IDL nocompile to get validation, and turn // these argument checks into CHECK(). @@ -76,36 +78,37 @@ void AppWindowCustomBindings::GetView( if (!args[1]->IsBoolean()) return; - int view_id = args[0]->Int32Value(); + int frame_id = args[0]->Int32Value(); bool inject_titlebar = args[1]->BooleanValue(); - if (view_id == MSG_ROUTING_NONE) + if (frame_id == MSG_ROUTING_NONE) return; - content::RenderView* view = content::RenderView::FromRoutingID(view_id); - if (!view) + content::RenderFrame* app_frame = + content::RenderFrame::FromRoutingID(frame_id); + if (!app_frame) return; - if (inject_titlebar) - new DidCreateDocumentElementObserver(view, dispatcher_); - // TODO(jeremya): it doesn't really make sense to set the opener here, but we // need to make sure the security origin is set up before returning the DOM // reference. A better way to do this would be to have the browser pass the // opener through so opener_id is set in RenderViewImpl's constructor. - content::RenderFrame* render_frame = context()->GetRenderFrame(); - content::RenderView* render_view = - render_frame ? render_frame->GetRenderView() : nullptr; - if (!render_view) + content::RenderFrame* context_render_frame = context()->GetRenderFrame(); + if (!context_render_frame) return; - blink::WebFrame* opener = render_view->GetWebView()->mainFrame(); - blink::WebFrame* frame = view->GetWebView()->mainFrame(); - frame->setOpener(opener); + + if (inject_titlebar) + new DidCreateDocumentElementObserver(app_frame, script_context_set_); + + blink::WebFrame* opener = context_render_frame->GetWebFrame(); + blink::WebLocalFrame* app_web_frame = app_frame->GetWebFrame(); + app_web_frame->setOpener(opener); content::RenderThread::Get()->Send( - new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); + new ExtensionHostMsg_ResumeRequests(app_frame->GetRoutingID())); - v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); + v8::Local<v8::Value> window = + app_web_frame->mainWorldScriptContext()->Global(); args.GetReturnValue().Set(window); } |