| 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 "chrome/browser/automation/automation_tab_helper.h" | 5 #include "chrome/browser/automation/automation_tab_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/common/automation_messages.h" | 9 #include "chrome/common/automation_messages.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
| 13 #include "ui/gfx/point.h" |
| 13 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 14 | 15 |
| 15 using content::WebContents; | 16 using content::WebContents; |
| 16 | 17 |
| 17 TabEventObserver::TabEventObserver() { } | 18 TabEventObserver::TabEventObserver() { } |
| 18 | 19 |
| 19 TabEventObserver::~TabEventObserver() { | 20 TabEventObserver::~TabEventObserver() { |
| 20 for (size_t i = 0; i < event_sources_.size(); ++i) { | 21 for (size_t i = 0; i < event_sources_.size(); ++i) { |
| 21 if (event_sources_[i]) | 22 if (event_sources_[i]) |
| 22 event_sources_[i]->RemoveObserver(this); | 23 event_sources_[i]->RemoveObserver(this); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 void AutomationTabHelper::SnapshotEntirePage() { | 55 void AutomationTabHelper::SnapshotEntirePage() { |
| 55 Send(new AutomationMsg_SnapshotEntirePage(routing_id())); | 56 Send(new AutomationMsg_SnapshotEntirePage(routing_id())); |
| 56 } | 57 } |
| 57 | 58 |
| 58 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 59 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 59 void AutomationTabHelper::HeapProfilerDump(const std::string& reason) { | 60 void AutomationTabHelper::HeapProfilerDump(const std::string& reason) { |
| 60 Send(new AutomationMsg_HeapProfilerDump(routing_id(), reason)); | 61 Send(new AutomationMsg_HeapProfilerDump(routing_id(), reason)); |
| 61 } | 62 } |
| 62 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 63 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 63 | 64 |
| 65 void AutomationTabHelper::ProcessMouseEvent( |
| 66 const AutomationMouseEvent& event) { |
| 67 Send(new AutomationMsg_ProcessMouseEvent(routing_id(), event)); |
| 68 } |
| 69 |
| 64 bool AutomationTabHelper::has_pending_loads() const { | 70 bool AutomationTabHelper::has_pending_loads() const { |
| 65 return is_loading_ || !pending_client_redirects_.empty(); | 71 return is_loading_ || !pending_client_redirects_.empty(); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void AutomationTabHelper::DidStartLoading() { | 74 void AutomationTabHelper::DidStartLoading() { |
| 69 if (is_loading_) { | 75 if (is_loading_) { |
| 70 // DidStartLoading is often called twice. Once when the renderer sends a | 76 // DidStartLoading is often called twice. Once when the renderer sends a |
| 71 // load start message, and once when the browser calls it directly as a | 77 // load start message, and once when the browser calls it directly as a |
| 72 // result of some user-initiated navigation. | 78 // result of some user-initiated navigation. |
| 73 VLOG(1) << "Received DidStartLoading while loading already started."; | 79 VLOG(1) << "Received DidStartLoading while loading already started."; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 118 } |
| 113 | 119 |
| 114 void AutomationTabHelper::OnSnapshotEntirePageACK( | 120 void AutomationTabHelper::OnSnapshotEntirePageACK( |
| 115 bool success, | 121 bool success, |
| 116 const std::vector<unsigned char>& png_data, | 122 const std::vector<unsigned char>& png_data, |
| 117 const std::string& error_msg) { | 123 const std::string& error_msg) { |
| 118 FOR_EACH_OBSERVER(TabEventObserver, observers_, | 124 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 119 OnSnapshotEntirePageACK(success, png_data, error_msg)); | 125 OnSnapshotEntirePageACK(success, png_data, error_msg)); |
| 120 } | 126 } |
| 121 | 127 |
| 128 void AutomationTabHelper::OnWillProcessMouseEventAt(const gfx::Point& point) { |
| 129 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 130 OnWillProcessMouseEventAt(point)); |
| 131 } |
| 132 |
| 133 void AutomationTabHelper::OnProcessMouseEventACK( |
| 134 bool success, |
| 135 const std::string& error_msg) { |
| 136 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 137 OnProcessMouseEventACK(success, error_msg)); |
| 138 } |
| 139 |
| 122 bool AutomationTabHelper::OnMessageReceived(const IPC::Message& message) { | 140 bool AutomationTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 123 bool handled = true; | 141 bool handled = true; |
| 124 bool msg_is_good = true; | 142 bool msg_is_good = true; |
| 125 IPC_BEGIN_MESSAGE_MAP_EX(AutomationTabHelper, message, msg_is_good) | 143 IPC_BEGIN_MESSAGE_MAP_EX(AutomationTabHelper, message, msg_is_good) |
| 126 IPC_MESSAGE_HANDLER(AutomationMsg_SnapshotEntirePageACK, | 144 IPC_MESSAGE_HANDLER(AutomationMsg_SnapshotEntirePageACK, |
| 127 OnSnapshotEntirePageACK) | 145 OnSnapshotEntirePageACK) |
| 146 IPC_MESSAGE_HANDLER(AutomationMsg_WillProcessMouseEventAt, |
| 147 OnWillProcessMouseEventAt) |
| 148 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessMouseEventACK, |
| 149 OnProcessMouseEventACK) |
| 128 IPC_MESSAGE_HANDLER(AutomationMsg_WillPerformClientRedirect, | 150 IPC_MESSAGE_HANDLER(AutomationMsg_WillPerformClientRedirect, |
| 129 OnWillPerformClientRedirect) | 151 OnWillPerformClientRedirect) |
| 130 IPC_MESSAGE_HANDLER(AutomationMsg_DidCompleteOrCancelClientRedirect, | 152 IPC_MESSAGE_HANDLER(AutomationMsg_DidCompleteOrCancelClientRedirect, |
| 131 OnDidCompleteOrCancelClientRedirect) | 153 OnDidCompleteOrCancelClientRedirect) |
| 132 IPC_MESSAGE_UNHANDLED(handled = false) | 154 IPC_MESSAGE_UNHANDLED(handled = false) |
| 133 IPC_END_MESSAGE_MAP_EX() | 155 IPC_END_MESSAGE_MAP_EX() |
| 134 if (!msg_is_good) { | 156 if (!msg_is_good) { |
| 135 LOG(ERROR) << "Failed to deserialize an IPC message"; | 157 LOG(ERROR) << "Failed to deserialize an IPC message"; |
| 136 } | 158 } |
| 137 return handled; | 159 return handled; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 161 // It is possible that we did not track the redirect becasue it had a non-zero | 183 // It is possible that we did not track the redirect becasue it had a non-zero |
| 162 // delay. See the comment in |OnWillPerformClientRedirect|. | 184 // delay. See the comment in |OnWillPerformClientRedirect|. |
| 163 if (iter != pending_client_redirects_.end()) { | 185 if (iter != pending_client_redirects_.end()) { |
| 164 pending_client_redirects_.erase(iter); | 186 pending_client_redirects_.erase(iter); |
| 165 if (!has_pending_loads()) { | 187 if (!has_pending_loads()) { |
| 166 FOR_EACH_OBSERVER(TabEventObserver, observers_, | 188 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 167 OnNoMorePendingLoads(web_contents())); | 189 OnNoMorePendingLoads(web_contents())); |
| 168 } | 190 } |
| 169 } | 191 } |
| 170 } | 192 } |
| OLD | NEW |