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_value_serializer.h" | 10 #include "base/json/json_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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 extension_dispatcher_->CheckIdleStatus(extension_id); | 195 extension_dispatcher_->CheckIdleStatus(extension_id); |
194 } | 196 } |
195 | 197 |
196 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, | 198 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, |
197 const std::string& function_name, | 199 const std::string& function_name, |
198 const ListValue& args, | 200 const ListValue& args, |
199 const GURL& event_url) { | 201 const GURL& event_url, |
| 202 bool user_gesture) { |
| 203 scoped_ptr<WebScopedUserGesture> web_user_gesture; |
| 204 if (user_gesture) { |
| 205 web_user_gesture.reset(new WebScopedUserGesture); |
| 206 } |
| 207 |
200 extension_dispatcher_->v8_context_set().DispatchChromeHiddenMethod( | 208 extension_dispatcher_->v8_context_set().DispatchChromeHiddenMethod( |
201 extension_id, function_name, args, render_view(), event_url); | 209 extension_id, function_name, args, render_view(), event_url); |
202 } | 210 } |
203 | 211 |
204 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, | 212 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, |
205 const std::string& message) { | 213 const std::string& message) { |
206 MiscellaneousBindings::DeliverMessage( | 214 MiscellaneousBindings::DeliverMessage( |
207 extension_dispatcher_->v8_context_set().GetAll(), | 215 extension_dispatcher_->v8_context_set().GetAll(), |
208 target_id, | 216 target_id, |
209 message, | 217 message, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 routing_id(), *pending_app_info_)); | 358 routing_id(), *pending_app_info_)); |
351 pending_app_info_.reset(NULL); | 359 pending_app_info_.reset(NULL); |
352 } | 360 } |
353 | 361 |
354 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { | 362 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { |
355 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 363 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
356 render_view()->GetWebView()->mainFrame()->addMessageToConsole( | 364 render_view()->GetWebView()->mainFrame()->addMessageToConsole( |
357 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 365 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
358 } | 366 } |
359 } | 367 } |
OLD | NEW |