| 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_render_process_observer.h" | 5 #include "content/shell/shell_render_process_observer.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/public/renderer/render_view.h" | 8 #include "content/public/renderer/render_view.h" |
| 9 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
| 10 #include "content/shell/shell_messages.h" | 10 #include "content/shell/shell_messages.h" |
| 11 #include "content/shell/shell_switches.h" | 11 #include "content/shell/shell_switches.h" |
| 12 #include "content/shell/webkit_test_runner_bindings.h" | 12 #include "content/shell/webkit_test_runner_bindings.h" |
| 13 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
| 14 #include "webkit/support/gc_extension.h" | 14 #include "webkit/support/gc_extension.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTestingSupport.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTestingSupport.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 16 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestInterfaces.h" | 17 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestInterfaces.h" |
| 17 | 18 |
| 18 using WebKit::WebFrame; | 19 using WebKit::WebFrame; |
| 19 using WebKit::WebTestingSupport; | 20 using WebKit::WebTestingSupport; |
| 20 using WebTestRunner::WebTestDelegate; | 21 using WebTestRunner::WebTestDelegate; |
| 21 using WebTestRunner::WebTestInterfaces; | 22 using WebTestRunner::WebTestInterfaces; |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 ShellRenderProcessObserver* g_instance = NULL; | 27 ShellRenderProcessObserver* g_instance = NULL; |
| 27 } | 28 } |
| 28 | 29 |
| 29 // static | 30 // static |
| 30 ShellRenderProcessObserver* ShellRenderProcessObserver::GetInstance() { | 31 ShellRenderProcessObserver* ShellRenderProcessObserver::GetInstance() { |
| 31 return g_instance; | 32 return g_instance; |
| 32 } | 33 } |
| 33 | 34 |
| 34 ShellRenderProcessObserver::ShellRenderProcessObserver() | 35 ShellRenderProcessObserver::ShellRenderProcessObserver() |
| 35 : test_delegate_(NULL) { | 36 : main_render_view_(NULL), |
| 37 test_delegate_(NULL) { |
| 36 CHECK(!g_instance); | 38 CHECK(!g_instance); |
| 37 g_instance = this; | 39 g_instance = this; |
| 38 RenderThread::Get()->AddObserver(this); | 40 RenderThread::Get()->AddObserver(this); |
| 39 } | 41 } |
| 40 | 42 |
| 41 ShellRenderProcessObserver::~ShellRenderProcessObserver() { | 43 ShellRenderProcessObserver::~ShellRenderProcessObserver() { |
| 42 CHECK(g_instance == this); | 44 CHECK(g_instance == this); |
| 43 g_instance = NULL; | 45 g_instance = NULL; |
| 44 } | 46 } |
| 45 | 47 |
| 46 void ShellRenderProcessObserver::SetMainWindow( | 48 void ShellRenderProcessObserver::SetMainWindow( |
| 47 RenderView* view, | 49 RenderView* view, |
| 48 WebTestDelegate* delegate) { | 50 WebTestDelegate* delegate) { |
| 49 if (view == NULL) { | 51 test_interfaces_->setDelegate(delegate); |
| 50 if (delegate == test_delegate_) { | 52 test_interfaces_->setWebView(view->GetWebView()); |
| 51 test_interfaces_->setDelegate(NULL); | 53 main_render_view_ = view; |
| 52 test_interfaces_->setWebView(NULL); | 54 test_delegate_ = delegate; |
| 53 test_delegate_ = NULL; | |
| 54 } | |
| 55 } else { | |
| 56 test_interfaces_->setDelegate(delegate); | |
| 57 test_interfaces_->setWebView(view->GetWebView()); | |
| 58 test_delegate_ = delegate; | |
| 59 } | |
| 60 } | 55 } |
| 61 | 56 |
| 62 void ShellRenderProcessObserver::BindTestRunnersToWindow(WebFrame* frame) { | 57 void ShellRenderProcessObserver::BindTestRunnersToWindow(WebFrame* frame) { |
| 63 WebTestingSupport::injectInternalsObject(frame); | 58 WebTestingSupport::injectInternalsObject(frame); |
| 64 test_interfaces_->bindTo(frame); | 59 test_interfaces_->bindTo(frame); |
| 65 } | 60 } |
| 66 | 61 |
| 67 void ShellRenderProcessObserver::WebKitInitialized() { | 62 void ShellRenderProcessObserver::WebKitInitialized() { |
| 68 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 63 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 69 return; | 64 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 85 IPC_BEGIN_MESSAGE_MAP(ShellRenderProcessObserver, message) | 80 IPC_BEGIN_MESSAGE_MAP(ShellRenderProcessObserver, message) |
| 86 IPC_MESSAGE_HANDLER(ShellViewMsg_ResetAll, OnResetAll) | 81 IPC_MESSAGE_HANDLER(ShellViewMsg_ResetAll, OnResetAll) |
| 87 IPC_MESSAGE_UNHANDLED(handled = false) | 82 IPC_MESSAGE_UNHANDLED(handled = false) |
| 88 IPC_END_MESSAGE_MAP() | 83 IPC_END_MESSAGE_MAP() |
| 89 | 84 |
| 90 return handled; | 85 return handled; |
| 91 } | 86 } |
| 92 | 87 |
| 93 void ShellRenderProcessObserver::OnResetAll() { | 88 void ShellRenderProcessObserver::OnResetAll() { |
| 94 test_interfaces_->resetAll(); | 89 test_interfaces_->resetAll(); |
| 95 // We don't reset the WebTestingSupport objects, as we don't reuse WebViews. | 90 if (main_render_view_) { |
| 91 WebTestingSupport::resetInternalsObject( |
| 92 main_render_view_->GetWebView()->mainFrame()); |
| 93 } |
| 96 } | 94 } |
| 97 | 95 |
| 98 } // namespace content | 96 } // namespace content |
| OLD | NEW |