diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 04:13:47 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 04:13:47 +0000 |
commit | 01ec4ec8ef85dc181f3744fdb6fd41cab7b00018 (patch) | |
tree | e8208faaa428979491fc36130c11c6257ce2a91d /content/browser | |
parent | b729f1fca403a7b2424e78fe3257683637e6b1d1 (diff) | |
download | chromium_src-01ec4ec8ef85dc181f3744fdb6fd41cab7b00018.zip chromium_src-01ec4ec8ef85dc181f3744fdb6fd41cab7b00018.tar.gz chromium_src-01ec4ec8ef85dc181f3744fdb6fd41cab7b00018.tar.bz2 |
Switch chrome code to use content::WebUI interface instead of WebUI concrete class. The latter will be renamed to WebUIImpl in a followup change. This completes hiding WebUI from chrome code, and now we can block it through DEPS.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9241032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/tab_contents/render_view_host_manager_unittest.cc | 2 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.cc | 16 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.h | 14 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_unittest.cc | 2 | ||||
-rw-r--r-- | content/browser/webui/generic_handler.cc | 2 | ||||
-rw-r--r-- | content/browser/webui/web_ui.cc | 30 | ||||
-rw-r--r-- | content/browser/webui/web_ui.h | 193 |
7 files changed, 92 insertions, 167 deletions
diff --git a/content/browser/tab_contents/render_view_host_manager_unittest.cc b/content/browser/tab_contents/render_view_host_manager_unittest.cc index a19b4de..bac92f4 100644 --- a/content/browser/tab_contents/render_view_host_manager_unittest.cc +++ b/content/browser/tab_contents/render_view_host_manager_unittest.cc @@ -51,7 +51,7 @@ class RenderViewHostManagerTestWebUIFactory } // WebUIFactory implementation. - virtual WebUIController* CreateWebUIForURL(WebUI* web_ui, + virtual WebUIController* CreateWebUIForURL(content::WebUI* web_ui, const GURL& url) const OVERRIDE { if (!(should_create_webui_ && HasWebUIScheme(url))) return NULL; diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 8a6b5dd..dbc5a5e 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -303,7 +303,7 @@ RenderViewHostManager* TabContents::GetRenderManagerForTesting() { } bool TabContents::OnMessageReceived(const IPC::Message& message) { - if (GetWebUI() && GetWebUI()->OnMessageReceived(message)) + if (GetWebUI() && static_cast<WebUI*>(GetWebUI())->OnMessageReceived(message)) return true; ObserverListBase<WebContentsObserver>::Iterator it(observers_); @@ -432,7 +432,7 @@ TabContentsView* TabContents::GetView() const { return view_.get(); } -WebUI* TabContents::CreateWebUI(const GURL& url) { +content::WebUI* TabContents::CreateWebUI(const GURL& url) { WebUI* web_ui = new WebUI(this); WebUIController* controller = content::GetContentClient()->browser()->GetWebUIFactory()-> @@ -446,12 +446,12 @@ WebUI* TabContents::CreateWebUI(const GURL& url) { return NULL; } -WebUI* TabContents::GetWebUI() const { +content::WebUI* TabContents::GetWebUI() const { return render_manager_.web_ui() ? render_manager_.web_ui() : render_manager_.pending_web_ui(); } -WebUI* TabContents::GetCommittedWebUI() const { +content::WebUI* TabContents::GetCommittedWebUI() const { return render_manager_.web_ui(); } @@ -1088,7 +1088,7 @@ WebUI::TypeID TabContents::GetWebUITypeForCurrentState() { GetWebUIType(GetBrowserContext(), GetURL()); } -WebUI* TabContents::GetWebUIForCurrentState() { +content::WebUI* TabContents::GetWebUIForCurrentState() { // When there is a pending navigation entry, we want to use the pending WebUI // that goes along with it to control the basic flags. For example, we want to // show the pending URL in the URL bar, so we want the display_url flag to @@ -1134,7 +1134,7 @@ bool TabContents::GotResponseToLockMouseRequest(bool allowed) { } bool TabContents::FocusLocationBarByDefault() { - WebUI* web_ui = GetWebUIForCurrentState(); + content::WebUI* web_ui = GetWebUIForCurrentState(); if (web_ui) return web_ui->ShouldFocusLocationBarByDefault(); NavigationEntry* entry = controller_.GetActiveEntry(); @@ -1480,7 +1480,7 @@ void TabContents::DidNavigateMainFramePostCommit( // that opened the window, as long as both renderers have the same // privileges. if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { - WebUI* web_ui = CreateWebUI(GetURL()); + WebUI* web_ui = static_cast<WebUI*>(CreateWebUI(GetURL())); // web_ui might be NULL if the URL refers to a non-existent extension. if (web_ui) { render_manager_.SetWebUIPostCommit(web_ui); @@ -2192,7 +2192,7 @@ NavigationControllerImpl& TabContents::GetControllerForRenderManager() { } WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { - return CreateWebUI(url); + return static_cast<WebUI*>(CreateWebUI(url)); } NavigationEntry* diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index b8d6fd81..56539a1 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -105,7 +105,7 @@ class CONTENT_EXPORT TabContents render_manager_.remove_interstitial_page(); } - void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) { + void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) { opener_web_ui_type_ = opener_web_ui_type; } @@ -133,9 +133,9 @@ class CONTENT_EXPORT TabContents virtual RenderViewHost* GetRenderViewHost() const OVERRIDE; virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE; virtual TabContentsView* GetView() const OVERRIDE; - virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE; - virtual WebUI* GetWebUI() const OVERRIDE; - virtual WebUI* GetCommittedWebUI() const OVERRIDE; + virtual content::WebUI* CreateWebUI(const GURL& url) OVERRIDE; + virtual content::WebUI* GetWebUI() const OVERRIDE; + virtual content::WebUI* GetCommittedWebUI() const OVERRIDE; virtual const string16& GetTitle() const OVERRIDE; virtual int32 GetMaxPageID() OVERRIDE; virtual int32 GetMaxPageIDForSiteInstance( @@ -207,8 +207,8 @@ class CONTENT_EXPORT TabContents virtual int GetMaximumZoomPercent() const OVERRIDE; virtual gfx::Size GetPreferredSize() const OVERRIDE; virtual int GetContentRestrictions() const OVERRIDE; - virtual WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE; - virtual WebUI* GetWebUIForCurrentState() OVERRIDE; + virtual content::WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE; + virtual content::WebUI* GetWebUIForCurrentState() OVERRIDE; virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE; // Implementation of PageNavigator. @@ -609,7 +609,7 @@ class CONTENT_EXPORT TabContents // If this tab was created from a renderer using window.open, this will be // non-NULL and represent the WebUI of the opening renderer. - WebUI::TypeID opener_web_ui_type_; + content::WebUI::TypeID opener_web_ui_type_; // The time that we started to create the new tab page. base::TimeTicks new_tab_start_time_; diff --git a/content/browser/tab_contents/tab_contents_unittest.cc b/content/browser/tab_contents/tab_contents_unittest.cc index 4a591e2..f39f9bc 100644 --- a/content/browser/tab_contents/tab_contents_unittest.cc +++ b/content/browser/tab_contents/tab_contents_unittest.cc @@ -37,7 +37,7 @@ namespace { class TabContentsTestWebUIFactory : public content::EmptyWebUIFactory { public: - virtual WebUIController* CreateWebUIForURL(WebUI* web_ui, + virtual WebUIController* CreateWebUIForURL(content::WebUI* web_ui, const GURL& url) const OVERRIDE { if (!HasWebUIScheme(url)) return NULL; diff --git a/content/browser/webui/generic_handler.cc b/content/browser/webui/generic_handler.cc index 0ecff70..8d401ad 100644 --- a/content/browser/webui/generic_handler.cc +++ b/content/browser/webui/generic_handler.cc @@ -51,7 +51,7 @@ void GenericHandler::HandleNavigateToUrl(const ListValue* args) { if (disposition == CURRENT_TAB && target_string == "_blank") disposition = NEW_FOREGROUND_TAB; - web_ui()->web_contents()->OpenURL(OpenURLParams( + web_ui()->GetWebContents()->OpenURL(OpenURLParams( GURL(url_string), content::Referrer(), disposition, content::PAGE_TRANSITION_LINK, false)); diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc index 1cc7c8b..cfa743e 100644 --- a/content/browser/webui/web_ui.cc +++ b/content/browser/webui/web_ui.cc @@ -24,6 +24,10 @@ using content::WebContents; using content::WebUIController; using content::WebUIMessageHandler; +namespace content { + +const WebUI::TypeID WebUI::kNoWebUI = NULL; + // static string16 WebUI::GetJavascriptCall( const std::string& function_name, @@ -41,13 +45,14 @@ string16 WebUI::GetJavascriptCall( char16('(') + parameters + char16(')') + char16(';'); } +} + WebUI::WebUI(WebContents* contents) : hide_favicon_(false), focus_location_bar_by_default_(false), should_hide_url_(false), link_transition_type_(content::PAGE_TRANSITION_LINK), bindings_(content::BINDINGS_POLICY_WEB_UI), - register_callback_overwrites_(false), web_contents_(contents) { DCHECK(contents); AddMessageHandler(new GenericHandler()); @@ -62,8 +67,6 @@ WebUI::~WebUI() { // WebUI, public: ------------------------------------------------------------- -const WebUI::TypeID WebUI::kNoWebUI = NULL; - bool WebUI::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebUI, message) @@ -191,7 +194,7 @@ void WebUI::CallJavascriptFunction(const std::string& function_name, DCHECK(IsStringASCII(function_name)); std::vector<const Value*> args; args.push_back(&arg); - ExecuteJavascript(WebUI::GetJavascriptCall(function_name, args)); + ExecuteJavascript(GetJavascriptCall(function_name, args)); } void WebUI::CallJavascriptFunction( @@ -201,7 +204,7 @@ void WebUI::CallJavascriptFunction( std::vector<const Value*> args; args.push_back(&arg1); args.push_back(&arg2); - ExecuteJavascript(WebUI::GetJavascriptCall(function_name, args)); + ExecuteJavascript(GetJavascriptCall(function_name, args)); } void WebUI::CallJavascriptFunction( @@ -212,7 +215,7 @@ void WebUI::CallJavascriptFunction( args.push_back(&arg1); args.push_back(&arg2); args.push_back(&arg3); - ExecuteJavascript(WebUI::GetJavascriptCall(function_name, args)); + ExecuteJavascript(GetJavascriptCall(function_name, args)); } void WebUI::CallJavascriptFunction( @@ -227,24 +230,25 @@ void WebUI::CallJavascriptFunction( args.push_back(&arg2); args.push_back(&arg3); args.push_back(&arg4); - ExecuteJavascript(WebUI::GetJavascriptCall(function_name, args)); + ExecuteJavascript(GetJavascriptCall(function_name, args)); } void WebUI::CallJavascriptFunction( const std::string& function_name, const std::vector<const Value*>& args) { DCHECK(IsStringASCII(function_name)); - ExecuteJavascript(WebUI::GetJavascriptCall(function_name, args)); + ExecuteJavascript(GetJavascriptCall(function_name, args)); } void WebUI::RegisterMessageCallback(const std::string &message, const MessageCallback& callback) { - std::pair<MessageCallbackMap::iterator, bool> result = - message_callbacks_.insert(std::make_pair(message, callback)); + message_callbacks_.insert(std::make_pair(message, callback)); +} - // Overwrite preexisting message callback mappings. - if (!result.second && register_callback_overwrites()) - result.first->second = callback; +void WebUI::ProcessWebUIMessage(const GURL& source_url, + const std::string& message, + const base::ListValue& args) { + OnWebUISend(source_url, message, args); } // WebUI, protected: ---------------------------------------------------------- diff --git a/content/browser/webui/web_ui.h b/content/browser/webui/web_ui.h index 7731262..63a6dcb 100644 --- a/content/browser/webui/web_ui.h +++ b/content/browser/webui/web_ui.h @@ -7,158 +7,82 @@ #pragma once #include <map> -#include <string> -#include <vector> -#include "base/callback.h" #include "base/compiler_specific.h" -#include "base/string16.h" -#include "content/common/content_export.h" -#include "content/public/common/page_transition_types.h" +#include "content/public/browser/web_ui.h" #include "ipc/ipc_channel.h" -class GURL; class RenderViewHost; -namespace base { -class ListValue; -class Value; -} - -namespace content { -class WebContents; -class WebUIController; -class WebUIMessageHandler; -} - -// A WebUI sets up the datasources and message handlers for a given HTML-based -// UI. -// -// NOTE: If you're creating a new WebUI for Chrome code, make sure you extend -// ChromeWebUI. -class CONTENT_EXPORT WebUI : public IPC::Channel::Listener { +class CONTENT_EXPORT WebUI : public content::WebUI, + public IPC::Channel::Listener { public: explicit WebUI(content::WebContents* contents); virtual ~WebUI(); - // IPC::Channel::Listener implementation: - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - // TODO(jam): move to private - // IPC message handling. - void OnWebUISend(const GURL& source_url, - const std::string& message, - const base::ListValue& args); - // Called by TabContents when the RenderView is first created. This is *not* // called for every page load because in some cases RenderViewHostManager will // reuse RenderView instances. void RenderViewCreated(RenderViewHost* render_view_host); - // TODO(jam): below is what will be the public API of WebUI - content::WebContents* GetWebContents() const; - - // Returns true if the favicon should be hidden for the current tab. - bool ShouldHideFavicon() const; - void HideFavicon(); - - // Returns true if the location bar should be focused by default rather than - // the page contents. Some pages will want to use this to encourage the user - // to type in the URL bar. - bool ShouldFocusLocationBarByDefault() const; - void FocusLocationBarByDefault(); - - // Returns true if the page's URL should be hidden. Some Web UI pages - // like the new tab page will want to hide it. - bool ShouldHideURL() const; - void HideURL(); - - // Gets a custom tab title provided by the Web UI. If there is no title - // override, the string will be empty which should trigger the default title - // behavior for the tab. - const string16& GetOverriddenTitle() const; - void OverrideTitle(const string16& title); - - // Returns the transition type that should be used for link clicks on this - // Web UI. This will default to LINK but may be overridden. - content::PageTransition GetLinkTransitionType() const; - void SetLinkTransitionType(content::PageTransition type); - - // Allows a controller to override the BindingsPolicy that should be enabled - // for this page. - int GetBindings() const; - void SetBindings(int bindings); - - // Sets the path for the iframe if this WebUI is embedded in a page. - void SetFrameXPath(const std::string& xpath); - - // Takes ownership of |handler|, which will be destroyed when the WebUI is. - void AddMessageHandler(content::WebUIMessageHandler* handler); - - // Execute a string of raw Javascript on the page. Overridable for - // testing purposes. - virtual void ExecuteJavascript(const string16& javascript); - - // Used by WebUIMessageHandlers. If the given message is already registered, - // the call has no effect unless |register_callback_overwrites_| is set to - // true. + // WebUI implementation: + virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual content::WebUIController* GetController() const OVERRIDE; + virtual void SetController(content::WebUIController* controller) OVERRIDE; + virtual bool ShouldHideFavicon() const OVERRIDE; + virtual void HideFavicon() OVERRIDE; + virtual bool ShouldFocusLocationBarByDefault() const OVERRIDE; + virtual void FocusLocationBarByDefault() OVERRIDE; + virtual bool ShouldHideURL() const OVERRIDE; + virtual void HideURL() OVERRIDE; + virtual const string16& GetOverriddenTitle() const OVERRIDE; + virtual void OverrideTitle(const string16& title) OVERRIDE; + virtual content::PageTransition GetLinkTransitionType() const OVERRIDE; + virtual void SetLinkTransitionType(content::PageTransition type) OVERRIDE; + virtual int GetBindings() const OVERRIDE; + virtual void SetBindings(int bindings) OVERRIDE; + virtual void SetFrameXPath(const std::string& xpath) OVERRIDE; + virtual void AddMessageHandler( + content::WebUIMessageHandler* handler) OVERRIDE; typedef base::Callback<void(const base::ListValue*)> MessageCallback; - void RegisterMessageCallback(const std::string& message, - const MessageCallback& callback); - - // Indicates whether RegisterMessageCallback() will overwrite an existing - // message callback mapping. Serves as the hook for test mocks. - bool register_callback_overwrites() const { - return register_callback_overwrites_; - } - - void set_register_callback_overwrites(bool value) { - register_callback_overwrites_ = value; - } - - content::WebUIController* GetController() const; - void SetController(content::WebUIController* controller); - - // 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 - // the page. - // All function names in WebUI must consist of only ASCII characters. - // There are variants for calls with more arguments. - void CallJavascriptFunction(const std::string& function_name); - void CallJavascriptFunction(const std::string& function_name, - const base::Value& arg); - void CallJavascriptFunction(const std::string& function_name, - const base::Value& arg1, - const base::Value& arg2); - void CallJavascriptFunction(const std::string& function_name, - const base::Value& arg1, - const base::Value& arg2, - const base::Value& arg3); - void CallJavascriptFunction(const std::string& function_name, - const base::Value& arg1, - const base::Value& arg2, - const base::Value& arg3, - const base::Value& arg4); - void CallJavascriptFunction(const std::string& function_name, - const std::vector<const base::Value*>& args); - - content::WebContents* web_contents() const { return web_contents_; } - - // An opaque identifier used to identify a WebUI. This can only be compared to - // kNoWebUI or other WebUI types. See GetWebUIType. - typedef void* TypeID; - - // A special WebUI type that signifies that a given page would not use the - // Web UI system. - static const TypeID kNoWebUI; - - // Returns JavaScript code that, when executed, calls the function specified - // by |function_name| with the arguments specified in |arg_list|. - static string16 GetJavascriptCall( + virtual void RegisterMessageCallback( + const std::string& message, + const MessageCallback& callback) OVERRIDE; + virtual void ProcessWebUIMessage(const GURL& source_url, + const std::string& message, + const base::ListValue& args) OVERRIDE; + virtual void CallJavascriptFunction( + const std::string& function_name) OVERRIDE; + virtual void CallJavascriptFunction(const std::string& function_name, + const base::Value& arg) OVERRIDE; + virtual void CallJavascriptFunction(const std::string& function_name, + const base::Value& arg1, + const base::Value& arg2) OVERRIDE; + virtual void CallJavascriptFunction(const std::string& function_name, + const base::Value& arg1, + const base::Value& arg2, + const base::Value& arg3) OVERRIDE; + virtual void CallJavascriptFunction(const std::string& function_name, + const base::Value& arg1, + const base::Value& arg2, + const base::Value& arg3, + const base::Value& arg4) OVERRIDE; + virtual void CallJavascriptFunction( const std::string& function_name, - const std::vector<const base::Value*>& arg_list); + const std::vector<const base::Value*>& args) OVERRIDE; + + // IPC::Channel::Listener implementation: + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; private: + // IPC message handling. + void OnWebUISend(const GURL& source_url, + const std::string& message, + const base::ListValue& args); + + // Execute a string of raw Javascript on the page. + void ExecuteJavascript(const string16& javascript); + // A map of message name -> message handling callback. typedef std::map<std::string, MessageCallback> MessageCallbackMap; MessageCallbackMap message_callbacks_; @@ -173,9 +97,6 @@ class CONTENT_EXPORT WebUI : public IPC::Channel::Listener { int bindings_; // The bindings from BindingsPolicy that should be enabled for // this page. - // Used by test mocks. See the public getters for more information. - bool register_callback_overwrites_; // Defaults to false. - // The WebUIMessageHandlers we own. std::vector<content::WebUIMessageHandler*> handlers_; |