OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/shell_devtools_frontend.h" | 5 #include "content/shell/browser/shell_devtools_frontend.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/public/browser/devtools_http_handler.h" | 13 #include "content/public/browser/devtools_http_handler.h" |
14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
18 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
19 #include "content/shell/browser/shell_browser_context.h" | 19 #include "content/shell/browser/shell_browser_context.h" |
20 #include "content/shell/browser/shell_browser_main_parts.h" | 20 #include "content/shell/browser/shell_browser_main_parts.h" |
21 #include "content/shell/browser/shell_content_browser_client.h" | 21 #include "content/shell/browser/shell_content_browser_client.h" |
22 #include "content/shell/browser/shell_devtools_delegate.h" | 22 #include "content/shell/browser/shell_devtools_delegate.h" |
23 #include "content/shell/browser/webkit_test_controller.h" | 23 #include "content/shell/browser/webkit_test_controller.h" |
24 #include "content/shell/common/shell_switches.h" | 24 #include "content/shell/common/shell_switches.h" |
25 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 // DevTools frontend path for inspector LayoutTests. | |
30 GURL GetDevToolsPathAsURL(const std::string& settings, | |
31 const std::string& frontend_url) { | |
32 if (!frontend_url.empty()) | |
33 return GURL(frontend_url); | |
34 base::FilePath dir_exe; | |
35 if (!PathService::Get(base::DIR_EXE, &dir_exe)) { | |
36 NOTREACHED(); | |
37 return GURL(); | |
38 } | |
39 #if defined(OS_MACOSX) | |
40 // On Mac, the executable is in | |
41 // out/Release/Content Shell.app/Contents/MacOS/Content Shell. | |
42 // We need to go up 3 directories to get to out/Release. | |
43 dir_exe = dir_exe.AppendASCII("../../.."); | |
44 #endif | |
45 base::FilePath dev_tools_path = dir_exe.AppendASCII( | |
46 "resources/inspector/devtools.html"); | |
47 | |
48 GURL result = net::FilePathToFileURL(dev_tools_path); | |
49 if (!settings.empty()) | |
50 result = GURL(base::StringPrintf("%s?settings=%s&experiments=true", | |
51 result.spec().c_str(), | |
52 settings.c_str())); | |
53 return result; | |
54 } | |
55 | |
56 // static | 29 // static |
57 ShellDevToolsFrontend* ShellDevToolsFrontend::Show( | 30 ShellDevToolsFrontend* ShellDevToolsFrontend::Show( |
58 WebContents* inspected_contents) { | 31 WebContents* inspected_contents) { |
59 return ShellDevToolsFrontend::Show(inspected_contents, "", ""); | |
60 } | |
61 | |
62 // static | |
63 ShellDevToolsFrontend* ShellDevToolsFrontend::Show( | |
64 WebContents* inspected_contents, | |
65 const std::string& settings, | |
66 const std::string& frontend_url) { | |
67 scoped_refptr<DevToolsAgentHost> agent( | 32 scoped_refptr<DevToolsAgentHost> agent( |
68 DevToolsAgentHost::GetOrCreateFor(inspected_contents)); | 33 DevToolsAgentHost::GetOrCreateFor(inspected_contents)); |
69 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(), | 34 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(), |
70 GURL(), | 35 GURL(), |
71 NULL, | 36 NULL, |
72 MSG_ROUTING_NONE, | 37 MSG_ROUTING_NONE, |
73 gfx::Size()); | 38 gfx::Size()); |
74 ShellDevToolsFrontend* devtools_frontend = new ShellDevToolsFrontend( | 39 ShellDevToolsFrontend* devtools_frontend = new ShellDevToolsFrontend( |
75 shell, | 40 shell, |
76 agent.get()); | 41 agent.get()); |
77 | 42 |
78 ShellDevToolsDelegate* delegate = ShellContentBrowserClient::Get()-> | 43 ShellDevToolsDelegate* delegate = ShellContentBrowserClient::Get() |
79 shell_browser_main_parts()->devtools_delegate(); | 44 ->shell_browser_main_parts() |
80 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 45 ->devtools_delegate(); |
81 shell->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); | 46 shell->LoadURL(delegate->devtools_http_handler()->GetFrontendURL()); |
82 else | |
83 shell->LoadURL(delegate->devtools_http_handler()->GetFrontendURL()); | |
84 | 47 |
85 return devtools_frontend; | 48 return devtools_frontend; |
86 } | 49 } |
87 | 50 |
88 void ShellDevToolsFrontend::Activate() { | 51 void ShellDevToolsFrontend::Activate() { |
89 frontend_shell_->ActivateContents(web_contents()); | 52 frontend_shell_->ActivateContents(web_contents()); |
90 } | 53 } |
91 | 54 |
92 void ShellDevToolsFrontend::Focus() { | 55 void ShellDevToolsFrontend::Focus() { |
93 web_contents()->Focus(); | 56 web_contents()->Focus(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 base::string16 javascript = base::UTF8ToUTF16(code); | 141 base::string16 javascript = base::UTF8ToUTF16(code); |
179 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 142 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); |
180 } | 143 } |
181 | 144 |
182 void ShellDevToolsFrontend::AgentHostClosed( | 145 void ShellDevToolsFrontend::AgentHostClosed( |
183 DevToolsAgentHost* agent_host, bool replaced) { | 146 DevToolsAgentHost* agent_host, bool replaced) { |
184 frontend_shell_->Close(); | 147 frontend_shell_->Close(); |
185 } | 148 } |
186 | 149 |
187 } // namespace content | 150 } // namespace content |
OLD | NEW |