| 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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/chrome_view_type.h" | 15 #include "chrome/common/chrome_view_type.h" |
| 16 #include "chrome/common/extensions/extension_messages.h" | 16 #include "chrome/common/extensions/extension_messages.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/renderer/extensions/chrome_v8_context.h" | 19 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 20 #include "chrome/renderer/extensions/extension_dispatcher.h" | 20 #include "chrome/renderer/extensions/extension_dispatcher.h" |
| 21 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 21 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 22 #include "chrome/renderer/extensions/schema_generated_bindings.h" | 22 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
| 23 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" | 23 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" |
| 24 #include "chrome/renderer/extensions/user_script_slave.h" | 24 #include "chrome/renderer/extensions/user_script_slave.h" |
| 25 #include "content/public/renderer/render_view.h" | 25 #include "content/public/renderer/render_view.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 30 #include "webkit/glue/image_resource_fetcher.h" | 31 #include "webkit/glue/image_resource_fetcher.h" |
| 31 #include "webkit/glue/resource_fetcher.h" | 32 #include "webkit/glue/resource_fetcher.h" |
| 32 | 33 |
| 33 using extensions::MiscellaneousBindings; | 34 using extensions::MiscellaneousBindings; |
| 34 using extensions::SchemaGeneratedBindings; | 35 using extensions::SchemaGeneratedBindings; |
| 35 using WebKit::WebConsoleMessage; | 36 using WebKit::WebConsoleMessage; |
| 36 using WebKit::WebDataSource; | 37 using WebKit::WebDataSource; |
| 37 using WebKit::WebFrame; | 38 using WebKit::WebFrame; |
| 38 using WebKit::WebURLRequest; | 39 using WebKit::WebURLRequest; |
| 40 using WebKit::WebScopedUserGesture; |
| 39 using WebKit::WebView; | 41 using WebKit::WebView; |
| 40 using webkit_glue::ImageResourceFetcher; | 42 using webkit_glue::ImageResourceFetcher; |
| 41 using webkit_glue::ResourceFetcher; | 43 using webkit_glue::ResourceFetcher; |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 // Keeps a mapping from the frame pointer to a UserScriptIdleScheduler object. | 46 // Keeps a mapping from the frame pointer to a UserScriptIdleScheduler object. |
| 45 // We store this mapping per process, because a frame can jump from one | 47 // We store this mapping per process, because a frame can jump from one |
| 46 // document to another with adoptNode, and so having the object be a | 48 // document to another with adoptNode, and so having the object be a |
| 47 // RenderViewObserver means it might miss some notifications after it moves. | 49 // RenderViewObserver means it might miss some notifications after it moves. |
| 48 typedef std::map<WebFrame*, UserScriptIdleScheduler*> SchedulerMap; | 50 typedef std::map<WebFrame*, UserScriptIdleScheduler*> SchedulerMap; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 const std::string& error) { | 189 const std::string& error) { |
| 188 std::string extension_id; | 190 std::string extension_id; |
| 189 SchemaGeneratedBindings::HandleResponse( | 191 SchemaGeneratedBindings::HandleResponse( |
| 190 extension_dispatcher_->v8_context_set(), request_id, success, | 192 extension_dispatcher_->v8_context_set(), request_id, success, |
| 191 response, error, &extension_id); | 193 response, error, &extension_id); |
| 192 } | 194 } |
| 193 | 195 |
| 194 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, | 196 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, |
| 195 const std::string& function_name, | 197 const std::string& function_name, |
| 196 const ListValue& args, | 198 const ListValue& args, |
| 197 const GURL& event_url) { | 199 const GURL& event_url, |
| 200 bool user_gesture) { |
| 201 scoped_ptr<WebScopedUserGesture> web_user_gesture; |
| 202 if (user_gesture) { |
| 203 web_user_gesture.reset(new WebScopedUserGesture); |
| 204 } |
| 205 |
| 198 extension_dispatcher_->v8_context_set().DispatchChromeHiddenMethod( | 206 extension_dispatcher_->v8_context_set().DispatchChromeHiddenMethod( |
| 199 extension_id, function_name, args, render_view(), event_url); | 207 extension_id, function_name, args, render_view(), event_url); |
| 200 } | 208 } |
| 201 | 209 |
| 202 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, | 210 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, |
| 203 const std::string& message) { | 211 const std::string& message) { |
| 204 MiscellaneousBindings::DeliverMessage( | 212 MiscellaneousBindings::DeliverMessage( |
| 205 extension_dispatcher_->v8_context_set().GetAll(), | 213 extension_dispatcher_->v8_context_set().GetAll(), |
| 206 target_id, | 214 target_id, |
| 207 message, | 215 message, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 routing_id(), *pending_app_info_)); | 356 routing_id(), *pending_app_info_)); |
| 349 pending_app_info_.reset(NULL); | 357 pending_app_info_.reset(NULL); |
| 350 } | 358 } |
| 351 | 359 |
| 352 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { | 360 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { |
| 353 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 361 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 354 render_view()->GetWebView()->mainFrame()->addMessageToConsole( | 362 render_view()->GetWebView()->mainFrame()->addMessageToConsole( |
| 355 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 363 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
| 356 } | 364 } |
| 357 } | 365 } |
| OLD | NEW |