Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 8540012: Enable extension APIs for content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_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"
11 #include "chrome/common/extensions/extension_messages.h" 11 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/extensions/extension_permission_set.h" 12 #include "chrome/common/extensions/extension_permission_set.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "chrome/renderer/chrome_render_process_observer.h" 14 #include "chrome/renderer/chrome_render_process_observer.h"
15 #include "chrome/renderer/extensions/app_bindings.h" 15 #include "chrome/renderer/extensions/app_bindings.h"
16 #include "chrome/renderer/extensions/chrome_v8_context.h" 16 #include "chrome/renderer/extensions/chrome_v8_context.h"
17 #include "chrome/renderer/extensions/chrome_v8_extension.h" 17 #include "chrome/renderer/extensions/chrome_v8_extension.h"
18 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" 18 #include "chrome/renderer/extensions/chrome_webstore_bindings.h"
19 #include "chrome/renderer/extensions/event_bindings.h" 19 #include "chrome/renderer/extensions/event_bindings.h"
20 #include "chrome/renderer/extensions/extension_groups.h" 20 #include "chrome/renderer/extensions/extension_groups.h"
21 #include "chrome/renderer/extensions/extension_process_bindings.h"
22 #include "chrome/renderer/extensions/file_browser_private_bindings.h" 21 #include "chrome/renderer/extensions/file_browser_private_bindings.h"
23 #include "chrome/renderer/extensions/renderer_extension_bindings.h" 22 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
23 #include "chrome/renderer/extensions/schema_generated_bindings.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_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/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
32 #include "v8/include/v8.h" 32 #include "v8/include/v8.h"
33 33
34 namespace { 34 namespace {
35 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; 35 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
36 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; 36 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
37 } 37 }
38 38
39 using extensions::MiscellaneousBindings;
40 using extensions::SchemaGeneratedBindings;
39 using WebKit::WebDataSource; 41 using WebKit::WebDataSource;
40 using WebKit::WebFrame; 42 using WebKit::WebFrame;
41 using WebKit::WebSecurityPolicy; 43 using WebKit::WebSecurityPolicy;
42 using WebKit::WebString; 44 using WebKit::WebString;
43 using content::RenderThread; 45 using content::RenderThread;
44 46
45 ExtensionDispatcher::ExtensionDispatcher() 47 ExtensionDispatcher::ExtensionDispatcher()
46 : is_webkit_initialized_(false), 48 : is_webkit_initialized_(false),
47 webrequest_adblock_(false), 49 webrequest_adblock_(false),
48 webrequest_adblock_plus_(false), 50 webrequest_adblock_plus_(false),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 97 }
96 98
97 RegisterExtension(new AppBindings(this), false); 99 RegisterExtension(new AppBindings(this), false);
98 RegisterExtension(ChromeWebstoreExtension::Get(), false); 100 RegisterExtension(ChromeWebstoreExtension::Get(), false);
99 101
100 // Add v8 extensions related to chrome extensions. 102 // Add v8 extensions related to chrome extensions.
101 RegisterExtension(new ChromeV8Extension( 103 RegisterExtension(new ChromeV8Extension(
102 "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), true); 104 "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), true);
103 RegisterExtension(EventBindings::Get(this), true); 105 RegisterExtension(EventBindings::Get(this), true);
104 RegisterExtension(new FileBrowserPrivateBindings(), true); 106 RegisterExtension(new FileBrowserPrivateBindings(), true);
105 RegisterExtension(RendererExtensionBindings::Get(this), true); 107 RegisterExtension(MiscellaneousBindings::Get(this), true);
106 RegisterExtension(ExtensionProcessBindings::Get(this), true); 108 RegisterExtension(SchemaGeneratedBindings::Get(this), true);
107 RegisterExtension(new ChromeV8Extension( 109 RegisterExtension(new ChromeV8Extension(
108 "extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL), true); 110 "extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL), true);
109 111
110 // Initialize host permissions for any extensions that were activated before 112 // Initialize host permissions for any extensions that were activated before
111 // WebKit was initialized. 113 // WebKit was initialized.
112 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 114 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
113 iter != active_extension_ids_.end(); ++iter) { 115 iter != active_extension_ids_.end(); ++iter) {
114 const Extension* extension = extensions_.GetByID(*iter); 116 const Extension* extension = extensions_.GetByID(*iter);
115 if (extension) 117 if (extension)
116 InitOriginPermissions(extension); 118 InitOriginPermissions(extension);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (CommandLine::ForCurrentProcess()->HasSwitch( 160 if (CommandLine::ForCurrentProcess()->HasSwitch(
159 switches::kEnableLazyBackgroundPages) && 161 switches::kEnableLazyBackgroundPages) &&
160 function_name == "Event.dispatchJSON") { // may always be true 162 function_name == "Event.dispatchJSON") { // may always be true
161 RenderThread::Get()->Send( 163 RenderThread::Get()->Send(
162 new ExtensionHostMsg_ExtensionEventAck(extension_id)); 164 new ExtensionHostMsg_ExtensionEventAck(extension_id));
163 CheckIdleStatus(extension_id); 165 CheckIdleStatus(extension_id);
164 } 166 }
165 } 167 }
166 168
167 void ExtensionDispatcher::CheckIdleStatus(const std::string& extension_id) { 169 void ExtensionDispatcher::CheckIdleStatus(const std::string& extension_id) {
168 if (!ExtensionProcessBindings::HasPendingRequests(extension_id)) 170 if (!SchemaGeneratedBindings::HasPendingRequests(extension_id))
169 RenderThread::Get()->Send(new ExtensionHostMsg_ExtensionIdle(extension_id)); 171 RenderThread::Get()->Send(new ExtensionHostMsg_ExtensionIdle(extension_id));
170 } 172 }
171 173
172 void ExtensionDispatcher::OnDeliverMessage(int target_port_id, 174 void ExtensionDispatcher::OnDeliverMessage(int target_port_id,
173 const std::string& message) { 175 const std::string& message) {
174 RendererExtensionBindings::DeliverMessage( 176 MiscellaneousBindings::DeliverMessage(
175 v8_context_set_.GetAll(), 177 v8_context_set_.GetAll(),
176 target_port_id, 178 target_port_id,
177 message, 179 message,
178 NULL); // All render views. 180 NULL); // All render views.
179 } 181 }
180 182
181 void ExtensionDispatcher::OnLoaded(const ExtensionMsg_Loaded_Params& params) { 183 void ExtensionDispatcher::OnLoaded(const ExtensionMsg_Loaded_Params& params) {
182 scoped_refptr<const Extension> extension(params.ConvertToExtension()); 184 scoped_refptr<const Extension> extension(params.ConvertToExtension());
183 if (!extension) { 185 if (!extension) {
184 // This can happen if extension parsing fails for any reason. One reason 186 // This can happen if extension parsing fails for any reason. One reason
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 409
408 RenderThread::Get()->RegisterExtension(extension); 410 RenderThread::Get()->RegisterExtension(extension);
409 } 411 }
410 412
411 void ExtensionDispatcher::OnUsingWebRequestAPI( 413 void ExtensionDispatcher::OnUsingWebRequestAPI(
412 bool adblock, bool adblock_plus, bool other) { 414 bool adblock, bool adblock_plus, bool other) {
413 webrequest_adblock_ = adblock; 415 webrequest_adblock_ = adblock;
414 webrequest_adblock_plus_ = adblock_plus; 416 webrequest_adblock_plus_ = adblock_plus;
415 webrequest_other_ = other; 417 webrequest_other_ = other;
416 } 418 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_api_json_validity_unittest.cc ('k') | chrome/renderer/extensions/extension_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698