OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/shell_content_renderer_client.h" | 5 #include "content/shell/shell_content_renderer_client.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/sys_string_conversions.h" | |
10 #include "base/utf_string_conversions.h" | |
11 #include "content/public/common/content_constants.h" | 9 #include "content/public/common/content_constants.h" |
12 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
13 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
14 #include "content/public/test/layouttest_support.h" | 12 #include "content/public/test/layouttest_support.h" |
15 #include "content/shell/shell_render_process_observer.h" | 13 #include "content/shell/shell_render_process_observer.h" |
16 #include "content/shell/shell_switches.h" | 14 #include "content/shell/shell_switches.h" |
17 #include "content/shell/webkit_test_runner.h" | 15 #include "content/shell/webkit_test_runner.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
20 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestPlugin.h" | 18 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestPlugin.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 84 |
87 bool ShellContentRendererClient::WillSendRequest( | 85 bool ShellContentRendererClient::WillSendRequest( |
88 WebFrame* frame, | 86 WebFrame* frame, |
89 PageTransition transition_type, | 87 PageTransition transition_type, |
90 const GURL& url, | 88 const GURL& url, |
91 const GURL& first_party_for_cookies, | 89 const GURL& first_party_for_cookies, |
92 GURL* new_url) { | 90 GURL* new_url) { |
93 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 91 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
94 if (!command_line->HasSwitch(switches::kDumpRenderTree)) | 92 if (!command_line->HasSwitch(switches::kDumpRenderTree)) |
95 return false; | 93 return false; |
| 94 ShellRenderProcessObserver* render_process_observer = |
| 95 ShellRenderProcessObserver::GetInstance(); |
96 if (!command_line->HasSwitch(switches::kAllowExternalPages) && | 96 if (!command_line->HasSwitch(switches::kAllowExternalPages) && |
97 IsExternalPage(url) && !IsExternalPage(first_party_for_cookies)) { | 97 IsExternalPage(url) && !IsExternalPage(first_party_for_cookies)) { |
98 ShellRenderProcessObserver::GetInstance()->test_delegate()->printMessage( | 98 render_process_observer->test_delegate()->printMessage( |
99 std::string("Blocked access to external URL " + url.spec() + "\n")); | 99 std::string("Blocked access to external URL " + url.spec() + "\n")); |
100 *new_url = GURL(); | 100 *new_url = GURL(); |
101 return true; | 101 return true; |
102 } | 102 } |
103 *new_url = RewriteLayoutTestsURL(url); | 103 *new_url = render_process_observer->test_delegate()->rewriteLayoutTestsURL( |
| 104 url.spec()); |
104 return true; | 105 return true; |
105 } | 106 } |
106 | 107 |
107 void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view, | 108 void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view, |
108 WebTestProxyBase* proxy) { | 109 WebTestProxyBase* proxy) { |
109 WebKitTestRunner* test_runner = new WebKitTestRunner(render_view); | 110 WebKitTestRunner* test_runner = new WebKitTestRunner(render_view); |
110 if (!ShellRenderProcessObserver::GetInstance()->test_delegate()) { | 111 if (!ShellRenderProcessObserver::GetInstance()->test_delegate()) { |
111 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view, | 112 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view, |
112 test_runner, | 113 test_runner, |
113 test_runner); | 114 test_runner); |
114 } | 115 } |
115 test_runner->set_proxy(proxy); | 116 test_runner->set_proxy(proxy); |
116 proxy->setDelegate( | 117 proxy->setDelegate( |
117 ShellRenderProcessObserver::GetInstance()->test_delegate()); | 118 ShellRenderProcessObserver::GetInstance()->test_delegate()); |
118 proxy->setInterfaces( | 119 proxy->setInterfaces( |
119 ShellRenderProcessObserver::GetInstance()->test_interfaces()); | 120 ShellRenderProcessObserver::GetInstance()->test_interfaces()); |
120 } | 121 } |
121 | 122 |
122 GURL ShellContentRendererClient::RewriteLayoutTestsURL(const GURL& url) { | |
123 const char kPrefix[] = "file:///tmp/LayoutTests/"; | |
124 const int kPrefixLen = arraysize(kPrefix) - 1; | |
125 | |
126 if (url.spec().compare(0, kPrefixLen, kPrefix, kPrefixLen)) | |
127 return url; | |
128 | |
129 FilePath replace_path = | |
130 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append( | |
131 FILE_PATH_LITERAL("LayoutTests/")); | |
132 #if defined(OS_WIN) | |
133 std::string utf8_path = WideToUTF8(replace_path.value()); | |
134 #else | |
135 std::string utf8_path = | |
136 WideToUTF8(base::SysNativeMBToWide(replace_path.value())); | |
137 #endif | |
138 std::string new_url = | |
139 std::string("file://") + utf8_path + url.spec().substr(kPrefixLen); | |
140 return GURL(new_url); | |
141 } | |
142 | |
143 } // namespace content | 123 } // namespace content |
OLD | NEW |