summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 19:35:09 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 19:35:09 +0000
commit81e6378c98d0e69339302527eb1de4735d1e2c3f (patch)
treed8020f1a2a842b0735c22a35e89a97ec7630bf17
parent4c8c60ee58cf2f22fcdc0cf3b30f1f5e8884f0ff (diff)
downloadchromium_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
-rw-r--r--chrome/browser/browser.scons2
-rw-r--r--chrome/browser/browser.vcproj8
-rwxr-xr-xchrome/browser/extensions/extension_view.cc32
-rwxr-xr-xchrome/browser/extensions/extension_view.h46
-rwxr-xr-xchrome/browser/extensions/extension_view_unittest.cc108
-rw-r--r--chrome/browser/extensions/extensions_service.cc15
-rw-r--r--chrome/browser/extensions/extensions_service.h11
-rw-r--r--chrome/browser/profile.cc3
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc25
-rw-r--r--chrome/browser/renderer_host/render_view_host.h16
-rw-r--r--chrome/browser/tab_contents/interstitial_page.cc2
-rw-r--r--chrome/browser/views/hwnd_html_view.cc9
-rw-r--r--chrome/browser/views/hwnd_html_view.h14
-rw-r--r--chrome/chrome.gyp5
-rw-r--r--chrome/chrome.xcodeproj/project.pbxproj14
-rwxr-xr-xchrome/common/bindings_policy.h42
-rw-r--r--chrome/common/common.scons1
-rw-r--r--chrome/common/common.vcproj4
-rw-r--r--chrome/common/render_messages_internal.h18
-rw-r--r--chrome/common/temp_scaffolding_stubs.h16
-rw-r--r--chrome/renderer/dom_ui_bindings.cc8
-rw-r--r--chrome/renderer/dom_ui_bindings.h9
-rwxr-xr-xchrome/renderer/extensions/extension_bindings.cc19
-rwxr-xr-xchrome/renderer/extensions/extension_bindings.h25
-rw-r--r--chrome/renderer/external_host_bindings.cc2
-rw-r--r--chrome/renderer/external_host_bindings.h7
-rw-r--r--chrome/renderer/render_view.cc36
-rw-r--r--chrome/renderer/render_view.h15
-rw-r--r--chrome/renderer/renderer.scons4
-rw-r--r--chrome/renderer/renderer.vcproj12
-rw-r--r--chrome/test/data/extensions/good/extension1/1/index.html5
-rw-r--r--chrome/test/unit/unittests.vcproj4
32 files changed, 452 insertions, 85 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index 7e94112..ea53d85 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -506,6 +506,8 @@ input_files = ChromeFileList([
MSVSFilter('Extensions', [
'extensions/extension.cc',
'extensions/extension.h',
+ 'extensions/extension_view.cc',
+ 'extensions/extension_view.h',
'extensions/extension_error_reporter.cc',
'extensions/extension_error_reporter.h',
'extensions/extension_protocols.h',
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index e5995c1..6f1a886 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -1922,6 +1922,14 @@
>
</File>
<File
+ RelativePath=".\extensions\extension_view.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\extensions\extension_view.h"
+ >
+ </File>
+ <File
RelativePath=".\extensions\extensions_service.cc"
>
</File>
diff --git a/chrome/browser/extensions/extension_view.cc b/chrome/browser/extensions/extension_view.cc
new file mode 100755
index 0000000..1647ecb
--- /dev/null
+++ b/chrome/browser/extensions/extension_view.cc
@@ -0,0 +1,32 @@
+// Copyright (c) 2006-2009 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/browser/extensions/extension_view.h"
+
+#include "chrome/browser/renderer_host/render_view_host.h"
+
+ExtensionView::ExtensionView(const GURL& url, Profile* profile) :
+ HWNDHtmlView(url, this, false), profile_(profile) {
+}
+
+void ExtensionView::CreatingRenderer() {
+ render_view_host()->AllowExtensionBindings();
+}
+
+WebPreferences ExtensionView::GetWebkitPrefs() {
+ // TODO(mpcomplete): return some reasonable prefs.
+ return WebPreferences();
+}
+
+void ExtensionView::RunJavaScriptMessage(
+ const std::wstring& message,
+ const std::wstring& default_prompt,
+ const int flags,
+ IPC::Message* reply_msg,
+ bool* did_suppress_message) {
+ // Automatically cancel the javascript alert (otherwise the renderer hangs
+ // indefinitely).
+ *did_suppress_message = true;
+ render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L"");
+}
diff --git a/chrome/browser/extensions/extension_view.h b/chrome/browser/extensions/extension_view.h
new file mode 100755
index 0000000..5eb869c
--- /dev/null
+++ b/chrome/browser/extensions/extension_view.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2006-2009 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_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_
+
+#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+
+// TODO(port): Port these files.
+#if defined(OS_WIN)
+#include "chrome/browser/views/hwnd_html_view.h"
+#else
+#include "chrome/common/temp_scaffolding_stubs.h"
+#endif
+
+class Profile;
+struct WebPreferences;
+
+// This class is the browser component of an extension component's RenderView.
+// It handles setting up the renderer process, if needed, with special
+// priviliges available to extensions. The view may be drawn to the screen or
+// hidden.
+class ExtensionView : public HWNDHtmlView,
+ public RenderViewHostDelegate {
+ public:
+ ExtensionView(const GURL& url, Profile* profile);
+
+ // HWNDHtmlView
+ virtual void CreatingRenderer();
+
+ // RenderViewHostDelegate
+ virtual Profile* GetProfile() const { return profile_; }
+ virtual WebPreferences GetWebkitPrefs();
+ virtual void RunJavaScriptMessage(
+ const std::wstring& message,
+ const std::wstring& default_prompt,
+ const int flags,
+ IPC::Message* reply_msg,
+ bool* did_suppress_message);
+
+ private:
+ Profile* profile_;
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc
new file mode 100755
index 0000000..930b068
--- /dev/null
+++ b/chrome/browser/extensions/extension_view_unittest.cc
@@ -0,0 +1,108 @@
+// 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 "base/message_loop.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/extensions/extension_view.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace {
+
+// How long to wait for the extension to put up a javascript alert before giving
+// up.
+const int kAlertTimeoutMs = 10000;
+
+// The extension we're using as our test case.
+const char* kExtensionId = "com.google.myextension1";
+
+// This class starts up an extension process and waits until it tries to put
+// up a javascript alert.
+class MockExtensionView : public ExtensionView {
+ public:
+ MockExtensionView(const GURL& url, Profile* profile)
+ : ExtensionView(url, profile), got_message_(false) {
+ InitHidden();
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ new MessageLoop::QuitTask, kAlertTimeoutMs);
+ ui_test_utils::RunMessageLoop();
+ }
+
+ bool got_message() { return got_message_; }
+ private:
+ virtual void RunJavaScriptMessage(
+ const std::wstring& message,
+ const std::wstring& default_prompt,
+ const int flags,
+ IPC::Message* reply_msg,
+ bool* did_suppress_message) {
+ got_message_ = true;
+ MessageLoopForUI::current()->Quit();
+ }
+
+ bool got_message_;
+};
+
+// This class waits for a specific extension to be loaded.
+class ExtensionLoadedObserver : public NotificationObserver {
+ public:
+ explicit ExtensionLoadedObserver() : extension_(NULL) {
+ registrar_.Add(this, NotificationType::EXTENSIONS_LOADED,
+ NotificationService::AllSources());
+ ui_test_utils::RunMessageLoop();
+ }
+
+ Extension* extension() { return extension_; }
+ private:
+ virtual void Observe(NotificationType type, const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::EXTENSIONS_LOADED) {
+ ExtensionList* extensions = Details<ExtensionList>(details).ptr();
+ for (size_t i = 0; i < (*extensions).size(); i++) {
+ if ((*extensions)[i]->id() == kExtensionId) {
+ extension_ = (*extensions)[i];
+ MessageLoopForUI::current()->Quit();
+ break;
+ }
+ }
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ NotificationRegistrar registrar_;
+ Extension* extension_;
+};
+
+} // namespace
+
+class ExtensionViewTest : public InProcessBrowserTest {
+};
+
+IN_PROC_BROWSER_TEST_F(ExtensionViewTest, TestMe) {
+ // Get the path to our extension.
+ FilePath path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
+ path = path.AppendASCII("extensions").
+ AppendASCII("good").AppendASCII("extension1").AppendASCII("1");
+
+ // Load it.
+ Profile* profile = browser()->profile();
+ profile->GetExtensionsService()->Init();
+ profile->GetExtensionsService()->LoadExtension(path);
+
+ // Now wait for it to load, and grab a pointer to it.
+ Extension* extension = ExtensionLoadedObserver().extension();
+ ASSERT_TRUE(extension);
+ GURL url = Extension::GetResourceURL(extension->url(), "index.html");
+
+ // Start the extension process and wait for it to show a javascript alert.
+ MockExtensionView view(url, profile);
+ EXPECT_TRUE(view.got_message());
+}
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 9fc0040..3271920 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -16,7 +16,9 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
#include "chrome/browser/extensions/user_script_master.h"
+#include "chrome/browser/extensions/extension_view.h"
#include "chrome/browser/plugin_service.h"
+#include "chrome/browser/profile.h"
#include "chrome/common/json_value_serializer.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/unzip.h"
@@ -63,12 +65,12 @@ const wchar_t kRegistryExtensionVersion[] = L"version";
const char kExternalInstallFile[] = "EXTERNAL_INSTALL";
}
-
-ExtensionsService::ExtensionsService(const FilePath& profile_directory,
+ExtensionsService::ExtensionsService(Profile* profile,
UserScriptMaster* user_script_master)
: message_loop_(MessageLoop::current()),
backend_(new ExtensionsServiceBackend),
- install_directory_(profile_directory.AppendASCII(kInstallDirectoryName)),
+ install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)),
+ profile_(profile),
user_script_master_(user_script_master) {
}
@@ -104,6 +106,13 @@ bool ExtensionsService::Init() {
return true;
}
+void ExtensionsService::LaunchExtensionProcess(Extension* extension) {
+ // TODO(mpcomplete): Do something useful here.
+ GURL url = Extension::GetResourceURL(extension->url(), "index.html");
+ ExtensionView* view = new ExtensionView(url, profile_);
+ view->InitHidden();
+}
+
MessageLoop* ExtensionsService::GetMessageLoop() {
return message_loop_;
}
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index efba0086..7489de7 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -16,6 +16,7 @@
typedef std::vector<Extension*> ExtensionList;
class ExtensionsServiceBackend;
+class Profile;
class UserScriptMaster;
// Interface for the frontend to implement. Typically, this will be
@@ -51,8 +52,7 @@ class ExtensionsServiceFrontendInterface
// Manages installed and running Chromium extensions.
class ExtensionsService : public ExtensionsServiceFrontendInterface {
public:
- ExtensionsService(const FilePath& profile_directory,
- UserScriptMaster* user_script_master);
+ ExtensionsService(Profile* profile, UserScriptMaster* user_script_master);
~ExtensionsService();
// Gets the list of currently installed extensions.
@@ -63,6 +63,10 @@ class ExtensionsService : public ExtensionsServiceFrontendInterface {
// Initialize and start all installed extensions.
bool Init();
+ // Start the extension process for this extension. TODO(mpcomplete): not sure
+ // how this should actually work yet.
+ void LaunchExtensionProcess(Extension* extension);
+
// ExtensionsServiceFrontendInterface
virtual MessageLoop* GetMessageLoop();
virtual void InstallExtension(const FilePath& extension_path);
@@ -90,6 +94,9 @@ class ExtensionsService : public ExtensionsServiceFrontendInterface {
// The full path to the directory where extensions are installed.
FilePath install_directory_;
+ // The profile associated with this set of extensions.
+ Profile* profile_;
+
// The user script master for this profile.
scoped_refptr<UserScriptMaster> user_script_master_;
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 9600c6c..7c7041e 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -371,8 +371,7 @@ void ProfileImpl::InitExtensions() {
ExtensionErrorReporter::Init(true); // allow noisy errors.
user_script_master_ = new UserScriptMaster(
g_browser_process->file_thread()->message_loop(), script_dir);
- extensions_service_ = new ExtensionsService(
- FilePath(GetPath()), user_script_master_.get());
+ extensions_service_ = new ExtensionsService(this, user_script_master_.get());
// If we have extensions, the extension service will kick off the first scan
// after extensions are loaded. Otherwise, we need to do that now.
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 894e02a..3da3fef 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/site_instance.h"
#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/common/bindings_policy.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/notification_service.h"
@@ -88,9 +89,8 @@ RenderViewHost::RenderViewHost(SiteInstance* instance,
renderer_initialized_(false),
waiting_for_drag_context_response_(false),
debugger_attached_(false),
- enable_dom_ui_bindings_(false),
+ enabled_bindings_(0),
pending_request_id_(0),
- enable_external_host_bindings_(false),
modal_dialog_count_(0),
navigations_suspended_(false),
suspended_nav_message_(NULL),
@@ -178,8 +178,7 @@ bool RenderViewHost::CreateRenderView() {
// If it's enabled, tell the renderer to set up the Javascript bindings for
// sending messages back to the browser.
- Send(new ViewMsg_AllowBindings(
- routing_id(), enable_dom_ui_bindings_, enable_external_host_bindings_));
+ Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_));
// Let our delegate know that we created a RenderView.
delegate_->RenderViewCreated(this);
@@ -574,24 +573,30 @@ void RenderViewHost::DragSourceSystemDragEnded() {
}
void RenderViewHost::AllowDomAutomationBindings() {
- // Expose the binding that allows the DOM to send messages here.
- Send(new ViewMsg_AllowDomAutomationBindings(routing_id(), true));
+ DCHECK(!renderer_initialized_);
+ enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
+}
+
+void RenderViewHost::AllowExternalHostBindings() {
+ DCHECK(!renderer_initialized_);
+ enabled_bindings_ |= BindingsPolicy::EXTERNAL_HOST;
}
void RenderViewHost::AllowDOMUIBindings() {
DCHECK(!renderer_initialized_);
- enable_dom_ui_bindings_ = true;
+ enabled_bindings_ |= BindingsPolicy::DOM_UI;
RendererSecurityPolicy::GetInstance()->GrantDOMUIBindings(
process()->host_id());
}
-void RenderViewHost::AllowExternalHostBindings() {
- enable_external_host_bindings_ = true;
+void RenderViewHost::AllowExtensionBindings() {
+ DCHECK(!renderer_initialized_);
+ enabled_bindings_ |= BindingsPolicy::EXTENSION;
}
void RenderViewHost::SetDOMUIProperty(const std::string& name,
const std::string& value) {
- DCHECK(enable_dom_ui_bindings_);
+ DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
Send(new ViewMsg_SetDOMUIProperty(routing_id(), name, value));
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 7a0a8148..79c9ca6 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -308,10 +308,12 @@ class RenderViewHost : public RenderWidgetHost {
// Tell the render view to expose DOM automation bindings so that the js
// content can send JSON-encoded data back to automation in the parent
// process.
+ // Must be called before CreateRenderView().
void AllowDomAutomationBindings();
// Tell the render view to allow the javascript access to
// the external host via automation.
+ // Must be called before CreateRenderView().
void AllowExternalHostBindings();
// Tell the render view to expose DOM bindings so that the JS content
@@ -320,6 +322,10 @@ class RenderViewHost : public RenderWidgetHost {
// Must be called before CreateRenderView().
void AllowDOMUIBindings();
+ // Tell the render view to expose privileged bindings for use by extensions.
+ // Must be called before CreateRenderView().
+ void AllowExtensionBindings();
+
// Tells the renderer which render view should be inspected by developer
// tools loaded in it. This method should be called before renderer is
// created.
@@ -574,9 +580,9 @@ class RenderViewHost : public RenderWidgetHost {
// is the debugger attached to us or not
bool debugger_attached_;
- // True if we've been told to set up the the Javascript bindings for
- // sending messages back to the browser.
- bool enable_dom_ui_bindings_;
+ // A bitwise OR of bindings types that have been enabled for this RenderView.
+ // See BindingsPolicy for details.
+ int enabled_bindings_;
// The request_id for the pending cross-site request. Set to -1 if
// there is a pending request, but we have not yet started the unload
@@ -585,10 +591,6 @@ class RenderViewHost : public RenderWidgetHost {
// and thus started the unload process.
int pending_request_id_;
- // True if javascript access to the external host (through
- // automation) is allowed.
- bool enable_external_host_bindings_;
-
// Handle to an event that's set when the page is showing a modal dialog box
// (or equivalent constrained window). The renderer and plugin processes
// check this to know if they should pump messages/tasks then.
diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc
index 9781a0e..688c6f1 100644
--- a/chrome/browser/tab_contents/interstitial_page.cc
+++ b/chrome/browser/tab_contents/interstitial_page.cc
@@ -256,11 +256,11 @@ RenderViewHost* InterstitialPage::CreateRenderViewHost() {
view->set_parent_hwnd(tab_->GetContentNativeView());
WebContentsViewWin* web_contents_view =
static_cast<WebContentsViewWin*>(tab_->view());
+ render_view_host->AllowDomAutomationBindings();
render_view_host->CreateRenderView();
// SetSize must be called after CreateRenderView or the HWND won't show.
view->SetSize(web_contents_view->GetContainerSize());
- render_view_host->AllowDomAutomationBindings();
return render_view_host;
#else
// TODO(port): RenderWidgetHost* is implemented, but Create and
diff --git a/chrome/browser/views/hwnd_html_view.cc b/chrome/browser/views/hwnd_html_view.cc
index 7b7fbfc..000d92b 100644
--- a/chrome/browser/views/hwnd_html_view.cc
+++ b/chrome/browser/views/hwnd_html_view.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/site_instance.h"
#include "chrome/views/widget.h"
+#include "chrome/views/widget_win.h"
HWNDHtmlView::~HWNDHtmlView() {
if (render_view_host_) {
@@ -18,6 +19,13 @@ HWNDHtmlView::~HWNDHtmlView() {
}
}
+void HWNDHtmlView::InitHidden() {
+ // TODO(mpcomplete): make it possible to create a RenderView without an HWND.
+ views::WidgetWin* win = new views::WidgetWin;
+ win->Init(NULL, gfx::Rect(), true);
+ win->SetContentsView(this);
+}
+
void HWNDHtmlView::Init(HWND parent_hwnd) {
DCHECK(!render_view_host_) << "Already initialized.";
RenderViewHost* rvh = new RenderViewHost(
@@ -40,6 +48,7 @@ void HWNDHtmlView::Init(HWND parent_hwnd) {
// Start up the renderer.
if (allow_dom_ui_bindings_)
rvh->AllowDOMUIBindings();
+ CreatingRenderer();
rvh->CreateRenderView();
rvh->NavigateToURL(content_url_);
initialized_ = true;
diff --git a/chrome/browser/views/hwnd_html_view.h b/chrome/browser/views/hwnd_html_view.h
index 4405f2a..67952a2 100644
--- a/chrome/browser/views/hwnd_html_view.h
+++ b/chrome/browser/views/hwnd_html_view.h
@@ -28,14 +28,22 @@ class HWNDHtmlView : public views::HWNDView {
RenderViewHost* render_view_host() { return render_view_host_; }
+ // Initialize the view without a parent window. Used for extensions that
+ // don't display UI.
+ void InitHidden();
+
protected:
- // View overrides.
- virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
+ // View overrides.
+ virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
+
+ // Called just before we create the RenderView, to give subclasses an
+ // opportunity to do some setup.
+ virtual void CreatingRenderer() {}
private:
// Initialize the view, parented to |parent|, and show it.
void Init(HWND parent);
-
+
// The URL of the HTML content to render and show in this view.
GURL content_url_;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 32c8e74..5313a3f 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -125,6 +125,7 @@
'common/accessibility.h',
'common/animation.cc',
'common/animation.h',
+ 'common/bindings_policy.h',
'common/child_process.cc',
'common/child_process.h',
'common/child_process_host.cc',
@@ -467,6 +468,8 @@
'browser/download/save_types.h',
'browser/extensions/extension.cc',
'browser/extensions/extension.h',
+ 'browser/extensions/extension_view.cc',
+ 'browser/extensions/extension_view.h',
'browser/extensions/extension_protocols.cc',
'browser/extensions/extension_protocols.h',
'browser/extensions/extensions_service.cc',
@@ -1245,6 +1248,8 @@
'renderer/dev_tools_messages_internal.h',
'renderer/dom_ui_bindings.cc',
'renderer/dom_ui_bindings.h',
+ 'renderer/extension_bindings.cc',
+ 'renderer/extension_bindings.h',
'renderer/external_host_bindings.cc',
'renderer/external_host_bindings.h',
'renderer/external_js_object.cc',
diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj
index 7b958a3..3d3fa1a 100644
--- a/chrome/chrome.xcodeproj/project.pbxproj
+++ b/chrome/chrome.xcodeproj/project.pbxproj
@@ -318,6 +318,7 @@
8CB218DCFAC761AC876C6531 /* ssl_blocking_page.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D16ECB0F21451600861FAC /* ssl_blocking_page.cc */; };
8F51B73AAAF1772ECF9BD180 /* url_fetcher.cc in Sources */ = {isa = PBXBuildFile; fileRef = 778D7927798B7E3FAA498D3D /* url_fetcher.cc */; };
9084D27A4F8690E6FD31083B /* session_backend.cc in Sources */ = {isa = PBXBuildFile; fileRef = 35AC9D9A03545594C102C5C1 /* session_backend.cc */; };
+ 9258B3C905B9E261667F7E0B /* extension_bindings.cc in Sources */ = {isa = PBXBuildFile; fileRef = A4457D7F38B3E87FD6F0812A /* extension_bindings.cc */; };
928300674E414B42615BA4F0 /* download_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF9CE0E9D48CE009A6919 /* download_manager.cc */; };
938D10370F57401C009F1128 /* renderer_webkitclient_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 938D10350F57401C009F1128 /* renderer_webkitclient_impl.cc */; };
93FB3ECE0F55E38400AA1185 /* libwebkit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BD53D90F54AB4300591DFA /* libwebkit.a */; };
@@ -683,6 +684,7 @@
F47CA12A0F44AE3500FFFAFB /* libwtf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 826850240F2FC82E009F6555 /* libwtf.a */; };
F58A0570E84AA76543E0C5CA /* bookmark_drag_data.cc in Sources */ = {isa = PBXBuildFile; fileRef = E7FDE61828F151056D975855 /* bookmark_drag_data.cc */; };
F775995035B63E51251B0922 /* ssl_error_info.cc in Sources */ = {isa = PBXBuildFile; fileRef = 26D97CE692D919FEB1521E43 /* ssl_error_info.cc */; };
+ F7DA1699176A4C039D5D10D0 /* extension_view.cc in Sources */ = {isa = PBXBuildFile; fileRef = 75388283AD5D97375B14859E /* extension_view.cc */; };
F8C26A3BB7CC2029E53889AB /* automation_provider_list.cc in Sources */ = {isa = PBXBuildFile; fileRef = E48FB9660EC4EA270052B72B /* automation_provider_list.cc */; };
F958714A0B14B028646CF087 /* save_package.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF9DA0E9D48CE009A6919 /* save_package.cc */; };
/* End PBXBuildFile section */
@@ -1942,6 +1944,7 @@
0114EE7E1097BDFBF94057E6 /* search_provider.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = search_provider.cc; path = browser/autocomplete/search_provider.cc; sourceTree = SOURCE_ROOT; };
05C9D404FC8116984CCCEDED /* base_session_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = base_session_service.cc; path = sessions/base_session_service.cc; sourceTree = "<group>"; };
07FE4EE1A3A0636A63757967 /* dev_tools_agent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dev_tools_agent.h; sourceTree = "<group>"; };
+ 0B470D4BA5E89469583CB80C /* bindings_policy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bindings_policy.h; sourceTree = "<group>"; };
0B7CC9C105E90E0665852528 /* url_fetcher_protect.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = url_fetcher_protect.cc; sourceTree = "<group>"; };
0DF4243691A34E9B11373400 /* dev_tools_messages_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dev_tools_messages_internal.h; sourceTree = "<group>"; };
12F137DA942221A44BFA0967 /* bookmark_drop_info.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bookmark_drop_info.cc; path = browser/bookmarks/bookmark_drop_info.cc; sourceTree = SOURCE_ROOT; };
@@ -1960,6 +1963,7 @@
3C56D1B8B7580A18DB8FE677 /* ssl_host_state.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ssl_host_state.h; path = ssl/ssl_host_state.h; sourceTree = "<group>"; };
3CCF8AA8A56FF8FE59F0C299 /* template_url.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = template_url.cc; sourceTree = "<group>"; };
3D00CDB6C665E7ED1A1090D7 /* bookmark_model.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bookmark_model.cc; path = bookmarks/bookmark_model.cc; sourceTree = "<group>"; };
+ 408A60BCB981BCA94219A0C7 /* extension_bindings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = extension_bindings.h; path = renderer/extensions/extension_bindings.h; sourceTree = SOURCE_ROOT; };
433B6EFB7A1D931A13C9556F /* url_fetcher_protect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = url_fetcher_protect.h; sourceTree = "<group>"; };
4590B61B84978823B2BADA68 /* file_descriptor_set_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_descriptor_set_posix.cc; sourceTree = "<group>"; };
4AF0AB80CD8E1D34AC0D5C51 /* v8_unit_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = v8_unit_test.h; sourceTree = "<group>"; };
@@ -2525,6 +2529,7 @@
6447F24FADC63E58A44DB762 /* url_pattern.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = url_pattern.cc; path = extensions/url_pattern.cc; sourceTree = "<group>"; };
68948A0302AADFF9A8419E28 /* extension_error_reporter.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extension_error_reporter.cc; sourceTree = "<group>"; };
699499C4FBA07FB2D7B298A2 /* user_script.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = user_script.cc; path = extensions/user_script.cc; sourceTree = "<group>"; };
+ 75388283AD5D97375B14859E /* extension_view.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extension_view.cc; sourceTree = "<group>"; };
759B3A1B81E261598122B03B /* v8_unit_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = v8_unit_test.cc; sourceTree = "<group>"; };
778D7927798B7E3FAA498D3D /* url_fetcher.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = url_fetcher.cc; sourceTree = "<group>"; };
7849CCC221723C1BC14D6384 /* history_publisher_none.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = history_publisher_none.cc; sourceTree = "<group>"; };
@@ -2571,6 +2576,7 @@
938D10350F57401C009F1128 /* renderer_webkitclient_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = renderer_webkitclient_impl.cc; sourceTree = "<group>"; };
938D10360F57401C009F1128 /* renderer_webkitclient_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = renderer_webkitclient_impl.h; sourceTree = "<group>"; };
A2FC5EE73E0DE8BF6C1C4C0F /* bookmark_utils.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bookmark_utils.cc; path = browser/bookmarks/bookmark_utils.cc; sourceTree = SOURCE_ROOT; };
+ A4457D7F38B3E87FD6F0812A /* extension_bindings.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = extension_bindings.cc; path = renderer/extensions/extension_bindings.cc; sourceTree = SOURCE_ROOT; };
A54612D90EE9957000A8EE5D /* extensions_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extensions_service.cc; sourceTree = "<group>"; };
A54612DA0EE9957000A8EE5D /* extensions_service.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = extensions_service.h; sourceTree = "<group>"; };
A54612DB0EE9958600A8EE5D /* extensions_service_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extensions_service_unittest.cc; sourceTree = "<group>"; };
@@ -2929,6 +2935,7 @@
F4143C8B0F4B1D07008C8F73 /* renderer.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = renderer.sb; sourceTree = "<group>"; };
F41444270F55AA97008C8F73 /* resource_bundle_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = resource_bundle_mac.mm; sourceTree = "<group>"; };
F60D7722C1302E1EC789B67A /* ssl_host_state.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ssl_host_state.cc; path = ssl/ssl_host_state.cc; sourceTree = "<group>"; };
+ F89AEC011AAB608B245CA291 /* extension_view.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = extension_view.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -3328,6 +3335,8 @@
E7FDE61828F151056D975855 /* bookmark_drag_data.cc */,
12F137DA942221A44BFA0967 /* bookmark_drop_info.cc */,
90BF0D1189BB7158BD7F1600 /* bookmark_context_menu.cc */,
+ 408A60BCB981BCA94219A0C7 /* extension_bindings.h */,
+ A4457D7F38B3E87FD6F0812A /* extension_bindings.cc */,
D224399513442348FF231FCB /* importer.cc */,
E7A3400C283C5FA030AD4BF2 /* firefox_importer_utils.cc */,
);
@@ -3831,6 +3840,7 @@
4D7BFB850E9D4C9F009A6919 /* animation.cc */,
4D7BFB860E9D4C9F009A6919 /* animation.h */,
4D7BFB870E9D4C9F009A6919 /* animation_unittest.cc */,
+ 0B470D4BA5E89469583CB80C /* bindings_policy.h */,
4D7BFB880E9D4C9F009A6919 /* bzip2_unittest.cc */,
4D7BFB890E9D4C9F009A6919 /* child_process.cc */,
4D7BFB8A0E9D4C9F009A6919 /* child_process.h */,
@@ -4702,6 +4712,8 @@
E48B6C270F2783E9002E47EC /* extension_protocols.cc */,
E48B6C260F2783E9002E47EC /* extension_protocols.h */,
E4F324420EE5CE94002533CE /* extension_unittest.cc */,
+ 75388283AD5D97375B14859E /* extension_view.cc */,
+ F89AEC011AAB608B245CA291 /* extension_view.h */,
A54612D90EE9957000A8EE5D /* extensions_service.cc */,
A54612DA0EE9957000A8EE5D /* extensions_service.h */,
A54612DB0EE9958600A8EE5D /* extensions_service_unittest.cc */,
@@ -5632,6 +5644,7 @@
29D0CE7BEF15AE6D5233BA6A /* dev_tools_client.cc in Sources */,
E45076D90F1538E4003BE099 /* dom_automation_controller.cc in Sources */,
E45076C90F1537F5003BE099 /* dom_ui_bindings.cc in Sources */,
+ 9258B3C905B9E261667F7E0B /* extension_bindings.cc in Sources */,
E45076CB0F15380C003BE099 /* external_host_bindings.cc in Sources */,
3380A6A30F2E9207004EF74F /* ipc_sync_channel.cc in Sources */,
E45076CF0F153871003BE099 /* localized_error.cc in Sources */,
@@ -5734,6 +5747,7 @@
E4F324430EE5CE94002533CE /* extension.cc in Sources */,
AC021BD1578D51C5FC94AA16 /* extension_error_reporter.cc in Sources */,
E48B6C280F2783E9002E47EC /* extension_protocols.cc in Sources */,
+ F7DA1699176A4C039D5D10D0 /* extension_view.cc in Sources */,
A54612E20EE995F600A8EE5D /* extensions_service.cc in Sources */,
9E85B39CA40439D93CE52E60 /* fav_icon_helper.cc in Sources */,
E45075C10F1506F2003BE099 /* firefox2_importer.cc in Sources */,
diff --git a/chrome/common/bindings_policy.h b/chrome/common/bindings_policy.h
new file mode 100755
index 0000000..eccce17
--- /dev/null
+++ b/chrome/common/bindings_policy.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2006-2009 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_COMMON_BINDINGS_POLICY_H__
+#define CHROME_COMMON_BINDINGS_POLICY_H__
+
+// This is a utility class that specifies flag values for the types of
+// JavaScript bindings exposed to renderers.
+class BindingsPolicy {
+ public:
+ enum {
+ // HTML-based UI bindings that allows he js content to send JSON-encoded
+ // data back to the browser process.
+ DOM_UI = 1 << 0,
+ // DOM automation bindings that allows the js content to send JSON-encoded
+ // data back to automation in the parent process. (By default this isn't
+ // allowed unless the app has been started up with the --dom-automation
+ // switch.)
+ DOM_AUTOMATION = 1 << 1,
+ // Bindings that allow access to the external host (through automation).
+ EXTERNAL_HOST = 1 << 2,
+ // Special bindings with privileged APIs for code running in the extension
+ // process.
+ EXTENSION = 1 << 3,
+ };
+
+ static bool is_dom_ui_enabled(int flags) {
+ return (flags & DOM_UI) != 0;
+ }
+ static bool is_dom_automation_enabled(int flags) {
+ return (flags & DOM_AUTOMATION) != 0;
+ }
+ static bool is_external_host_enabled(int flags) {
+ return (flags & EXTERNAL_HOST) != 0;
+ }
+ static bool is_extension_enabled(int flags) {
+ return (flags & EXTENSION) != 0;
+ }
+};
+
+#endif // CHROME_COMMON_BINDINGS_POLICY_H__
diff --git a/chrome/common/common.scons b/chrome/common/common.scons
index 6c3378a..b6b43aa 100644
--- a/chrome/common/common.scons
+++ b/chrome/common/common.scons
@@ -104,6 +104,7 @@ input_files = ChromeFileList([
'accessibility.h',
'animation.cc',
'animation.h',
+ 'bindings_policy.h',
'child_process.cc',
'child_process.h',
'child_process_host.cc',
diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj
index 181df44..d44bcf1 100644
--- a/chrome/common/common.vcproj
+++ b/chrome/common/common.vcproj
@@ -334,6 +334,10 @@
>
</File>
<File
+ RelativePath=".\bindings_policy.h"
+ >
+ </File>
+ <File
RelativePath=".\child_process.cc"
>
</File>
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 178abbe..e7ec9ed 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -302,19 +302,11 @@ IPC_BEGIN_MESSAGES(View)
// Notifies the renderer that the system DoDragDrop call has ended.
IPC_MESSAGE_ROUTED0(ViewMsg_DragSourceSystemDragEnded)
- // Used to tell a render view whether it should expose DOM Automation bindings
- // that allow JS content in the DOM to send a JSON-encoded value to the
- // browser process. (By default this isn't allowed unless the app has
- // been started up with the --dom-automation switch.)
- IPC_MESSAGE_ROUTED1(ViewMsg_AllowDomAutomationBindings,
- bool /* binding_allowed */)
-
- // Used to tell a render view whether it should expose DOM UI bindings
- // that allow JS content in the DOM to send a JSON-encoded value to the
- // browser process. This is for HTML-based UI.
- IPC_MESSAGE_ROUTED2(ViewMsg_AllowBindings,
- bool /* enable_dom_ui_bindings */,
- bool /* enable_external_host_bindings */)
+ // Used to tell a render view whether it should expose various bindings
+ // that allow JS content extended privileges. See BindingsPolicy for valid
+ // flag values.
+ IPC_MESSAGE_ROUTED1(ViewMsg_AllowBindings,
+ int /* enabled_bindings_flags */)
// Tell the renderer to add a property to the DOMUI binding object. This
// only works if we allowed DOMUI bindings.
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index e280f9e..975ded3 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -75,6 +75,7 @@ class ProfileManager;
class Profile;
class RenderProcessHost;
class RenderWidgetHelper;
+class RenderViewHostDelegate;
class ResourceMessageFilter;
class SessionBackend;
class SessionCommand;
@@ -770,4 +771,19 @@ class OSExchangeData {
class BaseDragSource {
};
+//---------------------------------------------------------------------------
+// These stubs are for extensions
+
+class HWNDHtmlView {
+ public:
+ HWNDHtmlView(const GURL& content_url, RenderViewHostDelegate* delegate,
+ bool allow_dom_ui_bindings) {
+ NOTIMPLEMENTED();
+ }
+ virtual ~HWNDHtmlView() {}
+
+ RenderViewHost* render_view_host() { NOTIMPLEMENTED(); return NULL; }
+ void InitHidden() { NOTIMPLEMENTED(); }
+};
+
#endif // CHROME_COMMON_TEMP_SCAFFOLDING_STUBS_H_
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"
>
diff --git a/chrome/test/data/extensions/good/extension1/1/index.html b/chrome/test/data/extensions/good/extension1/1/index.html
new file mode 100644
index 0000000..2a03e43
--- /dev/null
+++ b/chrome/test/data/extensions/good/extension1/1/index.html
@@ -0,0 +1,5 @@
+<body>
+<script>
+ window.setTimeout('alert(window.extension.getTestString())', 2500);
+</script>
+</body>
diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj
index e6ba858..827179b 100644
--- a/chrome/test/unit/unittests.vcproj
+++ b/chrome/test/unit/unittests.vcproj
@@ -471,6 +471,10 @@
>
</File>
<File
+ RelativePath="..\..\browser\extensions\extension_view_unittest.cc"
+ >
+ </File>
+ <File
RelativePath="..\..\browser\extensions\extensions_service_unittest.cc"
>
</File>