OLD | NEW |
1 // Copyright (c) 2009 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/renderer/user_script_idle_scheduler.h" | 5 #include "chrome/renderer/user_script_idle_scheduler.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/common/extensions/extension_messages.h" | 8 #include "chrome/common/extensions/extension_messages.h" |
9 #include "chrome/renderer/extension_groups.h" | 9 #include "chrome/renderer/extension_groups.h" |
10 #include "chrome/renderer/extensions/extension_dispatcher.h" | 10 #include "chrome/renderer/extensions/extension_dispatcher.h" |
11 #include "chrome/renderer/render_thread.h" | 11 #include "chrome/renderer/render_thread.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 pending_code_execution_queue_.front(); | 106 pending_code_execution_queue_.front(); |
107 ExecuteCodeImpl(GetMainFrame(), *params); | 107 ExecuteCodeImpl(GetMainFrame(), *params); |
108 pending_code_execution_queue_.pop(); | 108 pending_code_execution_queue_.pop(); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 void UserScriptIdleScheduler::OnExecuteCode( | 112 void UserScriptIdleScheduler::OnExecuteCode( |
113 const ExtensionMsg_ExecuteCode_Params& params) { | 113 const ExtensionMsg_ExecuteCode_Params& params) { |
114 WebFrame* main_frame = GetMainFrame(); | 114 WebFrame* main_frame = GetMainFrame(); |
115 if (!main_frame) { | 115 if (!main_frame) { |
116 Send(new ViewHostMsg_ExecuteCodeFinished( | 116 Send(new ExtensionHostMsg_ExecuteCodeFinished( |
117 routing_id(), params.request_id, false)); | 117 routing_id(), params.request_id, false)); |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 if (!has_run_) { | 121 if (!has_run_) { |
122 pending_code_execution_queue_.push( | 122 pending_code_execution_queue_.push( |
123 linked_ptr<ExtensionMsg_ExecuteCode_Params>( | 123 linked_ptr<ExtensionMsg_ExecuteCode_Params>( |
124 new ExtensionMsg_ExecuteCode_Params(params))); | 124 new ExtensionMsg_ExecuteCode_Params(params))); |
125 return; | 125 return; |
126 } | 126 } |
(...skipping 29 matching lines...) Expand all Loading... |
156 WebScriptSource(WebString::fromUTF8(params.code))); | 156 WebScriptSource(WebString::fromUTF8(params.code))); |
157 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); | 157 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
158 frame->executeScriptInIsolatedWorld( | 158 frame->executeScriptInIsolatedWorld( |
159 UserScriptSlave::GetIsolatedWorldId(params.extension_id), | 159 UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
160 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); | 160 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
161 } else { | 161 } else { |
162 frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); | 162 frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 Send(new ViewHostMsg_ExecuteCodeFinished( | 166 Send(new ExtensionHostMsg_ExecuteCodeFinished( |
167 routing_id(), params.request_id, true)); | 167 routing_id(), params.request_id, true)); |
168 } | 168 } |
169 | 169 |
170 bool UserScriptIdleScheduler::GetAllChildFrames( | 170 bool UserScriptIdleScheduler::GetAllChildFrames( |
171 WebFrame* parent_frame, | 171 WebFrame* parent_frame, |
172 std::vector<WebFrame*>* frames_vector) const { | 172 std::vector<WebFrame*>* frames_vector) const { |
173 if (!parent_frame) | 173 if (!parent_frame) |
174 return false; | 174 return false; |
175 | 175 |
176 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 176 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
177 child_frame = child_frame->nextSibling()) { | 177 child_frame = child_frame->nextSibling()) { |
178 frames_vector->push_back(child_frame); | 178 frames_vector->push_back(child_frame); |
179 GetAllChildFrames(child_frame, frames_vector); | 179 GetAllChildFrames(child_frame, frames_vector); |
180 } | 180 } |
181 return true; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 WebFrame* UserScriptIdleScheduler::GetMainFrame() { | 184 WebFrame* UserScriptIdleScheduler::GetMainFrame() { |
185 WebView* webview = render_view()->webview(); | 185 WebView* webview = render_view()->webview(); |
186 return webview ? webview->mainFrame() : NULL; | 186 return webview ? webview->mainFrame() : NULL; |
187 } | 187 } |
OLD | NEW |