diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 15:05:21 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 15:05:21 +0000 |
commit | 397908018088686f21a81bbb822c519bdc2eae7a (patch) | |
tree | 6bcbe9ae0d6038f782b4d628c3f1a4f098584463 /webkit/glue | |
parent | 77c327ddb532777dde7e3a6f5dc078d4a76dcfab (diff) | |
download | chromium_src-397908018088686f21a81bbb822c519bdc2eae7a.zip chromium_src-397908018088686f21a81bbb822c519bdc2eae7a.tar.gz chromium_src-397908018088686f21a81bbb822c519bdc2eae7a.tar.bz2 |
More removal of WebCore usage from webplugin_impl.cc
Adds a few helper methods on WebFrame.
R=jam
BUG=10036
TEST=none
Review URL: http://codereview.chromium.org/173152
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23956 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/plugins/plugin_instance.cc | 19 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_instance.h | 11 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl.cc | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl.h | 4 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_gtk.cc | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 6 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 23 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 3 | ||||
-rw-r--r-- | webkit/glue/webplugin_delegate.h | 4 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.cc | 115 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.h | 2 |
11 files changed, 95 insertions, 104 deletions
diff --git a/webkit/glue/plugins/plugin_instance.cc b/webkit/glue/plugins/plugin_instance.cc index 79b5b4f..061093d 100644 --- a/webkit/glue/plugins/plugin_instance.cc +++ b/webkit/glue/plugins/plugin_instance.cc @@ -66,13 +66,13 @@ PluginInstance::~PluginInstance() { plugin_->CloseInstance(); } -PluginStreamUrl *PluginInstance::CreateStream(int resource_id, - const std::string &url, - const std::string &mime_type, +PluginStreamUrl* PluginInstance::CreateStream(int resource_id, + const GURL& url, + const std::string& mime_type, bool notify_needed, - void *notify_data) { - PluginStreamUrl *stream = new PluginStreamUrl( - resource_id, GURL(url), this, notify_needed, notify_data); + void* notify_data) { + PluginStreamUrl* stream = new PluginStreamUrl( + resource_id, url, this, notify_needed, notify_data); AddStream(stream); return stream; @@ -142,7 +142,6 @@ bool PluginInstance::Start(const GURL& url, int param_count, bool load_manually) { load_manually_ = load_manually; - instance_url_ = url; unsigned short mode = load_manually_ ? NP_FULL : NP_EMBED; npp_->ndata = this; @@ -362,16 +361,12 @@ void PluginInstance::SendJavaScriptStream(const std::string& url, } } -void PluginInstance::DidReceiveManualResponse(const std::string& url, +void PluginInstance::DidReceiveManualResponse(const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, uint32 last_modified) { DCHECK(load_manually_); - std::string response_url = url; - if (response_url.empty()) { - response_url = instance_url_.spec(); - } plugin_data_stream_ = CreateStream(-1, url, mime_type, false, NULL); diff --git a/webkit/glue/plugins/plugin_instance.h b/webkit/glue/plugins/plugin_instance.h index ba8824f8..bed2a55 100644 --- a/webkit/glue/plugins/plugin_instance.h +++ b/webkit/glue/plugins/plugin_instance.h @@ -110,11 +110,11 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { // Set object_url to true if the load is for the object tag's // url, or false if it's for a url that the plugin // fetched through NPN_GetUrl[Notify]. - PluginStreamUrl *CreateStream(int resource_id, - const std::string &url, - const std::string &mime_type, + PluginStreamUrl* CreateStream(int resource_id, + const GURL& url, + const std::string& mime_type, bool notify_needed, - void *notify_data); + void* notify_data); // For each instance, we track all streams. When the // instance closes, all remaining streams are also @@ -170,7 +170,7 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { bool success, bool notify_needed, intptr_t notify_data); - void DidReceiveManualResponse(const std::string& url, + void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, @@ -238,7 +238,6 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { #endif MessageLoop* message_loop_; scoped_refptr<PluginStreamUrl> plugin_data_stream_; - GURL instance_url_; // This flag if true indicates that the plugin data would be passed from // webkit. if false indicates that the plugin should download the data. diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index 05975f4..37efc33 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -430,7 +430,7 @@ void WebPluginDelegateImpl::SendJavaScriptStream(const std::string& url, } void WebPluginDelegateImpl::DidReceiveManualResponse( - const std::string& url, const std::string& mime_type, + const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, uint32 last_modified) { if (!windowless_) { // Calling NPP_WriteReady before NPP_SetWindow causes movies to not load in @@ -1192,7 +1192,7 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, } WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( - int resource_id, const std::string &url, bool notify_needed, + int resource_id, const GURL& url, bool notify_needed, intptr_t notify_data, intptr_t existing_stream) { // Stream already exists. This typically happens for range requests // initiated via NPN_RequestRead. @@ -1204,7 +1204,7 @@ WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( } if (notify_needed) { - instance()->SetURLLoadData(GURL(url.c_str()), notify_data); + instance()->SetURLLoadData(url, notify_data); } std::string mime_type; NPAPI::PluginStreamUrl *stream = instance()->CreateStream( diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index 4cbf9c1..106a040 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -65,7 +65,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { const std::wstring& result, bool success, bool notify_needed, intptr_t notify_data); - virtual void DidReceiveManualResponse(const std::string& url, + virtual void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, @@ -76,7 +76,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { virtual FilePath GetPluginPath(); virtual void InstallMissingPlugin(); virtual WebPluginResourceClient* CreateResourceClient(int resource_id, - const std::string &url, + const GURL& url, bool notify_needed, intptr_t notify_data, intptr_t stream); diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc index eb9f963..da236b4 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc @@ -209,7 +209,7 @@ void WebPluginDelegateImpl::SendJavaScriptStream(const std::string& url, } void WebPluginDelegateImpl::DidReceiveManualResponse( - const std::string& url, const std::string& mime_type, + const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, uint32 last_modified) { if (!windowless_) { // Calling NPP_WriteReady before NPP_SetWindow causes movies to not load in @@ -837,7 +837,7 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, } WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( - int resource_id, const std::string &url, bool notify_needed, + int resource_id, const GURL& url, bool notify_needed, intptr_t notify_data, intptr_t existing_stream) { // Stream already exists. This typically happens for range requests // initiated via NPN_RequestRead. @@ -851,7 +851,7 @@ WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( } if (notify_needed) { - instance()->SetURLLoadData(GURL(url.c_str()), notify_data); + instance()->SetURLLoadData(url, notify_data); } std::string mime_type; NPAPI::PluginStreamUrl *stream = instance()->CreateStream( diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index ebec821..f52ed34 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -214,7 +214,7 @@ void WebPluginDelegateImpl::SendJavaScriptStream(const std::string& url, } void WebPluginDelegateImpl::DidReceiveManualResponse( - const std::string& url, const std::string& mime_type, + const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, uint32 last_modified) { instance()->DidReceiveManualResponse(url, mime_type, headers, expected_length, last_modified); @@ -512,7 +512,7 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, } WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( - int resource_id, const std::string &url, bool notify_needed, + int resource_id, const GURL& url, bool notify_needed, intptr_t notify_data, intptr_t existing_stream) { // Stream already exists. This typically happens for range requests // initiated via NPN_RequestRead. @@ -526,7 +526,7 @@ WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( } if (notify_needed) { - instance()->SetURLLoadData(GURL(url.c_str()), notify_data); + instance()->SetURLLoadData(url, notify_data); } std::string mime_type; NPAPI::PluginStreamUrl *stream = instance()->CreateStream( diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 40038b6..d58f5f0 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -854,6 +854,21 @@ bool WebFrameImpl::isViewSourceModeEnabled() const { return false; } +void WebFrameImpl::setReferrerForRequest( + WebURLRequest& request, const WebURL& referrer_url) { + String referrer; + if (referrer_url.isEmpty()) { + referrer = frame_->loader()->outgoingReferrer(); + } else { + referrer = webkit_glue::WebStringToString(referrer_url.spec().utf16()); + } + if (FrameLoader::shouldHideReferrer( + webkit_glue::WebURLToKURL(request.url()), referrer)) + return; + request.setHTTPHeaderField(WebString::fromUTF8("Referer"), + webkit_glue::StringToWebString(referrer)); +} + void WebFrameImpl::dispatchWillSendRequest(WebURLRequest& request) { ResourceResponse response; frame_->loader()->client()->dispatchWillSendRequest(NULL, 0, @@ -1410,6 +1425,14 @@ void WebFrameImpl::resetMatchCount() { frames_scoping_count_ = 0; } +WebURL WebFrameImpl::completeURL(const WebString& url) const { + if (!frame_ || !frame_->document()) + return WebURL(); + + return webkit_glue::KURLToWebURL( + frame_->document()->completeURL(webkit_glue::WebStringToString(url))); +} + WebString WebFrameImpl::contentAsText(size_t max_chars) const { if (!frame_) return WebString(); diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index ef37d48..9fd788e 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -123,6 +123,8 @@ class WebFrameImpl : public WebKit::WebFrame, virtual WebKit::WebHistoryItem currentHistoryItem() const; virtual void enableViewSourceMode(bool enable); virtual bool isViewSourceModeEnabled() const; + virtual void setReferrerForRequest( + WebKit::WebURLRequest& request, const WebKit::WebURL& referrer); virtual void dispatchWillSendRequest(WebKit::WebURLRequest& request); virtual void commitDocumentData(const char* data, size_t length); virtual unsigned unloadListenerCount() const; @@ -161,6 +163,7 @@ class WebFrameImpl : public WebKit::WebFrame, const WebKit::WebRect& selection_rect, int active_match_ordinal, int identifier); virtual void resetMatchCount(); + virtual WebKit::WebURL completeURL(const WebKit::WebString& url) const; virtual WebKit::WebString contentAsText(size_t max_chars) const; virtual WebKit::WebString contentAsMarkup() const; diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index c4d4005..ef24b03 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -108,7 +108,7 @@ class WebPluginDelegate { intptr_t notify_data) = 0; // Receives notification about data being available. - virtual void DidReceiveManualResponse(const std::string& url, + virtual void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, const std::string& headers, uint32 expected_length, @@ -131,7 +131,7 @@ class WebPluginDelegate { // Creates a WebPluginResourceClient instance and returns the same. virtual WebPluginResourceClient* CreateResourceClient(int resource_id, - const std::string &url, + const GURL& url, bool notify_needed, intptr_t notify_data, intptr_t stream) = 0; diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index 31f722c..fb45755 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -174,7 +174,7 @@ std::string GetAllHeaders(const WebURLResponse& response) { } struct ResponseInfo { - std::string url; + GURL url; std::string mime_type; uint32 last_modified; uint32 expected_length; @@ -182,7 +182,7 @@ struct ResponseInfo { void GetResponseInfo(const WebURLResponse& response, ResponseInfo* response_info) { - response_info->url = response.url().spec(); + response_info->url = response.url(); response_info->mime_type = response.mimeType().utf8(); // Measured in seconds since 12:00 midnight GMT, January 1, 1970. @@ -425,18 +425,13 @@ void WebPluginImpl::WillDestroyWindow(gfx::PluginWindowHandle window) { view_delegate->WillDestroyPluginWindow(window); } -bool WebPluginImpl::CompleteURL(const std::string& url_in, - std::string* url_out) { - if (!frame() || !frame()->document()) { +GURL WebPluginImpl::CompleteURL(const char* url) { + if (!webframe_) { NOTREACHED(); - return false; + return GURL(); } - - WebCore::String str(webkit_glue::StdStringToString(url_in)); - WebCore::String url = frame()->document()->completeURL(str); - std::wstring wurl = webkit_glue::StringToStdWString(url); - *url_out = WideToUTF8(wurl); - return true; + // TODO(darin): Is conversion from UTF8 correct here? + return webframe_->completeURL(WebString::fromUTF8(url)); } bool WebPluginImpl::ExecuteScript(const std::string& url, @@ -528,7 +523,7 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, const char* target, unsigned int len, const char* buf, bool is_file_data, bool notify, const char* url, - GURL* completeURL) { + GURL* unused) { // If there is no target, there is nothing to do if (!target) return NOT_ROUTED; @@ -556,37 +551,34 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, // If we got this far, we're routing content to a target frame. // Go fetch the URL. - WebCore::String complete_url_str = frame()->document()->completeURL( - WebCore::String(url)); - - WebCore::KURL complete_url_kurl(complete_url_str); + GURL complete_url = CompleteURL(url); if (strcmp(method, "GET") != 0) { - const WebCore::String& protocol_scheme = - complete_url_kurl.protocol(); // We're only going to route HTTP/HTTPS requests - if ((protocol_scheme != "http") && (protocol_scheme != "https")) + if (!(complete_url.SchemeIs("http") || complete_url.SchemeIs("https"))) return INVALID_URL; } - *completeURL = webkit_glue::KURLToGURL(complete_url_kurl); - WebURLRequest request(webkit_glue::KURLToWebURL(complete_url_kurl)); + WebURLRequest request(complete_url); request.setHTTPMethod(WebString::fromUTF8(method)); if (len > 0) { if (!is_file_data) { if (!SetPostData(&request, buf, len)) { // Uhoh - we're in trouble. There isn't a good way // to recover at this point. Break out. - ASSERT_NOT_REACHED(); + NOTREACHED(); return ROUTED; } } else { // TODO: Support "file" mode. For now, just break out // since proceeding may do something unintentional. - ASSERT_NOT_REACHED(); + NOTREACHED(); return ROUTED; } } + + // TODO(darin): Eliminate these WebCore dependencies. + WebCore::FrameLoadRequest load_request( *webkit_glue::WebURLRequestToResourceRequest(&request)); load_request.setFrameName(str_target); @@ -600,7 +592,7 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, 0, // event 0); // form state - // load() can cause the frame to go away. + // loadFrameRequest() can cause the frame to go away. if (webframe_) { WebPluginDelegate* last_plugin = webframe_->plugin_delegate(); if (last_plugin) { @@ -616,12 +608,11 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, } NPObject* WebPluginImpl::GetWindowScriptNPObject() { - if (!frame()) { - ASSERT_NOT_REACHED(); - return 0; + if (!webframe_) { + NOTREACHED(); + return NULL; } - - return frame()->script()->windowScriptNPObject(); + return webframe_->windowObject(); } NPObject* WebPluginImpl::GetPluginElement() { @@ -745,8 +736,7 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, for (size_t i = 0; i < clients_.size(); ++i) { if (clients_[i].loader.get() == loader) { WebPluginResourceClient* resource_client = - delegate_->CreateResourceClient(clients_[i].id, - plugin_url_.spec().c_str(), + delegate_->CreateResourceClient(clients_[i].id, plugin_url_, false, 0, NULL); clients_[i].client = resource_client; client = resource_client; @@ -911,13 +901,11 @@ void WebPluginImpl::HandleURLRequestInternal( ExecuteScript(original_url, webkit_glue::StringToStdWString(script), notify, notify_data, popups_allowed); } else { - std::string complete_url_string; - CompleteURL(url, &complete_url_string); + GURL complete_url = CompleteURL(url); int resource_id = GetNextResourceId(); - WebPluginResourceClient* resource_client = - delegate_->CreateResourceClient(resource_id, complete_url_string, - notify, notify_data, NULL); + WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( + resource_id, complete_url, notify, notify_data, NULL); // If the RouteToFrame call returned a failure then inform the result // back to the plugin asynchronously. @@ -928,8 +916,7 @@ void WebPluginImpl::HandleURLRequestInternal( } InitiateHTTPRequest(resource_id, resource_client, method, buf, len, - GURL(complete_url_string), NULL, - use_plugin_src_as_referrer); + complete_url, NULL, use_plugin_src_as_referrer); } } @@ -964,34 +951,21 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id, WebString::fromUTF8(range_info)); } - WebCore::String referrer; - // GetURL/PostURL requests initiated explicitly by plugins should specify the - // plugin SRC url as the referrer if it is available. - if (use_plugin_src_as_referrer && !plugin_url_.spec().empty()) { - referrer = webkit_glue::StdStringToString(plugin_url_.spec()); - } else { - referrer = frame()->loader()->outgoingReferrer(); - } - - if (!WebCore::FrameLoader::shouldHideReferrer(webkit_glue::GURLToKURL(url), - referrer)) { - info.request.setHTTPHeaderField(WebString::fromUTF8("Referer"), - webkit_glue::StringToWebString(referrer)); - } - if (strcmp(method, "POST") == 0) { // Adds headers or form data to a request. This must be called before // we initiate the actual request. SetPostData(&info.request, buf, buf_len); } + // GetURL/PostURL requests initiated explicitly by plugins should specify the + // plugin SRC url as the referrer if it is available. + GURL referrer_url; + if (use_plugin_src_as_referrer && !plugin_url_.spec().empty()) + referrer_url = plugin_url_; + webframe_->setReferrerForRequest(info.request, referrer_url); + // Sets the routing id to associate the ResourceRequest with the RenderView. - WebCore::ResourceResponse response; - frame()->loader()->client()->dispatchWillSendRequest( - NULL, - 0, - *webkit_glue::WebURLRequestToMutableResourceRequest(&info.request), - response); + webframe_->dispatchWillSendRequest(info.request); info.loader.reset(WebKit::webKitClient()->createURLLoader()); if (!info.loader.get()) @@ -1015,15 +989,13 @@ void WebPluginImpl::InitiateHTTPRangeRequest(const char* url, bool notify_needed, intptr_t notify_data) { int resource_id = GetNextResourceId(); - std::string complete_url_string; - CompleteURL(url, &complete_url_string); - - WebPluginResourceClient* resource_client = - delegate_->CreateResourceClient(resource_id, complete_url_string, - notify_needed, notify_data, - existing_stream); - InitiateHTTPRequest(resource_id, resource_client, "GET", NULL, 0, - GURL(complete_url_string), range_info, true); + GURL complete_url = CompleteURL(url); + + WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( + resource_id, complete_url, notify_needed, notify_data, existing_stream); + InitiateHTTPRequest( + resource_id, resource_client, "GET", NULL, 0, complete_url, range_info, + true); } void WebPluginImpl::SetDeferResourceLoading(int resource_id, bool defer) { @@ -1134,10 +1106,9 @@ void WebPluginImpl::TearDownPluginInstance( // of those sub JSObjects. if (frame()) { ASSERT(container_); - // TODO(darin): Avoid these casts! + // TODO(darin): Avoid this cast! frame()->script()->cleanupScriptObjectsForPlugin( - static_cast<WebCore::Widget*>( - static_cast<WebKit::WebPluginContainerImpl*>(container_))); + static_cast<WebKit::WebPluginContainerImpl*>(container_)); } if (delegate_) { diff --git a/webkit/glue/webplugin_impl.h b/webkit/glue/webplugin_impl.h index de31e57..fd83ba9 100644 --- a/webkit/glue/webplugin_impl.h +++ b/webkit/glue/webplugin_impl.h @@ -110,7 +110,7 @@ class WebPluginImpl : public WebPlugin, #endif // Given a (maybe partial) url, completes using the base url. - bool CompleteURL(const std::string& url_in, std::string* url_out); + GURL CompleteURL(const char* url); // Executes the script passed in. The notify_needed and notify_data arguments // are passed in by the plugin process. These indicate whether the plugin |