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