| 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/renderer/extensions/extension_helper.h" | 5 #include "chrome/renderer/extensions/extension_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 31 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 32 #include "third_party/WebKit/public/web/WebDocument.h" | 32 #include "third_party/WebKit/public/web/WebDocument.h" |
| 33 #include "third_party/WebKit/public/web/WebFrame.h" | 33 #include "third_party/WebKit/public/web/WebFrame.h" |
| 34 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 34 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 35 #include "third_party/WebKit/public/web/WebView.h" | 35 #include "third_party/WebKit/public/web/WebView.h" |
| 36 | 36 |
| 37 using content::ConsoleMessageLevel; | 37 using content::ConsoleMessageLevel; |
| 38 using blink::WebConsoleMessage; | 38 using blink::WebConsoleMessage; |
| 39 using blink::WebDataSource; | 39 using blink::WebDataSource; |
| 40 using blink::WebFrame; | 40 using blink::WebFrame; |
| 41 using blink::WebLocalFrame; |
| 41 using blink::WebURLRequest; | 42 using blink::WebURLRequest; |
| 42 using blink::WebScopedUserGesture; | 43 using blink::WebScopedUserGesture; |
| 43 using blink::WebView; | 44 using blink::WebView; |
| 44 | 45 |
| 45 namespace extensions { | 46 namespace extensions { |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 // Keeps a mapping from the frame pointer to a UserScriptScheduler object. | 49 // Keeps a mapping from the frame pointer to a UserScriptScheduler object. |
| 49 // We store this mapping per process, because a frame can jump from one | 50 // We store this mapping per process, because a frame can jump from one |
| 50 // document to another with adoptNode, and so having the object be a | 51 // document to another with adoptNode, and so having the object be a |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 OnNotifyRendererViewType) | 172 OnNotifyRendererViewType) |
| 172 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole, | 173 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole, |
| 173 OnAddMessageToConsole) | 174 OnAddMessageToConsole) |
| 174 IPC_MESSAGE_HANDLER(ExtensionMsg_AppWindowClosed, | 175 IPC_MESSAGE_HANDLER(ExtensionMsg_AppWindowClosed, |
| 175 OnAppWindowClosed); | 176 OnAppWindowClosed); |
| 176 IPC_MESSAGE_UNHANDLED(handled = false) | 177 IPC_MESSAGE_UNHANDLED(handled = false) |
| 177 IPC_END_MESSAGE_MAP() | 178 IPC_END_MESSAGE_MAP() |
| 178 return handled; | 179 return handled; |
| 179 } | 180 } |
| 180 | 181 |
| 181 void ExtensionHelper::DidFinishDocumentLoad(WebFrame* frame) { | 182 void ExtensionHelper::DidFinishDocumentLoad(WebLocalFrame* frame) { |
| 182 dispatcher_->user_script_slave()->InjectScripts( | 183 dispatcher_->user_script_slave()->InjectScripts( |
| 183 frame, UserScript::DOCUMENT_END); | 184 frame, UserScript::DOCUMENT_END); |
| 184 | 185 |
| 185 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 186 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 186 if (i != g_schedulers.Get().end()) | 187 if (i != g_schedulers.Get().end()) |
| 187 i->second->DidFinishDocumentLoad(); | 188 i->second->DidFinishDocumentLoad(); |
| 188 } | 189 } |
| 189 | 190 |
| 190 void ExtensionHelper::DidFinishLoad(blink::WebFrame* frame) { | 191 void ExtensionHelper::DidFinishLoad(blink::WebLocalFrame* frame) { |
| 191 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 192 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 192 if (i != g_schedulers.Get().end()) | 193 if (i != g_schedulers.Get().end()) |
| 193 i->second->DidFinishLoad(); | 194 i->second->DidFinishLoad(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void ExtensionHelper::DidCreateDocumentElement(WebFrame* frame) { | 197 void ExtensionHelper::DidCreateDocumentElement(WebLocalFrame* frame) { |
| 197 dispatcher_->user_script_slave()->InjectScripts( | 198 dispatcher_->user_script_slave()->InjectScripts( |
| 198 frame, UserScript::DOCUMENT_START); | 199 frame, UserScript::DOCUMENT_START); |
| 199 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 200 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 200 if (i != g_schedulers.Get().end()) | 201 if (i != g_schedulers.Get().end()) |
| 201 i->second->DidCreateDocumentElement(); | 202 i->second->DidCreateDocumentElement(); |
| 202 | 203 |
| 203 dispatcher_->DidCreateDocumentElement(frame); | 204 dispatcher_->DidCreateDocumentElement(frame); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void ExtensionHelper::DidStartProvisionalLoad(blink::WebFrame* frame) { | 207 void ExtensionHelper::DidStartProvisionalLoad(blink::WebLocalFrame* frame) { |
| 207 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 208 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 208 if (i != g_schedulers.Get().end()) | 209 if (i != g_schedulers.Get().end()) |
| 209 i->second->DidStartProvisionalLoad(); | 210 i->second->DidStartProvisionalLoad(); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void ExtensionHelper::DraggableRegionsChanged(blink::WebFrame* frame) { | 213 void ExtensionHelper::DraggableRegionsChanged(blink::WebFrame* frame) { |
| 213 blink::WebVector<blink::WebDraggableRegion> webregions = | 214 blink::WebVector<blink::WebDraggableRegion> webregions = |
| 214 frame->document().draggableRegions(); | 215 frame->document().draggableRegions(); |
| 215 std::vector<DraggableRegion> regions; | 216 std::vector<DraggableRegion> regions; |
| 216 for (size_t i = 0; i < webregions.size(); ++i) { | 217 for (size_t i = 0; i < webregions.size(); ++i) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 227 // won't be in the map. | 228 // won't be in the map. |
| 228 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 229 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 229 if (i == g_schedulers.Get().end()) | 230 if (i == g_schedulers.Get().end()) |
| 230 return; | 231 return; |
| 231 | 232 |
| 232 delete i->second; | 233 delete i->second; |
| 233 g_schedulers.Get().erase(i); | 234 g_schedulers.Get().erase(i); |
| 234 } | 235 } |
| 235 | 236 |
| 236 void ExtensionHelper::DidMatchCSS( | 237 void ExtensionHelper::DidMatchCSS( |
| 237 blink::WebFrame* frame, | 238 blink::WebLocalFrame* frame, |
| 238 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 239 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 239 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 240 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 240 dispatcher_->DidMatchCSS( | 241 dispatcher_->DidMatchCSS( |
| 241 frame, newly_matching_selectors, stopped_matching_selectors); | 242 frame, newly_matching_selectors, stopped_matching_selectors); |
| 242 } | 243 } |
| 243 | 244 |
| 244 void ExtensionHelper::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) { | 245 void ExtensionHelper::DidCreateDataSource(WebLocalFrame* frame, |
| 246 WebDataSource* ds) { |
| 245 // Check first if we created a scheduler for the frame, since this function | 247 // Check first if we created a scheduler for the frame, since this function |
| 246 // gets called for navigations within the document. | 248 // gets called for navigations within the document. |
| 247 if (g_schedulers.Get().count(frame)) | 249 if (g_schedulers.Get().count(frame)) |
| 248 return; | 250 return; |
| 249 | 251 |
| 250 g_schedulers.Get()[frame] = new UserScriptScheduler(frame, dispatcher_); | 252 g_schedulers.Get()[frame] = new UserScriptScheduler(frame, dispatcher_); |
| 251 } | 253 } |
| 252 | 254 |
| 253 void ExtensionHelper::OnExtensionResponse(int request_id, | 255 void ExtensionHelper::OnExtensionResponse(int request_id, |
| 254 bool success, | 256 bool success, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 render_view()->GetWebView()->mainFrame()->mainWorldScriptContext(); | 372 render_view()->GetWebView()->mainFrame()->mainWorldScriptContext(); |
| 371 ChromeV8Context* chrome_v8_context = | 373 ChromeV8Context* chrome_v8_context = |
| 372 dispatcher_->v8_context_set().GetByV8Context(script_context); | 374 dispatcher_->v8_context_set().GetByV8Context(script_context); |
| 373 if (!chrome_v8_context) | 375 if (!chrome_v8_context) |
| 374 return; | 376 return; |
| 375 chrome_v8_context->module_system()->CallModuleMethod( | 377 chrome_v8_context->module_system()->CallModuleMethod( |
| 376 "app.window", "onAppWindowClosed"); | 378 "app.window", "onAppWindowClosed"); |
| 377 } | 379 } |
| 378 | 380 |
| 379 } // namespace extensions | 381 } // namespace extensions |
| OLD | NEW |