| 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/renderer/extensions/extension_helper.h" | 5 #include "chrome/renderer/extensions/extension_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_value_serializer.h" | 8 #include "base/json/json_value_serializer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/chrome_view_types.h" | 13 #include "chrome/common/chrome_view_types.h" |
| 14 #include "chrome/common/extensions/extension_messages.h" | 14 #include "chrome/common/extensions/extension_messages.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/renderer/extensions/app_bindings.h" | 17 #include "chrome/renderer/extensions/app_bindings.h" |
| 18 #include "chrome/renderer/extensions/chrome_v8_context.h" | 18 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 19 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" | 19 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" |
| 20 #include "chrome/renderer/extensions/event_bindings.h" | 20 #include "chrome/renderer/extensions/event_bindings.h" |
| 21 #include "chrome/renderer/extensions/extension_dispatcher.h" | 21 #include "chrome/renderer/extensions/extension_dispatcher.h" |
| 22 #include "chrome/renderer/extensions/extension_process_bindings.h" | 22 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 23 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 23 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
| 24 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" | 24 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" |
| 25 #include "chrome/renderer/extensions/user_script_slave.h" | 25 #include "chrome/renderer/extensions/user_script_slave.h" |
| 26 #include "content/public/renderer/render_view.h" | 26 #include "content/public/renderer/render_view.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 31 #include "webkit/glue/image_resource_fetcher.h" | 31 #include "webkit/glue/image_resource_fetcher.h" |
| 32 #include "webkit/glue/resource_fetcher.h" | 32 #include "webkit/glue/resource_fetcher.h" |
| 33 | 33 |
| 34 using extensions::MiscellaneousBindings; |
| 35 using extensions::SchemaGeneratedBindings; |
| 34 using WebKit::WebConsoleMessage; | 36 using WebKit::WebConsoleMessage; |
| 35 using WebKit::WebDataSource; | 37 using WebKit::WebDataSource; |
| 36 using WebKit::WebFrame; | 38 using WebKit::WebFrame; |
| 37 using WebKit::WebURLRequest; | 39 using WebKit::WebURLRequest; |
| 38 using WebKit::WebView; | 40 using WebKit::WebView; |
| 39 using webkit_glue::ImageResourceFetcher; | 41 using webkit_glue::ImageResourceFetcher; |
| 40 using webkit_glue::ResourceFetcher; | 42 using webkit_glue::ResourceFetcher; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 // Keeps a mapping from the frame pointer to a UserScriptIdleScheduler object. | 45 // Keeps a mapping from the frame pointer to a UserScriptIdleScheduler object. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 193 |
| 192 g_schedulers.Get()[frame] = new UserScriptIdleScheduler( | 194 g_schedulers.Get()[frame] = new UserScriptIdleScheduler( |
| 193 frame, extension_dispatcher_); | 195 frame, extension_dispatcher_); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void ExtensionHelper::OnExtensionResponse(int request_id, | 198 void ExtensionHelper::OnExtensionResponse(int request_id, |
| 197 bool success, | 199 bool success, |
| 198 const std::string& response, | 200 const std::string& response, |
| 199 const std::string& error) { | 201 const std::string& error) { |
| 200 std::string extension_id; | 202 std::string extension_id; |
| 201 ExtensionProcessBindings::HandleResponse( | 203 SchemaGeneratedBindings::HandleResponse( |
| 202 extension_dispatcher_->v8_context_set(), request_id, success, | 204 extension_dispatcher_->v8_context_set(), request_id, success, |
| 203 response, error, &extension_id); | 205 response, error, &extension_id); |
| 204 | 206 |
| 205 if (CommandLine::ForCurrentProcess()->HasSwitch( | 207 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 206 switches::kEnableLazyBackgroundPages)) | 208 switches::kEnableLazyBackgroundPages)) |
| 207 extension_dispatcher_->CheckIdleStatus(extension_id); | 209 extension_dispatcher_->CheckIdleStatus(extension_id); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, | 212 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, |
| 211 const std::string& function_name, | 213 const std::string& function_name, |
| 212 const ListValue& args, | 214 const ListValue& args, |
| 213 const GURL& event_url) { | 215 const GURL& event_url) { |
| 214 extension_dispatcher_->v8_context_set().DispatchChromeHiddenMethod( | 216 extension_dispatcher_->v8_context_set().DispatchChromeHiddenMethod( |
| 215 extension_id, function_name, args, render_view(), event_url); | 217 extension_id, function_name, args, render_view(), event_url); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, | 220 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, |
| 219 const std::string& message) { | 221 const std::string& message) { |
| 220 RendererExtensionBindings::DeliverMessage( | 222 MiscellaneousBindings::DeliverMessage( |
| 221 extension_dispatcher_->v8_context_set().GetAll(), | 223 extension_dispatcher_->v8_context_set().GetAll(), |
| 222 target_id, | 224 target_id, |
| 223 message, | 225 message, |
| 224 render_view()); | 226 render_view()); |
| 225 } | 227 } |
| 226 | 228 |
| 227 void ExtensionHelper::OnExecuteCode( | 229 void ExtensionHelper::OnExecuteCode( |
| 228 const ExtensionMsg_ExecuteCode_Params& params) { | 230 const ExtensionMsg_ExecuteCode_Params& params) { |
| 229 WebView* webview = render_view()->GetWebView(); | 231 WebView* webview = render_view()->GetWebView(); |
| 230 WebFrame* main_frame = webview->mainFrame(); | 232 WebFrame* main_frame = webview->mainFrame(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 routing_id(), *pending_app_info_)); | 365 routing_id(), *pending_app_info_)); |
| 364 pending_app_info_.reset(NULL); | 366 pending_app_info_.reset(NULL); |
| 365 } | 367 } |
| 366 | 368 |
| 367 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { | 369 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { |
| 368 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 370 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 369 render_view()->GetWebView()->mainFrame()->addMessageToConsole( | 371 render_view()->GetWebView()->mainFrame()->addMessageToConsole( |
| 370 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 372 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
| 371 } | 373 } |
| 372 } | 374 } |
| OLD | NEW |