| 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 30 matching lines...) Expand all Loading... |
| 41 using WebKit::WebScopedUserGesture; | 41 using WebKit::WebScopedUserGesture; |
| 42 using WebKit::WebView; | 42 using WebKit::WebView; |
| 43 using webkit_glue::ImageResourceFetcher; | 43 using webkit_glue::ImageResourceFetcher; |
| 44 using webkit_glue::ResourceFetcher; | 44 using webkit_glue::ResourceFetcher; |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 // Keeps a mapping from the frame pointer to a UserScriptScheduler object. | 47 // Keeps a mapping from the frame pointer to a UserScriptScheduler object. |
| 48 // We store this mapping per process, because a frame can jump from one | 48 // We store this mapping per process, because a frame can jump from one |
| 49 // document to another with adoptNode, and so having the object be a | 49 // document to another with adoptNode, and so having the object be a |
| 50 // RenderViewObserver means it might miss some notifications after it moves. | 50 // RenderViewObserver means it might miss some notifications after it moves. |
| 51 typedef std::map<WebFrame*, UserScriptScheduler*> SchedulerMap; | 51 typedef std::map<WebFrame*, extensions::UserScriptScheduler*> SchedulerMap; |
| 52 static base::LazyInstance<SchedulerMap> g_schedulers = | 52 static base::LazyInstance<SchedulerMap> g_schedulers = |
| 53 LAZY_INSTANCE_INITIALIZER; | 53 LAZY_INSTANCE_INITIALIZER; |
| 54 | 54 |
| 55 // A RenderViewVisitor class that iterates through the set of available | 55 // A RenderViewVisitor class that iterates through the set of available |
| 56 // views, looking for a view of the given type, in the given browser window | 56 // views, looking for a view of the given type, in the given browser window |
| 57 // and within the given extension. | 57 // and within the given extension. |
| 58 // Used to accumulate the list of views associated with an extension. | 58 // Used to accumulate the list of views associated with an extension. |
| 59 class ExtensionViewAccumulator : public content::RenderViewVisitor { | 59 class ExtensionViewAccumulator : public content::RenderViewVisitor { |
| 60 public: | 60 public: |
| 61 ExtensionViewAccumulator(const std::string& extension_id, | 61 ExtensionViewAccumulator(const std::string& extension_id, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 OnNotifyRendererViewType) | 218 OnNotifyRendererViewType) |
| 219 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole, | 219 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole, |
| 220 OnAddMessageToConsole) | 220 OnAddMessageToConsole) |
| 221 IPC_MESSAGE_UNHANDLED(handled = false) | 221 IPC_MESSAGE_UNHANDLED(handled = false) |
| 222 IPC_END_MESSAGE_MAP() | 222 IPC_END_MESSAGE_MAP() |
| 223 return handled; | 223 return handled; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void ExtensionHelper::DidFinishDocumentLoad(WebFrame* frame) { | 226 void ExtensionHelper::DidFinishDocumentLoad(WebFrame* frame) { |
| 227 extension_dispatcher_->user_script_slave()->InjectScripts( | 227 extension_dispatcher_->user_script_slave()->InjectScripts( |
| 228 frame, UserScript::DOCUMENT_END); | 228 frame, extensions::UserScript::DOCUMENT_END); |
| 229 | 229 |
| 230 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 230 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 231 if (i != g_schedulers.Get().end()) | 231 if (i != g_schedulers.Get().end()) |
| 232 i->second->DidFinishDocumentLoad(); | 232 i->second->DidFinishDocumentLoad(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void ExtensionHelper::DidFinishLoad(WebKit::WebFrame* frame) { | 235 void ExtensionHelper::DidFinishLoad(WebKit::WebFrame* frame) { |
| 236 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 236 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 237 if (i != g_schedulers.Get().end()) | 237 if (i != g_schedulers.Get().end()) |
| 238 i->second->DidFinishLoad(); | 238 i->second->DidFinishLoad(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void ExtensionHelper::DidCreateDocumentElement(WebFrame* frame) { | 241 void ExtensionHelper::DidCreateDocumentElement(WebFrame* frame) { |
| 242 extension_dispatcher_->user_script_slave()->InjectScripts( | 242 extension_dispatcher_->user_script_slave()->InjectScripts( |
| 243 frame, UserScript::DOCUMENT_START); | 243 frame, extensions::UserScript::DOCUMENT_START); |
| 244 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 244 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 245 if (i != g_schedulers.Get().end()) | 245 if (i != g_schedulers.Get().end()) |
| 246 i->second->DidCreateDocumentElement(); | 246 i->second->DidCreateDocumentElement(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ExtensionHelper::DidStartProvisionalLoad(WebKit::WebFrame* frame) { | 249 void ExtensionHelper::DidStartProvisionalLoad(WebKit::WebFrame* frame) { |
| 250 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 250 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| 251 if (i != g_schedulers.Get().end()) | 251 if (i != g_schedulers.Get().end()) |
| 252 i->second->DidStartProvisionalLoad(); | 252 i->second->DidStartProvisionalLoad(); |
| 253 } | 253 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 269 if (!frame->parent()) { | 269 if (!frame->parent()) { |
| 270 app_icon_fetchers_.clear(); | 270 app_icon_fetchers_.clear(); |
| 271 app_definition_fetcher_.reset(NULL); | 271 app_definition_fetcher_.reset(NULL); |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Check first if we created a scheduler for the frame, since this function | 274 // Check first if we created a scheduler for the frame, since this function |
| 275 // gets called for navigations within the document. | 275 // gets called for navigations within the document. |
| 276 if (g_schedulers.Get().count(frame)) | 276 if (g_schedulers.Get().count(frame)) |
| 277 return; | 277 return; |
| 278 | 278 |
| 279 g_schedulers.Get()[frame] = new UserScriptScheduler( | 279 g_schedulers.Get()[frame] = new extensions::UserScriptScheduler( |
| 280 frame, extension_dispatcher_); | 280 frame, extension_dispatcher_); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void ExtensionHelper::OnExtensionResponse(int request_id, | 283 void ExtensionHelper::OnExtensionResponse(int request_id, |
| 284 bool success, | 284 bool success, |
| 285 const base::ListValue& response, | 285 const base::ListValue& response, |
| 286 const std::string& error) { | 286 const std::string& error) { |
| 287 extension_dispatcher_->OnExtensionResponse(request_id, | 287 extension_dispatcher_->OnExtensionResponse(request_id, |
| 288 success, | 288 success, |
| 289 response, | 289 response, |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 target_level = WebConsoleMessage::LevelWarning; | 505 target_level = WebConsoleMessage::LevelWarning; |
| 506 break; | 506 break; |
| 507 case content::CONSOLE_MESSAGE_LEVEL_ERROR: | 507 case content::CONSOLE_MESSAGE_LEVEL_ERROR: |
| 508 target_level = WebConsoleMessage::LevelError; | 508 target_level = WebConsoleMessage::LevelError; |
| 509 break; | 509 break; |
| 510 } | 510 } |
| 511 render_view()->GetWebView()->mainFrame()->addMessageToConsole( | 511 render_view()->GetWebView()->mainFrame()->addMessageToConsole( |
| 512 WebConsoleMessage(target_level, message)); | 512 WebConsoleMessage(target_level, message)); |
| 513 } | 513 } |
| 514 } | 514 } |
| OLD | NEW |