diff options
30 files changed, 221 insertions, 196 deletions
diff --git a/chrome/browser/blocked_popup_container.cc b/chrome/browser/blocked_popup_container.cc index ede0cda..7bab882 100644 --- a/chrome/browser/blocked_popup_container.cc +++ b/chrome/browser/blocked_popup_container.cc @@ -4,7 +4,6 @@ #include "chrome/browser/blocked_popup_container.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/pref_names.h" @@ -243,12 +242,6 @@ TabContents* BlockedPopupContainer::GetConstrainingContents( return owner_; } -ExtensionFunctionDispatcher* BlockedPopupContainer:: - CreateExtensionFunctionDispatcher(RenderViewHost* render_view_host, - const std::string& extension_id) { - return new ExtensionFunctionDispatcher(render_view_host, NULL, extension_id); -} - void BlockedPopupContainer::HideSelf() { view_->HideView(); owner_->PopupNotificationVisibilityChanged(false); diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h index c7d94ea..0af72cc 100644 --- a/chrome/browser/blocked_popup_container.h +++ b/chrome/browser/blocked_popup_container.h @@ -176,11 +176,6 @@ class BlockedPopupContainer : public TabContentsDelegate, // Ignored; BlockedPopupContainer doesn't display a URL bar. virtual void UpdateTargetURL(TabContents* source, const GURL& url) { } - // Creates an ExtensionFunctionDispatcher that has no browser - virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id); - // A number larger than the internal popup count on the Renderer; meant for // preventing a compromised renderer from exhausting GDI memory by spawning // infinite windows. diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index e782a6c..ea81a21 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1906,12 +1906,6 @@ void Browser::RenderWidgetShowing() { window_->DisableInactiveFrame(); } -ExtensionFunctionDispatcher* Browser::CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id) { - return new ExtensionFunctionDispatcher(render_view_host, this, extension_id); -} - int Browser::GetExtraRenderViewHeight() const { return window_->GetExtraRenderViewHeight(); } diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index b5d619f..47ff65a 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -13,7 +13,6 @@ #include "base/scoped_ptr.h" #include "base/task.h" #include "chrome/browser/command_updater.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/browser/tabs/tab_strip_model.h" @@ -42,8 +41,7 @@ class Browser : public TabStripModelDelegate, public PageNavigator, public CommandUpdater::CommandUpdaterDelegate, public NotificationObserver, - public SelectFileDialog::Listener, - public ExtensionFunctionDispatcher::Delegate { + public SelectFileDialog::Listener { public: enum Type { TYPE_NORMAL = 0, @@ -484,9 +482,6 @@ class Browser : public TabStripModelDelegate, bool* proceed_to_fire_unload); virtual void SetFocusToLocationBar(); virtual void RenderWidgetShowing(); - virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id); virtual int GetExtraRenderViewHeight() const; virtual void OnStartDownload(DownloadItem* download); virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, @@ -500,11 +495,6 @@ class Browser : public TabStripModelDelegate, const NotificationSource& source, const NotificationDetails& details); - // Overridden from ExtensionFunctionDispatcher::Delegate - virtual Browser* GetBrowser() { - return this; - } - // Command and state updating /////////////////////////////////////////////// // Initialize state for all browser commands. diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index 3a7b221..3b0472b 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -13,6 +13,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/common/bindings_policy.h" DOMUI::DOMUI(TabContents* contents) : hide_favicon_(false), @@ -20,6 +21,7 @@ DOMUI::DOMUI(TabContents* contents) focus_location_bar_by_default_(false), should_hide_url_(false), link_transition_type_(PageTransition::LINK), + bindings_(BindingsPolicy::DOM_UI), tab_contents_(contents) { } @@ -32,7 +34,9 @@ DOMUI::~DOMUI() { // DOMUI, public: ------------------------------------------------------------- void DOMUI::ProcessDOMUIMessage(const std::string& message, - const std::string& content) { + const std::string& content, + int request_id, + bool has_callback) { // Look up the callback for this message. MessageCallbackMap::const_iterator callback = message_callbacks_.find(message); diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h index f7bb0e7..fad04e5 100644 --- a/chrome/browser/dom_ui/dom_ui.h +++ b/chrome/browser/dom_ui/dom_ui.h @@ -32,8 +32,10 @@ class DOMUI { virtual void RenderViewCreated(RenderViewHost* render_view_host) {} // Called from DOMUIContents. - void ProcessDOMUIMessage(const std::string& message, - const std::string& content); + virtual void ProcessDOMUIMessage(const std::string& message, + const std::string& content, + int request_id, + bool has_callback); // Used by DOMMessageHandlers. typedef Callback1<const Value*>::Type MessageCallback; @@ -77,6 +79,10 @@ class DOMUI { return link_transition_type_; } + const int bindings() const { + return bindings_; + } + // Call a Javascript function by sending its name and arguments down to // the renderer. This is asynchronous; there's no way to get the result // of the call, and should be thought of more like sending a message to @@ -106,6 +112,8 @@ class DOMUI { bool should_hide_url_; string16 overridden_title_; // Defaults to empty string. PageTransition::Type link_transition_type_; // Defaults to LINK. + int bindings_; // The bindings from BindingsPolicy that should be enabled for + // this page. private: // Execute a string of raw Javascript on the page. diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index c5576cf..8827c02 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -10,6 +10,7 @@ #include "chrome/browser/dom_ui/html_dialog_ui.h" #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/extensions/extensions_ui.h" +#include "chrome/browser/extensions/extension_dom_ui.h" #include "chrome/common/url_constants.h" #ifdef CHROME_PERSONALIZATION #include "chrome/personalization/personalization.h" @@ -34,6 +35,12 @@ static bool CreateDOMUI(const GURL& url, TabContents* tab_contents, return true; } + if (url.SchemeIs(chrome::kExtensionScheme)) { + if (new_ui) + *new_ui = new ExtensionDOMUI(tab_contents); + return true; + } + #ifdef CHROME_PERSONALIZATION if (Personalization::NeedsDOMUI(url)) { if (new_ui) @@ -91,7 +98,8 @@ static bool CreateDOMUI(const GURL& url, TabContents* tab_contents, // static bool DOMUIFactory::HasDOMUIScheme(const GURL& url) { return url.SchemeIs(chrome::kChromeInternalScheme) || - url.SchemeIs(chrome::kChromeUIScheme); + url.SchemeIs(chrome::kChromeUIScheme) || + url.SchemeIs(chrome::kExtensionScheme); } // static diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc new file mode 100644 index 0000000..0d24345 --- /dev/null +++ b/chrome/browser/extensions/extension_dom_ui.cc @@ -0,0 +1,31 @@ +#include "chrome/browser/extensions/extension_dom_ui.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/bindings_policy.h" + +ExtensionDOMUI::ExtensionDOMUI(TabContents* tab_contents) + : DOMUI(tab_contents) { + // TODO(aa): It would be cool to show the extension's icon in here. + hide_favicon_ = true; + should_hide_url_ = true; + bindings_ = BindingsPolicy::EXTENSION; +} + +void ExtensionDOMUI::RenderViewCreated(RenderViewHost* render_view_host) { + extension_function_dispatcher_.reset( + new ExtensionFunctionDispatcher(render_view_host, this, + tab_contents()->GetURL())); +} + +void ExtensionDOMUI::ProcessDOMUIMessage(const std::string& message, + const std::string& content, + int request_id, + bool has_callback) { + extension_function_dispatcher_->HandleRequest(message, content, request_id, + has_callback); +} + +Browser* ExtensionDOMUI::GetBrowser() { + return static_cast<Browser*>(tab_contents()->delegate()); +} diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h new file mode 100644 index 0000000..2de94cf --- /dev/null +++ b/chrome/browser/extensions/extension_dom_ui.h @@ -0,0 +1,33 @@ +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ + +#include "base/scoped_ptr.h" +#include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/extensions/extension_function_dispatcher.h" + +// This class implements DOMUI for extensions and allows extensions to put UI in +// the main tab contents area. +class ExtensionDOMUI + : public DOMUI, + public ExtensionFunctionDispatcher::Delegate { + public: + explicit ExtensionDOMUI(TabContents* tab_contents); + ExtensionFunctionDispatcher* extension_function_dispatcher() const { + return extension_function_dispatcher_.get(); + } + + // DOMUI + virtual void RenderViewCreated(RenderViewHost* render_view_host); + virtual void ProcessDOMUIMessage(const std::string& message, + const std::string& content, + int request_id, + bool has_callback); + + // ExtensionFunctionDispatcher::Delegate + virtual Browser* GetBrowser(); + + private: + scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 7b873a5..24eacf2 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -168,23 +168,31 @@ void ExtensionFunctionDispatcher::ResetFunctions() { FactoryRegistry::instance()->ResetFunctions(); } +std::set<ExtensionFunctionDispatcher*>* + ExtensionFunctionDispatcher::all_instances() { + static std::set<ExtensionFunctionDispatcher*> instances; + return &instances; +} + ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( RenderViewHost* render_view_host, Delegate* delegate, - const std::string& extension_id) + const GURL& url) : render_view_host_(render_view_host), delegate_(delegate), - extension_id_(extension_id), + url_(url), ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { + all_instances()->insert(this); RenderProcessHost* process = render_view_host_->process(); ExtensionMessageService* message_service = ExtensionMessageService::GetInstance(profile()->GetRequestContext()); DCHECK(process); DCHECK(message_service); - message_service->RegisterExtension(extension_id, process->pid()); + message_service->RegisterExtension(extension_id(), process->pid()); } ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { + all_instances()->erase(this); peer_->dispatcher_ = NULL; } diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h index b59e256..0e79882 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.h +++ b/chrome/browser/extensions/extension_function_dispatcher.h @@ -6,9 +6,11 @@ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ #include <string> +#include <set> #include <vector> #include "base/ref_counted.h" +#include "googleurl/src/gurl.h" class Browser; class ExtensionFunction; @@ -47,9 +49,12 @@ class ExtensionFunctionDispatcher { // Resets all functions to their initial implementation. static void ResetFunctions(); + // Retrieves a vector of all EFD instances. + static std::set<ExtensionFunctionDispatcher*>* all_instances(); + ExtensionFunctionDispatcher(RenderViewHost* render_view_host, Delegate* delegate, - const std::string& extension_id); + const GURL& url); ~ExtensionFunctionDispatcher(); // Handle a request to execute an extension function. @@ -67,18 +72,24 @@ class ExtensionFunctionDispatcher { // the renderer. void HandleBadMessage(ExtensionFunction* api); + // Gets the URL for the view we're displaying. + const GURL& url() { return url_; } + // Gets the ID for this extension. - std::string extension_id() { return extension_id_; } + const std::string extension_id() { return url_.host(); } // The profile that this dispatcher is associated with. Profile* profile(); + // The RenderViewHost this dispatcher is associated with. + RenderViewHost* render_view_host() { return render_view_host_; } + private: RenderViewHost* render_view_host_; Delegate* delegate_; - std::string extension_id_; + GURL url_; scoped_refptr<Peer> peer_; diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 94b759d..669dbdd 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -20,6 +20,7 @@ #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/common/bindings_policy.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" @@ -84,7 +85,7 @@ ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, url_(url) { render_view_host_ = new RenderViewHost( site_instance, this, MSG_ROUTING_NONE, NULL); - render_view_host_->AllowExtensionBindings(); + render_view_host_->AllowBindings(BindingsPolicy::EXTENSION); } ExtensionHost::~ExtensionHost() { @@ -196,12 +197,6 @@ void ExtensionHost::DidInsertCSS() { #endif } -ExtensionFunctionDispatcher* ExtensionHost:: - CreateExtensionFunctionDispatcher(RenderViewHost *render_view_host, - const std::string& extension_id) { - return new ExtensionFunctionDispatcher(render_view_host, this, extension_id); -} - RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() const { // TODO(erikkay) this is unfortunate. The interface declares that this method // must be const (no good reason for it as far as I can tell) which means you @@ -303,3 +298,16 @@ Browser* ExtensionHost::GetBrowser() { // is available. http://code.google.com/p/chromium/issues/detail?id=13284 return browser; } + +void ExtensionHost::ProcessDOMUIMessage(const std::string& message, + const std::string& content, + int request_id, + bool has_callback) { + extension_function_dispatcher_->HandleRequest(message, content, request_id, + has_callback); +} + +void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { + extension_function_dispatcher_.reset( + new ExtensionFunctionDispatcher(render_view_host_, this, url_)); +} diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index a7ca899..e54fc39 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -8,6 +8,7 @@ #include <string> #include "base/scoped_ptr.h" +#include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" #if defined(TOOLKIT_VIEWS) @@ -63,6 +64,7 @@ class ExtensionHost : public RenderViewHostDelegate, // RenderViewHostDelegate virtual const GURL& GetURL() const { return url_; } + virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewGone(RenderViewHost* render_view_host); virtual WebPreferences GetWebkitPrefs(); virtual void RunJavaScriptMessage( @@ -74,9 +76,11 @@ class ExtensionHost : public RenderViewHostDelegate, bool* did_suppress_message); virtual void DidStopLoading(RenderViewHost* render_view_host); virtual RenderViewHostDelegate::View* GetViewDelegate() const; - virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher( - RenderViewHost *render_view_host, const std::string& extension_id); virtual void DidInsertCSS(); + virtual void ProcessDOMUIMessage(const std::string& message, + const std::string& content, + int request_id, + bool has_callback); // RenderViewHostDelegate::View virtual void CreateNewWindow(int route_id, @@ -129,6 +133,8 @@ class ExtensionHost : public RenderViewHostDelegate, // The URL being hosted. GURL url_; + scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; + DISALLOW_COPY_AND_ASSIGN(ExtensionHost); }; diff --git a/chrome/browser/extensions/extension_startup_unittest.cc b/chrome/browser/extensions/extension_startup_unittest.cc index ce9b885..a9c494a 100644 --- a/chrome/browser/extensions/extension_startup_unittest.cc +++ b/chrome/browser/extensions/extension_startup_unittest.cc @@ -152,12 +152,22 @@ IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, Test) { &result); EXPECT_TRUE(result); + result = false; ui_test_utils::ExecuteJavaScriptAndExtractBool( browser()->GetSelectedTabContents(), L"", L"window.domAutomationController.send(document.title == 'Modified')", &result); EXPECT_TRUE(result); + // Load an extension page into the tab area to make sure it works. + result = false; + ui_test_utils::NavigateToURL( + browser(), + GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html")); + ui_test_utils::ExecuteJavaScriptAndExtractBool( + browser()->GetSelectedTabContents(), L"", L"testTabsAPI()", &result); + EXPECT_TRUE(result); + // TODO(aa): Move the stuff in ExtensionBrowserTest here? } diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index 7ad40cc..62fb559 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -226,29 +226,16 @@ DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue( std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension( const std::string& extension_id) { std::vector<ExtensionPage> result; - - ExtensionMessageService* ems = ExtensionMessageService::GetInstance( - dom_ui_->GetProfile()->GetOriginalProfile()->GetRequestContext()); - RenderProcessHost* process_host = ems->GetProcessForExtension(extension_id); - if (!process_host) - return result; - - RenderProcessHost::listeners_iterator iter; - for (iter = process_host->listeners_begin(); - iter != process_host->listeners_end(); ++iter) { - // NOTE: This is a bit dangerous. We know that for now, listeners are - // always RenderWidgetHosts. But in theory, they don't have to be. - RenderWidgetHost* widget = static_cast<RenderWidgetHost*>(iter->second); - if (!widget->IsRenderView()) - continue; - - RenderViewHost* view = static_cast<RenderViewHost*>(widget); - ExtensionFunctionDispatcher* efd = view->extension_function_dispatcher(); - if (efd && efd->extension_id() == extension_id) { - ExtensionPage page(view->delegate()->GetURL(), - process_host->pid(), - view->routing_id()); - result.push_back(page); + std::set<ExtensionFunctionDispatcher*>* all_instances = + ExtensionFunctionDispatcher::all_instances(); + + for (std::set<ExtensionFunctionDispatcher*>::iterator iter = + all_instances->begin(); iter != all_instances->end(); ++iter) { + RenderViewHost* view = (*iter)->render_view_host(); + if ((*iter)->extension_id() == extension_id && view) { + result.push_back(ExtensionPage((*iter)->url(), + view->process()->pid(), + view->routing_id())); } } diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index d7e4836..68fc66b 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -10,13 +10,13 @@ #include "base/win_util.h" #include "chrome/browser/automation/automation_provider.h" #include "chrome/browser/browser.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/load_notification_details.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/provisional_load_details.h" #include "chrome/browser/views/tab_contents/render_view_context_menu_external_win.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/tab_contents/tab_contents_container.h" +#include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/notification_service.h" #include "chrome/test/automation/automation_messages.h" @@ -66,7 +66,8 @@ bool ExternalTabContainer::Init(Profile* profile, tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); tab_contents_->set_delegate(this); - tab_contents_->render_view_host()->AllowExternalHostBindings(); + tab_contents_->render_view_host()->AllowBindings( + BindingsPolicy::EXTERNAL_HOST); // Create a TabContentsContainer to handle focus cycling using Tab and // Shift-Tab. @@ -246,12 +247,6 @@ void ExternalTabContainer::ForwardMessageToExternalHost( } } -ExtensionFunctionDispatcher* ExternalTabContainer:: - CreateExtensionFunctionDispatcher(RenderViewHost* render_view_host, - const std::string& extension_id) { - return new ExtensionFunctionDispatcher(render_view_host, NULL, extension_id); -} - bool ExternalTabContainer::TakeFocus(bool reverse) { if (automation_) { automation_->Send(new AutomationMsg_TabbedOut(0, tab_handle_, diff --git a/chrome/browser/external_tab_container.h b/chrome/browser/external_tab_container.h index 1f98891..3037847 100644 --- a/chrome/browser/external_tab_container.h +++ b/chrome/browser/external_tab_container.h @@ -87,9 +87,6 @@ class ExternalTabContainer : public TabContentsDelegate, return true; }; - virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id); virtual bool TakeFocus(bool reverse); // Overridden from NotificationObserver: diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index d313178..8072eb2 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -42,7 +42,6 @@ #endif using base::TimeDelta; -using webkit_glue::AutofillForm; using webkit_glue::PasswordFormDomManager; using WebKit::WebConsoleMessage; using WebKit::WebFindOptions; @@ -570,24 +569,9 @@ void RenderViewHost::DragSourceSystemDragEnded() { Send(new ViewMsg_DragSourceSystemDragEnded(routing_id())); } -void RenderViewHost::AllowDomAutomationBindings() { +void RenderViewHost::AllowBindings(int bindings_flags) { 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_); - enabled_bindings_ |= BindingsPolicy::DOM_UI; -} - -void RenderViewHost::AllowExtensionBindings() { - DCHECK(!renderer_initialized_); - enabled_bindings_ |= BindingsPolicy::EXTENSION; + enabled_bindings_ |= bindings_flags; } void RenderViewHost::SetDOMUIProperty(const std::string& name, @@ -889,15 +873,6 @@ void RenderViewHost::OnMsgNavigate(const IPC::Message& msg) { FilterURL(policy, renderer_id, &validated_params.password_form.origin); FilterURL(policy, renderer_id, &validated_params.password_form.action); - if (PageTransition::IsMainFrame(validated_params.transition)) { - ExtensionFunctionDispatcher* new_efd = NULL; - if (validated_params.url.SchemeIs(chrome::kExtensionScheme)) { - new_efd = delegate()->CreateExtensionFunctionDispatcher(this, - validated_params.url.host()); - } - extension_function_dispatcher_.reset(new_efd); - } - delegate_->DidNavigate(this, validated_params); UpdateBackForwardListCount(); @@ -1077,7 +1052,14 @@ void RenderViewHost::OnMsgDOMUISend( NOTREACHED() << "Blocked unauthorized use of DOMUIBindings."; return; } - delegate_->ProcessDOMUIMessage(message, content); + + // DOMUI doesn't use these values yet. + // TODO(aa): When DOMUI is ported to ExtensionFunctionDispatcher, send real + // values here. + const int kRequestId = -1; + const bool kHasCallback = false; + + delegate_->ProcessDOMUIMessage(message, content, kRequestId, kHasCallback); } void RenderViewHost::OnMsgForwardMessageToExternalHost( @@ -1161,7 +1143,7 @@ void RenderViewHost::OnMsgPasswordFormsSeen( } void RenderViewHost::OnMsgAutofillFormSubmitted( - const AutofillForm& form) { + const webkit_glue::AutofillForm& form) { delegate_->AutofillFormSubmitted(form); } @@ -1386,9 +1368,7 @@ void RenderViewHost::OnExtensionRequest(const std::string& name, return; } - DCHECK(extension_function_dispatcher_.get()); - extension_function_dispatcher_->HandleRequest(name, args, request_id, - has_callback); + delegate_->ProcessDOMUIMessage(name, args, request_id, has_callback); } void RenderViewHost::SendExtensionResponse(int request_id, bool success, diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index a30dbc2..b932e1c 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -92,9 +92,6 @@ class RenderViewHost : public RenderWidgetHost { SiteInstance* site_instance() const { return instance_; } RenderViewHostDelegate* delegate() const { return delegate_; } - ExtensionFunctionDispatcher* extension_function_dispatcher() const { - return extension_function_dispatcher_.get(); - } // Set up the RenderView child process. Virtual because it is overridden by // TestRenderViewHost. @@ -306,26 +303,9 @@ class RenderViewHost : public RenderWidgetHost { // This allows the renderer to reset some state. void DragSourceSystemDragEnded(); - // 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 - // can send JSON-encoded data back to the browser process. - // This is used for HTML-based UI. - // 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(); + // Tell the render view to enable a set of javascript bindings. The argument + // should be a combination of values from BindingsPolicy. + void AllowBindings(int binding_flags); // Sets a property with the given name and value on the DOM UI binding object. // Must call AllowDOMUIBindings() on this renderer first. @@ -609,11 +589,6 @@ class RenderViewHost : public RenderWidgetHost { bool are_javascript_messages_suppressed_; - // Handles processing IPC messages request extension functions be executed. - // This changes during navigation and may be NULL if the current content is - // not an extension. - scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; - // True if the render view can be shut down suddenly. bool sudden_termination_allowed_; diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index fd52627..09b34bc 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -19,9 +19,7 @@ #include "webkit/glue/webpreferences.h" #include "webkit/glue/window_open_disposition.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" - -class ExtensionFunctionDispatcher; +class AutofillForm; class NavigationEntry; class Profile; class RenderProcessHost; @@ -161,14 +159,6 @@ class RenderViewHostDelegate { // Gets the URL that is currently being displayed, if there is one. virtual const GURL& GetURL() const = 0; - // Create a new browser window to be sized, shown and contents managed - // by the caller. - virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id) { - return NULL; - } - // Return this object cast to a TabContents, if it is one. virtual TabContents* GetAsTabContents() { return NULL; } @@ -278,7 +268,9 @@ class RenderViewHostDelegate { // A message was sent from HTML-based UI. // By default we ignore such messages. virtual void ProcessDOMUIMessage(const std::string& message, - const std::string& content) { } + const std::string& content, + int request_id, + bool has_callback) { } // A message for external host. By default we ignore such messages. // |receiver| can be a receiving script and |message| is any diff --git a/chrome/browser/renderer_host/render_view_host_manager.cc b/chrome/browser/renderer_host/render_view_host_manager.cc index c0be053..7c4d219 100644 --- a/chrome/browser/renderer_host/render_view_host_manager.cc +++ b/chrome/browser/renderer_host/render_view_host_manager.cc @@ -19,6 +19,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" namespace base { class WaitableEvent; @@ -294,6 +295,14 @@ bool RenderViewHostManager::ShouldSwapProcessesForNavigation( DOMUIFactory::HasDOMUIScheme(new_entry->url())) return true; + // Also, we must switch if one is an extension and the other is not the exact + // same extension. + if (cur_entry->url().SchemeIs(chrome::kExtensionScheme) || + new_entry->url().SchemeIs(chrome::kExtensionScheme)) + if (cur_entry->url().GetOrigin() != new_entry->url().GetOrigin()) + return true; + + return false; } diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index b4e33d8..4683259 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -16,6 +16,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/common/bindings_policy.h" #include "chrome/common/notification_service.h" #include "grit/browser_resources.h" #include "net/base/escape.h" @@ -292,7 +293,7 @@ TabContentsView* InterstitialPage::CreateTabContentsView() { RenderWidgetHostView* view = tab_contents_view->CreateViewForWidget(render_view_host_); render_view_host_->set_view(view); - render_view_host_->AllowDomAutomationBindings(); + render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION); render_view_host_->CreateRenderView(); view->SetSize(tab_contents_view->GetContainerSize()); // Don't show the interstitial until we have navigated to it. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 5b89157..e0e6fe5 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -497,10 +497,6 @@ bool TabContents::ShouldDisplayURL() { if (entry && entry->IsViewSourceMode()) return true; - // Hide the URL in chrome-extension://. - if (GetURL().SchemeIs(chrome::kExtensionScheme)) - return false; - DOMUI* dom_ui = GetDOMUIForCurrentState(); if (dom_ui) return !dom_ui->should_hide_url(); @@ -1503,13 +1499,6 @@ RendererPreferences TabContents::GetRendererPrefs() const { return RendererPreferences(); } -ExtensionFunctionDispatcher* TabContents::CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id) { - return delegate()->CreateExtensionFunctionDispatcher(render_view_host, - extension_id); -} - TabContents* TabContents::GetAsTabContents() { return this; } @@ -1864,7 +1853,9 @@ void TabContents::DomOperationResponse(const std::string& json_string, } void TabContents::ProcessDOMUIMessage(const std::string& message, - const std::string& content) { + const std::string& content, + int request_id, + bool has_callback) { if (!render_manager_.dom_ui()) { // We shouldn't get a DOM UI message when we haven't enabled the DOM UI. // Because the renderer might be owned and sending random messages, we need @@ -1872,7 +1863,8 @@ void TabContents::ProcessDOMUIMessage(const std::string& message, NOTREACHED(); return; } - render_manager_.dom_ui()->ProcessDOMUIMessage(message, content); + render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id, + has_callback); } void TabContents::DocumentLoadedInFrame() { @@ -2280,16 +2272,11 @@ TabContents::GetLastCommittedNavigationEntryForRenderManager() { bool TabContents::CreateRenderViewForRenderManager( RenderViewHost* render_view_host) { - // When we're running a DOM UI, the RenderViewHost needs to be put in DOM UI - // mode before CreateRenderView is called. When we're asked to create a - // RenderView, that means it's for the pending entry, so we have to use the - // pending DOM UI. + // If the pending navigation is to a DOMUI, tell the RenderView about any + // bindings it will need enabled. if (render_manager_.pending_dom_ui()) - render_view_host->AllowDOMUIBindings(); - - // Ditto for extension bindings. - if (controller().pending_entry()->url().SchemeIs(chrome::kExtensionScheme)) - render_view_host->AllowExtensionBindings(); + render_view_host->AllowBindings( + render_manager_.pending_dom_ui()->bindings()); RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); if (!render_view_host->CreateRenderView()) diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index b92642b..ae35b8d 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -28,6 +28,7 @@ #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/page_navigator.h" +#include "chrome/common/url_constants.h" #include "chrome/common/gears_api.h" #include "chrome/common/navigation_types.h" #include "chrome/common/notification_registrar.h" @@ -142,8 +143,8 @@ class TabContents : public PageNavigator, bool SupportsURL(GURL* url); // Returns true if contains content rendered by an extension. - bool HostsExtension() const { - return render_view_host()->extension_function_dispatcher() != NULL; + const bool HostsExtension() const { + return GetURL().SchemeIs(chrome::kExtensionScheme); } // Returns the AutofillManager, creating it if necessary. @@ -732,9 +733,6 @@ class TabContents : public PageNavigator, virtual RendererPreferences GetRendererPrefs() const; virtual RenderViewHostDelegate::View* GetViewDelegate() const; virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; - virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id); virtual TabContents* GetAsTabContents(); virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewReady(RenderViewHost* render_view_host); @@ -787,7 +785,9 @@ class TabContents : public PageNavigator, virtual void DomOperationResponse(const std::string& json_string, int automation_id); virtual void ProcessDOMUIMessage(const std::string& message, - const std::string& content); + const std::string& content, + int request_id, + bool has_callback); virtual void DocumentLoadedInFrame(); virtual void ProcessExternalHostMessage(const std::string& message, const std::string& origin, diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index adf7903..0052971 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -444,12 +444,6 @@ void DraggedTabController::UpdateTargetURL(TabContents* source, // Ignored. } -ExtensionFunctionDispatcher* DraggedTabController:: - CreateExtensionFunctionDispatcher(RenderViewHost* render_view_host, - const std::string& extension_id) { - return new ExtensionFunctionDispatcher(render_view_host, NULL, extension_id); -} - /////////////////////////////////////////////////////////////////////////////// // DraggedTabController, NotificationObserver implementation: diff --git a/chrome/browser/views/tabs/dragged_tab_controller.h b/chrome/browser/views/tabs/dragged_tab_controller.h index 4b2c2f0..5330b8a 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.h +++ b/chrome/browser/views/tabs/dragged_tab_controller.h @@ -106,11 +106,6 @@ class DraggedTabController : public TabContentsDelegate, virtual void URLStarredChanged(TabContents* source, bool starred); virtual void UpdateTargetURL(TabContents* source, const GURL& url); - // Creates an ExtensionFunctionDispatcher that has no browser - virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( - RenderViewHost* render_view_host, - const std::string& extension_id); - // Overridden from NotificationObserver: virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 852d27e0..8bb0aa3 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -870,6 +870,8 @@ 'browser/extensions/extension_bookmarks_module_constants.h', 'browser/extensions/extension_creator.cc', 'browser/extensions/extension_creator.h', + 'browser/extensions/extension_dom_ui.cc', + 'browser/extensions/extension_dom_ui.h', 'browser/extensions/extension_event_names.cc', 'browser/extensions/extension_event_names.h', 'browser/extensions/extension_function.cc', diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index 874f57a..c59e98c 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. mp2 --> +without changes to the corresponding grd file. --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 0fbec3f..8b4c4bb 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -7,7 +7,7 @@ // have your change take effect. // ----------------------------------------------------------------------------- -var chrome; +var chrome = chrome || {}; (function() { native function GetViews(); native function GetWindow(); diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/page.html b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/page.html new file mode 100755 index 0000000..5b039a3 --- /dev/null +++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/page.html @@ -0,0 +1,12 @@ +<title>Foobar</title> + +<script> +// This function is called from the C++ browser test. It does a basic sanity +// test that we can call extension APIs. +function testTabsAPI() { + chrome.tabs.getSelected(null, function(tab) { + window.domAutomationController.send( + tab.title == document.title && tab.url == location.href); + }); +} +</script> |