diff options
52 files changed, 958 insertions, 855 deletions
diff --git a/base/weak_ptr.h b/base/weak_ptr.h index bd7069a..720beb5 100644 --- a/base/weak_ptr.h +++ b/base/weak_ptr.h @@ -161,6 +161,11 @@ class WeakPtr : public internal::WeakPtrBase { return get(); } + void reset() { + ref_ = internal::WeakReference(); + ptr_ = NULL; + } + private: friend class SupportsWeakPtr<T>; friend class WeakPtrFactory<T>; diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h index b022f7e..508be27 100644 --- a/chrome/browser/renderer_host/render_widget_host_view.h +++ b/chrome/browser/renderer_host/render_widget_host_view.h @@ -70,7 +70,7 @@ class RenderWidgetHostView { // Moves all plugin windows as described in the given list. virtual void MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves) = 0; + const std::vector<webkit_glue::WebPluginGeometry>& moves) = 0; // Actually set/take focus to/from the associated View component. virtual void Focus() = 0; diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index 159e1cd..ec6be0f 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -403,9 +403,9 @@ gfx::NativeView RenderWidgetHostViewGtk::GetNativeView() { } void RenderWidgetHostViewGtk::MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves) { - for (size_t i = 0; i < plugin_window_moves.size(); ++i) { - plugin_container_manager_.MovePluginContainer(plugin_window_moves[i]); + const std::vector<webkit_glue::WebPluginGeometry>& moves) { + for (size_t i = 0; i < moves.size(); ++i) { + plugin_container_manager_.MovePluginContainer(moves[i]); } } diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h index 95b8c2d..9f5c76d 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h @@ -45,7 +45,7 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { virtual void SetSize(const gfx::Size& size); virtual gfx::NativeView GetNativeView(); virtual void MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves); + const std::vector<webkit_glue::WebPluginGeometry>& moves); virtual void Focus(); virtual void Blur(); virtual bool HasFocus(); diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index 7c6ece5..1633a52 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -84,7 +84,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { virtual void SetSize(const gfx::Size& size); virtual gfx::NativeView GetNativeView(); virtual void MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves); + const std::vector<webkit_glue::WebPluginGeometry>& moves); virtual void Focus(); virtual void Blur(); virtual bool HasFocus(); diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 1010475..fef480b 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -149,7 +149,7 @@ gfx::NativeView RenderWidgetHostViewMac::GetNativeView() { } void RenderWidgetHostViewMac::MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves) { + const std::vector<webkit_glue::WebPluginGeometry>& moves) { // All plugin stuff is TBD. TODO(avi,awalker): fill in // http://crbug.com/8192 } diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 8409006..6838e08 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -40,11 +40,11 @@ using base::TimeDelta; using base::TimeTicks; - using WebKit::WebInputEvent; using WebKit::WebInputEventFactory; using WebKit::WebMouseEvent; using WebKit::WebTextDirection; +using webkit_glue::WebPluginGeometry; namespace { diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.h b/chrome/browser/renderer_host/render_widget_host_view_win.h index 751dbb2..5bfbd86 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.h +++ b/chrome/browser/renderer_host/render_widget_host_view_win.h @@ -114,7 +114,7 @@ class RenderWidgetHostViewWin : virtual void SetSize(const gfx::Size& size); virtual gfx::NativeView GetNativeView(); virtual void MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves); + const std::vector<webkit_glue::WebPluginGeometry>& moves); virtual void Focus(); virtual void Blur(); virtual bool HasFocus(); diff --git a/chrome/browser/renderer_host/test/test_render_view_host.h b/chrome/browser/renderer_host/test/test_render_view_host.h index 537c149..18a6db7 100644 --- a/chrome/browser/renderer_host/test/test_render_view_host.h +++ b/chrome/browser/renderer_host/test/test_render_view_host.h @@ -48,7 +48,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostView { virtual void SetSize(const gfx::Size& size) {} virtual gfx::NativeView GetNativeView() { return NULL; } virtual void MovePluginWindows( - const std::vector<WebPluginGeometry>& plugin_window_moves) {} + const std::vector<webkit_glue::WebPluginGeometry>& moves) {} #if defined(OS_WIN) virtual void ForwardMouseEventToRenderer(UINT message, WPARAM wparam, diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index b1b21ec..16a2037 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -197,7 +197,7 @@ struct ViewHostMsg_PaintRect_Params { gfx::Size view_size; // New window locations for plugin child windows. - std::vector<WebPluginGeometry> plugin_window_moves; + std::vector<webkit_glue::WebPluginGeometry> plugin_window_moves; // The following describes the various bits that may be set in flags: // @@ -234,7 +234,7 @@ struct ViewHostMsg_ScrollRect_Params { gfx::Size view_size; // New window locations for plugin child windows. - std::vector<WebPluginGeometry> plugin_window_moves; + std::vector<webkit_glue::WebPluginGeometry> plugin_window_moves; }; // Parameters structure for ViewMsg_UploadFile. @@ -1060,8 +1060,8 @@ struct ParamTraits<ViewHostMsg_ScrollRect_Params> { }; template <> -struct ParamTraits<WebPluginGeometry> { - typedef WebPluginGeometry param_type; +struct ParamTraits<webkit_glue::WebPluginGeometry> { + typedef webkit_glue::WebPluginGeometry param_type; static void Write(Message* m, const param_type& p) { WriteParam(m, p.window); WriteParam(m, p.window_rect); diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index fda6909..65bdfdc 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -25,6 +25,9 @@ using WebKit::WebBindings; using WebKit::WebCursorInfo; +using webkit_glue::WebPlugin; +using webkit_glue::WebPluginDelegate; +using webkit_glue::WebPluginResourceClient; class FinishDestructionTask : public Task { public: @@ -152,15 +155,16 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, // PluginThread::current()->Send(new PluginProcessHostMsg_MapNativeViewId( // params.containing_window, &parent)); #endif - delegate_ = WebPluginDelegate::Create(path, mime_type_, parent); - if (delegate_) { - webplugin_ = new WebPluginProxy( - channel_, instance_id_, delegate_, page_url_); + webplugin_ = new WebPluginProxy(channel_, instance_id_, page_url_); #if defined(OS_WIN) - if (!webplugin_->SetModalDialogEvent(params.modal_dialog_event)) - return; + if (!webplugin_->SetModalDialogEvent(params.modal_dialog_event)) + return; #endif + + delegate_ = WebPluginDelegate::Create(path, mime_type_, parent); + if (delegate_) { + webplugin_->set_delegate(delegate_); *result = delegate_->Initialize( params.url, argn, argv, argc, webplugin_, params.load_manually); } diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index d0c6542..34cde08 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -18,7 +18,6 @@ class PluginChannel; class WebPluginProxy; -class WebPluginDelegate; struct PluginMsg_Init_Params; struct PluginMsg_DidReceiveResponseParams; struct PluginMsg_URLRequestReply_Params; @@ -28,6 +27,10 @@ namespace WebKit { class WebInputEvent; } +namespace webkit_glue { +class WebPluginDelegate; +} + // Converts the IPC messages from WebPluginDelegateProxy into calls to the // actual WebPluginDelegate object. class WebPluginDelegateStub : public IPC::Channel::Listener, @@ -99,7 +102,7 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, scoped_refptr<PluginChannel> channel_; - WebPluginDelegate* delegate_; + webkit_glue::WebPluginDelegate* delegate_; WebPluginProxy* webplugin_; // The url of the main frame hosting the plugin. diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index 1684785..739fc74 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -34,6 +34,8 @@ #endif using WebKit::WebBindings; +using webkit_glue::WebPluginDelegate; +using webkit_glue::WebPluginResourceClient; typedef std::map<CPBrowsingContext, WebPluginProxy*> ContextMap; static ContextMap& GetContextMap() { @@ -43,14 +45,13 @@ static ContextMap& GetContextMap() { WebPluginProxy::WebPluginProxy( PluginChannel* channel, int route_id, - WebPluginDelegate* delegate, const GURL& page_url) : channel_(channel), route_id_(route_id), cp_browsing_context_(0), window_npobject_(NULL), plugin_element_(NULL), - delegate_(delegate), + delegate_(NULL), waiting_for_paint_(false), page_url_(page_url), ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)) diff --git a/chrome/plugin/webplugin_proxy.h b/chrome/plugin/webplugin_proxy.h index 8e13638..6297f24 100644 --- a/chrome/plugin/webplugin_proxy.h +++ b/chrome/plugin/webplugin_proxy.h @@ -22,25 +22,29 @@ #include "ipc/ipc_message.h" #include "webkit/glue/webplugin.h" +class PluginChannel; + namespace base { class WaitableEvent; } -class PluginChannel; +namespace webkit_glue { class WebPluginDelegate; +} // This is an implementation of WebPlugin that proxies all calls to the // renderer. -class WebPluginProxy : public WebPlugin { +class WebPluginProxy : public webkit_glue::WebPlugin { public: // Creates a new proxy for WebPlugin, using the given sender to send the // marshalled WebPlugin calls. WebPluginProxy(PluginChannel* channel, int route_id, - WebPluginDelegate* delegate, const GURL& page_url); ~WebPluginProxy(); + void set_delegate(webkit_glue::WebPluginDelegate* d) { delegate_ = d; } + // WebPlugin overrides void SetWindow(gfx::PluginWindowHandle window); void WillDestroyWindow(gfx::PluginWindowHandle window); @@ -83,7 +87,7 @@ class WebPluginProxy : public WebPlugin { // Returns a WebPluginResourceClient object given its id, or NULL if no // object with that id exists. - WebPluginResourceClient* GetResourceClient(int id); + webkit_glue::WebPluginResourceClient* GetResourceClient(int id); // Returns the process id of the renderer that contains this plugin. int GetRendererProcessId(); @@ -122,7 +126,8 @@ class WebPluginProxy : public WebPlugin { bool IsOffTheRecord(); - void ResourceClientDeleted(WebPluginResourceClient* resource_client); + void ResourceClientDeleted( + webkit_glue::WebPluginResourceClient* resource_client); base::WaitableEvent* modal_dialog_event() { return modal_dialog_event_.get(); @@ -151,7 +156,8 @@ class WebPluginProxy : public WebPlugin { // transform of the local HDC. void UpdateTransform(); - typedef base::hash_map<int, WebPluginResourceClient*> ResourceClientMap; + typedef base::hash_map<int, webkit_glue::WebPluginResourceClient*> + ResourceClientMap; ResourceClientMap resource_clients_; scoped_refptr<PluginChannel> channel_; @@ -159,7 +165,7 @@ class WebPluginProxy : public WebPlugin { uint32 cp_browsing_context_; NPObject* window_npobject_; NPObject* plugin_element_; - WebPluginDelegate* delegate_; + webkit_glue::WebPluginDelegate* delegate_; gfx::Rect damaged_rect_; bool waiting_for_paint_; scoped_ptr<base::WaitableEvent> modal_dialog_event_; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index c76c31a..e0015e8 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -88,6 +88,7 @@ #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webmediaplayer_impl.h" #include "webkit/glue/webplugin_delegate.h" +#include "webkit/glue/webplugin_impl.h" #include "webkit/glue/webview.h" #if defined(OS_WIN) @@ -191,7 +192,6 @@ RenderView::RenderView(RenderThreadBase* render_thread, last_indexed_page_id_(-1), opened_by_user_gesture_(true), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), - first_default_plugin_(NULL), devtools_agent_(NULL), devtools_client_(NULL), history_back_list_count_(0), @@ -216,13 +216,6 @@ RenderView::~RenderView() { if (decrement_shared_popup_at_destruction_) shared_popup_counter_->data--; - // Clear any back-pointers that might still be held by plugins. - PluginDelegateList::iterator it = plugin_delegates_.begin(); - while (it != plugin_delegates_.end()) { - (*it)->DropRenderView(); - it = plugin_delegates_.erase(it); - } - render_thread_->RemoveFilter(audio_message_filter_); } @@ -256,25 +249,11 @@ void RenderView::SetNextPageID(int32 next_page_id) { next_page_id_ = next_page_id; } -void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) { - PluginDelegateList::iterator it = - std::find(plugin_delegates_.begin(), plugin_delegates_.end(), proxy); - DCHECK(it != plugin_delegates_.end()); - plugin_delegates_.erase(it); - // If the plugin is deleted, we need to clear our reference in case user - // clicks the info bar to install. Unfortunately we are getting - // PluginDestroyed in single process mode. However, that is not a huge - // concern. - if (proxy == first_default_plugin_) - first_default_plugin_ = NULL; -} - void RenderView::PluginCrashed(base::ProcessId pid, const FilePath& plugin_path) { Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path)); } - void RenderView::JSOutOfMemory() { Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); } @@ -1070,7 +1049,7 @@ void RenderView::DidStartLoading(WebView* webview) { is_loading_ = true; // Clear the pointer so that we can assign it only when there is an unknown // plugin on a page. - first_default_plugin_ = NULL; + first_default_plugin_.reset(); Send(new ViewHostMsg_DidStartLoading(routing_id_)); } @@ -1784,16 +1763,6 @@ void RenderView::OnPopupNotificationVisibilityChanged(bool visible) { popup_notification_visible_ = visible; } -void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height, - const std::string& json_arguments, - std::string* json_retval) { - IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog( - routing_id_, url, width, height, json_arguments, json_retval); - - msg->set_pump_messages_event(modal_dialog_event_.get()); - Send(msg); -} - uint32 RenderView::GetCPBrowsingContext() { uint32 context = 0; Send(new ViewHostMsg_GetCPBrowsingContext(&context)); @@ -1911,51 +1880,9 @@ WebWidget* RenderView::CreatePopupWidgetWithInfo(WebView* webview, return widget->webwidget(); } -WebPluginDelegate* RenderView::CreatePluginDelegate( - WebView* webview, - const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type) { - if (!PluginChannelHost::IsListening()) - return NULL; - - GURL policy_url; - if (webview->GetMainFrame()) - policy_url = webview->GetMainFrame()->url(); - - FilePath path; - render_thread_->Send( - new ViewHostMsg_GetPluginPath(url, policy_url, mime_type, clsid, &path, - actual_mime_type)); - if (path.value().empty()) - return NULL; - - std::string mime_type_to_use; - if (!actual_mime_type->empty()) - mime_type_to_use = *actual_mime_type; - else - mime_type_to_use = mime_type; - - if (RenderProcess::current()->in_process_plugins()) { -#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac. - return WebPluginDelegate::Create(path, - mime_type_to_use, - gfx::NativeViewFromId(host_window_)); -#else - NOTIMPLEMENTED(); - return NULL; -#endif - } - - WebPluginDelegateProxy* proxy = - WebPluginDelegateProxy::Create(url, mime_type_to_use, clsid, this); - if (!proxy) - return NULL; - - plugin_delegates_.push_back(proxy); - - return proxy; +WebKit::WebPlugin* RenderView::CreatePlugin( + WebFrame* frame, const WebKit::WebPluginParams& params) { + return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); } WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer( @@ -1993,13 +1920,14 @@ WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer( return new webkit_glue::WebMediaPlayerImpl(client, factory); } -void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate, - int status) { +void RenderView::OnMissingPluginStatus( + WebPluginDelegateProxy* delegate, + int status) { #if defined(OS_WIN) - if (first_default_plugin_ == NULL) { + if (!first_default_plugin_) { // Show the InfoBar for the first available plugin. if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { - first_default_plugin_ = delegate; + first_default_plugin_ = delegate->AsWeakPtr(); Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); } } else { @@ -2087,6 +2015,88 @@ void RenderView::runModal() { Send(msg); } +webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type) { + if (!PluginChannelHost::IsListening()) + return NULL; + + GURL policy_url; + WebFrame* main_frame = webview()->GetMainFrame(); + if (main_frame) + policy_url = main_frame->url(); + + FilePath path; + render_thread_->Send( + new ViewHostMsg_GetPluginPath(url, policy_url, mime_type, clsid, &path, + actual_mime_type)); + if (path.value().empty()) + return NULL; + + const std::string* mime_type_to_use; + if (!actual_mime_type->empty()) + mime_type_to_use = actual_mime_type; + else + mime_type_to_use = &mime_type; + + if (RenderProcess::current()->in_process_plugins()) { +#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac. + return webkit_glue::WebPluginDelegate::Create( + path, *mime_type_to_use, gfx::NativeViewFromId(host_window_)); +#else + NOTIMPLEMENTED(); + return NULL; +#endif + } + + return WebPluginDelegateProxy::Create( + url, *mime_type_to_use, clsid, AsWeakPtr()); +} + +void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { +#if defined(OS_LINUX) + RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( + routing_id(), window)); +#endif +} + +void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { +#if defined(OS_LINUX) + RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( + routing_id(), window)); +#endif + CleanupWindowInPluginMoves(window); +} + +void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { + SchedulePluginMove(move); +} + +void RenderView::DidStartLoadingForPlugin() { + // TODO(darin): Make is_loading_ be a counter! + DidStartLoading(webview()); +} + +void RenderView::DidStopLoadingForPlugin() { + // TODO(darin): Make is_loading_ be a counter! + DidStopLoading(webview()); +} + +void RenderView::ShowModalHTMLDialogForPlugin( + const GURL& url, + const gfx::Size& size, + const std::string& json_arguments, + std::string* json_retval) { + IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog( + routing_id_, url, size.width(), size.height(), json_arguments, + json_retval); + + msg->set_pump_messages_event(modal_dialog_event_.get()); + Send(msg); +} + void RenderView::SyncNavigationState() { if (!webview()) return; @@ -2742,9 +2752,8 @@ void RenderView::OnSetAltErrorPageURL(const GURL& url) { void RenderView::OnInstallMissingPlugin() { // This could happen when the first default plugin is deleted. - if (first_default_plugin_ == NULL) - return; - first_default_plugin_->InstallMissingPlugin(); + if (first_default_plugin_) + first_default_plugin_->InstallMissingPlugin(); } void RenderView::OnFileChooserResponse( @@ -3297,25 +3306,6 @@ void RenderView::FocusAccessibilityObject( #endif } -void RenderView::DidMovePlugin(const WebPluginGeometry& move) { - SchedulePluginMove(move); -} - -void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { -#if defined(OS_LINUX) - RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( - routing_id(), window)); -#endif -} - -void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { -#if defined(OS_LINUX) - RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( - routing_id(), window)); -#endif - CleanupWindowInPluginMoves(window); -} - void RenderView::SendPasswordForms(WebFrame* frame) { WebVector<WebForm> forms; frame->forms(forms); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 7317385..83518cd 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -17,6 +17,7 @@ #include "base/shared_memory.h" #include "base/timer.h" #include "base/values.h" +#include "base/weak_ptr.h" #include "build/build_config.h" #include "chrome/common/renderer_preferences.h" #include "chrome/common/view_types.h" @@ -33,6 +34,7 @@ #include "webkit/glue/form_data.h" #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/webaccessibilitymanager.h" +#include "webkit/glue/webplugin_page_delegate.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/webview_delegate.h" #include "webkit/glue/webview.h" @@ -53,7 +55,6 @@ class GURL; class ListValue; class NavigationState; class PrintWebViewHelper; -class WebPluginDelegate; class WebPluginDelegateProxy; class WebDevToolsAgentDelegate; struct ContextMenuMediaParams; @@ -98,11 +99,14 @@ typedef base::RefCountedData<int> SharedRenderViewCounter; // class RenderView : public RenderWidget, public WebViewDelegate, - public webkit_glue::DomSerializerDelegate { + public webkit_glue::WebPluginPageDelegate, + public webkit_glue::DomSerializerDelegate, + public base::SupportsWeakPtr<RenderView> { public: struct RenderViewSet { - std::set<RenderView* > render_view_set_; + std::set<RenderView*> render_view_set_; }; + // Creates a new RenderView. The parent_hwnd specifies a HWND to use as the // parent of the WebView HWND that will be created. The modal_dialog_event // is set by the RenderView whenever a modal dialog alert is shown, so that @@ -150,9 +154,6 @@ class RenderView : public RenderWidget, // WebViewDelegate virtual bool CanAcceptLoadDrops() const; - virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, - const std::string& json_arguments, - std::string* json_retval); virtual void RunJavaScriptAlert(WebKit::WebFrame* webframe, const std::wstring& message); virtual bool RunJavaScriptConfirm(WebKit::WebFrame* webframe, @@ -263,16 +264,15 @@ class RenderView : public RenderWidget, virtual WebKit::WebWidget* CreatePopupWidgetWithInfo( WebView* webview, const WebKit::WebPopupMenuInfo& info); - 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* frame, + const WebKit::WebPluginParams& params); virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client); virtual WebKit::WebMediaPlayer* CreateWebMediaPlayer( WebKit::WebMediaPlayerClient* client); - virtual void OnMissingPluginStatus(WebPluginDelegate* delegate, int status); + virtual void OnMissingPluginStatus( + WebPluginDelegateProxy* delegate, + int status); virtual void OpenURL(WebView* webview, const GURL& url, const GURL& referrer, WebKit::WebNavigationPolicy policy); @@ -327,9 +327,6 @@ class RenderView : public RenderWidget, const WebKit::WebRect& selection); virtual bool WasOpenedByUserGesture() const; virtual void FocusAccessibilityObject(WebCore::AccessibilityObject* acc_obj); - virtual void DidMovePlugin(const WebPluginGeometry& move); - virtual void CreatedPluginWindow(gfx::PluginWindowHandle handle); - virtual void WillDestroyPluginWindow(gfx::PluginWindowHandle handle); virtual void SpellCheck(const std::wstring& word, int* misspell_location, int* misspell_length); virtual std::wstring GetAutoCorrectWord(const std::wstring& word); @@ -338,22 +335,36 @@ class RenderView : public RenderWidget, virtual void UserMetricsRecordAction(const std::wstring& action); virtual void DnsPrefetch(const std::vector<std::string>& host_names); - // DomSerializerDelegate - virtual void DidSerializeDataForFrame(const GURL& frame_url, - const std::string& data, PageSavingSerializationStatus status); - // WebKit::WebWidgetClient // Most methods are handled by RenderWidget. virtual void show(WebKit::WebNavigationPolicy policy); virtual void closeWidgetSoon(); virtual void runModal(); + // 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); + + // DomSerializerDelegate + virtual void DidSerializeDataForFrame(const GURL& frame_url, + const std::string& data, PageSavingSerializationStatus status); + // Do not delete directly. This class is reference counted. virtual ~RenderView(); - // Called when a plugin is destroyed. - void PluginDestroyed(WebPluginDelegateProxy* proxy); - // Called when a plugin has crashed. void PluginCrashed(base::ProcessId pid, const FilePath& plugin_path); @@ -754,12 +765,9 @@ class RenderView : public RenderWidget, // Timer used to delay the updating of nav state (see SyncNavigationState). base::OneShotTimer<RenderView> nav_state_sync_timer_; - typedef std::vector<WebPluginDelegateProxy*> PluginDelegateList; - PluginDelegateList plugin_delegates_; - // Remember the first uninstalled plugin, so that we can ask the plugin // to install itself when user clicks on the info bar. - WebPluginDelegate* first_default_plugin_; + base::WeakPtr<webkit_glue::WebPluginDelegate> first_default_plugin_; // If the browser hasn't sent us an ACK for the last FindReply we sent // to it, then we need to queue up the message (keeping only the most diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index fa97dda..f668896 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -879,7 +879,8 @@ WebScreenInfo RenderWidget::screenInfo() { return results; } -void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { +void RenderWidget::SchedulePluginMove( + const webkit_glue::WebPluginGeometry& move) { size_t i = 0; for (; i < plugin_window_moves_.size(); ++i) { if (plugin_window_moves_[i].window == move.window) { diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h index f8580ce..38dfad8 100644 --- a/chrome/renderer/render_widget.h +++ b/chrome/renderer/render_widget.h @@ -25,12 +25,15 @@ class RenderThreadBase; struct ViewHostMsg_ShowPopup_Params; -struct WebPluginGeometry; namespace WebKit { struct WebPopupMenuInfo; } +namespace webkit_glue { +struct WebPluginGeometry; +} + // RenderWidget provides a communication bridge between a WebWidget and // a RenderWidgetHost, the latter of which lives in a different process. class RenderWidget : public IPC::Channel::Listener, @@ -84,7 +87,7 @@ class RenderWidget : public IPC::Channel::Listener, // Called when a plugin is moved. These events are queued up and sent with // the next paint or scroll message to the host. - void SchedulePluginMove(const WebPluginGeometry& move); + void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move); // Called when a plugin window has been destroyed, to make sure the currently // pending moves don't try to reference it. @@ -297,7 +300,7 @@ class RenderWidget : public IPC::Channel::Listener, bool activatable_; // Holds all the needed plugin window moves for a scroll. - typedef std::vector<WebPluginGeometry> WebPluginGeometryVector; + typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector; WebPluginGeometryVector plugin_window_moves_; // A custom background for the widget. diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 2068a50..66cf1c6 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -59,7 +59,7 @@ using WebKit::WebString; // Proxy for WebPluginResourceClient. The object owns itself after creation, // deleting itself after its callback has been called. -class ResourceClientProxy : public WebPluginResourceClient { +class ResourceClientProxy : public webkit_glue::WebPluginResourceClient { public: ResourceClientProxy(PluginChannelHost* channel, int instance_id) : channel_(channel), instance_id_(instance_id), resource_id_(0), @@ -162,13 +162,14 @@ WebPluginDelegateProxy* WebPluginDelegateProxy::Create( const GURL& url, const std::string& mime_type, const std::string& clsid, - RenderView* render_view) { + const base::WeakPtr<RenderView>& render_view) { return new WebPluginDelegateProxy(mime_type, clsid, render_view); } -WebPluginDelegateProxy::WebPluginDelegateProxy(const std::string& mime_type, - const std::string& clsid, - RenderView* render_view) +WebPluginDelegateProxy::WebPluginDelegateProxy( + const std::string& mime_type, + const std::string& clsid, + const base::WeakPtr<RenderView>& render_view) : render_view_(render_view), plugin_(NULL), windowless_(false), @@ -221,13 +222,12 @@ void WebPluginDelegateProxy::PluginDestroyed() { channel_host_ = NULL; } - render_view_->PluginDestroyed(this); MessageLoop::current()->DeleteSoon(FROM_HERE, this); } bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn, char** argv, int argc, - WebPlugin* plugin, + webkit_glue::WebPlugin* plugin, bool load_manually) { IPC::ChannelHandle channel_handle; FilePath plugin_path; @@ -881,9 +881,10 @@ void WebPluginDelegateProxy::OnShowModalHTMLDialog( const GURL& url, int width, int height, const std::string& json_arguments, std::string* json_retval) { DCHECK(json_retval); - if (render_view_) - render_view_->ShowModalHTMLDialog(url, width, height, json_arguments, - json_retval); + if (render_view_) { + render_view_->ShowModalHTMLDialogForPlugin( + url, gfx::Size(width, height), json_arguments, json_retval); + } } static void EncodeDragData(const WebDragData& data, bool add_data, @@ -1048,7 +1049,8 @@ void WebPluginDelegateProxy::OnHandleURLRequest( params.popups_allowed); } -WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient( +webkit_glue::WebPluginResourceClient* +WebPluginDelegateProxy::CreateResourceClient( int resource_id, const GURL& url, bool notify_needed, intptr_t notify_data, intptr_t npstream) { ResourceClientProxy* proxy = new ResourceClientProxy(channel_host_, @@ -1057,6 +1059,26 @@ WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient( return proxy; } +bool WebPluginDelegateProxy::IsWindowless() const { + NOTREACHED(); + return false; +} + +gfx::Rect WebPluginDelegateProxy::GetRect() const { + NOTREACHED(); + return gfx::Rect(); +} + +gfx::Rect WebPluginDelegateProxy::GetClipRect() const { + NOTREACHED(); + return gfx::Rect(); +} + +int WebPluginDelegateProxy::GetQuirks() const { + NOTREACHED(); + return 0; +} + void WebPluginDelegateProxy::OnCancelDocumentLoad() { plugin_->CancelDocumentLoad(); } diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index 61dfa8b..45ffb8d 100644 --- a/chrome/renderer/webplugin_delegate_proxy.h +++ b/chrome/renderer/webplugin_delegate_proxy.h @@ -12,6 +12,7 @@ #include "base/gfx/rect.h" #include "base/gfx/native_widget_types.h" #include "base/ref_counted.h" +#include "base/weak_ptr.h" #include "chrome/common/transport_dib.h" #include "chrome/renderer/plugin_channel_host.h" #include "googleurl/src/gurl.h" @@ -34,17 +35,17 @@ class WaitableEvent; // An implementation of WebPluginDelegate that proxies all calls to // the plugin process. -class WebPluginDelegateProxy : public WebPluginDelegate, - public IPC::Channel::Listener, - public IPC::Message::Sender { +class WebPluginDelegateProxy : + public webkit_glue::WebPluginDelegate, + public IPC::Channel::Listener, + public IPC::Message::Sender, + public base::SupportsWeakPtr<WebPluginDelegateProxy> { public: - static WebPluginDelegateProxy* Create(const GURL& url, - const std::string& mime_type, - const std::string& clsid, - RenderView* render_view); - - // Called to drop our back-pointer to the containing RenderView. - void DropRenderView() { render_view_ = NULL; } + static WebPluginDelegateProxy* Create( + const GURL& url, + const std::string& mime_type, + const std::string& clsid, + const base::WeakPtr<RenderView>& render_view); // Called to drop our pointer to the window script object. void DropWindowScriptObject() { window_script_object_ = NULL; } @@ -52,7 +53,7 @@ class WebPluginDelegateProxy : public WebPluginDelegate, // WebPluginDelegate implementation: virtual void PluginDestroyed(); virtual bool Initialize(const GURL& url, char** argn, char** argv, int argc, - WebPlugin* plugin, bool load_manually); + webkit_glue::WebPlugin* plugin, bool load_manually); virtual void UpdateGeometry(const gfx::Rect& window_rect, const gfx::Rect& clip_rect); virtual void Paint(gfx::NativeDrawingContext context, const gfx::Rect& rect); @@ -87,11 +88,16 @@ class WebPluginDelegateProxy : 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 existing_stream); + virtual webkit_glue::WebPluginResourceClient* CreateResourceClient( + int resource_id, + const GURL& url, + bool notify_needed, + intptr_t notify_data, + intptr_t existing_stream); + virtual bool IsWindowless() const; + virtual gfx::Rect GetRect() const; + virtual gfx::Rect GetClipRect() const; + virtual int GetQuirks() const; protected: template<class WebPluginDelegateProxy> friend class DeleteTask; @@ -100,7 +106,7 @@ class WebPluginDelegateProxy : public WebPluginDelegate, private: WebPluginDelegateProxy(const std::string& mime_type, const std::string& clsid, - RenderView* render_view); + const base::WeakPtr<RenderView>& render_view); // Message handlers for messages that proxy WebPlugin methods, which // we translate into calls to the real WebPlugin. @@ -161,8 +167,8 @@ class WebPluginDelegateProxy : public WebPluginDelegate, // point the window has already been destroyed). void WillDestroyWindow(); - RenderView* render_view_; - WebPlugin* plugin_; + base::WeakPtr<RenderView> render_view_; + webkit_glue::WebPlugin* plugin_; bool windowless_; gfx::PluginWindowHandle window_; scoped_refptr<PluginChannelHost> channel_host_; 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', |