diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-27 19:35:09 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-27 19:35:09 +0000 |
commit | 81e6378c98d0e69339302527eb1de4735d1e2c3f (patch) | |
tree | d8020f1a2a842b0735c22a35e89a97ec7630bf17 /chrome/renderer | |
parent | 4c8c60ee58cf2f22fcdc0cf3b30f1f5e8884f0ff (diff) | |
download | chromium_src-81e6378c98d0e69339302527eb1de4735d1e2c3f.zip chromium_src-81e6378c98d0e69339302527eb1de4735d1e2c3f.tar.gz chromium_src-81e6378c98d0e69339302527eb1de4735d1e2c3f.tar.bz2 |
Prototype extension process. This is a proof of concept, with a lot of
rough edges. Mostly this just fires up a renderer with an "extension" object
exposed, which right now only has a single method "getTestString".
I also did some misc cleanup along the way.
Review URL: http://codereview.chromium.org/27187
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/dom_ui_bindings.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/dom_ui_bindings.h | 9 | ||||
-rwxr-xr-x | chrome/renderer/extensions/extension_bindings.cc | 19 | ||||
-rwxr-xr-x | chrome/renderer/extensions/extension_bindings.h | 25 | ||||
-rw-r--r-- | chrome/renderer/external_host_bindings.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/external_host_bindings.h | 7 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 36 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 15 | ||||
-rw-r--r-- | chrome/renderer/renderer.scons | 4 | ||||
-rw-r--r-- | chrome/renderer/renderer.vcproj | 12 |
10 files changed, 93 insertions, 44 deletions
diff --git a/chrome/renderer/dom_ui_bindings.cc b/chrome/renderer/dom_ui_bindings.cc index a39cef6..b5558cf7 100644 --- a/chrome/renderer/dom_ui_bindings.cc +++ b/chrome/renderer/dom_ui_bindings.cc @@ -9,14 +9,14 @@ #include "chrome/common/render_messages.h" #include "chrome/common/stl_util-inl.h" -void DOMUIBindings::BindMethods() { - BindMethod("send", &DOMUIBindings::send); -} - DOMBoundBrowserObject::~DOMBoundBrowserObject() { STLDeleteContainerPointers(properties_.begin(), properties_.end()); } +DOMUIBindings::DOMUIBindings() { + BindMethod("send", &DOMUIBindings::send); +} + void DOMUIBindings::send(const CppArgumentList& args, CppVariant* result) { // We expect at least a string message identifier, and optionally take // an object parameter. If we get anything else we bail. diff --git a/chrome/renderer/dom_ui_bindings.h b/chrome/renderer/dom_ui_bindings.h index d5a18ed..75b1385 100644 --- a/chrome/renderer/dom_ui_bindings.h +++ b/chrome/renderer/dom_ui_bindings.h @@ -15,10 +15,6 @@ class DOMBoundBrowserObject : public CppBoundClass { public: DOMBoundBrowserObject() : routing_id_(0) { } virtual ~DOMBoundBrowserObject(); - - // Different for each subclass; associates the javascript object with any - // number of methods. - virtual void BindMethods() = 0; // Set the message channel back to the browser. void set_message_sender(IPC::Message::Sender* sender) { @@ -59,12 +55,9 @@ class DOMBoundBrowserObject : public CppBoundClass { // delegate. class DOMUIBindings : public DOMBoundBrowserObject { public: - DOMUIBindings() { BindMethods(); } + DOMUIBindings(); virtual ~DOMUIBindings() {} - // DOMBoundBrowserObject implementation. - virtual void BindMethods(); - // The send() function provided to Javascript. void send(const CppArgumentList& args, CppVariant* result); private: diff --git a/chrome/renderer/extensions/extension_bindings.cc b/chrome/renderer/extensions/extension_bindings.cc new file mode 100755 index 0000000..24c66d3 --- /dev/null +++ b/chrome/renderer/extensions/extension_bindings.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2006-2008 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 "chrome/renderer/extensions/extension_bindings.h" + +#include "base/values.h" +#include "chrome/common/render_messages.h" + +#define BIND_METHOD(name) BindMethod(#name, &ExtensionBindings::name) +ExtensionBindings::ExtensionBindings() { + BIND_METHOD(getTestString); +} +#undef BIND_METHOD + +void ExtensionBindings::getTestString( + const CppArgumentList& args, CppVariant* result) { + result->Set("This is a placeholder string. It's here to hold places."); +} diff --git a/chrome/renderer/extensions/extension_bindings.h b/chrome/renderer/extensions/extension_bindings.h new file mode 100755 index 0000000..a4b86cc --- /dev/null +++ b/chrome/renderer/extensions/extension_bindings.h @@ -0,0 +1,25 @@ +// Copyright (c) 2006-2008 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 CHROME_RENDERER_EXTENSIONS_EXTENSION_BINDINGS_H__ +#define CHROME_RENDERER_EXTENSIONS_EXTENSION_BINDINGS_H__ + +#include "chrome/common/ipc_message.h" +#include "chrome/renderer/dom_ui_bindings.h" + +// ExtensionBindings is the class backing the "extension" object +// accessible from JavaScript. +class ExtensionBindings : public DOMBoundBrowserObject { + public: + ExtensionBindings(); + virtual ~ExtensionBindings() {} + + // Methods exposed to JavaScript. + void getTestString(const CppArgumentList& args, CppVariant* result); + + private: + DISALLOW_COPY_AND_ASSIGN(ExtensionBindings); +}; + +#endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_BINDINGS_H__ diff --git a/chrome/renderer/external_host_bindings.cc b/chrome/renderer/external_host_bindings.cc index 0f0ad92..4ac3b67 100644 --- a/chrome/renderer/external_host_bindings.cc +++ b/chrome/renderer/external_host_bindings.cc @@ -7,7 +7,7 @@ #include "base/values.h" #include "chrome/common/render_messages.h" -void ExternalHostBindings::BindMethods() { +ExternalHostBindings::ExternalHostBindings() { BindMethod("ForwardMessageToExternalHost", &ExternalHostBindings::ForwardMessageToExternalHost); } diff --git a/chrome/renderer/external_host_bindings.h b/chrome/renderer/external_host_bindings.h index 2160bbc..fdec590 100644 --- a/chrome/renderer/external_host_bindings.h +++ b/chrome/renderer/external_host_bindings.h @@ -6,7 +6,7 @@ #define CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_ #include "chrome/common/ipc_message.h" -#include "dom_ui_bindings.h" +#include "chrome/renderer/dom_ui_bindings.h" // ExternalHostBindings is the class backing the "externalHost" object // accessible from Javascript @@ -15,12 +15,9 @@ // ForwardMessageToExternalHost(String receiver, String message); class ExternalHostBindings : public DOMBoundBrowserObject { public: - ExternalHostBindings() { BindMethods(); } + ExternalHostBindings(); virtual ~ExternalHostBindings() {}; - // DOMBoundBrowserObject implementation. - virtual void BindMethods(); - // The ForwardMessageToExternalHost() function provided to Javascript. void ForwardMessageToExternalHost(const CppArgumentList& args, CppVariant* result); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 91efbf4..043a2b9 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -14,6 +14,7 @@ #include "base/string_piece.h" #include "base/string_util.h" #include "build/build_config.h" +#include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/gfx/favicon_size.h" #include "chrome/common/gfx/color_utils.h" @@ -158,9 +159,7 @@ class RenderViewExtraRequestData : public WebRequest::ExtraData { RenderView::RenderView(RenderThreadBase* render_thread) : RenderWidget(render_thread, true), - enable_dom_automation_(false), - enable_dom_ui_bindings_(false), - enable_external_host_bindings_(false), + enabled_bindings_(0), target_url_status_(TARGET_NONE), is_loading_(false), navigation_gesture_(NavigationGestureUnknown), @@ -312,8 +311,8 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd, modal_dialog_event_.reset(modal_dialog_event); const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - enable_dom_automation_ = - command_line.HasSwitch(switches::kDomAutomationController); + if (command_line.HasSwitch(switches::kDomAutomationController)) + enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; disable_popup_blocking_ = command_line.HasSwitch(switches::kDisablePopupBlocking); @@ -382,8 +381,6 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) - IPC_MESSAGE_HANDLER(ViewMsg_AllowDomAutomationBindings, - OnAllowDomAutomationBindings) IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, @@ -1531,18 +1528,23 @@ void RenderView::BindDOMAutomationController(WebFrame* webframe) { void RenderView::WindowObjectCleared(WebFrame* webframe) { external_js_object_.set_render_view(this); external_js_object_.BindToJavascript(webframe, L"external"); - if (enable_dom_automation_) + if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) BindDOMAutomationController(webframe); - if (enable_dom_ui_bindings_) { + if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) { dom_ui_bindings_.set_message_sender(this); dom_ui_bindings_.set_routing_id(routing_id_); dom_ui_bindings_.BindToJavascript(webframe, L"chrome"); } - if (enable_external_host_bindings_) { + if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { external_host_bindings_.set_message_sender(this); external_host_bindings_.set_routing_id(routing_id_); external_host_bindings_.BindToJavascript(webframe, L"externalHost"); } + if (BindingsPolicy::is_extension_enabled(enabled_bindings_)) { + extension_bindings_.set_message_sender(this); + extension_bindings_.set_routing_id(routing_id_); + extension_bindings_.BindToJavascript(webframe, L"extension"); + } #ifdef CHROME_PERSONALIZATION Personalization::ConfigureRendererPersonalization(personalization_, this, @@ -1578,7 +1580,7 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction( if (frame == webview->GetMainFrame() && !request->GetExtraData()) { // When we received such unsolicited navigations, we sometimes want to // punt them up to the browser to handle. - if (enable_dom_ui_bindings_ || + if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || frame->GetInViewSourceMode() || url.SchemeIs(chrome::kViewSourceScheme)) { OpenURL(webview, url, GURL(), disposition); @@ -2529,19 +2531,13 @@ void RenderView::OnDebugAttach() { NOTIMPLEMENTED(); } void RenderView::OnDebugDetach() { NOTIMPLEMENTED(); } #endif -void RenderView::OnAllowDomAutomationBindings(bool allow_bindings) { - enable_dom_automation_ = allow_bindings; -} - -void RenderView::OnAllowBindings(bool enable_dom_ui_bindings, - bool enable_external_host_bindings) { - enable_dom_ui_bindings_ = enable_dom_ui_bindings; - enable_external_host_bindings_ = enable_external_host_bindings; +void RenderView::OnAllowBindings(int enabled_bindings_flags) { + enabled_bindings_ |= enabled_bindings_flags; } void RenderView::OnSetDOMUIProperty(const std::string& name, const std::string& value) { - DCHECK(enable_dom_ui_bindings_); + DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); dom_ui_bindings_.SetProperty(name, value); } diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index b4a39bb..1f7dce0 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -23,6 +23,7 @@ #include "chrome/renderer/automation/dom_automation_controller.h" #include "chrome/renderer/dom_ui_bindings.h" #include "chrome/renderer/external_host_bindings.h" +#include "chrome/renderer/extensions/extension_bindings.h" #include "chrome/renderer/external_js_object.h" #include "chrome/renderer/render_widget.h" #include "media/audio/audio_output.h" @@ -483,9 +484,7 @@ class RenderView : public RenderWidget, void OnDragTargetDragLeave(); void OnDragTargetDrop(const gfx::Point& client_pt, const gfx::Point& screen_pt); - void OnAllowDomAutomationBindings(bool allow_binding); - void OnAllowBindings(bool enable_dom_ui_bindings, - bool enable_external_host_bindings); + void OnAllowBindings(int enabled_bindings_flags); void OnSetDOMUIProperty(const std::string& name, const std::string& value); void OnSetInitialFocus(bool reverse); void OnUpdateWebPreferences(const WebPreferences& prefs); @@ -624,12 +623,14 @@ class RenderView : public RenderWidget, // Handles resource loads for this view. scoped_refptr<ResourceDispatcher> resource_dispatcher_; + // Bitwise-ORed set of extra bindings that have been enabled. See + // BindingsPolicy for details. + int enabled_bindings_; + // DOM Automation Controller CppBoundClass. - bool enable_dom_automation_; DomAutomationController dom_automation_controller_; // Chrome page<->browser messaging CppBoundClass. - bool enable_dom_ui_bindings_; DOMUIBindings dom_ui_bindings_; #ifdef CHROME_PERSONALIZATION @@ -640,9 +641,11 @@ class RenderView : public RenderWidget, ExternalJSObject external_js_object_; // External host exposed through automation controller. - bool enable_external_host_bindings_; ExternalHostBindings external_host_bindings_; + // Extension bindings exposed for script running in the extension process. + ExtensionBindings extension_bindings_; + // The last gotten main frame's encoding. std::wstring last_encoding_name_; diff --git a/chrome/renderer/renderer.scons b/chrome/renderer/renderer.scons index e280cb8..81da02e 100644 --- a/chrome/renderer/renderer.scons +++ b/chrome/renderer/renderer.scons @@ -60,6 +60,10 @@ input_files = ChromeFileList([ 'net/render_dns_queue.cc', 'net/render_dns_queue.h', ]), + MSVSFilter('extensions', [ + 'extensions/extension_bindings.cc', + 'extensions/extension_bindings.h', + ]), 'about_handler.cc', 'about_handler.h', 'chrome_plugin_host.cc', diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj index 4879a93..908f55d 100644 --- a/chrome/renderer/renderer.vcproj +++ b/chrome/renderer/renderer.vcproj @@ -181,6 +181,18 @@ > </File> </Filter> + <Filter + Name="extensions" + > + <File + RelativePath=".\extensions\extension_bindings.cc" + > + </File> + <File + RelativePath=".\extensions\extension_bindings.h" + > + </File> + </Filter> <File RelativePath=".\about_handler.cc" > |