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_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_dispatcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/common/child_process_logging.h" | 8 #include "chrome/common/child_process_logging.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/renderer/extensions/user_script_slave.h" | 23 #include "chrome/renderer/extensions/user_script_slave.h" |
24 #include "chrome/renderer/extensions/webstore_bindings.h" | 24 #include "chrome/renderer/extensions/webstore_bindings.h" |
25 #include "content/public/renderer/render_thread.h" | 25 #include "content/public/renderer/render_thread.h" |
26 #include "grit/renderer_resources.h" | 26 #include "grit/renderer_resources.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
34 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
35 #include "v8/include/v8.h" | 36 #include "v8/include/v8.h" |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 40 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
40 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 41 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
41 | 42 |
42 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) { | 43 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) { |
43 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) | 44 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) |
44 return ChromeV8Context::CONTENT_SCRIPT; | 45 return ChromeV8Context::CONTENT_SCRIPT; |
45 return ChromeV8Context::OTHER; | 46 return ChromeV8Context::OTHER; |
46 } | 47 } |
47 | 48 |
48 } | 49 } |
49 | 50 |
50 using namespace extensions; | 51 using namespace extensions; |
51 | 52 |
52 using WebKit::WebDataSource; | 53 using WebKit::WebDataSource; |
53 using WebKit::WebDocument; | 54 using WebKit::WebDocument; |
54 using WebKit::WebFrame; | 55 using WebKit::WebFrame; |
55 using WebKit::WebSecurityPolicy; | 56 using WebKit::WebSecurityPolicy; |
56 using WebKit::WebString; | 57 using WebKit::WebString; |
| 58 using WebKit::WebScopedUserGesture; |
57 using WebKit::WebVector; | 59 using WebKit::WebVector; |
58 using WebKit::WebView; | 60 using WebKit::WebView; |
59 using content::RenderThread; | 61 using content::RenderThread; |
60 | 62 |
61 ExtensionDispatcher::ExtensionDispatcher() | 63 ExtensionDispatcher::ExtensionDispatcher() |
62 : is_webkit_initialized_(false), | 64 : is_webkit_initialized_(false), |
63 webrequest_adblock_(false), | 65 webrequest_adblock_(false), |
64 webrequest_adblock_plus_(false), | 66 webrequest_adblock_plus_(false), |
65 webrequest_other_(false) { | 67 webrequest_other_(false) { |
66 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 68 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void ExtensionDispatcher::OnSetFunctionNames( | 160 void ExtensionDispatcher::OnSetFunctionNames( |
159 const std::vector<std::string>& names) { | 161 const std::vector<std::string>& names) { |
160 function_names_.clear(); | 162 function_names_.clear(); |
161 for (size_t i = 0; i < names.size(); ++i) | 163 for (size_t i = 0; i < names.size(); ++i) |
162 function_names_.insert(names[i]); | 164 function_names_.insert(names[i]); |
163 } | 165 } |
164 | 166 |
165 void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id, | 167 void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id, |
166 const std::string& function_name, | 168 const std::string& function_name, |
167 const ListValue& args, | 169 const ListValue& args, |
168 const GURL& event_url) { | 170 const GURL& event_url, |
| 171 bool user_gesture) { |
| 172 scoped_ptr<WebScopedUserGesture> web_user_gesture; |
| 173 if (user_gesture) { |
| 174 web_user_gesture.reset(new WebScopedUserGesture); |
| 175 } |
| 176 |
169 v8_context_set_.DispatchChromeHiddenMethod( | 177 v8_context_set_.DispatchChromeHiddenMethod( |
170 extension_id, function_name, args, NULL, event_url); | 178 extension_id, function_name, args, NULL, event_url); |
171 | 179 |
172 // Reset the idle handler each time there's any activity like event or message | 180 // Reset the idle handler each time there's any activity like event or message |
173 // dispatch, for which Invoke is the chokepoint. | 181 // dispatch, for which Invoke is the chokepoint. |
174 if (is_extension_process_) { | 182 if (is_extension_process_) { |
175 RenderThread::Get()->ScheduleIdleHandler( | 183 RenderThread::Get()->ScheduleIdleHandler( |
176 kInitialExtensionIdleHandlerDelayMs); | 184 kInitialExtensionIdleHandlerDelayMs); |
177 } | 185 } |
178 | 186 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 540 |
533 RenderThread::Get()->RegisterExtension(extension); | 541 RenderThread::Get()->RegisterExtension(extension); |
534 } | 542 } |
535 | 543 |
536 void ExtensionDispatcher::OnUsingWebRequestAPI( | 544 void ExtensionDispatcher::OnUsingWebRequestAPI( |
537 bool adblock, bool adblock_plus, bool other) { | 545 bool adblock, bool adblock_plus, bool other) { |
538 webrequest_adblock_ = adblock; | 546 webrequest_adblock_ = adblock; |
539 webrequest_adblock_plus_ = adblock_plus; | 547 webrequest_adblock_plus_ = adblock_plus; |
540 webrequest_other_ = other; | 548 webrequest_other_ = other; |
541 } | 549 } |
OLD | NEW |