diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:39:36 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:39:36 +0000 |
commit | 7685f64a35b6d029f7d11ce752dc126163d9474e (patch) | |
tree | 0cb10d4ed10d781bc6de27672bbcc8528134baab /extensions/shell/renderer | |
parent | af97fe7d55c6310aacf1585bdbd8d38e3bc4c080 (diff) | |
download | chromium_src-7685f64a35b6d029f7d11ce752dc126163d9474e.zip chromium_src-7685f64a35b6d029f7d11ce752dc126163d9474e.tar.gz chromium_src-7685f64a35b6d029f7d11ce752dc126163d9474e.tar.bz2 |
Move apps/shell to extensions/shell.
This does:
- Move files
- Fix up all namespaces in these files to be extensions, not apps
- Clean up DEPS files
This does not:
- Change the name of the build targets (app_shell, app_shell_browsertests)
BUG=394987
TBR=ben@chromium.org
Review URL: https://codereview.chromium.org/412713002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/shell/renderer')
11 files changed, 506 insertions, 0 deletions
diff --git a/extensions/shell/renderer/DEPS b/extensions/shell/renderer/DEPS new file mode 100644 index 0000000..baafcac --- /dev/null +++ b/extensions/shell/renderer/DEPS @@ -0,0 +1,7 @@ +include_rules = [ + # Only allow includes the renderer can use. + "+content/public/renderer", + + "+third_party/WebKit/public", + "+v8/include", +] diff --git a/extensions/shell/renderer/shell_content_renderer_client.cc b/extensions/shell/renderer/shell_content_renderer_client.cc new file mode 100644 index 0000000..c7a9be6 --- /dev/null +++ b/extensions/shell/renderer/shell_content_renderer_client.cc @@ -0,0 +1,131 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/shell/renderer/shell_content_renderer_client.h" + +#include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_frame_observer.h" +#include "content/public/renderer/render_frame_observer_tracker.h" +#include "content/public/renderer/render_thread.h" +#include "extensions/common/extensions_client.h" +#include "extensions/renderer/dispatcher.h" +#include "extensions/renderer/extension_helper.h" +#include "extensions/shell/common/shell_extensions_client.h" +#include "extensions/shell/renderer/shell_dispatcher_delegate.h" +#include "extensions/shell/renderer/shell_extensions_renderer_client.h" +#include "extensions/shell/renderer/shell_renderer_main_delegate.h" + +using blink::WebFrame; +using blink::WebString; +using content::RenderThread; + +namespace extensions { + +namespace { + +// TODO: promote ExtensionFrameHelper to a common place and share with this. +class ShellFrameHelper + : public content::RenderFrameObserver, + public content::RenderFrameObserverTracker<ShellFrameHelper> { + public: + ShellFrameHelper(content::RenderFrame* render_frame, + Dispatcher* extension_dispatcher); + virtual ~ShellFrameHelper(); + + // RenderFrameObserver implementation. + virtual void WillReleaseScriptContext(v8::Handle<v8::Context>, + int world_id) OVERRIDE; + + private: + Dispatcher* extension_dispatcher_; + + DISALLOW_COPY_AND_ASSIGN(ShellFrameHelper); +}; + +ShellFrameHelper::ShellFrameHelper(content::RenderFrame* render_frame, + Dispatcher* extension_dispatcher) + : content::RenderFrameObserver(render_frame), + content::RenderFrameObserverTracker<ShellFrameHelper>(render_frame), + extension_dispatcher_(extension_dispatcher) { +} + +ShellFrameHelper::~ShellFrameHelper() { +} + +void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context, + int world_id) { + extension_dispatcher_->WillReleaseScriptContext( + render_frame()->GetWebFrame(), context, world_id); +} + +} // namespace + +ShellContentRendererClient::ShellContentRendererClient( + scoped_ptr<ShellRendererMainDelegate> delegate) + : delegate_(delegate.Pass()) { +} + +ShellContentRendererClient::~ShellContentRendererClient() { +} + +void ShellContentRendererClient::RenderThreadStarted() { + RenderThread* thread = RenderThread::Get(); + + extensions_client_.reset(new ShellExtensionsClient); + ExtensionsClient::Set(extensions_client_.get()); + + extensions_renderer_client_.reset(new ShellExtensionsRendererClient); + ExtensionsRendererClient::Set(extensions_renderer_client_.get()); + + extension_dispatcher_delegate_.reset(new ShellDispatcherDelegate()); + + // Must be initialized after ExtensionsRendererClient. + extension_dispatcher_.reset( + new Dispatcher(extension_dispatcher_delegate_.get())); + thread->AddObserver(extension_dispatcher_.get()); + + // TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes. + // See ChromeContentRendererClient for details. + if (delegate_) + delegate_->OnThreadStarted(thread); +} + +void ShellContentRendererClient::RenderFrameCreated( + content::RenderFrame* render_frame) { + // ShellFrameHelper destroyes itself when the RenderFrame is destroyed. + new ShellFrameHelper(render_frame, extension_dispatcher_.get()); +} + +void ShellContentRendererClient::RenderViewCreated( + content::RenderView* render_view) { + new ExtensionHelper(render_view, extension_dispatcher_.get()); + if (delegate_) + delegate_->OnViewCreated(render_view); +} + +bool ShellContentRendererClient::WillSendRequest( + blink::WebFrame* frame, + content::PageTransition transition_type, + const GURL& url, + const GURL& first_party_for_cookies, + GURL* new_url) { + // TODO(jamescook): Cause an error for bad extension scheme requests? + return false; +} + +void ShellContentRendererClient::DidCreateScriptContext( + WebFrame* frame, + v8::Handle<v8::Context> context, + int extension_group, + int world_id) { + extension_dispatcher_->DidCreateScriptContext( + frame, context, extension_group, world_id); +} + +bool ShellContentRendererClient::ShouldEnableSiteIsolationPolicy() const { + // Extension renderers don't need site isolation. + return false; +} + +} // namespace extensions diff --git a/extensions/shell/renderer/shell_content_renderer_client.h b/extensions/shell/renderer/shell_content_renderer_client.h new file mode 100644 index 0000000..e7a1fbc --- /dev/null +++ b/extensions/shell/renderer/shell_content_renderer_client.h @@ -0,0 +1,55 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_SHELL_RENDERER_SHELL_CONTENT_RENDERER_CLIENT_H_ +#define EXTENSIONS_SHELL_RENDERER_SHELL_CONTENT_RENDERER_CLIENT_H_ + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/renderer/content_renderer_client.h" + +namespace extensions { + +class Dispatcher; +class DispatcherDelegate; +class ShellExtensionsClient; +class ShellExtensionsRendererClient; +class ShellRendererMainDelegate; + +// Renderer initialization and runtime support for app_shell. +class ShellContentRendererClient : public content::ContentRendererClient { + public: + explicit ShellContentRendererClient( + scoped_ptr<ShellRendererMainDelegate> delegate); + virtual ~ShellContentRendererClient(); + + // content::ContentRendererClient implementation: + virtual void RenderThreadStarted() OVERRIDE; + virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE; + virtual void RenderViewCreated(content::RenderView* render_view) OVERRIDE; + virtual bool WillSendRequest(blink::WebFrame* frame, + content::PageTransition transition_type, + const GURL& url, + const GURL& first_party_for_cookies, + GURL* new_url) OVERRIDE; + virtual void DidCreateScriptContext(blink::WebFrame* frame, + v8::Handle<v8::Context> context, + int extension_group, + int world_id) OVERRIDE; + virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE; + + private: + scoped_ptr<ShellRendererMainDelegate> delegate_; + scoped_ptr<ShellExtensionsClient> extensions_client_; + scoped_ptr<ShellExtensionsRendererClient> extensions_renderer_client_; + scoped_ptr<DispatcherDelegate> extension_dispatcher_delegate_; + scoped_ptr<Dispatcher> extension_dispatcher_; + + DISALLOW_COPY_AND_ASSIGN(ShellContentRendererClient); +}; + +} // namespace extensions + +#endif // EXTENSIONS_SHELL_RENDERER_SHELL_CONTENT_RENDERER_CLIENT_H_ diff --git a/extensions/shell/renderer/shell_custom_bindings.cc b/extensions/shell/renderer/shell_custom_bindings.cc new file mode 100644 index 0000000..40965ca --- /dev/null +++ b/extensions/shell/renderer/shell_custom_bindings.cc @@ -0,0 +1,57 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/shell/renderer/shell_custom_bindings.h" + +#include "content/public/renderer/render_thread.h" +#include "content/public/renderer/render_view.h" +#include "content/public/renderer/v8_value_converter.h" +#include "extensions/common/extension_messages.h" +#include "extensions/renderer/script_context.h" +#include "extensions/renderer/script_context_set.h" +#include "third_party/WebKit/public/web/WebFrame.h" +#include "third_party/WebKit/public/web/WebView.h" +#include "v8/include/v8.h" + +namespace extensions { + +ShellCustomBindings::ShellCustomBindings(ScriptContext* context) + : ObjectBackedNativeHandler(context) { + RouteFunction( + "GetView", + base::Bind(&ShellCustomBindings::GetView, base::Unretained(this))); +} + +void ShellCustomBindings::GetView( + const v8::FunctionCallbackInfo<v8::Value>& args) { + if (args.Length() != 1 || !args[0]->IsInt32()) + return; + + int view_id = args[0]->Int32Value(); + if (view_id == MSG_ROUTING_NONE) + return; + + content::RenderView* view = content::RenderView::FromRoutingID(view_id); + if (!view) + return; + + // Set the opener so we have a security origin set up before returning the DOM + // reference. + content::RenderView* render_view = context()->GetRenderView(); + if (!render_view) + return; + blink::WebFrame* opener = render_view->GetWebView()->mainFrame(); + blink::WebFrame* frame = view->GetWebView()->mainFrame(); + frame->setOpener(opener); + + // Resume resource requests. + content::RenderThread::Get()->Send( + new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); + + // Return the script context. + v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); + args.GetReturnValue().Set(window); +} + +} // namespace extensions diff --git a/extensions/shell/renderer/shell_custom_bindings.h b/extensions/shell/renderer/shell_custom_bindings.h new file mode 100644 index 0000000..aaa4abe --- /dev/null +++ b/extensions/shell/renderer/shell_custom_bindings.h @@ -0,0 +1,25 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_SHELL_RENDERER_SHELL_CUSTOM_BINDINGS_H_ +#define EXTENSIONS_SHELL_RENDERER_SHELL_CUSTOM_BINDINGS_H_ + +#include "extensions/renderer/object_backed_native_handler.h" + +namespace extensions { + +// Implements custom bindings for the chrome.shell API. +class ShellCustomBindings : public ObjectBackedNativeHandler { + public: + ShellCustomBindings(ScriptContext* context); + + private: + void GetView(const v8::FunctionCallbackInfo<v8::Value>& args); + + DISALLOW_COPY_AND_ASSIGN(ShellCustomBindings); +}; + +} // namespace extensions + +#endif // EXTENSIONS_SHELL_RENDERER_SHELL_CUSTOM_BINDINGS_H_ diff --git a/extensions/shell/renderer/shell_custom_bindings.js b/extensions/shell/renderer/shell_custom_bindings.js new file mode 100644 index 0000000..5fe9a9ae --- /dev/null +++ b/extensions/shell/renderer/shell_custom_bindings.js @@ -0,0 +1,78 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var shellNatives = requireNative('shell_natives'); +var Binding = require('binding').Binding; +var forEach = require('utils').forEach; +var renderViewObserverNatives = requireNative('renderViewObserverNatives'); + +var currentAppWindow = null; + +var shell = Binding.create('shell'); +shell.registerCustomHook(function(bindingsAPI) { + var apiFunctions = bindingsAPI.apiFunctions; + + apiFunctions.setCustomCallback('createWindow', + function(name, request, windowParams) { + var view = null; + + // When window creation fails, |windowParams| will be undefined. + if (windowParams && windowParams.viewId) { + view = shellNatives.GetView(windowParams.viewId); + } + + if (!view) { + // No route to created window. If given a callback, trigger it with an + // undefined object. + if (request.callback) { + request.callback(undefined); + delete request.callback; + } + return; + } + + // Initialize the app window in the newly created JS context + view.chrome.shell.initializeAppWindow(); + + var callback = request.callback; + if (callback) { + delete request.callback; + + var willCallback = + renderViewObserverNatives.OnDocumentElementCreated( + windowParams.viewId, + function(success) { + if (success) { + callback(view.chrome.shell.currentWindow()); + } else { + callback(undefined); + } + }); + if (!willCallback) { + callback(undefined); + } + } + }); + + apiFunctions.setHandleRequest('currentWindow', function() { + if (!currentAppWindow) { + console.error( + 'The JavaScript context calling chrome.shell.currentWindow() has' + + ' no associated AppWindow.'); + return null; + } + return currentAppWindow; + }); + + // This is an internal function, but needs to be bound into a closure + // so the correct JS context is used for global variables such as + // currentAppWindow. + apiFunctions.setHandleRequest('initializeAppWindow', function() { + var AppWindow = function() {}; + AppWindow.prototype.contentWindow = window; + currentAppWindow = new AppWindow; + }); +}); + +exports.binding = shell.generate(); diff --git a/extensions/shell/renderer/shell_dispatcher_delegate.cc b/extensions/shell/renderer/shell_dispatcher_delegate.cc new file mode 100644 index 0000000..0f6b04b --- /dev/null +++ b/extensions/shell/renderer/shell_dispatcher_delegate.cc @@ -0,0 +1,35 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/shell/renderer/shell_dispatcher_delegate.h" + +#include "extensions/renderer/module_system.h" +#include "extensions/renderer/resource_bundle_source_map.h" +#include "extensions/renderer/script_context.h" +#include "extensions/shell/renderer/shell_custom_bindings.h" +#include "grit/app_shell_resources.h" + +namespace extensions { + +ShellDispatcherDelegate::ShellDispatcherDelegate() { +} + +ShellDispatcherDelegate::~ShellDispatcherDelegate() { +} + +void ShellDispatcherDelegate::RegisterNativeHandlers( + Dispatcher* dispatcher, + ModuleSystem* module_system, + ScriptContext* context) { + module_system->RegisterNativeHandler( + "shell_natives", + scoped_ptr<NativeHandler>(new ShellCustomBindings(context))); +} + +void ShellDispatcherDelegate::PopulateSourceMap( + ResourceBundleSourceMap* source_map) { + source_map->RegisterSource("shell", IDR_SHELL_CUSTOM_BINDINGS_JS); +} + +} // namespace extensions diff --git a/extensions/shell/renderer/shell_dispatcher_delegate.h b/extensions/shell/renderer/shell_dispatcher_delegate.h new file mode 100644 index 0000000..5009ce7 --- /dev/null +++ b/extensions/shell/renderer/shell_dispatcher_delegate.h @@ -0,0 +1,33 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_SHELL_RENDERER_SHELL_DISPATCHER_DELEGATE_H_ +#define EXTENSIONS_SHELL_RENDERER_SHELL_DISPATCHER_DELEGATE_H_ + +#include "base/macros.h" +#include "extensions/renderer/default_dispatcher_delegate.h" + +namespace extensions { + +// app_shell's implementation of DispatcherDelegate. This inherits the behavior +// of the default delegate while augmenting its own script resources and native +// native handlers. +class ShellDispatcherDelegate : public DefaultDispatcherDelegate { + public: + ShellDispatcherDelegate(); + virtual ~ShellDispatcherDelegate(); + + // DispatcherDelegate implementation. + virtual void RegisterNativeHandlers(Dispatcher* dispatcher, + ModuleSystem* module_system, + ScriptContext* context) OVERRIDE; + virtual void PopulateSourceMap(ResourceBundleSourceMap* source_map) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ShellDispatcherDelegate); +}; + +} // namespace extensions + +#endif // EXTENSIONS_SHELL_RENDERER_SHELL_DISPATCHER_DELEGATE_H_ diff --git a/extensions/shell/renderer/shell_extensions_renderer_client.cc b/extensions/shell/renderer/shell_extensions_renderer_client.cc new file mode 100644 index 0000000..c3be350 --- /dev/null +++ b/extensions/shell/renderer/shell_extensions_renderer_client.cc @@ -0,0 +1,27 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/shell/renderer/shell_extensions_renderer_client.h" + +namespace extensions { + +ShellExtensionsRendererClient::ShellExtensionsRendererClient() { +} + +ShellExtensionsRendererClient::~ShellExtensionsRendererClient() { +} + +bool ShellExtensionsRendererClient::IsIncognitoProcess() const { + // app_shell doesn't support off-the-record contexts. + return false; +} + +int ShellExtensionsRendererClient::GetLowestIsolatedWorldId() const { + // app_shell doesn't need to reserve world IDs for anything other than + // extensions, so we always return 1. Note that 0 is reserved for the global + // world. + return 1; +} + +} // namespace extensions diff --git a/extensions/shell/renderer/shell_extensions_renderer_client.h b/extensions/shell/renderer/shell_extensions_renderer_client.h new file mode 100644 index 0000000..1bbe3f4 --- /dev/null +++ b/extensions/shell/renderer/shell_extensions_renderer_client.h @@ -0,0 +1,28 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_SHELL_RENDERER_SHELL_EXTENSIONS_RENDERER_CLIENT_H_ +#define EXTENSIONS_SHELL_RENDERER_SHELL_EXTENSIONS_RENDERER_CLIENT_H_ + +#include "base/macros.h" +#include "extensions/renderer/extensions_renderer_client.h" + +namespace extensions { + +class ShellExtensionsRendererClient : public ExtensionsRendererClient { + public: + ShellExtensionsRendererClient(); + virtual ~ShellExtensionsRendererClient(); + + // ExtensionsRendererClient implementation. + virtual bool IsIncognitoProcess() const OVERRIDE; + virtual int GetLowestIsolatedWorldId() const OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ShellExtensionsRendererClient); +}; + +} // namespace extensions + +#endif // EXTENSIONS_SHELL_RENDERER_SHELL_EXTENSIONS_RENDERER_CLIENT_H_ diff --git a/extensions/shell/renderer/shell_renderer_main_delegate.h b/extensions/shell/renderer/shell_renderer_main_delegate.h new file mode 100644 index 0000000..51396bd --- /dev/null +++ b/extensions/shell/renderer/shell_renderer_main_delegate.h @@ -0,0 +1,30 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_SHELL_RENDERER_SHELL_RENDERER_MAIN_DELEGATE_H_ +#define EXTENSIONS_SHELL_RENDERER_SHELL_RENDERER_MAIN_DELEGATE_H_ + +namespace content { +class RenderThread; +class RenderView; +} + +namespace extensions { + +class ShellRendererMainDelegate { + public: + virtual ~ShellRendererMainDelegate() {} + + // Called when |thread| is started, after the extensions subsystem has been + // initialized for |thread|. + virtual void OnThreadStarted(content::RenderThread* thread) = 0; + + // Called for each RenderView created in the renderer process, after the + // extension related code has been initialized for the view. + virtual void OnViewCreated(content::RenderView* view) = 0; +}; + +} // namespace extensions + +#endif // EXTENSIONS_SHELL_RENDERER_SHELL_RENDERER_MAIN_DELEGATE_H_ |