| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/tab_contents/navigation_controller.h" | 9 #include "content/browser/tab_contents/navigation_controller.h" |
| 10 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/common/automation_messages.h" | 11 #include "chrome/common/automation_messages.h" |
| 12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
| 13 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
| 14 | 14 |
| 15 #include "ui/gfx/size.h" |
| 16 |
| 15 TabEventObserver::TabEventObserver() { } | 17 TabEventObserver::TabEventObserver() { } |
| 16 | 18 |
| 17 TabEventObserver::~TabEventObserver() { | 19 TabEventObserver::~TabEventObserver() { |
| 18 for (size_t i = 0; i < event_sources_.size(); ++i) { | 20 for (size_t i = 0; i < event_sources_.size(); ++i) { |
| 19 if (event_sources_[i]) | 21 if (event_sources_[i]) |
| 20 event_sources_[i]->RemoveObserver(this); | 22 event_sources_[i]->RemoveObserver(this); |
| 21 } | 23 } |
| 22 } | 24 } |
| 23 | 25 |
| 24 void TabEventObserver::StartObserving(AutomationTabHelper* tab_helper) { | 26 void TabEventObserver::StartObserving(AutomationTabHelper* tab_helper) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 AutomationTabHelper::~AutomationTabHelper() { } | 44 AutomationTabHelper::~AutomationTabHelper() { } |
| 43 | 45 |
| 44 void AutomationTabHelper::AddObserver(TabEventObserver* observer) { | 46 void AutomationTabHelper::AddObserver(TabEventObserver* observer) { |
| 45 observers_.AddObserver(observer); | 47 observers_.AddObserver(observer); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void AutomationTabHelper::RemoveObserver(TabEventObserver* observer) { | 50 void AutomationTabHelper::RemoveObserver(TabEventObserver* observer) { |
| 49 observers_.RemoveObserver(observer); | 51 observers_.RemoveObserver(observer); |
| 50 } | 52 } |
| 51 | 53 |
| 54 void AutomationTabHelper::SnapshotEntirePage() { |
| 55 Send(new AutomationMsg_SnapshotEntirePage(routing_id())); |
| 56 } |
| 57 |
| 52 bool AutomationTabHelper::has_pending_loads() const { | 58 bool AutomationTabHelper::has_pending_loads() const { |
| 53 return is_loading_ || !pending_client_redirects_.empty(); | 59 return is_loading_ || !pending_client_redirects_.empty(); |
| 54 } | 60 } |
| 55 | 61 |
| 56 void AutomationTabHelper::DidStartLoading() { | 62 void AutomationTabHelper::DidStartLoading() { |
| 57 if (is_loading_) { | 63 if (is_loading_) { |
| 58 // DidStartLoading is often called twice. Once when the renderer sends a | 64 // DidStartLoading is often called twice. Once when the renderer sends a |
| 59 // load start message, and once when the browser calls it directly as a | 65 // load start message, and once when the browser calls it directly as a |
| 60 // result of some user-initiated navigation. | 66 // result of some user-initiated navigation. |
| 61 VLOG(1) << "Received DidStartLoading while loading already started."; | 67 VLOG(1) << "Received DidStartLoading while loading already started."; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 92 void AutomationTabHelper::OnTabOrRenderViewDestroyed( | 98 void AutomationTabHelper::OnTabOrRenderViewDestroyed( |
| 93 TabContents* tab_contents) { | 99 TabContents* tab_contents) { |
| 94 if (has_pending_loads()) { | 100 if (has_pending_loads()) { |
| 95 is_loading_ = false; | 101 is_loading_ = false; |
| 96 pending_client_redirects_.clear(); | 102 pending_client_redirects_.clear(); |
| 97 FOR_EACH_OBSERVER(TabEventObserver, observers_, | 103 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 98 OnNoMorePendingLoads(tab_contents)); | 104 OnNoMorePendingLoads(tab_contents)); |
| 99 } | 105 } |
| 100 } | 106 } |
| 101 | 107 |
| 108 void AutomationTabHelper::OnSnapshotEntirePageACK( |
| 109 bool success, |
| 110 const std::vector<unsigned char>& png_data, |
| 111 const std::string& error_msg) { |
| 112 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 113 OnSnapshotEntirePageACK(success, png_data, error_msg)); |
| 114 } |
| 115 |
| 102 bool AutomationTabHelper::OnMessageReceived(const IPC::Message& message) { | 116 bool AutomationTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 103 bool handled = true; | 117 bool handled = true; |
| 104 bool msg_is_good = true; | 118 bool msg_is_good = true; |
| 105 IPC_BEGIN_MESSAGE_MAP_EX(AutomationTabHelper, message, msg_is_good) | 119 IPC_BEGIN_MESSAGE_MAP_EX(AutomationTabHelper, message, msg_is_good) |
| 120 IPC_MESSAGE_HANDLER(AutomationMsg_SnapshotEntirePageACK, |
| 121 OnSnapshotEntirePageACK) |
| 106 IPC_MESSAGE_HANDLER(AutomationMsg_WillPerformClientRedirect, | 122 IPC_MESSAGE_HANDLER(AutomationMsg_WillPerformClientRedirect, |
| 107 OnWillPerformClientRedirect) | 123 OnWillPerformClientRedirect) |
| 108 IPC_MESSAGE_HANDLER(AutomationMsg_DidCompleteOrCancelClientRedirect, | 124 IPC_MESSAGE_HANDLER(AutomationMsg_DidCompleteOrCancelClientRedirect, |
| 109 OnDidCompleteOrCancelClientRedirect) | 125 OnDidCompleteOrCancelClientRedirect) |
| 110 IPC_MESSAGE_UNHANDLED(handled = false) | 126 IPC_MESSAGE_UNHANDLED(handled = false) |
| 111 IPC_END_MESSAGE_MAP_EX() | 127 IPC_END_MESSAGE_MAP_EX() |
| 112 if (!msg_is_good) { | 128 if (!msg_is_good) { |
| 113 LOG(ERROR) << "Failed to deserialize an IPC message"; | 129 LOG(ERROR) << "Failed to deserialize an IPC message"; |
| 114 } | 130 } |
| 115 return handled; | 131 return handled; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 139 // It is possible that we did not track the redirect becasue it had a non-zero | 155 // It is possible that we did not track the redirect becasue it had a non-zero |
| 140 // delay. See the comment in |OnWillPerformClientRedirect|. | 156 // delay. See the comment in |OnWillPerformClientRedirect|. |
| 141 if (iter != pending_client_redirects_.end()) { | 157 if (iter != pending_client_redirects_.end()) { |
| 142 pending_client_redirects_.erase(iter); | 158 pending_client_redirects_.erase(iter); |
| 143 if (!has_pending_loads()) { | 159 if (!has_pending_loads()) { |
| 144 FOR_EACH_OBSERVER(TabEventObserver, observers_, | 160 FOR_EACH_OBSERVER(TabEventObserver, observers_, |
| 145 OnNoMorePendingLoads(tab_contents())); | 161 OnNoMorePendingLoads(tab_contents())); |
| 146 } | 162 } |
| 147 } | 163 } |
| 148 } | 164 } |
| OLD | NEW |