diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 17:10:59 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 17:10:59 +0000 |
commit | f103ab7a3af66f93aa6b674598ee8c977917f5f2 (patch) | |
tree | 670587d6caf0d0fc0a864f7b8d6e7b8da8f11f6d /webkit | |
parent | ee2bd0350faae7e862af993b8884d6c9c48559a4 (diff) | |
download | chromium_src-f103ab7a3af66f93aa6b674598ee8c977917f5f2.zip chromium_src-f103ab7a3af66f93aa6b674598ee8c977917f5f2.tar.gz chromium_src-f103ab7a3af66f93aa6b674598ee8c977917f5f2.tar.bz2 |
Eliminate remaining WebCore dependencies from webplugin_impl.cc
Introduces WebPluginPageDelegate to hold the methods that only
existed on WebViewDelegate to allow WebPluginImpl to talk to the
RenderView. This enables us to eliminate those methods from
WebViewDelegate, which eliminates the last dependency on gfx/
native_widget_types.h in our WebKit interface!
WebViewDelegate grows a CreatePlugin method that returns a
WebKit::WebPlugin. It loses its CreatePluginDelegate method,
which now lives on WebPluginPageDelegate.
This change makes RenderView use WeakPtr when it hands itself to
each WebPluginDelegateProxy and WebPluginImpl instance. This
makes the memory management simpler.
This change also moves various WebPlugin* interfaces defined in
webkit/glue into the webkit_glue namespace. This was to help
reduce confusion with similarly named types in the WebKit
namespace.
WebKit::WebPluginParams is added to contain the set of parameters
used to construct a plugin.
WebPluginContainer gets a couple more methods to allow us to avoid
WebCore dependencies in WebPluginImpl.
R=jam
BUG=10036
TEST=none
Review URL: http://codereview.chromium.org/181014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25184 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
32 files changed, 713 insertions, 659 deletions
diff --git a/webkit/api/public/WebFrameClient.h b/webkit/api/public/WebFrameClient.h index 8140997..bdb38fa 100644 --- a/webkit/api/public/WebFrameClient.h +++ b/webkit/api/public/WebFrameClient.h @@ -51,9 +51,7 @@ namespace WebKit { // Factory methods ----------------------------------------------------- // May return null. - virtual WebPlugin* createPlugin( - WebFrame*, const WebURL& source, const WebString& mimeType, - const WebString& classID, WebString* actualMimeType) = 0; + virtual WebPlugin* createPlugin(WebFrame*, const WebPluginParams&) = 0; // May return null. virtual WebWorker* createWorker(WebFrame*, WebWorkerClient*) = 0; @@ -189,6 +187,9 @@ namespace WebKit { // FIXME need to add: // find-in-page + + protected: + ~WebFrameClient() { } }; } // namespace WebKit diff --git a/webkit/api/public/WebPlugin.h b/webkit/api/public/WebPlugin.h index 35caed3..c05db72 100644 --- a/webkit/api/public/WebPlugin.h +++ b/webkit/api/public/WebPlugin.h @@ -39,15 +39,18 @@ namespace WebKit { class WebDataSource; class WebFrame; class WebInputEvent; + class WebPluginContainer; class WebURL; class WebURLResponse; struct WebCursorInfo; + struct WebPluginParams; struct WebRect; struct WebURLError; template <typename T> class WebVector; class WebPlugin { public: + virtual bool initialize(WebPluginContainer*) = 0; virtual void destroy() = 0; virtual NPObject* scriptableObject() = 0; diff --git a/webkit/api/public/WebPluginContainer.h b/webkit/api/public/WebPluginContainer.h index 18013d7..29029e6 100644 --- a/webkit/api/public/WebPluginContainer.h +++ b/webkit/api/public/WebPluginContainer.h @@ -44,6 +44,16 @@ namespace WebKit { virtual void invalidate() = 0; virtual void invalidateRect(const WebRect&) = 0; + // Causes the container to report its current geometry via + // WebPlugin::updateGeometry. + virtual void reportGeometry() = 0; + + // Drop any references to script objects allocated by the plugin. + // These are objects derived from WebPlugin::scriptableObject. This is + // called when the plugin is being destroyed or if it needs to be + // re-initialized. + virtual void clearScriptObjects() = 0; + // Returns the scriptable object associated with the DOM element // containing the plugin. virtual NPObject* scriptableObjectForElement() = 0; diff --git a/webkit/api/public/WebPluginParams.h b/webkit/api/public/WebPluginParams.h new file mode 100644 index 0000000..28243c8 --- /dev/null +++ b/webkit/api/public/WebPluginParams.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebPluginParams_h +#define WebPluginParams_h + +#include "WebString.h" +#include "WebURL.h" +#include "WebVector.h" + +namespace WebKit { + + struct WebPluginParams { + WebURL url; + WebString mimeType; + WebVector<WebString> attributeNames; + WebVector<WebString> attributeValues; + bool loadManually; + }; + +} // namespace WebKit + +#endif diff --git a/webkit/api/src/WebPluginContainerImpl.cpp b/webkit/api/src/WebPluginContainerImpl.cpp index 6e2dc42..b537939 100644 --- a/webkit/api/src/WebPluginContainerImpl.cpp +++ b/webkit/api/src/WebPluginContainerImpl.cpp @@ -72,15 +72,7 @@ namespace WebKit { void WebPluginContainerImpl::setFrameRect(const IntRect& frameRect) { Widget::setFrameRect(frameRect); - - if (!parent()) - return; - - IntRect windowRect, clipRect; - Vector<IntRect> cutOutRects; - calculateGeometry(frameRect, windowRect, clipRect, cutOutRects); - - m_webPlugin->updateGeometry(windowRect, clipRect, cutOutRects, isVisible()); + reportGeometry(); } void WebPluginContainerImpl::paint(GraphicsContext* gc, const IntRect& damageRect) @@ -173,10 +165,7 @@ void WebPluginContainerImpl::handleEvent(Event* event) void WebPluginContainerImpl::frameRectsChanged() { Widget::frameRectsChanged(); - - // This is a hack to tickle re-positioning of the plugin in the case where - // our parent view was scrolled. - setFrameRect(frameRect()); + reportGeometry(); } void WebPluginContainerImpl::setParentVisible(bool parentVisible) @@ -206,7 +195,7 @@ void WebPluginContainerImpl::setParent(ScrollView* view) Widget::setParent(view); if (view) - setFrameRect(frameRect()); + reportGeometry(); } void WebPluginContainerImpl::invalidate() @@ -219,6 +208,26 @@ void WebPluginContainerImpl::invalidateRect(const WebRect& rect) invalidateRect(static_cast<IntRect>(rect)); } +void WebPluginContainerImpl::reportGeometry() +{ + if (!parent()) + return; + + IntRect windowRect, clipRect; + Vector<IntRect> cutOutRects; + calculateGeometry(frameRect(), windowRect, clipRect, cutOutRects); + + m_webPlugin->updateGeometry(windowRect, clipRect, cutOutRects, isVisible()); +} + +void WebPluginContainerImpl::clearScriptObjects() +{ + Frame* frame = m_element->document()->frame(); + if (!frame) + return; + frame->script()->cleanupScriptObjectsForPlugin(this); +} + NPObject* WebPluginContainerImpl::scriptableObjectForElement() { return m_element->getNPObject(); diff --git a/webkit/api/src/WebPluginContainerImpl.h b/webkit/api/src/WebPluginContainerImpl.h index 4e527d9..3f4114f 100644 --- a/webkit/api/src/WebPluginContainerImpl.h +++ b/webkit/api/src/WebPluginContainerImpl.h @@ -76,6 +76,8 @@ namespace WebKit { // WebPluginContainer methods virtual void invalidate(); virtual void invalidateRect(const WebRect&); + virtual void reportGeometry(); + virtual void clearScriptObjects(); virtual NPObject* scriptableObjectForElement(); virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed); virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData); diff --git a/webkit/glue/plugins/gtk_plugin_container_manager.cc b/webkit/glue/plugins/gtk_plugin_container_manager.cc index 4683e08..ecde3fb 100644 --- a/webkit/glue/plugins/gtk_plugin_container_manager.cc +++ b/webkit/glue/plugins/gtk_plugin_container_manager.cc @@ -52,7 +52,7 @@ void GtkPluginContainerManager::DestroyPluginContainer( } void GtkPluginContainerManager::MovePluginContainer( - const WebPluginGeometry& move) { + const webkit_glue::WebPluginGeometry& move) { DCHECK(host_widget_); GtkWidget *widget = MapIDToWidget(move.window); if (!widget) diff --git a/webkit/glue/plugins/gtk_plugin_container_manager.h b/webkit/glue/plugins/gtk_plugin_container_manager.h index 30a6b1a..54ce819 100644 --- a/webkit/glue/plugins/gtk_plugin_container_manager.h +++ b/webkit/glue/plugins/gtk_plugin_container_manager.h @@ -11,7 +11,10 @@ #include "base/gfx/native_widget_types.h" typedef struct _GtkWidget GtkWidget; + +namespace webkit_glue { struct WebPluginGeometry; +} // Helper class that creates and manages plugin containers (GtkSocket). class GtkPluginContainerManager { @@ -29,7 +32,7 @@ class GtkPluginContainerManager { // Takes an update from WebKit about a plugin's position and side and moves // the plugin accordingly. - void MovePluginContainer(const WebPluginGeometry& move); + void MovePluginContainer(const webkit_glue::WebPluginGeometry& move); private: // Maps a plugin XID to the corresponding container widget. diff --git a/webkit/glue/plugins/mozilla_extensions.cc b/webkit/glue/plugins/mozilla_extensions.cc index 4b1b46e..2ca0a50 100644 --- a/webkit/glue/plugins/mozilla_extensions.cc +++ b/webkit/glue/plugins/mozilla_extensions.cc @@ -273,7 +273,7 @@ NS_IMETHODIMP MozillaExtensionApi::GetCookie( if (!plugin_instance_) return NS_ERROR_FAILURE; - WebPlugin* webplugin = plugin_instance_->webplugin(); + webkit_glue::WebPlugin* webplugin = plugin_instance_->webplugin(); if (!webplugin) return NS_ERROR_FAILURE; @@ -306,7 +306,7 @@ NS_IMETHODIMP MozillaExtensionApi::SetCookie( if (!plugin_instance_) return NS_ERROR_FAILURE; - WebPlugin* webplugin = plugin_instance_->webplugin(); + webkit_glue::WebPlugin* webplugin = plugin_instance_->webplugin(); if (!webplugin) return NS_ERROR_FAILURE; diff --git a/webkit/glue/plugins/plugin_instance.h b/webkit/glue/plugins/plugin_instance.h index 5639211..352dab5 100644 --- a/webkit/glue/plugins/plugin_instance.h +++ b/webkit/glue/plugins/plugin_instance.h @@ -21,9 +21,12 @@ #include "googleurl/src/gurl.h" #include "third_party/npapi/bindings/npapi.h" -class WebPlugin; class MessageLoop; +namespace webkit_glue { +class WebPlugin; +} + namespace NPAPI { class PluginLib; @@ -88,8 +91,10 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { void set_transparent(bool value) { transparent_ = value; } // Get/Set the WebPlugin associated with this instance - WebPlugin* webplugin() { return webplugin_; } - void set_web_plugin(WebPlugin* webplugin) { webplugin_ = webplugin; } + webkit_glue::WebPlugin* webplugin() { return webplugin_; } + void set_web_plugin(webkit_glue::WebPlugin* webplugin) { + webplugin_ = webplugin; + } // Get the mimeType for this plugin stream const std::string &mime_type() { return mime_type_; } @@ -225,7 +230,7 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { gfx::PluginWindowHandle window_handle_; bool windowless_; bool transparent_; - WebPlugin* webplugin_; + webkit_glue::WebPlugin* webplugin_; std::string mime_type_; GURL get_url_; intptr_t get_notify_data_; diff --git a/webkit/glue/plugins/plugin_stream.h b/webkit/glue/plugins/plugin_stream.h index 80b88c56..97bea1c 100644 --- a/webkit/glue/plugins/plugin_stream.h +++ b/webkit/glue/plugins/plugin_stream.h @@ -12,7 +12,9 @@ #include "base/ref_counted.h" #include "third_party/npapi/bindings/npapi.h" +namespace webkit_glue { class WebPluginResourceClient; +} namespace NPAPI { @@ -59,7 +61,9 @@ class PluginStream : public base::RefCounted<PluginStream> { // Close the stream. virtual bool Close(NPReason reason); - virtual WebPluginResourceClient* AsResourceClient() { return NULL; } + virtual webkit_glue::WebPluginResourceClient* AsResourceClient() { + return NULL; + } // Cancels any HTTP requests initiated by the stream. virtual void CancelRequest() {} diff --git a/webkit/glue/plugins/plugin_stream_url.h b/webkit/glue/plugins/plugin_stream_url.h index 1f5fe57..b4a61c3 100644 --- a/webkit/glue/plugins/plugin_stream_url.h +++ b/webkit/glue/plugins/plugin_stream_url.h @@ -16,7 +16,7 @@ class PluginInstance; // A NPAPI Stream based on a URL. class PluginStreamUrl : public PluginStream, - public WebPluginResourceClient { + public webkit_glue::WebPluginResourceClient { public: // Create a new stream for sending to the plugin by fetching // a URL. If notifyNeeded is set, then the plugin will be notified @@ -34,8 +34,8 @@ class PluginStreamUrl : public PluginStream, // it is still loading. virtual bool Close(NPReason reason); - virtual WebPluginResourceClient* AsResourceClient() { - return static_cast<WebPluginResourceClient*>(this); + virtual webkit_glue::WebPluginResourceClient* AsResourceClient() { + return static_cast<webkit_glue::WebPluginResourceClient*>(this); } virtual void CancelRequest(); diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index 89285b6..078b6cf 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -21,6 +21,9 @@ #include "webkit/glue/plugins/plugin_stream_url.h" #include "webkit/glue/webkit_glue.h" +using webkit_glue::WebPlugin; +using webkit_glue::WebPluginDelegate; +using webkit_glue::WebPluginResourceClient; using WebKit::WebCursorInfo; using WebKit::WebKeyboardEvent; using WebKit::WebInputEvent; @@ -30,17 +33,17 @@ WebPluginDelegate* WebPluginDelegate::Create( const FilePath& filename, const std::string& mime_type, gfx::PluginWindowHandle containing_view) { - scoped_refptr<NPAPI::PluginLib> plugin = + scoped_refptr<NPAPI::PluginLib> plugin_lib = NPAPI::PluginLib::CreatePluginLib(filename); - if (plugin.get() == NULL) + if (plugin_lib.get() == NULL) return NULL; - NPError err = plugin->NP_Initialize(); + NPError err = plugin_lib->NP_Initialize(); if (err != NPERR_NO_ERROR) return NULL; scoped_refptr<NPAPI::PluginInstance> instance = - plugin->CreateInstance(mime_type); + plugin_lib->CreateInstance(mime_type); return new WebPluginDelegateImpl(containing_view, instance.get()); } @@ -52,7 +55,7 @@ bool WebPluginDelegateImpl::Initialize(const GURL& url, bool load_manually) { plugin_ = plugin; - instance_->set_web_plugin(plugin); + instance_->set_web_plugin(plugin_); NPAPI::PluginInstance* old_instance = NPAPI::PluginInstance::SetInitializingInstance(instance_); @@ -86,7 +89,7 @@ bool WebPluginDelegateImpl::Initialize(const GURL& url, instance_->set_window_handle(parent_); } - PlatformInitialize(plugin); + PlatformInitialize(); plugin_url_ = url.spec(); diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index 9ecd733..51f3839 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -29,7 +29,7 @@ class PluginInstance; // An implementation of WebPluginDelegate that proxies all calls to // the plugin process. -class WebPluginDelegateImpl : public WebPluginDelegate { +class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { public: static bool IsPluginDelegateWindow(gfx::NativeWindow window); static bool GetPluginNameFromWindow(gfx::NativeWindow window, @@ -45,7 +45,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { char** argn, char** argv, int argc, - WebPlugin* plugin, + webkit_glue::WebPlugin* plugin, bool load_manually); virtual void UpdateGeometry(const gfx::Rect& window_rect, const gfx::Rect& clip_rect); @@ -76,15 +76,16 @@ class WebPluginDelegateImpl : public WebPluginDelegate { virtual void DidManualLoadFail(); virtual FilePath GetPluginPath(); virtual void InstallMissingPlugin(); - virtual WebPluginResourceClient* CreateResourceClient(int resource_id, - const GURL& url, - bool notify_needed, - intptr_t notify_data, - intptr_t stream); + virtual webkit_glue::WebPluginResourceClient* CreateResourceClient( + int resource_id, + const GURL& url, + bool notify_needed, + intptr_t notify_data, + intptr_t stream); virtual bool IsWindowless() const { return windowless_ ; } - virtual const gfx::Rect& GetRect() const { return window_rect_; } - virtual const gfx::Rect& GetClipRect() const { return clip_rect_; } + virtual gfx::Rect GetRect() const { return window_rect_; } + virtual gfx::Rect GetClipRect() const { return clip_rect_; } virtual int GetQuirks() const { return quirks_; } #if defined(OS_MACOSX) @@ -100,9 +101,8 @@ class WebPluginDelegateImpl : public WebPluginDelegate { NPAPI::PluginInstance *instance); ~WebPluginDelegateImpl(); - // Called by Initialize(), used for platform-specific initialization - // code. - void PlatformInitialize(WebPlugin* plugin); + // Called by Initialize() for platform-specific initialization. + void PlatformInitialize(); // Called by DestroyInstance(), used for platform-specific destruction. void PlatformDestroyInstance(); @@ -185,7 +185,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { // used by windowed and windowless plugins bool windowless_; - WebPlugin* plugin_; + webkit_glue::WebPlugin* plugin_; scoped_refptr<NPAPI::PluginInstance> instance_; #if defined(OS_WIN) @@ -308,7 +308,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { // Holds the current cursor set by the windowless plugin. WebCursor current_windowless_cursor_; - friend class WebPluginDelegate; + friend class webkit_glue::WebPluginDelegate; DISALLOW_EVIL_CONSTRUCTORS(WebPluginDelegateImpl); }; diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc index ae169ae..7673699 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc @@ -84,10 +84,10 @@ WebPluginDelegateImpl::~WebPluginDelegateImpl() { } } -void WebPluginDelegateImpl::PlatformInitialize(WebPlugin* plugin) { +void WebPluginDelegateImpl::PlatformInitialize() { gfx::PluginWindowHandle handle = windowless_ ? 0 : gtk_plug_get_id(GTK_PLUG(plug_)); - plugin->SetWindow(handle); + plugin_->SetWindow(handle); } void WebPluginDelegateImpl::PlatformDestroyInstance() { diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index 485c6af..08e91bc 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -26,6 +26,9 @@ #include "webkit/glue/plugins/plugin_stream_url.h" #include "webkit/glue/webkit_glue.h" +using webkit_glue::WebPlugin; +using webkit_glue::WebPluginDelegate; +using webkit_glue::WebPluginResourceClient; using WebKit::WebCursorInfo; using WebKit::WebKeyboardEvent; using WebKit::WebInputEvent; @@ -160,9 +163,10 @@ void WebPluginDelegateImpl::DestroyInstance() { } } -void WebPluginDelegateImpl::PlatformInitialize(WebPlugin* plugin) { +void WebPluginDelegateImpl::PlatformInitialize() { // TODO(port): implement these after unforking. } + void WebPluginDelegateImpl::PlatformDestroyInstance() { // TODO(port): implement these after unforking. } diff --git a/webkit/glue/plugins/webplugin_delegate_impl_win.cc b/webkit/glue/plugins/webplugin_delegate_impl_win.cc index 1a3c091..a36d5fc 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_win.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_win.cc @@ -245,12 +245,12 @@ void WebPluginDelegateImpl::PluginDestroyed() { } } -void WebPluginDelegateImpl::PlatformInitialize(WebPlugin* plugin) { - plugin->SetWindow(windowed_handle_); +void WebPluginDelegateImpl::PlatformInitialize() { + plugin_->SetWindow(windowed_handle_); if (windowless_) { CreateDummyWindowForActivation(); handle_event_pump_messages_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); - plugin->SetWindowlessPumpEvent(handle_event_pump_messages_event_); + plugin_->SetWindowlessPumpEvent(handle_event_pump_messages_event_); } // The windowless version of the Silverlight plugin calls the diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index f423c2a..63d4d9f 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -31,10 +31,9 @@ #include "base/string_util.h" #include "net/base/mime_util.h" #include "net/base/net_errors.h" -#if defined(OS_WIN) -#include "webkit/activex_shim/activex_shared.h" -#endif #include "webkit/api/public/WebForm.h" +#include "webkit/api/public/WebPlugin.h" +#include "webkit/api/public/WebPluginParams.h" #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebURLError.h" #include "webkit/api/public/WebVector.h" @@ -49,8 +48,6 @@ #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webframeloaderclient_impl.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/glue/webplugin_delegate.h" -#include "webkit/glue/webplugin_impl.h" #include "webkit/glue/webview_delegate.h" #include "webkit/glue/webview_impl.h" @@ -63,8 +60,10 @@ using WebKit::WebData; using WebKit::WebDataSourceImpl; using WebKit::WebNavigationType; using WebKit::WebNavigationPolicy; +using WebKit::WebPlugin; using WebKit::WebPluginContainerImpl; using WebKit::WebPluginLoadObserver; +using WebKit::WebPluginParams; using WebKit::WebString; using WebKit::WebURL; using WebKit::WebURLError; @@ -82,6 +81,14 @@ enum { ERR_POLICY_CHANGE = -10000, }; +static void CopyStringVector( + const Vector<String>& input, WebVector<WebString>* output) { + WebVector<WebString> result(input.size()); + for (size_t i = 0; i < input.size(); ++i) + result[i] = webkit_glue::StringToWebString(input[i]); + output->swap(result); +} + WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) : webframe_(frame), has_representation_(false), @@ -1212,78 +1219,14 @@ PassRefPtr<Frame> WebFrameLoaderClient::createFrame( return webframe_->CreateChildFrame(frame_request, owner_element); } -// Utility function to convert a vector to an array of char*'s. -// Caller is responsible to free memory with DeleteToArray(). -static char** ToArray(const Vector<WebCore::String> &vector) { - char **rv = new char *[vector.size()+1]; - unsigned int index = 0; - for (index = 0; index < vector.size(); ++index) { - WebCore::CString src = vector[index].utf8(); - rv[index] = new char[src.length() + 1]; - base::strlcpy(rv[index], src.data(), src.length() + 1); - rv[index][src.length()] = '\0'; - } - rv[index] = 0; - return rv; -} - -static void DeleteToArray(char** arr) { - char **ptr = arr; - while (*ptr != 0) { - delete [] *ptr; - ++ptr; - } - delete [] arr; -} - -PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize& size, // TODO(erikkay): how do we use this? - HTMLPlugInElement* element, - const KURL&url, - const Vector<String>& param_names, - const Vector<String>& param_values, - const String& mime_type, - bool load_manually) { - WebViewImpl* webview = webframe_->GetWebViewImpl(); - WebViewDelegate* d = webview->delegate(); - if (!d) - return NULL; - - GURL gurl = webkit_glue::KURLToGURL(url); - std::string my_mime_type = - webkit_glue::CStringToStdString(mime_type.latin1()); - StringToLowerASCII(&my_mime_type); - - // Get the classid and version from attributes of the object. - std::string combined_clsid; -#if defined(OS_WIN) - std::string clsid, version; - if (activex_shim::IsMimeTypeActiveX(my_mime_type)) { - GURL url = webframe_->url(); - for (unsigned int i = 0; i < param_names.size(); i++) { - String lowercase_param_name = param_names[i].lower(); - if (lowercase_param_name == "classid") { - activex_shim::GetClsidFromClassidAttribute( - webkit_glue::CStringToStdString(param_values[i].latin1()), &clsid); - } else if (lowercase_param_name == "codebase") { - version = activex_shim::GetVersionFromCodebaseAttribute( - webkit_glue::CStringToStdString(param_values[i].latin1())); - } - } - - // Attempt to map this clsid to a known NPAPI mime type if possible, failing - // which we attempt to load the activex shim for the clsid. - if (!activex_shim::GetMimeTypeForClsid(clsid, &my_mime_type)) { - // We need to pass the combined clsid + version to PluginsList, so that it - // would detect if the requested version is installed. If not, it needs - // to use the default plugin to update the control. - if (!version.empty()) - combined_clsid = clsid + "#" + version; - else - combined_clsid = clsid; - } - } -#endif - +PassRefPtr<Widget> WebFrameLoaderClient::createPlugin( + const IntSize& size, // TODO(erikkay): how do we use this? + HTMLPlugInElement* element, + const KURL& url, + const Vector<String>& param_names, + const Vector<String>& param_values, + const String& mime_type, + bool load_manually) { #if defined(OS_POSIX) // WebCore asks us to make a plugin even if we don't have a // registered handler, with a comment saying it's so we can display @@ -1298,29 +1241,29 @@ PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize& size, // TO return NULL; #endif - std::string actual_mime_type; - WebPluginDelegate* plugin_delegate = - d->CreatePluginDelegate(webframe_->GetWebViewImpl(), gurl, my_mime_type, - combined_clsid, &actual_mime_type); - if (!plugin_delegate) + WebViewImpl* webview = webframe_->GetWebViewImpl(); + if (!webview->delegate()) return NULL; - if (!actual_mime_type.empty()) - my_mime_type = actual_mime_type; + WebPluginParams params; + params.url = webkit_glue::KURLToWebURL(url); + params.mimeType = webkit_glue::StringToWebString(mime_type); + CopyStringVector(param_names, ¶ms.attributeNames); + CopyStringVector(param_values, ¶ms.attributeValues); + params.loadManually = load_manually; - DCHECK(param_names.size() == param_values.size()); + WebPlugin* webplugin = webview->delegate()->CreatePlugin(webframe_, params); + if (!webplugin) + return NULL; - char **argn = ToArray(param_names); - char **argv = ToArray(param_values); - int argc = static_cast<int>(param_names.size()); - RefPtr<Widget> result = WebPluginImpl::Create(gurl, argn, argv, argc, element, - webframe_, plugin_delegate, - load_manually, my_mime_type); + // The container takes ownership of the WebPlugin. + RefPtr<WebPluginContainerImpl> container = + WebPluginContainerImpl::create(element, webplugin); - DeleteToArray(argn); - DeleteToArray(argv); + if (!webplugin->initialize(container.get())) + return NULL; - return result; + return container; } // This method gets called when a plugin is put in place of html content diff --git a/webkit/glue/webplugin.h b/webkit/glue/webplugin.h index 886b031..3ab6d35 100644 --- a/webkit/glue/webplugin.h +++ b/webkit/glue/webplugin.h @@ -1,9 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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 WEBKIT_GLUE_WEBPLUGIN_H__ -#define WEBKIT_GLUE_WEBPLUGIN_H__ +#ifndef WEBKIT_GLUE_WEBPLUGIN_H_ +#define WEBKIT_GLUE_WEBPLUGIN_H_ #include <string> #include <vector> @@ -18,10 +18,17 @@ typedef void* HANDLE; class GURL; -class WebPluginResourceClient; - struct NPObject; +namespace WebKit { +class WebFrame; +} + +namespace webkit_glue { + +class WebPluginParentView; +class WebPluginResourceClient; + // Describes the new location for a plugin window. struct WebPluginGeometry { // On Windows, this is the plugin window in the plugin process. @@ -37,20 +44,11 @@ struct WebPluginGeometry { bool visible; }; - -enum RoutingStatus { - ROUTED, - NOT_ROUTED, - INVALID_URL, - GENERAL_FAILURE -}; - // The WebKit side of a plugin implementation. It provides wrappers around // operations that need to interact with the frame and other WebCore objects. class WebPlugin { public: - WebPlugin() { } - virtual ~WebPlugin() { } + virtual ~WebPlugin() {} // Called by the plugin delegate to let the WebPlugin know if the plugin is // windowed (i.e. handle is not NULL) or windowless (handle is NULL). This @@ -127,9 +125,6 @@ class WebPlugin { // Defers the loading of the resource identified by resource_id. This is // controlled by the defer parameter. virtual void SetDeferResourceLoading(int resource_id, bool defer) = 0; - - private: - DISALLOW_EVIL_CONSTRUCTORS(WebPlugin); }; // Simpler version of ResourceHandleClient that lends itself to proxying. @@ -151,5 +146,6 @@ class WebPluginResourceClient { virtual bool IsMultiByteResponseExpected() = 0; }; +} // namespace webkit_glue -#endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_H__ +#endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_H_ diff --git a/webkit/glue/webplugin_delegate.cc b/webkit/glue/webplugin_delegate.cc deleted file mode 100644 index bc8f692..0000000 --- a/webkit/glue/webplugin_delegate.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 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 "config.h" - -#undef LOG - -#include "webkit/glue/webplugin_delegate.h" - -#include "base/logging.h" -#include "base/gfx/rect.h" - -bool WebPluginDelegate::IsWindowless() const { - NOTREACHED(); - return false; -} - -const gfx::Rect& WebPluginDelegate::GetRect() const { - NOTREACHED(); - static gfx::Rect dummy; - return dummy; -} - -const gfx::Rect& WebPluginDelegate::GetClipRect() const { - NOTREACHED(); - return GetRect(); -} - -// Returns a combinaison of PluginQuirks. -int WebPluginDelegate::GetQuirks() const { - NOTREACHED(); - return 0; -} diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index c1427cd..de83954 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -11,12 +11,9 @@ #include "base/string16.h" #include "third_party/npapi/bindings/npapi.h" -struct NPObject; - class FilePath; class GURL; -class WebPlugin; -class WebPluginResourceClient; +struct NPObject; namespace WebKit { class WebInputEvent; @@ -27,6 +24,11 @@ namespace gfx { class Rect; } +namespace webkit_glue { + +class WebPlugin; +class WebPluginResourceClient; + // This is the interface that a plugin implementation needs to provide. class WebPluginDelegate { public: @@ -43,7 +45,6 @@ class WebPluginDelegate { PLUGIN_QUIRK_WINDOWLESS_INVALIDATE_AFTER_SET_WINDOW = 512, // Linux }; - WebPluginDelegate() {} virtual ~WebPluginDelegate() {} static WebPluginDelegate* Create(const FilePath& filename, @@ -59,8 +60,8 @@ class WebPluginDelegate { // be passed from webkit. if false indicates that the plugin should download // the data. This also controls whether the plugin is instantiated as a full // page plugin (NP_FULL) or embedded (NP_EMBED). - virtual bool Initialize(const GURL& url, char** argn, char** argv, - int argc, WebPlugin* plugin, bool load_manually) = 0; + virtual bool Initialize(const GURL& url, char** argn, char** argv, int argc, + WebPlugin* plugin, bool load_manually) = 0; // Called when the WebPlugin is being destroyed. This is a signal to the // delegate that it should tear-down the plugin implementation and not call @@ -138,17 +139,16 @@ class WebPluginDelegate { intptr_t notify_data, intptr_t stream) = 0; - virtual bool IsWindowless() const; + virtual bool IsWindowless() const = 0; - virtual const gfx::Rect& GetRect() const; + virtual gfx::Rect GetRect() const = 0; - virtual const gfx::Rect& GetClipRect() const; + virtual gfx::Rect GetClipRect() const = 0; // Returns a combination of PluginQuirks. - virtual int GetQuirks() const; - - private: - DISALLOW_COPY_AND_ASSIGN(WebPluginDelegate); + virtual int GetQuirks() const = 0; }; -#endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_DELEGATE_H_ +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_WEBPLUGIN_DELEGATE_H_ diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index 09f2b3b..54576a6 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -1,58 +1,45 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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 "config.h" - -#include "Document.h" -#include "DocumentLoader.h" -#include "FormState.h" -#include "Frame.h" -#include "FrameLoader.h" -#include "FrameLoadRequest.h" -#include "HTMLFormElement.h" -#include "KURL.h" -#include "PlatformString.h" -#include "ResourceResponse.h" -#include "ScriptController.h" -#include "ScriptValue.h" -#include "Widget.h" - -#undef LOG #include "base/gfx/rect.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" #include "net/base/escape.h" +#include "skia/ext/platform_canvas.h" +#if defined(OS_WIN) +#include "webkit/activex_shim/activex_shared.h" +#endif #include "webkit/api/public/WebConsoleMessage.h" +#include "webkit/api/public/WebCString.h" #include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebData.h" +#include "webkit/api/public/WebFrame.h" #include "webkit/api/public/WebHTTPBody.h" #include "webkit/api/public/WebHTTPHeaderVisitor.h" #include "webkit/api/public/WebInputEvent.h" #include "webkit/api/public/WebKit.h" #include "webkit/api/public/WebKitClient.h" +#include "webkit/api/public/WebPluginContainer.h" +#include "webkit/api/public/WebPluginParams.h" #include "webkit/api/public/WebRect.h" -#include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebURLLoader.h" #include "webkit/api/public/WebURLLoaderClient.h" #include "webkit/api/public/WebURLResponse.h" -#include "webkit/api/public/WebVector.h" -#include "webkit/api/src/WebPluginContainerImpl.h" -#include "webkit/glue/chrome_client_impl.h" -#include "webkit/glue/glue_util.h" #include "webkit/glue/multipart_response_delegate.h" -#include "webkit/glue/webkit_glue.h" #include "webkit/glue/webplugin_impl.h" #include "webkit/glue/plugins/plugin_host.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/webplugin_delegate.h" -#include "webkit/glue/webview_impl.h" +#include "webkit/glue/webplugin_page_delegate.h" +#include "webkit/glue/webview.h" #include "googleurl/src/gurl.h" using WebKit::WebCanvas; using WebKit::WebConsoleMessage; +using WebKit::WebCString; using WebKit::WebCursorInfo; using WebKit::WebData; using WebKit::WebDataSource; @@ -63,7 +50,7 @@ using WebKit::WebInputEvent; using WebKit::WebKeyboardEvent; using WebKit::WebMouseEvent; using WebKit::WebPluginContainer; -using WebKit::WebPluginContainerImpl; +using WebKit::WebPluginParams; using WebKit::WebRect; using WebKit::WebString; using WebKit::WebURL; @@ -75,6 +62,7 @@ using WebKit::WebURLResponse; using WebKit::WebVector; using webkit_glue::MultipartResponseDelegate; +namespace webkit_glue { namespace { // This class handles individual multipart responses. It is instantiated when @@ -209,60 +197,87 @@ void GetResponseInfo(const WebURLResponse& response, } } +// Utility function to convert a vector to an array of char*'s. +// Caller is responsible to free memory with DeleteArray(). +static char** ToArray(const WebVector<WebString>& input) { + char** array = new char*[input.size() + 1]; + size_t index; + for (index = 0; index < input.size(); ++index) { + const WebCString& src = input[index].utf8(); + array[index] = new char[src.length() + 1]; + base::strlcpy(array[index], src.data(), src.length() + 1); + array[index][src.length()] = '\0'; + } + array[index] = 0; + return array; +} + +static void DeleteArray(char** array) { + char** ptr = array; + while (*ptr) { + delete[] *ptr; + ++ptr; + } + delete[] array; +} + } // namespace -PassRefPtr<WebCore::Widget> WebPluginImpl::Create( - const GURL& url, - char** argn, - char** argv, - int argc, - WebCore::HTMLPlugInElement* element, - WebFrameImpl* frame, - WebPluginDelegate* delegate, - bool load_manually, - const std::string& mime_type) { - // NOTE: frame contains element - - WebPluginImpl* webplugin = new WebPluginImpl( - frame, delegate, url, load_manually, mime_type, argc, argn, argv); - - if (!delegate->Initialize(url, argn, argv, argc, webplugin, load_manually)) { - delegate->PluginDestroyed(); - delete webplugin; - return NULL; +// WebKit::WebPlugin ---------------------------------------------------------- + +bool WebPluginImpl::initialize(WebPluginContainer* container) { + if (!page_delegate_) + return false; + + // Get the classid and version from attributes of the object. + std::string combined_clsid; +#if defined(OS_WIN) + std::string clsid, version; + if (activex_shim::IsMimeTypeActiveX(mime_type_)) { + for (size_t i = 0; i < arg_count_; i++) { + const char* param_name = arg_names_[i]; + const char* param_value = arg_values_[i]; + if (base::strcasecmp(param_name, "classid") == 0) { + activex_shim::GetClsidFromClassidAttribute(param_value, &clsid); + } else if (base::strcasecmp(param_name, "codebase") == 0) { + version = activex_shim::GetVersionFromCodebaseAttribute(param_value); + } + } + + // Attempt to map this clsid to a known NPAPI mime type if possible, failing + // which we attempt to load the activex shim for the clsid. + if (!activex_shim::GetMimeTypeForClsid(clsid, &mime_type_)) { + // We need to pass the combined clsid + version to PluginsList, so that it + // would detect if the requested version is installed. If not, it needs + // to use the default plugin to update the control. + if (!version.empty()) + combined_clsid = clsid + "#" + version; + else + combined_clsid = clsid; + } } +#endif - PassRefPtr<WebPluginContainerImpl> container = - WebPluginContainerImpl::create(element, webplugin); - webplugin->SetContainer(container.get()); - return container; -} + std::string actual_mime_type; + WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( + plugin_url_, mime_type_, combined_clsid, &actual_mime_type); + if (!plugin_delegate) + return NULL; -WebPluginImpl::WebPluginImpl(WebFrameImpl* webframe, - WebPluginDelegate* delegate, - const GURL& plugin_url, - bool load_manually, - const std::string& mime_type, - int arg_count, - char** arg_names, - char** arg_values) - : windowless_(false), - window_(NULL), - webframe_(webframe), - delegate_(delegate), - container_(NULL), - plugin_url_(plugin_url), - load_manually_(load_manually), - first_geometry_update_(true), - ignore_response_error_(false), - mime_type_(mime_type), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + bool ok = plugin_delegate->Initialize( + plugin_url_, arg_names_, arg_values_, arg_count_, this, load_manually_); + if (!ok) { + plugin_delegate->PluginDestroyed(); + return false; + } - ArrayToVector(arg_count, arg_names, &arg_names_); - ArrayToVector(arg_count, arg_values, &arg_values_); -} + if (!actual_mime_type.empty()) + mime_type_ = actual_mime_type; + delegate_ = plugin_delegate; -// WebKit::WebPlugin ----------------------------------------------------------- + SetContainer(container); + return true; +} void WebPluginImpl::destroy() { SetContainer(NULL); @@ -291,23 +306,20 @@ void WebPluginImpl::paint(WebCanvas* canvas, const WebRect& paint_rect) { void WebPluginImpl::updateGeometry( const WebRect& window_rect, const WebRect& clip_rect, const WebVector<WebRect>& cutout_rects, bool is_visible) { - if (window_) { - WebViewDelegate* view_delegate = GetWebViewDelegate(); - if (view_delegate) { - // Notify the window hosting the plugin (the WebViewDelegate) that - // it needs to adjust the plugin, so that all the HWNDs can be moved - // at the same time. - WebPluginGeometry move; - move.window = window_; - move.window_rect = window_rect; - move.clip_rect = clip_rect; - for (size_t i = 0; i < cutout_rects.size(); ++i) - move.cutout_rects.push_back(cutout_rects[i]); - move.rects_valid = true; - move.visible = is_visible; - - view_delegate->DidMovePlugin(move); - } + if (window_ && page_delegate_) { + // Notify the window hosting the plugin (the WebViewDelegate) that + // it needs to adjust the plugin, so that all the HWNDs can be moved + // at the same time. + WebPluginGeometry move; + move.window = window_; + move.window_rect = window_rect; + move.clip_rect = clip_rect; + for (size_t i = 0; i < cutout_rects.size(); ++i) + move.cutout_rects.push_back(cutout_rects[i]); + move.rects_valid = true; + move.visible = is_visible; + + page_delegate_->DidMovePlugin(move); } if (first_geometry_update_ || window_rect != window_rect_ || @@ -343,11 +355,7 @@ void WebPluginImpl::updateFocus(bool focused) { } void WebPluginImpl::updateVisibility(bool visible) { - if (!window_) - return; - - WebViewDelegate* view_delegate = GetWebViewDelegate(); - if (!view_delegate) + if (!window_ || !page_delegate_) return; WebPluginGeometry move; @@ -357,7 +365,7 @@ void WebPluginImpl::updateVisibility(bool visible) { move.rects_valid = false; move.visible = visible; - view_delegate->DidMovePlugin(move); + page_delegate_->DidMovePlugin(move); } bool WebPluginImpl::acceptsInputEvents() { @@ -415,19 +423,43 @@ void WebPluginImpl::didFailLoadingFrameRequest( // ----------------------------------------------------------------------------- -WebPluginImpl::~WebPluginImpl() { +WebPluginImpl::WebPluginImpl( + WebFrame* webframe, const WebPluginParams& params, + const base::WeakPtr<WebPluginPageDelegate>& page_delegate) + : windowless_(false), + window_(NULL), + page_delegate_(page_delegate), + webframe_(webframe), + delegate_(NULL), + container_(NULL), + plugin_url_(params.url), + load_manually_(params.loadManually), + first_geometry_update_(true), + ignore_response_error_(false), + mime_type_(params.mimeType.utf8()), + arg_names_(ToArray(params.attributeNames)), + arg_values_(ToArray(params.attributeValues)), + arg_count_(params.attributeNames.size()), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); + StringToLowerASCII(&mime_type_); } +WebPluginImpl::~WebPluginImpl() { + if (arg_names_) + DeleteArray(arg_names_); + if (arg_values_) + DeleteArray(arg_values_); +} void WebPluginImpl::SetWindow(gfx::PluginWindowHandle window) { if (window) { DCHECK(!windowless_); // Make sure not called twice. window_ = window; - WebViewDelegate* view_delegate = GetWebViewDelegate(); - if (view_delegate) { + if (page_delegate_) { // Tell the view delegate that the plugin window was created, so that it // can create necessary container widgets. - view_delegate->CreatedPluginWindow(window); + page_delegate_->CreatedPluginWindow(window); } } else { DCHECK(!window_); // Make sure not called twice. @@ -438,10 +470,8 @@ void WebPluginImpl::SetWindow(gfx::PluginWindowHandle window) { void WebPluginImpl::WillDestroyWindow(gfx::PluginWindowHandle window) { DCHECK_EQ(window, window_); window_ = NULL; - WebViewDelegate* view_delegate = GetWebViewDelegate(); - if (!view_delegate) - return; - view_delegate->WillDestroyPluginWindow(window); + if (page_delegate_) + page_delegate_->WillDestroyPluginWindow(window); } GURL WebPluginImpl::CompleteURL(const char* url) { @@ -475,8 +505,8 @@ bool WebPluginImpl::SetPostData(WebURLRequest* request, bool rv = NPAPI::PluginHost::SetPostData(buf, length, &names, &values, &body); for (size_t i = 0; i < names.size(); ++i) { - request->addHTTPHeaderField(webkit_glue::StdStringToWebString(names[i]), - webkit_glue::StdStringToWebString(values[i])); + request->addHTTPHeaderField(WebString::fromUTF8(names[i]), + WebString::fromUTF8(values[i])); } WebString content_type_header = WebString::fromUTF8("Content-Type"); @@ -498,13 +528,16 @@ bool WebPluginImpl::SetPostData(WebURLRequest* request, return rv; } -RoutingStatus WebPluginImpl::RouteToFrame(const char *method, - bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify_needed, - intptr_t notify_data, - const char* url, GURL* unused) { +WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( + const char *method, + bool is_javascript_url, + const char* target, + unsigned int len, + const char* buf, + bool is_file_data, + bool notify_needed, + intptr_t notify_data, + const char* url) { // If there is no target, there is nothing to do if (!target) return NOT_ROUTED; @@ -594,10 +627,9 @@ std::string WebPluginImpl::GetCookies(const GURL& url, const GURL& policy_url) { void WebPluginImpl::ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, std::string* json_retval) { - WebViewDelegate* view_delegate = GetWebViewDelegate(); - if (view_delegate) { - view_delegate->ShowModalHTMLDialog( - url, width, height, json_arguments, json_retval); + if (page_delegate_) { + page_delegate_->ShowModalHTMLDialogForPlugin( + url, gfx::Size(width, height), json_arguments, json_retval); } } @@ -767,9 +799,8 @@ void WebPluginImpl::didFinishLoading(WebURLLoader* loader) { if (index != multi_part_response_map_.end()) { delete (*index).second; multi_part_response_map_.erase(index); - - WebView* webview = webframe_->GetWebViewImpl(); - webview->GetDelegate()->DidStopLoading(webview); + if (page_delegate_) + page_delegate_->DidStopLoadingForPlugin(); } loader->setDefersLoading(true); WebPluginResourceClient* resource_client = client_info->client; @@ -807,9 +838,8 @@ void WebPluginImpl::RemoveClient(WebURLLoader* loader) { } void WebPluginImpl::SetContainer(WebPluginContainer* container) { - if (container == NULL) { + if (!container) TearDownPluginInstance(NULL); - } container_ = container; } @@ -836,10 +866,9 @@ void WebPluginImpl::HandleURLRequestInternal( // case in that the request is a javascript url and the target is "_self", // in which case we route the output to the plugin rather than routing it // to the plugin's frame. - GURL complete_url; - int routing_status = RouteToFrame(method, is_javascript_url, target, len, - buf, is_file_data, notify, notify_data, - url, &complete_url); + RoutingStatus routing_status = + RouteToFrame(method, is_javascript_url, target, len, buf, is_file_data, + notify, notify_data, url); if (routing_status == ROUTED) return; @@ -931,9 +960,9 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id, } void WebPluginImpl::CancelDocumentLoad() { - if (frame()->loader()->activeDocumentLoader()) { + if (webframe_) { ignore_response_error_ = true; - frame()->loader()->activeDocumentLoader()->stopLoading(); + webframe_->stopLoading(); } } @@ -988,8 +1017,8 @@ void WebPluginImpl::HandleHttpMultipartResponse( return; } - WebView* webview = webframe_->GetWebViewImpl(); - webview->GetDelegate()->DidStartLoading(webview); + if (page_delegate_) + page_delegate_->DidStartLoadingForPlugin(); MultiPartResponseClient* multi_part_response_client = new MultiPartResponseClient(client); @@ -1003,11 +1032,11 @@ void WebPluginImpl::HandleHttpMultipartResponse( bool WebPluginImpl::ReinitializePluginForResponse( WebURLLoader* loader) { - WebFrameImpl* webframe = webframe_; + WebFrame* webframe = webframe_; if (!webframe) return false; - WebViewImpl* webview = webframe->GetWebViewImpl(); + WebView* webview = webframe->view(); if (!webview) return false; @@ -1019,28 +1048,14 @@ bool WebPluginImpl::ReinitializePluginForResponse( container_ = container_widget; webframe_ = webframe; - WebViewDelegate* webview_delegate = webview->GetDelegate(); std::string actual_mime_type; - WebPluginDelegate* plugin_delegate = - webview_delegate->CreatePluginDelegate(webview, plugin_url_, - mime_type_, std::string(), - &actual_mime_type); - - char** arg_names = new char*[arg_names_.size()]; - char** arg_values = new char*[arg_values_.size()]; + WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( + plugin_url_, mime_type_, std::string(), &actual_mime_type); - for (unsigned int index = 0; index < arg_names_.size(); ++index) { - arg_names[index] = const_cast<char*>(arg_names_[index].c_str()); - arg_values[index] = const_cast<char*>(arg_values_[index].c_str()); - } - - bool init_ok = plugin_delegate->Initialize(plugin_url_, arg_names, - arg_values, arg_names_.size(), - this, load_manually_); - delete[] arg_names; - delete[] arg_values; + bool ok = plugin_delegate->Initialize( + plugin_url_, arg_names_, arg_values_, arg_count_, this, load_manually_); - if (!init_ok) { + if (!ok) { container_ = NULL; // TODO(iyengar) Should we delete the current plugin instance here? return false; @@ -1050,8 +1065,9 @@ bool WebPluginImpl::ReinitializePluginForResponse( delegate_ = plugin_delegate; // Force a geometry update to occur to ensure that the plugin becomes - // visible. TODO(darin): Avoid this cast! - static_cast<WebPluginContainerImpl*>(container_)->frameRectsChanged(); + // visible. + container_->reportGeometry(); + // The plugin move sequences accumulated via DidMove are sent to the browser // whenever the renderer paints. Force a paint here to ensure that changes // to the plugin window are propagated to the browser. @@ -1059,25 +1075,13 @@ bool WebPluginImpl::ReinitializePluginForResponse( return true; } -void WebPluginImpl::ArrayToVector(int total_values, char** values, - std::vector<std::string>* value_vector) { - DCHECK(value_vector != NULL); - for (int index = 0; index < total_values; ++index) { - value_vector->push_back(values[index]); - } -} - void WebPluginImpl::TearDownPluginInstance( WebURLLoader* loader_to_ignore) { - // The frame maintains a list of JSObjects which are related to this - // plugin. Tell the frame we're gone so that it can invalidate all - // of those sub JSObjects. - if (frame()) { - ASSERT(container_); - // TODO(darin): Avoid this cast! - frame()->script()->cleanupScriptObjectsForPlugin( - static_cast<WebKit::WebPluginContainerImpl*>(container_)); - } + // The container maintains a list of JSObjects which are related to this + // plugin. Tell the frame we're gone so that it can invalidate all of + // those sub JSObjects. + if (container_) + container_->clearScriptObjects(); if (delegate_) { // Call PluginDestroyed() first to prevent the plugin from calling us back @@ -1109,9 +1113,4 @@ void WebPluginImpl::TearDownPluginInstance( method_factory_.RevokeAll(); } -WebViewDelegate* WebPluginImpl::GetWebViewDelegate() { - if (!webframe_) - return NULL; - WebViewImpl* webview = webframe_->GetWebViewImpl(); - return webview ? webview->delegate() : NULL; -} +} // namespace webkit_glue diff --git a/webkit/glue/webplugin_impl.h b/webkit/glue/webplugin_impl.h index 09505af..07e043c 100644 --- a/webkit/glue/webplugin_impl.h +++ b/webkit/glue/webplugin_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -9,45 +9,33 @@ #include <map> #include <vector> -#include "Widget.h" - #include "base/basictypes.h" #include "base/gfx/native_widget_types.h" #include "base/linked_ptr.h" +#include "base/task.h" +#include "base/weak_ptr.h" +#include "googleurl/src/gurl.h" #include "webkit/api/public/WebPlugin.h" +#include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURLLoaderClient.h" #include "webkit/api/public/WebURLRequest.h" -#include "webkit/glue/webframe_impl.h" +#include "webkit/api/public/WebVector.h" #include "webkit/glue/webplugin.h" - -class WebFrameImpl; -class WebPluginDelegate; - -namespace WebCore { -class Event; -class Frame; -class HTMLPlugInElement; -class IntRect; -class KeyboardEvent; -class KURL; -class MouseEvent; -class ResourceError; -class ResourceResponse; -class ScrollView; -class String; -class Widget; -} +class WebViewDelegate; namespace WebKit { +class WebFrame; class WebPluginContainer; class WebURLResponse; class WebURLLoader; } namespace webkit_glue { + class MultipartResponseDelegate; -} +class WebPluginDelegate; +class WebPluginPageDelegate; // This is the WebKit side of the plugin implementation that forwards calls, // after changing out of WebCore types, to a delegate. The delegate may @@ -56,19 +44,11 @@ class WebPluginImpl : public WebPlugin, public WebKit::WebPlugin, public WebKit::WebURLLoaderClient { public: - // Creates a WebPlugin instance, as long as the delegate's initialization - // succeeds. If it fails, the delegate is deleted and NULL is returned. - // Note that argn and argv are UTF8. - static PassRefPtr<WebCore::Widget> Create(const GURL& url, - char** argn, - char** argv, - int argc, - WebCore::HTMLPlugInElement* element, - WebFrameImpl* frame, - WebPluginDelegate* delegate, - bool load_manually, - const std::string& mime_type); - virtual ~WebPluginImpl(); + WebPluginImpl( + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params, + const base::WeakPtr<WebPluginPageDelegate>& page_delegate); + ~WebPluginImpl(); // Helper function for sorting post data. static bool SetPostData(WebKit::WebURLRequest* request, @@ -76,12 +56,9 @@ class WebPluginImpl : public WebPlugin, uint32 length); private: - WebPluginImpl( - WebFrameImpl* frame, WebPluginDelegate* delegate, const GURL& plugin_url, - bool load_manually, const std::string& mime_type, int arg_count, - char** arg_names, char** arg_values); - // WebKit::WebPlugin methods: + virtual bool initialize( + WebKit::WebPluginContainer* container); virtual void destroy(); virtual NPObject* scriptableObject(); virtual void paint( @@ -123,6 +100,13 @@ class WebPluginImpl : public WebPlugin, bool notify_needed, intptr_t notify_data, bool popups_allowed); + enum RoutingStatus { + ROUTED, + NOT_ROUTED, + INVALID_URL, + GENERAL_FAILURE + }; + // Given a download request, check if we need to route the output to a frame. // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or // corresponding error codes otherwise. @@ -130,7 +114,7 @@ class WebPluginImpl : public WebPlugin, const char* target, unsigned int len, const char* buf, bool is_file_data, bool notify_needed, intptr_t notify_data, - const char* url, GURL* completeURL); + const char* url); // Cancels a pending request. void CancelResource(int id); @@ -195,8 +179,6 @@ class WebPluginImpl : public WebPlugin, // request given a handle. void RemoveClient(WebKit::WebURLLoader* loader); - WebCore::Frame* frame() { return webframe_ ? webframe_->frame() : NULL; } - void HandleURLRequest(const char *method, bool is_javascript_url, const char* target, unsigned int len, @@ -231,16 +213,9 @@ class WebPluginImpl : public WebPlugin, // to handle the response identified by the loader parameter. bool ReinitializePluginForResponse(WebKit::WebURLLoader* loader); - // Helper functions to convert an array of names/values to a vector. - static void ArrayToVector(int total_values, char** values, - std::vector<std::string>* value_vector); - // Delayed task for downloading the plugin source URL. void OnDownloadPluginSrcUrl(); - // Returns the WebViewDelegate associated with webframe_; - WebViewDelegate* GetWebViewDelegate(); - struct ClientInfo { int id; WebPluginResourceClient* client; @@ -257,7 +232,8 @@ class WebPluginImpl : public WebPlugin, bool windowless_; gfx::PluginWindowHandle window_; - WebFrameImpl* webframe_; + base::WeakPtr<WebPluginPageDelegate> page_delegate_; + WebKit::WebFrame* webframe_; WebPluginDelegate* delegate_; @@ -290,15 +266,17 @@ class WebPluginImpl : public WebPlugin, // The mime type of the plugin. std::string mime_type_; - // Holds the list of argument names passed to the plugin. - std::vector<std::string> arg_names_; - - // Holds the list of argument values passed to the plugin. - std::vector<std::string> arg_values_; + // Holds the list of argument names and values passed to the plugin. We keep + // these so that we can re-initialize the plugin if we need to. + char** arg_names_; + char** arg_values_; + size_t arg_count_; ScopedRunnableMethodFactory<WebPluginImpl> method_factory_; DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); }; +} // namespace webkit_glue + #endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ diff --git a/webkit/glue/webplugin_impl_unittest.cc b/webkit/glue/webplugin_impl_unittest.cc index b6c62f6..70c9436 100644 --- a/webkit/glue/webplugin_impl_unittest.cc +++ b/webkit/glue/webplugin_impl_unittest.cc @@ -1,23 +1,18 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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 "config.h" - -// Avoid collisions with the LOG macro -#include <wtf/Assertions.h> -#undef LOG - #include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/api/public/WebCString.h" #include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURLRequest.h" -#include "webkit/glue/glue_util.h" #include "webkit/glue/webplugin_impl.h" using WebKit::WebHTTPBody; using WebKit::WebString; using WebKit::WebURLRequest; +using webkit_glue::WebPluginImpl; namespace { @@ -26,18 +21,10 @@ class WebPluginImplTest : public testing::Test { } -// These exist only to support the gTest assertion macros, and -// shouldn't be used in normal program code. -std::ostream& operator<<(std::ostream& out, const WebCore::String& str) -{ - return out << str.latin1().data(); -} - static std::string GetHeader(const WebURLRequest& request, const char* name) { std::string result; TrimWhitespace( - webkit_glue::WebStringToStdString( - request.httpHeaderField(WebString::fromUTF8(name))), + request.httpHeaderField(WebString::fromUTF8(name)).utf8(), TRIM_ALL, &result); return result; diff --git a/webkit/glue/webplugin_page_delegate.h b/webkit/glue/webplugin_page_delegate.h new file mode 100644 index 0000000..56a8cec --- /dev/null +++ b/webkit/glue/webplugin_page_delegate.h @@ -0,0 +1,65 @@ +// Copyright (c) 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 WEBKIT_GLUE_WEBPLUGIN_PAGE_DELEGATE_ +#define WEBKIT_GLUE_WEBPLUGIN_PAGE_DELEGATE_ + +#include "base/gfx/native_widget_types.h" + +class GURL; + +namespace webkit_glue { + +class WebPluginDelegate; +struct WebPluginGeometry; + +// Used by the WebPlugin to communicate back to the containing page. +class WebPluginPageDelegate { + public: + // This method is called to create a WebPluginDelegate implementation when a + // new plugin is instanced. See webkit_glue::CreateWebPluginDelegateHelper + // for a default WebPluginDelegate implementation. + // TODO(port): clsid is very Win- and ActiveX-specific; refactor to be more + // platform-neutral + virtual WebPluginDelegate* CreatePluginDelegate( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type) = 0; + + // Called when a windowed plugin is created. + // Lets the view delegate create anything it is using to wrap the plugin. + virtual void CreatedPluginWindow( + gfx::PluginWindowHandle handle) = 0; + + // Called when a windowed plugin is closing. + // Lets the view delegate shut down anything it is using to wrap the plugin. + virtual void WillDestroyPluginWindow( + gfx::PluginWindowHandle handle) = 0; + + // Keeps track of the necessary window move for a plugin window that resulted + // from a scroll operation. That way, all plugin windows can be moved at the + // same time as each other and the page. + virtual void DidMovePlugin( + const WebPluginGeometry& move) = 0; + + // Notifies the parent view that a load has begun. + virtual void DidStartLoadingForPlugin() = 0; + + // Notifies the parent view that all loads are finished. + virtual void DidStopLoadingForPlugin() = 0; + + // Asks the browser to show a modal HTML dialog. The dialog is passed the + // given arguments as a JSON string, and returns its result as a JSON string + // through json_retval. + virtual void ShowModalHTMLDialogForPlugin( + const GURL& url, + const gfx::Size& size, + const std::string& json_arguments, + std::string* json_retval) = 0; +}; + +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_WEBPLUGIN_PAGE_DELEGATE_H_ diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index 386f2e8..11a55f8 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -28,7 +28,6 @@ #include <vector> -#include "base/gfx/native_widget_types.h" #include "webkit/api/public/WebFrame.h" #include "webkit/api/public/WebNavigationPolicy.h" #include "webkit/api/public/WebNavigationType.h" @@ -38,6 +37,7 @@ namespace webkit_glue { class WebMediaPlayerDelegate; +struct WebPluginGeometry; } namespace WebCore { @@ -54,9 +54,11 @@ class WebMediaPlayer; class WebMediaPlayerClient; class WebNode; class WebNotificationPresenter; +class WebPlugin; class WebURLRequest; class WebURLResponse; class WebWidget; +struct WebPluginParams; struct WebPoint; struct WebPopupMenuInfo; struct WebRect; @@ -67,10 +69,8 @@ class FilePath; class SkBitmap; class WebDevToolsAgentDelegate; class WebMediaPlayerDelegate; -class WebPluginDelegate; class WebView; struct ContextMenuMediaParams; -struct WebPluginGeometry; struct WebPreferences; enum NavigationGesture { @@ -136,28 +136,12 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { return NULL; } - // This method is called to create a WebPluginDelegate implementation when a - // new plugin is instanced. See webkit_glue::CreateWebPluginDelegateHelper - // for a default WebPluginDelegate implementation. - // TODO(port): clsid is very Win- and ActiveX-specific; refactor to be more - // platform-neutral - virtual WebPluginDelegate* CreatePluginDelegate( - WebView* webview, - const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type) { + virtual WebKit::WebPlugin* CreatePlugin( + WebKit::WebFrame* parent_frame, + const WebKit::WebPluginParams& params) { return NULL; } - // Called when a windowed plugin is created. - // Lets the view delegate create anything it is using to wrap the plugin. - virtual void CreatedPluginWindow(gfx::PluginWindowHandle handle) { } - - // Called when a windowed plugin is closing. - // Lets the view delegate shut down anything it is using to wrap the plugin. - virtual void WillDestroyPluginWindow(gfx::PluginWindowHandle handle) { } - // This method is called when the renderer creates a worker object. virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client) { return NULL; @@ -205,12 +189,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { virtual void FocusAccessibilityObject(WebCore::AccessibilityObject* acc_obj) { } - // Keeps track of the necessary window move for a plugin window that resulted - // from a scroll operation. That way, all plugin windows can be moved at the - // same time as each other and the page. - virtual void DidMovePlugin(const WebPluginGeometry& move) { - } - // FrameLoaderClient ------------------------------------------------------- virtual bool CanAcceptLoadDrops() const { @@ -558,14 +536,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { // UIDelegate -------------------------------------------------------------- - // Asks the browser to show a modal HTML dialog. The dialog is passed the - // given arguments as a JSON string, and returns its result as a JSON string - // through json_retval. - virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, - const std::string& json_arguments, - std::string* json_retval) { - } - // Displays a JavaScript alert panel associated with the given view. Clients // should visually indicate that this panel comes from JavaScript and some // information about the originating frame (at least the domain). The panel diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm index 4634aa8..3eb93cf 100644 --- a/webkit/tools/test_shell/mac/test_webview_delegate.mm +++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm @@ -21,7 +21,7 @@ using WebKit::WebPopupMenuInfo; using WebKit::WebRect; using WebKit::WebWidget; -// WebViewDelegate ----------------------------------------------------------- +// WebViewDelegate ------------------------------------------------------------ WebWidget* TestWebViewDelegate::CreatePopupWidgetWithInfo( WebView* webview, @@ -31,34 +31,6 @@ WebWidget* TestWebViewDelegate::CreatePopupWidgetWithInfo( return webwidget; } -WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( - WebView* webview, - const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type) { - WebWidgetHost *host = GetWidgetHost(); - if (!host) - return NULL; - gfx::NativeView view = host->view_handle(); - - bool allow_wildcard = true; - WebPluginInfo info; - if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, - allow_wildcard, &info, - actual_mime_type)) - return NULL; - - if (actual_mime_type && !actual_mime_type->empty()) - return WebPluginDelegateImpl::Create(info.path, *actual_mime_type, view); - else - return WebPluginDelegateImpl::Create(info.path, mime_type, view); -} - -void TestWebViewDelegate::DidMovePlugin(const WebPluginGeometry& move) { - // TODO(port): add me once plugins work. -} - void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { NSString *text = [NSString stringWithUTF8String:WideToUTF8(message).c_str()]; @@ -70,8 +42,7 @@ void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { [alert runModal]; } - -// WebWidgetDelegate --------------------------------------------------------- +// WebWidgetClient ------------------------------------------------------------ void TestWebViewDelegate::show(WebNavigationPolicy policy) { if (!popup_menu_info_.get()) @@ -199,11 +170,51 @@ void TestWebViewDelegate::runModal() { NOTIMPLEMENTED(); } +// WebPluginPageDelegate ------------------------------------------------------ + +webkit_glue::WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type) { + WebWidgetHost *host = GetWidgetHost(); + if (!host) + return NULL; + gfx::NativeView view = host->view_handle(); + + bool allow_wildcard = true; + WebPluginInfo info; + if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, + allow_wildcard, &info, + actual_mime_type)) + return NULL; + + if (actual_mime_type && !actual_mime_type->empty()) + return WebPluginDelegateImpl::Create(info.path, *actual_mime_type, view); + else + return WebPluginDelegateImpl::Create(info.path, mime_type, view); +} + +void TestWebViewDelegate::CreatedPluginWindow( + gfx::PluginWindowHandle handle) { +} + +void TestWebViewDelegate::WillDestroyPluginWindow( + gfx::PluginWindowHandle handle) { +} + +void TestWebViewDelegate::DidMovePlugin( + const webkit_glue::WebPluginGeometry& move) { + // TODO(port): add me once plugins work. +} + +// Public methods ------------------------------------------------------------- + void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { // No selection clipboard on mac, do nothing. } -// Private methods ----------------------------------------------------------- +// Private methods ------------------------------------------------------------ void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { [[shell_->webViewHost()->view_handle() window] diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 74916a1..27eacce 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -38,6 +38,7 @@ #include "webkit/glue/media/media_resource_loader_bridge_factory.h" #include "webkit/glue/media/simple_data_source.h" #include "webkit/glue/webdropdata.h" +#include "webkit/glue/webplugin_impl.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webview.h" @@ -62,6 +63,8 @@ using WebKit::WebFrame; using WebKit::WebHistoryItem; using WebKit::WebNavigationType; using WebKit::WebNavigationPolicy; +using WebKit::WebPlugin; +using WebKit::WebPluginParams; using WebKit::WebRect; using WebKit::WebScreenInfo; using WebKit::WebSize; @@ -184,6 +187,11 @@ WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview, return shell_->CreatePopupWidget(webview); } +WebPlugin* TestWebViewDelegate::CreatePlugin( + WebFrame* frame, const WebPluginParams& params) { + return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); +} + WebKit::WebMediaPlayer* TestWebViewDelegate::CreateWebMediaPlayer( WebKit::WebMediaPlayerClient* client) { scoped_refptr<media::FilterFactoryCollection> factory = @@ -222,14 +230,6 @@ void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url, shell->Show(policy); } -void TestWebViewDelegate::DidStartLoading(WebView* webview) { - // Ignored -} - -void TestWebViewDelegate::DidStopLoading(WebView* webview) { - // Ignored -} - void TestWebViewDelegate::WindowObjectCleared(WebFrame* webframe) { shell_->BindJSObjectsToWindow(webframe); } @@ -817,7 +817,7 @@ void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) { prefs->Apply(shell_->webView()); } -// WebWidgetDelegate --------------------------------------------------------- +// WebWidgetClient ----------------------------------------------------------- void TestWebViewDelegate::didInvalidateRect(const WebRect& rect) { if (WebWidgetHost* host = GetWidgetHost()) @@ -869,8 +869,14 @@ TestWebViewDelegate::TestWebViewDelegate(TestShell* shell) block_redirects_(false) { } +TestWebViewDelegate::~TestWebViewDelegate() { +} + void TestWebViewDelegate::Reset() { - *this = TestWebViewDelegate(shell_); + // Do a little placement new dance... + TestShell* shell = shell_; + this->~TestWebViewDelegate(); + new (this) TestWebViewDelegate(shell); } void TestWebViewDelegate::SetSmartInsertDeleteEnabled(bool enabled) { diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 971f199..9887246 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -14,6 +14,7 @@ #if defined(OS_WIN) #include <windows.h> #endif + #include <map> #if defined(OS_LINUX) @@ -21,12 +22,14 @@ #endif #include "base/basictypes.h" -#include "base/linked_ptr.h" +#include "base/scoped_ptr.h" +#include "base/weak_ptr.h" #if defined(OS_MACOSX) #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebPopupMenuInfo.h" #endif #include "webkit/glue/webcursor.h" +#include "webkit/glue/webplugin_page_delegate.h" #include "webkit/glue/webview_delegate.h" #if defined(OS_WIN) #include "webkit/tools/test_shell/drag_delegate.h" @@ -40,7 +43,9 @@ class GURL; class TestShell; class WebWidgetHost; -class TestWebViewDelegate : public WebViewDelegate { +class TestWebViewDelegate : public WebViewDelegate, + public webkit_glue::WebPluginPageDelegate, + public base::SupportsWeakPtr<TestWebViewDelegate> { public: struct CapturedContextMenuEvent { CapturedContextMenuEvent(ContextNodeType in_node_type, @@ -70,16 +75,9 @@ class TestWebViewDelegate : public WebViewDelegate { WebView* webview, const WebKit::WebPopupMenuInfo& info); #endif - virtual WebPluginDelegate* CreatePluginDelegate( - WebView* webview, - const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type); -#if defined(OS_LINUX) - virtual void CreatedPluginWindow(gfx::PluginWindowHandle id); - virtual void WillDestroyPluginWindow(gfx::PluginWindowHandle id); -#endif + virtual WebKit::WebPlugin* CreatePlugin( + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params); virtual WebKit::WebMediaPlayer* CreateWebMediaPlayer( WebKit::WebMediaPlayerClient* client); virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client); @@ -87,7 +85,6 @@ class TestWebViewDelegate : public WebViewDelegate { const GURL& url, const GURL& referrer, WebKit::WebNavigationPolicy policy); - virtual void DidMovePlugin(const WebPluginGeometry& move); virtual void RunJavaScriptAlert(WebKit::WebFrame* webframe, const std::wstring& message); virtual bool RunJavaScriptConfirm(WebKit::WebFrame* webframe, @@ -202,10 +199,6 @@ class TestWebViewDelegate : public WebViewDelegate { virtual void DidChangeSelection(bool is_empty_selection); virtual void DidChangeContents(); virtual void DidEndEditing(); - - virtual void DidStartLoading(WebView* webview); - virtual void DidStopLoading(WebView* webview); - virtual void WindowObjectCleared(WebKit::WebFrame* webframe); virtual WebKit::WebNavigationPolicy PolicyForNavigationAction( WebView* webview, @@ -234,7 +227,28 @@ class TestWebViewDelegate : public WebViewDelegate { virtual WebKit::WebRect windowResizerRect(); virtual WebKit::WebScreenInfo screenInfo(); + // webkit_glue::WebPluginPageDelegate + virtual webkit_glue::WebPluginDelegate* CreatePluginDelegate( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type); + virtual void CreatedPluginWindow( + gfx::PluginWindowHandle handle); + virtual void WillDestroyPluginWindow( + gfx::PluginWindowHandle handle); + virtual void DidMovePlugin( + const webkit_glue::WebPluginGeometry& move); + virtual void DidStartLoadingForPlugin() {} + virtual void DidStopLoadingForPlugin() {} + virtual void ShowModalHTMLDialogForPlugin( + const GURL& url, + const gfx::Size& size, + const std::string& json_arguments, + std::string* json_retval) {} + TestWebViewDelegate(TestShell* shell); + ~TestWebViewDelegate(); void Reset(); void SetSmartInsertDeleteEnabled(bool enabled); @@ -333,7 +347,7 @@ class TestWebViewDelegate : public WebViewDelegate { int page_id_; int last_page_id_updated_; - linked_ptr<TestShellExtraData> pending_extra_data_; + scoped_ptr<TestShellExtraData> pending_extra_data_; // Maps resource identifiers to a descriptive string. typedef std::map<uint32, std::string> ResourceMap; @@ -358,7 +372,7 @@ class TestWebViewDelegate : public WebViewDelegate { #endif #if defined(OS_MACOSX) - linked_ptr<WebKit::WebPopupMenuInfo> popup_menu_info_; + scoped_ptr<WebKit::WebPopupMenuInfo> popup_menu_info_; WebKit::WebRect popup_bounds_; #endif @@ -370,6 +384,8 @@ class TestWebViewDelegate : public WebViewDelegate { // true if we should block any redirects bool block_redirects_; + + DISALLOW_COPY_AND_ASSIGN(TestWebViewDelegate); }; #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_WEBVIEW_DELEGATE_H_ diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc index 461d1d3..6a8bd58 100644 --- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc +++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc @@ -82,39 +82,7 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard, } // namespace -// WebViewDelegate ----------------------------------------------------------- - -WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( - WebView* webview, - const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type) { - bool allow_wildcard = true; - WebPluginInfo info; - if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, - allow_wildcard, &info, - actual_mime_type)) - return NULL; - - const std::string& mtype = - (actual_mime_type && !actual_mime_type->empty()) ? *actual_mime_type - : mime_type; - // TODO(evanm): we probably shouldn't be doing this mapping to X ids at - // this level. - GdkNativeWindow plugin_parent = - GDK_WINDOW_XWINDOW(shell_->webViewHost()->view_handle()->window); - - return WebPluginDelegateImpl::Create(info.path, mtype, plugin_parent); -} - -void TestWebViewDelegate::CreatedPluginWindow(gfx::PluginWindowHandle id) { - shell_->webViewHost()->CreatePluginContainer(id); -} - -void TestWebViewDelegate::WillDestroyPluginWindow(gfx::PluginWindowHandle id) { - shell_->webViewHost()->DestroyPluginContainer(id); -} +// WebViewDelegate ------------------------------------------------------------ void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { GtkWidget* dialog = gtk_message_dialog_new( @@ -125,6 +93,8 @@ void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { gtk_widget_destroy(dialog); } +// WebWidgetClient ------------------------------------------------------------ + void TestWebViewDelegate::show(WebNavigationPolicy policy) { WebWidgetHost* host = GetWidgetHost(); GtkWidget* drawing_area = host->view_handle(); @@ -220,16 +190,54 @@ WebRect TestWebViewDelegate::windowResizerRect() { return WebRect(); } -void TestWebViewDelegate::DidMovePlugin(const WebPluginGeometry& move) { +void TestWebViewDelegate::runModal() { + NOTIMPLEMENTED(); +} + +// WebPluginPageDelegate ------------------------------------------------------ + +webkit_glue::WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type) { + bool allow_wildcard = true; + WebPluginInfo info; + if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, + allow_wildcard, &info, + actual_mime_type)) + return NULL; + + const std::string& mtype = + (actual_mime_type && !actual_mime_type->empty()) ? *actual_mime_type + : mime_type; + // TODO(evanm): we probably shouldn't be doing this mapping to X ids at + // this level. + GdkNativeWindow plugin_parent = + GDK_WINDOW_XWINDOW(shell_->webViewHost()->view_handle()->window); + + return WebPluginDelegateImpl::Create(info.path, mtype, plugin_parent); +} + +void TestWebViewDelegate::CreatedPluginWindow( + gfx::PluginWindowHandle id) { + shell_->webViewHost()->CreatePluginContainer(id); +} + +void TestWebViewDelegate::WillDestroyPluginWindow( + gfx::PluginWindowHandle id) { + shell_->webViewHost()->DestroyPluginContainer(id); +} + +void TestWebViewDelegate::DidMovePlugin( + const webkit_glue::WebPluginGeometry& move) { WebWidgetHost* host = GetWidgetHost(); GtkPluginContainerManager* plugin_container_manager = static_cast<WebViewHost*>(host)->plugin_container_manager(); plugin_container_manager->MovePluginContainer(move); } -void TestWebViewDelegate::runModal() { - NOTIMPLEMENTED(); -} +// Public methods ------------------------------------------------------------- void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { if (is_empty_selection) @@ -252,7 +260,7 @@ void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { gtk_target_table_free(targets, num_targets); } -// Private methods ----------------------------------------------------------- +// Private methods ------------------------------------------------------------ void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()), diff --git a/webkit/tools/test_shell/test_webview_delegate_win.cc b/webkit/tools/test_shell/test_webview_delegate_win.cc index 8c174a4..9523dbd 100644 --- a/webkit/tools/test_shell/test_webview_delegate_win.cc +++ b/webkit/tools/test_shell/test_webview_delegate_win.cc @@ -39,66 +39,14 @@ using WebKit::WebCursorInfo; using WebKit::WebNavigationPolicy; using WebKit::WebRect; -// WebViewDelegate ----------------------------------------------------------- - -WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( - WebView* webview, - const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type) { - HWND hwnd = shell_->webViewHost()->view_handle(); - if (!hwnd) - return NULL; - - bool allow_wildcard = true; - WebPluginInfo info; - if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, - allow_wildcard, &info, - actual_mime_type)) - return NULL; - - if (actual_mime_type && !actual_mime_type->empty()) - return WebPluginDelegateImpl::Create(info.path, *actual_mime_type, hwnd); - else - return WebPluginDelegateImpl::Create(info.path, mime_type, hwnd); -} - -void TestWebViewDelegate::DidMovePlugin(const WebPluginGeometry& move) { - unsigned long flags = 0; - - if (move.rects_valid) { - HRGN hrgn = ::CreateRectRgn(move.clip_rect.x(), - move.clip_rect.y(), - move.clip_rect.right(), - move.clip_rect.bottom()); - gfx::SubtractRectanglesFromRegion(hrgn, move.cutout_rects); - - // Note: System will own the hrgn after we call SetWindowRgn, - // so we don't need to call DeleteObject(hrgn) - ::SetWindowRgn(move.window, hrgn, FALSE); - } else { - flags |= (SWP_NOSIZE | SWP_NOMOVE); - } - - if (move.visible) - flags |= SWP_SHOWWINDOW; - else - flags |= SWP_HIDEWINDOW; - - ::SetWindowPos(move.window, - NULL, - move.window_rect.x(), - move.window_rect.y(), - move.window_rect.width(), - move.window_rect.height(), - flags); -} +// WebViewDelegate ------------------------------------------------------------ void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) { MessageBox(NULL, message.c_str(), L"JavaScript Alert", MB_OK); } +// WebWidgetClient ------------------------------------------------------------ + void TestWebViewDelegate::show(WebNavigationPolicy) { if (WebWidgetHost* host = GetWidgetHost()) { HWND root = GetAncestor(host->view_handle(), GA_ROOT); @@ -176,11 +124,79 @@ void TestWebViewDelegate::runModal() { EnableWindow(*i, TRUE); } +// WebPluginPageDelegate ------------------------------------------------------ + +webkit_glue::WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type) { + HWND hwnd = shell_->webViewHost()->view_handle(); + if (!hwnd) + return NULL; + + bool allow_wildcard = true; + WebPluginInfo info; + if (!NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, + allow_wildcard, &info, + actual_mime_type)) + return NULL; + + if (actual_mime_type && !actual_mime_type->empty()) + return WebPluginDelegateImpl::Create(info.path, *actual_mime_type, hwnd); + else + return WebPluginDelegateImpl::Create(info.path, mime_type, hwnd); +} + +void TestWebViewDelegate::CreatedPluginWindow( + gfx::PluginWindowHandle handle) { + // ignored +} + +void TestWebViewDelegate::WillDestroyPluginWindow( + gfx::PluginWindowHandle handle) { + // ignored +} + +void TestWebViewDelegate::DidMovePlugin( + const webkit_glue::WebPluginGeometry& move) { + unsigned long flags = 0; + + if (move.rects_valid) { + HRGN hrgn = ::CreateRectRgn(move.clip_rect.x(), + move.clip_rect.y(), + move.clip_rect.right(), + move.clip_rect.bottom()); + gfx::SubtractRectanglesFromRegion(hrgn, move.cutout_rects); + + // Note: System will own the hrgn after we call SetWindowRgn, + // so we don't need to call DeleteObject(hrgn) + ::SetWindowRgn(move.window, hrgn, FALSE); + } else { + flags |= (SWP_NOSIZE | SWP_NOMOVE); + } + + if (move.visible) + flags |= SWP_SHOWWINDOW; + else + flags |= SWP_HIDEWINDOW; + + ::SetWindowPos(move.window, + NULL, + move.window_rect.x(), + move.window_rect.y(), + move.window_rect.width(), + move.window_rect.height(), + flags); +} + +// Public methods ------------------------------------------------------------- + void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) { // No selection clipboard on windows, do nothing. } -// Private methods ----------------------------------------------------------- +// Private methods ------------------------------------------------------------ void TestWebViewDelegate::SetPageTitle(const std::wstring& title) { // The Windows test shell, pre-refactoring, ignored this. *shrug* diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 397d56c..f700208 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1461,7 +1461,6 @@ 'glue/webmenurunner_mac.h', 'glue/webmenurunner_mac.mm', 'glue/webplugin.h', - 'glue/webplugin_delegate.cc', 'glue/webplugin_delegate.h', 'glue/webplugin_impl.cc', 'glue/webplugin_impl.h', |