diff options
42 files changed, 761 insertions, 495 deletions
diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h index ab2ec6f..3bc169b 100644 --- a/chrome/common/plugin_messages_internal.h +++ b/chrome/common/plugin_messages_internal.h @@ -159,8 +159,10 @@ IPC_BEGIN_MESSAGES(Plugin) int /* route_id */, intptr_t /* npobject_ptr */) - IPC_SYNC_MESSAGE_ROUTED1_0(PluginMsg_DidFinishLoadWithReason, - int /* reason */) + IPC_SYNC_MESSAGE_ROUTED3_0(PluginMsg_DidFinishLoadWithReason, + GURL /* url */, + int /* reason */, + intptr_t /* notify_data */) // Updates the plugin location. For windowless plugins, windowless_buffer // contains a buffer that the plugin draws into. background_buffer is used @@ -198,8 +200,8 @@ IPC_BEGIN_MESSAGES(Plugin) int /* id */) IPC_MESSAGE_ROUTED5(PluginMsg_SendJavaScriptStream, - std::string /* url */, - std::wstring /* result */, + GURL /* url */, + std::string /* result */, bool /* success */, bool /* notify required */, intptr_t /* notify data */) @@ -219,11 +221,6 @@ IPC_BEGIN_MESSAGES(Plugin) IPC_SYNC_MESSAGE_ROUTED1_0(PluginMsg_HandleURLRequestReply, PluginMsg_URLRequestReply_Params) - - IPC_SYNC_MESSAGE_ROUTED3_0(PluginMsg_URLRequestRouted, - std::string /* url */, - bool /* notify_needed */, - intptr_t /* notify data */) IPC_END_MESSAGES(Plugin) diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index a8a652f..9b33329 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -107,7 +107,6 @@ void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginMsg_InstallMissingPlugin, OnInstallMissingPlugin) IPC_MESSAGE_HANDLER(PluginMsg_HandleURLRequestReply, OnHandleURLRequestReply) - IPC_MESSAGE_HANDLER(PluginMsg_URLRequestRouted, OnURLRequestRouted) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() @@ -214,8 +213,9 @@ void WebPluginDelegateStub::OnDidFail(int id) { client->DidFail(); } -void WebPluginDelegateStub::OnDidFinishLoadWithReason(int reason) { - delegate_->DidFinishLoadWithReason(reason); +void WebPluginDelegateStub::OnDidFinishLoadWithReason( + const GURL& url, int reason, intptr_t notify_data) { + delegate_->DidFinishLoadWithReason(url, reason, notify_data); } void WebPluginDelegateStub::OnSetFocus() { @@ -299,8 +299,8 @@ void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, WebBindings::releaseObject(object); } -void WebPluginDelegateStub::OnSendJavaScriptStream(const std::string& url, - const std::wstring& result, +void WebPluginDelegateStub::OnSendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data) { @@ -374,9 +374,3 @@ void WebPluginDelegateStub::OnHandleURLRequestReply( params.stream); webplugin_->OnResourceCreated(params.resource_id, resource_client); } - -void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, - bool notify_needed, - intptr_t notify_data) { - delegate_->URLRequestRouted(url, notify_needed, notify_data); -} diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index e385156..d0c6542 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -58,7 +58,8 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, void OnDidFinishLoading(int id); void OnDidFail(int id); - void OnDidFinishLoadWithReason(int reason); + void OnDidFinishLoadWithReason(const GURL& url, int reason, + intptr_t notify_data); void OnSetFocus(); void OnHandleInputEvent(const WebKit::WebInputEvent* event, bool* handled, WebCursor* cursor); @@ -73,8 +74,8 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, const TransportDIB::Handle& windowless_buffer, const TransportDIB::Handle& background_buffer); void OnGetPluginScriptableObject(int* route_id, intptr_t* npobject_ptr); - void OnSendJavaScriptStream(const std::string& url, - const std::wstring& result, + void OnSendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data); @@ -89,9 +90,6 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, void OnHandleURLRequestReply( const PluginMsg_URLRequestReply_Params& params); - void OnURLRequestRouted(const std::string& url, bool notify_needed, - intptr_t notify_data); - void CreateSharedBuffer(size_t size, base::SharedMemory* shared_buf, base::SharedMemoryHandle* remote_handle); diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc index f09b361..96bcc8f 100644 --- a/chrome/renderer/render_view_unittest.cc +++ b/chrome/renderer/render_view_unittest.cc @@ -11,10 +11,12 @@ #include "printing/image.h" #include "printing/native_metafile.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURLError.h" using WebKit::WebCompositionCommand; using WebKit::WebFrame; +using WebKit::WebString; using WebKit::WebTextDirection; using WebKit::WebURLError; @@ -382,7 +384,8 @@ TEST_F(RenderViewTest, PrintWithIframe) { // Find the frame and set it as the focused one. This should mean that that // the printout should only contain the contents of that frame. - WebFrame* sub1_frame = view_->webview()->GetFrameWithName(L"sub1"); + WebFrame* sub1_frame = + view_->webview()->GetFrameWithName(WebString::fromUTF8("sub1")); ASSERT_TRUE(sub1_frame); view_->webview()->SetFocusedFrame(sub1_frame); ASSERT_NE(view_->webview()->GetFocusedFrame(), diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 56da66c..c72c654 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -306,8 +306,8 @@ bool WebPluginDelegateProxy::Send(IPC::Message* msg) { return channel_host_->Send(msg); } -void WebPluginDelegateProxy::SendJavaScriptStream(const std::string& url, - const std::wstring& result, +void WebPluginDelegateProxy::SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data) { @@ -756,8 +756,10 @@ NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { return WebBindings::retainObject(npobject_); } -void WebPluginDelegateProxy::DidFinishLoadWithReason(NPReason reason) { - Send(new PluginMsg_DidFinishLoadWithReason(instance_id_, reason)); +void WebPluginDelegateProxy::DidFinishLoadWithReason( + const GURL& url, NPReason reason, intptr_t notify_data) { + Send(new PluginMsg_DidFinishLoadWithReason( + instance_id_, url, reason, notify_data)); } void WebPluginDelegateProxy::SetFocus() { @@ -1056,13 +1058,6 @@ WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient( return proxy; } -void WebPluginDelegateProxy::URLRequestRouted(const std::string& url, - bool notify_needed, - intptr_t notify_data) { - Send(new PluginMsg_URLRequestRouted(instance_id_, url, notify_needed, - notify_data)); -} - void WebPluginDelegateProxy::OnCancelDocumentLoad() { plugin_->CancelDocumentLoad(); } diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index 5680d9e..61dfa8b 100644 --- a/chrome/renderer/webplugin_delegate_proxy.h +++ b/chrome/renderer/webplugin_delegate_proxy.h @@ -58,7 +58,8 @@ class WebPluginDelegateProxy : public WebPluginDelegate, virtual void Paint(gfx::NativeDrawingContext context, const gfx::Rect& rect); virtual void Print(gfx::NativeDrawingContext context); virtual NPObject* GetPluginScriptableObject(); - virtual void DidFinishLoadWithReason(NPReason reason); + virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, + intptr_t notify_data); virtual void SetFocus(); virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, WebKit::WebCursorInfo* cursor); @@ -71,8 +72,8 @@ class WebPluginDelegateProxy : public WebPluginDelegate, // IPC::Message::Sender implementation: virtual bool Send(IPC::Message* msg); - virtual void SendJavaScriptStream(const std::string& url, - const std::wstring& result, + virtual void SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data); @@ -92,10 +93,6 @@ class WebPluginDelegateProxy : public WebPluginDelegate, intptr_t notify_data, intptr_t existing_stream); - // Notifies the delegate about a Get/Post URL request getting routed - virtual void URLRequestRouted(const std::string&url, bool notify_needed, - intptr_t notify_data); - protected: template<class WebPluginDelegateProxy> friend class DeleteTask; ~WebPluginDelegateProxy(); diff --git a/webkit/api/public/WebPlugin.h b/webkit/api/public/WebPlugin.h index 1d0b900..35caed3 100644 --- a/webkit/api/public/WebPlugin.h +++ b/webkit/api/public/WebPlugin.h @@ -36,7 +36,10 @@ struct NPObject; namespace WebKit { + class WebDataSource; + class WebFrame; class WebInputEvent; + class WebURL; class WebURLResponse; struct WebCursorInfo; struct WebRect; @@ -67,6 +70,12 @@ namespace WebKit { virtual void didFinishLoading() = 0; virtual void didFailLoading(const WebURLError&) = 0; + // Called in response to WebPluginContainer::loadFrameRequest + virtual void didFinishLoadingFrameRequest( + const WebURL&, void* notifyData) = 0; + virtual void didFailLoadingFrameRequest( + const WebURL&, void* notifyData, const WebURLError&) = 0; + protected: ~WebPlugin() { } }; diff --git a/webkit/api/public/WebPluginContainer.h b/webkit/api/public/WebPluginContainer.h index 61b1421..18013d7 100644 --- a/webkit/api/public/WebPluginContainer.h +++ b/webkit/api/public/WebPluginContainer.h @@ -34,6 +34,9 @@ struct NPObject; namespace WebKit { + class WebString; + class WebURL; + class WebURLRequest; struct WebRect; class WebPluginContainer { @@ -45,6 +48,20 @@ namespace WebKit { // containing the plugin. virtual NPObject* scriptableObjectForElement() = 0; + // Executes a "javascript:" URL on behalf of the plugin in the context + // of the frame containing the plugin. Returns the result of script + // execution, if any. + virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed) = 0; + + // Loads an URL in the specified frame (or the frame containing this + // plugin if target is empty). If notifyNeeded is true, then upon + // completion, WebPlugin::didFinishLoadingFrameRequest is called if the + // load was successful or WebPlugin::didFailLoadingFrameRequest is + // called if the load failed. The given notifyData is passed along to + // the callback. + virtual void loadFrameRequest( + const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) = 0; + protected: ~WebPluginContainer() { } }; diff --git a/webkit/api/src/WebDataSourceImpl.cpp b/webkit/api/src/WebDataSourceImpl.cpp new file mode 100644 index 0000000..67740a6 --- /dev/null +++ b/webkit/api/src/WebDataSourceImpl.cpp @@ -0,0 +1,173 @@ +/* + * 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. + */ + +#include "config.h" +#include "WebDataSourceImpl.h" + +#include "WebURL.h" +#include "WebURLError.h" +#include "WebVector.h" + +using namespace WebCore; + +namespace WebKit { + +WebPluginLoadObserver* WebDataSourceImpl::m_nextPluginLoadObserver = 0; + +PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::create(const ResourceRequest& request, const SubstituteData& data) +{ + return adoptRef(new WebDataSourceImpl(request, data)); +} + +const WebURLRequest& WebDataSourceImpl::originalRequest() const +{ + m_originalRequestWrapper.bind(DocumentLoader::originalRequest()); + return m_originalRequestWrapper; +} + +const WebURLRequest& WebDataSourceImpl::request() const +{ + m_requestWrapper.bind(DocumentLoader::request()); + return m_requestWrapper; +} + +const WebURLResponse& WebDataSourceImpl::response() const +{ + m_responseWrapper.bind(DocumentLoader::response()); + return m_responseWrapper; +} + +bool WebDataSourceImpl::hasUnreachableURL() const +{ + return !DocumentLoader::unreachableURL().isEmpty(); +} + +WebURL WebDataSourceImpl::unreachableURL() const +{ + return DocumentLoader::unreachableURL(); +} + +void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const +{ + result.assign(m_redirectChain); +} + +WebString WebDataSourceImpl::pageTitle() const +{ + return title(); +} + +WebNavigationType WebDataSourceImpl::navigationType() const +{ + return toWebNavigationType(triggeringAction().type()); +} + +double WebDataSourceImpl::triggeringEventTime() const +{ + if (!triggeringAction().event()) + return 0.0; + + // DOMTimeStamp uses units of milliseconds. + return triggeringAction().event()->timeStamp() / 1000.0; +} + +WebDataSource::ExtraData* WebDataSourceImpl::extraData() const +{ + return m_extraData.get(); +} + +void WebDataSourceImpl::setExtraData(ExtraData* extraData) +{ + m_extraData.set(extraData); +} + +WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type) +{ + switch (type) { + case NavigationTypeLinkClicked: + return WebNavigationTypeLinkClicked; + case NavigationTypeFormSubmitted: + return WebNavigationTypeFormSubmitted; + case NavigationTypeBackForward: + return WebNavigationTypeBackForward; + case NavigationTypeReload: + return WebNavigationTypeReload; + case NavigationTypeFormResubmitted: + return WebNavigationTypeFormResubmitted; + case NavigationTypeOther: + default: + return WebNavigationTypeOther; + } +} + +WebURL WebDataSourceImpl::endOfRedirectChain() const +{ + ASSERT(!m_redirectChain.isEmpty()); + return m_redirectChain.last(); +} + +void WebDataSourceImpl::clearRedirectChain() +{ + m_redirectChain.clear(); +} + +void WebDataSourceImpl::appendRedirect(const WebURL& url) +{ + m_redirectChain.append(url); +} + +void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer) +{ + // This call should always be followed up with the creation of a + // WebDataSourceImpl, so we should never leak this object. + m_nextPluginLoadObserver = observer.release(); +} + +WebDataSourceImpl::WebDataSourceImpl(const ResourceRequest& request, const SubstituteData& data) + : DocumentLoader(request, data) +{ + if (m_nextPluginLoadObserver) { + // When a new frame is created, it initially gets a data source for an + // empty document. Then it is navigated to the source URL of the + // frame, which results in a second data source being created. We want + // to wait to attach the WebPluginLoadObserver to that data source. + if (!request.url().isEmpty()) { + ASSERT(m_nextPluginLoadObserver->url() == request.url()); + m_pluginLoadObserver.set(m_nextPluginLoadObserver); + m_nextPluginLoadObserver = 0; + } + } +} + +WebDataSourceImpl::~WebDataSourceImpl() +{ +} + +} // namespace WebKit diff --git a/webkit/api/src/WebDataSourceImpl.h b/webkit/api/src/WebDataSourceImpl.h new file mode 100644 index 0000000..2e3e9c8 --- /dev/null +++ b/webkit/api/src/WebDataSourceImpl.h @@ -0,0 +1,105 @@ +/* + * 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 WebDataSourceImpl_h +#define WebDataSourceImpl_h + +// FIXME: This relative path is a temporary hack to support using this +// header from webkit/glue. +#include "../public/WebDataSource.h" +#include "WebPluginLoadObserver.h" +#include "WrappedResourceRequest.h" +#include "WrappedResourceResponse.h" + +#include "DocumentLoader.h" +#include <wtf/PassOwnPtr.h> +#include <wtf/OwnPtr.h> +#include <wtf/Vector.h> + +namespace WebKit { + class WebPluginLoadObserver; + + class WebDataSourceImpl : public WebCore::DocumentLoader, public WebDataSource { + public: + static PassRefPtr<WebDataSourceImpl> create(const WebCore::ResourceRequest&, + const WebCore::SubstituteData&); + + static WebDataSourceImpl* fromDocumentLoader(WebCore::DocumentLoader* loader) + { + return static_cast<WebDataSourceImpl*>(loader); + } + + // WebDataSource methods: + virtual const WebURLRequest& originalRequest() const; + virtual const WebURLRequest& request() const; + virtual const WebURLResponse& response() const; + virtual bool hasUnreachableURL() const; + virtual WebURL unreachableURL() const; + virtual void redirectChain(WebVector<WebURL>&) const; + virtual WebString pageTitle() const; + virtual WebNavigationType navigationType() const; + virtual double triggeringEventTime() const; + virtual ExtraData* extraData() const; + virtual void setExtraData(ExtraData*); + + static WebNavigationType toWebNavigationType(WebCore::NavigationType type); + + bool hasRedirectChain() const { return !m_redirectChain.isEmpty(); } + WebURL endOfRedirectChain() const; + void clearRedirectChain(); + void appendRedirect(const WebURL& url); + + PassOwnPtr<WebPluginLoadObserver> releasePluginLoadObserver() { return m_pluginLoadObserver.release(); } + static void setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver>); + + private: + WebDataSourceImpl(const WebCore::ResourceRequest&, const WebCore::SubstituteData&); + ~WebDataSourceImpl(); + + // Mutable because the const getters will magically sync these to the + // latest version from WebKit. + mutable WrappedResourceRequest m_originalRequestWrapper; + mutable WrappedResourceRequest m_requestWrapper; + mutable WrappedResourceResponse m_responseWrapper; + + // Lists all intermediate URLs that have redirected for the current provisional load. + // See WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad for a + // description of who modifies this when to keep it up to date. + Vector<WebURL> m_redirectChain; + + OwnPtr<ExtraData> m_extraData; + OwnPtr<WebPluginLoadObserver> m_pluginLoadObserver; + + static WebPluginLoadObserver* m_nextPluginLoadObserver; + }; + +} // namespace WebKit + +#endif // WebDataSourceImpl_h diff --git a/webkit/api/src/WebPluginContainerImpl.cpp b/webkit/api/src/WebPluginContainerImpl.cpp index 065d85e..fb1e416 100644 --- a/webkit/api/src/WebPluginContainerImpl.cpp +++ b/webkit/api/src/WebPluginContainerImpl.cpp @@ -33,20 +33,25 @@ #include "TemporaryGlue.h" #include "WebCursorInfo.h" +#include "WebDataSourceImpl.h" #include "WebInputEvent.h" #include "WebInputEventConversion.h" #include "WebPlugin.h" #include "WebRect.h" #include "WebURLError.h" +#include "WebURLRequest.h" #include "WebVector.h" #include "WrappedResourceResponse.h" #include "EventNames.h" #include "FocusController.h" +#include "FormState.h" #include "Frame.h" +#include "FrameLoadRequest.h" #include "FrameView.h" #include "GraphicsContext.h" #include "HostWindow.h" +#include "HTMLFormElement.h" #include "HTMLNames.h" #include "HTMLPlugInElement.h" #include "KeyboardEvent.h" @@ -219,6 +224,52 @@ NPObject* WebPluginContainerImpl::scriptableObjectForElement() return m_element->getNPObject(); } +WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popupsAllowed) +{ + Frame* frame = m_element->document()->frame(); + if (!frame) + return WebString(); + + const KURL& kurl = url; + ASSERT(kurl.protocolIs("javascript")); + + String script = decodeURLEscapeSequences( + kurl.string().substring(strlen("javascript:"))); + + ScriptValue result = frame->loader()->executeScript(script, popupsAllowed); + + // Failure is reported as a null string. + String resultStr; + result.getString(resultStr); + return resultStr; +} + +void WebPluginContainerImpl::loadFrameRequest( + const WebURLRequest& request, const WebString& target, bool notifyNeeded, void* notifyData) +{ + Frame* frame = m_element->document()->frame(); + if (!frame) + return; // FIXME: send a notification in this case? + + if (notifyNeeded) { + // FIXME: This is a bit of hack to allow us to observe completion of + // our frame request. It would be better to evolve FrameLoader to + // support a completion callback instead. + WebDataSourceImpl::setNextPluginLoadObserver( + new WebPluginLoadObserver(this, request.url(), notifyData)); + } + + FrameLoadRequest frameRequest(request.toResourceRequest()); + frameRequest.setFrameName(target); + + frame->loader()->loadFrameRequest( + frameRequest, + false, // lock history + false, // lock back forward list + 0, // event + 0); // form state +} + void WebPluginContainerImpl::didReceiveResponse(const ResourceResponse& response) { // Make sure that the plugin receives window geometry before data, or else @@ -249,6 +300,14 @@ NPObject* WebPluginContainerImpl::scriptableObject() return m_webPlugin->scriptableObject(); } +void WebPluginContainerImpl::willDestroyPluginLoadObserver(WebPluginLoadObserver* observer) +{ + size_t pos = m_pluginLoadObservers.find(observer); + if (pos == notFound) + return; + m_pluginLoadObservers.remove(pos); +} + // Private methods ------------------------------------------------------------- WebPluginContainerImpl::~WebPluginContainerImpl() diff --git a/webkit/api/src/WebPluginContainerImpl.h b/webkit/api/src/WebPluginContainerImpl.h index d8f34cd..4e527d9 100644 --- a/webkit/api/src/WebPluginContainerImpl.h +++ b/webkit/api/src/WebPluginContainerImpl.h @@ -52,6 +52,7 @@ namespace WebCore { namespace WebKit { class WebPlugin; + class WebPluginLoadObserver; class WebPluginContainerImpl : public WebCore::Widget, public WebPluginContainer { public: @@ -76,6 +77,8 @@ namespace WebKit { virtual void invalidate(); virtual void invalidateRect(const WebRect&); virtual NPObject* scriptableObjectForElement(); + virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed); + virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData); // Resource load events for the plugin's source data: void didReceiveResponse(const WebCore::ResourceResponse&); @@ -85,6 +88,11 @@ namespace WebKit { NPObject* scriptableObject(); + // This cannot be null. + WebPlugin* plugin() { return m_webPlugin; } + + void willDestroyPluginLoadObserver(WebPluginLoadObserver*); + private: WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin) : m_element(element) @@ -104,6 +112,7 @@ namespace WebKit { WebCore::HTMLPlugInElement* m_element; WebPlugin* m_webPlugin; + Vector<WebPluginLoadObserver*> m_pluginLoadObservers; }; } // namespace WebKit diff --git a/webkit/api/src/WebPluginLoadObserver.cpp b/webkit/api/src/WebPluginLoadObserver.cpp new file mode 100644 index 0000000..5ec59a6 --- /dev/null +++ b/webkit/api/src/WebPluginLoadObserver.cpp @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#include "config.h" +#include "WebPluginLoadObserver.h" + +#include "WebPlugin.h" +#include "WebPluginContainerImpl.h" + +namespace WebKit { + +WebPluginLoadObserver::~WebPluginLoadObserver() +{ + if (m_pluginContainer) + m_pluginContainer->willDestroyPluginLoadObserver(this); +} + +void WebPluginLoadObserver::didFinishLoading() +{ + if (m_pluginContainer) + m_pluginContainer->plugin()->didFinishLoadingFrameRequest(m_notifyURL, m_notifyData); +} + +void WebPluginLoadObserver::didFailLoading(const WebURLError& error) +{ + if (m_pluginContainer) + m_pluginContainer->plugin()->didFailLoadingFrameRequest(m_notifyURL, m_notifyData, error); +} + +} // namespace WebKit diff --git a/webkit/api/src/WebPluginLoadObserver.h b/webkit/api/src/WebPluginLoadObserver.h new file mode 100644 index 0000000..1828f8f --- /dev/null +++ b/webkit/api/src/WebPluginLoadObserver.h @@ -0,0 +1,66 @@ +/* + * 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 WebPluginLoadObserver_h +#define WebPluginLoadObserver_h + +#include "../public/WebURL.h" + +namespace WebKit { + class WebPluginContainerImpl; + struct WebURLError; + + class WebPluginLoadObserver { + public: + WebPluginLoadObserver(WebPluginContainerImpl* pluginContainer, + const WebURL& notifyURL, void* notifyData) + : m_pluginContainer(pluginContainer) + , m_notifyURL(notifyURL) + , m_notifyData(notifyData) + { + } + + ~WebPluginLoadObserver(); + + const WebURL& url() const { return m_notifyURL; } + + void clearPluginContainer() { m_pluginContainer = 0; } + void didFinishLoading(); + void didFailLoading(const WebURLError&); + + private: + WebPluginContainerImpl* m_pluginContainer; + WebURL m_notifyURL; + void* m_notifyData; + }; + +} // namespace WebKit + +#endif diff --git a/webkit/data/layout_tests/chrome/plugins/get-url-with-blank-target.html b/webkit/data/layout_tests/chrome/plugins/get-url-with-blank-target.html index c61db2b..6e69390 100644 --- a/webkit/data/layout_tests/chrome/plugins/get-url-with-blank-target.html +++ b/webkit/data/layout_tests/chrome/plugins/get-url-with-blank-target.html @@ -18,7 +18,11 @@ function runtest() { if (window.layoutTestController) { layoutTestController.dumpAsText(); layoutTestController.waitUntilDone(); - plg.getURLNotify("http://www.apple.com", "_blank", "callback"); + layoutTestController.setCanOpenWindows(); + // The new window should close immediately after it opens and finishes + // loading. The setTimeout allows NPP_URLNotify to run before the + // window is closed. + plg.getURLNotify("data:text/html,<body onload='setTimeout(function(){close()},0)'></body>", "_blank", "callback"); } else { document.write("Cannot run interactively"); } diff --git a/webkit/data/layout_tests/chrome/plugins/get-url-with-iframe-target-expected.txt b/webkit/data/layout_tests/chrome/plugins/get-url-with-iframe-target-expected.txt new file mode 100644 index 0000000..2499c66 --- /dev/null +++ b/webkit/data/layout_tests/chrome/plugins/get-url-with-iframe-target-expected.txt @@ -0,0 +1,3 @@ + This tests that the plugin properly receives NPP_URLNotify for subframe loads. +SUCCESS + diff --git a/webkit/data/layout_tests/chrome/plugins/get-url-with-iframe-target.html b/webkit/data/layout_tests/chrome/plugins/get-url-with-iframe-target.html new file mode 100644 index 0000000..b984540 --- /dev/null +++ b/webkit/data/layout_tests/chrome/plugins/get-url-with-iframe-target.html @@ -0,0 +1,33 @@ +<html> +<script> +var NPERR_NO_ERROR = 0; +var NPERR_GENERIC_ERROR = 1; + +function callback(result) { + var d = document.getElementById('result'); + + if (result == NPERR_NO_ERROR) + d.innerHTML = "SUCCESS" + else + d.innerHTML = "FAILED - got error code " + result + + layoutTestController.notifyDone(); +} + +function runtest() { + if (window.layoutTestController) { + layoutTestController.dumpAsText(); + layoutTestController.waitUntilDone(); + plg.getURLNotify("data:,hello world", "frame", "callback"); + } else { + document.write("Cannot run interactively"); + } +} +</script> +<body onload="runtest()"> +<embed id="plg" type="application/x-webkit-test-netscape"></embed> +This tests that the plugin properly receives NPP_URLNotify for subframe loads. +<div id="result">FAILED</div> +<iframe id="frame"></iframe> +</body> +</html> diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc index ca2dee8..c3c6ff2 100644 --- a/webkit/glue/context_menu_client_impl.cc +++ b/webkit/glue/context_menu_client_impl.cc @@ -28,14 +28,15 @@ MSVC_POP_WARNING(); #include "base/string_util.h" #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebURLResponse.h" +#include "webkit/api/src/WebDataSourceImpl.h" #include "webkit/glue/context_menu.h" #include "webkit/glue/glue_util.h" -#include "webkit/glue/webdatasource_impl.h" #include "webkit/glue/webview_impl.h" #include "base/word_iterator.h" using WebKit::WebDataSource; +using WebKit::WebDataSourceImpl; namespace { @@ -135,7 +136,7 @@ static ContextNodeType GetTypeAndURLFromFrame( if (frame) { WebCore::DocumentLoader* dl = frame->loader()->documentLoader(); if (dl) { - WebDataSource* ds = WebDataSourceImpl::FromLoader(dl); + WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); if (ds) { node_type = page_node_type; *url = ds->hasUnreachableURL() ? ds->unreachableURL() @@ -260,7 +261,7 @@ WebCore::PlatformMenuDescription // Now retrieve the security info. WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader(); - WebDataSource* ds = WebDataSourceImpl::FromLoader(dl); + WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); if (ds) security_info = ds->response().securityInfo(); diff --git a/webkit/glue/iframe_redirect_unittest.cc b/webkit/glue/iframe_redirect_unittest.cc index 1a4fa03..2778c09 100644 --- a/webkit/glue/iframe_redirect_unittest.cc +++ b/webkit/glue/iframe_redirect_unittest.cc @@ -12,6 +12,7 @@ #include "base/string_util.h" #include "webkit/api/public/WebDataSource.h" #include "webkit/api/public/WebFrame.h" +#include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebVector.h" #include "webkit/glue/webkit_glue.h" @@ -20,6 +21,7 @@ using WebKit::WebDataSource; using WebKit::WebFrame; +using WebKit::WebString; using WebKit::WebURL; using WebKit::WebVector; @@ -38,7 +40,8 @@ TEST_F(IFrameRedirectTest, Test) { test_shell_->LoadURL(test_url.c_str()); test_shell_->WaitTestFinished(); - WebFrame* iframe = test_shell_->webView()->GetFrameWithName(L"ifr"); + WebFrame* iframe = + test_shell_->webView()->GetFrameWithName(WebString::fromUTF8("ifr")); ASSERT_TRUE(iframe != NULL); WebDataSource* iframe_ds = iframe->dataSource(); ASSERT_TRUE(iframe_ds != NULL); diff --git a/webkit/glue/plugins/plugin_instance.cc b/webkit/glue/plugins/plugin_instance.cc index a753004..ad8c9bf 100644 --- a/webkit/glue/plugins/plugin_instance.cc +++ b/webkit/glue/plugins/plugin_instance.cc @@ -41,7 +41,6 @@ PluginInstance::PluginInstance(PluginLib *plugin, const std::string &mime_type) transparent_(true), webplugin_(0), mime_type_(mime_type), - get_notify_data_(NULL), use_mozilla_user_agent_(false), message_loop_(MessageLoop::current()), load_manually_(false), @@ -158,21 +157,10 @@ NPObject *PluginInstance::GetPluginScriptableObject() { return value; } -void PluginInstance::SetURLLoadData(const GURL& url, - intptr_t notify_data) { - get_url_ = url; - get_notify_data_ = notify_data; -} - // WebPluginLoadDelegate methods -void PluginInstance::DidFinishLoadWithReason(NPReason reason) { - if (!get_url_.is_empty()) { - NPP_URLNotify(get_url_.spec().c_str(), reason, - reinterpret_cast<void*>(get_notify_data_)); - } - - get_url_ = GURL(); - get_notify_data_ = NULL; +void PluginInstance::DidFinishLoadWithReason(const GURL& url, NPReason reason, + void* notify_data) { + NPP_URLNotify(url.spec().c_str(), reason, notify_data); } // NPAPI methods @@ -340,8 +328,8 @@ bool PluginInstance::NPP_Print(NPPrint* platform_print) { return false; } -void PluginInstance::SendJavaScriptStream(const std::string& url, - const std::wstring& result, +void PluginInstance::SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data) { @@ -350,12 +338,12 @@ void PluginInstance::SendJavaScriptStream(const std::string& url, new PluginStringStream(this, url, notify_needed, reinterpret_cast<void*>(notify_data)); AddStream(stream); - stream->SendToPlugin(WideToUTF8(result), "text/html"); + stream->SendToPlugin(result, "text/html"); } else { // NOTE: Sending an empty stream here will crash MacroMedia // Flash 9. Just send the URL Notify. if (notify_needed) { - this->NPP_URLNotify(url.c_str(), NPRES_DONE, + this->NPP_URLNotify(url.spec().c_str(), NPRES_DONE, reinterpret_cast<void*>(notify_data)); } } diff --git a/webkit/glue/plugins/plugin_instance.h b/webkit/glue/plugins/plugin_instance.h index bed2a55..5639211 100644 --- a/webkit/glue/plugins/plugin_instance.h +++ b/webkit/glue/plugins/plugin_instance.h @@ -135,11 +135,8 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { // WebViewDelegate methods that we implement. This is for handling // callbacks during getURLNotify. - virtual void DidFinishLoadWithReason(NPReason reason); - - // Helper method to set some persistent data for getURLNotify since - // resource fetches happen async. - void SetURLLoadData(const GURL& url, intptr_t notify_data); + virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, + void* notify_data); // If true, send the Mozilla user agent instead of Chrome's to the plugin. bool use_mozilla_user_agent() { return use_mozilla_user_agent_; } @@ -166,7 +163,7 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { void NPP_Destroy(); bool NPP_Print(NPPrint* platform_print); - void SendJavaScriptStream(const std::string& url, const std::wstring& result, + void SendJavaScriptStream(const GURL& url, const std::string& result, bool success, bool notify_needed, intptr_t notify_data); diff --git a/webkit/glue/plugins/plugin_string_stream.cc b/webkit/glue/plugins/plugin_string_stream.cc index f1e2a1a..3997fba 100644 --- a/webkit/glue/plugins/plugin_string_stream.cc +++ b/webkit/glue/plugins/plugin_string_stream.cc @@ -4,14 +4,16 @@ #include "webkit/glue/plugins/plugin_string_stream.h" +#include "googleurl/src/gurl.h" + namespace NPAPI { PluginStringStream::PluginStringStream( - PluginInstance *instance, - const std::string &url, + PluginInstance* instance, + const GURL& url, bool notify_needed, - void *notify_data) - : PluginStream(instance, url.c_str(), notify_needed, notify_data) { + void* notify_data) + : PluginStream(instance, url.spec().c_str(), notify_needed, notify_data) { } PluginStringStream::~PluginStringStream() { diff --git a/webkit/glue/plugins/plugin_string_stream.h b/webkit/glue/plugins/plugin_string_stream.h index a8a25ad..0946934 100644 --- a/webkit/glue/plugins/plugin_string_stream.h +++ b/webkit/glue/plugins/plugin_string_stream.h @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_STRING_STREAM_H__ -#define WEBKIT_GLUE_PLUGIN_PLUGIN_STRING_STREAM_H__ +#ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_STRING_STREAM_H_ +#define WEBKIT_GLUE_PLUGIN_PLUGIN_STRING_STREAM_H_ #include "webkit/glue/plugins/plugin_stream.h" +class GURL; + namespace NPAPI { class PluginInstance; @@ -17,21 +19,20 @@ class PluginStringStream : public PluginStream { // Create a new stream for sending to the plugin. // If notify_needed, will notify the plugin after the data has // all been sent. - PluginStringStream(PluginInstance *instance, - const std::string &url, + PluginStringStream(PluginInstance* instance, + const GURL& url, bool notify_needed, - void *notify_data); + void* notify_data); virtual ~PluginStringStream(); // Initiates the sending of data to the plugin. - void SendToPlugin(const std::string &data, - const std::string &mime_type); + void SendToPlugin(const std::string& data, + const std::string& mime_type); private: - - DISALLOW_EVIL_CONSTRUCTORS(PluginStringStream); + DISALLOW_COPY_AND_ASSIGN(PluginStringStream); }; } // namespace NPAPI -#endif // WEBKIT_GLUE_PLUGIN_PLUGIN_STRING_STREAM_H__ +#endif // WEBKIT_GLUE_PLUGIN_PLUGIN_STRING_STREAM_H_ diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index a76e5d9..89285b6 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -130,8 +130,11 @@ NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { return instance_->GetPluginScriptableObject(); } -void WebPluginDelegateImpl::DidFinishLoadWithReason(NPReason reason) { - instance()->DidFinishLoadWithReason(reason); +void WebPluginDelegateImpl::DidFinishLoadWithReason(const GURL& url, + NPReason reason, + intptr_t notify_data) { + instance()->DidFinishLoadWithReason( + url, reason, reinterpret_cast<void*>(notify_data)); } int WebPluginDelegateImpl::GetProcessId() { @@ -139,8 +142,8 @@ int WebPluginDelegateImpl::GetProcessId() { return base::GetCurrentProcId(); } -void WebPluginDelegateImpl::SendJavaScriptStream(const std::string& url, - const std::wstring& result, +void WebPluginDelegateImpl::SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data) { @@ -200,20 +203,9 @@ WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( return plugin_stream->AsResourceClient(); } - if (notify_needed) { - instance()->SetURLLoadData(url, notify_data); - } std::string mime_type; NPAPI::PluginStreamUrl *stream = instance()->CreateStream( resource_id, url, mime_type, notify_needed, reinterpret_cast<void*>(notify_data)); return stream; } - -void WebPluginDelegateImpl::URLRequestRouted(const std::string&url, - bool notify_needed, - intptr_t notify_data) { - if (notify_needed) { - instance()->SetURLLoadData(GURL(url.c_str()), notify_data); - } -} diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index 6563003..9ecd733 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -58,11 +58,12 @@ class WebPluginDelegateImpl : public WebPluginDelegate { virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, WebKit::WebCursorInfo* cursor); virtual NPObject* GetPluginScriptableObject(); - virtual void DidFinishLoadWithReason(NPReason reason); + virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, + intptr_t notify_data); virtual int GetProcessId(); - virtual void SendJavaScriptStream(const std::string& url, - const std::wstring& result, + virtual void SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data); virtual void DidReceiveManualResponse(const GURL& url, @@ -81,8 +82,6 @@ class WebPluginDelegateImpl : public WebPluginDelegate { intptr_t notify_data, intptr_t stream); - virtual void URLRequestRouted(const std::string&url, bool notify_needed, - intptr_t notify_data); virtual bool IsWindowless() const { return windowless_ ; } virtual const gfx::Rect& GetRect() const { return window_rect_; } virtual const gfx::Rect& GetClipRect() const { return clip_rect_; } diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc index d0afce8..ad93428b 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc @@ -708,4 +708,3 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, return ret; } - diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index 62ea2de..485c6af 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -202,8 +202,10 @@ NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { return instance_->GetPluginScriptableObject(); } -void WebPluginDelegateImpl::DidFinishLoadWithReason(NPReason reason) { - instance()->DidFinishLoadWithReason(reason); +void WebPluginDelegateImpl::DidFinishLoadWithReason( + const GURL& url, NPReason reason, intptr_t notify_data) { + instance()->DidFinishLoadWithReason( + url, reason, reinterpret_cast<void*>(notify_data)); } int WebPluginDelegateImpl::GetProcessId() { @@ -211,8 +213,8 @@ int WebPluginDelegateImpl::GetProcessId() { return getpid(); } -void WebPluginDelegateImpl::SendJavaScriptStream(const std::string& url, - const std::wstring& result, +void WebPluginDelegateImpl::SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data) { @@ -532,9 +534,6 @@ WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( return plugin_stream->AsResourceClient(); } - if (notify_needed) { - instance()->SetURLLoadData(url, notify_data); - } std::string mime_type; NPAPI::PluginStreamUrl *stream = instance()->CreateStream( resource_id, url, mime_type, notify_needed, @@ -542,14 +541,6 @@ WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( return stream; } -void WebPluginDelegateImpl::URLRequestRouted(const std::string&url, - bool notify_needed, - intptr_t notify_data) { - if (notify_needed) { - instance()->SetURLLoadData(GURL(url.c_str()), notify_data); - } -} - void WebPluginDelegateImpl::OnNullEvent() { NPEvent np_event = {0}; np_event.what = nullEvent; diff --git a/webkit/glue/webdatasource_impl.cc b/webkit/glue/webdatasource_impl.cc deleted file mode 100644 index b67c57d..0000000 --- a/webkit/glue/webdatasource_impl.cc +++ /dev/null @@ -1,121 +0,0 @@ -// 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 "webkit/glue/webdatasource_impl.h" - -#include "webkit/api/public/WebURL.h" -#include "webkit/api/public/WebVector.h" -#include "webkit/glue/glue_util.h" - -using WebCore::DocumentLoader; -using WebCore::ResourceRequest; -using WebCore::ResourceResponse; -using WebCore::SubstituteData; - -using WebKit::WebDataSource; -using WebKit::WebNavigationType; -using WebKit::WebString; -using WebKit::WebURL; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; -using WebKit::WebVector; - -// static -PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::Create( - const ResourceRequest& request, - const SubstituteData& data) { - return adoptRef(new WebDataSourceImpl(request, data)); -} - -WebDataSourceImpl::WebDataSourceImpl(const ResourceRequest& request, - const SubstituteData& data) - : DocumentLoader(request, data) { -} - -WebDataSourceImpl::~WebDataSourceImpl() { -} - -const WebURLRequest& WebDataSourceImpl::originalRequest() const { - original_request_.bind(DocumentLoader::originalRequest()); - return original_request_; -} - -const WebURLRequest& WebDataSourceImpl::request() const { - request_.bind(DocumentLoader::request()); - return request_; -} - -const WebURLResponse& WebDataSourceImpl::response() const { - response_.bind(DocumentLoader::response()); - return response_; -} - -bool WebDataSourceImpl::hasUnreachableURL() const { - return !DocumentLoader::unreachableURL().isEmpty(); -} - -WebURL WebDataSourceImpl::unreachableURL() const { - return webkit_glue::KURLToWebURL(DocumentLoader::unreachableURL()); -} - -void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const { - result.assign(redirect_chain_); -} - -WebString WebDataSourceImpl::pageTitle() const { - return webkit_glue::StringToWebString(title()); -} - -WebNavigationType WebDataSourceImpl::navigationType() const { - return NavigationTypeToWebNavigationType(triggeringAction().type()); -} - -double WebDataSourceImpl::triggeringEventTime() const { - if (!triggeringAction().event()) - return 0.0; - - // DOMTimeStamp uses units of milliseconds. - return triggeringAction().event()->timeStamp() / 1000.0; -} - -WebDataSource::ExtraData* WebDataSourceImpl::extraData() const { - return extra_data_.get(); -} - -void WebDataSourceImpl::setExtraData(ExtraData* extra_data) { - extra_data_.set(extra_data); -} - -WebNavigationType WebDataSourceImpl::NavigationTypeToWebNavigationType( - WebCore::NavigationType type) { - switch (type) { - case WebCore::NavigationTypeLinkClicked: - return WebKit::WebNavigationTypeLinkClicked; - case WebCore::NavigationTypeFormSubmitted: - return WebKit::WebNavigationTypeFormSubmitted; - case WebCore::NavigationTypeBackForward: - return WebKit::WebNavigationTypeBackForward; - case WebCore::NavigationTypeReload: - return WebKit::WebNavigationTypeReload; - case WebCore::NavigationTypeFormResubmitted: - return WebKit::WebNavigationTypeFormResubmitted; - case WebCore::NavigationTypeOther: - default: - return WebKit::WebNavigationTypeOther; - } -} - -GURL WebDataSourceImpl::GetEndOfRedirectChain() const { - ASSERT(!redirect_chain_.isEmpty()); - return redirect_chain_.last(); -} - -void WebDataSourceImpl::ClearRedirectChain() { - redirect_chain_.clear(); -} - -void WebDataSourceImpl::AppendRedirect(const GURL& url) { - redirect_chain_.append(url); -} diff --git a/webkit/glue/webdatasource_impl.h b/webkit/glue/webdatasource_impl.h deleted file mode 100644 index e1f9029..0000000 --- a/webkit/glue/webdatasource_impl.h +++ /dev/null @@ -1,73 +0,0 @@ -// 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_WEBDATASOURCE_IMPL_H_ -#define WEBKIT_GLUE_WEBDATASOURCE_IMPL_H_ - -#include "DocumentLoader.h" -#include <wtf/Vector.h> -#include <wtf/OwnPtr.h> - -#include "webkit/api/public/WebDataSource.h" -#include "webkit/api/src/WrappedResourceRequest.h" -#include "webkit/api/src/WrappedResourceResponse.h" - -class GURL; -class WebFrameImpl; -class WebDocumentLoaderImpl; - -class WebDataSourceImpl : public WebCore::DocumentLoader, - public WebKit::WebDataSource { - public: - static PassRefPtr<WebDataSourceImpl> Create(const WebCore::ResourceRequest&, - const WebCore::SubstituteData&); - - static WebDataSourceImpl* FromLoader(WebCore::DocumentLoader* loader) { - return static_cast<WebDataSourceImpl*>(loader); - } - - // WebDataSource methods: - virtual const WebKit::WebURLRequest& originalRequest() const; - virtual const WebKit::WebURLRequest& request() const; - virtual const WebKit::WebURLResponse& response() const; - virtual bool hasUnreachableURL() const; - virtual WebKit::WebURL unreachableURL() const; - virtual void redirectChain(WebKit::WebVector<WebKit::WebURL>&) const; - virtual WebKit::WebString pageTitle() const; - virtual WebKit::WebNavigationType navigationType() const; - virtual double triggeringEventTime() const; - virtual ExtraData* extraData() const; - virtual void setExtraData(ExtraData*); - - static WebKit::WebNavigationType NavigationTypeToWebNavigationType( - WebCore::NavigationType type); - - bool HasRedirectChain() const { return !redirect_chain_.isEmpty(); } - GURL GetEndOfRedirectChain() const; - void ClearRedirectChain(); - void AppendRedirect(const GURL& url); - - private: - WebDataSourceImpl(const WebCore::ResourceRequest&, - const WebCore::SubstituteData&); - ~WebDataSourceImpl(); - - // Mutable because the const getters will magically sync these to the - // latest version from WebKit. - mutable WebKit::WrappedResourceRequest original_request_; - mutable WebKit::WrappedResourceRequest request_; - mutable WebKit::WrappedResourceResponse response_; - - // Lists all intermediate URLs that have redirected for the current - // provisional load. See WebFrameLoaderClient:: - // dispatchDidReceiveServerRedirectForProvisionalLoad for a description of - // who modifies this when to keep it up to date. - Vector<WebKit::WebURL> redirect_chain_; - - OwnPtr<ExtraData> extra_data_; - - DISALLOW_COPY_AND_ASSIGN(WebDataSourceImpl); -}; - -#endif // WEBKIT_GLUE_WEBDATASOURCE_IMPL_H_ diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index d58f5f0..1324e34 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -154,11 +154,11 @@ MSVC_POP_WARNING(); #include "webkit/api/public/WebSize.h" #include "webkit/api/public/WebURLError.h" #include "webkit/api/public/WebVector.h" +#include "webkit/api/src/WebDataSourceImpl.h" #include "webkit/glue/chrome_client_impl.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/dom_operations_private.h" #include "webkit/glue/glue_util.h" -#include "webkit/glue/webdatasource_impl.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webview_impl.h" @@ -214,6 +214,7 @@ using WebKit::WebCanvas; using WebKit::WebConsoleMessage; using WebKit::WebData; using WebKit::WebDataSource; +using WebKit::WebDataSourceImpl; using WebKit::WebFindOptions; using WebKit::WebFrame; using WebKit::WebHistoryItem; @@ -360,7 +361,7 @@ class ChromePrintContext : public WebCore::PrintContext { }; static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) { - return loader ? WebDataSourceImpl::FromLoader(loader) : NULL; + return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : NULL; } // WebFrame ------------------------------------------------------------------- @@ -1454,7 +1455,6 @@ int WebFrameImpl::live_object_count_ = 0; WebFrameImpl::WebFrameImpl() : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(scope_matches_factory_(this)), - plugin_delegate_(NULL), active_match_frame_(NULL), active_match_index_(-1), locating_active_rect_(false), diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 9fd788e..b1c1240 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -40,8 +40,6 @@ MSVC_PUSH_WARNING_LEVEL(0); MSVC_POP_WARNING(); class ChromePrintContext; -class WebDataSourceImpl; -class WebPluginDelegate; class WebView; class WebViewImpl; @@ -60,6 +58,10 @@ class SubstituteData; struct WindowFeatures; } +namespace WebKit { +class WebDataSourceImpl; +} + // Implementation of WebFrame, note that this is a reference counted object. class WebFrameImpl : public WebKit::WebFrame, public base::RefCounted<WebFrameImpl> { @@ -186,16 +188,6 @@ class WebFrameImpl : public WebKit::WebFrame, void CreateFrameView(); - // The plugin delegate is used to get notifications when downloads complete. - // This is used by the NPAPI method getURLNotify. plugin_delegate() may - // return NULL. TODO(darin): how come there is only one per frame?!? - WebPluginDelegate* plugin_delegate() const { - return plugin_delegate_; - } - void set_plugin_delegate(WebPluginDelegate* plugin_delegate) { - plugin_delegate_ = plugin_delegate; - } - WebCore::Frame* frame() const { return frame_; } @@ -210,8 +202,8 @@ class WebFrameImpl : public WebKit::WebFrame, // Getters for the impls corresponding to Get(Provisional)DataSource. They // may return NULL if there is no corresponding data source. - WebDataSourceImpl* GetDataSourceImpl() const; - WebDataSourceImpl* GetProvisionalDataSourceImpl() const; + WebKit::WebDataSourceImpl* GetDataSourceImpl() const; + WebKit::WebDataSourceImpl* GetProvisionalDataSourceImpl() const; // Returns which frame has an active match. This function should only be // called on the main frame, as it is the only frame keeping track. Returned @@ -270,10 +262,6 @@ class WebFrameImpl : public WebKit::WebFrame, // ourselves is held while frame_ is valid. See our Closing method. WebCore::Frame* frame_; - // Plugins sometimes need to be notified when loads are complete so we keep - // a pointer back to the appropriate plugin. - WebPluginDelegate* plugin_delegate_; - // A way for the main frame to keep track of which frame has an active // match. Should be NULL for all other frames. WebFrameImpl* active_match_frame_; diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index ed356d9..09e6bd3 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -38,12 +38,13 @@ #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebURLError.h" #include "webkit/api/public/WebVector.h" +#include "webkit/api/src/WebDataSourceImpl.h" #include "webkit/api/src/WebPluginContainerImpl.h" +#include "webkit/api/src/WebPluginLoadObserver.h" #include "webkit/api/src/WrappedResourceRequest.h" #include "webkit/api/src/WrappedResourceResponse.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/plugins/plugin_list.h" -#include "webkit/glue/webdatasource_impl.h" #include "webkit/glue/webdevtoolsagent_impl.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webframeloaderclient_impl.h" @@ -59,9 +60,11 @@ using base::Time; using base::TimeDelta; using WebKit::WebData; +using WebKit::WebDataSourceImpl; using WebKit::WebNavigationType; using WebKit::WebNavigationPolicy; using WebKit::WebPluginContainerImpl; +using WebKit::WebPluginLoadObserver; using WebKit::WebString; using WebKit::WebURL; using WebKit::WebURLError; @@ -314,7 +317,7 @@ void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { DocumentLoader* documentLoader = webframe_->frame()->loader()->activeDocumentLoader(); WebDataSourceImpl* data_source = - WebDataSourceImpl::FromLoader(documentLoader); + WebDataSourceImpl::fromDocumentLoader(documentLoader); // A frame may be reused. This call ensures we don't hold on to our password // listeners and their associated HTMLInputElements. @@ -452,13 +455,13 @@ void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad() // A provisional load should have started already, which should have put an // entry in our redirect chain. - DCHECK(ds->HasRedirectChain()); + DCHECK(ds->hasRedirectChain()); // The URL of the destination is on the provisional data source. We also need // to update the redirect chain to account for this addition (we do this // before the callback so the callback can look at the redirect chain to see // what happened). - ds->AppendRedirect(ds->request().url()); + ds->appendRedirect(ds->request().url()); // Dispatch callback WebViewImpl* webview = webframe_->GetWebViewImpl(); @@ -527,8 +530,8 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() { DCHECK(ds) << "DataSource NULL when navigating to reference fragment"; if (ds) { GURL url = ds->request().url(); - GURL chain_end = ds->GetEndOfRedirectChain(); - ds->ClearRedirectChain(); + GURL chain_end = ds->endOfRedirectChain(); + ds->clearRedirectChain(); // Figure out if this location change is because of a JS-initiated client // redirect (e.g onload/setTimeout document.location.href=). @@ -546,7 +549,7 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() { if (was_client_redirect) { if (d) d->DidCompleteClientRedirect(webview, webframe_, chain_end); - ds->AppendRedirect(chain_end); + ds->appendRedirect(chain_end); // Make sure we clear the expected redirect since we just effectively // completed it. expected_client_redirect_src_ = GURL(); @@ -555,7 +558,7 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() { // Regardless of how we got here, we are navigating to a URL so we need to // add it to the redirect chain. - ds->AppendRedirect(url); + ds->appendRedirect(url); } bool is_new_navigation; @@ -598,7 +601,7 @@ void WebFrameLoaderClient::dispatchDidStartProvisionalLoad() { // Since the provisional load just started, we should have not gotten // any redirects yet. - DCHECK(!ds->HasRedirectChain()); + DCHECK(!ds->hasRedirectChain()); WebViewImpl* webview = webframe_->GetWebViewImpl(); WebViewDelegate* d = webview->delegate(); @@ -612,10 +615,10 @@ void WebFrameLoaderClient::dispatchDidStartProvisionalLoad() { // "javascript:". See bug: 1080873 DCHECK(expected_client_redirect_dest_.SchemeIs("javascript") || expected_client_redirect_dest_ == url); - ds->AppendRedirect(expected_client_redirect_src_); + ds->appendRedirect(expected_client_redirect_src_); completing_client_redirect = true; } - ds->AppendRedirect(url); + ds->appendRedirect(url); if (d) { // As the comment for DidCompleteClientRedirect in webview_delegate.h @@ -658,23 +661,25 @@ void WebFrameLoaderClient::dispatchDidFailProvisionalLoad( const ResourceError& error) { // If a policy change occured, then we do not want to inform the plugin // delegate. See bug 907789 for details. + // TODO(darin): This means the plugin won't receive NPP_URLNotify, which + // seems like it could result in a memory leak in the plugin!! if (error.domain() == kInternalErrorDomain && error.errorCode() == ERR_POLICY_CHANGE) { webframe_->DidFail(cancelledError(error.failingURL()), true); - } else { - webframe_->DidFail(error, true); - WebPluginDelegate* plg_delegate = webframe_->plugin_delegate(); - if (plg_delegate) - plg_delegate->DidFinishLoadWithReason(NPRES_NETWORK_ERR); + return; } + + OwnPtr<WebPluginLoadObserver> plugin_load_observer = GetPluginLoadObserver(); + webframe_->DidFail(error, true); + if (plugin_load_observer) + plugin_load_observer->didFailLoading(error); } void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) { + OwnPtr<WebPluginLoadObserver> plugin_load_observer = GetPluginLoadObserver(); webframe_->DidFail(error, false); - - WebPluginDelegate* plg_delegate = webframe_->plugin_delegate(); - if (plg_delegate) - plg_delegate->DidFinishLoadWithReason(NPRES_NETWORK_ERR); + if (plugin_load_observer) + plugin_load_observer->didFailLoading(error); // Don't clear the redirect chain, this will happen in the middle of client // redirects, and we need the context. The chain will be cleared when the @@ -682,17 +687,14 @@ void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) { } void WebFrameLoaderClient::dispatchDidFinishLoad() { - DocumentLoader* documentLoader = - webframe_->frame()->loader()->activeDocumentLoader(); - WebDataSourceImpl* dataSource = - WebDataSourceImpl::FromLoader(documentLoader); + OwnPtr<WebPluginLoadObserver> plugin_load_observer = GetPluginLoadObserver(); + WebViewImpl* webview = webframe_->GetWebViewImpl(); WebViewDelegate* d = webview->delegate(); if (d) d->DidFinishLoadForFrame(webview, webframe_); - WebPluginDelegate* plg_delegate = webframe_->plugin_delegate(); - if (plg_delegate) - plg_delegate->DidFinishLoadWithReason(NPRES_DONE); + if (plugin_load_observer) + plugin_load_observer->didFinishLoading(); // Don't clear the redirect chain, this will happen in the middle of client // redirects, and we need the context. The chain will be cleared when the @@ -846,10 +848,10 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction( HandleBackForwardNavigation(url); navigation_policy = WebKit::WebNavigationPolicyIgnore; } else { - bool is_redirect = ds->HasRedirectChain(); + bool is_redirect = ds->hasRedirectChain(); WebNavigationType webnav_type = - WebDataSourceImpl::NavigationTypeToWebNavigationType(action.type()); + WebDataSourceImpl::toWebNavigationType(action.type()); navigation_policy = d->PolicyForNavigationAction( wv, webframe_, ds->request(), webnav_type, navigation_policy, @@ -1131,10 +1133,11 @@ void WebFrameLoaderClient::provisionalLoadStarted() { } void WebFrameLoaderClient::didFinishLoad() { - WebPluginDelegate* plg_delegate = webframe_->plugin_delegate(); - if (plg_delegate) - plg_delegate->DidFinishLoadWithReason(NPRES_DONE); + OwnPtr<WebPluginLoadObserver> plugin_load_observer = GetPluginLoadObserver(); + if (plugin_load_observer) + plugin_load_observer->didFinishLoading(); } + void WebFrameLoaderClient::prepareForDataSourceReplacement() { // FIXME } @@ -1142,7 +1145,7 @@ void WebFrameLoaderClient::prepareForDataSourceReplacement() { PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader( const ResourceRequest& request, const SubstituteData& data) { - RefPtr<WebDataSourceImpl> ds = WebDataSourceImpl::Create(request, data); + RefPtr<WebDataSourceImpl> ds = WebDataSourceImpl::create(request, data); WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); if (d) d->DidCreateDataSource(webframe_, ds.get()); @@ -1432,3 +1435,9 @@ void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) { if (d) d->NavigateBackForwardSoon(offset); } + +PassOwnPtr<WebPluginLoadObserver> WebFrameLoaderClient::GetPluginLoadObserver() { + WebDataSourceImpl* ds = WebDataSourceImpl::fromDocumentLoader( + webframe_->frame()->loader()->activeDocumentLoader()); + return ds->releasePluginLoadObserver(); +} diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h index 95cef30..a623187 100644 --- a/webkit/glue/webframeloaderclient_impl.h +++ b/webkit/glue/webframeloaderclient_impl.h @@ -6,6 +6,7 @@ #define WEBKIT_GLUE_WEBFRAMELOADERCLIENT_IMPL_H_ #include "FrameLoaderClient.h" +#include <wtf/PassOwnPtr.h> #include <wtf/RefPtr.h> #include "googleurl/src/gurl.h" @@ -16,6 +17,7 @@ class WebFrameImpl; namespace WebKit { class WebPluginContainerImpl; +class WebPluginLoadObserver; } class WebFrameLoaderClient : public WebCore::FrameLoaderClient { @@ -186,8 +188,8 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { const WTF::Vector<WebCore::String>& paramNames, const WTF::Vector<WebCore::String>& paramValues); - virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL& url, - const WebCore::String& mimeType); + virtual WebCore::ObjectContentType objectContentType( + const WebCore::KURL& url, const WebCore::String& mimeType); virtual WebCore::String overrideMediaType() const; virtual void didPerformFirstNavigation() const; @@ -210,6 +212,8 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { // Called when a dummy back-forward navigation is intercepted. void HandleBackForwardNavigation(const GURL&); + PassOwnPtr<WebKit::WebPluginLoadObserver> GetPluginLoadObserver(); + // The WebFrame that owns this object and manages its lifetime. Therefore, // the web frame object is guaranteed to exist. WebFrameImpl* webframe_; diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index ef24b03..c1427cd 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -8,7 +8,7 @@ #include <string> #include "base/gfx/native_widget_types.h" -#include "build/build_config.h" +#include "base/string16.h" #include "third_party/npapi/bindings/npapi.h" struct NPObject; @@ -96,14 +96,16 @@ class WebPluginDelegate { // Receives notification about a resource load that the plugin initiated // for a frame. - virtual void DidFinishLoadWithReason(NPReason reason) = 0; + virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, + intptr_t notify_data) = 0; // Returns the process id of the process that is running the plugin. virtual int GetProcessId() = 0; - // The result of the script execution is returned via this function. - virtual void SendJavaScriptStream(const std::string& url, - const std::wstring& result, + // The result, UTF-8 encoded, of the script execution is returned via this + // function. + virtual void SendJavaScriptStream(const GURL& url, + const std::string& result, bool success, bool notify_needed, intptr_t notify_data) = 0; @@ -136,10 +138,6 @@ class WebPluginDelegate { intptr_t notify_data, intptr_t stream) = 0; - // Notifies the delegate about a Get/Post URL request getting routed. - virtual void URLRequestRouted(const std::string&url, bool notify_needed, - intptr_t notify_data) = 0; - virtual bool IsWindowless() const; virtual const gfx::Rect& GetRect() const; diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index 0f2c9ae..09f2b3b 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -24,6 +24,7 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "net/base/escape.h" +#include "webkit/api/public/WebConsoleMessage.h" #include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebData.h" #include "webkit/api/public/WebHTTPBody.h" @@ -51,8 +52,11 @@ #include "googleurl/src/gurl.h" using WebKit::WebCanvas; +using WebKit::WebConsoleMessage; using WebKit::WebCursorInfo; using WebKit::WebData; +using WebKit::WebDataSource; +using WebKit::WebFrame; using WebKit::WebHTTPBody; using WebKit::WebHTTPHeaderVisitor; using WebKit::WebInputEvent; @@ -62,6 +66,7 @@ using WebKit::WebPluginContainer; using WebKit::WebPluginContainerImpl; using WebKit::WebRect; using WebKit::WebString; +using WebKit::WebURL; using WebKit::WebURLError; using WebKit::WebURLLoader; using WebKit::WebURLLoaderClient; @@ -391,6 +396,23 @@ void WebPluginImpl::didFailLoading(const WebURLError& error) { delegate_->DidManualLoadFail(); } +void WebPluginImpl::didFinishLoadingFrameRequest( + const WebURL& url, void* notify_data) { + if (delegate_) { + delegate_->DidFinishLoadWithReason( + url, NPRES_DONE, reinterpret_cast<intptr_t>(notify_data)); + } +} + +void WebPluginImpl::didFailLoadingFrameRequest( + const WebURL& url, void* notify_data, const WebURLError& error) { + // TODO(darin): Map net::ERR_ABORTED to NPRES_USER_BREAK? + if (delegate_) { + delegate_->DidFinishLoadWithReason( + url, NPRES_NETWORK_ERR, reinterpret_cast<intptr_t>(notify_data)); + } +} + // ----------------------------------------------------------------------------- WebPluginImpl::~WebPluginImpl() { @@ -431,45 +453,6 @@ GURL WebPluginImpl::CompleteURL(const char* url) { return webframe_->completeURL(WebString::fromUTF8(url)); } -bool WebPluginImpl::ExecuteScript(const std::string& url, - const std::wstring& script, - bool notify_needed, - intptr_t notify_data, - bool popups_allowed) { - // This could happen if the WebPluginContainer was already deleted. - if (!frame()) - return false; - - // Pending resource fetches should also not trigger a callback. - webframe_->set_plugin_delegate(NULL); - - WebCore::String script_str(webkit_glue::StdWStringToString(script)); - - // Note: the call to executeScript might result in the frame being - // deleted, so add an extra reference to it in this scope. - // For KJS, keeping a pointer to the JSBridge is enough, but for V8 - // we also need to addref the frame. - WTF::RefPtr<WebCore::Frame> cur_frame(frame()); - - WebCore::ScriptValue result = - frame()->loader()->executeScript(script_str, popups_allowed); - WebCore::String script_result; - std::wstring wresult; - bool succ = false; - if (result.getString(script_result)) { - succ = true; - wresult = webkit_glue::StringToStdWString(script_result); - } - - // delegate_ could be NULL because executeScript caused the container to be - // deleted. - if (delegate_) - delegate_->SendJavaScriptStream(url, wresult, succ, notify_needed, - notify_data); - - return succ; -} - void WebPluginImpl::CancelResource(int id) { for (size_t i = 0; i < clients_.size(); ++i) { if (clients_[i].id == id) { @@ -519,25 +502,31 @@ 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, const char* url, - GURL* unused) { + bool notify_needed, + intptr_t notify_data, + const char* url, GURL* unused) { // If there is no target, there is nothing to do if (!target) return NOT_ROUTED; // This could happen if the WebPluginContainer was already deleted. - if (!frame()) + if (!webframe_) return NOT_ROUTED; + WebString target_str = WebString::fromUTF8(target); + // Take special action for JavaScript URLs - WebCore::String str_target = target; if (is_javascript_url) { - WebCore::Frame *frameTarget = frame()->tree()->find(str_target); + WebFrame* target_frame = webframe_->view()->GetFrameWithName(target_str); // For security reasons, do not allow JavaScript on frames // other than this frame. - if (frameTarget != frame()) { - // FIXME - might be good to log this into a security - // log somewhere. + if (target_frame != webframe_) { + // TODO(darin): Localize this message. + const char kMessage[] = + "Ignoring cross-frame javascript URL load requested by plugin."; + webframe_->addMessageToConsole( + WebConsoleMessage(WebConsoleMessage::LevelError, + WebString::fromUTF8(kMessage))); return ROUTED; } @@ -574,33 +563,8 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, } } - // TODO(darin): Eliminate these WebCore dependencies. - - WebCore::FrameLoadRequest load_request( - *webkit_glue::WebURLRequestToResourceRequest(&request)); - load_request.setFrameName(str_target); - WebCore::FrameLoader *loader = frame()->loader(); - // we actually don't know whether usergesture is true or false, - // passing true since all we can do is assume it is okay. - loader->loadFrameRequest( - load_request, - false, // lock history - false, // lock back forward list - 0, // event - 0); // form state - - // loadFrameRequest() can cause the frame to go away. - if (webframe_) { - WebPluginDelegate* last_plugin = webframe_->plugin_delegate(); - if (last_plugin) { - last_plugin->DidFinishLoadWithReason(NPRES_USER_BREAK); - webframe_->set_plugin_delegate(NULL); - } - - if (notify) - webframe_->set_plugin_delegate(delegate_); - } - + container_->loadFrameRequest(request, target_str, notify_needed, + reinterpret_cast<void*>(notify_data)); return ROUTED; } @@ -874,27 +838,21 @@ void WebPluginImpl::HandleURLRequestInternal( // to the plugin's frame. GURL complete_url; int routing_status = RouteToFrame(method, is_javascript_url, target, len, - buf, is_file_data, notify, url, - &complete_url); - if (routing_status == ROUTED) { - // The delegate could have gone away because of this call. - if (delegate_) - delegate_->URLRequestRouted(url, notify, notify_data); + buf, is_file_data, notify, notify_data, + url, &complete_url); + if (routing_status == ROUTED) return; - } if (is_javascript_url) { - std::string original_url = url; - - // Convert the javascript: URL to javascript by unescaping. WebCore uses - // decode_string for this, so we do, too. - std::string escaped_script = original_url.substr(strlen("javascript:")); - WebCore::String script = WebCore::decodeURLEscapeSequences( - WebCore::String(escaped_script.data(), - static_cast<int>(escaped_script.length()))); - - ExecuteScript(original_url, webkit_glue::StringToStdWString(script), notify, - notify_data, popups_allowed); + GURL gurl(url); + WebString result = container_->executeScriptURL(gurl, popups_allowed); + + // delegate_ could be NULL because executeScript caused the container to + // be deleted. + if (delegate_) { + delegate_->SendJavaScriptStream( + gurl, result.utf8(), !result.isNull(), notify, notify_data); + } } else { GURL complete_url = CompleteURL(url); @@ -1147,7 +1105,6 @@ void WebPluginImpl::TearDownPluginInstance( // This needs to be called now and not in the destructor since the // webframe_ might not be valid anymore. - webframe_->set_plugin_delegate(NULL); webframe_ = NULL; method_factory_.RevokeAll(); } diff --git a/webkit/glue/webplugin_impl.h b/webkit/glue/webplugin_impl.h index b8cace4..09505af 100644 --- a/webkit/glue/webplugin_impl.h +++ b/webkit/glue/webplugin_impl.h @@ -98,6 +98,11 @@ class WebPluginImpl : public WebPlugin, virtual void didReceiveData(const char* data, int data_length); virtual void didFinishLoading(); virtual void didFailLoading(const WebKit::WebURLError& error); + virtual void didFinishLoadingFrameRequest( + const WebKit::WebURL& url, void* notify_data); + virtual void didFailLoadingFrameRequest( + const WebKit::WebURL& url, void* notify_data, + const WebKit::WebURLError& error); // WebPlugin implementation: void SetWindow(gfx::PluginWindowHandle window); @@ -112,17 +117,19 @@ class WebPluginImpl : public WebPlugin, // Executes the script passed in. The notify_needed and notify_data arguments // are passed in by the plugin process. These indicate whether the plugin // expects a notification on script execution. We pass them back to the - // plugin as is. This avoids having to track the notification arguments - // in the plugin process. + // plugin as is. This avoids having to track the notification arguments in + // the plugin process. bool ExecuteScript(const std::string& url, const std::wstring& script, - bool notify_needed, intptr_t notify_data, bool popups_allowed); + bool notify_needed, intptr_t notify_data, + bool popups_allowed); - // 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. - RoutingStatus RouteToFrame(const char *method, bool is_javascript_url, + // 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. + RoutingStatus RouteToFrame(const char* method, bool is_javascript_url, const char* target, unsigned int len, - const char* buf, bool is_file_data, bool notify, + const char* buf, bool is_file_data, + bool notify_needed, intptr_t notify_data, const char* url, GURL* completeURL); // Cancels a pending request. diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index 42334b1..d451a1e 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -108,7 +108,7 @@ class WebView : public WebKit::WebWidget { virtual void SetFocusedFrame(WebKit::WebFrame* frame) = 0; // Returns the frame with the given name, or NULL if not found. - virtual WebKit::WebFrame* GetFrameWithName(const std::wstring& name) = 0; + virtual WebKit::WebFrame* GetFrameWithName(const WebKit::WebString& name) = 0; // Returns the frame previous to the specified frame, by traversing the frame // tree, wrapping around if necessary. diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index 2c6069e..2a387df 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -1294,8 +1294,8 @@ void WebViewImpl::SetFocusedFrame(WebFrame* frame) { webcore_frame->page()->focusController()->setFocusedFrame(webcore_frame); } -WebFrame* WebViewImpl::GetFrameWithName(const std::wstring& name) { - String name_str = webkit_glue::StdWStringToString(name); +WebFrame* WebViewImpl::GetFrameWithName(const WebString& name) { + String name_str = webkit_glue::WebStringToString(name); Frame* frame = page_->mainFrame()->tree()->find(name_str); return frame ? WebFrameImpl::FromFrame(frame) : NULL; } diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 91e05b9..5cc3c29 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -82,7 +82,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual WebKit::WebFrame* GetMainFrame(); virtual WebKit::WebFrame* GetFocusedFrame(); virtual void SetFocusedFrame(WebKit::WebFrame* frame); - virtual WebKit::WebFrame* GetFrameWithName(const std::wstring& name); + virtual WebKit::WebFrame* GetFrameWithName(const WebKit::WebString& name); virtual WebKit::WebFrame* GetPreviousFrameBefore(WebKit::WebFrame* frame, bool wrap); virtual WebKit::WebFrame* GetNextFrameAfter(WebKit::WebFrame* frame, bool wrap); virtual void ClearFocusedNode(); diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index 76f4400..f02668d 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -27,8 +27,8 @@ #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebWorkerClient.h" #include "webkit/api/src/PlatformMessagePortChannel.h" +#include "webkit/api/src/WebDataSourceImpl.h" #include "webkit/glue/glue_util.h" -#include "webkit/glue/webdatasource_impl.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/webview.h" @@ -72,7 +72,8 @@ class WorkerWebViewDelegate : public WebViewDelegate { // Tell the loader to load the data into the 'shadow page' synchronously, // so we can grab the resulting Document right after load. virtual void DidCreateDataSource(WebFrame* frame, WebKit::WebDataSource* ds) { - static_cast<WebDataSourceImpl*>(ds)->setDeferMainResourceDataLoad(false); + static_cast<WebKit::WebDataSourceImpl*>(ds)-> + setDeferMainResourceDataLoad(false); } // Lazy allocate and leak this instance. diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 89980fe..5563505 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -519,8 +519,10 @@ void TestShell::LoadURL(const wchar_t* url) { bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { // Get the right target frame for the entry. WebFrame* frame = webView()->GetMainFrame(); - if (!entry.GetTargetFrame().empty()) - frame = webView()->GetFrameWithName(entry.GetTargetFrame()); + if (!entry.GetTargetFrame().empty()) { + frame = webView()->GetFrameWithName( + WideToUTF16Hack(entry.GetTargetFrame())); + } // TODO(mpcomplete): should we clear the target frame, or should // back/forward navigations maintain the target frame? diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 70c2ec1..7df3979 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1070,6 +1070,8 @@ 'api/src/WebCString.cpp', 'api/src/WebCursorInfo.cpp', 'api/src/WebData.cpp', + 'api/src/WebDataSourceImpl.cpp', + 'api/src/WebDataSourceImpl.h', 'api/src/WebDragData.cpp', 'api/src/WebForm.cpp', 'api/src/WebHistoryItem.cpp', @@ -1087,6 +1089,8 @@ 'api/src/WebPluginContainerImpl.cpp', 'api/src/WebPluginListBuilderImpl.cpp', 'api/src/WebPluginListBuilderImpl.h', + 'api/src/WebPluginLoadObserver.cpp', + 'api/src/WebPluginLoadObserver.h', 'api/src/WebRange.cpp', 'api/src/WebSettingsImpl.cpp', 'api/src/WebSettingsImpl.h', @@ -1423,8 +1427,6 @@ 'glue/webcursor_gtk_data.h', 'glue/webcursor_mac.mm', 'glue/webcursor_win.cc', - 'glue/webdatasource_impl.cc', - 'glue/webdatasource_impl.h', 'glue/webdevtoolsagent.h', 'glue/webdevtoolsagent_delegate.h', 'glue/webdevtoolsagent_impl.cc', |