PKGBUILDs/extra/chromium/chromium-31.0.1650.48-NPAPI-cookies.patch
2013-11-14 00:31:37 +00:00

277 lines
8.8 KiB
Diff

Index: content/browser/child_process_security_policy_impl.cc
===================================================================
--- content/browser/child_process_security_policy_impl.cc (revision 233522)
+++ content/browser/child_process_security_policy_impl.cc (working copy)
@@ -793,7 +793,7 @@
bool ChildProcessSecurityPolicyImpl::CanSendCookiesForOrigin(int child_id,
const GURL& gurl) {
for (PluginProcessHostIterator iter; !iter.Done(); ++iter) {
- if (iter.GetData().process_type == child_id) {
+ if (iter.GetData().id == child_id) {
if (iter.GetData().process_type == PROCESS_TYPE_PLUGIN) {
// NPAPI plugin processes are unsandboxed and so are trusted. Plugins
// can make request to any origin.
Index: content/browser/plugin_browsertest.cc
===================================================================
--- content/browser/plugin_browsertest.cc (revision 233522)
+++ content/browser/plugin_browsertest.cc (working copy)
@@ -5,15 +5,21 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/common/shell_switches.h"
#include "content/test/content_browser_test.h"
#include "content/test/content_browser_test_utils.h"
#include "content/test/net/url_request_mock_http_job.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/url_request/url_request.h"
#include "ui/gfx/rect.h"
#if defined(OS_WIN)
@@ -468,4 +474,77 @@
}
#endif // defined(OS_WIN)
+class TestResourceDispatcherHostDelegate
+ : public ResourceDispatcherHostDelegate {
+ public:
+ TestResourceDispatcherHostDelegate() : found_cookie_(false) {}
+
+ bool found_cookie() { return found_cookie_; }
+
+ void WaitForPluginRequest() {
+ if (found_cookie_)
+ return;
+
+ runner_ = new MessageLoopRunner;
+ runner_->Run();
+ }
+
+ private:
+ // ResourceDispatcherHostDelegate implementation:
+ virtual void OnResponseStarted(
+ net::URLRequest* request,
+ ResourceContext* resource_context,
+ ResourceResponse* response,
+ IPC::Sender* sender) OVERRIDE {
+ // The URL below comes from plugin_geturl_test.cc.
+ if (!EndsWith(request->url().spec(),
+ "npapi/plugin_ref_target_page.html",
+ true)) {
+ return;
+ }
+ net::HttpRequestHeaders headers;
+ bool found_cookie = false;
+ if (request->GetFullRequestHeaders(&headers) &&
+ headers.ToString().find("Cookie: blah") != std::string::npos) {
+ found_cookie = true;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&TestResourceDispatcherHostDelegate::GotCookie,
+ base::Unretained(this), found_cookie));
+ }
+
+ void GotCookie(bool found_cookie) {
+ found_cookie_ = found_cookie;
+ if (runner_)
+ runner_->QuitClosure().Run();
+ }
+
+ scoped_refptr<MessageLoopRunner> runner_;
+ bool found_cookie_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate);
+};
+
+// Ensure that cookies get sent with plugin requests.
+IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Cookies)) {
+ // Create a new browser just to ensure that the plugin process' child_id is
+ // not equal to its type (PROCESS_TYPE_PLUGIN), as that was the error which
+ // caused this bug.
+ NavigateToURL(CreateBrowser(), GURL("about:blank"));
+
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+ GURL url(embedded_test_server()->GetURL("/npapi/cookies.html"));
+
+ TestResourceDispatcherHostDelegate test_delegate;
+ ResourceDispatcherHostDelegate* old_delegate =
+ ResourceDispatcherHostImpl::Get()->delegate();
+ ResourceDispatcherHostImpl::Get()->SetDelegate(&test_delegate);
+ LoadAndWait(url);
+ test_delegate.WaitForPluginRequest();
+ ASSERT_TRUE(test_delegate.found_cookie());
+ ResourceDispatcherHostImpl::Get()->SetDelegate(old_delegate);
+}
+
} // namespace content
Index: content/test/data/npapi/cookies.html
===================================================================
--- content/test/data/npapi/cookies.html (revision 0)
+++ content/test/data/npapi/cookies.html (revision 0)
@@ -0,0 +1,27 @@
+<html>
+
+<head>
+<script src="npapi.js"></script>
+<script>document.cookie="blah"</script>
+</head>
+
+
+<body>
+<div id="statusPanel" style="border: 1px solid red; width: 100%">
+Test running....
+</div>
+
+
+Cookies Test<p>
+This test fetches an URL via the plugin, and verifies that the cookies are sent
+with plugin-initiated requests.
+
+<embed type="application/vnd.npapi-test"
+ src="foo"
+ name="cookies"
+ id="1"
+ mode="np_embed"
+>
+
+</body>
+</html>
Property changes on: content\test\data\npapi\cookies.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:eol-style
+ LF
Index: content/test/plugin/plugin_geturl_test.cc
===================================================================
--- content/test/plugin/plugin_geturl_test.cc (revision 233522)
+++ content/test/plugin/plugin_geturl_test.cc (working copy)
@@ -48,7 +48,8 @@
expect_404_response_(false),
npn_evaluate_context_(false),
handle_url_redirects_(false),
- received_url_redirect_notification_(false) {
+ received_url_redirect_notification_(false),
+ check_cookies_(false) {
}
PluginGetURLTest::~PluginGetURLTest() {}
@@ -78,7 +79,14 @@
"geturlredirectnotify")) {
handle_url_redirects_ = true;
}
- return PluginTest::New(mode, argc, argn, argv, saved);
+
+ NPError error = PluginTest::New(mode, argc, argn, argv, saved);
+
+ // The above sets test_name().
+ if (test_name() == "cookies")
+ check_cookies_ = true;
+
+ return error;
}
NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) {
@@ -108,6 +116,13 @@
id(), REDIRECT_SRC_URL, NULL,
reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ID));
return NPERR_NO_ERROR;
+ } else if (check_cookies_) {
+ HostFunctions()->geturlnotify(
+ id(),
+ "plugin_ref_target_page.html",
+ NULL,
+ reinterpret_cast<void*>(SELF_URL_STREAM_ID));
+ return NPERR_NO_ERROR;
}
std::string url = SELF_URL;
@@ -161,7 +176,7 @@
return NPERR_NO_ERROR;
}
- if (!fail_write_url_.empty()) {
+ if (!fail_write_url_.empty() || check_cookies_) {
return NPERR_NO_ERROR;
}
@@ -217,7 +232,7 @@
return PluginTest::WriteReady(stream);
}
- if (!referrer_target_url_.empty()) {
+ if (!referrer_target_url_.empty() || check_cookies_) {
return STREAM_CHUNK;
}
@@ -242,7 +257,7 @@
return -1;
}
- if (!referrer_target_url_.empty()) {
+ if (!referrer_target_url_.empty() || check_cookies_) {
return len;
}
@@ -314,6 +329,11 @@
return NPERR_NO_ERROR;
}
+ if (check_cookies_) {
+ SignalTestCompleted();
+ return NPERR_NO_ERROR;
+ }
+
unsigned long stream_id =
reinterpret_cast<unsigned long>(stream->notifyData);
switch (stream_id) {
@@ -367,6 +387,9 @@
return;
}
+ if (check_cookies_)
+ return;
+
COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data), cast_validity_check);
unsigned long stream_id = reinterpret_cast<unsigned long>(data);
switch (stream_id) {
Index: content/test/plugin/plugin_geturl_test.h
===================================================================
--- content/test/plugin/plugin_geturl_test.h (revision 233522)
+++ content/test/plugin/plugin_geturl_test.h (working copy)
@@ -57,6 +57,7 @@
std::string page_not_found_url_;
std::string fail_write_url_;
std::string referrer_target_url_;
+ bool check_cookies_;
};
} // namespace NPAPIClient
Index: content/test/plugin/plugin_test_factory.cc
===================================================================
--- content/test/plugin/plugin_test_factory.cc (revision 233522)
+++ content/test/plugin/plugin_test_factory.cc (working copy)
@@ -38,7 +38,8 @@
} else if (test_name == "geturl" || test_name == "geturl_404_response" ||
test_name == "geturl_fail_write" ||
test_name == "plugin_referrer_test" ||
- test_name == "geturlredirectnotify") {
+ test_name == "geturlredirectnotify" ||
+ test_name == "cookies") {
new_test = new PluginGetURLTest(instance, host_functions);
} else if (test_name == "npobject_identity") {
new_test = new NPObjectIdentityTest(instance, host_functions);